|
|
@@ -25,15 +25,19 @@ import com.izouma.wenlvju.service.storage.StorageService;
|
|
|
import com.izouma.wenlvju.utils.JpaUtils;
|
|
|
import freemarker.template.Configuration;
|
|
|
import freemarker.template.Template;
|
|
|
+import freemarker.template.TemplateException;
|
|
|
import freemarker.template.Version;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.StringWriter;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
@@ -142,6 +146,7 @@ public class ReportService {
|
|
|
.collect(Collectors.groupingBy(Record::getExaminationAgency));
|
|
|
//备案承办单位
|
|
|
Map<String, List<Record>> organizer = records.stream()
|
|
|
+ .filter(record -> ObjectUtil.isNotNull(record.getUscc()))
|
|
|
.collect(Collectors.groupingBy(Record::getUscc));
|
|
|
//备案监管
|
|
|
// List<RecordExpertAudit> recordAudits = recordExpertAuditRepo.findAllByRecordIdIn(recordIds);
|
|
|
@@ -158,10 +163,20 @@ public class ReportService {
|
|
|
|
|
|
List<ReportDTO> reportDTOS = new ArrayList<>();
|
|
|
examinationAgency.forEach((key, value) -> {
|
|
|
- GradingOrganization go = gradingOrganizationMap.get(key);
|
|
|
+ GradingOrganization go = gradingOrganizationMap.get(key.trim());
|
|
|
+
|
|
|
// 投诉
|
|
|
- List<Complain> complainList = complainsByName.get(go.getId());
|
|
|
- String complainContent = complainList.stream().map(Complain::getTitle).collect(Collectors.joining(","));
|
|
|
+ String complainContent = "";
|
|
|
+ int size = 0;
|
|
|
+ if (ObjectUtil.isNotNull(go)) {
|
|
|
+ List<Complain> complainList = complainsByName.get(go.getId());
|
|
|
+ if (ObjectUtil.isNotNull(complainList)) {
|
|
|
+ complainContent = complainList.stream().map(Complain::getTitle).collect(Collectors.joining(","));
|
|
|
+ size = complainList.size();
|
|
|
+ }
|
|
|
+ ids.remove(go.getId());
|
|
|
+ }
|
|
|
+
|
|
|
// 备案
|
|
|
int examCenterQuantity = value.stream().mapToInt(Record::getExamCenterQuantity).sum();
|
|
|
int examQuantity = value.stream().mapToInt(Record::getExamQuantity).sum();
|
|
|
@@ -174,32 +189,45 @@ public class ReportService {
|
|
|
reportDTOS.add(ReportDTO.builder()
|
|
|
.unitType(UnitType.GRADING_ORGANIZATION)
|
|
|
.name(key)
|
|
|
- .complain(complainList.size())
|
|
|
+ .complain(size)
|
|
|
.complainContent(complainContent)
|
|
|
.examCenterQuantity(examCenterQuantity)
|
|
|
.examQuantity(examQuantity)
|
|
|
.build());
|
|
|
- ids.remove(go.getId());
|
|
|
+
|
|
|
});
|
|
|
|
|
|
organizer.forEach((key, value) -> {
|
|
|
Organization or = organizationMap.get(key);
|
|
|
+
|
|
|
// 投诉
|
|
|
- List<Complain> complainList = complainsByName.get(or.getId());
|
|
|
- String complainContent = complainList.stream().map(Complain::getTitle).collect(Collectors.joining(","));
|
|
|
+ String name = value.get(0).getOrganizer();
|
|
|
+ String complainContent = "";
|
|
|
+ int size = 0;
|
|
|
+ if (ObjectUtil.isNotNull(or)) {
|
|
|
+ name = or.getName();
|
|
|
+ // 投诉
|
|
|
+ List<Complain> complainList = complainsByName.get(or.getId());
|
|
|
+ if (ObjectUtil.isNotNull(complainList)) {
|
|
|
+ complainContent = complainList.stream().map(Complain::getTitle).collect(Collectors.joining(","));
|
|
|
+ size = complainList.size();
|
|
|
+ }
|
|
|
+ ids.remove(or.getId());
|
|
|
+ }
|
|
|
// 备案
|
|
|
int examCenterQuantity = value.stream().mapToInt(Record::getExamCenterQuantity).sum();
|
|
|
int examQuantity = value.stream().mapToInt(Record::getExamQuantity).sum();
|
|
|
|
|
|
+
|
|
|
reportDTOS.add(ReportDTO.builder()
|
|
|
.unitType(UnitType.ORGANIZATION)
|
|
|
- .name(key)
|
|
|
- .complain(complainList.size())
|
|
|
+ .name(name)
|
|
|
+ .complain(size)
|
|
|
.complainContent(complainContent)
|
|
|
.examCenterQuantity(examCenterQuantity)
|
|
|
.examQuantity(examQuantity)
|
|
|
.build());
|
|
|
- ids.remove(or.getId());
|
|
|
+
|
|
|
});
|
|
|
|
|
|
if (CollUtil.isNotEmpty(ids)) {
|
|
|
@@ -293,7 +321,7 @@ public class ReportService {
|
|
|
/*
|
|
|
生成word
|
|
|
*/
|
|
|
- public void word(Report report) {
|
|
|
+ public void word(Report report) throws IOException, TemplateException {
|
|
|
// 开始结束时间
|
|
|
Map<String, Object> date = this.getDate(report);
|
|
|
if (ObjectUtil.isNull(date)) {
|
|
|
@@ -311,68 +339,87 @@ public class ReportService {
|
|
|
List<RecordSpecialty> recordSpecialties = recordSpecialtyRepo.findAllByRecordIdIn(recordIds);
|
|
|
|
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
|
- try {
|
|
|
- //标题
|
|
|
- dataMap.put("year", report.getYear());
|
|
|
- if (ReportType.QUARTERLY.equals(report.getType())) {
|
|
|
- String[] arr = {"一季度", "二季度", "三季度", "四季度"};
|
|
|
- dataMap.put("quarterly", arr[report.getQuarterly() - 1]);
|
|
|
- } else if (ReportType.MONTHLY.equals(report.getType())) {
|
|
|
- dataMap.put("month", report.getMonth() + "月");
|
|
|
- }
|
|
|
-
|
|
|
- //总统计
|
|
|
- Map<String, Integer> total = this.getTotal(records, complains);
|
|
|
- dataMap.put("record", total.get("record"));
|
|
|
- dataMap.put("totalExamQuantity", total.get("examQuantity"));
|
|
|
- dataMap.put("totalComplain", total.get("complain"));
|
|
|
-
|
|
|
- //各专业统计
|
|
|
- Map<String, Long> specialty = this.getSpecialty(recordSpecialties);
|
|
|
- dataMap.put("music", specialty.get("01"));
|
|
|
- dataMap.put("dance", specialty.get("02"));
|
|
|
- dataMap.put("fineArt", specialty.get("03"));
|
|
|
- dataMap.put("operaDrama", specialty.get("04"));
|
|
|
- dataMap.put("folkArt", specialty.get("05"));
|
|
|
-
|
|
|
- //考级机构/承办单位统计
|
|
|
- List<ReportDTO> reportDTOS = this.generate(records, recordIds, complains);
|
|
|
- Map<UnitType, List<ReportDTO>> unitTypeListMap = reportDTOS.stream()
|
|
|
- .collect(Collectors.groupingBy(ReportDTO::getUnitType));
|
|
|
- //承办单位
|
|
|
- List<ReportDTO> reports = unitTypeListMap.get(UnitType.ORGANIZATION);
|
|
|
- List<Map<String, Object>> listMap = new ArrayList<>();
|
|
|
- reports.forEach(dto -> {
|
|
|
- Map<String, Object> goMap = new HashMap<>();
|
|
|
- goMap.put("name", dto.getName());
|
|
|
- goMap.put("examCenterQuantity", dto.getExamCenterQuantity());
|
|
|
- goMap.put("examQuantity", dto.getExamQuantity());
|
|
|
- goMap.put("complain", dto.getComplain());
|
|
|
- goMap.put("complainContent", dto.getComplainContent());
|
|
|
- listMap.add(goMap);
|
|
|
- });
|
|
|
-
|
|
|
- dataMap.put("list", listMap);
|
|
|
-
|
|
|
- //Configuration 用于读取ftl文件
|
|
|
- Configuration configuration = new Configuration(new Version("2.3.0"));
|
|
|
-
|
|
|
- configuration.setDefaultEncoding("utf-8");
|
|
|
- configuration.setClassForTemplateLoading(this.getClass(), "/templates");//指定ftl所在目录,根据自己的改
|
|
|
- StringWriter writer = new StringWriter();
|
|
|
- Template template = configuration.getTemplate("ReportTemplate.ftl", "utf-8");//以utf-8的编码读取ftl文件
|
|
|
- template.process(dataMap, writer);
|
|
|
-
|
|
|
- InputStream is = IOUtils.toInputStream(writer.toString(), "UTF-8");
|
|
|
- String url = storageService.uploadFromInputStream(is, "/word");
|
|
|
-
|
|
|
- report.setFile(url);
|
|
|
- report.setTime(String.valueOf(date.get("time")));
|
|
|
- report.setTitle("南京市社会艺术水平考级监管报告");
|
|
|
- reportRepo.save(report);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("生成word错误", e);
|
|
|
- throw new BusinessException(e.getMessage());
|
|
|
+// try {
|
|
|
+ //标题
|
|
|
+ dataMap.put("year", report.getYear());
|
|
|
+ if (ReportType.QUARTERLY.equals(report.getType())) {
|
|
|
+ String[] arr = {"一季度", "二季度", "三季度", "四季度"};
|
|
|
+ dataMap.put("quarterly", arr[report.getQuarterly() - 1]);
|
|
|
+ dataMap.put("month", "");
|
|
|
+ } else if (ReportType.MONTHLY.equals(report.getType())) {
|
|
|
+ dataMap.put("month", report.getMonth() + "月");
|
|
|
+ dataMap.put("quarterly", "");
|
|
|
+ } else {
|
|
|
+ dataMap.put("quarterly", "");
|
|
|
+ dataMap.put("month", "");
|
|
|
}
|
|
|
+
|
|
|
+ //总统计
|
|
|
+ Map<String, Integer> total = this.getTotal(records, complains);
|
|
|
+ dataMap.put("record", total.get("record"));
|
|
|
+ dataMap.put("totalExamQuantity", total.get("examQuantity"));
|
|
|
+ dataMap.put("totalComplain", total.get("complain"));
|
|
|
+
|
|
|
+ //各专业统计
|
|
|
+ Map<String, Long> specialty = this.getSpecialty(recordSpecialties);
|
|
|
+ dataMap.put("music", specialty.get("01"));
|
|
|
+ dataMap.put("dance", specialty.get("02"));
|
|
|
+ dataMap.put("fineArt", specialty.get("03"));
|
|
|
+ dataMap.put("operaDrama", specialty.get("04"));
|
|
|
+ dataMap.put("folkArt", specialty.get("05"));
|
|
|
+
|
|
|
+ //考级机构/承办单位统计
|
|
|
+ List<ReportDTO> reportDTOS = this.generate(records, recordIds, complains);
|
|
|
+ Map<UnitType, List<ReportDTO>> unitTypeListMap = reportDTOS.stream()
|
|
|
+ .collect(Collectors.groupingBy(ReportDTO::getUnitType));
|
|
|
+ //考级机构
|
|
|
+ List<ReportDTO> reportsGo = unitTypeListMap.get(UnitType.GRADING_ORGANIZATION);
|
|
|
+ List<Map<String, Object>> listMapGo = new ArrayList<>();
|
|
|
+ reportsGo.forEach(dto -> {
|
|
|
+ Map<String, Object> goMap = new HashMap<>();
|
|
|
+ goMap.put("name", dto.getName());
|
|
|
+ goMap.put("examCenterQuantity", dto.getExamCenterQuantity());
|
|
|
+ goMap.put("examQuantity", dto.getExamQuantity());
|
|
|
+ goMap.put("complain", dto.getComplain());
|
|
|
+ goMap.put("complainContent", dto.getComplainContent());
|
|
|
+ listMapGo.add(goMap);
|
|
|
+ });
|
|
|
+ dataMap.put("list", listMapGo);
|
|
|
+
|
|
|
+ //承办单位
|
|
|
+ List<ReportDTO> reports = unitTypeListMap.get(UnitType.ORGANIZATION);
|
|
|
+ List<Map<String, Object>> listMap = new ArrayList<>();
|
|
|
+ reports.forEach(dto -> {
|
|
|
+ Map<String, Object> orMap = new HashMap<>();
|
|
|
+ orMap.put("name", dto.getName());
|
|
|
+ orMap.put("examCenterQuantity", dto.getExamCenterQuantity());
|
|
|
+ orMap.put("examQuantity", dto.getExamQuantity());
|
|
|
+ orMap.put("complain", dto.getComplain());
|
|
|
+ orMap.put("complainContent", dto.getComplainContent());
|
|
|
+ listMap.add(orMap);
|
|
|
+ });
|
|
|
+ dataMap.put("listOr", listMap);
|
|
|
+
|
|
|
+ //Configuration 用于读取ftl文件
|
|
|
+ Configuration configuration = new Configuration(new Version("2.3.0"));
|
|
|
+
|
|
|
+ configuration.setDefaultEncoding("utf-8");
|
|
|
+ configuration.setClassForTemplateLoading(this.getClass(), "/templates");//指定ftl所在目录,根据自己的改
|
|
|
+ StringWriter writer = new StringWriter();
|
|
|
+ Template template = configuration.getTemplate("ReportTemplate.ftl", "utf-8");//以utf-8的编码读取ftl文件
|
|
|
+ template.process(dataMap, writer);
|
|
|
+
|
|
|
+ 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.setFile(url);
|
|
|
+ report.setTime(String.valueOf(date.get("time")));
|
|
|
+ report.setTitle("南京市社会艺术水平考级监管报告");
|
|
|
+ reportRepo.save(report);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("生成word错误", e);
|
|
|
+// throw new BusinessException(e.getMessage());
|
|
|
+// }
|
|
|
}
|
|
|
}
|