zhanghl
2025-04-28 cbdf99e2c3be57e14f4e8162f76d7d48917a65f2
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java
@@ -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;
@@ -184,8 +185,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()));
                    }
                    //插入 年 月 日
@@ -257,14 +258,13 @@
            }
            apsGasPipingRouteStats = apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(apsGasPipingRouteStat);
            //根据开工日进行升序排序
            apsGasPipingRouteStats.sort((a, b)->a.getPlanStartDay().compareTo(b.getPlanStartDay()));
            apsGasPipingRouteStats.sort((a, b)->a.getProcessPlanStartDay().compareTo(b.getProcessPlanStartDay()));
            //工序分组统计
            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<>();
            //工序开工日期
            String planStartDate = "";
            //统计所有工序对应的开工时间
            for (ApsGasPipingRouteStat apsGasPipingRouteStatTemp : apsGasPipingRouteStats) {
                planStartDate = simpleDateFormat.format(apsGasPipingRouteStatTemp.getProcessPlanStartDay());
                if("month".equals(apsGasPipingRouteStat.getSearchType())){
@@ -278,7 +278,9 @@
                //查询料号工序产能表
                apsResourceDateStat.setRequireTimes(apsGasPipingRouteStatTemp.getProcessTotalTime().intValue());
                if(apsResourceDateStat.getDesignTimes()!=0){
                    apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStat.getRequireTimes()/apsResourceDateStat.getDesignTimes()* 100L));
                    apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStat.getRequireTimes())
                            .divide(BigDecimal.valueOf(apsResourceDateStat.getDesignTimes()), 2, RoundingMode.HALF_UP)
                            .multiply(BigDecimal.valueOf(100)));
                }else{
                    apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(0));
                }
@@ -289,86 +291,47 @@
                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().intValue():0);
                        apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes()+apsResourceDateStat.getRequireTimes());
                        if(apsResourceDateStatTemp.getDesignTimes()!=0){
                            apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStat.getRequireTimes())
                                    .divide(BigDecimal.valueOf(apsResourceDateStat.getDesignTimes()), 2, RoundingMode.HALF_UP)
                                    .multiply(BigDecimal.valueOf(100)));
                        }else{
                            dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStat);
                            apsResourceDateStatTemp.setCapacityLoad(BigDecimal.valueOf(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);
                });
//                processMap.put(processName, tempList);
                HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
                temp.put(processName, tempList);
                processList.add(temp);
            });
//            for (String key : processMap.keySet()) {
//                HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
//                temp.put(key, processMap.get(key));
//                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();