|
|
@@ -45,13 +45,22 @@ public class HazardHiddenAccountServiceImpl extends ServiceImpl<HazardHiddenAcco
|
|
|
wrapper.eq(dto.getHazardLevel() != null && !dto.getHazardLevel().isEmpty(), HazardHiddenAccount::getHazardLevel, dto.getHazardLevel());
|
|
|
wrapper.eq(dto.getHazardStatus() != null && !dto.getHazardStatus().isEmpty(), HazardHiddenAccount::getHazardStatus, dto.getHazardStatus());
|
|
|
wrapper.eq(StringUtils.hasText(dto.getHazardSource()), HazardHiddenAccount::getHazardSource, dto.getHazardSource());
|
|
|
+ wrapper.eq(StringUtils.hasText(dto.getDistrict()), HazardHiddenAccount::getDistrict, dto.getDistrict());
|
|
|
wrapper.eq(dto.getIsSubmitted() != null, HazardHiddenAccount::getIsSubmitted, dto.getIsSubmitted());
|
|
|
+ if ("1".equals(dto.getFeedbackStatus())) {
|
|
|
+ // 已反馈:治理反馈内容已填写
|
|
|
+ wrapper.isNotNull(HazardHiddenAccount::getRectifyFeedback);
|
|
|
+ wrapper.ne(HazardHiddenAccount::getRectifyFeedback, "");
|
|
|
+ } else if ("0".equals(dto.getFeedbackStatus())) {
|
|
|
+ // 未反馈:治理反馈内容为空
|
|
|
+ wrapper.and(item -> item.isNull(HazardHiddenAccount::getRectifyFeedback)
|
|
|
+ .or().eq(HazardHiddenAccount::getRectifyFeedback, ""));
|
|
|
+ }
|
|
|
wrapper.eq(dto.getNetworkId() != null && !dto.getNetworkId().isEmpty(), HazardHiddenAccount::getNetworkId, dto.getNetworkId());
|
|
|
wrapper.eq(dto.getEquipmentId() != null && !dto.getEquipmentId().isEmpty(), HazardHiddenAccount::getEquipmentId, dto.getEquipmentId());
|
|
|
if (StringUtils.hasText(dto.getKeyword())) {
|
|
|
wrapper.and(item -> item.like(HazardHiddenAccount::getHazardNo, dto.getKeyword())
|
|
|
- .or().like(HazardHiddenAccount::getHazardDesc, dto.getKeyword())
|
|
|
- .or().like(HazardHiddenAccount::getReportUnit, dto.getKeyword()));
|
|
|
+ .or().like(HazardHiddenAccount::getHazardDesc, dto.getKeyword()));
|
|
|
}
|
|
|
boolean querySubmitTime = "submit".equalsIgnoreCase(dto.getTimeType());
|
|
|
if (StringUtils.hasText(dto.getStartDate())) {
|
|
|
@@ -123,41 +132,66 @@ public class HazardHiddenAccountServiceImpl extends ServiceImpl<HazardHiddenAcco
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean feedback(String hazardId, String rectifyFeedback) {
|
|
|
+ HazardHiddenAccount hazard = this.getById(hazardId);
|
|
|
+ if (hazard == null) {
|
|
|
+ throw new ServiceException("隐患信息不存在:" + hazardId);
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(hazard.getRectifyFeedback())) {
|
|
|
+ throw new ServiceException("该隐患已反馈,不允许二次修改");
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(rectifyFeedback)) {
|
|
|
+ throw new ServiceException("治理反馈内容不能为空");
|
|
|
+ }
|
|
|
+ HazardHiddenAccount update = new HazardHiddenAccount();
|
|
|
+ update.setHazardId(hazardId);
|
|
|
+ update.setRectifyFeedback(rectifyFeedback);
|
|
|
+ // 反馈后状态置为已反馈,与前端未报送/已报送/已反馈状态口径一致
|
|
|
+ update.setHazardStatus("已反馈");
|
|
|
+ update.setUpdateTime(LocalDateTime.now());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Long submitHazard(String hazardId) {
|
|
|
HazardHiddenAccount hazard = this.getById(hazardId);
|
|
|
if (hazard == null) {
|
|
|
- return null;
|
|
|
+ throw new ServiceException("隐患信息不存在:" + hazardId);
|
|
|
+ }
|
|
|
+ if (Integer.valueOf(1).equals(hazard.getIsSubmitted())) {
|
|
|
+ throw new ServiceException("该隐患已报送,请勿重复报送");
|
|
|
+ }
|
|
|
+ // 报送即流转工单系统:未关联设备的隐患无法生成工单,直接拦截而不是静默报送
|
|
|
+ if (hazard.getEquipmentId() == null || hazard.getEquipmentId().isEmpty()) {
|
|
|
+ throw new ServiceException("该隐患未关联设备,无法自动生成工单,请先补充关联设备");
|
|
|
}
|
|
|
hazard.setIsSubmitted(1);
|
|
|
hazard.setSubmitTime(LocalDateTime.now());
|
|
|
this.updateById(hazard);
|
|
|
|
|
|
- // 当隐患关联了设备时,自动创建工单
|
|
|
- if (hazard.getEquipmentId() != null && !hazard.getEquipmentId().isEmpty()) {
|
|
|
- try {
|
|
|
- Date planFinishTime = null;
|
|
|
- if (hazard.getRectifyDeadline() != null) {
|
|
|
- planFinishTime = java.sql.Date.valueOf(hazard.getRectifyDeadline());
|
|
|
- }
|
|
|
- Long orderId = businessWorkOrderService.createWorkOrderFromHazard(
|
|
|
- hazard.getHazardId(),
|
|
|
- hazard.getHazardNo(),
|
|
|
- hazard.getHazardDesc(),
|
|
|
- hazard.getEquipmentId(),
|
|
|
- hazard.getHazardLevel(),
|
|
|
- hazard.getHazardImages(),
|
|
|
- planFinishTime
|
|
|
- );
|
|
|
- log.info("隐患报送[{}]自动创建工单成功,工单ID={}", hazardId, orderId);
|
|
|
- return orderId;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("隐患报送[{}]自动创建工单失败", hazardId, e);
|
|
|
- throw new ServiceException("报送成功但工单创建失败:" + e.getMessage());
|
|
|
+ try {
|
|
|
+ Date planFinishTime = null;
|
|
|
+ if (hazard.getRectifyDeadline() != null) {
|
|
|
+ planFinishTime = java.sql.Date.valueOf(hazard.getRectifyDeadline());
|
|
|
}
|
|
|
+ Long orderId = businessWorkOrderService.createWorkOrderFromHazard(
|
|
|
+ hazard.getHazardId(),
|
|
|
+ hazard.getHazardNo(),
|
|
|
+ hazard.getHazardDesc(),
|
|
|
+ hazard.getEquipmentId(),
|
|
|
+ hazard.getHazardLevel(),
|
|
|
+ hazard.getHazardImages(),
|
|
|
+ planFinishTime
|
|
|
+ );
|
|
|
+ log.info("隐患报送[{}]自动创建工单成功,工单ID={}", hazardId, orderId);
|
|
|
+ return orderId;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("隐患报送[{}]自动创建工单失败", hazardId, e);
|
|
|
+ throw new ServiceException("报送失败,工单创建异常:" + e.getMessage());
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -171,7 +205,8 @@ public class HazardHiddenAccountServiceImpl extends ServiceImpl<HazardHiddenAcco
|
|
|
HazardHiddenAccount::getHazardStatus, HazardHiddenAccount::getHazardDesc,
|
|
|
HazardHiddenAccount::getLongitude, HazardHiddenAccount::getLatitude,
|
|
|
HazardHiddenAccount::getRectifyFeedback, HazardHiddenAccount::getReportTime,
|
|
|
- HazardHiddenAccount::getReportUnit, HazardHiddenAccount::getRectifyPlan,
|
|
|
+ HazardHiddenAccount::getRectifyPlan,
|
|
|
+ HazardHiddenAccount::getIsSubmitted,
|
|
|
HazardHiddenAccount::getRemark);
|
|
|
return this.list(wrapper);
|
|
|
}
|
|
|
@@ -247,29 +282,6 @@ public class HazardHiddenAccountServiceImpl extends ServiceImpl<HazardHiddenAcco
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> statisticsByRegion(String startDate, String endDate) {
|
|
|
- // 无日期参数时默认最近7天
|
|
|
- if (!StringUtils.hasText(startDate)) {
|
|
|
- startDate = LocalDate.now().minusDays(6).toString();
|
|
|
- }
|
|
|
- if (!StringUtils.hasText(endDate)) {
|
|
|
- endDate = LocalDate.now().toString();
|
|
|
- }
|
|
|
- List<HazardHiddenAccount> list = this.list(buildDateWrapper(startDate, endDate));
|
|
|
- Map<String, Long> grouped = list.stream()
|
|
|
- .collect(Collectors.groupingBy(h -> h.getReportUnit() != null && !h.getReportUnit().isEmpty()
|
|
|
- ? h.getReportUnit() : "未知区域", Collectors.counting()));
|
|
|
- List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- for (Map.Entry<String, Long> entry : grouped.entrySet()) {
|
|
|
- Map<String, Object> item = new HashMap<>();
|
|
|
- item.put("name", entry.getKey());
|
|
|
- item.put("value", entry.getValue());
|
|
|
- result.add(item);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Map<String, Object> statisticsTypeTimeline(String startDate, String endDate) {
|
|
|
// 无日期参数时默认最近7天
|
|
|
@@ -383,4 +395,61 @@ public class HazardHiddenAccountServiceImpl extends ServiceImpl<HazardHiddenAcco
|
|
|
}
|
|
|
return wrapper;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 隐患整改统计(饼图):关联工单已结案(order_status=5)为已整改,其余(无工单或工单未结案)为未整改
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> statisticsRectifyPie(String startDate, String endDate) {
|
|
|
+ List<HazardHiddenAccount> list = this.list(buildDateWrapper(startDate, endDate));
|
|
|
+
|
|
|
+ // 收集关联的工单ID,批量查工单状态
|
|
|
+ List<Long> orderIds = list.stream()
|
|
|
+ .map(HazardHiddenAccount::getWorkOrderId)
|
|
|
+ .filter(java.util.Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, Integer> orderStatusMap = new HashMap<>();
|
|
|
+ if (!orderIds.isEmpty()) {
|
|
|
+ businessWorkOrderService.listByIds(orderIds).forEach(o -> orderStatusMap.put(o.getOrderId(), o.getOrderStatus()));
|
|
|
+ }
|
|
|
+
|
|
|
+ long rectified = list.stream()
|
|
|
+ .filter(h -> h.getWorkOrderId() != null
|
|
|
+ && Integer.valueOf(5).equals(orderStatusMap.get(h.getWorkOrderId())))
|
|
|
+ .count();
|
|
|
+ long unrectified = list.size() - rectified;
|
|
|
+
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ Map<String, Object> un = new HashMap<>();
|
|
|
+ un.put("name", "未整改");
|
|
|
+ un.put("value", unrectified);
|
|
|
+ result.add(un);
|
|
|
+ Map<String, Object> done = new HashMap<>();
|
|
|
+ done.put("name", "已整改");
|
|
|
+ done.put("value", rectified);
|
|
|
+ result.add(done);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 各区域隐患统计(饼图):按片区分组,片区编码经字典 drainage_district 转中文标签
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> statisticsDistrictPie(String startDate, String endDate) {
|
|
|
+ List<HazardHiddenAccount> list = this.list(buildDateWrapper(startDate, endDate));
|
|
|
+ Map<String, Long> grouped = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ h -> StringUtils.hasText(h.getDistrict()) ? h.getDistrict() : "未知",
|
|
|
+ Collectors.counting()));
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, Long> entry : grouped.entrySet()) {
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ String label = dictDataService.selectDictLabel("drainage_district", entry.getKey());
|
|
|
+ item.put("name", StringUtils.hasText(label) ? label : entry.getKey());
|
|
|
+ item.put("value", entry.getValue());
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|