From 010f4ba252db180fc7fea4d7cb1b84a0bca7479f Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Fri, 11 Aug 2023 16:37:43 +0800
Subject: [PATCH] Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into wb

---
 screen-api/src/main/java/com/moral/api/controller/SysTestController.java |  345 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 345 insertions(+), 0 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/SysTestController.java b/screen-api/src/main/java/com/moral/api/controller/SysTestController.java
new file mode 100644
index 0000000..36f131a
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/controller/SysTestController.java
@@ -0,0 +1,345 @@
+package com.moral.api.controller;
+
+import cn.afterturn.easypoi.word.WordExportUtil;
+import com.moral.api.entity.SysTest;
+import com.moral.api.service.SysTestService;
+import com.moral.util.DateUtils;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ResourceUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.net.URLEncoder;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @ClassName SysTestController
+ * @Description TODO
+ * @Author @lizijie
+ * @Date 2023-08-01 13:45
+ * @Version 1.0
+ */
+@Slf4j
+@Api(tags = {"������������������������"})
+@RestController
+@RequestMapping("/systest")
+public class SysTestController {
+    @Autowired
+    private SysTestService sysTestService;
+
+
+    @GetMapping("resultWord")
+    public void adresultWordd(HttpServletResponse response,String time) {
+        List<SysTest> listAll = sysTestService.listAll(time,"2022-06-22",null);
+        if(CollectionUtils.isEmpty(listAll)){
+            return;
+        }
+        Date endTime =listAll.get(0).getTime();
+        String endTimeStr = DateUtils.dateToDateString(endTime,DateUtils.yyyyMMdd_EN);
+        String  fileName = "������������������.docx";
+        Map<String,Object> map = resultMap(listAll);
+
+        //���������map
+       // Map result = JSON.parseObject(JSON.toJSONString(entity), Map.class);
+        //        Map<String, Object> result = EasyPoiUtil.entityToMap(entity);
+        downloadWord(fileName, map, response,"������������������"+endTimeStr+".docx");
+
+
+
+    }
+
+
+    public static void downloadWord(String fileName, Map<String, Object> params, HttpServletResponse response,String newFileName) {
+        String path = getPath(fileName);//��������� resources������
+        try {
+            //������������������
+
+            File rootFile = new File(ResourceUtils.getURL("classpath:").getPath());
+            File file= new File(rootFile, path);
+
+            XWPFDocument word = WordExportUtil.exportWord07(file.getPath(), params);
+            response.setCharacterEncoding("utf-8");
+            response.setContentType("multipart/form-data");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(newFileName, "utf-8"));
+            OutputStream out = response.getOutputStream();
+            word.write(out);
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            log.error ("������������������������������������������", e);
+        }
+    }
+
+
+    public static String getPath(String filename) {
+        filename = "/word/" + filename;
+        return filename;
+    }
+
+
+    /**
+     ������������Map
+     */
+    public static Map<String, Object> entityToMap(Object object) {
+        Map<String, Object> map = new HashMap<>();
+        for (Field field : object.getClass().getDeclaredFields()) {
+            try {
+                boolean flag = field.isAccessible();
+                field.setAccessible(true);
+                Object o = field.get(object);
+                map.put(field.getName(), o);
+                field.setAccessible(flag);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return map;
+    }
+
+    private Map<String,Object> resultMap(List<SysTest> listAll){
+        String first = "2020-06-22";
+        String firstYear = "2020";
+
+        Map<String,Object> resultMap = new HashMap<>();
+        Date endTime =listAll.get(0).getTime();
+        String endTimeStr = DateUtils.dateToDateString(endTime,DateUtils.yyyy_MM_dd_EN);
+        List<String> endTimeList= Arrays.asList(endTimeStr.split("-"));
+        if(Integer.parseInt(firstYear)<Integer.parseInt(endTimeList.get(0))){
+            firstYear = endTimeList.get(0);
+            first = endTimeList.get(0)+"-01-01";
+        }
+        String firstM = String.valueOf(Integer.parseInt(endTimeList.get(1)));
+        String firstD = String.valueOf(Integer.parseInt(endTimeList.get(2)));
+        Long day = DateUtils.getQuotByDays(first,endTimeStr)+1  ;
+        resultMap.put("���",firstYear);
+        resultMap.put("���",firstM);
+        resultMap.put("���",firstD);
+        resultMap.put("���",day.intValue());
+        String name = "���";
+        for(SysTest s : listAll){
+            if(s.getName().contains("���")){
+                name = "���";
+            }else if(s.getName().contains("���")){
+                name = "���";
+            }else {
+                name = "���";
+            }
+            resultMap.put(name+"AQI", StringUtils.isNotEmpty(s.getAqi())?s.getAqi():"--");
+            resultMap.put(name+"PM10", StringUtils.isNotEmpty(s.getPm10())?s.getPm10():"--");
+            resultMap.put(name+"PM2", StringUtils.isNotEmpty(s.getPm25())?s.getPm25():"--");
+            resultMap.put(name+"SO2", StringUtils.isNotEmpty(s.getSo2())?s.getSo2():"--");
+            resultMap.put(name+"NO2", StringUtils.isNotEmpty(s.getNo2())?s.getNo2():"--");
+            resultMap.put(name+"CO", StringUtils.isNotEmpty(s.getCo())?s.getCo():"--");
+            resultMap.put(name+"O3", StringUtils.isNotEmpty(s.getO3())?s.getO3():"--");
+            resultMap.put(name+"TV", StringUtils.isNotEmpty(s.getVoc())?s.getVoc():"--");
+            resultMap.put(name+"S", StringUtils.isNotEmpty(s.getSu())?s.getSu():"--");
+        }
+
+        String bodyName = stringButterStr(listAll);
+        resultMap.put("������������",bodyName);
+        return resultMap;
+    }
+
+    private String stringButterStr(List<SysTest> listAll){
+
+        // 0 ������1 ������ 2���������3���������
+        int type = 0;
+        // TODO: 2023-08-01 ���������������������������������������������
+        int aqiHigh = Integer.parseInt(listAll.get(0).getAqi());
+        int aqiMiddle = Integer.parseInt(listAll.get(1).getAqi());
+        int aqiLow = Integer.parseInt(listAll.get(2).getAqi());
+        List<Integer> numList = Arrays.asList(aqiHigh,aqiMiddle,aqiLow);
+        StringBuffer stringBuffer = new StringBuffer();
+        Set<Integer> stringSet = new HashSet<>(numList);
+        List<Integer> listTest = stringSet.stream().collect(Collectors.toList());
+        Collections.sort(listTest);
+        int aqiHighResult = listTest.get(listTest.size()-1);
+        int aqiLowResult = listTest.get(0);
+        if(stringSet.size() == 1){
+            type = 0;
+            stringBuffer.append("���������������������AQI���������������,������������������");
+            return stringBuffer.toString();
+        }else if(stringSet.size() == 3){
+            type = 3;
+        }else {
+            int count = Collections.frequency(numList, listTest.get(0));
+            if(count == 1){
+                type = 2;
+            }else {
+                type = 1;
+            }
+        }
+        int sizeHighResult = 0;
+        int sizeLowResult = 0;
+        String highName = "���������";
+        String lowName = "���������";
+        //1 ������ 2������
+        if(type == 1){
+            SysTest ResultAqi = listAll.stream().min(Comparator.comparing(SysTest::getAqi)).get();
+            if(ResultAqi.getName().contains("���������")){
+                lowName = "���������";
+                highName = "���������������������";
+            }else if(ResultAqi.getName().contains("���������")){
+                lowName = "���������";
+                highName = "���������������������";
+            } else if(ResultAqi.getName().contains("���������")){
+                lowName = "���������";
+                highName = "���������������������";
+            }
+
+        }else if(type == 2){
+            SysTest ResultAqi = listAll.stream().max(Comparator.comparing(SysTest::getAqi)).get();
+            if(ResultAqi.getName().contains("���������")){
+                highName = "���������";
+                lowName = "���������������������";
+            }else if(ResultAqi.getName().contains("���������")){
+                highName = "���������";
+                lowName = "���������������������";
+            } else if(ResultAqi.getName().contains("���������")){
+                highName = "���������";
+                lowName = "���������������������";
+            }
+        }else if(type == 3){
+            if(aqiHigh == aqiHighResult){
+                sizeHighResult = 0;
+            }
+            if(aqiMiddle == aqiHighResult){
+                sizeHighResult = 1;
+            }
+            if(aqiLow == aqiHighResult){
+                sizeHighResult = 2;
+            }
+            if(aqiHigh == aqiLowResult){
+                sizeLowResult = 0;
+            }
+            if(aqiMiddle == aqiLowResult){
+                sizeLowResult = 1;
+            }
+            if(aqiLow == aqiLowResult){
+                sizeLowResult = 2;
+            }
+            SysTest HighResult = listAll.get(sizeHighResult);
+            SysTest LowResult = listAll.get(sizeLowResult);
+
+            if(HighResult.getName().contains("���������")){
+                highName = "���������";
+            }else if(HighResult.getName().contains("���������")){
+                highName = "���������";
+            }
+            if(LowResult.getName().contains("���������")){
+                lowName = "���������";
+            }else if(LowResult.getName().contains("���������")){
+                lowName = "���������";
+            }
+        }
+        SysTest result0 = listAll.get(0);
+        SysTest result1 = listAll.get(1);
+        SysTest result2 = listAll.get(2);
+        Map<String,String> pm10 = nameCode(result0.getName(),result1.getName(),result2.getName(),result0.getPm10(),result1.getPm10(),result2.getPm10());
+        Map<String,String> pm25 = nameCode(result0.getName(),result1.getName(),result2.getName(),result0.getPm25(),result1.getPm25(),result2.getPm25());
+        Map<String,String> so = nameCode(result0.getName(),result1.getName(),result2.getName(),result0.getSo2(),result1.getSo2(),result2.getSo2());
+        Map<String,String> no = nameCode(result0.getName(),result1.getName(),result2.getName(),result0.getNo2(),result1.getNo2(),result2.getNo2());
+        Map<String,String> co = nameCode(result0.getName(),result1.getName(),result2.getName(),result0.getCo(),result1.getCo(),result2.getCo());
+        Map<String,String> o3 = nameCode(result0.getName(),result1.getName(),result2.getName(),result0.getO3(),result1.getO3(),result2.getO3());
+        stringBuffer.append(highName+"���������������������AQI������������"+lowName+"���������������������AQI������������");
+        if(pm10.isEmpty()&& pm25.isEmpty()&&so.isEmpty()&& no.isEmpty()&& co.isEmpty()&& o3.isEmpty()){
+            return stringBuffer.toString();
+        }
+        stringBuffer.append("���������");
+        if(!pm10.isEmpty()){
+            stringBuffer.append("PM10���������������"+pm10.get("high")+"������������������"+pm10.get("low")+"���");
+        }
+        if(!pm25.isEmpty()){
+            stringBuffer.append("PM2.5���������������"+pm25.get("high")+"������������������"+pm25.get("low")+"���");
+        }
+        if(!so.isEmpty()){
+            stringBuffer.append("SO2���������������"+so.get("high")+"������������������"+so.get("low")+"���");
+        }
+        if(!no.isEmpty()){
+            stringBuffer.append("NO2���������������"+no.get("high")+"������������������"+no.get("low")+"���");
+        }
+        if(!co.isEmpty()){
+            stringBuffer.append("CO���������������"+co.get("high")+"������������������"+co.get("low")+"���");
+        }
+        if(!o3.isEmpty()){
+            stringBuffer.append("O3���������������"+o3.get("high")+"������������������"+o3.get("low")+"���");
+        }
+        return stringBuffer.toString();
+
+    }
+
+
+    private Map<String,String> nameCode(String name1,String name2,String name3,String nums1,String nums2,String nums3){
+        double num1 = StringUtils.isNotEmpty(nums1)?Double.parseDouble(nums1):0;
+        double num2 = StringUtils.isNotEmpty(nums2)?Double.parseDouble(nums2):0;
+        double num3 = StringUtils.isNotEmpty(nums3)?Double.parseDouble(nums3):0;
+        Map<String,String> map = new HashMap<>();
+        if(num1 ==num2 && num2 ==num3){
+            return map;
+        }
+        name1 = name1.substring(3,name1.length());
+        name2 = name2.substring(3,name2.length());
+        name3 = name3.substring(3,name3.length());
+        if(num1 ==num2 && num2 < num3){
+            map.put("high",name3);
+            map.put("low",name1+"���"+name2);
+            return map;
+        }else if(num1 ==num2 && num2 > num3){
+            map.put("low",name3);
+            map.put("high",name1+"���"+name2);
+            return map;
+        }
+        if(num1 == num3 && num2 < num3){
+            map.put("low",name2);
+            map.put("high",name1+"���"+name3);
+            return map;
+        }else if(num1 == num3 && num2 > num3){
+            map.put("high",name2);
+            map.put("low",name1+"���"+name3);
+            return map;
+        }
+        if(num2 == num3 && num1 < num2){
+            map.put("low",name1);
+            map.put("high",name2+"���"+name3);
+            return map;
+        }else if(num2 == num3 && num1 > num2){
+            map.put("high",name1);
+            map.put("low",name2+"���"+name3);
+            return map;
+        }
+        List<Double> numList = Arrays.asList(num1,num2,num3);
+        int high = numList.indexOf(Collections.max(numList));
+        int low = numList.indexOf(Collections.min(numList));
+        if(high == 0){
+            map.put("high",name1);
+        }else if(high == 1){
+            map.put("high",name2);
+        }else if(high == 2){
+            map.put("high",name3);
+        }
+        if(low == 0){
+            map.put("low",name1);
+        }else if(low == 1){
+            map.put("low",name2);
+        }else if(low == 2){
+            map.put("low",name3);
+        }
+        return map;
+
+    }
+
+
+
+
+}

--
Gitblit v1.8.0