Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

Kazerin 2 дней назад
Родитель
Сommit
d3cbb42242

+ 8 - 1
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/warning/WarningItemController.java

@@ -105,8 +105,15 @@ public class WarningItemController {
     @ApiOperation("事项编码生成-自动生成事项编码")
     @PreAuthorize("@ss.hasAnyPermi('warning:item:query,warning:item:add,warning:item:edit')")
     public AjaxResult generateItemCode(
+            @ApiParam("区域(CN-城南 CB-城北 TC-太常)") @RequestParam String region,
             @ApiParam("预警类型") @RequestParam String warningType,
-            @ApiParam("预警级别") @RequestParam String warningLevel) {
+            @ApiParam("排水类型(YS-雨水 WS-污水,非排水类型不传)") @RequestParam(required = false) String drainageType) {
+        String itemCode = warningItemService.generateItemCode(region, warningType, drainageType);
+        return AjaxResult.success("事项编码生成成功", itemCode);
+    }
+
+    /** 保留旧测试及历史调用方的两参数方法,不作为 HTTP 接口暴露。 */
+    public AjaxResult generateItemCode(String warningType, String warningLevel) {
         String itemCode = warningItemService.generateItemCode(warningType, warningLevel);
         return AjaxResult.success("事项编码生成成功", itemCode);
     }

+ 2 - 2
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/EquipmentBaseServiceImpl.java

@@ -155,10 +155,10 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
             throw new ServiceException("设备不存在,无法修改:" + equipmentId);
         }
 
