From d4020168658efdee89a633083cd9c14b06c4d863 Mon Sep 17 00:00:00 2001
From: zhangf <1603559716@qq.com>
Date: 星期三, 11 九月 2024 17:09:10 +0800
Subject: [PATCH] 修改消息推送时间间隔

---
 src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasWarnLogServiceImpl.java |  120 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 102 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasWarnLogServiceImpl.java b/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasWarnLogServiceImpl.java
index 1846dd5..8fda170 100644
--- a/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasWarnLogServiceImpl.java
+++ b/src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasWarnLogServiceImpl.java
@@ -8,17 +8,24 @@
 import com.gkhy.fourierSpecialGasMonitor.domain.account.entity.User;
 import com.gkhy.fourierSpecialGasMonitor.domain.account.enums.UserStatusEnum;
 import com.gkhy.fourierSpecialGasMonitor.domain.account.repository.jpa.UserRepository;
+import com.gkhy.fourierSpecialGasMonitor.entity.GasConcentration;
 import com.gkhy.fourierSpecialGasMonitor.entity.GasWarnLog;
-import com.gkhy.fourierSpecialGasMonitor.entity.MonitorDailyReport;
-import com.gkhy.fourierSpecialGasMonitor.entity.query.FindDailyReportPageQuery;
 import com.gkhy.fourierSpecialGasMonitor.entity.query.FindGasWarnLogPageQuery;
-import com.gkhy.fourierSpecialGasMonitor.entity.resp.FindDailyReportPageRespDTO;
-import com.gkhy.fourierSpecialGasMonitor.entity.resp.FindGasWarnLogPageRespDTO;
-import com.gkhy.fourierSpecialGasMonitor.entity.resp.FindGasWarnLogSmsUserPageRespDTO;
+import com.gkhy.fourierSpecialGasMonitor.entity.query.GasWarnTimesCountTimeSlotQuery;
+import com.gkhy.fourierSpecialGasMonitor.entity.query.WindRoseTimeSlotQuery;
+import com.gkhy.fourierSpecialGasMonitor.entity.req.GasWarnLogCountByTimeReqDTO;
+import com.gkhy.fourierSpecialGasMonitor.entity.req.GasWarnLogInfoReqDTO;
+import com.gkhy.fourierSpecialGasMonitor.entity.req.HandleGasWarnLogReqDTO;
+import com.gkhy.fourierSpecialGasMonitor.entity.req.WindRoseByTimeReqDTO;
+import com.gkhy.fourierSpecialGasMonitor.entity.resp.*;
+import com.gkhy.fourierSpecialGasMonitor.enums.GasWarnTimesCountEnum;
 import com.gkhy.fourierSpecialGasMonitor.enums.WarnHandleStatusEnum;
+import com.gkhy.fourierSpecialGasMonitor.enums.WindRoseEnum;
+import com.gkhy.fourierSpecialGasMonitor.repository.GasConcentrationRepository;
 import com.gkhy.fourierSpecialGasMonitor.repository.GasWarnLogRepository;
 import com.gkhy.fourierSpecialGasMonitor.service.GasWarnLogService;
 import com.gkhy.fourierSpecialGasMonitor.utils.ThreadLocalUtil;
+import io.micrometer.core.instrument.util.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -29,18 +36,14 @@
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
-import java.time.temporal.TemporalAdjusters;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -53,6 +56,9 @@
 
     @Autowired
     private GasWarnLogRepository gasWarnLogRepository;
+
+    @Resource
+    private GasConcentrationRepository gasConcentrationRepository;
 
     @Autowired
     private UserRepository userRepository;
@@ -77,7 +83,7 @@
                 Set<Predicate> predicateList = new HashSet<>();
                 FindGasWarnLogPageQuery searchParams = pageQuery.getSearchParams();
                 if (searchParams != null && searchParams.getStartTime() != null && searchParams.getEndTime() != null){
-                    predicateList.add(criteriaBuilder.between(root.get("gmtCreate").as(LocalDateTime.class),searchParams.getStartTime(),searchParams.getEndTime()));
+                    predicateList.add(criteriaBuilder.between(root.get("warnTime").as(LocalDateTime.class),searchParams.getStartTime(),searchParams.getEndTime()));
                 }
                 if (searchParams != null && searchParams.getStatus() != null){
                     predicateList.add(criteriaBuilder.equal(root.get("status").as(Byte.class), searchParams.getStatus()));
@@ -115,18 +121,28 @@
     }
 
     @Override
