From bcc6047ef19e2bd7a83c7f6e6abcb2cd1d8107cc Mon Sep 17 00:00:00 2001
From: baizonghao <1719256278@qq.com>
Date: 星期五, 24 二月 2023 17:51:36 +0800
Subject: [PATCH] 按照报警时间统计

---
 ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java |  159 +++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 129 insertions(+), 30 deletions(-)

diff --git a/ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java
index 9c21b2c..a3e2584 100644
--- a/ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java
+++ b/ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java
@@ -2,6 +2,7 @@
 
 import com.ycl.dto.statistics.CategoryDto;
 import com.ycl.dto.statistics.StatusDto;
+import com.ycl.dto.statistics.TimeDto;
 import com.ycl.dto.statistics.UnlawfulDto;
 import com.ycl.mapper.unlawful.UnlawfulMapper;
 import com.ycl.service.unlawful.UnlawfulService;
@@ -10,9 +11,9 @@
 import javax.annotation.Resource;
 import java.math.RoundingMode;
 import java.text.NumberFormat;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.function.Consumer;
 
 @Service
 public class UnlawfulServiceImpl implements UnlawfulService {
@@ -21,52 +22,104 @@
     private UnlawfulMapper unlawfuldao;
 
 
+    /**
+     * 鎸夌被鍨�
+     */
     @Override
     public List<UnlawfulDto> getUnlawfulByType(Integer currentPage, Integer pageSize, String startTime, String endTime) {
         List<UnlawfulDto> res = new ArrayList<>();
         Double total = unlawfuldao.getTotal().doubleValue();
         List<CategoryDto> data = unlawfuldao.getDataByType(currentPage, pageSize, startTime, endTime);
         data.forEach(categoryDto -> {
-            Double checkedRatio; //瀹℃牳鐜�
-            Double registerRatio; //绔嬫鐜�
             StatusDto statusData = unlawfuldao.getStatusDataByType(startTime, endTime, categoryDto.getId());
-            UnlawfulDto build = new UnlawfulDto().builder().name(categoryDto.getName())     //绫诲瀷鍚嶇О
-                    .count(statusData.getTotal())   //浜嬩欢鎬绘暟
-                    .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //鍗犳瘮
-                    .register(statusData.getRegister())     //绔嬫
-                    .notRegister(statusData.getNotRegister())   //鏆備笉绔嬫
-                    .closing(statusData.getClosing())   //缁撴
-                    .relearn(statusData.getRelearn())   //鍦ㄥ涔�
-                    .checked(statusData.getChecked())   //宸插鏍�
-                    .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //瀹℃牳鐜�
-                    .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //绔嬫鐜�
-                    .build();
-            res.add(build);
+            format(res, total, categoryDto, statusData);
         });
         return res;
     }
-
     @Override
     public List<UnlawfulDto> getUnlawfulByTypeExport() {
         List<UnlawfulDto> res = new ArrayList<>();
         Double total = unlawfuldao.getTotal().doubleValue();
         List<CategoryDto> data = unlawfuldao.getDataByTypeExp();
         data.forEach(categoryDto -> {
-            Double checkedRatio; //瀹℃牳鐜�
-            Double registerRatio; //绔嬫鐜�
             StatusDto statusData = unlawfuldao.getStatusDataByType(null, null, categoryDto.getId());
-            UnlawfulDto build = new UnlawfulDto().builder().name(categoryDto.getName())     //绫诲瀷鍚嶇О
-                    .count(statusData.getTotal())   //浜嬩欢鎬绘暟
-                    .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //鍗犳瘮
-                    .register(statusData.getRegister())     //绔嬫
-                    .notRegister(statusData.getNotRegister())   //鏆備笉绔嬫
-                    .closing(statusData.getClosing())   //缁撴
-                    .relearn(statusData.getRelearn())   //鍦ㄥ涔�
-                    .checked(statusData.getChecked())   //宸插鏍�
-                    .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //瀹℃牳鐜�
-                    .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //绔嬫鐜�
-                    .build();
-            res.add(build);
+            format(res, total, categoryDto, statusData);
+        });
+        return res;
+    }
+
+    /**
+     * 鎸夊尯鍩�
+     */
+    @Override
+    public List<UnlawfulDto> getUnlawfulByStreet(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+        List<UnlawfulDto> res = new ArrayList<>();
+        Double total = unlawfuldao.getTotal().doubleValue();
+        List<CategoryDto> data = unlawfuldao.getDataByStreet(currentPage, pageSize, startTime, endTime);
+        data.forEach(categoryDto -> {
+            StatusDto statusData = unlawfuldao.getStatusDataByStreet(startTime, endTime, categoryDto.getId());
+            format(res, total, categoryDto, statusData);
+        });
+        return res;
+    }
+    @Override
+    public List<UnlawfulDto> getUnlawfulByStreetExport() {
+        List<UnlawfulDto> res = new ArrayList<>();
+        Double total = unlawfuldao.getTotal().doubleValue();
+        List<CategoryDto> data = unlawfuldao.getDataByStreetExp();
+        data.forEach(categoryDto -> {
+            StatusDto statusData = unlawfuldao.getStatusDataByStreet(null, null, categoryDto.getId());
+            format(res, total, categoryDto, statusData);
+        });
+        return res;
+    }
+
+    /**
+     * 鎸夋姤璀︾偣浣�
+     */
+    @Override
+    public List<UnlawfulDto> getUnlawfulBySite(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+        List<UnlawfulDto> res = new ArrayList<>();
+        Double total = unlawfuldao.getTotal().doubleValue();
+        List<String> data = unlawfuldao.getDataBySite(currentPage, pageSize, startTime, endTime);
+        data.forEach(site -> {
+            StatusDto statusData = unlawfuldao.getStatusDataBySite(startTime, endTime, site);
+            format1(res, total, site, statusData);
+        });
+        return res;
+    }
+    @Override
+    public List<UnlawfulDto> getUnlawfulBySiteExport() {
+        List<UnlawfulDto> res = new ArrayList<>();
+        Double total = unlawfuldao.getTotal().doubleValue();
+        List<String> data = unlawfuldao.getDataBySiteExp();
+        data.forEach(site -> {
+            StatusDto statusData = unlawfuldao.getStatusDataBySite(null, null, site);
+            format1(res, total, site, statusData);
+        });
+        return res;
+    }
+
+    @Override
+    public List<UnlawfulDto> getUnlawfulByTime(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+        List<UnlawfulDto> res = new ArrayList<>();
+        Double total = unlawfuldao.getTotal().doubleValue();
+        List<TimeDto> data = unlawfuldao.getDataByTime(currentPage, pageSize, startTime, endTime);
+        data.forEach(timeDto -> {
+            StatusDto statusData = unlawfuldao.getStatusDataByTime(startTime, endTime, timeDto.getId());
+            format2(res, total, timeDto, statusData);
+        });
+        return res;
+    }
+
+    @Override
+    public List<UnlawfulDto> getUnlawfulByTimeExport() {
+        List<UnlawfulDto> res = new ArrayList<>();
+        Double total = unlawfuldao.getTotal().doubleValue();
+        List<TimeDto> data = unlawfuldao.getDataByTimeExp();
+        data.forEach(timeDto -> {
+            StatusDto statusData = unlawfuldao.getStatusDataByTime(null, null, timeDto.getId());
+            format2(res, total, timeDto, statusData);
         });
         return res;
     }
@@ -78,4 +131,50 @@
         String format = numberInstance.format(previous);
         return Double.parseDouble(format);
     }
