...
|
...
|
@@ -28,6 +28,9 @@ import javax.annotation.Resource; |
28
|
28
|
import javax.servlet.http.HttpServletResponse;
|
29
|
29
|
import java.io.*;
|
30
|
30
|
import java.nio.charset.StandardCharsets;
|
|
31
|
+import java.nio.file.Files;
|
|
32
|
+import java.nio.file.Path;
|
|
33
|
+import java.nio.file.StandardCopyOption;
|
31
|
34
|
import java.text.ParseException;
|
32
|
35
|
import java.text.SimpleDateFormat;
|
33
|
36
|
import java.util.*;
|
...
|
...
|
@@ -471,8 +474,8 @@ public class StatisticsController extends BaseController { |
471
|
474
|
String filePath = JFChartUtils.OUTPUT_DIR + fileName;
|
472
|
475
|
|
473
|
476
|
String dataRange = "【" + (startTime.equals(endTime) ? startTime : startTime + "~" + endTime) + "】";
|
474
|
|
-
|
475
|
|
- buildWord(dataMap, dataRange, filePath);
|
|
477
|
+ List<String> tempFilePath = new ArrayList<>();
|
|
478
|
+ buildWord(dataMap, dataRange, filePath, tempFilePath);
|
476
|
479
|
try {
|
477
|
480
|
response.setContentType("application/octet-stream");
|
478
|
481
|
response.setCharacterEncoding("utf-8");
|
...
|
...
|
@@ -491,15 +494,29 @@ public class StatisticsController extends BaseController { |
491
|
494
|
outputStream.close();
|
492
|
495
|
} catch (Exception e) {
|
493
|
496
|
e.printStackTrace();
|
|
497
|
+ } finally {
|
|
498
|
+ tempFilePath.add(filePath);
|
|
499
|
+ for (String tp : tempFilePath) {
|
|
500
|
+ File t = new File(tp);
|
|
501
|
+ if (t.exists()) {
|
|
502
|
+ if (!t.delete()) {
|
|
503
|
+ log.error("delete tempfile error!" + tp);
|
|
504
|
+ }
|
|
505
|
+ }
|
|
506
|
+ }
|
494
|
507
|
}
|
495
|
508
|
|
496
|
509
|
}
|
497
|
510
|
|
498
|
511
|
@SuppressWarnings("unchecked")
|
499
|
|
- public void buildWord(Map<String, Object> data, String dataRange, String filePath) throws IOException {
|
|
512
|
+ public void buildWord(Map<String, Object> data, String dataRange, String filePath, List<String> tempFilePath) throws IOException {
|
500
|
513
|
|
501
|
514
|
ClassPathResource resource = new ClassPathResource("/template/statisticsReport.docx");
|
502
|
|
- File file = new File(resource.getFile().toPath().toString());
|
|
515
|
+ Path tempFile = Files.createTempFile("custTemp", ".docx");
|
|
516
|
+ try (InputStream inputStream = resource.getInputStream()) {
|
|
517
|
+ Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING);
|
|
518
|
+ }
|
|
519
|
+
|
503
|
520
|
|
504
|
521
|
Map<String, Object> dataMap = new HashMap<>();
|
505
|
522
|
|
...
|
...
|
@@ -533,57 +550,67 @@ public class StatisticsController extends BaseController { |
533
|
550
|
List<PieChartVo> wiAreaDataList = (List<PieChartVo>) data.get("wiAreaData");
|
534
|
551
|
String dailyPicFile = JFChartUtils.createChart(wiAreaDataList, JFChartTypeEnum.PIE, dataRange + "警情分布图", "市", "数量");
|
535
|
552
|
dataMap.put("sWIAreaPic", Pictures.ofStream(new FileInputStream(dailyPicFile), PictureType.JPEG).size(600, 200).create());
|
|
553
|
+ tempFilePath.add(dailyPicFile);
|
536
|
554
|
|
537
|
555
|
//警情各地市环比变化柱状图
|
538
|
556
|
List<PieChartVo> wissAreaData = (List<PieChartVo>) data.get("wissAreaData");
|
539
|
557
|
String sWISeqAreaPic = JFChartUtils.createChart(wissAreaData, JFChartTypeEnum.BAR, dataRange + "警情环比情况", "市", "环比");
|
540
|
558
|
dataMap.put("sWISeqAreaPic", Pictures.ofStream(new FileInputStream(sWISeqAreaPic), PictureType.JPEG).size(600, 200).create());
|
|
559
|
+ tempFilePath.add(sWISeqAreaPic);
|
541
|
560
|
|
542
|
561
|
//警情子类分布
|
543
|
562
|
List<PieChartVo> wiSubTypeData = (List<PieChartVo>) data.get("wiSubTypeData");
|
544
|
563
|
String wiSubTypeDataPic = JFChartUtils.createChart(wiSubTypeData, JFChartTypeEnum.PIE, dataRange + "警情类别分布", "警情类别", "数量");
|
545
|
564
|
dataMap.put("wiSubTypeDataPic", Pictures.ofStream(new FileInputStream(wiSubTypeDataPic), PictureType.JPEG).size(600, 200).create());
|
546
|
|
-
|
|
565
|
+ tempFilePath.add(wiSubTypeDataPic);
|
547
|
566
|
|
548
|
567
|
//警情分析
|
549
|
568
|
List<PieChartVo> wisDateData = (List<PieChartVo>) data.get("wisDateData");
|
550
|
569
|
String wisDateDataPic = JFChartUtils.createChart(wisDateData, JFChartTypeEnum.LINE, dataRange + "警情趋势", "市", "数量");
|
551
|
570
|
dataMap.put("wisDateDataPic", Pictures.ofStream(new FileInputStream(wisDateDataPic), PictureType.JPEG).size(600, 200).create());
|
|
571
|
+ tempFilePath.add(wisDateDataPic);
|
552
|
572
|
|
553
|
573
|
//案件各地市分布
|
554
|
574
|
List<PieChartVo> caseAreaData = (List<PieChartVo>) data.get("caseAreaData");
|
555
|
575
|
String caseAreaDataPic = JFChartUtils.createChart(caseAreaData, JFChartTypeEnum.PIE, dataRange + "案件分布图", "市", "数量");
|
556
|
576
|
dataMap.put("caseAreaDataPic", Pictures.ofStream(new FileInputStream(caseAreaDataPic), PictureType.JPEG).size(600, 200).create());
|
|
577
|
+ tempFilePath.add(caseAreaDataPic);
|
557
|
578
|
|
558
|
579
|
//电诈案件环比情况
|
559
|
580
|
List<PieChartVo> caseSsAreaData = (List<PieChartVo>) data.get("caseSsAreaData");
|
560
|
581
|
String caseSsAreaDataPic = JFChartUtils.createChart(caseSsAreaData, JFChartTypeEnum.BAR, dataRange + "电诈案件环比情况", "市", "环比");
|
561
|
582
|
dataMap.put("caseSsAreaDataPic", Pictures.ofStream(new FileInputStream(caseSsAreaDataPic), PictureType.JPEG).size(600, 200).create());
|
|
583
|
+ tempFilePath.add(caseSsAreaDataPic);
|
562
|
584
|
|
563
|
585
|
//案件诈骗类型分布
|
564
|
586
|
List<PieChartVo> csfData = (List<PieChartVo>) data.get("csfData");
|
565
|
587
|
String sCsfDataPic = JFChartUtils.createChart(csfData, JFChartTypeEnum.PIE, dataRange + "诈骗类型分布", "诈骗类型", "数量");
|
566
|
588
|
dataMap.put("sCsfDataaPic", Pictures.ofStream(new FileInputStream(sCsfDataPic), PictureType.JPEG).size(600, 200).create());
|
|
589
|
+ tempFilePath.add(sCsfDataPic);
|
567
|
590
|
|
568
|
591
|
//案件引流方式分布图
|
569
|
592
|
List<PieChartVo> ccrmData = (List<PieChartVo>) data.get("ccrmData");
|
570
|
593
|
String ccrmDataPic = JFChartUtils.createChart(ccrmData, JFChartTypeEnum.PIE, dataRange + "引流方式分布图", "引流方式", "数量");
|
571
|
594
|
dataMap.put("ccrmDataPic", Pictures.ofStream(new FileInputStream(ccrmDataPic), PictureType.JPEG).size(600, 200).create());
|
|
595
|
+ tempFilePath.add(ccrmDataPic);
|
572
|
596
|
|
573
|
597
|
//案件支付方式分布图
|
574
|
598
|
List<PieChartVo> ccpmData = (List<PieChartVo>) data.get("ccpmData");
|
575
|
599
|
String ccpmDataPic = JFChartUtils.createChart(ccpmData, JFChartTypeEnum.PIE, dataRange + "支付方式分布图", "支付方式", "数量");
|
576
|
600
|
dataMap.put("ccpmDataPic", Pictures.ofStream(new FileInputStream(ccpmDataPic), PictureType.JPEG).size(600, 200).create());
|
|
601
|
+ tempFilePath.add(ccpmDataPic);
|
577
|
602
|
|
578
|
603
|
//案件受害人职业分布图
|
579
|
604
|
List<PieChartVo> ccCareerData = (List<PieChartVo>) data.get("ccCareerData");
|
580
|
605
|
String ccCareerDataPic = JFChartUtils.createChart(ccCareerData, JFChartTypeEnum.BAR, dataRange + "受害人职业分布图", "受害人职业", "数量");
|
581
|
606
|
dataMap.put("ccCareerDataPic", Pictures.ofStream(new FileInputStream(ccCareerDataPic), PictureType.JPEG).size(600, 200).create());
|
|
607
|
+ tempFilePath.add(ccCareerDataPic);
|
582
|
608
|
|
583
|
609
|
//案损分布
|
584
|
610
|
List<PieChartVo> ccLossData = (List<PieChartVo>) data.get("ccLossData");
|
585
|
611
|
String ccLossDataPic = JFChartUtils.createChart(ccLossData, JFChartTypeEnum.BAR, dataRange + "案损分布", "案损", "数量");
|
586
|
612
|
dataMap.put("ccLossDataPic", Pictures.ofStream(new FileInputStream(ccLossDataPic), PictureType.JPEG).size(600, 200).create());
|
|
613
|
+ tempFilePath.add(ccLossDataPic);
|
587
|
614
|
|
588
|
615
|
int clIndex = 1;
|
589
|
616
|
for (PieChartVo clData : ccLossData) {
|
...
|
...
|
@@ -595,7 +622,7 @@ public class StatisticsController extends BaseController { |
595
|
622
|
List<PieChartVo> ccDateData = (List<PieChartVo>) data.get("ccDateData");
|
596
|
623
|
String ccDateDataPic = JFChartUtils.createChart(ccDateData, JFChartTypeEnum.LINE, dataRange + "发案趋势", "日期", "数量");
|
597
|
624
|
dataMap.put("ccDateDataPic", Pictures.ofStream(new FileInputStream(ccDateDataPic), PictureType.JPEG).size(600, 200).create());
|
598
|
|
-
|
|
625
|
+ tempFilePath.add(ccDateDataPic);
|
599
|
626
|
|
600
|
627
|
//案件受害人性别占比
|
601
|
628
|
List<PieChartVo> sexData = (List<PieChartVo>) data.get("sexData");
|
...
|
...
|
@@ -724,11 +751,15 @@ public class StatisticsController extends BaseController { |
724
|
751
|
dataMap.put("caseLossAreas", caseLossAreas);
|
725
|
752
|
|
726
|
753
|
|
727
|
|
- try (XWPFTemplate template = XWPFTemplate.compile(file, Configure.newBuilder().buildGramer("${", "}").build())
|
|
754
|
+ try (XWPFTemplate template = XWPFTemplate.compile(tempFile.toFile(), Configure.newBuilder().buildGramer("${", "}").build())
|
728
|
755
|
.render(dataMap)) {
|
729
|
756
|
template.writeToFile(filePath);
|
730
|
757
|
}
|
731
|
758
|
|
|
759
|
+ //清理临时文件
|
|
760
|
+ File tf = tempFile.toFile();
|
|
761
|
+ tf.deleteOnExit();
|
|
762
|
+
|
732
|
763
|
}
|
733
|
764
|
|
734
|
765
|
} |
...
|
...
|
|