//将前者的属性copy给后者,属性名要一样
import org.springframework.beans.BeanUtils;
BeanUtils.copyProperties(productInfo,productInfoVO);
这里要提示一点假如productInfo中对应的属性(即名字和productInfoVO一样的)是null的时候也会复制过去,把后面target中productInfoVO有值的属性冲掉
如果是groovy中进行属性复制,会复制metaclass的属性,会导致当前的对象的class值变成copy源对象的class,使得后面的属性赋值报找不到属性报错
ScrapDetailVO scrapDetailVO
List<ScrapDetailVO> scrapDetailVOList = []
for(RfLocationInventory rfl : rfLocationInventoryList){
Integer countNum = rfl.onHandQty + rfl.inTransitQty - rfl.allocatedQty - rfl.lockedQty - rfl.frozenQty
if(countNum <= 0 ){
continue
}
scrapDetailVO = new ScrapDetailVO()
MetaClass metaClass = scrapDetailVO.metaClass
//复制一下属性
BeanUtils.copyProperties(rfl,scrapDetailVO)
scrapDetailVO.metaClass = metaClass
scrapDetailVO.inventoryId = rfl.id
//数量=在库+移库-分配-锁定-冻结
scrapDetailVO.availableNum = countNum
scrapDetailVO.zoneCode = locationMap.get(scrapDetailVO.locationCode)
//查询的就是正品,这里给个默认值正品
scrapDetailVO.itemStatus = "ZP"
scrapDetailVOList.add(scrapDetailVO)
}