|
@@ -17,14 +17,18 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
+import java.io.Serializable;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.Collection;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 排水预警信息 ServiceImpl
|
|
* 排水预警信息 ServiceImpl
|
|
@@ -48,6 +52,26 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
/** warning_type 非空兜底值:设备侧发起、无预警类型时的默认值 */
|
|
/** warning_type 非空兜底值:设备侧发起、无预警类型时的默认值 */
|
|
|
private static final String DEFAULT_WARNING_TYPE = "DRAINAGE_DEVICE";
|
|
private static final String DEFAULT_WARNING_TYPE = "DRAINAGE_DEVICE";
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设备名称不再落 early_warning.device_name(共享库已移除该列),
|
|
|
|
|
+ * 因此设备名称筛选必须先查 equipment_base,再按设备编码/ID回查预警。
|
|
|
|
|
+ * 排水设备类型筛选同样改为按设备档案的类型判断,并兼容历史库把类型ID写进 device_code 的数据。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String DRAINAGE_DEVICE_KEYS_SQL =
|
|
|
|
|
+ "SELECT CAST(et.id AS varchar) FROM app_user.equipment_type et "
|
|
|
|
|
+ + "WHERE et.id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId()
|
|
|
|
|
+ + " OR et.parent_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId()
|
|
|
|
|
+ + " UNION ALL "
|
|
|
|
|
+ + "SELECT e.equipment_id FROM app_user.equipment_base e "
|
|
|
|
|
+ + "WHERE e.equipment_type_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId()
|
|
|
|
|
+ + " OR e.equipment_type_id IN (SELECT et.id FROM app_user.equipment_type et "
|
|
|
|
|
+ + "WHERE et.parent_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId() + ") "
|
|
|
|
|
+ + " UNION ALL "
|
|
|
|
|
+ + "SELECT e.equipment_code FROM app_user.equipment_base e "
|
|
|
|
|
+ + "WHERE e.equipment_type_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId()
|
|
|
|
|
+ + " OR e.equipment_type_id IN (SELECT et.id FROM app_user.equipment_type et "
|
|
|
|
|
+ + "WHERE et.parent_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId() + ")";
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Page<DrainageWarning> findCurrentPage(long pageNum, long pageSize,
|
|
public Page<DrainageWarning> findCurrentPage(long pageNum, long pageSize,
|
|
|
String warningLevel, String warningType) {
|
|
String warningLevel, String warningType) {
|
|
@@ -64,7 +88,7 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
}
|
|
}
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
Page<DrainageWarning> result = this.page(page, wrapper);
|
|
Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
- fillMissingCoordinates(result);
|
|
|
|
|
|
|
+ fillDeviceInfo(result.getRecords());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -80,14 +104,8 @@ 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)) {
|
|
|
|
|
- // device_code 保存设备类型主键(字符串形式),按排水类型树筛选:根节点或其直接子类型
|
|
|
|
|
- wrapper.inSql(DrainageWarning::getDeviceCode,
|
|
|
|
|
- "SELECT CAST(et.id AS varchar) FROM app_user.equipment_type et "
|
|
|
|
|
- + "WHERE et.id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId()
|
|
|
|
|
- + " OR et.parent_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // device_code 现在保存设备编码,历史数据可能保存类型ID:两种形态都纳入排水设备筛选。
|
|
|
|
|
+ applyDrainageDeviceFilter(wrapper, equipmentType);
|
|
|
// 附加筛选条件
|
|
// 附加筛选条件
|
|
|
if (warningLevel != null) {
|
|
if (warningLevel != null) {
|
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
@@ -98,9 +116,7 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (status != null && !status.isEmpty()) {
|
|
if (status != null && !status.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getStatus, status);
|
|
wrapper.eq(DrainageWarning::getStatus, status);
|
|
|
}
|
|
}
|
|
|
- if (equipmentName != null && !equipmentName.isEmpty()) {
|
|
|
|
|
- wrapper.like(DrainageWarning::getEquipmentName, equipmentName);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ applyEquipmentNameFilter(wrapper, equipmentName);
|
|
|
if (startTime != null && !startTime.isEmpty()) {
|
|
if (startTime != null && !startTime.isEmpty()) {
|
|
|
wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
}
|
|
@@ -109,13 +125,15 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
}
|
|
}
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
Page<DrainageWarning> result = this.page(page, wrapper);
|
|
Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
- fillMissingCoordinates(result);
|
|
|
|
|
|
|
+ fillDeviceInfo(result.getRecords());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public boolean saveWithCheck(DrainageWarning entity) {
|
|
public boolean saveWithCheck(DrainageWarning entity) {
|
|
|
|
|
+ // 设备名称不再落库:用前端传来的设备ID/编码关联设备档案,统一 device_code 口径并回填展示字段
|
|
|
|
|
+ bindDevice(entity);
|
|
|
// 自动生成预警单号:WRN + 时间戳
|
|
// 自动生成预警单号:WRN + 时间戳
|
|
|
if (entity.getWarningNo() == null || entity.getWarningNo().isEmpty()) {
|
|
if (entity.getWarningNo() == null || entity.getWarningNo().isEmpty()) {
|
|
|
entity.setWarningNo("WRN" + LocalDateTime.now().format(WARNING_NO_FORMATTER));
|
|
entity.setWarningNo("WRN" + LocalDateTime.now().format(WARNING_NO_FORMATTER));
|
|
@@ -136,6 +154,7 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (this.getById(id) == null) {
|
|
if (this.getById(id) == null) {
|
|
|
throw new ServiceException("预警信息不存在,无法修改:" + id);
|
|
throw new ServiceException("预警信息不存在,无法修改:" + id);
|
|
|
}
|
|
}
|
|
|
|
|
+ bindDevice(entity);
|
|
|
return this.updateById(entity);
|
|
return this.updateById(entity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -180,6 +199,8 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
warning.setWarningType(fallbackType == null || fallbackType.trim().isEmpty()
|
|
warning.setWarningType(fallbackType == null || fallbackType.trim().isEmpty()
|
|
|
? DEFAULT_WARNING_TYPE : fallbackType);
|
|
? DEFAULT_WARNING_TYPE : fallbackType);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 共享库已删除 early_warning.device_name:设备名称只从设备档案关联,绝不参与 INSERT。
|
|
|
|
|
+ bindDevice(warning);
|
|
|
warning.setPublishTime(LocalDateTime.now());
|
|
warning.setPublishTime(LocalDateTime.now());
|
|
|
// 默认状态为PENDING(待办)
|
|
// 默认状态为PENDING(待办)
|
|
|
warning.setStatus("PENDING");
|
|
warning.setStatus("PENDING");
|
|
@@ -264,17 +285,9 @@ 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)) {
|
|
|
|
|
- // device_code 保存设备类型主键(字符串形式),按排水类型树筛选:根节点或其直接子类型
|
|
|
|
|
- wrapper.inSql(DrainageWarning::getDeviceCode,
|
|
|
|
|
- "SELECT CAST(et.id AS varchar) FROM app_user.equipment_type et "
|
|
|
|
|
- + "WHERE et.id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId()
|
|
|
|
|
- + " OR et.parent_id = " + EquipmentTypeEnum.ROOT_DRAINAGE_DEVICE.getId());
|
|
|
|
|
- }
|
|
|
|
|
- if (equipmentName != null && !equipmentName.isEmpty()) {
|
|
|
|
|
- wrapper.like(DrainageWarning::getEquipmentName, equipmentName);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // device_code 现在保存设备编码,历史数据可能保存类型ID:两种形态都纳入排水设备筛选。
|
|
|
|
|
+ applyDrainageDeviceFilter(wrapper, equipmentType);
|
|
|
|
|
+ applyEquipmentNameFilter(wrapper, equipmentName);
|
|
|
if (startTime != null && !startTime.isEmpty()) {
|
|
if (startTime != null && !startTime.isEmpty()) {
|
|
|
wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
}
|
|
@@ -284,49 +297,188 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
|
|
|
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
Page<DrainageWarning> result = this.page(page, wrapper);
|
|
Page<DrainageWarning> result = this.page(page, wrapper);
|
|
|
- fillMissingCoordinates(result);
|
|
|
|
|
|
|
+ fillDeviceInfo(result.getRecords());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 详情同样要展示设备名称:device_name 列已不存在,查询后从设备档案补齐。 */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public DrainageWarning getById(Serializable id) {
|
|
|
|
|
+ DrainageWarning warning = super.getById(id);
|
|
|
|
|
+ if (warning != null) {
|
|
|
|
|
+ fillDeviceInfo(Collections.singletonList(warning));
|
|
|
|
|
+ }
|
|
|
|
|
+ return warning;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /** 按排水设备模块筛选:新数据 device_code=设备编码,老数据 device_code=设备类型ID。 */
|
|
|
|
|
+ private void applyDrainageDeviceFilter(LambdaQueryWrapper<DrainageWarning> wrapper, String equipmentType) {
|
|
|
|
|
+ if ("drainage".equalsIgnoreCase(equipmentType)) {
|
|
|
|
|
+ wrapper.inSql(DrainageWarning::getDeviceCode, DRAINAGE_DEVICE_KEYS_SQL);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设备名称筛选:equipment_name 不是数据库列(@TableField(exist=false)),
|
|
|
|
|
+ * 不能再生成 device_name LIKE ?。先查设备档案拿到匹配设备的ID/编码/类型ID,
|
|
|
|
|
+ * 再按这些键过滤预警;同时兼容极少数历史库把名称直接写进 device_code 的数据。
|
|
|
|
|
+ */
|
|
|
|
|
+ private void applyEquipmentNameFilter(LambdaQueryWrapper<DrainageWarning> wrapper, String equipmentName) {
|
|
|
|
|
+ if (!StringUtils.hasText(equipmentName)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String keyword = equipmentName.trim();
|
|
|
|
|
+ List<EquipmentBase> devices = equipmentBaseMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<EquipmentBase>().like(EquipmentBase::getEquipmentName, keyword));
|
|
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
|
|
+ for (EquipmentBase device : devices) {
|
|
|
|
|
+ addIfAbsent(keys, device.getEquipmentId());
|
|
|
|
|
+ addIfAbsent(keys, device.getEquipmentCode());
|
|
|
|
|
+ if (device.getEquipmentTypeId() != null) {
|
|
|
|
|
+ addIfAbsent(keys, String.valueOf(device.getEquipmentTypeId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ addIfAbsent(keys, keyword);
|
|
|
|
|
+ wrapper.in(DrainageWarning::getDeviceCode, keys);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addIfAbsent(List<String> values, String value) {
|
|
|
|
|
+ if (StringUtils.hasText(value) && !values.contains(value)) {
|
|
|
|
|
+ values.add(value.trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发布/修改时把前端传来的设备ID换成持久化的设备编码,并回填展示用设备名称。
|
|
|
|
|
+ * 设备名称、坐标、位置、权属单位均不写 early_warning(共享库已移除 device_name 列),
|
|
|
|
|
+ * 仅 device_code 落库作为关联键。
|
|
|
|
|
+ */
|
|
|
|
|
+ private void bindDevice(DrainageWarning warning) {
|
|
|
|
|
+ if (warning == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String deviceId = trimToNull(warning.getEquipmentId());
|
|
|
|
|
+ String deviceCode = trimToNull(warning.getDeviceCode());
|
|
|
|
|
+ EquipmentBase device = null;
|
|
|
|
|
+ if (deviceId != null) {
|
|
|
|
|
+ device = equipmentBaseMapper.selectById(deviceId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (device == null && deviceCode != null) {
|
|
|
|
|
+ device = equipmentBaseMapper.selectOne(new LambdaQueryWrapper<EquipmentBase>()
|
|
|
|
|
+ .eq(EquipmentBase::getEquipmentCode, deviceCode).last("LIMIT 1"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (device == null && deviceCode != null) {
|
|
|
|
|
+ Integer typeId = parseInteger(deviceCode);
|
|
|
|
|
+ if (typeId != null) {
|
|
|
|
|
+ device = equipmentBaseMapper.selectOne(new LambdaQueryWrapper<EquipmentBase>()
|
|
|
|
|
+ .eq(EquipmentBase::getEquipmentTypeId, typeId).last("LIMIT 1"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (device != null) {
|
|
|
|
|
+ String code = trimToNull(device.getEquipmentCode());
|
|
|
|
|
+ if (code != null) {
|
|
|
|
|
+ warning.setDeviceCode(code);
|
|
|
|
|
+ }
|
|
|
|
|
+ warning.setEquipmentName(device.getEquipmentName());
|
|
|
|
|
+ if (!StringUtils.hasText(warning.getLocation())) {
|
|
|
|
|
+ warning.setLocation(device.getEquipmentLocation());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtils.hasText(warning.getOwnershipUnit())) {
|
|
|
|
|
+ warning.setOwnershipUnit(device.getOwnershipUnit());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (warning.getLongitude() == null) {
|
|
|
|
|
+ warning.setLongitude(device.getLongitude());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (warning.getLatitude() == null) {
|
|
|
|
|
+ warning.setLatitude(device.getLatitude());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (deviceId != null) {
|
|
|
|
|
+ // 前端给了设备ID但档案查不到:保留该ID作为关联键,避免关联信息整个丢失
|
|
|
|
|
+ warning.setDeviceCode(deviceId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 预警历史数据可能只保存了设备名称,坐标为空时从设备基础表补齐真实坐标,
|
|
|
|
|
- * 供列表和 GIS 页面统一使用。仅补齐缺失坐标,不覆盖预警表已有坐标。
|
|
|
|
|
|
|
+ * 从设备档案批量回填设备名称、坐标、位置。
|
|
|
|
|
+ * early_warning 只存 device_code;设备名称等展示字段一律实时关联,不落库。
|
|
|
*/
|
|
*/
|
|
|
- private void fillMissingCoordinates(Page<DrainageWarning> page) {
|
|
|
|
|
- if (page == null || page.getRecords() == null || page.getRecords().isEmpty()) {
|
|
|
|
|
|
|
+ private void fillDeviceInfo(Collection<DrainageWarning> records) {
|
|
|
|
|
+ if (records == null || records.isEmpty()) {
|
|
|
return;
|
|
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()) {
|
|
|
|
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
|
|
+ for (DrainageWarning warning : records) {
|
|
|
|
|
+ addIfAbsent(keys, warning.getDeviceCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (keys.isEmpty()) {
|
|
|
return;
|
|
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);
|
|
|
|
|
|
|
+ List<Integer> typeIds = new ArrayList<>();
|
|
|
|
|
+ for (String key : keys) {
|
|
|
|
|
+ Integer typeId = parseInteger(key);
|
|
|
|
|
+ if (typeId != null && !typeIds.contains(typeId)) {
|
|
|
|
|
+ typeIds.add(typeId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- for (DrainageWarning warning : page.getRecords()) {
|
|
|
|
|
- if (warning.getLongitude() != null && warning.getLatitude() != null) {
|
|
|
|
|
|
|
+ LambdaQueryWrapper<EquipmentBase> query = new LambdaQueryWrapper<EquipmentBase>()
|
|
|
|
|
+ .in(EquipmentBase::getEquipmentId, keys)
|
|
|
|
|
+ .or().in(EquipmentBase::getEquipmentCode, keys);
|
|
|
|
|
+ if (!typeIds.isEmpty()) {
|
|
|
|
|
+ query.or().in(EquipmentBase::getEquipmentTypeId, typeIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<EquipmentBase> devices = equipmentBaseMapper.selectList(query);
|
|
|
|
|
+ Map<String, EquipmentBase> byId = new HashMap<>();
|
|
|
|
|
+ Map<String, EquipmentBase> byCode = new HashMap<>();
|
|
|
|
|
+ Map<String, EquipmentBase> byType = new HashMap<>();
|
|
|
|
|
+ for (EquipmentBase device : devices) {
|
|
|
|
|
+ if (StringUtils.hasText(device.getEquipmentId())) {
|
|
|
|
|
+ byId.putIfAbsent(device.getEquipmentId().trim(), device);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(device.getEquipmentCode())) {
|
|
|
|
|
+ byCode.putIfAbsent(device.getEquipmentCode().trim(), device);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (device.getEquipmentTypeId() != null) {
|
|
|
|
|
+ byType.putIfAbsent(String.valueOf(device.getEquipmentTypeId()), device);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (DrainageWarning warning : records) {
|
|
|
|
|
+ String key = trimToNull(warning.getDeviceCode());
|
|
|
|
|
+ if (key == null) {
|
|
|
continue;
|
|
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());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ EquipmentBase device = byId.get(key);
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ device = byCode.get(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ device = byType.get(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ warning.setEquipmentName(device.getEquipmentName());
|
|
|
|
|
+ if (warning.getLongitude() == null || warning.getLatitude() == null) {
|
|
|
|
|
+ warning.setLongitude(device.getLongitude());
|
|
|
|
|
+ warning.setLatitude(device.getLatitude());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtils.hasText(warning.getLocation())) {
|
|
|
|
|
+ warning.setLocation(device.getEquipmentLocation());
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!StringUtils.hasText(warning.getOwnershipUnit())) {
|
|
|
|
|
+ warning.setOwnershipUnit(device.getOwnershipUnit());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String trimToNull(String value) {
|
|
|
|
|
+ return StringUtils.hasText(value) ? value.trim() : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Integer parseInteger(String value) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Integer.valueOf(value.trim());
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|