From d4d5f196cc42ef8cfe739de6ecd40f2d21a96e31 Mon Sep 17 00:00:00 2001 From: huangjiayang <5265313@qq.com> Date: 星期二, 29 四月 2025 09:45:57 +0800 Subject: [PATCH] 【UPDATE-BUGFIX】优化计算产能开始结束日期 --- aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java | 112 ++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 81 insertions(+), 31 deletions(-) diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java index c0cbf3a..be5115c 100644 --- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java +++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java @@ -145,9 +145,10 @@ apsGasPipingPlans.forEach(apsGasPipingPlan -> { List<ApsProcessRoute> apsProcessRoutes = apsGasPipingPlan.getApsProcessRoutes(); //鎸夌収宸ュ簭搴忓彿鍗囧簭鎺掑簭 - apsProcessRoutes.sort((a, b)->a.getProcessNumber().compareTo(b.getProcessNumber())); + apsProcessRoutes.sort((a, b)->b.getProcessNumber().compareTo(a.getProcessNumber())); //鏄惁鎵惧埌褰撳墠宸ュ簭 - boolean isFind = false; + boolean isCurrentProcess = false; + ApsGasPipingRouteStat preApsProcessRoute = null; for (int i=0;i<apsProcessRoutes.size();i++){ ApsProcessRoute apsProcessRoute = apsProcessRoutes.get(i); ApsGasPipingRouteStat apsGasPipingRouteStat = new ApsGasPipingRouteStat(); @@ -156,7 +157,7 @@ //鏂欏彿 apsGasPipingRouteStat.setItemNumber(apsGasPipingPlan.getItemNumber()); //褰撳墠宸ュ簭鍙� - apsGasPipingRouteStat.setCurrentProcessNumber(apsGasPipingPlan.getProcessNumber()); + apsGasPipingRouteStat.setCurrentProcessNumber(new BigDecimal(apsGasPipingPlan.getProcessNumber())); //鐢熶骇鏁伴噺 apsGasPipingRouteStat.setProductionQuantity(apsGasPipingPlan.getProductionQuantity()); //宸ュ簭鍚嶇О @@ -169,8 +170,8 @@ apsGasPipingRouteStat.setMajor(apsGasPipingPlan.getPlanType()); //宸ュ簭鎬诲伐鏃� 绛変簬 鏍囧噯宸ユ椂*鐢熶骇鏁伴噺 apsGasPipingRouteStat.setProcessTotalTime(apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity())); - //璁″垝寮�宸ユ棩 - if(apsGasPipingRouteStat.getCurrentProcessNumber().equals(apsGasPipingRouteStat.getRoadProcessNumber())) { + //璁″垝寮�宸ユ棩 濡傛灉鏄綋鍓嶅簭 + if(apsGasPipingRouteStat.getCurrentProcessNumber().toString().equals(apsGasPipingRouteStat.getRoadProcessNumber())) { /* 瀵� stat.getProcessPlanStartDay() 鍜屽綋鍓嶆棩鏈� 杩涜瀵规瘮锛屽彧瀵规瘮鍒版棩锛屼笉鐢ㄧ鍗佸垎绉�*/ LocalDate startLocalDate = LocalDate.ofInstant(apsProcessRoute.getProcessPlanStartDay().toInstant(), ZoneId.systemDefault()); LocalDate nowLocalDate = LocalDate.now(); @@ -179,17 +180,32 @@ }else{ apsGasPipingRouteStat.setProcessPlanStartDay(apsProcessRoute.getProcessPlanStartDay()); } - isFind = true; - } - if(!isFind){ - continue; - } - // 涓婁竴閬撳伐搴忕殑缁撴潫鏃堕棿 = 涓婁竴閬撳伐搴忕殑寮�濮嬫椂闂� + 涓婁竴閬撳伐搴忕殑鎬诲伐鏃� - if(apsGasPipingRouteStat.getProcessPlanStartDay()==null){ - LocalDateTime previousProcessPlanStartDay = apsProcessRoutes.get(i - 1).getProcessPlanStartDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - 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(currentProcessPlanStartDay.atZone(ZoneId.systemDefault()).toInstant())); + LocalDateTime planStartDay = apsGasPipingRouteStat.getProcessPlanStartDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + long seconds = apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()).multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); + apsGasPipingRouteStat.setProcessPlanEndDay(Date.from(planStartDay.plusSeconds(seconds).atZone(ZoneId.systemDefault()).toInstant())); + isCurrentProcess = true; + }else{ + // 涓婁竴閬撳伐搴忕殑缁撴潫鏃堕棿 = 涓婁竴閬撳伐搴忕殑寮�濮嬫椂闂� + 涓婁竴閬撳伐搴忕殑鎬诲伐鏃� + if(i==0){ + apsGasPipingRouteStat.setProcessPlanEndDay(apsGasPipingPlan.getPlanEndDay()); + LocalDate endLocalDate = LocalDate.ofInstant(apsGasPipingPlan.getPlanEndDay().toInstant(), ZoneId.systemDefault()); + LocalDate nowLocalDate = LocalDate.now(); + LocalDateTime planEndDay; + if(endLocalDate.isBefore(nowLocalDate)){ + planEndDay = LocalDateTime.now(); + }else{ + planEndDay = apsGasPipingPlan.getPlanEndDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } + long seconds = apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()).multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); + LocalDateTime planStartDay = planEndDay.plusSeconds(-seconds); + apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(planStartDay.atZone(ZoneId.systemDefault()).toInstant())); + }else{ + apsGasPipingRouteStat.setProcessPlanEndDay(preApsProcessRoute.getProcessPlanEndDay()); + LocalDateTime planEndDay = apsGasPipingPlan.getPlanEndDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + long seconds = apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()).multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); + LocalDateTime planStartDay = planEndDay.plusSeconds(-seconds); + apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(planStartDay.atZone(ZoneId.systemDefault()).toInstant())); + } } //鎻掑叆 骞� 鏈� 鏃� SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -211,6 +227,10 @@ apsGasPipingRouteStat.setBatchNumber(batchNum); apsGasPipingRouteStat.setId(IdUtils.fastSimpleUUID()); apsGasPipingRouteStatList.add(apsGasPipingRouteStat); + preApsProcessRoute = apsGasPipingRouteStat; + if(isCurrentProcess){ + break; + } } }); List<ApsGasPipingRouteStat> tempInsertList = new ArrayList<>(); @@ -234,9 +254,9 @@ @Override public JSONObject getCapacityPlanData(ApsGasPipingRouteStat apsGasPipingRouteStat) { JSONObject result = new JSONObject(); - HashSet<String> startPlanTimeSet = new HashSet<>(); YearMonth yearMonth = YearMonth.parse(apsGasPipingRouteStat.getSearchEndDate()); int daysInMonth = yearMonth.lengthOfMonth(); + LinkedHashSet<String> startPlanTimeSet = new LinkedHashSet<>(); //宸ュ簭鍒嗙粍缁熻 LinkedHashMap<String, List<ApsResourceDateStat>> processMap = new LinkedHashMap<>(); List<HashMap<String, List<ApsResourceDateStat>>> processList = new ArrayList<>(); @@ -256,12 +276,19 @@ if("day".equals(apsGasPipingRouteStat.getSearchType())){ searchCapacityPlan.setYear(yearMonth.getYear()+""); searchCapacityPlan.setMonth(yearMonth.getMonthValue()+""); + for(int i=1;i<=daysInMonth;i++){ + startPlanTimeSet.add(yearMonth +"-"+ (i<10?"0"+i:i)); + } }else if("month".equals(apsGasPipingRouteStat.getSearchType())){ searchCapacityPlan.setYear(yearMonth.getYear()+""); + YearMonth start = YearMonth.of(Integer.parseInt(apsGasPipingRouteStat.getSearchStartDate().split("-")[0]), Integer.parseInt(apsGasPipingRouteStat.getSearchStartDate().split("-")[1])); + YearMonth end = YearMonth.of(Integer.parseInt(apsGasPipingRouteStat.getSearchEndDate().split("-")[0]), Integer.parseInt(apsGasPipingRouteStat.getSearchEndDate().split("-")[1])); + List<String> yearMonths = getYearMonthsInRange(start, end); + startPlanTimeSet.addAll(yearMonths); } List<ApsGasPipelineCapacityPlan> apsGasPipelineCapacityPlanList = apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(searchCapacityPlan); apsGasPipelineCapacityPlanList.forEach(apsGasPipelineCapacityPlan -> { - apsGasPipingPlanMap.put(apsGasPipelineCapacityPlan.getProcessName(),apsGasPipelineCapacityPlan); + apsGasPipingPlanMap.put(apsGasPipelineCapacityPlan.getProcessName()+"-"+apsGasPipelineCapacityPlan.getYear()+"-"+(Integer.parseInt(apsGasPipelineCapacityPlan.getMonth())<10?"0"+apsGasPipelineCapacityPlan.getMonth():apsGasPipelineCapacityPlan.getMonth()),apsGasPipelineCapacityPlan); }); //璁$畻鏃ヤ骇鑳芥暟鎹� DateTimeFormatter formatter = null; @@ -291,7 +318,7 @@ apsResourceDateStat.setPlanDay(LocalDate.parse(planStartDate, formatter)); apsResourceDateStat.setResourceName(apsGasPipingRouteStatTemp.getProcessName()); //鏌ヨ姘旀煖绠¤矾浜ц兘瑙勫垝琛� - apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName())!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()).getDayProduceAllNum():new BigDecimal(0)); + apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()+"-"+planStartDate.substring(0, 7))!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()+"-"+planStartDate.substring(0, 7)).getDayProduceAllNum():new BigDecimal(0)); //鏌ヨ鏂欏彿宸ュ簭浜ц兘琛� apsResourceDateStat.setRequireTimes(apsGasPipingRouteStatTemp.getProcessTotalTime()); if(apsResourceDateStat.getDesignTimes().compareTo(BigDecimal.ZERO)>0){ @@ -312,18 +339,18 @@ processMap.forEach((processName, apsResourceDateStatList) -> { LinkedHashMap<String, ApsResourceDateStat> dayMap = new LinkedHashMap<>(); apsResourceDateStatList.forEach(apsResourceDateStat -> { - startPlanTimeSet.add(apsResourceDateStat.getPlanDay().toString()); +// startPlanTimeSet.add(apsResourceDateStat.getPlanDay().toString()); if(dayMap.containsKey(apsResourceDateStat.getPlanDay().toString())){ ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(apsResourceDateStat.getPlanDay().toString()); if("month".equals(apsGasPipingRouteStat.getSearchType())){ - apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getMonthProduceAllNum():new BigDecimal(0)); + apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7))!=null?apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7)).getMonthProduceAllNum():new BigDecimal(0)); }else{ - apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getDayProduceAllNum():new BigDecimal(0)); + apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7))!=null?apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7)).getDayProduceAllNum():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) + apsResourceDateStatTemp.setCapacityLoad(apsResourceDateStatTemp.getRequireTimes() + .divide(apsResourceDateStatTemp.getDesignTimes(), 2, RoundingMode.HALF_UP) .multiply(new BigDecimal(100))); }else{ apsResourceDateStatTemp.setCapacityLoad(new BigDecimal(0)); @@ -350,22 +377,33 @@ HashMap<String, List<ApsResourceDateStat>> temp = processList.get(i); for (Map.Entry<String, List<ApsResourceDateStat>> entry : temp.entrySet()){ List<ApsResourceDateStat> apsResourceDateStatList = entry.getValue(); - if(apsResourceDateStatList.size()<=0){ - for(String tempTime:sortedStartPlanTimeList){ + String key = entry.getKey(); + List<ApsResourceDateStat> crtList = new ArrayList<>(); + for(String tempTime:sortedStartPlanTimeList) { + if("month".equals(apsGasPipingRouteStat.getSearchType())){ + tempTime += "-01"; + } + LocalDate crtDate = LocalDate.parse(tempTime, formatter); + Optional<ApsResourceDateStat> first = apsResourceDateStatList.stream().filter(x -> x.getPlanDay().equals(crtDate)).findFirst(); + if (first.isPresent()) { + ApsResourceDateStat apsResourceDateStat = first.get(); + crtList.add(apsResourceDateStat); + } else { ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat(); apsResourceDateStat.setPlanDay(LocalDate.parse(tempTime, formatter)); - if("month".equals(apsGasPipingRouteStat.getSearchType())){ - apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey())!=null?apsGasPipingPlanMap.get(entry.getKey()).getMonthProduceAllNum():new BigDecimal(0)); - }else{ - apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey())!=null?apsGasPipingPlanMap.get(entry.getKey()).getDayProduceAllNum():new BigDecimal(0)); + if ("month".equals(apsGasPipingRouteStat.getSearchType())) { + apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)) != null ? apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)).getMonthProduceAllNum() : new BigDecimal(0)); + } else { + apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)) != null ? apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)).getDayProduceAllNum() : new BigDecimal(0)); } apsResourceDateStat.setRequireTimes(new BigDecimal(0)); apsResourceDateStat.setCapacityLoad(new BigDecimal(0)); apsResourceDateStat.setResourceName(entry.getKey()); apsResourceDateStat.setResourceGroupName(entry.getKey()); apsResourceDateStatList.add(apsResourceDateStat); + crtList.add(apsResourceDateStat); } - temp.put(entry.getKey(), apsResourceDateStatList); + temp.put(entry.getKey(), crtList); processList.set(i, temp); } } @@ -471,4 +509,16 @@ styles.put("title", style); return styles; } + + public static List<String> getYearMonthsInRange(YearMonth start, YearMonth end) { + List<String> yearMonths = new ArrayList<>(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + + while (!start.isAfter(end)) { + yearMonths.add(start.format(formatter)); + start = start.plusMonths(1); + } + + return yearMonths; + } } -- Gitblit v1.9.3