浏览代码

“日报;小时划分排除节假日”

yangjunfeng 1 年之前
父节点
当前提交
1f61ca79fb

+ 9 - 8
snws-gps/snws-gps-boot/src/main/java/com/tofly/gpsboot/service/fill/impl/FillMonthServiceImpl.java

@@ -31,10 +31,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -206,11 +203,13 @@ public class FillMonthServiceImpl extends ServiceImpl<FillMonthMapper, FillMonth
             BeanUtils.copyProperties(fillVo,fillVoRes);
             fillVoRes.setRecordTime(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"));
             if (CollUtil.isNotEmpty(fillEcs)) {
-                List<FillEc> fillEcsFinal = fillEcs.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))).collect(Collectors.toList());
+                List<FillEc> fillEcsFinal = fillEcs.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))
+                        && Objects.equals(e.getBelongStationId(), fillVo.getBelongStationId())).collect(Collectors.toList());
                 fillVoRes.setElectro(CollUtil.isNotEmpty(fillEcsFinal) ? fillEcsFinal.get(0).getElectro() : "0");
             }
             if (CollUtil.isNotEmpty(fillSludgeDeals)) {
-                List<FillSludgeDeal> fillSludgeDealsFinal = fillSludgeDeals.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))).collect(Collectors.toList());
+                List<FillSludgeDeal> fillSludgeDealsFinal = fillSludgeDeals.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))
+                        && Objects.equals(e.getBelongStationId(), fillVo.getBelongStationId())).collect(Collectors.toList());
                 fillVoRes.setDaySludgeDehydration(CollUtil.isNotEmpty(fillSludgeDealsFinal) ? fillSludgeDealsFinal.get(0).getDaySludgeDehydration() : "0");
                 fillVoRes.setDaySludgeTransfer(CollUtil.isNotEmpty(fillSludgeDealsFinal) ? fillSludgeDealsFinal.get(0).getDaySludgeTransfer() : "0");
                 fillVoRes.setSludgeWaterCutRate(CollUtil.isNotEmpty(fillSludgeDealsFinal) ? fillSludgeDealsFinal.get(0).getSludgeWaterCutRate() : "0");
@@ -219,12 +218,14 @@ public class FillMonthServiceImpl extends ServiceImpl<FillMonthMapper, FillMonth
 //                List<FillSludgeTransfer> fillSludgeTransfersFinal = fillSludgeTransfers.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))).collect(Collectors.toList());
 //            }
             if (CollUtil.isNotEmpty(fillStcs)) {
-                List<FillStc> fillStcsFinal = fillStcs.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))).collect(Collectors.toList());
+                List<FillStc> fillStcsFinal = fillStcs.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))
+                        && Objects.equals(e.getBelongStationId(), fillVo.getBelongStationId())).collect(Collectors.toList());
                 fillVoRes.setDayIntoWater(CollUtil.isNotEmpty(fillStcsFinal) ? fillStcsFinal.get(0).getDayIntoWater() : "0");
                 fillVoRes.setDayOutWater(CollUtil.isNotEmpty(fillStcsFinal) ? fillStcsFinal.get(0).getDayOutWater() : "0");
             }
             if (CollUtil.isNotEmpty(fillWaters)) {
-                List<FillWater> fillWatersFinal = fillWaters.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))).collect(Collectors.toList());
+                List<FillWater> fillWatersFinal = fillWaters.stream().filter(e -> DateUtil.format(e.getRecordTime(), "yyyy-MM-dd HH:mm:ss").equals(DateUtil.format(info, "yyyy-MM-dd HH:mm:ss"))
+                        && Objects.equals(e.getBelongStationId(), fillVo.getBelongStationId())).collect(Collectors.toList());
                 fillVoRes.setBod5(CollUtil.isNotEmpty(fillWatersFinal) ? fillWatersFinal.get(0).getBod5() : "0");
                 fillVoRes.setBod5Out(CollUtil.isNotEmpty(fillWatersFinal) ? fillWatersFinal.get(0).getBod5Out() : "0");
                 fillVoRes.setCodCr(CollUtil.isNotEmpty(fillWatersFinal) ? fillWatersFinal.get(0).getCodCr() : "0");

+ 22 - 4
snws-gps/snws-gps-boot/src/main/java/com/tofly/gpsboot/util/DateTimeUtil.java

@@ -467,18 +467,36 @@ public class DateTimeUtil {
         }
     }
 
-    public static Map<LocalDateTime,LocalDateTime> getCustomHourPeriodMap( LocalDateTime startTime , LocalDateTime endTime , Integer intervalHour){
+    public static Map<LocalDateTime,LocalDateTime> getCustomHourPeriodMap( LocalDateTime startTime, LocalDateTime endTime, Integer intervalHour){
         Map<LocalDateTime,LocalDateTime> resultMap = new LinkedHashMap<>(12);
         while (true){
-            LocalDateTime localDateTime = startTime.plusHours(intervalHour);
-            if(localDateTime.isBefore(endTime)){
+            while (startTime.getHour() >= 18 || startTime.getHour() < 9) {
+                startTime = startTime.plusHours(1);
+            }
+            DayOfWeek dayOfWeek = startTime.getDayOfWeek();
+            if (dayOfWeek.getValue() == 6) {
+                startTime = startTime.plusDays(2);
+            } else if (dayOfWeek.getValue() == 7) {
+                startTime = startTime.plusDays(1);
+            }
+            LocalDateTime localDateTime = getWorkHourDate(startTime, intervalHour);
+            if(localDateTime.isBefore(endTime)) {
                 resultMap.put(startTime,localDateTime);
                 startTime = localDateTime;
             }else {
-                resultMap.put(startTime,endTime);
                 return resultMap;
             }
         }
     }
 
+    private static LocalDateTime getWorkHourDate(LocalDateTime localDateTime, Integer intervalHour) {
+        for (int i = 0; i < intervalHour; i++) {
+            localDateTime = localDateTime.plusHours(1);
+            if (localDateTime.getHour() == 18) {
+                return localDateTime;
+            }
+        }
+        return localDateTime;
+    }
+
 }