fix: 优化游向逻辑

This commit is contained in:
tangwei 2026-08-13 10:59:40 +08:00
parent 2e2c91f679
commit 8ce31d9c80
4 changed files with 97 additions and 11 deletions

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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<Integer, String> 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;

View File

@ -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);
}
}