|
|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.wenlvju.service.regulation;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -26,6 +27,7 @@ import com.izouma.wenlvju.service.poi.PoiWordTable;
|
|
|
import com.izouma.wenlvju.service.storage.StorageService;
|
|
|
import com.izouma.wenlvju.utils.ChartUtils;
|
|
|
import com.izouma.wenlvju.utils.JpaUtils;
|
|
|
+import com.izouma.wenlvju.utils.ObjUtils;
|
|
|
import freemarker.template.Configuration;
|
|
|
import freemarker.template.Template;
|
|
|
import freemarker.template.TemplateException;
|
|
|
@@ -138,6 +140,71 @@ public class ReportService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ public void getDate1(Report report) {
|
|
|
+ //开始结束时间
|
|
|
+ int year = report.getYear();
|
|
|
+ LocalDateTime start = LocalDateTime.of(year, 1, 1, 0, 0);
|
|
|
+ LocalDate endDate = LocalDate.of(year, 12, 31);
|
|
|
+ //名称
|
|
|
+ String time = year + "年";
|
|
|
+
|
|
|
+ switch (report.getType()) {
|
|
|
+ case ANNUAL:
|
|
|
+ Report result = reportRepo.findByTypeAndYear(ReportType.ANNUAL, year);
|
|
|
+ if (ObjectUtil.isNotNull(result)) {
|
|
|
+ BeanUtil.copyProperties(result, report);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case QUARTERLY:
|
|
|
+ int quarterly = report.getQuarterly();
|
|
|
+ Report result1 = reportRepo.findByYearAndQuarterly(year, quarterly);
|
|
|
+ if (ObjectUtil.isNotNull(result1)) {
|
|
|
+ BeanUtil.copyProperties(result1, report);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (quarterly) {
|
|
|
+ case 1:
|
|
|
+ endDate = LocalDate.of(year, 3, 31);
|
|
|
+ time += "一季度";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ start = LocalDateTime.of(year, 4, 1, 0, 0);
|
|
|
+ endDate = LocalDate.of(year, 6, 30);
|
|
|
+ time += "二季度";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ start = LocalDateTime.of(year, 7, 1, 0, 0);
|
|
|
+ endDate = LocalDate.of(year, 9, 30);
|
|
|
+ time += "三季度";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ start = LocalDateTime.of(year, 10, 1, 0, 0, 0);
|
|
|
+ time += "四季度";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case MONTHLY:
|
|
|
+ Report result2 = reportRepo.findByYearAndMonth(year, report.getMonth());
|
|
|
+ if (ObjectUtil.isNotNull(result2)) {
|
|
|
+ BeanUtil.copyProperties(result2, report);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDate startDate = LocalDate.of(year, report.getMonth(), 1);
|
|
|
+ start = LocalDateTime.of(startDate, LocalTime.MIN);
|
|
|
+ endDate = startDate.plusMonths(1).minusDays(1);
|
|
|
+ time += report.getMonth() + "月";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 结束日期
|
|
|
+ LocalDateTime end = LocalDateTime.of(endDate, LocalTime.MAX);
|
|
|
+ report.setStart(start);
|
|
|
+ report.setEnd(end);
|
|
|
+ report.setTime(time);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成报告
|
|
|
*/
|
|
|
@@ -338,13 +405,13 @@ public class ReportService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 生成word
|
|
|
+ * 生成freemarkerWord
|
|
|
*
|
|
|
* @param report
|
|
|
* @throws IOException
|
|
|
* @throws TemplateException
|
|
|
*/
|
|
|
- public void word(Report report) throws IOException, TemplateException {
|
|
|
+ public void freemarkerWord(Report report) throws IOException, TemplateException {
|
|
|
// 开始结束时间
|
|
|
Map<String, Object> date = this.getDate(report);
|
|
|
if (ObjectUtil.isNull(date)) {
|
|
|
@@ -386,9 +453,6 @@ public class ReportService {
|
|
|
//各专业统计
|
|
|
List<NumOfReport> specialty = this.getSpecialty(recordSpecialties);
|
|
|
specialty.forEach(num -> dataMap.put(num.getName(), num.getNum()));
|
|
|
- //画图
|
|
|
- Map<String, Integer> specialtyMap = specialty.stream()
|
|
|
- .collect(Collectors.toMap(NumOfReport::getName, NumOfReport::getNum));
|
|
|
|
|
|
//考级机构/承办单位统计
|
|
|
List<ReportStatistic> reportDTOS = this.generate(records, complains);
|
|
|
@@ -409,9 +473,9 @@ public class ReportService {
|
|
|
dataMap.put("list", listMapGo);
|
|
|
|
|
|
//承办单位
|
|
|
- List<ReportStatistic> reportStatistics = unitTypeListMap.get(UnitType.ORGANIZATION);
|
|
|
+ List<ReportStatistic> reportOr = unitTypeListMap.get(UnitType.ORGANIZATION);
|
|
|
List<Map<String, Object>> listMap = new ArrayList<>();
|
|
|
- reportStatistics.forEach(dto -> {
|
|
|
+ reportOr.forEach(dto -> {
|
|
|
Map<String, Object> orMap = new HashMap<>();
|
|
|
orMap.put("name", dto.getName());
|
|
|
orMap.put("examCenterQuantity", dto.getExamCenterQuantity());
|
|
|
@@ -442,7 +506,7 @@ public class ReportService {
|
|
|
report.setTime(String.valueOf(date.get("time")));
|
|
|
report.setTitle("南京市社会艺术水平考级监管报告");
|
|
|
Long id = reportRepo.save(report).getId();
|
|
|
- List<ReportStatistic> statistics = reportStatistics.stream()
|
|
|
+ List<ReportStatistic> statistics = reportDTOS.stream()
|
|
|
.peek(statistic -> statistic.setReportId(id))
|
|
|
.collect(Collectors.toList());
|
|
|
reportStatisticRepo.saveAll(statistics);
|
|
|
@@ -469,10 +533,9 @@ public class ReportService {
|
|
|
|
|
|
//标题
|
|
|
String time = String.valueOf(date.get("time"));
|
|
|
- final String returnurl = "/Users/qiufangchao/Desktop/result.docx"; // 结果文件
|
|
|
- final String templateurl = "/Users/qiufangchao/Desktop/poiTemp.docx"; // 模板文件
|
|
|
|
|
|
- InputStream is = new FileInputStream(templateurl);
|
|
|
+ InputStream is = this.getClass()
|
|
|
+ .getResourceAsStream("/templates/chart/poiTemp.docx");
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
|
|
|
Map<String, String> textMap = new HashMap<>();
|
|
|
@@ -593,33 +656,23 @@ public class ReportService {
|
|
|
PoiWordTable.doParagraphs(doc, textMap, tableList);
|
|
|
PoiWordTable.doCharts(doc, items);
|
|
|
|
|
|
- try {
|
|
|
- File file = new File(returnurl);
|
|
|
- if (file.exists()) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
- FileOutputStream fos = new FileOutputStream(returnurl);
|
|
|
- doc.write(fos);
|
|
|
- fos.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
|
|
+ doc.write(fos);
|
|
|
+ fos.close();
|
|
|
|
|
|
-// InputStream is = IOUtils.toInputStream(writer.toString(), "UTF-8");
|
|
|
-//
|
|
|
-// String url = storageService.uploadFromInputStream(is, "word" + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
-// + RandomStringUtils.randomAlphabetic(8) + ".docx");
|
|
|
-//
|
|
|
-// report.setSpecialty(specialty);
|
|
|
-// report.setTotal(total);
|
|
|
-// report.setFile(url);
|
|
|
-// report.setTime(time);
|
|
|
-// report.setTitle("南京市社会艺术水平考级监管报告");
|
|
|
-// Long id = reportRepo.save(report).getId();
|
|
|
-// List<ReportStatistic> statistics = reportsOr.stream()
|
|
|
-// .peek(statistic -> statistic.setReportId(id))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-// reportStatisticRepo.saveAll(statistics);
|
|
|
+ String url = storageService.uploadFromInputStream(new ByteArrayInputStream(fos.toByteArray()), "word" + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
+ + RandomStringUtils.randomAlphabetic(8) + ".docx");
|
|
|
+
|
|
|
+ report.setSpecialty(specialty);
|
|
|
+ report.setTotal(total);
|
|
|
+ report.setFile(url);
|
|
|
+ report.setTime(time);
|
|
|
+ report.setTitle("南京市社会艺术水平考级监管报告");
|
|
|
+ Long id = reportRepo.save(report).getId();
|
|
|
+ List<ReportStatistic> statistics = reportsOr.stream()
|
|
|
+ .peek(statistic -> statistic.setReportId(id))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ reportStatisticRepo.saveAll(statistics);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -647,4 +700,223 @@ public class ReportService {
|
|
|
// }
|
|
|
return doc;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 存数据
|
|
|
+ *
|
|
|
+ * @param report
|
|
|
+ */
|
|
|
+ public void saveStatistic(Report report) {
|
|
|
+ // 开始结束时间
|
|
|
+ this.getDate1(report);
|
|
|
+ List<ReportStatistic> reportStatistics = null;
|
|
|
+ if (ObjectUtil.isNotNull(report.getId())) {
|
|
|
+ if (report.getGeneratedAt().isAfter(report.getEnd())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ reportStatistics = reportStatisticRepo.findAllByReportId(report.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime start = report.getStart();
|
|
|
+ LocalDateTime end = report.getEnd();
|
|
|
+ //备案
|
|
|
+ List<Record> records = recordRepo.findAllByExaminationStartTimeBetween(start.toLocalDate(), end.toLocalDate());
|
|
|
+ //投诉
|
|
|
+ List<Complain> complains = complainRepo.findAllByFinishIsTrueAndComplainAtBetween(start, end);
|
|
|
+ //备案专业
|
|
|
+ List<Long> recordIds = records.stream().map(Record::getId).collect(Collectors.toList());
|
|
|
+ List<RecordSpecialty> recordSpecialties = recordSpecialtyRepo.findAllByRecordIdIn(recordIds);
|
|
|
+ //备案检查
|
|
|
+ List<RecordExpertAudit> recordAudits = recordExpertAuditRepo.findAllByRecordIdIn(recordIds);
|
|
|
+
|
|
|
+ //总统计
|
|
|
+ List<NumOfReport> total = this.getTotal(records, complains, recordAudits);
|
|
|
+
|
|
|
+ //各专业统计
|
|
|
+ List<NumOfReport> specialty = this.getSpecialty(recordSpecialties);
|
|
|
+
|
|
|
+ //考级机构/承办单位统计
|
|
|
+ List<ReportStatistic> reportDTOS = this.generate(records, complains);
|
|
|
+
|
|
|
+ report.setSpecialty(specialty);
|
|
|
+ report.setTotal(total);
|
|
|
+ report.setTitle("南京市社会艺术水平考级监管报告");
|
|
|
+ //生成时间
|
|
|
+ report.setGeneratedAt(LocalDateTime.now());
|
|
|
+ Long id = reportRepo.save(report).getId();
|
|
|
+ List<ReportStatistic> statistics = reportDTOS.stream()
|
|
|
+ .peek(statistic -> statistic.setReportId(id))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(reportStatistics)) {
|
|
|
+ Map<UnitType, List<ReportStatistic>> unitTypeListMap = reportDTOS.stream()
|
|
|
+ .collect(Collectors.groupingBy(ReportStatistic::getUnitType));
|
|
|
+ //考级机构
|
|
|
+ Map<String, ReportStatistic> reportGo = unitTypeListMap.get(UnitType.GRADING_ORGANIZATION)
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ReportStatistic::getName, rs -> rs));
|
|
|
+ Map<String, ReportStatistic> reportsOr = unitTypeListMap.get(UnitType.ORGANIZATION).stream()
|
|
|
+ .collect(Collectors.toMap(ReportStatistic::getName, rs -> rs));
|
|
|
+ statistics.forEach(st -> {
|
|
|
+ if (UnitType.GRADING_ORGANIZATION.equals(st.getUnitType())) {
|
|
|
+ ReportStatistic rs = reportGo.get(st.getName());
|
|
|
+ if (ObjectUtil.isNotNull(rs)) {
|
|
|
+ st.setId(rs.getId());
|
|
|
+ }
|
|
|
+ } else if (UnitType.ORGANIZATION.equals(st.getUnitType())) {
|
|
|
+ ReportStatistic rs = reportsOr.get(st.getName());
|
|
|
+ if (ObjectUtil.isNotNull(rs)) {
|
|
|
+ st.setId(rs.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ reportStatisticRepo.saveAll(statistics);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成文档
|
|
|
+ *
|
|
|
+ * @param report
|
|
|
+ * @throws IOException
|
|
|
+ * @throws InvalidFormatException
|
|
|
+ */
|
|
|
+ public String generateWord(Report report) throws IOException, InvalidFormatException {
|
|
|
+ if (StrUtil.isNotEmpty(report.getFile())) {
|
|
|
+ return report.getFile();
|
|
|
+ }
|
|
|
+
|
|
|
+ InputStream is = this.getClass()
|
|
|
+ .getResourceAsStream("/templates/chart/poiTemp.docx");
|
|
|
+ XWPFDocument doc = new XWPFDocument(is);
|
|
|
+
|
|
|
+ Map<String, String> textMap = new HashMap<>();
|
|
|
+ List<List<String[]>> tableList = new ArrayList<>();
|
|
|
+ List<ChartItem> items = new ArrayList<>();
|
|
|
+
|
|
|
+ textMap.put("Title", report.getTime() + "南京市社会艺术水平考级监管报告");
|
|
|
+
|
|
|
+ //总统计
|
|
|
+ List<NumOfReport> total = report.getTotal();
|
|
|
+ List<String[]> tableTotal = new ArrayList<>();
|
|
|
+ tableTotal.add(new String[]{"备案条数", "报考人数", "投诉数量", "检查数量"});
|
|
|
+ Map<String, Integer> totalMap = total.stream()
|
|
|
+ .collect(Collectors.toMap(NumOfReport::getName, NumOfReport::getNum));
|
|
|
+ tableTotal.add(new String[]{String.valueOf(totalMap.get("record")), String.valueOf(totalMap.get("totalExamQuantity")),
|
|
|
+ String.valueOf(totalMap.get("totalComplain")), String.valueOf(totalMap.get("totalAudit"))});
|
|
|
+ tableList.add(tableTotal);
|
|
|
+
|
|
|
+ //各专业统计
|
|
|
+ List<NumOfReport> specialty = report.getSpecialty();
|
|
|
+ List<String[]> tableSpecialty = new ArrayList<>();
|
|
|
+ Map<String, Integer> specialtyMap = specialty.stream()
|
|
|
+ .collect(Collectors.toMap(NumOfReport::getName, NumOfReport::getNum));
|
|
|
+ tableSpecialty.add(new String[]{"音乐", "舞蹈", "美术", "戏曲戏剧", "曲艺"});
|
|
|
+ tableSpecialty.add(new String[]{String.valueOf(specialtyMap.get("音乐")), String.valueOf(specialtyMap.get("舞蹈")),
|
|
|
+ String.valueOf(specialtyMap.get("美术")), String.valueOf(specialtyMap.get("戏曲戏剧")), String.valueOf(specialtyMap.get("曲艺"))});
|
|
|
+ tableList.add(tableSpecialty);
|
|
|
+
|
|
|
+ //画图
|
|
|
+ List<String> titleArr = new ArrayList<>();// 标题
|
|
|
+ titleArr.add("title");
|
|
|
+ titleArr.add("各专业报考场数");
|
|
|
+
|
|
|
+ List<String> fldNameArr = new ArrayList<>();// 字段名
|
|
|
+ fldNameArr.add("key");
|
|
|
+ fldNameArr.add("value");
|
|
|
+
|
|
|
+ List<Map<String, String>> listItemsByType = new ArrayList<>();
|
|
|
+ specialty.forEach(sp -> {
|
|
|
+ Map<String, String> con = new HashMap<>();
|
|
|
+ con.put("key", sp.getName());
|
|
|
+ con.put("value", String.valueOf(sp.getNum()));
|
|
|
+ listItemsByType.add(con);
|
|
|
+ });
|
|
|
+
|
|
|
+ items.add(ChartItem.builder()
|
|
|
+ .fldNameArr(fldNameArr)
|
|
|
+ .type("pie")
|
|
|
+ .titleArr(titleArr)
|
|
|
+ .listItemsByType(listItemsByType)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ //考级机构/承办单位统计
|
|
|
+ List<ReportStatistic> reportDTOS = reportStatisticRepo.findAllByReportId(report.getId());
|
|
|
+ Map<UnitType, List<ReportStatistic>> unitTypeListMap = reportDTOS.stream()
|
|
|
+ .collect(Collectors.groupingBy(ReportStatistic::getUnitType));
|
|
|
+ //考级机构
|
|
|
+ List<ReportStatistic> reportsGo = unitTypeListMap.get(UnitType.GRADING_ORGANIZATION);
|
|
|
+ String[] goTile = {"机构名称", "考级数量", "报考人数", "投诉条数", "投诉内容"};
|
|
|
+ List<String[]> tableGo = new ArrayList<>();
|
|
|
+ tableGo.add(goTile);
|
|
|
+ reportsGo.forEach(dto -> tableGo.add(new String[]{dto.getName(), String.valueOf(dto.getExamCenterQuantity()), String.valueOf(dto.getExamQuantity()),
|
|
|
+ String.valueOf(dto.getComplain()), dto.getComplainContent()}));
|
|
|
+ tableList.add(tableGo);
|
|
|
+
|
|
|
+ //承办单位
|
|
|
+ List<ReportStatistic> reportsOr = unitTypeListMap.get(UnitType.ORGANIZATION);
|
|
|
+ List<String[]> tableOr = new ArrayList<>();
|
|
|
+ tableOr.add(goTile);
|
|
|
+ reportsOr.forEach(dto -> tableOr.add(new String[]{dto.getName(), String.valueOf(dto.getExamCenterQuantity()), String.valueOf(dto.getExamQuantity()),
|
|
|
+ String.valueOf(dto.getComplain()), dto.getComplainContent()}));
|
|
|
+ tableList.add(tableOr);
|
|
|
+
|
|
|
+ //投诉饼图
|
|
|
+ //画图
|
|
|
+ List<String> titleCom = new ArrayList<>();// 标题
|
|
|
+ titleCom.add("title");
|
|
|
+ titleCom.add("考级机构投诉统计");
|
|
|
+
|
|
|
+ List<Map<String, String>> comItemsByType = new ArrayList<>();
|
|
|
+ reportsGo.forEach(sp -> {
|
|
|
+ Map<String, String> con = new HashMap<>();
|
|
|
+ con.put("key", sp.getName());
|
|
|
+ con.put("value", String.valueOf(sp.getComplain()));
|
|
|
+ comItemsByType.add(con);
|
|
|
+ });
|
|
|
+
|
|
|
+ items.add(ChartItem.builder()
|
|
|
+ .fldNameArr(fldNameArr)
|
|
|
+ .type("pie")
|
|
|
+ .titleArr(titleCom)
|
|
|
+ .listItemsByType(comItemsByType)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ //备案柱状图
|
|
|
+ List<String> titleRecord = new ArrayList<>();// 标题
|
|
|
+ titleRecord.add("title");
|
|
|
+ titleRecord.add("承办单位报考人数统计");
|
|
|
+
|
|
|
+ List<Map<String, String>> recordItemsByType = new ArrayList<>();
|
|
|
+ reportsOr.forEach(sp -> {
|
|
|
+ Map<String, String> con = new HashMap<>();
|
|
|
+ con.put("key", sp.getName());
|
|
|
+ con.put("value", String.valueOf(sp.getExamQuantity()));
|
|
|
+ recordItemsByType.add(con);
|
|
|
+ });
|
|
|
+
|
|
|
+ items.add(ChartItem.builder()
|
|
|
+ .fldNameArr(fldNameArr)
|
|
|
+ .type("bar")
|
|
|
+ .titleArr(titleRecord)
|
|
|
+ .listItemsByType(recordItemsByType)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ // 生成文档
|
|
|
+ PoiWordTable.doParagraphs(doc, textMap, tableList);
|
|
|
+ PoiWordTable.doCharts(doc, items);
|
|
|
+
|
|
|
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
|
|
+ doc.write(fos);
|
|
|
+ fos.close();
|
|
|
+
|
|
|
+ String url = storageService.uploadFromInputStream(new ByteArrayInputStream(fos.toByteArray()), "word" + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
+ + RandomStringUtils.randomAlphabetic(8) + ".docx");
|
|
|
+
|
|
|
+ report.setFile(url);
|
|
|
+ reportRepo.save(report);
|
|
|
+
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
}
|