zhanghl
2025-05-09 191b8ae5c768fbb97c7cdea87edde77d0a10e7da
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java
@@ -178,7 +178,7 @@
            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()) {
@@ -196,6 +196,7 @@
     * 构建需求信息
     *
     * @param plant 工厂代码
     * @param bomHeaderCode BOM上级物料编码
     * @param bomLineId BOM行ID
     * @param itemCode 物料代码
     * @param itemNum 物料数量
@@ -205,14 +206,15 @@
     * @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);
@@ -259,6 +261,8 @@
                bomStockDetailService.saveStorageAndDetail(storage, plan, bomLineId,itemCode, batchNum, deductionAmount, afterStockAmount,require.getId());
            }
        }
        /*未匹配数量,默认为净需求*/
        require.setUnmatchedDemandAmount(require.getNetRequirement());
        /*工艺路线总需求*/
        ApsStandardProcessRouteLine routeHeader = routeLineService.getRouteLineTotalTime(require);
        String routeId = routeHeader.getRouteId();
@@ -268,21 +272,27 @@
        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);
        /*计算是否有风险*/
@@ -310,7 +320,7 @@
            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);
                });
            }
        }
@@ -330,10 +340,10 @@
     * 获取钣金计划 预留天数
     * */
    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;
    }
@@ -344,44 +354,50 @@
    private void matchRequireAndSubPlan(ApsPlateStandardRequire require) {
        BigDecimal netRequirement = require.getNetRequirement();
        require.setMatchMode("工单匹配");
        if(require.getBomLineCode().equals("W0202-100028")){
            System.out.println("W0202-100028");
        }
        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());
    }