钣金计划:优化bomline匹配库存和子单信息,改为批量保存
| | |
| | | public int deleteApsPlateStandardRequireBomOrderDetailByIds(Long[] ids); |
| | | |
| | | int deleteLastPatch(String batchNumber); |
| | | |
| | | int batchInsert(List<ApsPlateStandardRequireBomOrderDetail> list); |
| | | } |
| | |
| | | package com.aps.core.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.aps.core.domain.ApsPlateStandardRequireBomOrderDetail; |
| | | import com.aps.core.domain.ApsPlateStandardRequireBomStockDetail; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | |
| | | public int deleteApsPlateStandardRequireBomStockDetailByIds(Long[] ids); |
| | | |
| | | int deleteLastPatch(String batchNumber); |
| | | |
| | | int batchInsert(List<ApsPlateStandardRequireBomStockDetail> list); |
| | | } |
| | |
| | | */ |
| | | public int deleteApsPlateStandardRequireBomOrderDetailById(Long id); |
| | | |
| | | void savePlastPlanAndBomOrderDetail(ApsPlateStandardRequire require, ApsPlatePlan platePlan, BigDecimal subtract, BigDecimal stock, BigDecimal netRequirement); |
| | | void savePlastPlanAndBomOrderDetail(ApsPlateStandardRequire require, ApsPlatePlan platePlan, BigDecimal subtract |
| | | , BigDecimal stock, BigDecimal netRequirement, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList |
| | | ); |
| | | } |
| | |
| | | */ |
| | | public int deleteApsPlateStandardRequireBomStockDetailById(Long id); |
| | | |
| | | void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, String bomLineId,String itemCode, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId); |
| | | void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, String bomLineId |
| | | ,String itemCode, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId |
| | | , List<ApsPlateStandardRequireBomStockDetail> stockDetailsList |
| | | ); |
| | | } |
| | |
| | | } |
| | | @Transactional |
| | | @Override |
| | | public void savePlastPlanAndBomOrderDetail(ApsPlateStandardRequire require, ApsPlatePlan platePlan, BigDecimal subtract, BigDecimal stock, BigDecimal netRequirement) { |
| | | public void savePlastPlanAndBomOrderDetail(ApsPlateStandardRequire require, ApsPlatePlan platePlan, BigDecimal subtract |
| | | , BigDecimal stock, BigDecimal netRequirement, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList) { |
| | | platePlan.setUnmatchedQuantity(subtract); |
| | | apsPlatePlanMapper.updatePlanUnMatchQtyByVersion(platePlan); |
| | | /* 记录工单与净需求的匹配关系*/ |
| | |
| | | .build(); |
| | | bomOrderDetail.setCreateTime(DateUtils.getNowDate()); |
| | | bomOrderDetail.setCreateBy(SecurityUtils.getUsername()); |
| | | apsPlateStandardRequireBomOrderDetailMapper.insertApsPlateStandardRequireBomOrderDetail(bomOrderDetail); |
| | | |
| | | orderDetailsList.add(bomOrderDetail); |
| | | // apsPlateStandardRequireBomOrderDetailMapper.insertApsPlateStandardRequireBomOrderDetail(bomOrderDetail); |
| | | } |
| | | } |
| | |
| | | * */ |
| | | @Transactional |
| | | @Override |
| | | public void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, String bomLineId,String itemCode, String batchNum, BigDecimal deductionAmount, BigDecimal afterStockAmount,Long requireId){ |
| | | public void saveStorageAndDetail(ApsMaterialStorageManagement itemStorage, ApsPlatePlan plan, String bomLineId, |
| | | String itemCode, String batchNum, BigDecimal deductionAmount, |
| | | BigDecimal afterStockAmount,Long requireId |
| | | ,List<ApsPlateStandardRequireBomStockDetail> stockDetailsList){ |
| | | /*更新物料剩余库存*/ |
| | | itemStorageMapper.updateMaterialStorageByVersion(itemStorage.getId(), afterStockAmount,itemStorage.getVersion()); |
| | | /*记录扣减明细*/ |
| | |
| | | bomStockDetail.setCreateBy(SecurityUtils.getUsername()); |
| | | bomStockDetail.setCreateTime(DateUtils.getNowDate()); |
| | | |
| | | plateBomStockDetailMapper.insertApsPlateStandardRequireBomStockDetail(bomStockDetail); |
| | | stockDetailsList.add(bomStockDetail); |
| | | //plateBomStockDetailMapper.insertApsPlateStandardRequireBomStockDetail(bomStockDetail); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | @Resource |
| | | IApsPlateStandardRequireBatchService requireBatchService; |
| | | @Autowired |
| | | private ApsPlateStandardRequireBomStockDetailMapper apsPlateStandardRequireBomStockDetailMapper; |
| | | |
| | | /** |
| | | * 查询钣金工单标准需求 |
| | |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | |
| | | List<ApsPlateStandardRequire> requiresList=new ArrayList<>(); |
| | | |
| | | getBomRequires(plantCode, "0","0",itemNumber,BigDecimal.ONE, batchNum, null, mainPlan, requiresList, 0L); |
| | | List<ApsPlateStandardRequireBomStockDetail> stockDetailsList=new ArrayList<>(); |
| | | List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList=new ArrayList<>(); |
| | | getBomRequires(plantCode, "0","0",itemNumber,BigDecimal.ONE, batchNum, null, mainPlan, requiresList, 0L,stockDetailsList,orderDetailsList); |
| | | |
| | | // 批量插入以提高性能 |
| | | if (!requiresList.isEmpty()) { |
| | |
| | | int end = Math.min(i + batchSize, requiresList.size()); |
| | | List<ApsPlateStandardRequire> batch = requiresList.subList(i, end); |
| | | apsPlateStandardRequireMapper.batchInsert(batch); |
| | | } |
| | | } |
| | | |
| | | if(!stockDetailsList.isEmpty()){ |
| | | int batchSize = 1000; |
| | | for (int i = 0; i < stockDetailsList.size(); i += batchSize) { |
| | | int end = Math.min(i + batchSize, stockDetailsList.size()); |
| | | List<ApsPlateStandardRequireBomStockDetail> batch = stockDetailsList.subList(i, end); |
| | | plateBomStockDetailMapper.batchInsert(batch); |
| | | } |
| | | } |
| | | |
| | | if(!orderDetailsList.isEmpty()){ |
| | | int batchSize = 1000; |
| | | for (int i = 0; i < orderDetailsList.size(); i += batchSize) { |
| | | int end = Math.min(i + batchSize, orderDetailsList.size()); |
| | | List<ApsPlateStandardRequireBomOrderDetail> batch = orderDetailsList.subList(i, end); |
| | | plateBomOrderDetailMapper.batchInsert(batch); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param allRequires 所有需求的列表 |
| | | * @param level 层级 |
| | | */ |
| | | private void getBomRequires(String plant, String bomHeaderCode, String bomLineId,String itemCode,BigDecimal itemNum, String batchNum, Date upLevelStartDate, ApsPlatePlan plan, List<ApsPlateStandardRequire> allRequires, Long level) { |
| | | private void getBomRequires(String plant, String bomHeaderCode, String bomLineId,String itemCode,BigDecimal itemNum, |
| | | String batchNum, Date upLevelStartDate, ApsPlatePlan plan, |
| | | List<ApsPlateStandardRequire> allRequires, |
| | | Long level,List<ApsPlateStandardRequireBomStockDetail> stockDetailsList |
| | | ,List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList |
| | | ) { |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | | require.setId(IdUtil.getSnowflakeNextId()); |
| | |
| | | require.setNetRequirement(BigDecimal.ZERO); |
| | | } |
| | | /*记录库存剩余数量,记录库存使用记录*/ |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLineId,itemCode, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLineId,itemCode, batchNum, deductionAmount, afterStockAmount,require.getId(),stockDetailsList); |
| | | } |
| | | } |
| | | /*未匹配数量,默认为净需求*/ |
| | |
| | | require.setMatchState("待匹配"); |
| | | require.setMatchMode("工单匹配"); |
| | | /*使用子件工单进行需求匹配*/ |
| | | matchRequireAndSubPlan(require); |
| | | matchRequireAndSubPlan(require,orderDetailsList); |
| | | } |
| | | allRequires.add(require); |
| | | if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { |
| | |
| | | List<ApsBom> bomLineList = bomLineService.selectRdsBomLineList(plant, itemCode); |
| | | if (!bomLineList.isEmpty()) { |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, itemCode, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum, require.getStartDate(), plan, allRequires, nextLevel); |
| | | getBomRequires(plant, itemCode, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum |
| | | , require.getStartDate(), plan, allRequires, nextLevel,stockDetailsList |
| | | ,orderDetailsList |
| | | ); |
| | | }); |
| | | } |
| | | } |
| | |
| | | * 使用子件工单匹配需求中的净需求 |
| | | * */ |
| | | |
| | | private void matchRequireAndSubPlan(ApsPlateStandardRequire require) { |
| | | private void matchRequireAndSubPlan(ApsPlateStandardRequire require, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList) { |
| | | BigDecimal netRequirement = require.getNetRequirement(); |
| | | require.setMatchMode("工单匹配"); |
| | | if (netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | |
| | | /* 库存数量 大于 净需求数量*/ |
| | | /* 净需求数量=0 ,子件工单未匹配数量= 库存-净需求*/ |
| | | BigDecimal subtract = stock.subtract(netRequirement); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList); |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setMatchState("已匹配"); |
| | | require.setUnmatchedDemandAmount(BigDecimal.ZERO); |
| | |
| | | /*净需求数量 == 库存数量*/ |
| | | |
| | | BigDecimal subtract = BigDecimal.ZERO; |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList); |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setMatchState("已匹配"); |
| | | require.setUnmatchedDemandAmount(BigDecimal.ZERO); |
| | |
| | | BigDecimal rest = netRequirement.subtract(stock); |
| | | require.setMatchState("匹配中"); |
| | | /*工单 未匹配数量为0 全部用于匹配需求*/ |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, BigDecimal.ZERO, stock, netRequirement); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, BigDecimal.ZERO, stock, netRequirement,orderDetailsList); |
| | | /*净需求未被满足,需要继续匹配*/ |
| | | platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | /*剩余净需求*/ |
| | |
| | | <update id="deleteLastPatch" parameterType="String"> |
| | | update aps_plate_standard_require_bom_order_detail set del_flag = '1' where batch_number = #{batchNumber} |
| | | </update> |
| | | |
| | | <insert id="batchInsert" parameterType="ApsPlateStandardRequireBomOrderDetail"> |
| | | insert into aps_plate_standard_require_bom_order_detail |
| | | (id, require_id,require_track_id, bom_line_id, bom_line_code, doc_no, |
| | | before_prod_amount, deduction_amount, after_prod_amount, |
| | | org_code, batch_number, del_flag, create_time, create_by,) |
| | | values |
| | | <foreach collection="list" item="item" index="index" separator=","> |
| | | (#{item.id}, #{item.requireId},#{item.requireTrackId}, #{item.bomLineId}, #{item.bomLineCode}, #{item.docNo}, |
| | | #{item.beforeProdAmount}, #{item.deductionAmount}, #{item.afterProdAmount}, |
| | | #{item.orgCode}, #{item.batchNumber}, #{item.delFlag}, #{item.createTime}, #{item.createBy},) |
| | | </foreach> |
| | | </insert> |
| | | </mapper> |
| | |
| | | <update id="deleteLastPatch" parameterType="String"> |
| | | update aps_plate_standard_require_bom_stock_detail set del_flag = '1' where batch_number = #{batchNumber} |
| | | </update> |
| | | |
| | | <insert id="batchInsert" parameterType="ApsPlateStandardRequireBomStockDetail"> |
| | | insert into aps_plate_standard_require_bom_stock_detail |
| | | (id,require_id, require_track_id, bom_line_id, bom_line_code, before_stock_amount, deduction_amount |
| | | , after_stock_amount, org_code, batch_number, del_flag, create_time, create_by) |
| | | values |
| | | <foreach item="item" index="index" collection="list" separator=","> |
| | | ( #{id}, #{item.requireId}, #{item.requireTrackId}, #{item.bomLineId}, #{item.bomLineCode} |
| | | , #{item.beforeStockAmount} , #{item.deductionAmount}, #{item.afterStockAmount}, #{item.orgCode} |
| | | , #{item.batchNumber} , #{item.delFlag}, #{item.createTime}, #{item.createBy} |
| | | ) |
| | | </foreach> |
| | | </insert> |
| | | </mapper> |