|
|
@@ -1,6 +1,8 @@
|
|
|
package com.izouma.wenlvju.service.regulation;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.wenlvju.domain.GradingOrganization;
|
|
|
+import com.izouma.wenlvju.domain.Organization;
|
|
|
import com.izouma.wenlvju.domain.Record;
|
|
|
import com.izouma.wenlvju.domain.regulation.Complain;
|
|
|
import com.izouma.wenlvju.domain.regulation.Report;
|
|
|
@@ -40,30 +42,62 @@ public class ReportService {
|
|
|
/**
|
|
|
* 生成报告
|
|
|
*/
|
|
|
- public void generate(Report report) {
|
|
|
- List<Record> records = new ArrayList<>();
|
|
|
- List<Complain> complains = new ArrayList<>();
|
|
|
+ public List<ReportDTO> generate(Report report) {
|
|
|
+ List<Record> records;
|
|
|
+ List<Complain> complains;
|
|
|
+
|
|
|
+ // 开始结束时间
|
|
|
+ int year = Integer.parseInt(report.getYear());
|
|
|
+ LocalDateTime start = LocalDateTime.of(year, 1, 1, 0, 0);
|
|
|
+ LocalDateTime end = LocalDateTime.of(year, 12, 31, 23, 59, 59, 59);
|
|
|
+
|
|
|
+ // 名称
|
|
|
+
|
|
|
+
|
|
|
switch (report.getType()) {
|
|
|
case ANNUAL:
|
|
|
- int year = Integer.parseInt(report.getYear());
|
|
|
- LocalDateTime start = LocalDateTime.of(year, 1, 1, 0, 0);
|
|
|
- LocalDateTime end = LocalDateTime.of(year, 12, 31, 23, 59, 59, 59);
|
|
|
- records = recordRepo.findAllByExaminationStartTimeBetween(start.toLocalDate(), end.toLocalDate());
|
|
|
- complains = complainRepo.findAllByComplainAtBetween(start, end);
|
|
|
+
|
|
|
break;
|
|
|
case QUARTERLY:
|
|
|
+ int quarterly = Integer.parseInt(report.getQuarterly());
|
|
|
+ switch (quarterly) {
|
|
|
+ case 1:
|
|
|
+ end = LocalDateTime.of(year, 3, 31, 23, 59, 59, 59);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ start = LocalDateTime.of(year, 4, 1, 0, 0);
|
|
|
+ end = LocalDateTime.of(year, 6, 30, 23, 59, 59, 59);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ start = LocalDateTime.of(year, 7, 1, 0, 0);
|
|
|
+ end = LocalDateTime.of(year, 9, 30, 23, 59, 59, 59);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ start = LocalDateTime.of(year, 10, 1, 0, 0, 0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
break;
|
|
|
case MONTHLY:
|
|
|
break;
|
|
|
}
|
|
|
+ records = recordRepo.findAllByExaminationStartTimeBetween(start.toLocalDate(), end.toLocalDate());
|
|
|
+ complains = complainRepo.findAllByComplainAtBetween(start, end);
|
|
|
+
|
|
|
Map<String, GradingOrganization> gradingOrganizationMap = gradingOrganizationRepo.findAll()
|
|
|
.stream()
|
|
|
.collect(Collectors.toMap(GradingOrganization::getName, go -> go));
|
|
|
+
|
|
|
+ Map<String, Organization> organizationMap = organizationRepo.findAll()
|
|
|
+ .stream()
|
|
|
+ .filter(or -> ObjectUtil.isNotNull(or.getUscc()))
|
|
|
+ .collect(Collectors.toMap(Organization::getUscc, or -> or));
|
|
|
+
|
|
|
Map<String, List<Record>> examinationAgency = records.stream()
|
|
|
.collect(Collectors.groupingBy(Record::getExaminationAgency));
|
|
|
|
|
|
Map<String, List<Record>> organizer = records.stream()
|
|
|
- .collect(Collectors.groupingBy(Record::getOrganizer));
|
|
|
+ .collect(Collectors.groupingBy(Record::getUscc));
|
|
|
|
|
|
Map<Long, List<Complain>> complainsByName = complains.stream()
|
|
|
.collect(Collectors.groupingBy(Complain::getUnitName));
|
|
|
@@ -90,9 +124,9 @@ public class ReportService {
|
|
|
});
|
|
|
|
|
|
organizer.forEach((key, value) -> {
|
|
|
- GradingOrganization go = gradingOrganizationMap.get(key);
|
|
|
+ Organization or = organizationMap.get(key);
|
|
|
// 投诉
|
|
|
- List<Complain> complainList = complainsByName.get(go.getId());
|
|
|
+ List<Complain> complainList = complainsByName.get(or.getId());
|
|
|
String complainContent = complainList.stream().map(Complain::getTitle).collect(Collectors.joining(","));
|
|
|
// 备案
|
|
|
List<Record> recordList = examinationAgency.get(key);
|
|
|
@@ -108,5 +142,8 @@ public class ReportService {
|
|
|
.examQuantity(examQuantity)
|
|
|
.build());
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+ return reportDTOS;
|
|
|
}
|
|
|
}
|