From 8ce31d9c8045f0149495f99baf917e77b510b818 Mon Sep 17 00:00:00 2001 From: tangwei Date: Thu, 13 Aug 2026 10:59:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=B8=B8=E5=90=91?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FishDraftDataController.java | 5 +- .../qgc_data/service/IFishImportService.java | 2 +- .../service/impl/FishImportServiceImpl.java | 97 +++++++++++++++++-- .../service/impl/AdminAuthServiceImpl.java | 4 +- 4 files changed, 97 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/yfd/platform/qgc_data/controller/FishDraftDataController.java b/backend/src/main/java/com/yfd/platform/qgc_data/controller/FishDraftDataController.java index 186e6971..c59aa0a2 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_data/controller/FishDraftDataController.java +++ b/backend/src/main/java/com/yfd/platform/qgc_data/controller/FishDraftDataController.java @@ -1227,8 +1227,9 @@ public class FishDraftDataController { if (data.getDirection() == null || data.getDirection().isEmpty()) { addWarning(warnings, "direction"); } else { - String direction = fishImportService.resolveDirection(data.getDirection().trim(), importRow); - if (direction == null) { + String direction = fishImportService.resolveDirection(data.getStnm(),data.getDirection().trim(), importRow); + if (direction == null||importRow.getWarnings().contains("direction")) { + data.setDirection(direction); addWarning(warnings, "direction"); } } diff --git a/backend/src/main/java/com/yfd/platform/qgc_data/service/IFishImportService.java b/backend/src/main/java/com/yfd/platform/qgc_data/service/IFishImportService.java index 44bfdb8d..a78c0c63 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_data/service/IFishImportService.java +++ b/backend/src/main/java/com/yfd/platform/qgc_data/service/IFishImportService.java @@ -42,7 +42,7 @@ public interface IFishImportService { String resolveBaseCode(String code,String baseName); String resolveRiverCode(String code,String riverName); String resolveHbrvcdCode(String code,String riverName); - String resolveDirection(String direction, FishImportResult.FishImportRow importRow); + String resolveDirection(String stnm,String direction, FishImportResult.FishImportRow importRow); String resolveIsfs(String value, FishImportResult.FishImportRow importRow); diff --git a/backend/src/main/java/com/yfd/platform/qgc_data/service/impl/FishImportServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_data/service/impl/FishImportServiceImpl.java index 23f1728b..68e67d3b 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_data/service/impl/FishImportServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_data/service/impl/FishImportServiceImpl.java @@ -342,12 +342,16 @@ public class FishImportServiceImpl implements IFishImportService { FishImportResult.FishImportRow importRow = new FishImportResult.FishImportRow(rowIndex); FishDraftData data = new FishDraftData(); data.setId(UUID.randomUUID().toString()); - + String stnm=null; for (Map.Entry entry : columnIndexMap.entrySet()) { Integer columnIndex = entry.getKey(); String fieldName = entry.getValue(); Cell cell = row.getCell(columnIndex); String cellValue = getCellStringValue(cell); + + if("stnm".equals(fieldName)){ + stnm=cellValue; + } try { switch (fieldName) { case "stationName": @@ -509,7 +513,7 @@ public class FishImportServiceImpl implements IFishImportService { importRow.getWarnings().add(fieldName); data.setDirection(cellValue.trim()); } else { - String direction = resolveDirection(cellValue.trim(), importRow); + String direction = resolveDirection(stnm,cellValue.trim(), importRow); data.setDirection(direction); } break; @@ -1372,25 +1376,104 @@ public class FishImportServiceImpl implements IFishImportService { return facilityName; } - public String resolveDirection(String direction, FishImportResult.FishImportRow importRow) { + + public String resolveDirection(String stnm, String direction, FishImportResult.FishImportRow importRow) { if (direction == null) { return null; } String lowerName = direction.toLowerCase().trim(); - if (lowerName.contains("上行") && lowerName.contains("折返")) { + // 独立判断四种方向类型(按优先级从高到低) + boolean isUpReturn = lowerName.contains("上行") && lowerName.contains("折返"); + boolean isDownReturn = lowerName.contains("下行") && lowerName.contains("折返"); + boolean isUp = lowerName.contains("上行") && !isUpReturn; // 排除上行折返 + boolean isDown = lowerName.contains("下行") && !isDownReturn; // 排除下行折返 + + // 判断 direction 是否为字典编码 + boolean isDictCode = "0".equals(direction) || "1".equals(direction) || + "2".equals(direction) || "3".equals(direction); + + // 如果 direction 本身是字典编码(0/1/2/3),直接识别 + if ("0".equals(direction)) { + isUp = true; + isUpReturn = false; + } else if ("1".equals(direction)) { + isDown = true; + isDownReturn = false; + } else if ("2".equals(direction)) { + isUpReturn = true; + isUp = false; + } else if ("3".equals(direction)) { + isDownReturn = true; + isDown = false; + } + + // 根据设施名称校验方向(仅当 stnm 不为 null 时) + if (StrUtil.isNotBlank(stnm)) { + String facilityName = stnm.toLowerCase().trim(); + // 设施名称包含"上行"时,只允许上行或上行折返 + if (facilityName.contains("上行") && !isUp && !isUpReturn) { + importRow.getWarnings().add("direction"); + // 如果是字典编码,返回对应的中文;否则返回原始数据 + return isDictCode ? getDirectionChinese(direction) : direction; + } + // 设施名称包含"下行"时,只允许下行或下行折返 + if (facilityName.contains("下行") && !isDown && !isDownReturn) { + importRow.getWarnings().add("direction"); + // 如果是字典编码,返回对应的中文;否则返回原始数据 + return isDictCode ? getDirectionChinese(direction) : direction; + } + } + + // 返回对应的字典编码 + if (isUpReturn) { return "2"; - } else if (lowerName.contains("下行") && lowerName.contains("折返")) { + } else if (isDownReturn) { return "3"; - } else if (lowerName.contains("上行")) { + } else if (isUp) { return "0"; - } else if (lowerName.contains("下行")) { + } else if (isDown) { return "1"; } + + // 未匹配任何方向 importRow.getWarnings().add("direction"); return direction; } + /** + * 根据字典编码返回对应的中文描述 + */ + private String getDirectionChinese(String dictCode) { + if ("0".equals(dictCode)) { + return "上行"; + } else if ("1".equals(dictCode)) { + return "下行"; + } else if ("2".equals(dictCode)) { + return "上行折返"; + } else if ("3".equals(dictCode)) { + return "下行折返"; + } + return dictCode; + } +// public String resolveDirection(String stnm,String direction, FishImportResult.FishImportRow importRow) { +// if (direction == null) { +// return null; +// } +// String lowerName = direction.toLowerCase().trim(); +// if (lowerName.contains("上行") && lowerName.contains("折返")) { +// return "2"; +// } else if (lowerName.contains("下行") && lowerName.contains("折返")) { +// return "3"; +// } else if (lowerName.contains("上行")) { +// return "0"; +// } else if (lowerName.contains("下行")) { +// return "1"; +// } +// importRow.getWarnings().add("direction"); +// return direction; +// } + public String resolveIsfs(String value, FishImportResult.FishImportRow importRow) { if (value == null) { return null; diff --git a/backend/src/main/java/com/yfd/platform/system/service/impl/AdminAuthServiceImpl.java b/backend/src/main/java/com/yfd/platform/system/service/impl/AdminAuthServiceImpl.java index 4f75a0aa..0afe0e2c 100644 --- a/backend/src/main/java/com/yfd/platform/system/service/impl/AdminAuthServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/system/service/impl/AdminAuthServiceImpl.java @@ -74,8 +74,10 @@ public class AdminAuthServiceImpl implements IAdminAuthService { @Override public boolean isCurrentManagedAdmin() { +// SysUser sysUser = userMapper.selectById(SecurityUtils.getUserId()); String maxLevel = userMapper.getMaxLevel(SecurityUtils.getUserId()); boolean adminRole = "1".equals(maxLevel); - return adminRole||isManagedAdminUsername(SecurityUtils.getCurrentUsername()); + String currentUsername = SecurityUtils.getCurrentUsername(); + return adminRole||isManagedAdminUsername(currentUsername); } }