|
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zksy.common.exception.ServiceException;
|
|
import com.zksy.common.exception.ServiceException;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
|
|
+import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
import com.zksy.drainage.domain.DrainageWarning;
|
|
import com.zksy.drainage.domain.DrainageWarning;
|
|
|
import com.zksy.drainage.domain.WarningScopeUser;
|
|
import com.zksy.drainage.domain.WarningScopeUser;
|
|
|
import com.zksy.drainage.mapper.DrainageWarningMapper;
|
|
import com.zksy.drainage.mapper.DrainageWarningMapper;
|
|
@@ -17,7 +19,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -34,6 +38,9 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private WarningScopeUserMapper warningScopeUserMapper;
|
|
private WarningScopeUserMapper warningScopeUserMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
|
|
+
|
|
|
private static final List<String> CURRENT_STATUSES = Arrays.asList("DRAFT", "PENDING", "PROCESSING", "RELEASED");
|
|
private static final List<String> CURRENT_STATUSES = Arrays.asList("DRAFT", "PENDING", "PROCESSING", "RELEASED");
|
|
|
private static final List<String> HISTORY_STATUSES = Arrays.asList("HANDLED", "CLOSED");
|
|
private static final List<String> HISTORY_STATUSES = Arrays.asList("HANDLED", "CLOSED");
|
|
|
|
|
|
|
@@ -44,7 +51,9 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = buildQueryWrapper(warningLevel, warningType, status, startTime, endTime);
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = buildQueryWrapper(warningLevel, warningType, status, startTime, endTime);
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
- return this.page(page, wrapper);
|
|
|
|
|
|
|
+ Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
|
|
+ fillMissingCoordinates(result);
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -62,14 +71,16 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
|
}
|
|
}
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
- return this.page(page, wrapper);
|
|
|
|
|
|
|
+ Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
|
|
+ fillMissingCoordinates(result);
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Page<DrainageWarning> findHistoryPage(long pageNum, long pageSize,
|
|
public Page<DrainageWarning> findHistoryPage(long pageNum, long pageSize,
|
|
|
Integer warningLevel, String warningType,
|
|
Integer warningLevel, String warningType,
|
|
|
String status, String startTime, String endTime,
|
|
String status, String startTime, String endTime,
|
|
|
- boolean historyOnly, String equipmentName) {
|
|
|
|
|
|
|
+ boolean historyOnly, String equipmentName, String equipmentType) {
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
|
// 历史查询默认只返回已处置或已解除的记录;传入 status 时允许
|
|
// 历史查询默认只返回已处置或已解除的记录;传入 status 时允许
|
|
@@ -77,6 +88,14 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (historyOnly && (status == null || status.isEmpty())) {
|
|
if (historyOnly && (status == null || status.isEmpty())) {
|
|
|
wrapper.in(DrainageWarning::getStatus, HISTORY_STATUSES);
|
|
wrapper.in(DrainageWarning::getStatus, HISTORY_STATUSES);
|
|
|
}
|
|
}
|
|
|
|
|
+ // device_code 保存设备类型业务编码;历史预警按排水设备类型树筛选。
|
|
|
|
|
+ if ("drainage".equalsIgnoreCase(equipmentType)) {
|
|
|
|
|
+ wrapper.inSql(DrainageWarning::getDeviceCode,
|
|
|
|
|
+ "SELECT et.type_id FROM app_user.equipment_type et "
|
|
|
|
|
+ + "WHERE et.type_id IS NOT NULL AND "
|
|
|
|
|
+ + "(et.type_id = 'drainage' OR et.parent_type_id = '2' OR et.parent_type_id IN "
|
|
|
|
|
+ + "(SELECT id FROM app_user.equipment_type WHERE type_id = 'drainage'))");
|
|
|
|
|
+ }
|
|
|
// 附加筛选条件
|
|
// 附加筛选条件
|
|
|
if (warningLevel != null) {
|
|
if (warningLevel != null) {
|
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
@@ -97,7 +116,9 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
wrapper.le(DrainageWarning::getCreateTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
wrapper.le(DrainageWarning::getCreateTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
}
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
- return this.page(page, wrapper);
|
|
|
|
|
|
|
+ Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
|
|
+ fillMissingCoordinates(result);
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -180,7 +201,8 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
Long userId, Long deptId, boolean isAdmin,
|
|
Long userId, Long deptId, boolean isAdmin,
|
|
|
Integer warningLevel, String warningType,
|
|
Integer warningLevel, String warningType,
|
|
|
String status, boolean currentOnly,
|
|
String status, boolean currentOnly,
|
|
|
- String equipmentName, String startTime, String endTime) {
|
|
|
|
|
|
|
+ String equipmentName, String startTime, String endTime,
|
|
|
|
|
+ String equipmentType) {
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
|
|
@@ -201,6 +223,14 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (warningType != null && !warningType.isEmpty()) {
|
|
if (warningType != null && !warningType.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
|
}
|
|
}
|
|
|
|
|
+ // device_code 保存设备类型的 type_id;当前预警按排水设备类型树筛选。
|
|
|
|
|
+ if ("drainage".equalsIgnoreCase(equipmentType)) {
|
|
|
|
|
+ wrapper.inSql(DrainageWarning::getDeviceCode,
|
|
|
|
|
+ "SELECT et.type_id FROM app_user.equipment_type et "
|
|
|
|
|
+ + "WHERE et.type_id IS NOT NULL AND "
|
|
|
|
|
+ + "(et.type_id = 'drainage' OR et.parent_type_id = '2' OR et.parent_type_id IN "
|
|
|
|
|
+ + "(SELECT id FROM app_user.equipment_type WHERE type_id = 'drainage'))");
|
|
|
|
|
+ }
|
|
|
if (equipmentName != null && !equipmentName.isEmpty()) {
|
|
if (equipmentName != null && !equipmentName.isEmpty()) {
|
|
|
wrapper.like(DrainageWarning::getEquipmentName, equipmentName);
|
|
wrapper.like(DrainageWarning::getEquipmentName, equipmentName);
|
|
|
}
|
|
}
|
|
@@ -212,7 +242,9 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
- return this.page(page, wrapper);
|
|
|
|
|
|
|
+ Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
|
|
+ fillMissingCoordinates(result);
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -294,4 +326,44 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
}
|
|
}
|
|
|
return wrapper;
|
|
return wrapper;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 预警历史数据可能只保存了设备名称,坐标为空时从设备基础表补齐真实坐标,
|
|
|
|
|
+ * 供列表和 GIS 页面统一使用。仅补齐缺失坐标,不覆盖预警表已有坐标。
|
|
|
|
|
+ */
|
|
|
|
|
+ private void fillMissingCoordinates(Page<DrainageWarning> page) {
|
|
|
|
|
+ if (page == null || page.getRecords() == null || page.getRecords().isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> names = page.getRecords().stream()
|
|
|
|
|
+ .filter(item -> item.getLongitude() == null || item.getLatitude() == null)
|
|
|
|
|
+ .map(DrainageWarning::getEquipmentName)
|
|
|
|
|
+ .filter(name -> name != null && !name.trim().isEmpty())
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (names.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<EquipmentBase> equipments = equipmentBaseMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<EquipmentBase>().in(EquipmentBase::getEquipmentName, names));
|
|
|
|
|
+ Map<String, EquipmentBase> equipmentMap = new HashMap<>();
|
|
|
|
|
+ for (EquipmentBase equipment : equipments) {
|
|
|
|
|
+ if (equipment.getLongitude() != null && equipment.getLatitude() != null) {
|
|
|
|
|
+ equipmentMap.putIfAbsent(equipment.getEquipmentName(), equipment);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (DrainageWarning warning : page.getRecords()) {
|
|
|
|
|
+ if (warning.getLongitude() != null && warning.getLatitude() != null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ EquipmentBase equipment = equipmentMap.get(warning.getEquipmentName());
|
|
|
|
|
+ if (equipment != null) {
|
|
|
|
|
+ warning.setLongitude(equipment.getLongitude());
|
|
|
|
|
+ warning.setLatitude(equipment.getLatitude());
|
|
|
|
|
+ if (warning.getLocation() == null || warning.getLocation().trim().isEmpty()) {
|
|
|
|
|
+ warning.setLocation(equipment.getEquipmentLocation());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|