From ab061be50b7653531cbe134416c3ebdd876e4791 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Thu, 19 Oct 2023 13:56:17 +0800
Subject: [PATCH] fix:风场数据范围提交

---
 screen-api/src/main/java/com/moral/api/controller/CruiserController.java |  124 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 123 insertions(+), 1 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/CruiserController.java b/screen-api/src/main/java/com/moral/api/controller/CruiserController.java
index 4e852a2..1ae8f5f 100644
--- a/screen-api/src/main/java/com/moral/api/controller/CruiserController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -1,38 +1,58 @@
 package com.moral.api.controller;
 
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.data.MiniTableRenderData;
+import com.deepoove.poi.data.RowRenderData;
+import com.deepoove.poi.data.TextRenderData;
 import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO;
+
+import cn.afterturn.easypoi.word.WordExportUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
+import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLEncoder;
 import java.text.ParseException;
 import java.util.ArrayList;
+
 import java.util.HashMap;
+
 import java.util.List;
 import java.util.Map;
 
+
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import com.moral.api.entity.Dustld;
 import com.moral.api.pojo.bo.ExcelBO;
+import com.moral.api.pojo.dust.DustForm;
 import com.moral.api.pojo.vo.excel.DailyVo;
 import com.moral.api.service.DustldService;
 import com.moral.api.service.SpecialDeviceService;
 import com.moral.constant.ResponseCodeEnum;
 import com.moral.constant.ResultMessage;
 import com.moral.util.WebUtils;
+
+import static com.moral.api.controller.SysTestController.getPath;
 
 @Slf4j
 @Api(tags = {"���������"})
@@ -217,6 +237,31 @@
         return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),map);
     }
 
+
+    /**
+     * ���������������������
+     * @return
+     */
+    @PostMapping("dailyDustlds")
+    public ResultMessage  dailyDustlds(@RequestBody Map<String,Object> params, HttpServletResponse response) throws IOException {
+
+//        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
+        if (!params.containsKey("mac") || !params.containsKey("startTime") || !params.containsKey("endTime")){
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+
+        Map<String, Object> map = dustldService.dailyDustlds(null,params);
+        test(map,response);
+        if (ObjectUtils.isEmpty(map)){
+            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
+        }
+//        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),map);
+        return ResultMessage.ok();
+    }
+
+
+
+
     /**
      * ������������������
      * @param id
@@ -252,4 +297,81 @@
     }
 
 
+
+    public static void downloadWord(String fileName, Map<String, Object> params, HttpServletResponse response, String newFileName) {
+        String path = getPath(fileName);//��������� resources������
+        try {
+            //������������������
+            OutputStream out = new FileOutputStream("G:\\home\\mon1\\" + newFileName);
+            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 void test( Map<String, Object> params,HttpServletResponse response) throws IOException {
+//        String path="D:\\���������������������.docx";
+        String path = getPath("���������������������.docx");
+        try {
+            //���������������������������
+            File rootFile = new File(ResourceUtils.getURL("classpath:").getPath());
+            File file= new File(rootFile, path);
+            //������������������������
+            XWPFTemplate compile = XWPFTemplate.compile(file.getPath());
+            //������������������������������������������������������{{}}������������������������,map������������key������������������������������������������
+            HashMap<String, Object> map = new HashMap<>();
+            //������������������������
+            RowRenderData header1 = RowRenderData.build(new TextRenderData("6495ED", "������"), new TextRenderData("6495ED", "������"),new TextRenderData("6495ED", "���������������������/������������"));
+
+            //���������������������������������������������������������list������������������������������foreach������������������
+            List<DustForm> list1 = (List<DustForm>) params.get("list1");
+
+            ArrayList<Map<String, Object>> mapArrayList = (ArrayList<Map<String, Object>>) params.get("list3");
+            ArrayList<RowRenderData> rsList1 = new ArrayList<>();
+            ArrayList<RowRenderData> rsList3 = new ArrayList<>();
+
+            for (int i = 0; i < list1.size(); i++) {
+                DustForm dustForm = list1.get(i);
+                RowRenderData row0 = RowRenderData.build(i+1+"",dustForm.getRoad(), dustForm.getValue()+"");
+                rsList1.add(row0);
+            }
+
+            for (int i = 0; i < mapArrayList.size(); i++) {
+                Map<String, Object> map1 = mapArrayList.get(i);
+                RowRenderData row = RowRenderData.build(i + 1 + "", map1.get("road").toString(), map1.get("value1").toString(), map1.get("value2").toString(), map1.get("value3").toString());
+                rsList3.add(row);
+            }
+
+            map.put("table1", new MiniTableRenderData(header1, rsList1));
+            map.put("table3", new MiniTableRenderData(rsList3));
+            map.put("data",params.get("data").toString());
+            map.put("time",params.get("time").toString());
+            map.put("date1",params.get("date1").toString());
+            map.put("date2",params.get("date2").toString());
+
+
+            compile.render(map);
+
+//            compile.writeToFile("G:\\home\\mon1\\" + "���������������������"+params.get("time").toString()+".docx");
+
+//        FileOutputStream out = new FileOutputStream("���������������������" + params.get("time").toString() + ".docx");
+            compile.write(response.getOutputStream());
+            compile.close();
+        } catch (IOException e) {
+            log.error ("������������������������������������������", e);
+        }
+
+    }
+
+
 }

--
Gitblit v1.8.0