|
|
@@ -1,16 +1,22 @@
|
|
|
package com.izouma.wenlvju.service.regulation;
|
|
|
|
|
|
+import com.izouma.wenlvju.domain.GradingOrganization;
|
|
|
import com.izouma.wenlvju.domain.Record;
|
|
|
+import com.izouma.wenlvju.domain.regulation.Complain;
|
|
|
import com.izouma.wenlvju.domain.regulation.Report;
|
|
|
import com.izouma.wenlvju.dto.PageQuery;
|
|
|
+import com.izouma.wenlvju.dto.ReportDTO;
|
|
|
+import com.izouma.wenlvju.enums.UnitType;
|
|
|
+import com.izouma.wenlvju.repo.GradingOrganizationRepo;
|
|
|
import com.izouma.wenlvju.repo.RecordRepo;
|
|
|
+import com.izouma.wenlvju.repo.regulation.ComplainRepo;
|
|
|
import com.izouma.wenlvju.repo.regulation.ReportRepo;
|
|
|
import com.izouma.wenlvju.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -20,8 +26,10 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
public class ReportService {
|
|
|
|
|
|
- private ReportRepo reportRepo;
|
|
|
- private RecordRepo recordRepo;
|
|
|
+ private ReportRepo reportRepo;
|
|
|
+ private RecordRepo recordRepo;
|
|
|
+ private ComplainRepo complainRepo;
|
|
|
+ private GradingOrganizationRepo gradingOrganizationRepo;
|
|
|
|
|
|
public Page<Report> all(PageQuery pageQuery) {
|
|
|
return reportRepo.findAll(JpaUtils.toSpecification(pageQuery, Report.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -32,20 +40,51 @@ public class ReportService {
|
|
|
*/
|
|
|
public void generate(Report report) {
|
|
|
List<Record> records = new ArrayList<>();
|
|
|
+ List<Complain> complains = new ArrayList<>();
|
|
|
switch (report.getType()) {
|
|
|
case ANNUAL:
|
|
|
int year = Integer.parseInt(report.getYear());
|
|
|
- LocalDate start = LocalDate.of(year, 1, 1);
|
|
|
- LocalDate end = LocalDate.of(year, 12, 31);
|
|
|
- recordRepo.findAllByExaminationStartTimeBetween(start, end);
|
|
|
-
|
|
|
+ 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:
|
|
|
break;
|
|
|
case MONTHLY:
|
|
|
break;
|
|
|
}
|
|
|
+ Map<String, GradingOrganization> gradingOrganizationMap = gradingOrganizationRepo.findAll()
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(GradingOrganization::getName, go -> go));
|
|
|
+ Map<String, List<Record>> examinationAgency = records.stream()
|
|
|
+ .collect(Collectors.groupingBy(Record::getExaminationAgency));
|
|
|
+
|
|
|
+ Map<String, List<Record>> organizer = records.stream()
|
|
|
+ .collect(Collectors.groupingBy(Record::getOrganizer));
|
|
|
+
|
|
|
+ Map<Long, List<Complain>> complainsByName = complains.stream()
|
|
|
+ .collect(Collectors.groupingBy(Complain::getUnitName));
|
|
|
+
|
|
|
+ List<ReportDTO> reportDTOS = new ArrayList<>();
|
|
|
+ examinationAgency.forEach((key, value) -> {
|
|
|
+ GradingOrganization go = gradingOrganizationMap.get(key);
|
|
|
+ // 投诉
|
|
|
+ List<Complain> complainList = complainsByName.get(go.getId());
|
|
|
+ String complainContent = complainList.stream().map(Complain::getTitle).collect(Collectors.joining(","));
|
|
|
+ // 备案
|
|
|
+ List<Record> recordList = examinationAgency.get(key);
|
|
|
+ int examCenterQuantity = recordList.stream().mapToInt(Record::getExamCenterQuantity).sum();
|
|
|
+ int examQuantity = recordList.stream().mapToInt(Record::getExamQuantity).sum();
|
|
|
|
|
|
-// records.forEach();
|
|
|
+ reportDTOS.add(ReportDTO.builder()
|
|
|
+ .unitType(UnitType.GRADING_ORGANIZATION)
|
|
|
+ .name(key)
|
|
|
+ .complain(complainList.size())
|
|
|
+ .complainContent(complainContent)
|
|
|
+ .examCenterQuantity(examCenterQuantity)
|
|
|
+ .examQuantity(examQuantity)
|
|
|
+ .build());
|
|
|
+ });
|
|
|
}
|
|
|
}
|