aps-modules/aps-core/src/main/java/com/aps/core/mapper/ApsPlatePlanMapper.java
@@ -75,7 +75,7 @@ List<ApsPlatePlan> selectPlatePlanByPlantMajor(String plant,String professionalAffiliation); /** * 获取未匹配的子计划 * 获取一条未匹配的子计划 * */ ApsPlatePlan selectUnMatchPlateSubPlan(String plant,String itemNumber); @@ -88,4 +88,13 @@ * 初始化 子件工单的 未匹配数量 * */ int initUnMatchQty(); /** * 获取未匹配的子计划 * */ List<ApsPlatePlan> selectUnMatchPlateSubPlanList(String plant,String itemNumber); /** * 更新子件工单未匹配数量和版本 * */ int updatePlanUnMatchQtyAndVersion(ApsPlatePlan plan); } aps-modules/aps-core/src/main/java/com/aps/core/service/IApsPlatePlanService.java
@@ -4,6 +4,7 @@ import com.aps.core.domain.ApsPlatePlanTemp; import com.aps.core.domain.ApsPlateStandardRequire; import java.util.Hashtable; import java.util.List; /** @@ -81,5 +82,7 @@ */ public List<ApsPlatePlan> selectPlateRedundantOrderList(ApsPlatePlan apsPlatePlan); // ApsPlatePlan selectUnMatchPlateSubPlan(ApsPlateStandardRequire require); ApsPlatePlan selectUnMatchPlateSubPlan(String plant, String itemNumber, Hashtable<String, List<ApsPlatePlan>> subPlans); // ApsPlatePlan selectUnMatchPlateSubPlan(ApsPlateStandardRequire require); } aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java
@@ -1,15 +1,11 @@ package com.aps.core.service.impl; import cn.hutool.core.util.IdUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.aps.common.core.utils.DateUtils; import com.aps.common.core.utils.uuid.IdUtils; import com.aps.common.security.utils.DictUtils; import com.aps.core.domain.ApsMaterialStorageManagement; import com.aps.core.domain.ApsPlatePlan; import com.aps.core.domain.ApsPlatePlanTemp; import com.aps.core.domain.ApsPlateStandardRequire; import com.aps.core.mapper.ApsPartPlanTempMapper; import com.aps.core.mapper.ApsPlatePlanMapper; import com.aps.core.mapper.ApsPlatePlanTempMapper; @@ -18,9 +14,10 @@ import org.apache.logging.log4j.util.Strings; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.Hashtable; import java.util.List; import java.util.Optional; @@ -197,4 +194,21 @@ public List<ApsPlatePlan> selectPlateRedundantOrderList(ApsPlatePlan apsPlatePlan) { return apsPlatePlanMapper.selectPlateRedundantOrderList(apsPlatePlan); } @Override public ApsPlatePlan selectUnMatchPlateSubPlan(String plant, String itemNumber, Hashtable<String, List<ApsPlatePlan>> subPlans) { if(subPlans.containsKey(itemNumber)) { List<ApsPlatePlan> subPlanList = subPlans.get(itemNumber); Optional<ApsPlatePlan> firstPlant = subPlanList.stream().filter(x -> x.getUnmatchedQuantity().compareTo(BigDecimal.ZERO) > 0).findFirst(); return firstPlant.orElse(null); }else { List<ApsPlatePlan> plans = apsPlatePlanMapper.selectUnMatchPlateSubPlanList(plant, itemNumber); if (!plans.isEmpty()) { subPlans.put(itemNumber, plans); return selectUnMatchPlateSubPlan(plant, itemNumber, subPlans); } else { return null; } } } } aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireBomOrderDetailServiceImpl.java
@@ -107,7 +107,7 @@ public void savePlastPlanAndBomOrderDetail(ApsPlateStandardRequire require, ApsPlatePlan platePlan, BigDecimal subtract , BigDecimal stock, BigDecimal netRequirement, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList) { platePlan.setUnmatchedQuantity(subtract); apsPlatePlanMapper.updatePlanUnMatchQtyByVersion(platePlan); // apsPlatePlanMapper.updatePlanUnMatchQtyByVersion(platePlan); /* 记录工单与净需求的匹配关系*/ ApsPlateStandardRequireBomOrderDetail bomOrderDetail = ApsPlateStandardRequireBomOrderDetail.builder() .id(IdUtil.getSnowflakeNextId()) aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java
@@ -64,7 +64,7 @@ ApsPlateStandardRequireBomOrderDetailMapper plateBomOrderDetailMapper; @Autowired private ApsPlatePlanMapper apsPlatePlanMapper; private IApsPlatePlanService apsPlatePlanService; @Resource IApsPlateStandardRequireBomOrderDetailService bomOrderDetailService; @@ -176,19 +176,23 @@ /*获取钣金主单信息*/ List<ApsPlatePlan> mainPlans = platePlanMapper.selectPlatePlanByPlantMajor(plantCode,mainOrderType); Hashtable<String, ApsMaterialStorageManagement> usedStorage = new Hashtable<>(); /*内存中存储子件工单*/ Hashtable<String, List<ApsPlatePlan>> subPlans = new Hashtable<>(); log.info("开始生成需求:"); for (ApsPlatePlan mainPlan : mainPlans) { String itemNumber = mainPlan.getItemNumber(); /*根据料号 获取BOM Header */ /*当前Bom节点处理完成后,处理下级BOM*/ List<ApsPlateStandardRequire> requiresList=new ArrayList<>(); List<ApsPlateStandardRequireBomStockDetail> stockDetailsList=new ArrayList<>(); List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList=new ArrayList<>(); log.info("开始生成需求:工单号:"+mainPlan.getDocumentNumber()); /*当前Bom节点处理完成后,处理下级BOM*/ getBomRequires(plantCode, "0","0",itemNumber,BigDecimal.ONE, batchNum, null , mainPlan, requiresList, 0L,stockDetailsList,orderDetailsList,usedStorage , mainPlan, requiresList, 0L,stockDetailsList,orderDetailsList,usedStorage,subPlans ); // 批量插入以提高性能 @@ -225,6 +229,15 @@ storageManagementService.updateRemainderStock(sm.getId(),sm.getRemainderStock(),sm.getVersion()); }); } if(!subPlans.isEmpty()){ subPlans.forEach((key, subPlansList) -> { subPlansList.forEach(x->{ if (!x.getUnmatchedQuantity().equals(x.getProductionQuantity())){ platePlanMapper.updatePlanUnMatchQtyAndVersion(x); } }); }); } } /** @@ -248,7 +261,8 @@ List<ApsPlateStandardRequire> allRequires, Long level,List<ApsPlateStandardRequireBomStockDetail> stockDetailsList, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList, Hashtable<String, ApsMaterialStorageManagement> usedStorage Hashtable<String, ApsMaterialStorageManagement> usedStorage, Hashtable<String, List<ApsPlatePlan>> subPlans ) { /*构建需求信息*/ ApsPlateStandardRequire require = new ApsPlateStandardRequire(); @@ -367,7 +381,7 @@ if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { require.setMatchMode("工单匹配"); /*使用子件工单进行需求匹配*/ matchRequireAndSubPlan(require,orderDetailsList); matchRequireAndSubPlan(require,orderDetailsList,subPlans); } allRequires.add(require); log.info("已生成需求:"+plan.getDocumentNumber()+"bomHeaderCode:"+bomHeaderCode+"bomLineCode:"+itemCode+"bomLevel:"+level); @@ -379,7 +393,7 @@ bomLineList.forEach(line -> { getBomRequires(plant, itemCode, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum , require.getStartDate(), plan, allRequires, nextLevel,stockDetailsList ,orderDetailsList,usedStorage ,orderDetailsList,usedStorage,subPlans ); }); } @@ -403,12 +417,12 @@ * 使用子件工单匹配需求中的净需求 * */ private void matchRequireAndSubPlan(ApsPlateStandardRequire require, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList) { private void matchRequireAndSubPlan(ApsPlateStandardRequire require, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList,Hashtable<String, List<ApsPlatePlan>> subPlans) { BigDecimal netRequirement = require.getNetRequirement(); require.setMatchMode("工单匹配"); require.setMatchState("已匹配"); if (netRequirement.compareTo(BigDecimal.ZERO) > 0) { ApsPlatePlan platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); ApsPlatePlan platePlan = apsPlatePlanService.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode(),subPlans); /*子件工单的未匹配数量 作为当前的库存*/ while (platePlan != null && netRequirement.compareTo(BigDecimal.ZERO) > 0) { BigDecimal stock = platePlan.getUnmatchedQuantity(); @@ -416,6 +430,8 @@ /* 库存数量 大于 净需求数量*/ /* 净需求数量=0 ,子件工单未匹配数量= 库存-净需求*/ BigDecimal subtract = stock.subtract(netRequirement); platePlan.setUnmatchedQuantity(subtract); platePlan.setVersion(platePlan.getVersion() + 1); bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList); netRequirement = BigDecimal.ZERO; @@ -426,6 +442,8 @@ /*净需求数量 == 库存数量*/ BigDecimal subtract = BigDecimal.ZERO; platePlan.setUnmatchedQuantity(subtract); platePlan.setVersion(platePlan.getVersion() + 1); bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList); netRequirement = BigDecimal.ZERO; @@ -436,11 +454,12 @@ /*需求大于库存*/ /*净需求 被部分满足 */ BigDecimal rest = netRequirement.subtract(stock); platePlan.setUnmatchedQuantity(BigDecimal.ZERO); platePlan.setVersion(platePlan.getVersion() + 1); /*工单 未匹配数量为0 全部用于匹配需求*/ bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, BigDecimal.ZERO, stock, netRequirement,orderDetailsList); /*净需求未被满足,需要继续匹配*/ platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); platePlan = apsPlatePlanService.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode(),subPlans); /*剩余净需求*/ netRequirement = rest; require.setUnmatchedDemandAmount(rest); aps-modules/aps-core/src/main/resources/mapper/core/ApsPlatePlanMapper.xml
@@ -293,7 +293,15 @@ order by document_number asc,id asc limit 1 </select> <select id="selectUnMatchPlateSubPlanList" parameterType="com.aps.core.domain.ApsPlatePlan" resultMap="ApsPlatePlanResult"> select id,document_number,main_part_number,item_number,plant,professional_affiliation,production_quantity, unmatched_quantity,version from aps_plate_plan where del_flag='0' and professional_affiliation ='sub' and unmatched_quantity > 0 <if test="plant != null and plant !='' "> and plant = #{plant}</if> <if test="itemNumber != null and itemNumber !='' "> and item_number = #{itemNumber}</if> order by document_number asc,id asc </select> <update id="updatePlanUnMatchQtyByVersion" parameterType="com.aps.core.domain.ApsPlatePlan"> update aps_plate_plan @@ -316,4 +324,9 @@ set unmatched_quantity=production_quantity, version=0,require_id=id where del_flag='0' and professional_affiliation !='0' </update> <update id="updatePlanUnMatchQtyAndVersion" parameterType="com.aps.core.domain.ApsPlatePlan"> update aps_plate_plan set unmatched_quantity=#{unmatchedQuantity},version=#{version},update_time=now() where id=#{id} </update> </mapper>