From 25cc1b887f5421353d94c5e6be0fca56b3f2e668 Mon Sep 17 00:00:00 2001
From: zhanghl <253316343@qq.com>
Date: 星期三, 21 五月 2025 16:29:24 +0800
Subject: [PATCH] 优化Job
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipingRouteStatServiceImpl.java | 684 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 615 insertions(+), 69 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 73cdfbd..756bec0 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
@@ -1,5 +1,6 @@
package com.aps.core.service.impl;
+import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.aps.common.core.utils.DateUtils;
import com.aps.common.core.utils.uuid.IdUtils;
@@ -20,18 +21,20 @@
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.YearMonth;
-import java.time.ZoneId;
+import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.groupingBy;
/**
* 姘斾綋绠¤矾浜ц兘璐熻浇缁熻Service涓氬姟灞傚鐞�
@@ -145,9 +148,11 @@
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;
+ boolean lastProcessStartTimeIsBeforeNow = false;
+ ApsGasPipingRouteStat preApsProcessRoute = null;
for (int i=0;i<apsProcessRoutes.size();i++){
ApsProcessRoute apsProcessRoute = apsProcessRoutes.get(i);
ApsGasPipingRouteStat apsGasPipingRouteStat = new ApsGasPipingRouteStat();
@@ -156,40 +161,52 @@
//鏂欏彿
apsGasPipingRouteStat.setItemNumber(apsGasPipingPlan.getItemNumber());
//褰撳墠宸ュ簭鍙�
- apsGasPipingRouteStat.setCurrentProcessNumber(apsGasPipingPlan.getProcessNumber());
+ apsGasPipingRouteStat.setCurrentProcessNumber(new BigDecimal(apsGasPipingPlan.getProcessNumber()));
//鐢熶骇鏁伴噺
apsGasPipingRouteStat.setProductionQuantity(apsGasPipingPlan.getProductionQuantity());
//宸ュ簭鍚嶇О
apsGasPipingRouteStat.setProcessName(apsProcessRoute.getProcessName());
//宸ュ簭鍙�
- apsGasPipingRouteStat.setRoadProcessNumber(apsProcessRoute.getProcessNumber());
+ apsGasPipingRouteStat.setRoadProcessNumber( new BigDecimal(apsProcessRoute.getProcessNumber()) );
//鏍囧噯宸ユ椂
apsGasPipingRouteStat.setStandardTime(apsProcessRoute.getStandardTime());
//涓撲笟
apsGasPipingRouteStat.setMajor(apsGasPipingPlan.getPlanType());
//宸ュ簭鎬诲伐鏃� 绛変簬 鏍囧噯宸ユ椂*鐢熶骇鏁伴噺
apsGasPipingRouteStat.setProcessTotalTime(apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()));
- //璁″垝寮�宸ユ棩
- if(apsGasPipingRouteStat.getCurrentProcessNumber().equals(apsGasPipingRouteStat.getRoadProcessNumber())) {
- /* 瀵� stat.getProcessPlanStartDay() 鍜屽綋鍓嶆棩鏈� 杩涜瀵规瘮锛屽彧瀵规瘮鍒版棩锛屼笉鐢ㄧ鍗佸垎绉�*/
- LocalDate startLocalDate = LocalDate.ofInstant(apsProcessRoute.getProcessPlanStartDay().toInstant(), ZoneId.systemDefault());
- LocalDate nowLocalDate = LocalDate.now();
- if (startLocalDate.isBefore(nowLocalDate)) {
- apsGasPipingRouteStat.setProcessPlanStartDay(new Date());
- }else{
- apsGasPipingRouteStat.setProcessPlanStartDay(apsProcessRoute.getProcessPlanStartDay());
- }
- isFind = true;
- }
- if(!isFind){
- continue;
+ //璁″垝寮�宸ユ棩 濡傛灉鏄綋鍓嶅簭
+ if(apsGasPipingPlan.getProcessNumber().equals(apsProcessRoute.getProcessNumber())) {
+ isCurrentProcess = true;
}
// 涓婁竴閬撳伐搴忕殑缁撴潫鏃堕棿 = 涓婁竴閬撳伐搴忕殑寮�濮嬫椂闂� + 涓婁竴閬撳伐搴忕殑鎬诲伐鏃�
- 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()));
+ if(i==0){
+ 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();
+ }
+ apsGasPipingRouteStat.setProcessPlanEndDay(Date.from(planEndDay.atZone(ZoneId.systemDefault()).toInstant()));
+ 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()));
+ if(planStartDay.isBefore(LocalDateTime.now())){
+ lastProcessStartTimeIsBeforeNow = true;
+ }
+ }else{
+ if(lastProcessStartTimeIsBeforeNow){
+ Date now = new Date();
+ apsGasPipingRouteStat.setProcessPlanStartDay(now);
+ apsGasPipingRouteStat.setProcessPlanEndDay(now);
+ }else{
+ apsGasPipingRouteStat.setProcessPlanEndDay(preApsProcessRoute.getProcessPlanStartDay());
+ LocalDateTime planEndDay = preApsProcessRoute.getProcessPlanStartDay().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 +228,10 @@
apsGasPipingRouteStat.setBatchNumber(batchNum);
apsGasPipingRouteStat.setId(IdUtils.fastSimpleUUID());
apsGasPipingRouteStatList.add(apsGasPipingRouteStat);
+ preApsProcessRoute = apsGasPipingRouteStat;
+ if(isCurrentProcess){
+ break;
+ }
}
});
List<ApsGasPipingRouteStat> tempInsertList = new ArrayList<>();
@@ -231,10 +252,11 @@
return true;
}
- @Override
- public JSONObject getCapacityPlanData(ApsGasPipingRouteStat apsGasPipingRouteStat) {
+ public JSONObject getCapacityPlanDataBackup(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<>();
@@ -249,16 +271,29 @@
}
//鑾峰彇宸ュ簭璁″垝浜ц兘鏁版嵁
HashMap<String, ApsGasPipelineCapacityPlan> apsGasPipingPlanMap = new HashMap<>();
- List<ApsGasPipelineCapacityPlan> apsGasPipelineCapacityPlanList = apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(new ApsGasPipelineCapacityPlan());
+ ApsGasPipelineCapacityPlan searchCapacityPlan = new ApsGasPipelineCapacityPlan();
+ searchCapacityPlan.setMajor(apsGasPipingRouteStat.getMajor().equals("gas")?"姘旀煖":"绠¤矾");
+ 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;
List<ApsGasPipingRouteStat> apsGasPipingRouteStats;
SimpleDateFormat simpleDateFormat = null;
- YearMonth yearMonth = YearMonth.parse(apsGasPipingRouteStat.getSearchEndDate());
- int daysInMonth = yearMonth.lengthOfMonth();
apsGasPipingRouteStat.setSearchStartDate(apsGasPipingRouteStat.getSearchStartDate()+"-01 00:00:00");
apsGasPipingRouteStat.setSearchEndDate(apsGasPipingRouteStat.getSearchEndDate()+"-"+ daysInMonth +" 23:59:59");
if("day".equals(apsGasPipingRouteStat.getSearchType())){
@@ -268,54 +303,59 @@
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
simpleDateFormat = new SimpleDateFormat("yyyy-MM");
}
- apsGasPipingRouteStats = apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(apsGasPipingRouteStat);
+ ApsGasPipingRouteStat queryStatParam = new ApsGasPipingRouteStat();
+ BeanUtils.copyProperties(apsGasPipingRouteStat,queryStatParam);
+ queryStatParam.setMajor("");
+ apsGasPipingRouteStats = apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(queryStatParam);
//鏍规嵁寮�宸ユ棩杩涜鍗囧簭鎺掑簭
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())){
- planStartDate = planStartDate+"-01";
- }
- ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat();
- 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.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));
- }
- List<ApsResourceDateStat> apsResourceDateStatList = new ArrayList<>();
if(processMap.containsKey(apsGasPipingRouteStatTemp.getProcessName())){
- apsResourceDateStatList = processMap.get(apsGasPipingRouteStatTemp.getProcessName());
+ planStartDate = simpleDateFormat.format(apsGasPipingRouteStatTemp.getProcessPlanStartDay());
+ if("month".equals(apsGasPipingRouteStat.getSearchType())){
+ planStartDate = planStartDate+"-01";
+ }
+ ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat();
+ apsResourceDateStat.setPlanDay(LocalDate.parse(planStartDate, formatter));
+ apsResourceDateStat.setResourceName(apsGasPipingRouteStatTemp.getProcessName());
+ //鏌ヨ姘旀煖绠¤矾浜ц兘瑙勫垝琛�
+ 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){
+ apsResourceDateStat.setCapacityLoad(apsResourceDateStat.getRequireTimes()
+ .divide(apsResourceDateStat.getDesignTimes(), 2, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal(100)));
+ }else{
+ apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(0));
+ }
+ // apsResourceDateStatList = new ArrayList<>();
+
+ List<ApsResourceDateStat> apsResourceDateStatList = processMap.get(apsGasPipingRouteStatTemp.getProcessName());
+ apsResourceDateStatList.add(apsResourceDateStat);
+ processMap.put(apsGasPipingRouteStatTemp.getProcessName(), apsResourceDateStatList);
}
- apsResourceDateStatList.add(apsResourceDateStat);
- processMap.put(apsGasPipingRouteStatTemp.getProcessName(), apsResourceDateStatList);
+
}
//鑱氬悎姣忛亾宸ュ簭鐨勫紑宸ユ椂闂村拰浜ц兘
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));
@@ -342,22 +382,319 @@
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);
+ }
+ }
+ }
+ result.put("planTable", processList);
+ result.put("planTitle", sortedStartPlanTimeList);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ @Override
+ public JSONObject getCapacityPlanData(ApsGasPipingRouteStat apsGasPipingRouteStat) {
+ JSONObject result = new JSONObject();
+ 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<>();
+ try {
+ //鑾峰彇鏍囧噯宸ュ簭鍚嶇О
+ 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<>();
+ ApsGasPipelineCapacityPlan searchCapacityPlan = new ApsGasPipelineCapacityPlan();
+ searchCapacityPlan.setMajor(apsGasPipingRouteStat.getMajor().equals("gas")?"姘旀煖":"绠¤矾");
+ 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 -> {
+ String key = apsGasPipelineCapacityPlan.getProcessName() + "-" + apsGasPipelineCapacityPlan.getOrgCode() + "-" + apsGasPipelineCapacityPlan.getYear() + "-" + (Integer.parseInt(apsGasPipelineCapacityPlan.getMonth())<10?"0"+apsGasPipelineCapacityPlan.getMonth():apsGasPipelineCapacityPlan.getMonth());
+ apsGasPipingPlanMap.put(key, apsGasPipelineCapacityPlan);
+ });
+ //璁$畻鏃ヤ骇鑳芥暟鎹�
+ DateTimeFormatter formatter = null;
+ List<ApsGasPipingRouteStat> apsGasPipingRouteStats;
+ SimpleDateFormat simpleDateFormat = null;
+ apsGasPipingRouteStat.setSearchStartDate(apsGasPipingRouteStat.getSearchStartDate()+"-01 00:00:00");
+ apsGasPipingRouteStat.setSearchEndDate(apsGasPipingRouteStat.getSearchEndDate()+"-"+ daysInMonth +" 23:59:59");
+ if("day".equals(apsGasPipingRouteStat.getSearchType())){
+ formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ }else if("month".equals(apsGasPipingRouteStat.getSearchType())){
+ formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ simpleDateFormat = new SimpleDateFormat("yyyy-MM");
+ }
+ ApsGasPipingRouteStat queryStatParam = new ApsGasPipingRouteStat();
+ BeanUtils.copyProperties(apsGasPipingRouteStat,queryStatParam);
+ queryStatParam.setMajor(apsGasPipingRouteStat.getMajor());
+ queryStatParam.setPlant(apsGasPipingRouteStat.getPlant());
+ apsGasPipingRouteStats = apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(queryStatParam);
+ //鏍规嵁寮�宸ユ棩杩涜鍗囧簭鎺掑簭
+ apsGasPipingRouteStats.sort((a, b)->a.getProcessPlanStartDay().compareTo(b.getProcessPlanStartDay()));
+ //宸ュ簭寮�宸ユ棩鏈�
+ String planStartDate = "";
+ //缁熻鎵�鏈夊伐搴忓搴旂殑寮�宸ユ椂闂�
+ for (ApsGasPipingRouteStat apsGasPipingRouteStatTemp : apsGasPipingRouteStats) {
+ if(processMap.containsKey(apsGasPipingRouteStatTemp.getProcessName())){
+ planStartDate = simpleDateFormat.format(apsGasPipingRouteStatTemp.getProcessPlanStartDay());
+ if("month".equals(apsGasPipingRouteStat.getSearchType())){
+ planStartDate = planStartDate+"-01";
+ }
+ ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat();
+ apsResourceDateStat.setPlanDay(LocalDate.parse(planStartDate, formatter));
+ apsResourceDateStat.setResourceName(apsGasPipingRouteStatTemp.getProcessName());
+ apsResourceDateStat.setPlant(apsGasPipingRouteStatTemp.getPlant());
+ //鏌ヨ姘旀煖绠¤矾浜ц兘瑙勫垝琛�
+ String capacityKey = apsGasPipingRouteStatTemp.getProcessName() + "-" + apsGasPipingRouteStatTemp.getPlant() + "-" + planStartDate.substring(0, 7);
+ apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey)!=null?apsGasPipingPlanMap.get(capacityKey).getDayProduceAllNum():new BigDecimal(0));
+ //鏌ヨ鏂欏彿宸ュ簭浜ц兘琛�
+ 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));
+ }
+
+ List<ApsResourceDateStat> apsResourceDateStatList = processMap.get(apsGasPipingRouteStatTemp.getProcessName());
+ apsResourceDateStatList.add(apsResourceDateStat);
+ processMap.put(apsGasPipingRouteStatTemp.getProcessName(), apsResourceDateStatList);
+ }
+ }
+ //鑱氬悎姣忛亾宸ュ簭鐨勫紑宸ユ椂闂村拰浜ц兘
+ for (Map.Entry<String, List<ApsResourceDateStat>> entry : processMap.entrySet()) {
+ String processName = entry.getKey();
+ List<ApsResourceDateStat> apsResourceDateStatList = entry.getValue();
+
+ if("day".equals(apsGasPipingRouteStat.getSearchType())) {
+ // 鎸夊ぉ缁熻鏃朵繚鎸佸師鏈夐�昏緫锛屼笉鎸夊伐鍘傚垎缁�
+ LinkedHashMap<String, ApsResourceDateStat> dayMap = new LinkedHashMap<>();
+
+ // 棣栧厛锛屼负鎵�鏈夋棩鏈熷垱寤哄垵濮嬭褰�
+ for(String date : startPlanTimeSet) {
+ ApsResourceDateStat initStat = new ApsResourceDateStat();
+ initStat.setPlanDay(LocalDate.parse(date, formatter));
+ initStat.setResourceName(processName);
+ initStat.setResourceGroupName(processName);
+ initStat.setRequireTimes(new BigDecimal(0));
+ String capacityKey = processName + "-" + date.substring(0,7);
+ initStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey)!=null?apsGasPipingPlanMap.get(capacityKey).getDayProduceAllNum():new BigDecimal(0));
+ initStat.setCapacityLoad(new BigDecimal(0));
+ dayMap.put(date, initStat);
+ }
+
+ // 鐒跺悗澶勭悊瀹為檯鏁版嵁
+ for (ApsResourceDateStat apsResourceDateStat : apsResourceDateStatList) {
+ String dateKey = apsResourceDateStat.getPlanDay().toString();
+ if(dayMap.containsKey(dateKey)){
+ ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(dateKey);
+ String capacityKey = processName + "-"+ apsResourceDateStat.getPlant() + "-" + dateKey.substring(0,7);
+ apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(capacityKey)!=null?apsGasPipingPlanMap.get(capacityKey).getDayProduceAllNum():new BigDecimal(0));
+ apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes().add(apsResourceDateStat.getRequireTimes()));
+ if(apsResourceDateStatTemp.getDesignTimes().compareTo(BigDecimal.ZERO) > 0){
+ apsResourceDateStatTemp.setCapacityLoad(apsResourceDateStatTemp.getRequireTimes()
+ .divide(apsResourceDateStatTemp.getDesignTimes(), 2, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal(100)));
+ }else{
+ apsResourceDateStatTemp.setCapacityLoad(new BigDecimal(0));
+ }
+ apsResourceDateStatTemp.setResourceGroupName(processName);
+ apsResourceDateStatTemp.setPlanDay(apsResourceDateStat.getPlanDay());
+ dayMap.put(dateKey, apsResourceDateStatTemp);
+ }
+ }
+
+ List<ApsResourceDateStat> tempList = new ArrayList<>(dayMap.values());
+ HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
+ temp.put(processName, tempList);
+ processList.add(temp);
+ } else {
+ // 鎸夋湀缁熻鏃舵墠鎸夊伐鍘傚垎缁�
+ if (apsResourceDateStatList.isEmpty()) {
+ // 浠庝骇鑳借鍒掓暟鎹腑鑾峰彇鎵�鏈夌殑宸ュ巶
+ Set<String> plants = apsGasPipelineCapacityPlanList.stream()
+ .filter(plan -> plan.getProcessName().equals(processName))
+ .map(ApsGasPipelineCapacityPlan::getOrgCode)
+ .filter(orgCode -> orgCode != null && !orgCode.trim().isEmpty())
+ .collect(Collectors.toSet());
+
+ // 濡傛灉娌℃湁鎵惧埌浠讳綍鏈夋晥宸ュ巶锛岃烦杩囪繖涓伐搴�
+ if (plants.isEmpty()) {
+ continue;
+ }
+
+ // 涓烘瘡涓伐鍘傚垱寤虹┖璁板綍
+ for (String plant : plants) {
+ LinkedHashMap<String, ApsResourceDateStat> dayMap = new LinkedHashMap<>();
+ // 涓烘瘡涓湀浠藉垱寤鸿褰�
+ for(String monthDate : startPlanTimeSet) {
+ String tempTime = monthDate + "-01";
+ ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat();
+ apsResourceDateStat.setPlanDay(LocalDate.parse(tempTime, formatter));
+ apsResourceDateStat.setResourceName(processName);
+ apsResourceDateStat.setResourceGroupName(processName + "-" + plant);
+ apsResourceDateStat.setPlant(plant);
+ apsResourceDateStat.setRequireTimes(new BigDecimal(0));
+ String capacityKey = processName + "-" + plant + "-" + monthDate;
+ apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey)!=null?apsGasPipingPlanMap.get(capacityKey).getMonthProduceAllNum():new BigDecimal(0));
+ apsResourceDateStat.setCapacityLoad(new BigDecimal(0));
+ dayMap.put(monthDate, apsResourceDateStat);
+ }
+ List<ApsResourceDateStat> tempList = new ArrayList<>(dayMap.values());
+ HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
+ temp.put(processName + "_" + plant, tempList);
+ processList.add(temp);
+ }
+ } else {
+ // 鎸夊伐鍘傚垎缁勶紝骞惰繃婊ゆ帀plant涓簄ull鎴栫┖瀛楃涓茬殑璁板綍
+ Map<String, List<ApsResourceDateStat>> plantGroups = apsResourceDateStatList.stream()
+ .filter(stat -> stat.getPlant() != null && !stat.getPlant().trim().isEmpty())
+ .collect(groupingBy(ApsResourceDateStat::getPlant));
+
+ // 濡傛灉杩囨护鍚庢病鏈夋湁鏁堢殑宸ュ巶鏁版嵁锛岃烦杩囪繖涓伐搴�
+ if (plantGroups.isEmpty()) {
+ continue;
+ }
+
+ // 瀵规瘡涓伐鍘傜殑鏁版嵁杩涜澶勭悊
+ for (Map.Entry<String, List<ApsResourceDateStat>> plantEntry : plantGroups.entrySet()) {
+ String plant = plantEntry.getKey();
+ // 鍐嶆纭plant涓嶄负绌�
+ if (plant == null || plant.trim().isEmpty()) {
+ continue;
+ }
+ List<ApsResourceDateStat> plantStats = plantEntry.getValue();
+ LinkedHashMap<String, ApsResourceDateStat> dayMap = new LinkedHashMap<>();
+
+ // 棣栧厛涓烘墍鏈夋湀浠藉垱寤哄垵濮嬭褰�
+ for(String monthDate : startPlanTimeSet) {
+ String tempTime = monthDate + "-01";
+ ApsResourceDateStat initStat = new ApsResourceDateStat();
+ initStat.setPlanDay(LocalDate.parse(tempTime, formatter));
+ initStat.setResourceName(processName);
+ initStat.setResourceGroupName(processName + "-" + plant);
+ initStat.setPlant(plant);
+ initStat.setRequireTimes(new BigDecimal(0));
+ String capacityKey = processName + "-" + plant + "-" + monthDate;
+ initStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey)!=null?apsGasPipingPlanMap.get(capacityKey).getMonthProduceAllNum():new BigDecimal(0));
+ initStat.setCapacityLoad(new BigDecimal(0));
+ dayMap.put(monthDate, initStat);
+ }
+
+ // 鐒跺悗澶勭悊瀹為檯鏁版嵁
+ for (ApsResourceDateStat stat : plantStats) {
+ String monthKey = stat.getPlanDay().toString().substring(0, 7);
+ if (dayMap.containsKey(monthKey)) {
+ ApsResourceDateStat existingStat = dayMap.get(monthKey);
+ String capacityKey = processName + "-" + plant + "-" + monthKey;
+ existingStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey)!=null?apsGasPipingPlanMap.get(capacityKey).getMonthProduceAllNum():new BigDecimal(0));
+ existingStat.setRequireTimes(existingStat.getRequireTimes().add(stat.getRequireTimes()));
+ if(existingStat.getDesignTimes().compareTo(BigDecimal.ZERO) > 0){
+ existingStat.setCapacityLoad(existingStat.getRequireTimes()
+ .divide(existingStat.getDesignTimes(), 2, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal(100)));
+ }
+ }
+ }
+
+ List<ApsResourceDateStat> tempList = new ArrayList<>(dayMap.values());
+ HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>();
+ temp.put(processName + "_" + plant, tempList);
+ processList.add(temp);
+ }
+ }
+ }
+ }
+ //鎺掑簭鏃堕棿鏍囬
+ List<String> sortedStartPlanTimeList = new ArrayList<>(startPlanTimeSet);
+ Collections.sort(sortedStartPlanTimeList);
+ for (int i=0;i<processList.size();i++){
+ HashMap<String, List<ApsResourceDateStat>> temp = processList.get(i);
+ for (Map.Entry<String, List<ApsResourceDateStat>> entry : temp.entrySet()){
+ List<ApsResourceDateStat> apsResourceDateStatList = entry.getValue();
+ 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));
+ String[] keyParts = key.split("-");
+ String processNamePart = keyParts[0];
+ String plantPart = keyParts[1];
+ String capacityKey = processNamePart + "-" + plantPart + "-" + tempTime.substring(0,7);
+ if ("month".equals(apsGasPipingRouteStat.getSearchType())) {
+ apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey) != null ? apsGasPipingPlanMap.get(capacityKey).getMonthProduceAllNum() : new BigDecimal(0));
+ } else {
+ apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(capacityKey) != null ? apsGasPipingPlanMap.get(capacityKey).getDayProduceAllNum() : new BigDecimal(0));
+ }
+ apsResourceDateStat.setRequireTimes(new BigDecimal(0));
+ apsResourceDateStat.setCapacityLoad(new BigDecimal(0));
+ apsResourceDateStat.setResourceName(processNamePart);
+ apsResourceDateStat.setResourceGroupName(key);
+ apsResourceDateStat.setPlant(plantPart);
+ apsResourceDateStatList.add(apsResourceDateStat);
+ crtList.add(apsResourceDateStat);
+ }
+ temp.put(entry.getKey(), crtList);
processList.set(i, temp);
}
}
@@ -463,4 +800,213 @@
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;
+ }
+
+ @Override
+ public void saveGasPipingProcessStat(){
+ try {
+ String batchNum = IdUtils.fastSimpleUUID();
+ List<ApsGasPipingRouteStat> tempList = apsGasPipingRouteStatMapper.queryTempStat();
+ Map<String, List<ApsGasPipingRouteStat>> groupByOrderNo = tempList.stream().collect(groupingBy(ApsGasPipingRouteStat::getWorkOrderNo));
+ Boolean hasBefore = false;
+ LocalDateTime now = LocalDateTime.now();
+ for (Map.Entry<String, List<ApsGasPipingRouteStat>> entry : groupByOrderNo.entrySet()) {
+ List<ApsGasPipingRouteStat> statPerOrder = entry.getValue();
+ /*num 涓烘牴鎹畬宸ユ椂闂存帓搴忓嚭鐨勫簭鍙凤紝鎸夋鎺掑簭锛屽彲淇濊瘉鏄寜瀹屽伐鏃堕棿鍊掑彊鎺掑垪*/
+ statPerOrder.sort((a, b)->a.getNum().compareTo(b.getNum()));
+ ApsGasPipingRouteStat last=null;
+ for (int i = 0; i <statPerOrder.size(); i++) {
+ ApsGasPipingRouteStat stat = statPerOrder.get(i);
+ stat.setId(IdUtils.fastSimpleUUID());
+ stat.setBatchNumber(batchNum);
+ stat.setCreateBy(SecurityUtils.getUsername());
+ stat.setWarning(false);
+ if(i==0){
+ Date orderPlanEndDay = stat.getOrderPlanEndDay();
+ LocalDateTime transLocalDateTime = transLocalDateTime(orderPlanEndDay);
+ LocalTime endOfDay = LocalTime.of(23, 59, 59);
+ LocalDateTime orderPlanEndDayLocalDateTime = LocalDateTime.of( transLocalDateTime.toLocalDate(), endOfDay);
+ if(orderPlanEndDayLocalDateTime.isBefore(now)){
+ hasBefore = true;
+ stat.setWarning(true);
+ stat.setProcessPlanEndDay(transDate(now));
+ stat.setProcessPlanStartDay(transDate(now));
+ }else {
+ /*璁″垝瀹屽伐鏃�=閽i噾璁″垝宸ュ崟瀹屾垚鏃堕棿*/
+ stat.setProcessPlanEndDay(transDate(orderPlanEndDayLocalDateTime));
+ /*璁″垝寮�宸ユ棩=閽i噾璁″垝宸ュ崟瀹屾垚鏃堕棿 - 宸ュ簭鎬诲伐鏃�*/
+ long seconds = stat.getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue();
+ LocalDateTime lastPlanStartDt = orderPlanEndDayLocalDateTime.minusSeconds(seconds);
+ if(lastPlanStartDt.isBefore(now)){
+ hasBefore = true;
+ stat.setProcessPlanStartDay(transDate(now));
+ }else {
+ stat.setProcessPlanStartDay(transDate(lastPlanStartDt));
+ }
+ }
+ }
+ /*褰撳伐鑹哄伐搴忓彿 >= 宸ュ崟褰撳墠宸ュ簭 浠h〃鏄湭鏉ュ伐搴忥紝鎵嶈繘琛岃鍒掑紑宸ユ棩 鍜岃鍒掑畬宸ユ棩鐨勮绠�
+ * 褰撳伐鑹哄伐搴忓彿 < 宸ュ崟褰撳墠宸ュ簭 杩囧幓宸ュ簭锛屼笉杩涜璁$畻
+ * */
+ if( stat.getRouteProcessNumber().compareTo(stat.getCurrentProcessNumber())>=0){
+ /*鍊掓帓鏃� 涓嬩竴閬撳伐搴忓瓨鍦� 姣斿綋鍓嶆椂闂村皬鐨勮鍒掓椂闂达紝鍒欏綋鍓嶈鍒掑紑濮嬪拰缁撴潫鏃堕棿閮芥槸褰撳墠鏃堕棿*/
+ if(hasBefore){
+ stat.setWarning(true);
+ stat.setProcessPlanEndDay(transDate(now));
+ stat.setProcessPlanStartDay(transDate(now));
+ }else{
+ /*涓嬩竴閬撳伐搴忚鍒掓椂闂撮兘姝e父鏃讹紝*/
+ if (last != null) {
+ /*褰撳墠宸ュ簭缁撴潫鏃堕棿=涓嬩竴閬撳伐搴忕殑寮�濮嬫椂闂�*/
+ stat.setProcessPlanEndDay(last.getProcessPlanStartDay());
+ /*寮�濮嬫椂闂�=缁撴潫鏃堕棿-鎬诲伐鏃�*/
+ long seconds = stat.getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue();
+ LocalDateTime crtStartDt = transLocalDateTime(last.getProcessPlanStartDay()).minusSeconds(seconds);
+ /*濡傛灉寮�濮嬫椂闂村皬浜庡綋鍓嶆椂闂�*/
+ if(crtStartDt.isBefore(now)){
+ hasBefore=true;
+ stat.setWarning(true);
+ stat.setProcessPlanStartDay(transDate(now));
+ }else {
+ stat.setProcessPlanStartDay(transDate(crtStartDt));
+ }
+ }
+ }
+ }
+ last = stat;
+ apsGasPipingRouteStatMapper.insertApsGasPipingRouteStat(stat);
+ }
+ hasBefore=false;
+
+ }
+ apsGasPipingRouteStatMapper.deleteApsGasPipingRouteStatByBatchNum(batchNum);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ };
+
+ private Date transDate(LocalDateTime localDateTime){
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ private LocalDateTime transLocalDateTime(Date date){
+ return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
+ }
+
+ /**
+ * 淇濆瓨閽i噾缁熻鏁版嵁
+ */
+ @Transactional
+ @Override
+ public void saveGasPipingRoutStateList() {
+ String batchNum = IdUtils.fastSimpleUUID();
+ List<ApsGasPipingRouteStat> tempList = apsGasPipingRouteStatMapper.queryTempStat();
+ Map<String, List<ApsGasPipingRouteStat>> groupByOrderNo = tempList.stream().collect(groupingBy(ApsGasPipingRouteStat::getWorkOrderNo));
+
+ LocalDateTime now = LocalDateTime.now();
+ /*寰呬繚瀛樼殑鏁版嵁*/
+ List<ApsGasPipingRouteStat> cptStateList = new ArrayList<>();
+ for (Map.Entry<String, List<ApsGasPipingRouteStat>> entry : groupByOrderNo.entrySet()) {
+ List<ApsGasPipingRouteStat> statPerOrder = entry.getValue();
+ /*num 涓烘牴鎹畬宸ユ椂闂存帓搴忓嚭鐨勫簭鍙凤紝鎸夋鎺掑簭锛屽彲淇濊瘉鏄寜瀹屽伐鏃堕棿鍊掑彊鎺掑垪*/
+ statPerOrder.sort((a, b)->a.getNum().compareTo(b.getNum()));
+ ApsGasPipingRouteStat last=null;
+ /*褰撳墠宸ュ簭鏄惁瀛樺湪 璁″垝寮�宸ユ椂闂� 灏忎簬 褰撳墠鐨勬椂闂达紝濡傛灉瀛樺湪鍚庣画璁剧疆涓哄綋鍓嶆椂闂�*/
+ boolean hasBefore = false;
+ for (int i = 0; i <statPerOrder.size(); i++) {
+ ApsGasPipingRouteStat stat = statPerOrder.get(i);
+ stat.setId(String.valueOf(IdUtil.getSnowflakeNextId()));
+ stat.setBatchNumber(batchNum);
+ stat.setCreateTime(DateUtils.getNowDate());
+ stat.setCreateBy(SecurityUtils.getUsername());
+ stat.setWarning(false);
+ stat.setDelFlag("0");
+ if(i==0){
+ Date orderPlanEndDay = stat.getOrderPlanEndDay();
+ LocalDateTime transLocalDateTime = transLocalDateTime(orderPlanEndDay);
+ LocalTime endOfDay = LocalTime.of(23, 59, 59);
+ LocalDateTime orderPlanEndDayLocalDateTime = LocalDateTime.of( transLocalDateTime.toLocalDate(), endOfDay);
+ if(orderPlanEndDayLocalDateTime.isBefore(now)){
+ hasBefore = true;
+ stat.setWarning(true);
+ stat.setProcessPlanEndDay(transDate(now));
+ stat.setProcessPlanStartDay(transDate(now));
+ }else {
+ /*璁″垝瀹屽伐鏃�=閽i噾璁″垝宸ュ崟瀹屾垚鏃堕棿*/
+ stat.setProcessPlanEndDay(transDate(orderPlanEndDayLocalDateTime));
+ /*璁″垝寮�宸ユ棩=閽i噾璁″垝宸ュ崟瀹屾垚鏃堕棿 - 宸ュ簭鎬诲伐鏃�*/
+ long seconds = stat.getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue();
+ LocalDateTime lastPlanStartDt = orderPlanEndDayLocalDateTime.minusSeconds(seconds);
+ if(lastPlanStartDt.isBefore(now)){
+ hasBefore = true;
+ stat.setProcessPlanStartDay(transDate(now));
+ }else {
+ stat.setProcessPlanStartDay(transDate(lastPlanStartDt));
+ }
+ }
+ }
+ /*褰撳伐鑹哄伐搴忓彿 >= 宸ュ崟褰撳墠宸ュ簭 浠h〃鏄湭鏉ュ伐搴忥紝鎵嶈繘琛岃鍒掑紑宸ユ棩 鍜岃鍒掑畬宸ユ棩鐨勮绠�
+ * 褰撳伐鑹哄伐搴忓彿 < 宸ュ崟褰撳墠宸ュ簭 杩囧幓宸ュ簭锛屼笉杩涜璁$畻
+ * */
+ if( stat.getRoadProcessNumber().compareTo(stat.getCurrentProcessNumber())>=0){
+ /*鍊掓帓鏃� 涓嬩竴閬撳伐搴忓瓨鍦� 姣斿綋鍓嶆椂闂村皬鐨勮鍒掓椂闂达紝鍒欏綋鍓嶈鍒掑紑濮嬪拰缁撴潫鏃堕棿閮芥槸褰撳墠鏃堕棿*/
+ if(hasBefore){
+ stat.setWarning(true);
+ stat.setProcessPlanEndDay(transDate(now));
+ stat.setProcessPlanStartDay(transDate(now));
+ }else{
+ /*涓嬩竴閬撳伐搴忚鍒掓椂闂撮兘姝e父鏃讹紝*/
+ if (last != null) {
+ /*褰撳墠宸ュ簭缁撴潫鏃堕棿=涓嬩竴閬撳伐搴忕殑寮�濮嬫椂闂�*/
+ stat.setProcessPlanEndDay(last.getProcessPlanStartDay());
+ /*寮�濮嬫椂闂�=缁撴潫鏃堕棿-鎬诲伐鏃�*/
+ long seconds = stat.getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue();
+ LocalDateTime crtStartDt = transLocalDateTime(last.getProcessPlanStartDay()).minusSeconds(seconds);
+ /*濡傛灉寮�濮嬫椂闂村皬浜庡綋鍓嶆椂闂�*/
+ if(crtStartDt.isBefore(now)){
+ hasBefore=true;
+ stat.setWarning(true);
+ stat.setProcessPlanStartDay(transDate(now));
+ }else {
+ stat.setProcessPlanStartDay(transDate(crtStartDt));
+ }
+ }
+ }
+ }
+ if(stat.getProcessPlanStartDay()!=null){
+ String[] strNow = new SimpleDateFormat("yyyy-MM-dd").format(stat.getProcessPlanStartDay()).toString().split("-");
+ stat.setPlanStartYear(strNow[0]);
+ stat.setPlanStartMonth(strNow[1]);
+ stat.setPlanStartDay(strNow[2]);
+ }
+ last = stat;
+ cptStateList.add(stat);
+ }
+ }
+ // 鎵归噺鎻掑叆浠ユ彁楂樻�ц兘
+ if (!cptStateList.isEmpty()) {
+ int batchSize = 1000;
+ int size = cptStateList.size();
+ for (int i = 0; i < size; i += batchSize) {
+ int end = Math.min(i + batchSize, size);
+ List<ApsGasPipingRouteStat> batch = cptStateList.subList(i, end);
+ apsGasPipingRouteStatMapper.insertApsGasPipingRouteStatBatch(batch);
+ log.info("鎵归噺鎻掑叆鏁版嵁锛屽紑濮嬩綅缃細{}锛岀粨鏉熶綅缃細{}", i, end);
+ }
+ }
+ apsGasPipingRouteStatMapper.deleteApsGasPipingRouteStatByBatchNum(batchNum);
+ log.info("鎵归噺鎻掑叆鏁版嵁瀹屾垚,batchNum:"+batchNum);
+ }
+
}
--
Gitblit v1.9.3