| | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.security.utils.DictUtils; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.aps.core.service.IApsPlateStandardRequireService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | @Resource |
| | | IApsStandardProcessRouteLineService routeLineService; |
| | | |
| | | @Resource |
| | | IApsPlateStandardRequireBatchService requireBatchService; |
| | | |
| | | /** |
| | | * 查询钣金工单标准需求 |
| | |
| | | return apsPlateStandardRequireMapper.selectPlateSupplyGapList(apsPlateStandardRequire); |
| | | } |
| | | |
| | | private void generatorPlan(){ |
| | | @Transactional |
| | | @Override |
| | | public void generatorPlan(){ |
| | | |
| | | /*初始化数据*/ |
| | | requireBatchService.initRequireBatch(); |
| | | /*定义工厂为南通 */ |
| | | String plantCode="FORTUNA"; |
| | | /*定义主单类型为钣金主单*/ |
| | | String mainOrderType = "钣金主件"; |
| | | /*定义子单类型为钣金子单*/ |
| | | String subOrderType = "钣金子件"; |
| | | String mainOrderType = "0"; |
| | | /*生成新批次号*/ |
| | | String batchNum=getBatch(); |
| | | String batchNum= requireBatchService.getNewBatchNumber(); |
| | | /*获取钣金主单信息*/ |
| | | List<ApsPlatePlan> mainPlans = platePlanMapper.selectPlatePlanByPlantMajor(plantCode,mainOrderType); |
| | | for (ApsPlatePlan mainPlan : mainPlans) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 构建需求信息 |
| | | * */ |
| | | private void getBomRequires(String plant, ApsBom bomLine, String batchNum, Date upLevelStartDate, ApsPlatePlan plan, List<ApsPlateStandardRequire> allRequires, Long level) { |
| | | |
| | | String itemNumber = bomLine.getItemCode(); |
| | | String productivityModel_combined_batch = "合批"; |
| | | String productivityModel_monopolize = "独占"; |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | | require.setId(IdUtil.getSnowflakeNextId()); |
| | | require.setRequireId(plan.getId()); |
| | | require.setRequireTrackId(plan.getId()); |
| | | require.setBatchNumber(batchNum); |
| | | require.setDocNum(plan.getDocumentNumber()); |
| | | require.setOrgCode(plant); |
| | |
| | | } |
| | | /*查找库存,计算净需求,保存剩余库存,保存库存扣减明细*/ |
| | | BigDecimal remainderStock = BigDecimal.ZERO; |
| | | /*默认净需求为BOM用量*/ |
| | | require.setNetRequirement(require.getBomUseAmount()); |
| | | Optional<ApsMaterialStorageManagement> itemStorage = getItemStorage(plant, itemNumber); |
| | | if (itemStorage.isPresent()) { |
| | | ApsMaterialStorageManagement storage = itemStorage.get(); |
| | |
| | | afterStockAmount = remainderStock.subtract(deductionAmount); |
| | | require.setNetRequirement(BigDecimal.ZERO); |
| | | } |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLine, batchNum, deductionAmount, afterStockAmount); |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLine, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | require.setStartDate(startDay); |
| | | |
| | | /*计算是否有风险*/ |
| | | require.setHasDelayRisk("无风险"); |
| | | require.setHasDelayRisk("0"); |
| | | Date dateZero = getDateZero(DateUtils.getNowDate()); |
| | | if (startDay.before(dateZero)) { |
| | | require.setHasDelayRisk("有风险"); |
| | | require.setHasDelayRisk("1"); |
| | | } |
| | | |
| | | /*生产基地*/ |
| | |
| | | if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { |
| | | require.setMatchState("待匹配"); |
| | | require.setMatchMode("工单匹配"); |
| | | /*使用子件工单进行需求匹配*/ |
| | | matchRequireAndSubPlan(require); |
| | | } |
| | | require.setHasDelayRisk("无风险"); |
| | | /*使用子件工单进行需求匹配*/ |
| | | matchRequireAndSubPlan(require); |
| | | |
| | | allRequires.add(require); |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemNumber); |
| | | if (!bomLineList.isEmpty()) { |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, line, batchNum, require.getStartDate(), plan, allRequires, level + 1); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private BigDecimal getRouteLineTotalTime(ApsStandardProcessRouteHeader routeHeader, String productivityModel_monopolize, BigDecimal netRequirement) { |
| | | ApsStandardProcessRouteLine routeLineParam = ApsStandardProcessRouteLine.builder() |
| | | .routeId(routeHeader.getRouteId()) |
| | | .build(); |
| | | List<ApsStandardProcessRouteLine> apsStandardProcessRouteLines = ApsStandardProcessRouteLineMapper.selectApsStandardProcessRouteLineList(routeLineParam); |
| | | /*工艺路线Line 总工时*/ |
| | | BigDecimal totalRouteTime = BigDecimal.ZERO; |
| | | apsStandardProcessRouteLines.forEach(line -> { |
| | | line.setRouteTime(line.getDesignCapacity()); |
| | | if (line.getProductivityModel().equals(productivityModel_monopolize)) { |
| | | line.setRouteTime(line.getDesignCapacity().multiply(netRequirement)); |
| | | if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemNumber); |
| | | if (!bomLineList.isEmpty()) { |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, line, batchNum, require.getStartDate(), plan, allRequires, level + 1); |
| | | }); |
| | | } |
| | | totalRouteTime.add(line.getRouteTime()); |
| | | }); |
| | | return totalRouteTime; |
| | | } |
| | | |
| | | /** |
| | | * 生成新批次号 |
| | | * */ |
| | | private String getBatch() { |
| | | String batchNum = System.currentTimeMillis() + ""; |
| | | ApsPlateStandardRequireBatch batchBuilder = ApsPlateStandardRequireBatch.builder() |
| | | .id(IdUtil.getSnowflakeNextId()) |
| | | .batchNumber(batchNum) |
| | | .delFlag("0").build(); |
| | | batchBuilder.setCreateBy(SecurityUtils.getUsername()); |
| | | batchBuilder.setCreateTime(DateUtils.getNowDate()); |
| | | requireBatchMapper.insertApsPlateStandardRequireBatch(batchBuilder); |
| | | return batchNum; |
| | | } |
| | | } |
| | | /** |
| | | * 获取物料库存信息 |