+
+    private void format(List<UnlawfulDto> res, Double total, CategoryDto categoryDto, StatusDto statusData) {
+        UnlawfulDto build = UnlawfulDto.builder().name(categoryDto.getName())     //绫诲瀷鍚嶇О
+                .count(statusData.getTotal())   //浜嬩欢鎬绘暟
+                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //鍗犳瘮
+                .register(statusData.getRegister())     //绔嬫
+                .notRegister(statusData.getNotRegister())   //鏆備笉绔嬫
+                .closing(statusData.getClosing())   //缁撴
+                .relearn(statusData.getRelearn())   //鍦ㄥ涔�
+                .checked(statusData.getChecked())   //宸插鏍�
+                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //瀹℃牳鐜�
+                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //绔嬫鐜�
+                .build();
+        res.add(build);
+    }
+
+    private void format2(List<UnlawfulDto> res, Double total, TimeDto timeDto, StatusDto statusData) {
+        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        UnlawfulDto build = UnlawfulDto.builder().name(timeDto.getTime().format(fmt))     //绫诲瀷鍚嶇О
+                .count(statusData.getTotal())   //浜嬩欢鎬绘暟
+                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //鍗犳瘮
+                .register(statusData.getRegister())     //绔嬫
+                .notRegister(statusData.getNotRegister())   //鏆備笉绔嬫
+                .closing(statusData.getClosing())   //缁撴
+                .relearn(statusData.getRelearn())   //鍦ㄥ涔�
+                .checked(statusData.getChecked())   //宸插鏍�
+                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //瀹℃牳鐜�
+                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //绔嬫鐜�
+                .build();
+        res.add(build);
+    }
+
+    private void format1(List<UnlawfulDto> res, Double total, String site, StatusDto statusData) {
+        UnlawfulDto build = UnlawfulDto.builder().name(site)     //绫诲瀷鍚嶇О
+                .count(statusData.getTotal())   //浜嬩欢鎬绘暟
+                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //鍗犳瘮
+                .register(statusData.getRegister())     //绔嬫
+                .notRegister(statusData.getNotRegister())   //鏆備笉绔嬫
+                .closing(statusData.getClosing())   //缁撴
+                .relearn(statusData.getRelearn())   //鍦ㄥ涔�
+                .checked(statusData.getChecked())   //宸插鏍�
+                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //瀹℃牳鐜�
+                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //绔嬫鐜�
+                .build();
+        res.add(build);
+    }
 }

--
Gitblit v1.8.0