From ead280567beb29e26e0980c6b3770815e6fe86d9 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期日, 12 十一月 2023 10:09:14 +0800
Subject: [PATCH] 油烟统计

---
 ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java |  135 ++++++++++++++------------------------------
 1 files changed, 43 insertions(+), 92 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 16b8cdc..e4f97a1 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
@@ -1,22 +1,25 @@
 package com.ycl.service.unlawful.impl;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 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;
+import com.ycl.utils.StringUtils;
 import org.springframework.stereotype.Service;
 
 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;
 
 @Service
 public class UnlawfulServiceImpl implements UnlawfulService {
-
-    private List<UnlawfulDto> res = new ArrayList<>();
 
     @Resource
     private UnlawfulMapper unlawfuldao;
@@ -26,109 +29,57 @@
      * 鎸夌被鍨�
      */
     @Override
-    public List<UnlawfulDto> getUnlawfulByType(Integer currentPage, Integer pageSize, String startTime, String endTime) {
-        Double total = unlawfuldao.getTotal().doubleValue();
-        List<CategoryDto> data = unlawfuldao.getDataByType(currentPage, pageSize, startTime, endTime);
-        data.forEach(categoryDto -> {
-            StatusDto statusData = unlawfuldao.getStatusDataByType(startTime, endTime, categoryDto.getId());
-            format(res, total, categoryDto, statusData);
-        });
-        return res;
+    public IPage<UnlawfulDto> getUnlawfulByType(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
+
+        Double total = unlawfuldao.getTotal(startTime, endTime, true, false, false).doubleValue();
+        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByType(page, startTime, endTime);
+        return getUnlawfulDtoIPage(total, page1);
     }
-    @Override
-    public List<UnlawfulDto> getUnlawfulByTypeExport() {
-        Double total = unlawfuldao.getTotal().doubleValue();
-        List<CategoryDto> data = unlawfuldao.getDataByTypeExp();
-        data.forEach(categoryDto -> {
-            StatusDto statusData = unlawfuldao.getStatusDataByType(null, null, categoryDto.getId());
-            format(res, total, categoryDto, statusData);
+
+    private IPage<UnlawfulDto> getUnlawfulDtoIPage(Double total, IPage<UnlawfulDto> page1) {
+        page1.getRecords().forEach(dto -> {
+            dto.setRatio(StringUtils.doubleTwo((double) dto.getCount() * 100 / total) + "%");
+            dto.setRegisterRatio(StringUtils.doubleTwo((double) dto.getRegister() * 100 / (double) dto.getCount()) + "%");
+            dto.setCheckedRatio(StringUtils.doubleTwo((double) dto.getChecked() * 100 / (double) dto.getCount()) + "%");
+            dto.setAccuracyRatio(StringUtils.doubleTwo(1.0 - (double) dto.getRelearn() * 100 / (double) dto.getCount()) + "%");
+
         });
-        return res;
+        return page1;
     }
 
     /**
      * 鎸夊尯鍩�
      */
     @Override
-    public List<UnlawfulDto> getUnlawfulByStreet(Integer currentPage, Integer pageSize, String startTime, String endTime) {
-        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;
+    public IPage<UnlawfulDto> getUnlawfulByStreet(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
+
+        Double total = unlawfuldao.getTotal(startTime, endTime, false, true, false).doubleValue();
+        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByStreet(page, startTime, endTime);
+        return getUnlawfulDtoIPage(total, page1);
     }
+
+
     @Override
-    public List<UnlawfulDto> getUnlawfulByStreetExport() {
-        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;
+    public IPage<UnlawfulDto> getUnlawfulByTime(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
+
+        Double total = unlawfuldao.getTotal(startTime, endTime, false, false, false).doubleValue();
+        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByTime(page, startTime, endTime);
+        return getUnlawfulDtoIPage(total, page1);
     }
 
-    /**
-     * 鎸夋姤璀︾偣浣�
-     */
+
     @Override
-    public List<UnlawfulDto> getUnlawfulBySite(Integer currentPage, Integer pageSize, String startTime, String endTime) {
-        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() {
-        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;
+    public IPage<UnlawfulDto> getUnlawfulByPoint(Integer currentPage, Integer pageSize, String startTime, String endTime) {
+
+        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
+
+        Double total = unlawfuldao.getTotal(startTime, endTime, false, false, true).doubleValue();
+        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByPoint(page, startTime, endTime);
+        return getUnlawfulDtoIPage(total, page1);
+
     }
 
-    private Double changeFormat(Double previous){
-        NumberFormat numberInstance = NumberFormat.getNumberInstance();
-        numberInstance.setMaximumFractionDigits(2);
-        numberInstance.setRoundingMode(RoundingMode.HALF_UP);
-        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 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