From f69073b835f1a0c66590130e1830edcdd75ebb8a Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 02 十一月 2024 16:59:35 +0800
Subject: [PATCH] 去掉dmpvar

---
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java |   78 +++++++++++++++++++--------------------
 1 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java
index dba1f4a..8a987b7 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/SuperAggregateStateServiceImpl.java
@@ -5,6 +5,7 @@
 import java.sql.Timestamp;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -19,14 +20,14 @@
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.qianwen.core.tool.utils.DateTimeUtil;
 import com.qianwen.core.tool.utils.DateUtil;
 import com.qianwen.core.tool.utils.Func;
 import com.qianwen.smartman.common.constant.CommonConstant;
 import com.qianwen.smartman.common.constant.DateConstant;
 import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
-import com.qianwen.smartman.common.utils.LocalDateUtil;
-import com.qianwen.smartman.modules.cps.entity.Workstation;
-import com.qianwen.smartman.modules.cps.service.IWorkstationService;
+import com.qianwen.smartman.modules.smis.entity.Workstation;
+import com.qianwen.smartman.modules.smis.service.IWorkstationService;
 import com.qianwen.smartman.modules.mdc.entity.SuperAggregate;
 import com.qianwen.smartman.modules.mdc.entity.SuperAggregateState;
 import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums;
@@ -56,9 +57,13 @@
     public List<SuperAggregateState> getStatusData(List<Long> workstationIds, StatisticalMethodEnum statisticalMethod, LocalDate startDate, LocalDate endDate) {
         List<SuperAggregateState> statusDataList;
         if (StatisticalMethodEnum.SHIFT.equals(statisticalMethod) || StatisticalMethodEnum.DAY.equals(statisticalMethod) || StatisticalMethodEnum.WEEK.equals(statisticalMethod) || StatisticalMethodEnum.MONTH.equals(statisticalMethod)) {
-            statusDataList = this.baseMapper.getStatusDataByFactoryDate(workstationIds, LocalDateTimeUtil.format(startDate, "yyyyMMdd"), LocalDateTimeUtil.format(endDate, "yyyyMMdd"));
+            statusDataList = this.baseMapper.getStatusDataByFactoryDate(workstationIds, Integer.parseInt(LocalDateTimeUtil.format(startDate, "yyyyMMdd")), Integer.parseInt(LocalDateTimeUtil.format(endDate, "yyyyMMdd")));
         } else {
-            statusDataList = this.baseMapper.getStatusData(workstationIds, LocalDateTimeUtil.format(startDate, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endDate.plusDays(1L), DateConstant.PATTERN_DATE_TIME));
+            //statusDataList = this.baseMapper.getStatusData(workstationIds, LocalDateTimeUtil.format(startDate, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endDate.plusDays(1L), DateConstant.PATTERN_DATE_TIME));
+        	LocalDateTime startTime = LocalDateTime.of(startDate, LocalTime.MIN);
+        	LocalDateTime endTime = LocalDateTime.of(endDate.plusDays(1L), LocalTime.MIN);
+        	//statusDataList = this.baseMapper.getStatusData(workstationIds, startDate,endDate.plusDays(1L));
+        	statusDataList = this.baseMapper.getStatusData(workstationIds, DateTimeUtil.toDate(startTime),DateTimeUtil.toDate(endTime));
         }
         return buildDuration(statusDataList);
     }
