|
|
@@ -0,0 +1,127 @@
|
|
|
+package org.springblade.business.service.impl;
|
|
|
+
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.business.entity.TrialSelfInspectionRecord;
|
|
|
+import org.springblade.business.service.IEntrustInfoService;
|
|
|
+import org.springblade.business.service.ITrialSampleInfoService;
|
|
|
+import org.springblade.business.service.ITrialSelfInspectionRecordService;
|
|
|
+import org.springblade.business.service.TrialDataBoardService;
|
|
|
+import org.springblade.business.vo.TrialDataBoardApproveVo;
|
|
|
+import org.springblade.business.vo.TrialDataBoardCountVO;
|
|
|
+import org.springblade.business.vo.TrialDataBoardChartVo;
|
|
|
+import org.springblade.business.vo.TrialMonthReport;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class TrialDataBoardServiceImpl implements TrialDataBoardService {
|
|
|
+
|
|
|
+ private final ITrialSampleInfoService trialSampleInfoService;
|
|
|
+ private final IEntrustInfoService entrustInfoService;
|
|
|
+ private final ITrialSelfInspectionRecordService trialSelfInspectionRecordService;
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TrialDataBoardCountVO trialDataBoardCount(Long contractId,Long nodeId) {
|
|
|
+ List<Long> nodeIds = selectAllNodeIds(nodeId);
|
|
|
+ Integer sampleInfoCount = trialSampleInfoService.selectSampleInfoCount(contractId,nodeIds);
|
|
|
+ Integer entrustInfoCount = entrustInfoService.selectEntrustInfoCount(contractId,nodeIds);
|
|
|
+ List<TrialSelfInspectionRecord> list=trialSelfInspectionRecordService.seleclListByContractIdAndNodeId(contractId,nodeIds);
|
|
|
+ TrialDataBoardCountVO vo = new TrialDataBoardCountVO();
|
|
|
+ vo.setSampleCount(sampleInfoCount);
|
|
|
+ vo.setEntrustCount(entrustInfoCount);
|
|
|
+ vo.setReportCount(list.size());
|
|
|
+ int qualifiedCountCount = (int) list.stream().filter(trialSelfInspectionRecord -> trialSelfInspectionRecord.getDetectionResult() == 1).count();
|
|
|
+ int unQualifiedCountCount = (int) list.stream().filter(trialSelfInspectionRecord -> trialSelfInspectionRecord.getDetectionResult() == 0).count();
|
|
|
+ vo.setReportQualifiedCount(qualifiedCountCount);
|
|
|
+ vo.setReportUnqualifiedCount(unQualifiedCountCount);
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ int rate = (qualifiedCountCount * 100) / list.size();
|
|
|
+ vo.setReportRate(rate + "%");
|
|
|
+ } else {
|
|
|
+ vo.setReportRate("0%");
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TrialDataBoardChartVo trialDataBoardChart(Long contractId, Long nodeId, String year) {
|
|
|
+ // 1. 参数校验
|
|
|
+ if (contractId == null || nodeId == null || year == null || year.length() != 4) {
|
|
|
+ throw new IllegalArgumentException("参数异常:contractId、nodeId、year不能为空,且year为4位年份");
|
|
|
+ }
|
|
|
+ List<Long> nodeIds = selectAllNodeIds(nodeId);
|
|
|
+
|
|
|
+ // 2. 查询原始统计数据
|
|
|
+ List<Map<String, Object>> rawData = trialSelfInspectionRecordService.countByTypeAndMonth(contractId, nodeIds, year);
|
|
|
+ // 3. 初始化返回VO
|
|
|
+ TrialDataBoardChartVo vo = new TrialDataBoardChartVo();
|
|
|
+ // 4. 拆分数据到三个类型的列表,并补全12个月数据
|
|
|
+ vo.setSgMonthReport(buildMonthReport(rawData, 1)); // 施工:type=1
|
|
|
+ vo.setJlMonthReport(buildMonthReport(rawData, 2)); // 监理:type=2
|
|
|
+ vo.setYzMonthReport(buildMonthReport(rawData, 3)); // 业主:type=3
|
|
|
+ //5 统计所有合格/不合格数量数量
|
|
|
+ List<TrialSelfInspectionRecord>list=trialSelfInspectionRecordService.selectCountByYear(contractId, nodeIds, year);
|
|
|
+ if(!list.isEmpty()){
|
|
|
+ vo.setAllQualifiedCount((int)list.stream().filter(trialSelfInspectionRecord -> trialSelfInspectionRecord.getDetectionResult() == 1).count());
|
|
|
+ vo.setAllUnQualifiedCount((int)list.stream().filter(trialSelfInspectionRecord -> trialSelfInspectionRecord.getDetectionResult() == 0).count());
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> selectAllYear(Long contractId) {
|
|
|
+ return trialSelfInspectionRecordService.selectAllYear(contractId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TrialDataBoardApproveVo trialDataBoardApprove(Long contractId, Long nodeId, Integer type) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TrialMonthReport> buildMonthReport(List<Map<String, Object>> rawData, Integer type) {
|
|
|
+ // 过滤当前类型数据,转为{月份:数量}的Map(月份为1-12的字符串)
|
|
|
+ Map<String, Integer> typeMonthCountMap = rawData.stream()
|
|
|
+ .filter(item -> type.equals(item.get("type")))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.get("month").toString(),
|
|
|
+ item -> Integer.parseInt(item.get("count").toString()),
|
|
|
+ (v1, v2) -> v1
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 生成12个月数据,month返回1/2/.../12
|
|
|
+ List<TrialMonthReport> monthReports = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
+ String month = String.valueOf(i);
|
|
|
+ TrialMonthReport report = new TrialMonthReport();
|
|
|
+ report.setMonth(month);
|
|
|
+ report.setCount(typeMonthCountMap.getOrDefault(month, 0));
|
|
|
+ monthReports.add(report);
|
|
|
+ }
|
|
|
+ return monthReports;
|
|
|
+ }
|
|
|
+ public List<Long> selectAllNodeIds(Long nodeId) {
|
|
|
+ String sql = "SELECT p_key_id " +
|
|
|
+ "FROM m_wbs_tree_private " +
|
|
|
+ "WHERE is_deleted = 0 " +
|
|
|
+ " AND ( " +
|
|
|
+ " p_key_id = ? " +
|
|
|
+ " OR ( " +
|
|
|
+ " ancestors_p_id IS NOT NULL " +
|
|
|
+ " AND CONCAT(',', ancestors_p_id, ',') LIKE CONCAT('%,', ?, ',%') " +
|
|
|
+ " ) " +
|
|
|
+ " )";
|
|
|
+ return jdbcTemplate.query(
|
|
|
+ sql,
|
|
|
+ new Object[]{nodeId, nodeId},
|
|
|
+ (rs, rowNum) -> rs.getLong("p_key_id")
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|