|  |  |  | 
|---|
|  |  |  | import com.deepoove.poi.data.TextRenderData; | 
|---|
|  |  |  | import com.deepoove.poi.policy.HackLoopTableRenderPolicy; | 
|---|
|  |  |  | import com.moral.api.entity.Dustld; | 
|---|
|  |  |  | import com.moral.api.exception.BusinessException; | 
|---|
|  |  |  | import com.moral.api.pojo.bo.ExcelBO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dust.DustForm; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("dailyDustlds") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public ResultMessage  dailyDustlds(@RequestBody Map<String,Object> params, HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | public void dailyDustlds(@RequestBody Map<String,Object> params, HttpServletResponse response,HttpServletRequest request) 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()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.out.println(CruiserController.class.getResource("/word/尘负荷监测报告.docx").getPath()); | 
|---|
|  |  |  | URL resource = getClass().getResource("/word/尘负荷监测报告.docx"); | 
|---|
|  |  |  | 
|---|
|  |  |  | System.out.println(path); | 
|---|
|  |  |  | Map<String, Object> map = dustldService.dailyDustlds(params); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(map)){ | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); | 
|---|
|  |  |  | throw new BusinessException("未找到路段信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | test(map,response); | 
|---|
|  |  |  | test(map,response,request); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public  void test( Map<String, Object> params,HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | public  void test( Map<String, Object> params,HttpServletResponse response,HttpServletRequest request) throws IOException { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //InputStream  inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/尘负荷监测报告.docx"); | 
|---|
|  |  |  | 
|---|
|  |  |  | maps.put("table2", dustForm.getRoad()); | 
|---|
|  |  |  | maps.put("table3", dustForm.getValue()); | 
|---|
|  |  |  | detailList.add(maps); | 
|---|
|  |  |  | /* RowRenderData row0 = RowRenderData.build(i+1+"",dustForm.getRoad(), dustForm.getValue()+""); | 
|---|
|  |  |  | rsList1.add(row0);*/ | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*for (int i = 0; i < mapArrayList.size(); i++) { | 
|---|
|  |  |  | List<Map> detailList2 = new ArrayList<>(); | 
|---|
|  |  |  | Map maps = new HashMap(); | 
|---|
|  |  |  | /* maps.put("table4", ""); | 
|---|
|  |  |  | maps.put("table5", ""); | 
|---|
|  |  |  | maps.put("table6", ""); | 
|---|
|  |  |  | maps.put("table7", map.get("date1")); | 
|---|
|  |  |  | maps.put("table8", map.get("date2")); | 
|---|
|  |  |  | detailList2.add(maps);*/ | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | maps = new HashMap(); | 
|---|
|  |  |  | maps.put("time4", i+1); | 
|---|
|  |  |  | maps.put("time5", map1.get("road").toString()); | 
|---|
|  |  |  | maps.put("time6", map1.get("value1").toString()); | 
|---|
|  |  |  | maps.put("time7", map1.get("value2").toString()); | 
|---|
|  |  |  | maps.put("time8", map1.get("value3").toString()); | 
|---|
|  |  |  | detailList2.add(maps); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(mapArrayList)){ | 
|---|
|  |  |  | map.put("table3", new MiniTableRenderData(rsList3)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("table1", new MiniTableRenderData(header1, rsList1));*/ | 
|---|
|  |  |  | String data = params.get("data").toString(); | 
|---|
|  |  |  | map.put("data",data); | 
|---|
|  |  |  | map.put("time",params.get("time").toString()); | 
|---|
|  |  |  | map.put("date1",params.get("date1").toString()); | 
|---|
|  |  |  | map.put("date2",params.get("date2").toString()); | 
|---|
|  |  |  | //map.put("detailList",detailList); | 
|---|
|  |  |  | /*File docxFile = new File("尘负荷监测报告.docx"); | 
|---|
|  |  |  | FileUtils.copyToFile(inputStream,docxFile); | 
|---|
|  |  |  | inputStream.close();*/ | 
|---|
|  |  |  | //XWPFDocument compile = WordExportUtil.exportWord07(filePath,map); | 
|---|
|  |  |  | HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy(); | 
|---|
|  |  |  | Configure config = Configure.newBuilder().bind("detailList", policy).build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Configure config = Configure.newBuilder().bind("detailList", policy).bind("detailList2", policy).build(); | 
|---|
|  |  |  | XWPFTemplate compile = XWPFTemplate.compile(filePath,config).render(new HashMap<String, Object>(){{ | 
|---|
|  |  |  | put("time",map.get("time")); | 
|---|
|  |  |  | put("data",map.get("data")); | 
|---|
|  |  |  | put("data1",map.get("data1")); | 
|---|
|  |  |  | put("data2",map.get("data2")); | 
|---|
|  |  |  | put("time1",map.get("date1").toString()); | 
|---|
|  |  |  | put("time2",map.get("date2").toString()); | 
|---|
|  |  |  | put("detailList", detailList); | 
|---|
|  |  |  | put("detailList2", detailList2); | 
|---|
|  |  |  | }}); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | response.setContentType("multipart/form-data"); | 
|---|
|  |  |  | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  | compile.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 
|---|
|  |  |  | compile.write(byteArrayOutputStream); | 
|---|
|  |  |  | byte[] bytes = byteArrayOutputStream.toByteArray(); | 
|---|
|  |  |  | response.setCharacterEncoding("utf-8"); | 
|---|
|  |  |  | response.setContentType("multipart/form-data"); | 
|---|
|  |  |  | response.setHeader("Content-Disposition", "attachment;filename=尘负荷监测报告.docx"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ServletOutputStream outputStream = response.getOutputStream(); | 
|---|
|  |  |  | outputStream.write(bytes); | 
|---|
|  |  |  | outputStream.flush(); | 
|---|
|  |  |  | outputStream.close();*/ | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | log.error ("导出失败,请联系网站管理员!", e); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|