| | |
| | | /*定义工厂为南通 */ |
| | | String plantCode="FORTUNA"; |
| | | /*定义主单类型为钣金主单*/ |
| | | String mainOrderType = "0"; |
| | | String mainOrderType = "main"; |
| | | /*生成新批次号*/ |
| | | String batchNum= requireBatchService.getNewBatchNumber(); |
| | | /*获取钣金主单信息*/ |
| | |
| | | |
| | | List<ApsPlateStandardRequire> requiresList=new ArrayList<>(); |
| | | |
| | | getBomRequires(plantCode, "0",itemNumber,BigDecimal.ONE, batchNum, null, mainPlan, requiresList, 0L); |
| | | getBomRequires(plantCode, "0","0",itemNumber,BigDecimal.ONE, batchNum, null, mainPlan, requiresList, 0L); |
| | | |
| | | // 批量插入以提高性能 |
| | | if (!requiresList.isEmpty()) { |
| | |
| | | * 构建需求信息 |
| | | * |
| | | * @param plant 工厂代码 |
| | | * @param bomHeaderCode BOM上级物料编码 |
| | | * @param bomLineId BOM行ID |
| | | * @param itemCode 物料代码 |
| | | * @param itemNum 物料数量 |
| | |
| | | * @param allRequires 所有需求的列表 |
| | | * @param level 层级 |
| | | */ |
| | | private void getBomRequires(String plant, 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) { |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | | require.setId(IdUtil.getSnowflakeNextId()); |
| | | require.setRequireTrackId(plan.getId()); |
| | | require.setRequireTrackId(plan.getId() + ""); |
| | | require.setBatchNumber(batchNum); |
| | | require.setDocNum(plan.getDocumentNumber()); |
| | | require.setOrgCode(plant); |
| | | require.setBomHeaderCode(bomHeaderCode); |
| | | require.setBomLineId(bomLineId); |
| | | require.setBomLineCode(itemCode); |
| | | require.setBomLineLevel(level); |
| | |
| | | /*计算需求数量*/ |
| | | if (level == 0) { |
| | | require.setBomUseAmount(BigDecimal.ONE); |
| | | require.setCompleteDate(plan.getPlanEndDay()); |
| | | require.setDemandDate(plan.getPlanEndDay()); |
| | | } else { |
| | | require.setBomUseAmount(itemNum.multiply(plan.getProductionQuantity())); |
| | | } |
| | |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLineId,itemCode, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | } |
| | | } |
| | | /*未匹配数量,默认为净需求*/ |
| | | require.setUnmatchedDemandAmount(require.getNetRequirement()); |
| | | /*工艺路线总需求*/ |
| | | ApsStandardProcessRouteLine routeHeader = routeLineService.getRouteLineTotalTime(require); |
| | | String routeId = routeHeader.getRouteId(); |
| | |
| | | require.setProcessRouteId(routeId); |
| | | require.setProcessRouteHours(String.valueOf(totalRouteTime)); |
| | | |
| | | /*完成时间,level=0 时默认为工单的计划完成日期*/ |
| | | Date completeDate = plan.getPlanEndDay(); |
| | | |
| | | /*预留天数*/ |
| | | Long reservedDay = getReservedDays(); |
| | | if (level > 0) { |
| | | /*设置完成日期*/ |
| | | if(level==0){ |
| | | /*完成时间,level=0 时默认为工单的计划完成日期*/ |
| | | require.setCompleteDate(plan.getPlanEndDay()); |
| | | require.setDemandDate(plan.getPlanEndDay()); |
| | | } else { |
| | | /* 当前需求完成日期为上阶层需求的开始时间 - 预留天数(转换为毫秒)*/ |
| | | long reservedMillisecond = reservedDay * 24 * millisecond; |
| | | Date completeDate = new Date(); |
| | | completeDate.setTime(upLevelStartDate.getTime() - reservedMillisecond); |
| | | require.setCompleteDate(completeDate); |
| | | require.setDemandDate(completeDate); |
| | | } |
| | | /*设置完成日期*/ |
| | | require.setCompleteDate(completeDate); |
| | | require.setDemandDate(completeDate); |
| | | |
| | | |
| | | /*设置开始时间*/ |
| | | Date startDay = new Date(); |
| | | startDay.setTime(completeDate.getTime() - totalRouteMillisecond); |
| | | startDay.setTime(require.getCompleteDate().getTime() - totalRouteMillisecond); |
| | | require.setStartDate(startDay); |
| | | |
| | | /*计算是否有风险*/ |
| | |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemCode); |
| | | if (!bomLineList.isEmpty()) { |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, 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); |
| | | }); |
| | | } |
| | | } |
| | |
| | | * 获取钣金计划 预留天数 |
| | | * */ |
| | | private Long getReservedDays(){ |
| | | Long days=0L; |
| | | List<SysDictData> dictDataList = DictUtils.getDictCache("aps_is_suspended"); |
| | | if (dictDataList != null) { |
| | | Long.getLong(dictDataList.get(0).getDictValue()); |
| | | long days=0L; |
| | | List<SysDictData> dictDataList = DictUtils.getDictCache("plate_plan_param"); |
| | | if (dictDataList != null && !dictDataList.isEmpty()) { |
| | | days = Long.parseLong(dictDataList.get(0).getDictValue()); |
| | | } |
| | | return days; |
| | | } |
| | |
| | | |
| | | private void matchRequireAndSubPlan(ApsPlateStandardRequire require) { |
| | | BigDecimal netRequirement = require.getNetRequirement(); |
| | | require.setMatchMode("工单匹配"); |
| | | if (netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | | ApsPlatePlan platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode()); |
| | | ApsPlatePlan platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | /*子件工单的未匹配数量 作为当前的库存*/ |
| | | while (platePlan != null && netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal stock = platePlan.getUnmatchedQuantity(); |
| | | if (netRequirement.compareTo(stock) < 0) { |
| | | /* 库存数量 大于 净需求数量*/ |
| | | /* 净需求数量=0 ,子件工单未匹配数量= 库存-净需求*/ |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setNetRequirement(netRequirement); |
| | | BigDecimal subtract = stock.subtract(netRequirement); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement); |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setMatchState("已匹配"); |
| | | require.setUnmatchedDemandAmount(BigDecimal.ZERO); |
| | | /*净需求已经被满足,不需要继续匹配*/ |
| | | |
| | | } else if (netRequirement.compareTo(stock) == 0) { |
| | | /*净需求数量 == 库存数量*/ |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setNetRequirement(netRequirement); |
| | | |
| | | BigDecimal subtract = BigDecimal.ZERO; |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement); |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setMatchState("已匹配"); |
| | | require.setUnmatchedDemandAmount(BigDecimal.ZERO); |
| | | /*净需求已经被满足,不需要继续匹配*/ |
| | | } |
| | | if (netRequirement.compareTo(stock) > 0) { |
| | | /*需求大于库存*/ |
| | | /*净需求 被部分满足 */ |
| | | BigDecimal rest = netRequirement.subtract(stock); |
| | | require.setNetRequirement(rest); |
| | | require.setMatchState("匹配中"); |
| | | /*工单 未匹配数量为0 全部用于匹配需求*/ |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, BigDecimal.ZERO, stock, netRequirement); |
| | | /*净需求未被满足,需要继续匹配*/ |
| | | platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode()); |
| | | platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | /*剩余净需求*/ |
| | | netRequirement = rest; |
| | | require.setUnmatchedDemandAmount(rest); |
| | | } |
| | | } |
| | | } |
| | | require.setUnmatchedDemandAmount(require.getNetRequirement()); |
| | | |
| | | } |
| | | |
| | | |