|
|
@@ -253,6 +253,63 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
equipmentTypeId, status, alarmStatus, alertLevel).getRecords();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean createWaterDevice(EquipmentBase device) {
|
|
|
+ if (device == null || StrUtil.isBlank(device.getEquipmentCode())) {
|
|
|
+ throw new IllegalArgumentException("设备编码不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(device.getEquipmentTypeId())) {
|
|
|
+ throw new IllegalArgumentException("设备类型不能为空");
|
|
|
+ }
|
|
|
+ EquipmentType type = equipmentTypeMapper.selectById(device.getEquipmentTypeId());
|
|
|
+ if (type == null || !isWaterTypeRecord(type)) {
|
|
|
+ throw new IllegalArgumentException("设备类型不属于供水:" + device.getEquipmentTypeId());
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<EquipmentBase> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(EquipmentBase::getEquipmentCode, device.getEquipmentCode());
|
|
|
+ if (this.count(wrapper) > 0) {
|
|
|
+ throw new IllegalArgumentException("设备编码已存在:" + device.getEquipmentCode());
|
|
|
+ }
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ device.setEquipmentId(null);
|
|
|
+ device.setCreateTime(now);
|
|
|
+ device.setUpdateTime(now);
|
|
|
+ return save(device);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean deleteWaterDevices(List<String> equipmentIds) {
|
|
|
+ if (CollUtil.isEmpty(equipmentIds)) {
|
|
|
+ throw new IllegalArgumentException("设备ID列表不能为空");
|
|
|
+ }
|
|
|
+ List<String> invalidIds = equipmentIds.stream()
|
|
|
+ .filter(equipmentId -> findWaterDeviceById(equipmentId) == null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!invalidIds.isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("存在非供水设备,无法删除:" + String.join(",", invalidIds));
|
|
|
+ }
|
|
|
+ return equipmentBaseService.removeBatchWithCheck(equipmentIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isWaterTypeRecord(EquipmentType type) {
|
|
|
+ List<EquipmentType> allTypes = equipmentTypeMapper.selectList(new LambdaQueryWrapper<EquipmentType>());
|
|
|
+ Map<String, EquipmentType> typesById = new HashMap<>();
|
|
|
+ for (EquipmentType item : allTypes) {
|
|
|
+ typesById.putIfAbsent(item.getId(), item);
|
|
|
+ }
|
|
|
+ EquipmentType cursor = type;
|
|
|
+ int guard = 0;
|
|
|
+ while (cursor != null && guard++ <= typesById.size()) {
|
|
|
+ if (waterTopLevelTypeName.equals(cursor.getTypeName()) && "0".equals(cursor.getParentTypeId())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ cursor = typesById.get(cursor.getParentTypeId());
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<DeviceGisVO> getAllDeviceGisPoints(String equipmentTypeId) {
|
|
|
List<EquipmentBase> list = findWaterDevices().stream()
|