jinpengyong
2024-06-19 32cc13189371ee1e367897a64fbc22f90b53add8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
package com.moral.api.controller;
 
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.poi.word.WordUtil;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.PictureRenderData;
import com.deepoove.poi.data.RowRenderData;
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;
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.DateUtils;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
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 static com.moral.api.controller.SysTestController.getPath;
 
@Slf4j
@Api(tags = {"走航车"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/cruiser")
public class CruiserController {
 
    @Autowired
    private SpecialDeviceService specialDeviceService;
 
    /**
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("selectCruisers")
    @ApiOperation(value = "获取当前组织下所有走航车列表", notes = "走航车轨迹")
    public ResultMessage getCarsInfo() {
        List<Map<String, Object>> response = specialDeviceService.selectCruisers();
        return ResultMessage.ok(response);
    }
 
    /**
     * @param mac 设备mac
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("getDates")
    @ApiOperation(value = "获取有走航数据的日期", notes = "获取有走航数据的日期")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getDates(String mac) {
        if (ObjectUtils.isEmpty(mac)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<String> response = specialDeviceService.getDatesByMac(mac);
        return ResultMessage.ok(response);
    }
 
    /**
     * @param request 请求信息
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("cruiserTrajectory")
    @ApiOperation(value = "走航车轨迹", notes = "走航车轨迹")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time1", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time2", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage carTrajectory(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("time2")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> response = specialDeviceService.carTrajectory(params,true);
        return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response);
    }
    @GetMapping("carTrajectoryNewAvg")
    @ApiOperation(value = "走航车轨迹", notes = "走航车轨迹")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time1", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time2", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "采集因子", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "range", value = "范围", required = true, paramType = "query", dataType = "int")
    })
    public ResultMessage carTrajectoryNewAvg(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("time1")||!params.containsKey("range")|| !params.containsKey("type")|| !params.containsKey("time2")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<HistorySecondCruiserResultDTO> response = specialDeviceService.carTrajectoryNewAvg(params);
 
        //计算执行时间
 
        return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response);
 
    }
 
    /**
     * 走航车日报
     * @param request
     * @return
     */
    @PostMapping("getDaily")
    @ApiOperation(value = "走航车日报", notes = "走航车日报")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time1", value = "开始时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time2", value = "结束时间,2021-08-18", required = true, paramType = "query", dataType = "String")
    })
    public  ResultMessage getDaily(HttpServletRequest request) throws ParseException {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("time2")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
        ExcelBO daily = specialDeviceService.getDaily(params, files);
        if (daily==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return ObjectUtils.isEmpty(daily) ? ResultMessage.ok() : ResultMessage.ok(daily);
    }
 
 
 
    /**
     * 下载走航车日报
     * @param params
     * @return
     */
    @PostMapping("loadDaily")
    public void loadDaily( @RequestBody Map<String,Object> params,HttpServletResponse response) throws IOException {
        List<Integer> ids = (List<Integer>) params.get("ids");
        List<DailyVo> dailyVos = specialDeviceService.loadDaily(ids);
        if (ObjectUtils.isEmpty(dailyVos)){
            throw new BusinessException("未找到走航信息");
        }
        dailyDocx(dailyVos,response);
    }
 
    /**
     * 查询日报
     * @param request
     * @return
     */
    @GetMapping("selectDaily")
    public ResultMessage selectDaily(HttpServletRequest request){
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if ( !params.containsKey("startTime")|| !params.containsKey("endTime")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<ExcelBO> excelBOS = specialDeviceService.selectDaily(params);
        if (excelBOS==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBOS);
    }
 
    @Autowired
    private DustldService dustldService;
 
    /**
     * 尘负荷走航
     * @param request
     * @return
     */
    @PostMapping("getDailyDustld")
    public  ResultMessage getDailyDustld(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("road") || !params.containsKey("table")){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        MultipartFile file = ((MultipartHttpServletRequest) request).getFile("files");
 
        Integer dailyDustld = null;
        try {
            dailyDustld = dustldService.getDailyDustld(params,file);
        } catch (ParseException e) {
            log.error("{错误}"+e.getMessage());
        }
        if (ObjectUtils.isEmpty(dailyDustld)){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),dailyDustld);
    }
 
    /**
     * 下载尘负荷报告
     * @return
     */
    @PostMapping("dailyDustld")
    public ResultMessage  dailyDustld(HttpServletRequest request,Integer id){
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
 
        Map<String, Object> map = dustldService.dailyDustld(id,files);
        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
     */
    @PostMapping("dailyDustlds")
    @Transactional
    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;
        }
        Map<String, Object> map = dustldService.dailyDustlds(params);
        if (ObjectUtils.isEmpty(map)){
            throw new BusinessException("未找到路段信息");
        }
        test(map,response,request);
 
 
    }
 
 
 
 
    /**
     * 查看路段高值
     * @param id
     * @return
     */
    @GetMapping("selectDust")
    public  ResultMessage selectDust(Integer id){
        Map<String, Object> map = null;
        try {
            map = dustldService.selectDust(id);
        } catch (Exception e) {
            log.error("{错误}"+e.getMessage());
        }
        return  new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),map);
    }
 
    /**
     * 查询一段时间的路段数据
     * @param request
     * @return
     */
    @GetMapping("selectAll")
    public  ResultMessage selectAll(HttpServletRequest request){
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        List<Dustld> dustlds = null;
        try {
            dustlds = dustldService.selectAll(params);
        } catch (Exception e) {
           log.error("{错误}"+e.getMessage());
        }
        return  new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),dustlds);
 
    }
 
    @GetMapping("sort")
    @ApiOperation("路段排序")
    public ResultMessage sectionRanking(@RequestParam @ApiParam(value = "mac",name = "mac号") String mac,
                                        @RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
                                        @RequestParam @ApiParam(value = "endTime",name = "结束时间") String endTime){
 
        List<DustForm> sort = dustldService.sort(mac, startTime, endTime);
        return ResultMessage.ok(sort);
    }
 
 
 
    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,HttpServletRequest request) throws IOException {
 
        try {
            //InputStream  inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/尘负荷监测报告.docx");
            InputStream stream = WordUtil.class.getClassLoader().getResourceAsStream("word/尘负荷监测报告.docx");
            //获取临时文件
            File file = new File("word/尘负荷监测报告.docx");
            //将读取到的类容存储到临时文件中,后面就可以用这个临时文件访问了
            FileUtils.copyInputStreamToFile(stream, file);
            //这个时候再去获取证书的文件路径 就可以正常获取了
            String filePath = file.getAbsolutePath();
 
 
 
            //第二步:创建数据,用于把我们模板中的{{}}包裹的变量替换掉,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");
 
            List<Map<String, Object>> mapArrayList = (ArrayList<Map<String, Object>>) params.get("list3");
            ArrayList<RowRenderData> rsList1 = new ArrayList<>();
            ArrayList<RowRenderData> rsList3 = new ArrayList<>();
            List<Map> detailList = new ArrayList<>();
            for (int i = 0; i < list1.size(); i++) {
                DustForm dustForm = list1.get(i);
                Map maps = new HashMap();
                maps.put("table1", i+1);
                maps.put("table2", dustForm.getRoad());
                maps.put("table3", dustForm.getValue());
                detailList.add(maps);
            }
            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);
                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);
            }
            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());
            HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
            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("time1",map.get("date1").toString());
                put("time2",map.get("date2").toString());
                put("detailList", detailList);
                put("detailList2", detailList2);
            }});
 
            response.setContentType("multipart/form-data");
            // 设置文件名
            response.addHeader("Content-Disposition", "attachment;fileName=ce.docx" );
            response.setCharacterEncoding("UTF-8");
            OutputStream out = response.getOutputStream();
            compile.write(out);
            out.flush();
            out.close();
            compile.close();
        } catch (IOException e) {
            log.error ("导出失败,请联系网站管理员!", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
 
    }
 
 
 
    public  void dailyDocx( List<DailyVo> dailyVos,HttpServletResponse response) throws IOException {
//        String path = getPath(fileName);
        //获取jar包所在目录
        ApplicationHome applicationHome = new ApplicationHome(getClass());
        //在jar包所在目录下生成一个upload文件夹用来存储上传的图片
        String path = applicationHome.getSource().getParentFile().toString() + "\\static\\img";
 
        String name1 = dailyVos.size()>1?"word/盐城市走航监测报告.docx":"word/盐城市走航监测报告2.docx";
 
        try {
            //InputStream  inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/尘负荷监测报告.docx");
            InputStream stream = WordUtil.class.getClassLoader().getResourceAsStream(name1);
            //获取临时文件
            File file = new File(name1);
            //将读取到的类容存储到临时文件中,后面就可以用这个临时文件访问了
            FileUtils.copyInputStreamToFile(stream, file);
            //这个时候再去获取证书的文件路径 就可以正常获取了
            String filePath = file.getAbsolutePath();
 
 
 
            //第二步:创建数据,用于把我们模板中的{{}}包裹的变量替换掉,map中保存的key一定要和模板中的变量保持一致
            HashMap<String, Object> map = new HashMap<>();
            //设置单元格,表头
            //RowRenderData header1 = RowRenderData.build(new TextRenderData("6495ED", "序号"), new TextRenderData("6495ED", "道路"),new TextRenderData("6495ED", "平均尘负荷(克/平方米)"));
 
            //设置表内容,如果在实际应用中,传入一个list集合或者数组,方可用foreach进行循环填充
            List<Map> detailList1 = new ArrayList<>();
            List<Map> detailList2 = new ArrayList<>();
            List<Map> detailList3 = new ArrayList<>();
            List<Map> detailList4 = new ArrayList<>();
            List<Map> detailList5 = new ArrayList<>();
            List<Map> detailList6 = new ArrayList<>();
            List<Map> detailList7 = new ArrayList<>();
            List<Map> detailList8 = new ArrayList<>();
            StringBuilder builder = new StringBuilder();
            List<Map> pic1 = new ArrayList<>();
            List<Map> pic2 = new ArrayList<>();
            List<Map> pic3 = new ArrayList<>();
            List<Map> pic4 = new ArrayList<>();
            List<Map> pic5 = new ArrayList<>();
            List<Map> pic6 = new ArrayList<>();
            List<Map> pic7 = new ArrayList<>();
            List<Map> pic8 = new ArrayList<>();
 
//            picMap.put("urlImg", Pictures.ofUrl(str, PictureType.JPEG).size(width, height).create());
//            picMap.put("urlImg",new PictureRenderData(500, 500, "G:\\home\\3d423e3cb05d7edc35c38e3173af2a0d.jpg"));
//            picMap.put("urlImg1",new PictureRenderData(500, 500, "G:\\home\\3d423e3cb05d7edc35c38e3173af2a0d.jpg"));
//            picMap.put("urlImg", Pictures.ofUrl("G:\\home\\3d423e3cb05d7edc35c38e3173af2a0d.jpg", PictureType.JPEG).size(500, 500).create());
//            picMap.put("urlImg1", Pictures.ofUrl("G:\\home\\3d423e3cb05d7edc35c38e3173af2a0d.jpg", PictureType.JPEG).size(500, 500).create());
            int i =1;
            for (DailyVo dailyVo : dailyVos) {
                Map picMap1 = new HashMap();
                Map picMap2 = new HashMap();
                Map picMap3 = new HashMap();
                Map picMap4 = new HashMap();
                Map picMap5 = new HashMap();
                Map picMap6 = new HashMap();
                Map picMap7 = new HashMap();
                Map picMap8 = new HashMap();
                List<String> images = dailyVo.getImages();
                if (!ObjectUtils.isEmpty(images)){
 
                    picMap1.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(0)));
//                    picMap1.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\0a4ab467-304d-4871-948f-55aa7e820975.png"));
                    pic1.add(picMap1);
                    picMap2.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(1)));
//                    picMap2.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\0a4ab467-304d-4871-948f-55aa7e820975.png"));
                    pic2.add(picMap2);
                    picMap3.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(2)));
                    pic3.add(picMap3);
                    picMap4.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(3)));
                    pic4.add(picMap4);
                    picMap5.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(4)));
                    pic5.add(picMap5);
                    picMap6.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(5)));
                    pic6.add(picMap6);
                    picMap7.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(6)));
                    pic7.add(picMap7);
                    picMap8.put("urlImg"+i,new PictureRenderData(500, 500, path+"\\"+images.get(7)));
                    pic8.add(picMap8);
                    i++;
                }
                detailList1.add(dailyVo.getCode());
                detailList2.add(dailyVo.getCode());
                detailList3.add(dailyVo.getCode());
                detailList4.add(dailyVo.getCode());
                detailList5.add(dailyVo.getCode());
                detailList6.add(dailyVo.getCode());
                detailList7.add(dailyVo.getCode());
                detailList8.add(dailyVo.getCode());
 
 
                builder.append("("+dailyVo.getCode().get("mac")+")白天对市重点区域(宝龙广场、盐城电厂为主)进行走航监测:常规7参数走航过程中PM\u2082.\u2085均值浓度为"+dailyVo.getCode().get("avgPm25")+"ug/m\u00b3;PM\u2081\u2080均值浓度为"+dailyVo.getCode().get("avgPm10")+"ug/m\u00b3;NO\u2082均值浓度为"
                        +dailyVo.getCode().get("avgNO2")+"ug/m\u00b3;CO均值浓度为"+dailyVo.getCode().get("avgCO")+"mg/m\u00b3;SO\u2082均值浓度为"+dailyVo.getCode().get("avgSO2")+"ug/m\u00b3;O\u2083均值浓度为"+dailyVo.getCode().get("avgO3")+"ug/m\u00b3,VOCs均值浓度"+dailyVo.getCode().get("avgVOC")+"mg/m\u00b3。"+"\n"+"    ");
            }
 
            if (dailyVos.size()>1){
                String name = dailyVos.get(0).getName();
                String type = dailyVos.get(0).getType();
                map.put("code",builder);
                map.put("time1",DateUtils.getCurCNDate());
                map.put("name",name);
                map.put("type",type);
                map.put("mac",dailyVos.get(0).getCode().get("mac"));
                map.put("pm25",dailyVos.get(0).getCode().get("avgPm25"));
                map.put("pm10",dailyVos.get(0).getCode().get("avgPm10"));
                map.put("no2",dailyVos.get(0).getCode().get("avgNO2"));
                map.put("co",dailyVos.get(0).getCode().get("avgCO"));
                map.put("so2",dailyVos.get(0).getCode().get("avgSO2"));
                map.put("o3",dailyVos.get(0).getCode().get("avgO3"));
                map.put("VOCs",dailyVos.get(0).getCode().get("avgVOC"));
                map.put("mac2",dailyVos.get(1).getCode().get("mac"));
                map.put("2pm25",dailyVos.get(1).getCode().get("avgPm25"));
                map.put("2pm10",dailyVos.get(1).getCode().get("avgPm10"));
                map.put("2no2",dailyVos.get(1).getCode().get("avgNO2"));
                map.put("2co",dailyVos.get(1).getCode().get("avgCO"));
                map.put("2so2",dailyVos.get(1).getCode().get("avgSO2"));
                map.put("2o3",dailyVos.get(1).getCode().get("avgO3"));
                map.put("2VOCs",dailyVos.get(1).getCode().get("avgVOC"));
 
 
                HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
                Configure config = Configure.newBuilder().bind("detailList1", policy).bind("detailList2", policy).bind("detailList3", policy).bind("detailList4", policy)
                        .bind("detailList5", policy).bind("detailList6", policy).bind("detailList7", policy).bind("detailList8", policy).build();
                XWPFTemplate compile = XWPFTemplate.compile(filePath,config).render(new HashMap<String, Object>(){{
                    put("code",map.get("code"));
                    put("time1",map.get("time1"));
                    put("mac",map.get("mac"));
                    put("pm25",map.get("pm25"));
                    put("pm10",map.get("pm10"));
                    put("no2",map.get("no2"));
                    put("co",map.get("co"));
                    put("so2",map.get("so2"));
                    put("o3",map.get("o3"));
                    put("VOCs",map.get("VOCs"));
                    put("2pm25",map.get("2pm25"));
                    put("2pm10",map.get("2pm10"));
                    put("2no2",map.get("2no2"));
                    put("2co",map.get("2co"));
                    put("2so2",map.get("2so2"));
                    put("2o3",map.get("2o3"));
                    put("2VOCs",map.get("2VOCs"));
                    put("mac2",map.get("mac2"));
//                put("pho", map.get("pho"));
//                put("pho1", map.get("pho1"));
                    put("name",map.get("name"));
                    put("type",map.get("type"));
                    put("detailList1", detailList1);
                    put("detailList2", detailList2);
                    put("detailList3", detailList3);
                    put("detailList4", detailList4);
                    put("detailList5", detailList5);
                    put("detailList6", detailList6);
                    put("detailList7", detailList7);
                    put("detailList8", detailList8);
                    put("picList1", pic1);
                    put("picList2", pic2);
                    put("picList3", pic3);
                    put("picList4", pic4);
                    put("picList5", pic5);
                    put("picList6", pic6);
                    put("picList7", pic7);
                    put("picList8", pic8);
                }});
                response.setContentType("multipart/form-data");
                // 设置文件名
                response.addHeader("Content-Disposition", "attachment;fileName=ce.docx" );
//            response.setHeader("Content-Disposition", "attachment; filename=\"" + name+type+"监测报告" + "\"");
                response.setCharacterEncoding("UTF-8");
                //保存到本地
/*            File file1 = new File("G:\\test\\test2.docx");
            FileOutputStream out = new FileOutputStream(file1);
            compile.write(out);*/
                //下载到线上
                OutputStream out = response.getOutputStream();
                compile.write(out);
                out.flush();
                out.close();
                compile.close();
 
            }else {
                String name = dailyVos.get(0).getName();
                String type = dailyVos.get(0).getType();
                map.put("code",builder);
                map.put("time1",DateUtils.getCurCNDate());
                map.put("name",name);
                map.put("type",type);
                map.put("mac",dailyVos.get(0).getCode().get("mac"));
                map.put("pm25",dailyVos.get(0).getCode().get("avgPm25"));
                map.put("pm10",dailyVos.get(0).getCode().get("avgPm10"));
                map.put("no2",dailyVos.get(0).getCode().get("avgNO2"));
                map.put("co",dailyVos.get(0).getCode().get("avgCO"));
                map.put("so2",dailyVos.get(0).getCode().get("avgSO2"));
                map.put("o3",dailyVos.get(0).getCode().get("avgO3"));
                map.put("VOCs",dailyVos.get(0).getCode().get("avgVOC"));
 
                HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
                Configure config = Configure.newBuilder().bind("detailList1", policy).bind("detailList2", policy).bind("detailList3", policy).bind("detailList4", policy)
                        .bind("detailList5", policy).bind("detailList6", policy).bind("detailList7", policy).bind("detailList8", policy).build();
                XWPFTemplate compile = XWPFTemplate.compile(filePath,config).render(new HashMap<String, Object>(){{
                    put("code",map.get("code"));
                    put("time1",map.get("time1"));
                    put("mac",map.get("mac"));
                    put("pm25",map.get("pm25"));
                    put("pm10",map.get("pm10"));
                    put("no2",map.get("no2"));
                    put("co",map.get("co"));
                    put("so2",map.get("so2"));
                    put("o3",map.get("o3"));
                    put("VOCs",map.get("VOCs"));
//                put("pho", map.get("pho"));
//                put("pho1", map.get("pho1"));
                    put("name",map.get("name"));
                    put("type",map.get("type"));
                    put("detailList1", detailList1);
                    put("detailList2", detailList2);
                    put("detailList3", detailList3);
                    put("detailList4", detailList4);
                    put("detailList5", detailList5);
                    put("detailList6", detailList6);
                    put("detailList7", detailList7);
                    put("detailList8", detailList8);
                    put("picList1", pic1);
                    put("picList2", pic2);
                    put("picList3", pic3);
                    put("picList4", pic4);
                    put("picList5", pic5);
                    put("picList6", pic6);
                    put("picList7", pic7);
                    put("picList8", pic8);
                }});
                response.setContentType("multipart/form-data");
                // 设置文件名
                response.addHeader("Content-Disposition", "attachment;fileName=ce.docx" );
//            response.setHeader("Content-Disposition", "attachment; filename=\"" + name+type+"监测报告" + "\"");
                response.setCharacterEncoding("UTF-8");
                //保存到本地
/*            File file1 = new File("G:\\test\\test2.docx");
            FileOutputStream out = new FileOutputStream(file1);
            compile.write(out);*/
                //下载到线上
                OutputStream out = response.getOutputStream();
                compile.write(out);
                out.flush();
                out.close();
                compile.close();
 
            }
 
 
        } catch (IOException e) {
            log.error ("导出失败,请联系网站管理员!", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
 
    }
 
}