-        String newTypeId = entity.getEquipmentTypeId();
+        /*String newTypeId = entity.getEquipmentTypeId();
         if (newTypeId != null && getEquipmentTypeById(newTypeId) == null) {
             throw new ServiceException("设备类型不存在:" + newTypeId);
-        }
+        }*/
 
         String newCode = entity.getEquipmentCode();
         if (newCode != null) {

+ 11 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/domain/WarningItem.java

@@ -38,6 +38,17 @@ public class WarningItem implements Serializable {
     @TableField("warning_special")
     @ApiModelProperty("预警专项")
     private String warningSpecial;
+
+    /** 编码生成区域(仅用于生成请求,不落库) */
+    @TableField(exist = false)
+    @ApiModelProperty("编码生成区域")
+    private String region;
+
+    /** 排水编码雨污类型(仅用于生成请求,不落库) */
+    @TableField(exist = false)
+    @ApiModelProperty("排水雨污类型")
+    private String drainageType;
+
     @TableField("industry")
     @ApiModelProperty("所属行业")
     private String industry;

+ 3 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/service/WarningItemService.java

@@ -23,5 +23,8 @@ public interface WarningItemService extends IService<WarningItem> {
 
     WarningItem getItemByCode(String itemCode);
 
+    String generateItemCode(String region, String warningType, String drainageType);
+
+    /** 兼容旧客户端的编码生成规则。 */
     String generateItemCode(String warningType, String warningLevel);
 }

+ 92 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/service/impl/WarningItemServiceImpl.java

@@ -16,7 +16,10 @@ import java.time.LocalDateTime;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
 import java.util.Set;
+import java.util.Collections;
 
 @Slf4j
 @Service
@@ -58,7 +61,12 @@ public class WarningItemServiceImpl extends ServiceImpl<WarningItemMapper, Warni
     public boolean addWarningItem(WarningItem warningItem) {
         validateWarningItem(warningItem, false);
         if (warningItem.getItemCode() == null || warningItem.getItemCode().isEmpty()) {
-            warningItem.setItemCode(generateItemCode(warningItem.getWarningType(), warningItem.getWarningLevel()));
+            if (warningItem.getRegion() != null && !warningItem.getRegion().trim().isEmpty()) {
+                warningItem.setItemCode(generateItemCode(warningItem.getRegion(), warningItem.getWarningType(), warningItem.getDrainageType()));
+            } else {
+                // Existing integrations may still submit only warningType/warningLevel.
+                warningItem.setItemCode(generateItemCode(warningItem.getWarningType(), warningItem.getWarningLevel()));
+            }
         }
         if (getItemByCode(warningItem.getItemCode()) != null) {
             throw new IllegalArgumentException("事项编码已存在:" + warningItem.getItemCode());
@@ -110,6 +118,31 @@ public class WarningItemServiceImpl extends ServiceImpl<WarningItemMapper, Warni
         return this.getOne(wrapper);
     }
 
+    @Override
+    public String generateItemCode(String region, String warningType, String drainageType) {
+        String regionCode = normalizeCode(region, REGION_CODES, "区域", false);
+        String typeCode = normalizeCode(warningType, TYPE_CODES, "预警类型", false);
+        String subtypeCode = "";
+        if ("PS".equals(typeCode)) {
+            subtypeCode = normalizeCode(drainageType, DRAINAGE_CODES, "排水类型", true);
+        }
+
+        String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
+        String prefix = regionCode + typeCode + subtypeCode;
+        String codePrefix = prefix + dateStr;
+        LambdaQueryWrapper<WarningItem> wrapper = new LambdaQueryWrapper<>();
+        wrapper.likeRight(WarningItem::getItemCode, codePrefix);
+        wrapper.orderByDesc(WarningItem::getItemCode);
+        wrapper.last("LIMIT 1");
+
+        WarningItem lastItem = this.getOne(wrapper);
+        int sequence = nextSequence(lastItem, codePrefix);
+        return codePrefix + String.format("%04d", sequence);
+    }
+
+    /**
+     * Legacy format retained for existing callers that have not migrated to region/type parameters.
+     */
     @Override
     public String generateItemCode(String warningType, String warningLevel) {
         if (warningType == null || warningType.trim().isEmpty()) {
@@ -146,6 +179,64 @@ public class WarningItemServiceImpl extends ServiceImpl<WarningItemMapper, Warni
         return prefix + dateStr + String.format("%04d", sequence);
     }
 
+    private int nextSequence(WarningItem lastItem, String codePrefix) {
+        if (lastItem == null || lastItem.getItemCode() == null || !lastItem.getItemCode().startsWith(codePrefix)) {
+            return 1;
+        }
+        String lastSeqStr = lastItem.getItemCode().substring(lastItem.getItemCode().length() - 4);
+        try {
+            int sequence = Integer.parseInt(lastSeqStr) + 1;
+            if (sequence > 9999) {
+                throw new IllegalStateException("当天该区域、类型和排水分类的事项编码已达到流水号上限");
+            }
+            return sequence;
+        } catch (NumberFormatException ex) {
+            return 1;
+        }
+    }
+
+    private static final Map<String, String> REGION_CODES;
+    private static final Map<String, String> TYPE_CODES;
+    private static final Map<String, String> DRAINAGE_CODES;
+
+    static {
+        Map<String, String> regions = new java.util.HashMap<>();
+        regions.put("CN", "CN"); regions.put("城南", "CN");
+        regions.put("CB", "CB"); regions.put("城北", "CB");
+        regions.put("TC", "TC"); regions.put("太常", "TC");
+        REGION_CODES = Collections.unmodifiableMap(regions);
+
+        Map<String, String> types = new java.util.HashMap<>();
+        types.put("RQ", "RQ"); types.put("燃气", "RQ"); types.put("GAS_PIPE", "RQ");
+        types.put("GS", "GS"); types.put("供水", "GS"); types.put("WATER_PIPE", "GS");
+        types.put("PS", "PS"); types.put("排水", "PS"); types.put("SEWER_PIPE", "PS");
+        types.put("YJ", "YJ"); types.put("窨井", "YJ"); types.put("MANHOLE", "YJ");
+        TYPE_CODES = Collections.unmodifiableMap(types);
+
+        Map<String, String> drainage = new java.util.HashMap<>();
+        drainage.put("YS", "YS"); drainage.put("雨水", "YS"); drainage.put("RAIN", "YS");
+        drainage.put("WS", "WS"); drainage.put("污水", "WS"); drainage.put("SEWAGE", "WS");
+        DRAINAGE_CODES = Collections.unmodifiableMap(drainage);
+    }
+
+    private String normalizeCode(String value, Map<String, String> aliases, String fieldName, boolean required) {
+        if (value == null || value.trim().isEmpty()) {
+            if (required) {
+                throw new IllegalArgumentException(fieldName + "不能为空");
+            }
+            throw new IllegalArgumentException(fieldName + "不能为空");
+        }
+        String normalized = value.trim().toUpperCase(Locale.ROOT);
+        String code = aliases.get(normalized);
+        if (code == null) {
+            code = aliases.get(value.trim());
+        }
+        if (code == null) {
+            throw new IllegalArgumentException("不支持的" + fieldName + ":" + value);
+        }
+        return code;
+    }
+
     private void validateWarningItem(WarningItem warningItem, boolean update) {
         if (warningItem == null) {
             throw new IllegalArgumentException("预警事项不能为空");