huangjiayang
2025-04-28 b0496b57b807044c8d4a866128b1ca42f4b339ad
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java
@@ -1,6 +1,5 @@
package com.aps.core.service.impl;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.aps.common.core.utils.DateUtils;
import com.aps.common.core.utils.uuid.IdUtils;
@@ -11,6 +10,7 @@
import com.aps.core.mapper.ApsGasPipingRouteStatMapper;
import com.aps.core.service.IApsGasMaterialUsageService;
import com.aps.core.service.IApsGasPipingRouteStatService;
import com.aps.core.service.IApsStandardProcessService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
@@ -24,6 +24,7 @@
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
@@ -54,6 +55,9 @@
    @Autowired
    private IApsGasMaterialUsageService apsGasMaterialUsageService;
    @Autowired
    private IApsStandardProcessService apsStandardProcessService;
    /**
     * 查询气体管路产能负载统计
@@ -184,8 +188,8 @@
                    // 上一道工序的结束时间 = 上一道工序的开始时间 + 上一道工序的总工时
                    if(apsGasPipingRouteStat.getProcessPlanStartDay()==null){
                        LocalDateTime previousProcessPlanStartDay = apsProcessRoutes.get(i - 1).getProcessPlanStartDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                        long previousProcessTotalTime = apsGasPipingRouteStatList.get(i - 1).getProcessTotalTime().longValue();
                        LocalDateTime currentProcessPlanStartDay = previousProcessPlanStartDay.plusHours(previousProcessTotalTime);
                        long seconds = apsGasPipingRouteStatList.get(i - 1).getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue();
                        LocalDateTime currentProcessPlanStartDay = previousProcessPlanStartDay.plusSeconds(seconds);
                        apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(Timestamp.valueOf(currentProcessPlanStartDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).toInstant()));
                    }
                    //插入 年 月 日
@@ -232,8 +236,19 @@
    public JSONObject getCapacityPlanData(ApsGasPipingRouteStat apsGasPipingRouteStat) {
        JSONObject result = new JSONObject();
        HashSet<String> startPlanTimeSet = new HashSet<>();
        JSONArray processData = new JSONArray();
        //工序分组统计
        LinkedHashMap<String, List<ApsResourceDateStat>> processMap = new LinkedHashMap<>();
        List<HashMap<String, List<ApsResourceDateStat>>> processList = new ArrayList<>();
        try {
            //获取标准工序名称
            List<String> processNameList = new ArrayList<>();
            ApsStandardProcess apsStandardProcess = new ApsStandardProcess();
            apsStandardProcess.setMajor(apsGasPipingRouteStat.getMajor().equals("gas")?"气柜":"管路");
            List<ApsStandardProcess> apsStandardProcessList = apsStandardProcessService.selectApsStandardProcessList(apsStandardProcess);
            apsStandardProcessList.sort((a, b)->a.getProcessName().compareTo(b.getProcessName()));
            for(ApsStandardProcess temp:apsStandardProcessList){
                processMap.put(temp.getProcessName(), new ArrayList<ApsResourceDateStat>());
            }
            //获取工序计划产能数据
            HashMap<String, ApsGasPipelineCapacityPlan> apsGasPipingPlanMap = new HashMap<>();
            List<ApsGasPipelineCapacityPlan> apsGasPipelineCapacityPlanList = apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(new ApsGasPipelineCapacityPlan());
@@ -257,14 +272,10 @@
            }
            apsGasPipingRouteStats = apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(apsGasPipingRouteStat);
            //根据开工日进行升序排序
            apsGasPipingRouteStats.sort((a, b)->a.getPlanStartDay().compareTo(b.getPlanStartDay()));
            //工序分组统计
            HashMap<String, List<ApsResourceDateStat>> processMap = new HashMap<>();
            List<HashMap<String, List<ApsResourceDateStat>>> processList = new ArrayList<>();
            HashMap<String, List<ApsResourceDateStat>> processMapMonth = new HashMap<>();
            List<HashMap<String, List<ApsResourceDateStat>>> processListMonth = new ArrayList<>();
            apsGasPipingRouteStats.sort((a, b)->a.getProcessPlanStartDay().compareTo(b.getProcessPlanStartDay()));
            //工序开工日期
            String planStartDate = "";
            //统计所有工序对应的开工时间
            for (ApsGasPipingRouteStat apsGasPipingRouteStatTemp : apsGasPipingRouteStats) {
                planStartDate = simpleDateFormat.format(apsGasPipingRouteStatTemp.getProcessPlanStartDay());
                if("month".equals(apsGasPipingRouteStat.getSearchType())){
@@ -274,11 +285,13 @@
                apsResourceDateStat.setPlanDay(LocalDate.parse(planStartDate, formatter));
                apsResourceDateStat.setResourceName(apsGasPipingRouteStatTemp.getProcessName());
                //查询气柜管路产能规划表
                apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName())!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()).getDayProduceAllNum().intValue():0);
                apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName())!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()).getDayProduceAllNum():new BigDecimal(0));
                //查询料号工序产能表
                apsResourceDateStat.setRequireTimes(apsGasPipingRouteStatTemp.getProcessTotalTime().intValue());
                if(apsResourceDateStat.getDesignTimes()!=0){
                    apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStat.getRequireTimes()/apsResourceDateStat.getDesignTimes()* 100L));
                apsResourceDateStat.setRequireTimes(apsGasPipingRouteStatTemp.getProcessTotalTime());
                if(apsResourceDateStat.getDesignTimes().compareTo(BigDecimal.ZERO)>0){
                    apsResourceDateStat.setCapacityLoad(apsResourceDateStat.getRequireTimes()
                            .divide(apsResourceDateStat.getDesignTimes(), 2, RoundingMode.HALF_UP)
                            .multiply(new BigDecimal(100)));
                }else{
                    apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(0));
                }
@@ -289,86 +302,42 @@
                apsResourceDateStatList.add(apsResourceDateStat);
                processMap.put(apsGasPipingRouteStatTemp.getProcessName(), apsResourceDateStatList);
            }
            //聚合每道工序的开工时间和产能
            processMap.forEach((processName, apsResourceDateStatList) -> {
                HashMap<String, ApsResourceDateStat> dayMap = new HashMap<>();
                LinkedHashMap<String, ApsResourceDateStat> dayMap = new LinkedHashMap<>();
                apsResourceDateStatList.forEach(apsResourceDateStat -> {
                    startPlanTimeSet.add(apsResourceDateStat.getPlanDay().toString());
                    if("month".equals(apsGasPipingRouteStat.getSearchType())){
                        if(dayMap.containsKey(apsResourceDateStat.getPlanDay().toString())){
                            ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(apsResourceDateStat.getPlanDay().toString());
                            apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getMonthProduceAllNum().intValue():0);
                            apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes()+apsResourceDateStat.getRequireTimes());
                            if(apsResourceDateStatTemp.getDesignTimes()!=0){
                                apsResourceDateStatTemp.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStatTemp.getRequireTimes()/apsResourceDateStatTemp.getDesignTimes()* 100L));
                            }else{
                                apsResourceDateStatTemp.setCapacityLoad(BigDecimal.valueOf(0));
                            }
                            apsResourceDateStatTemp.setResourceGroupName(processName);
                            apsResourceDateStatTemp.setPlanDay(apsResourceDateStat.getPlanDay());
                            dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStatTemp);
                    if(dayMap.containsKey(apsResourceDateStat.getPlanDay().toString())){
                        ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(apsResourceDateStat.getPlanDay().toString());
                        apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getMonthProduceAllNum():new BigDecimal(0));
                        apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes().add(apsResourceDateStat.getRequireTimes()));
                        if(apsResourceDateStatTemp.getDesignTimes().compareTo(BigDecimal.ZERO) > 0){
                            apsResourceDateStat.setCapacityLoad(apsResourceDateStat.getRequireTimes()
                                    .divide(apsResourceDateStat.getDesignTimes(), 2, RoundingMode.HALF_UP)
                                    .multiply(new BigDecimal(100)));
                        }else{
                            dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStat);
                            apsResourceDateStatTemp.setCapacityLoad(new BigDecimal(0));
                        }
                        apsResourceDateStatTemp.setResourceGroupName(processName);
                        apsResourceDateStatTemp.setPlanDay(apsResourceDateStat.getPlanDay());
                        dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStatTemp);
                    }else{
                        dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStat);
                    }
                });
                if("month".equals(apsGasPipingRouteStat.getSearchType())){
                    List<ApsResourceDateStat> tempList = new ArrayList<>();
                    dayMap.forEach((key, value) -> {
                        tempList.add(value);
                    });
                    processMapMonth.put(processName, tempList);
                }
                List<ApsResourceDateStat> tempList = new ArrayList<>();
                dayMap.forEach((key, value) -> {
                    tempList.add(value);
                });
                HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
                temp.put(processName, tempList);
                processNameList.remove(processName);
                processList.add(temp);
            });
            //排序时间标题
            List<String> sortedStartPlanTimeList = new ArrayList<>(startPlanTimeSet);
            Collections.sort(sortedStartPlanTimeList);
//            processMap.forEach((processName, apsResourceDateStatList) -> {
//                HashMap<String, ApsResourceDateStat> dayMap = new HashMap<>();
//                apsResourceDateStatList.forEach(apsResourceDateStat -> {
//                    startPlanTimeSet.add(apsResourceDateStat.getPlanDay().toString());
//                    if(dayMap.containsKey(apsResourceDateStat.getPlanDay().toString())){
//                        ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(apsResourceDateStat.getPlanDay().toString());
//                        if("day".equals(apsGasPipingRouteStat.getSearchType())){
//                            apsResourceDateStatTemp.setDesignTimes(apsResourceDateStatTemp.getDesignTimes()+apsResourceDateStat.getDesignTimes());
//                        }else if("month".equals(apsGasPipingRouteStat.getSearchType())){
//                            apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getMonthProduceAllNum().intValue():0);
//                        }
//                        apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes()+apsResourceDateStat.getRequireTimes());
//                        if(apsResourceDateStatTemp.getDesignTimes()!=0){
//                            apsResourceDateStatTemp.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStatTemp.getRequireTimes()/apsResourceDateStatTemp.getDesignTimes()* 100L));
//                        }
//                        apsResourceDateStatTemp.setResourceGroupName(processName);
//                        dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStatTemp);
//                    }else{
//                        dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStat);
//                    }
//                });
//                JSONArray tempList = new JSONArray();
//                dayMap.forEach((key, value) -> {
//                    JSONObject temp = new JSONObject();
//                    temp.put("planDay", key);
//                    temp.put("designTimes", value.getDesignTimes());
//                    temp.put("requireTimes", value.getRequireTimes());
//                    temp.put("capacityLoad", value.getCapacityLoad());
//                    temp.put("resourceGroupName", value.getResourceGroupName());
//                    tempList.add(temp);
//                });
//                processData.add(new JSONObject().put(processName, tempList));
//            });
            if("month".equals(apsGasPipingRouteStat.getSearchType())){
                for (String key : processMapMonth.keySet()) {
                    HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
                    temp.put(key, processMapMonth.get(key));
                    processListMonth.add(temp);
                }
                result.put("planTable", processListMonth);
            }else{
                for (String key : processMap.keySet()) {
                    HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
                    temp.put(key, processMap.get(key));
                    processList.add(temp);
                }
                result.put("planTable", processList);
            }
            result.put("planTable", processList);
            result.put("planTitle", sortedStartPlanTimeList);
        } catch (Exception e) {
            e.printStackTrace();
@@ -431,8 +400,8 @@
                    dataRow.createCell(0).setCellValue(resourceName);
                    for (int j = 0; j < resourceDateStats.size(); j++) {
                        ApsResourceDateStat apsResourceDateStat = resourceDateStats.get(j);
                        dataRow.createCell(j*3+1).setCellValue(apsResourceDateStat.getDesignTimes());
                        dataRow.createCell(j*3+2).setCellValue(apsResourceDateStat.getRequireTimes());
                        dataRow.createCell(j*3+1).setCellValue(apsResourceDateStat.getDesignTimes().doubleValue());
                        dataRow.createCell(j*3+2).setCellValue(apsResourceDateStat.getRequireTimes().doubleValue());
                        if(apsResourceDateStat.getCapacityLoad()!=null){
                            dataRow.createCell(j*3+3).setCellValue(apsResourceDateStat.getCapacityLoad().doubleValue()+"%");
                        }else{