@@ -68,29 +73,38 @@
     	//绋煎姩鐜囨煡璇�
         List<SuperAggregateState> statusDataList;
         if (StatisticalMethodEnum.SHIFT.equals(statisticalMethod) || StatisticalMethodEnum.DAY.equals(statisticalMethod) || StatisticalMethodEnum.WEEK.equals(statisticalMethod) || StatisticalMethodEnum.MONTH.equals(statisticalMethod)) {
-            statusDataList = this.aggregateStateFeedbackMapper.getStatusDataByFactoryDate(workstationIds, LocalDateTimeUtil.format(startDate, "yyyyMMdd"), LocalDateTimeUtil.format(endDate, "yyyyMMdd"));
+            //statusDataList = this.aggregateStateFeedbackMapper.getStatusDataByFactoryDate(workstationIds, LocalDateTimeUtil.format(startDate, "yyyyMMdd"), LocalDateTimeUtil.format(endDate, "yyyyMMdd"));
+        	int startFactoryDate = Integer.parseInt(LocalDateTimeUtil.format(startDate, "yyyyMMdd"));
+        	int endFactoryDate = Integer.parseInt(LocalDateTimeUtil.format(endDate, "yyyyMMdd"));
+        	statusDataList = this.aggregateStateFeedbackMapper.getStatusDataByFactoryDate(workstationIds, startFactoryDate, endFactoryDate);
         } else {
-            statusDataList = this.aggregateStateFeedbackMapper.getStatusData(workstationIds, LocalDateTimeUtil.format(startDate, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endDate.plusDays(1L), DateConstant.PATTERN_DATE_TIME));
+            //statusDataList = this.aggregateStateFeedbackMapper.getStatusData(workstationIds, LocalDateTimeUtil.format(startDate, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endDate.plusDays(1L), DateConstant.PATTERN_DATE_TIME));
+        	LocalDateTime startTime = LocalDateTime.of(startDate, LocalTime.MIN);
+        	LocalDateTime endTime = LocalDateTime.of(endDate.plusDays(1L), LocalTime.MIN);
+        	statusDataList = this.aggregateStateFeedbackMapper.getStatusData(workstationIds, DateTimeUtil.toDate(startTime),DateTimeUtil.toDate(endTime));
         }
         return buildDuration(statusDataList);
     }
 
     @Override
     public List<SuperAggregateState> getStatusByCondition(List<Long> workstationIds, LocalDateTime startTime, LocalDateTime endTime) {
-        List<SuperAggregateState> statusDataList = this.baseMapper.getStatusData(workstationIds, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME));
+        //List<SuperAggregateState> statusDataList = this.baseMapper.getStatusData(workstationIds, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME));
+    	List<SuperAggregateState> statusDataList = this.baseMapper.getStatusData(workstationIds,  DateTimeUtil.toDate(startTime), DateTimeUtil.toDate(endTime));
         return buildDuration(statusDataList);
     }
 
     @Override
     public List<SuperAggregateState> getStatusByTimeSection(List<Long> workstationIds, LocalDateTime startTime, LocalDateTime endTime) {
         //List<SuperAggregateState> statusDataList = this.baseMapper.getStatusDataByTimeSection(workstationIds, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME));
-    	List<SuperAggregateState> statusDataList = this.baseMapper.getStatusDataByTimeSection(workstationIds, startTime, endTime);
+    	
+    	List<SuperAggregateState> statusDataList = this.baseMapper.getStatusDataByTimeSection(workstationIds, DateTimeUtil.toDate(startTime), DateTimeUtil.toDate(endTime));
         return buildDuration(startTime, statusDataList);
     }
 
     @Override
     public List<StatusTimeTopVO> getStatusTimeByWcs(List<Long> workstationIds, LocalDateTime startTime, LocalDateTime endTime, Integer status, Integer top) {
         List<StatusTimeTopVO> voList = new ArrayList<>();
+        
         Map<Long, Workstation> workstationMap = this.workstationService.list(Wrappers.<Workstation>lambdaQuery()
         		.eq(Workstation::getStatus, CommonConstant.ENABLE)).stream().collect(Collectors.toMap(Workstation::getId, Function.identity()));
         /*
@@ -101,17 +115,15 @@
         }, Function.identity()));*/
         //List<SuperAggregateState> equipmentStatusDuration = this.baseMapper.getEquipmentStatusDuration(workstationIds, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME), status);
         
-        Date startTimeD = LocalDateUtil.localDateTimeToDate(startTime);
-        startTimeD = new Date(124,8,2);
-        Date endTimeD = LocalDateUtil.localDateTimeToDate(endTime);
-        endTimeD = new Date(124,8,3);
+       // Date startTimeD = LocalDateUtil.localDateTimeToDate(startTime);
+        //startTimeD = new Date(124,8,2);
+        //Date endTimeD = LocalDateUtil.localDateTimeToDate(endTime);
+        //endTimeD = new Date(124,8,3);
         
-        LocalDateTime startTime2 = LocalDateTime.of(2024, 9, 2, 1, 0);
-        LocalDateTime endTime2 = LocalDateTime.of(2024, 9, 3, 1, 0);
-        List<SuperAggregateState> equipmentStatusDuration = this.baseMapper.getEquipmentStatusDuration(workstationIds, startTime2, endTime2, status);
+        List<SuperAggregateState> equipmentStatusDuration = this.baseMapper.getEquipmentStatusDuration(workstationIds, DateTimeUtil.toDate(startTime), DateTimeUtil.toDate(endTime), status);
         
         List<SuperAggregateState> equipmentStatusDuration2 = FilterOffUtils.filterOffDay(equipmentStatusDuration, OpenTypeEnums.TIME_USED_ANALYSIS);
-        Map<Long, Long> timeMap = buildDuration(startTime2, equipmentStatusDuration2).stream().collect(Collectors.groupingBy(SuperAggregate::getWorkstationId, Collectors.summingLong(SuperAggregateState::getDurationCollect))).entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(top.intValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, java.util.LinkedHashMap::new));
+        Map<Long, Long> timeMap = buildDuration(startTime, equipmentStatusDuration2).stream().collect(Collectors.groupingBy(SuperAggregate::getWorkstationId, Collectors.summingLong(SuperAggregateState::getDurationCollect))).entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(top.intValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, java.util.LinkedHashMap::new));
         //yangys鏀逛簡buildDuration锛屽幓鎺変簡startTime鍙傛暟
         //Map<Long, Long> timeMap = buildDuration(equipmentStatusDuration2,ChronoUnit.SECONDS).stream().collect(Collectors.groupingBy(SuperAggregate::getWorkstationId, Collectors.summingLong(SuperAggregateState::getDurationCollect))).entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(top.intValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, java.util.LinkedHashMap::new));
         /*
@@ -137,10 +149,10 @@
 
     @Override
     public List<SuperAggregateState> getOeeAnalysis(List<Long> workStationIdList, LocalDateTime startTime, LocalDateTime endTime) {
-    	Date startTimeD = LocalDateUtil.localDateTimeToDate(startTime);
-        Date endTimeD = LocalDateUtil.localDateTimeToDate(endTime);
+    	//Date startTimeD = LocalDateUtil.localDateTimeToDate(startTime);
+        //Date endTimeD = LocalDateUtil.localDateTimeToDate(endTime);
         //List<SuperAggregateState> statusDataList = this.baseMapper.getEquipmentStatusDuration(workStationIdList, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME), null);
-        List<SuperAggregateState> statusDataList = this.baseMapper.getEquipmentStatusDuration(workStationIdList, startTime, endTime, null);
+        List<SuperAggregateState> statusDataList = this.baseMapper.getEquipmentStatusDuration(workStationIdList, DateTimeUtil.toDate(startTime), DateTimeUtil.toDate(endTime), null);
         return buildDuration(startTime, FilterOffUtils.filterOffDay(statusDataList, OpenTypeEnums.OEE));
     }
 
@@ -172,6 +184,7 @@
     @Override
     public List<SuperAggregateState> getDataByMonth(List<Long> ids, Integer year, List<Integer> monthList) {
         List<SuperAggregateState> data = this.baseMapper.getDataByMonth(ids, year, monthList);
+        
         return buildDuration(data);
     }
 
@@ -306,32 +319,16 @@
     private List<SuperAggregateState> buildDuration(List<SuperAggregateState> statusDataShift) {
         Date now = DateUtil.now();
         statusDataShift.forEach(x -> {
-            if (Func.isEmpty(x.getEndTime()) || x.getEndTime().toLocalDateTime().getYear()==1970) {
+            if (Func.isEmpty(x.getEndTime()) ) {//|| x.getEndTime().toLocalDateTime().getYear()==1970
                 x.setEndTime(new Timestamp(now.getTime()));
             }
             x.setDurationCollect(LocalDateTimeUtils.betweenTwoTime(x.getStartTime().toLocalDateTime(), x.getEndTime().toLocalDateTime(), ChronoUnit.MILLIS));
-            System.out.println(x);
+            //System.out.println(x);
         });
         return statusDataShift;
     }
 
-    /**
-     * 璁剧疆鏃堕棿宸�
-     * @param statusDataShift
-     * @param chUnit
-     * @return
-     */
-    private List<SuperAggregateState> buildDuration(List<SuperAggregateState> statusDataShift, ChronoUnit chUnit) {
-        Date now = DateUtil.now();
-        statusDataShift.forEach(x -> {
-            if (Func.isEmpty(x.getEndTime()) || x.getEndTime().toLocalDateTime().getYear()==1970) {
-                x.setEndTime(new Timestamp(now.getTime()));
-            }
-            x.setDurationCollect(LocalDateTimeUtils.betweenTwoTime(x.getStartTime().toLocalDateTime(), x.getEndTime().toLocalDateTime(), chUnit));
-            System.out.println("s="+x);
-        });
-        return statusDataShift;
-    }
+    
     
     private List<SuperAggregateState> buildDuration(LocalDateTime startTime, List<SuperAggregateState> statusDataShift) {
         Date now = DateUtil.now();
@@ -341,9 +338,10 @@
             }
             if (x.getStartTime().toLocalDateTime().isBefore(startTime)) {
                 x.setStartTime(Timestamp.valueOf(startTime));
+                x.setTime(Timestamp.valueOf(startTime));//杩欎釜鎵嶈捣浣滅敤锛実etStartTime鑾峰彇鐨勬槸time
             }
             x.setDurationCollect(LocalDateTimeUtils.betweenTwoTime(x.getStartTime().toLocalDateTime(), x.getEndTime().toLocalDateTime(), ChronoUnit.MILLIS));
-            System.out.println(x);
+            //System.out.println(x);
         });
         return statusDataShift;
     }

--
Gitblit v1.9.3