-    public Result handleGasWarnLog(Long id) {
+    public Result handleGasWarnLog(HandleGasWarnLogReqDTO reqDto) {
         User currentUser = getCurrentUser();
-        if (id == null){
+        if (reqDto == null){
             throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
         }
-        GasWarnLog gasWarnLog = gasWarnLogRepository.findByIdAndStatus(id, WarnHandleStatusEnum.HANDLE_NO.getStatus());
+        if (reqDto.getId() == null)
+            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
+        if (reqDto.getUserId() == null)
+            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
+        if (StringUtils.isBlank(reqDto.getHandlerDesc()))
+            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
+        GasWarnLog gasWarnLog = gasWarnLogRepository.findByIdAndStatus(reqDto.getId(), WarnHandleStatusEnum.HANDLE_NO.getStatus());
         if (gasWarnLog == null)
             throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"预警信息不存在");
-        gasWarnLog.setHandlerId(currentUser.getId());
-        gasWarnLog.setHandlerName(currentUser.getName());
-        gasWarnLog.setHandlerRealName(currentUser.getRealName());
+        User user = userRepository.findUserByIdAndStatus(reqDto.getUserId(), UserStatusEnum.STATUS_ACTIVE.getStatus());
+        if (user == null)
+            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"处理人不存在");
+        gasWarnLog.setHandlerId(user.getId());
+        gasWarnLog.setHandlerName(user.getName());
+        gasWarnLog.setHandlerRealName(user.getRealName());
         gasWarnLog.setHandlerTime(LocalDateTime.now());
+        gasWarnLog.setHandlerDesc(reqDto.getHandlerDesc());
         gasWarnLog.setStatus(WarnHandleStatusEnum.HANDLE_YES.getStatus());
         GasWarnLog save = gasWarnLogRepository.save(gasWarnLog);
         if (save == null)
@@ -160,4 +176,72 @@
         List<GasWarnLog> warnLogs = gasWarnLogRepository.findAll(specification);
         return warnLogs;
     }
+
+    @Override
+    public Result gasWarnLogCountByTime(GasWarnLogCountByTimeReqDTO gasWarnLogCountByTimeReqDTO) {
+        if (gasWarnLogCountByTimeReqDTO == null && gasWarnLogCountByTimeReqDTO .getCountTime() == null)
+            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
+        Integer countTime = gasWarnLogCountByTimeReqDTO.getCountTime();
+        GasWarnTimesCountTimeSlotQuery query = GasWarnTimesCountEnum.getQueryObject(countTime).getTimeSlotByStrategy();
+        Result result = Result.success();
+        List<GasWarnLog> gasWarnLog = gasWarnLogRepository.findAllByWarnTimeBetweenOrderByWarnTimeDesc(query.getStartTime(), query.getEndTime());
+        if (CollectionUtils.isEmpty(gasWarnLog))
+            return result;
+        GasWarnLogCountByTimeRespDTO gasWarnLogCountByTimeRespDTO = new GasWarnLogCountByTimeRespDTO();
+        Map<Integer, Long> nameCountMap = gasWarnLog.stream()
+                .collect(Collectors.groupingBy(GasWarnLog::getGasThresholdId, Collectors.counting()));
+        gasWarnLogCountByTimeRespDTO.setYellowWarnNum(nameCountMap.get(1));
+        gasWarnLogCountByTimeRespDTO.setRedWarnNum(nameCountMap.get(2));
+        result.setData(gasWarnLogCountByTimeRespDTO);
+        return result;
+    }
+
+    @Override
+    public Result gasWindRoseByTime(WindRoseByTimeReqDTO reqDTO) {
+        if (reqDTO == null && reqDTO .getCountTime() == null)
+            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
+        Integer countTime = reqDTO.getCountTime();
+        List<GasConcentration> gasConcentrations;
+        if (reqDTO.getCountTime().equals(WindRoseEnum.CUSTOM_TIME.getState())){
+            if (reqDTO.getStartTime() == null && reqDTO.getEndTime() == null)
+                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL,"参数不能为空");
+            gasConcentrations = gasConcentrationRepository.findAllByDataReceivingTimeBetweenOrderByDataReceivingTimeDesc(reqDTO.getStartTime(), reqDTO.getEndTime());
+        }else {
+            WindRoseTimeSlotQuery query = WindRoseEnum.getQueryObject(countTime).getTimeSlotByStrategy();
+             gasConcentrations = gasConcentrationRepository.findAllByDataReceivingTimeBetweenOrderByDataReceivingTimeDesc(query.getStartTime(), query.getEndTime());
+        }
+        Result result = Result.success();
+        if (CollectionUtils.isEmpty(gasConcentrations))
+            return result;
+        List<WindRoseByTimeRespDTO> collect = gasConcentrations.stream().map(gasConcentration -> {
+            WindRoseByTimeRespDTO dto = new WindRoseByTimeRespDTO();
+            BeanUtils.copyProperties(gasConcentration, dto);
+            return dto;
+        }).collect(Collectors.toList());
+        result.setData(collect);
+        return result;
+    }
+
+    @Override
+    public Result gasWarnLogInfoByTime(GasWarnLogInfoReqDTO gasWarnLogInfoReqDTO) {
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime startTime = now.with(LocalTime.MIN);
+        if (gasWarnLogInfoReqDTO != null && gasWarnLogInfoReqDTO.getStartTime() != null) {
+            startTime = gasWarnLogInfoReqDTO.getStartTime();
+        }
+        if (gasWarnLogInfoReqDTO != null && gasWarnLogInfoReqDTO.getEndTime() != null) {
+            now = gasWarnLogInfoReqDTO.getEndTime();
+        }
+        Result result = Result.success();
+        List<GasWarnLog> gasWarnLogs = gasWarnLogRepository.findAllByWarnTimeBetweenOrderByWarnTimeDesc(startTime, now);
+        if (CollectionUtils.isEmpty(gasWarnLogs))
+            return result;
+        List<GasWarnLogInfoByTimeRespDTO> dtos = gasWarnLogs.stream().map(gasWarnLog -> {
+            GasWarnLogInfoByTimeRespDTO dto = new GasWarnLogInfoByTimeRespDTO();
+            BeanUtils.copyProperties(gasWarnLog, dto);
+            return dto;
+        }).collect(Collectors.toList());
+        result.setData(dtos);
+        return result;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.2