@ -1,25 +1,54 @@
package com.win.module.wms.service.productreceiptRecord ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.LocalDateTimeUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.win.framework.common.pojo.CustomConditions ;
import com.win.framework.common.pojo.PageResult ;
import com.win.framework.common.util.collection.CollectionUtils ;
import com.win.framework.common.util.date.LocalDateTimeUtils ;
import com.win.module.wms.controller.productreceiptRecord.vo.* ;
import com.win.module.wms.controller.transaction.vo.TransactionCreateReqVO ;
import com.win.module.wms.convert.backflushdetailbqad.BackflushDetailbQadConvert ;
import com.win.module.wms.convert.productreceiptRecord.BackflushRecordDetailbConvert ;
import com.win.module.wms.dal.dataobject.areabasic.AreabasicDO ;
import com.win.module.wms.dal.dataobject.backflushdetailbqad.BackflushDetailbQadDO ;
import com.win.module.wms.dal.dataobject.balance.BalanceDO ;
import com.win.module.wms.dal.dataobject.businesstype.BusinesstypeDO ;
import com.win.module.wms.dal.dataobject.itemarea.ItemareaDO ;
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO ;
import com.win.module.wms.dal.dataobject.location.LocationDO ;
import com.win.module.wms.dal.dataobject.productreceiptDetailb.ProductreceiptDetailbDO ;
import com.win.module.wms.dal.dataobject.productreceiptRecord.ProductreceiptRecordDetailDO ;
import com.win.module.wms.dal.dataobject.productreceiptRecord.ProductreceiptRecordDetailbDO ;
import com.win.module.wms.dal.dataobject.productreceiptRecord.ProductreceiptRecordMainDO ;
import com.win.module.wms.dal.dataobject.productredressRecord.ProductredressRecordDetailDO ;
import com.win.module.wms.dal.dataobject.productredressRecord.ProductredressRecordMainDO ;
import com.win.module.wms.dal.dataobject.transactiontype.TransactiontypeDO ;
import com.win.module.wms.dal.dataobject.workstation.WorkstationDO ;
import com.win.module.wms.dal.mysql.itembasic.ItembasicMapper ;
import com.win.module.wms.dal.mysql.productreceiptRecord.ProductreceiptRecordDetailMapper ;
import com.win.module.wms.dal.mysql.productreceiptRecord.ProductreceiptRecordDetailbMapper ;
import com.win.module.wms.dal.mysql.productreceiptRecord.ProductreceiptRecordMainMapper ;
import com.win.module.wms.dal.mysql.productredressRecord.ProductredressRecordDetailMapper ;
import com.win.module.wms.dal.mysql.productredressRecord.ProductredressRecordMainMapper ;
import com.win.module.wms.enums.common.InventoryStatusEnum ;
import org.springframework.beans.BeanUtils ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.validation.annotation.Validated ;
import javax.annotation.Resource ;
import java.math.BigDecimal ;
import java.time.LocalDateTime ;
import java.util.* ;
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception ;
import static com.win.module.wms.enums.ErrorCodeConstants.BACKFLUSH_DETAILB_QAD_IMPORT_LIST_IS_EMPTY ;
import static com.win.module.wms.enums.ErrorCodeConstants.BACKFLUSH_RECORD_DETAILB_NOT_EXISTS ;
import static com.win.module.wms.enums.ErrorCodeConstants.* ;
import static com.win.module.wms.enums.ErrorCodeConstants.BALANCE_EXCEPTION ;
/ * *
* 制品收货记录子 Service 实现类
@ -33,7 +62,15 @@ public class BackflushRecordDetailbServiceImpl implements BackflushRecordDetailb
@Resource
private ProductreceiptRecordDetailbMapper productreceiptRecordDetailbMapper ;
@Resource
private ProductreceiptRecordMainService productreceiptRecordMainService ;
private ProductreceiptRecordMainMapper productreceiptRecordMainMapper ;
@Resource
private ProductreceiptRecordDetailMapper productreceiptRecordDetailMapper ;
@Resource
private ProductredressRecordDetailMapper productredressRecordDetailMapper ;
@Resource
private ItembasicMapper itembasicMapper ;
@Resource
private ProductredressRecordMainMapper productredressRecordMainMapper ;
@Override
public String createBackflushRecordDetailb ( BackflushRecordDetailbCreateReqVO createReqVO ) {
@ -123,6 +160,42 @@ public class BackflushRecordDetailbServiceImpl implements BackflushRecordDetailb
if ( mainDO . getQty ( ) = = null | | mainDO . getQty ( ) . compareTo ( BigDecimal . ZERO ) = = 0 ) {
message . append ( "消耗原料数量不能为空并且等于0" ) . append ( "," ) ;
}
if ( message = = null | | message . length ( ) = = 0 ) {
// 验证物料是否存在
ItembasicDO itembasicDO = itembasicMapper . selectByCode ( mainDO . getParentItemCode ( ) ) ;
if ( itembasicDO = = null ) message . append ( "父物料号不存在【" ) . append ( mainDO . getParentItemCode ( ) ) . append ( "】" ) . append ( "," ) ;
ItembasicDO itembasicDOI = itembasicMapper . selectByCode ( mainDO . getItemCode ( ) ) ;
if ( itembasicDOI = = null ) message . append ( "消耗原料物料号不存在【" ) . append ( mainDO . getItemCode ( ) ) . append ( "】" ) . append ( "," ) ;
}
if ( message = = null | | message . length ( ) = = 0 ) {
// 校验数据
// 判断 qad回传数据 是完工的还是回收的 负数为完工消耗 正数为回收入库
String isProductreceipt = "true" ;
if ( mainDO . getQty ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) {
isProductreceipt = "false" ;
}
if ( isProductreceipt . equals ( "true" ) ) {
ProductreceiptRecordMainDO productreceiptRecordMainDO = productreceiptRecordMainMapper . selectOne ( "number" , mainDO . getProductreceiptNumber ( ) ) ;
if ( productreceiptRecordMainDO = = null ) {
message . append ( "未查询到收货记录 单据号:" ) . append ( mainDO . getProductreceiptNumber ( ) ) ;
} else {
List < ProductreceiptRecordDetailDO > productreceiptRecordDetailDOList = productreceiptRecordDetailMapper . selectList ( "master_id" , productreceiptRecordMainDO . getId ( ) , "item_code" , mainDO . getParentItemCode ( ) ) ;
if ( productreceiptRecordDetailDOList = = null | | productreceiptRecordDetailDOList . size ( ) = = 0 ) {
message . append ( "未查询到收货记录 物料:" ) . append ( mainDO . getParentItemCode ( ) ) . append ( " ;单据号:" ) . append ( mainDO . getProductreceiptNumber ( ) ) ;
}
}
} else {
ProductredressRecordMainDO productredressRecordMainDO = productredressRecordMainMapper . selectOne ( "number" , mainDO . getProductreceiptNumber ( ) ) ;
if ( productredressRecordMainDO = = null ) {
message . append ( "未查询到回收记录 单据号:" ) . append ( mainDO . getProductreceiptNumber ( ) ) ;
} else {
List < ProductredressRecordDetailDO > productredressRecordDetailDOList = productredressRecordDetailMapper . selectList ( "master_id" , productredressRecordMainDO . getId ( ) , "item_code" , mainDO . getParentItemCode ( ) ) ;
if ( productredressRecordDetailDOList = = null | | productredressRecordDetailDOList . size ( ) = = 0 ) {
message . append ( "未查询到回收记录 物料:" ) . append ( mainDO . getParentItemCode ( ) ) . append ( " ;单据号:" ) . append ( mainDO . getProductreceiptNumber ( ) ) ;
}
}
}
}
return message . toString ( ) ;
}
@ -170,14 +243,462 @@ public class BackflushRecordDetailbServiceImpl implements BackflushRecordDetailb
isProductreceipt = "false" ;
}
if ( isProductreceipt . equals ( "true" ) ) {
productreceiptRecordMainService . generateProductreceiptRecordByQAD ( backflushDetailbQadDOList . get ( 0 ) . getProductreceiptNumber ( ) , backflushDetailbQadDOList . get ( 0 ) . getParentItemCode ( ) , backflushDetailbQadDOList , false ) ;
// this.generateProductreceiptRecordTransaction(backflushDetailbQadDOList.get(0).getProductreceiptNumber(),backflushDetailbQadDOList.get(0).getParentItemCode(),backflushDetailbQadDOList);
} else {
productreceiptRecordMainService . generateProductredressByQAD ( backflushDetailbQadDOList . get ( 0 ) . getProductreceiptNumber ( ) , backflushDetailbQadDOList . get ( 0 ) . getParentItemCode ( ) , backflushDetailbQadDOList , false ) ;
// this.generateProductredressTransaction(backflushDetailbQadDOList.get(0).getProductreceiptNumber(),backflushDetailbQadDOList.get(0).getParentItemCode(),backflushDetailbQadDOList);
}
}
}
return errorList ;
}
//
// private void generateProductreceiptRecordTransaction(String number, String parentItemCode, List<BackflushDetailbQadDO> backflushDetailbQadDOListNumber) {
// ProductreceiptRecordMainDO productreceiptRecordMainDO = productreceiptRecordMainMapper.selectOne("number", number);
// List<ProductreceiptRecordDetailDO> productreceiptRecordDetailDOList = productreceiptRecordDetailMapper.selectList("master_id", productreceiptRecordMainDO.getId(), "item_code", parentItemCode);
//
// ProductreceiptRecordDetailDO productreceiptRecordDetailDO = productreceiptRecordDetailDOList.get(0);
// // 下线结算集合
// List<ProductreceiptRecordDetailbDO> offlinesettlementRecordList = new ArrayList<>();
// //库存事务
// List<TransactionCreateReqVO> transactionCreateReqVOList = new ArrayList<>();
// List<ProductreceiptRecordDetailbDO> productreceiptRequestDetailbDOList = new ArrayList<>();
// for (BackflushDetailbQadDO backflushDetailbQadDO : backflushDetailbQadDOListNumber) {
// ProductreceiptRecordDetailbDO productreceiptRecordDetailbDO = new ProductreceiptRecordDetailbDO();
// productreceiptRecordDetailbDO.setProcessCode(productreceiptRecordDetailDO.getProcessCode());
// productreceiptRecordDetailbDO.setBomVersion("1");
// productreceiptRecordDetailbDO.setItemCode(backflushDetailbQadDO.getItemCode());
// productreceiptRecordDetailbDO.setMasterId(productreceiptRecordDetailDO.getId());
// productreceiptRecordDetailbDO.setNumber(productreceiptRecordMainDO.getNumber());
// productreceiptRecordDetailbDO.setQty(backflushDetailbQadDO.getQty().abs()); // 从QAD回传的数量有正有负 统一绝对值处理
// productreceiptRecordDetailbDO.setCreator(productreceiptRecordMainDO.getCreator());
// productreceiptRecordDetailbDO.setUpdater(productreceiptRecordMainDO.getUpdater());
// // 赋值物料相关信息
//// ItembasicDO itembasicDO = itembasicService.selectItembasic(backflushDetailbQadDO.getItemCode());
// QueryWrapper<ItembasicDO> itembasicDOQueryWrapper = new QueryWrapper<>();
// itembasicDOQueryWrapper.eq("code", backflushDetailbQadDO.getItemCode());
// itembasicDOQueryWrapper.eq("available", "TRUE");
// ItembasicDO itembasicDO = itembasicMapper.selectOne(itembasicDOQueryWrapper);
// productreceiptRecordDetailbDO.setUom(itembasicDO.getUom());
// productreceiptRecordDetailbDO.setItemName(itembasicDO.getName());
// productreceiptRecordDetailbDO.setItemDesc1(itembasicDO.getDesc1());
// productreceiptRecordDetailbDO.setItemDesc2(itembasicDO.getDesc2());
// productreceiptRecordDetailbDO.setProjectCode(itembasicDO.getProject());
// // 根据 生产线 工位 查询工位信息 并赋值 from_location_code
//// WorkstationDO workstationDO = workstationService.selectWorkstationExist(productreceiptRecordDetailDO.getWorkStationCode(), productreceiptRecordMainDO.getWorkshopCode(), productreceiptRecordDetailDO.getProductionlineCode());
// WorkstationDO workstationDO;
// QueryWrapper<WorkstationDO> queryWrapperWorkstation = new QueryWrapper<>();
// queryWrapperWorkstation.eq("code", productreceiptRecordDetailDO.getWorkStationCode());
// queryWrapperWorkstation.eq("workshop_code", productreceiptRecordMainDO.getWorkshopCode());
// if (!org.apache.commons.lang3.StringUtils.isEmpty(productreceiptRecordDetailDO.getProductionlineCode())) {
// queryWrapperWorkstation.eq("production_line_code", productreceiptRecordDetailDO.getProductionlineCode());
// }
// queryWrapperWorkstation.eq("available", "TRUE");
// List<WorkstationDO> workstationDOS = workstationMapper.selectList(queryWrapperWorkstation);
// if (!CollectionUtil.isEmpty(workstationDOS)) {
// workstationDO = workstationDOS.get(0);
// } else {
// if (auto) {
// backflushDetailbQadDO.setRemark("车间,生产线代码与工位不匹配:" + "车间" + productreceiptRecordMainDO.getWorkshopCode() + "生产线" + productreceiptRecordDetailDO.getProductionlineCode() + "工位" + productreceiptRecordDetailDO.getWorkStationCode() + "无效");
// backflushDetailbQadDO.setStatus(2);// 失败
// continue;
// } else {
// throw exception(WORKSTATION_RELATION_ERROR, "车间" + productreceiptRecordMainDO.getWorkshopCode() + "生产线" + productreceiptRecordDetailDO.getProductionlineCode() + "工位" + productreceiptRecordDetailDO.getWorkStationCode() + "无效");
// }
// }
// productreceiptRecordDetailbDO.setFromLocationCode(workstationDO.getRawLocationCode());
// // 查询 管理精度 根据不同管理精度进行消耗
// String manageMode = jobUtils.getManageMode(productreceiptRecordDetailbDO.getItemCode(), workstationDO.getRawLocationCode());
// // 按数量管理
// if ("BY_QUANTITY".equals(manageMode)) {
// // 根据 from_location_code 查询库存余额
//// TODO: 如果按批次 查询批次获取库存余额 排序批次 如果第一条批次不够数量 需要扣除第二条余额 库存事务出的动作要存2条
// List<String> inventoryStatus = new ArrayList<>();
// inventoryStatus.add("OK");
// BalanceDO balanceDO = balanceService.checkBalanceNotError(productreceiptRecordDetailbDO.getPackingNumber(), productreceiptRecordDetailbDO.getItemCode(), productreceiptRecordDetailbDO.getBatch(), "OK", workstationDO.getRawLocationCode());
// if (balanceDO != null) {
// productreceiptRecordDetailbDO.setPackingNumber(balanceDO.getPackingNumber());
// productreceiptRecordDetailbDO.setBatch(balanceDO.getBatch());
// productreceiptRecordDetailbDO.setInventoryStatus(InventoryStatusEnum.OK.getCode());
// productreceiptRecordDetailbDO.setFromAreaCode(balanceDO.getAreaCode());
// productreceiptRecordDetailbDO.setFromLocationGroupCode(balanceDO.getLocationGroupCode());
// //添加库存事务list
// // 出动作
// TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO();
// BeanUtils.copyProperties(productreceiptRecordDetailbDO, transactionCreateReqVO);
// BusinesstypeDO businesstypeDO = businesstypeService.selectBusinesstypeExist(productreceiptRecordMainDO.getBusinessType());
// TransactiontypeDO transactiontypeDO = jobUtils.selectDocumentFromTransactionType(businesstypeDO.getOutTransactionType());
// transactionCreateReqVO.setWorker(productreceiptRecordMainDO.getCreator());
// transactionCreateReqVO.setInventoryAction(transactiontypeDO.getInventoryAction());
// transactionCreateReqVO.setTransactionType(transactiontypeDO.getCode());
// transactionCreateReqVO.setBusinessType(businesstypeDO.getCode());
// transactionCreateReqVO.setOwnerCode("");
// transactionCreateReqVO.setRecordNumber(productreceiptRecordDetailbDO.getNumber());
// transactionCreateReqVO.setId(null);
// transactionCreateReqVO.setPackingNumber(productreceiptRecordDetailbDO.getPackingNumber());
// transactionCreateReqVO.setBatch(productreceiptRecordDetailbDO.getBatch());
// transactionCreateReqVO.setContainerNumber("");
// transactionCreateReqVO.setSinglePrice(balanceDO.getSinglePrice());
// transactionCreateReqVO.setWarehouseCode(balanceDO.getWarehouseCode());
// transactionCreateReqVO.setAmount(balanceDO.getAmount());
// transactionCreateReqVO.setDeptId(productreceiptRecordMainDO.getDepartmentCode());
// transactionCreateReqVO.setUserId(Long.valueOf(productreceiptRecordMainDO.getCreator()));
// if (balanceDO.getArriveDate() == null) {
// transactionCreateReqVO.setArriveDate(LocalDateTime.now());
// } else {
// transactionCreateReqVO.setArriveDate(balanceDO.getArriveDate());
// }
// if (balanceDO.getProduceDate() == null) {
// transactionCreateReqVO.setProduceDate(LocalDateTime.now());
// } else {
// transactionCreateReqVO.setProduceDate(balanceDO.getProduceDate());
// }
// transactionCreateReqVO.setExpireDate(balanceDO.getExpireDate());
// transactionCreateReqVO.setActiveTime(LocalDateTime.now());
// transactionCreateReqVO.setLocationCode(productreceiptRecordDetailbDO.getFromLocationCode());
// transactionCreateReqVO.setQty(productreceiptRecordDetailbDO.getQty());
// // 根据 库位 获取 库区DO
// AreabasicDO areabasicDOOut = jobUtils.getAreabasicDO(transactionCreateReqVO.getLocationCode());
// transactionCreateReqVO.setWarehouseCode(areabasicDOOut.getWarehouseCode());
// transactionCreateReqVO.setAreaType(areabasicDOOut.getType());
// transactionCreateReqVO.setAreaCode(areabasicDOOut.getCode());
//// transactionCreateReqVO.setPackUnit(jobUtils.getItemareaDO(productreceiptRecordDetailbDO.getItemCode(), areabasicDOOut.getCode()).getOutPackUnit());
//// transactionCreateReqVO.setPackQty(jobUtils.getItempackageDO(productreceiptRecordDetailbDO.getItemCode(),transactionCreateReqVO.getPackUnit()).getPackQty());
// transactionCreateReqVO.setPackUnit(null);
// transactionCreateReqVO.setPackQty(BigDecimal.ZERO);
// transactionCreateReqVOList.add(transactionCreateReqVO);
// } else {
// // 增加负库存逻辑
// ItemareaDO itemareaDOByLocationCode = jobUtils.getItemareaDOByLocationCode(productreceiptRecordDetailbDO.getItemCode(), workstationDO.getRawLocationCode());
// productreceiptRecordDetailbDO.setPackingNumber(null);
// productreceiptRecordDetailbDO.setBatch("");
// productreceiptRecordDetailbDO.setInventoryStatus(InventoryStatusEnum.OK.getCode());
// productreceiptRecordDetailbDO.setFromAreaCode(itemareaDOByLocationCode.getAreaCode());
// QueryWrapper<LocationDO> queryWrapperLocationDO = new QueryWrapper<>();
// queryWrapperLocationDO.eq("code", workstationDO.getRawLocationCode());
// queryWrapperLocationDO.eq("available", "TRUE");
// LocationDO locationDO = locationMapper.selectOne(queryWrapperLocationDO);
// productreceiptRecordDetailbDO.setFromLocationGroupCode(locationDO.getLocationGroupCode());
// //添加库存事务list
// // 出动作
// TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO();
// BeanUtils.copyProperties(productreceiptRecordDetailbDO, transactionCreateReqVO);
// BusinesstypeDO businesstypeDO = businesstypeService.selectBusinesstypeExist(productreceiptRecordMainDO.getBusinessType());
// TransactiontypeDO transactiontypeDO = jobUtils.selectDocumentFromTransactionType(businesstypeDO.getOutTransactionType());
// transactionCreateReqVO.setWorker(productreceiptRecordMainDO.getCreator());
// transactionCreateReqVO.setInventoryAction(transactiontypeDO.getInventoryAction());
// transactionCreateReqVO.setTransactionType(transactiontypeDO.getCode());
// transactionCreateReqVO.setBusinessType(businesstypeDO.getCode());
// transactionCreateReqVO.setOwnerCode("");
// transactionCreateReqVO.setRecordNumber(productreceiptRecordDetailbDO.getNumber());
// transactionCreateReqVO.setId(null);
// transactionCreateReqVO.setPackingNumber(productreceiptRecordDetailbDO.getPackingNumber());
// transactionCreateReqVO.setBatch(productreceiptRecordDetailbDO.getBatch());
// transactionCreateReqVO.setContainerNumber("");
// transactionCreateReqVO.setSinglePrice(BigDecimal.ZERO);
// transactionCreateReqVO.setAmount(BigDecimal.ZERO);
// transactionCreateReqVO.setArriveDate(LocalDateTime.now());
// transactionCreateReqVO.setProduceDate(LocalDateTime.now());
// transactionCreateReqVO.setExpireDate(LocalDateTimeUtils.max());
// transactionCreateReqVO.setActiveTime(LocalDateTime.now());
// transactionCreateReqVO.setLocationCode(productreceiptRecordDetailbDO.getFromLocationCode());
// transactionCreateReqVO.setDeptId(productreceiptRecordMainDO.getDepartmentCode());
// transactionCreateReqVO.setUserId(Long.valueOf(productreceiptRecordMainDO.getCreator()));
//
// LocationDO fromLocationCode = locationService.queryByCode(productreceiptRecordDetailbDO.getFromLocationCode());
// if (fromLocationCode != null) {
// transactionCreateReqVO.setLocationGroupCode(fromLocationCode.getLocationGroupCode());
// transactionCreateReqVO.setAreaCode(fromLocationCode.getAreaCode());
// transactionCreateReqVO.setWarehouseCode(fromLocationCode.getWarehouseCode());
// }
// transactionCreateReqVO.setQty(productreceiptRecordDetailbDO.getQty());
// // 根据 库位 获取 库区DO
// AreabasicDO areabasicDOOut = jobUtils.getAreabasicDO(transactionCreateReqVO.getLocationCode());
// transactionCreateReqVO.setWarehouseCode(areabasicDOOut.getWarehouseCode());
// transactionCreateReqVO.setAreaType(areabasicDOOut.getType());
// transactionCreateReqVO.setAreaCode(areabasicDOOut.getCode());
//// transactionCreateReqVO.setPackUnit(jobUtils.getItemareaDO(productreceiptRecordDetailbDO.getItemCode(), areabasicDOOut.getCode()).getOutPackUnit());
//// transactionCreateReqVO.setPackQty(jobUtils.getItempackageDO(productreceiptRecordDetailbDO.getItemCode(),transactionCreateReqVO.getPackUnit()).getPackQty());
// transactionCreateReqVO.setPackUnit(null);
// transactionCreateReqVO.setPackQty(BigDecimal.ZERO);
// transactionCreateReqVOList.add(transactionCreateReqVO);
// }
// }
// // 按批次管理
// if ("BY_BATCH".equals(manageMode)) {
// LambdaQueryWrapper<BalanceDO> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(BalanceDO::getPackingNumber, "")
// .eq(BalanceDO::getItemCode, productreceiptRecordDetailbDO.getItemCode())
// .eq(BalanceDO::getInventoryStatus, "OK")
// .eq(BalanceDO::getLocationCode, workstationDO.getRawLocationCode())
// .eq(BalanceDO::getFrozen, "FALSE")
// .gt(BalanceDO::getExpireDate, LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_FORMATTER))
// .orderByAsc(BalanceDO::getBatch)
// .orderByDesc(BalanceDO::getQty);
// List<BalanceDO> balanceDOList = balanceMapper.selectList(queryWrapper);
// if (!CollectionUtils.isAnyEmpty(balanceDOList)) {
// // throw exception(BALANCE_EXCEPTION,"库存余额不足");
// BigDecimal totalQty = productreceiptRecordDetailbDO.getQty();
// boolean flag = false;
// for (BalanceDO balanceDO : balanceDOList) {
// productreceiptRecordDetailbDO.setPackingNumber(balanceDO.getPackingNumber());
// productreceiptRecordDetailbDO.setBatch(balanceDO.getBatch());
// productreceiptRecordDetailbDO.setInventoryStatus(InventoryStatusEnum.OK.getCode());
// productreceiptRecordDetailbDO.setFromAreaCode(balanceDO.getAreaCode());
// productreceiptRecordDetailbDO.setFromLocationGroupCode(balanceDO.getLocationGroupCode());
// // 出动作
// TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO();
// BeanUtils.copyProperties(productreceiptRecordDetailbDO, transactionCreateReqVO);
// BusinesstypeDO businesstypeDO = businesstypeService.selectBusinesstypeExist(productreceiptRecordMainDO.getBusinessType());
// TransactiontypeDO transactiontypeDO = jobUtils.selectDocumentFromTransactionType(businesstypeDO.getOutTransactionType());
// transactionCreateReqVO.setWorker(productreceiptRecordMainDO.getCreator());
// transactionCreateReqVO.setInventoryAction(transactiontypeDO.getInventoryAction());
// transactionCreateReqVO.setTransactionType(transactiontypeDO.getCode());
// transactionCreateReqVO.setBusinessType(businesstypeDO.getCode());
// transactionCreateReqVO.setOwnerCode("");
// transactionCreateReqVO.setRecordNumber(productreceiptRecordDetailbDO.getNumber());
// transactionCreateReqVO.setId(null);
// transactionCreateReqVO.setPackingNumber(productreceiptRecordDetailbDO.getPackingNumber());
// transactionCreateReqVO.setBatch(productreceiptRecordDetailbDO.getBatch());
// transactionCreateReqVO.setContainerNumber("");
// transactionCreateReqVO.setSinglePrice(balanceDO.getSinglePrice());
// transactionCreateReqVO.setAmount(balanceDO.getAmount());
// transactionCreateReqVO.setDeptId(productreceiptRecordMainDO.getDepartmentCode());
// transactionCreateReqVO.setUserId(Long.valueOf(productreceiptRecordMainDO.getCreator()));
// if (balanceDO.getArriveDate() == null) {
// transactionCreateReqVO.setArriveDate(LocalDateTime.now());
// } else {
// transactionCreateReqVO.setArriveDate(balanceDO.getArriveDate());
// }
// if (balanceDO.getProduceDate() == null) {
// transactionCreateReqVO.setProduceDate(LocalDateTime.now());
// } else {
// transactionCreateReqVO.setProduceDate(balanceDO.getProduceDate());
// }
// transactionCreateReqVO.setExpireDate(balanceDO.getExpireDate());
// transactionCreateReqVO.setActiveTime(LocalDateTime.now());
// transactionCreateReqVO.setLocationCode(productreceiptRecordDetailbDO.getFromLocationCode());
//
// // 根据 库位 获取 库区DO
// AreabasicDO areabasicDOOut = jobUtils.getAreabasicDO(transactionCreateReqVO.getLocationCode());
// transactionCreateReqVO.setWarehouseCode(areabasicDOOut.getWarehouseCode());
// transactionCreateReqVO.setAreaType(areabasicDOOut.getType());
// LocationDO fromLocationCode = locationService.queryByCode(transactionCreateReqVO.getLocationCode());
// if (fromLocationCode != null) {
// transactionCreateReqVO.setLocationGroupCode(fromLocationCode.getLocationGroupCode());
// transactionCreateReqVO.setAreaCode(fromLocationCode.getAreaCode());
// transactionCreateReqVO.setWarehouseCode(fromLocationCode.getWarehouseCode());
// }
// transactionCreateReqVO.setPackUnit(null);
// transactionCreateReqVO.setPackQty(BigDecimal.ZERO);
// transactionCreateReqVO.setSiteId(productreceiptRecordDetailbDO.getSiteId());
// if (balanceDO.getQty().compareTo(BigDecimal.ZERO) == 0) {
// continue;
// }
// // 判断 库存余额数量是整数还是负数
// if (balanceDO.getQty().compareTo(BigDecimal.ZERO) < 0) {
// // 库存余额是负数
// // 则此时库存应该负的更多
// // 正常情况下负库存只有99999999的批次
// if (balanceDO.getBatch().equals("99999999")) {
// transactionCreateReqVO.setQty(totalQty);
// transactionCreateReqVOList.add(transactionCreateReqVO);
// flag = true;
// break;
// }
// } else {
// // 库存余额是正数
// if (totalQty.compareTo(balanceDO.getQty()) > 0) {
// // 消耗数量 大于 库存数量 10 -3 =7
// totalQty = totalQty.subtract(balanceDO.getQty());
// transactionCreateReqVO.setQty(balanceDO.getQty());
// transactionCreateReqVOList.add(transactionCreateReqVO);
// } else {
// // 消耗数量 小于 库存
// transactionCreateReqVO.setQty(totalQty);
// transactionCreateReqVOList.add(transactionCreateReqVO);
// flag = true;
// break;
// }
// }
// }
// if (totalQty.compareTo(BigDecimal.ZERO) > 0 && !flag) { //所有的库存余额依然 不够 消耗的数量,生成一个负库存
// // 增加负库存数据场景
// increaseNegativeInventory(productreceiptRecordMainDO, transactionCreateReqVOList, productreceiptRecordDetailbDO, workstationDO, totalQty);
// }
// } else {
// // 增加负库存数据场景
// increaseNegativeInventory(productreceiptRecordMainDO, transactionCreateReqVOList, productreceiptRecordDetailbDO, workstationDO, BigDecimal.ZERO);
// }
// }
// // 按包装管理
// if ("BY_PACKAGING".equals(manageMode)) {
// throw exception(BALANCE_EXCEPTION, "物料:" + productreceiptRecordDetailbDO.getItemCode() + " 库位:" + workstationDO.getRawLocationCode() + " 暂不支持按包装管理");
// }
// // 按唯一码管理
// if ("BY_UNIQUE_ID".equals(manageMode)) {
// throw exception(BALANCE_EXCEPTION, "暂不支持按唯一码管理");
// }
// // 判断 物料 是否为 下线结算物料 创建 下线结算记录
// if (itembasicService.isOfflines(productreceiptRecordDetailbDO.getItemCode())) {
// offlinesettlementRecordList.add(productreceiptRecordDetailbDO);
// }
// productreceiptRequestDetailbDOList.add(productreceiptRecordDetailbDO);
// backflushDetailbQadDO.setStatus(1);
// }
// productreceiptRecordDetailbMapper.insertBatch(productreceiptRequestDetailbDOList);
// //增加库存事务
// if (transactionCreateReqVOList != null && transactionCreateReqVOList.size() > 0) {
// transactionService.createTransaction(transactionCreateReqVOList);
// }
// // 更新 qad 状态
// if (auto) {
// backflushDetailbQadMapper.updateBatch(backflushDetailbQadDOListNumber);
// }
// // 创建 下线结算记录
// if (offlinesettlementRecordList != null && !offlinesettlementRecordList.isEmpty()) {
// generateOfflinesettlementRecord(productreceiptRecordMainDO, offlinesettlementRecordList);
// }
// }
//
// private void generateProductredressTransaction(String number, String parentItemCode, List<BackflushDetailbQadDO> backflushDetailbQadDOListNumber) {
//
// ProductredressRecordMainDO productredressRecordMainDO = productredressRecordMainMapper.selectOne("number", number);
// if (productredressRecordMainDO == null) {
// if (auto) {
// for (BackflushDetailbQadDO backflushDetailbQadDO : backflushDetailbQadDOListNumber) {
// backflushDetailbQadDO.setRemark("未查询到回收记录 单据号:" + number);
// backflushDetailbQadDO.setStatus(2);// 失败
// }
// // 更新 qad 状态
// backflushDetailbQadMapper.updateBatch(backflushDetailbQadDOListNumber);
// return;
// } else {
// throw exception(PRODUCTREDRESS_RECORD_MAIN_NOT_EXISTS, "单据号:" + number);
// }
// }
// List<ProductredressRecordDetailDO> productredressRecordDetailDOList = productredressRecordDetailMapper.selectList("master_id", productredressRecordMainDO.getId(), "item_code", parentItemCode);
// if (productredressRecordDetailDOList == null || productredressRecordDetailDOList.size() == 0) {
// if (auto) {
// for (BackflushDetailbQadDO backflushDetailbQadDO : backflushDetailbQadDOListNumber) {
// backflushDetailbQadDO.setRemark("未查询到回收记录 物料:" + parentItemCode + " ;单据号:" + number);
// backflushDetailbQadDO.setStatus(2);// 失败
// }
// // 更新 qad 状态
// backflushDetailbQadMapper.updateBatch(backflushDetailbQadDOListNumber);
// return;
// } else {
// throw exception(PRODUCTREDRESS_RECORD_DETAIL_NOT_EXISTS, "单据号:" + number + " 物料:" + parentItemCode);
// }
// }
// ProductredressRecordDetailDO productredressRecordDetailDO = productredressRecordDetailDOList.get(0);
// // 增加业务类型
// BusinesstypeDO businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("ProductredressRecord", "制品回收记录");
// // 查询制品收货子表:回冲记录子表 record_backflush_detailb
// // 查询 制品收货记录 子表 —— 按照 物料代码 箱码 批次 库位 查询制品收货记录子表 对应数据
// QueryWrapper<ProductreceiptRecordDetailDO> productreceiptRecordDetailMapperQueryWrapper = new QueryWrapper<>();
// productreceiptRecordDetailMapperQueryWrapper.eq("item_code", productredressRecordDetailDO.getItemCode());
// productreceiptRecordDetailMapperQueryWrapper.eq("packing_number", productredressRecordDetailDO.getPackingNumber());
// productreceiptRecordDetailMapperQueryWrapper.eq("batch", productredressRecordDetailDO.getBatch());
// // productreceiptRecordDetailMapperQueryWrapper.eq("to_location_code",productredressRecordDetailDO.getToLocationCode());
// List<ProductreceiptRecordDetailDO> productreceiptRecordDetailDOList = productreceiptRecordDetailMapper.selectList(productreceiptRecordDetailMapperQueryWrapper);
// if (productreceiptRecordDetailDOList == null || productreceiptRecordDetailDOList.size() == 0) {
// if (auto) {
// for (BackflushDetailbQadDO backflushDetailbQadDO : backflushDetailbQadDOListNumber) {
// backflushDetailbQadDO.setRemark("未查询到收货记录子 物料:" + productredressRecordDetailDO.getItemCode() + " ;包装号:" + productredressRecordDetailDO.getPackingNumber() + ";批次:" + productredressRecordDetailDO.getBatch());
// backflushDetailbQadDO.setStatus(2);// 失败
// }
// // 更新 qad 状态
// backflushDetailbQadMapper.updateBatch(backflushDetailbQadDOListNumber);
// return;
// } else {
// throw exception(PRODUCTREDRESS_RECORD_DETAIL_NOT_EXISTS);
// }
// }
// // 查询 制品收货子子表 —— 按照 收货记录子表id
// QueryWrapper<ProductreceiptRecordDetailbDO> productreceiptRecordDetailbDOQueryWrapper = new QueryWrapper<>();
// productreceiptRecordDetailbDOQueryWrapper.eq("master_id", productreceiptRecordDetailDOList.get(0).getId());
// List<ProductreceiptRecordDetailbDO> productreceiptRecordDetailbDOList = productreceiptRecordDetailbMapper.selectList(productreceiptRecordDetailbDOQueryWrapper);
// TransactiontypeDO transactiontypeDOIN = jobUtils.selectDocumentFromTransactionType(businesstypeDO.getInTransactionType());
// // 库存事务
// List<TransactionCreateReqVO> transactionCreateReqVOList = new ArrayList<>();
// for (BackflushDetailbQadDO backflushDetailbQadDO : backflushDetailbQadDOListNumber) {
//
//// List<ProductreceiptRecordDetailbDO> filteredList = productreceiptRecordDetailbDOList.stream()
//// .filter(detail -> backflushDetailbQadDO.getItemCode().equals(detail.getItemCode()))
//// .collect(Collectors.toList());
//
// // 匹配 收货记录子子表与当地QAD回传数据 无匹配 批次为8个0
// List<ProductreceiptRecordDetailbDO> filteredList = new ArrayList<>();
// for (ProductreceiptRecordDetailbDO productreceiptRecordDetailbDO : productreceiptRecordDetailbDOList) {
// if (backflushDetailbQadDO.getItemCode().equals(productreceiptRecordDetailbDO.getItemCode())) {
// filteredList.add(productreceiptRecordDetailbDO);
// }
// }
//
// ProductreceiptRecordDetailbDO productreceiptRecordDetailbDO;
// // 当QAD回传数据大于收货消耗数据时 插入8个0批次的库存
// String batch = "";
// if (filteredList == null || filteredList.size() == 0) {
// // 没有匹配的收货消耗时,获取集合第一条
// if (productreceiptRecordDetailbDOList == null || productreceiptRecordDetailbDOList.size() == 0) {
// backflushDetailbQadDO.setRemark("未查询到消耗记录 主表ID:" + productreceiptRecordDetailDOList.get(0).getId());
// backflushDetailbQadDO.setStatus(2);// 失败
// continue;
// }
// productreceiptRecordDetailbDO = productreceiptRecordDetailbDOList.get(0);
// batch = "00000000";
// } else {
// productreceiptRecordDetailbDO = filteredList.get(0);
// batch = productreceiptRecordDetailbDO.getBatch();
// }
//
// // 消耗的原材料 入动作
// TransactionCreateReqVO transactionCreateReqVOIN = new TransactionCreateReqVO();
// BeanUtils.copyProperties(productreceiptRecordDetailbDO, transactionCreateReqVOIN);
// transactionCreateReqVOIN.setItemCode(backflushDetailbQadDO.getItemCode());
// transactionCreateReqVOIN.setLocationGroupCode(productreceiptRecordDetailbDO.getFromLocationGroupCode());
// transactionCreateReqVOIN.setWorker(productredressRecordMainDO.getCreator());
// transactionCreateReqVOIN.setInventoryAction(transactiontypeDOIN.getInventoryAction());
// transactionCreateReqVOIN.setTransactionType(transactiontypeDOIN.getCode());
// transactionCreateReqVOIN.setBusinessType(productredressRecordMainDO.getBusinessType());
// transactionCreateReqVOIN.setOwnerCode("");
// transactionCreateReqVOIN.setRecordNumber(number);
// transactionCreateReqVOIN.setId(null);
// transactionCreateReqVOIN.setPackingNumber(productreceiptRecordDetailbDO.getPackingNumber());
// transactionCreateReqVOIN.setBatch(batch);
// transactionCreateReqVOIN.setContainerNumber("");
// transactionCreateReqVOIN.setAmount(BigDecimal.ZERO);
// transactionCreateReqVOIN.setQty(backflushDetailbQadDO.getQty().abs());
// transactionCreateReqVOIN.setDeptId(productredressRecordMainDO.getDepartmentCode());
// transactionCreateReqVOIN.setUserId(Long.valueOf(productredressRecordMainDO.getCreator()));
// //工位库位
// transactionCreateReqVOIN.setLocationCode(productreceiptRecordDetailbDO.getFromLocationCode());
// // 根据 库位 获取 库区DO
// AreabasicDO areabasicDOIN = jobUtils.getAreabasicDO(transactionCreateReqVOIN.getLocationCode());
// transactionCreateReqVOIN.setWarehouseCode(areabasicDOIN.getWarehouseCode());
// transactionCreateReqVOIN.setAreaType(areabasicDOIN.getType());
// transactionCreateReqVOIN.setPackQty(new BigDecimal(0));
// transactionCreateReqVOIN.setPackUnit(null);
// transactionCreateReqVOIN.setSiteId(productreceiptRecordDetailbDO.getSiteId());
// transactionCreateReqVOList.add(transactionCreateReqVOIN);
// backflushDetailbQadDO.setStatus(1);
// }
//
// // 20240803 cxm 回收子子物料 根据包装号更新ProductreceiptDetailbDO mes绑定表中 is_return 释放唯一码 保证下次唯一码能再次使用
// List<ProductreceiptDetailbDO> productreceiptDetailbDOList = productreceiptDetailbMapper.selectList("packing_number", productredressRecordDetailDO.getPackingNumber());
// if (!org.springframework.util.CollectionUtils.isEmpty(productreceiptDetailbDOList)) {
// for (ProductreceiptDetailbDO productreceiptDetailbDO : productreceiptDetailbDOList) {
// productreceiptDetailbDO.setIsReturn("TRUE");
// }
// productreceiptDetailbMapper.updateBatch(productreceiptDetailbDOList);
// }
// // 增加库存事务
// if (transactionCreateReqVOList != null && transactionCreateReqVOList.size() > 0) {
// transactionService.createTransaction(transactionCreateReqVOList);
// }
// // 更新 qad 状态
// if (auto) {
// backflushDetailbQadMapper.updateBatch(backflushDetailbQadDOListNumber);
// }
// }
}