Commit 4e3f0c3b authored by tianbo's avatar tianbo

refactor(amos-boot-module-jg): 优化生成登记证号逻辑

- 新增 getCityCode 方法,根据监管单位代码获取对应地市代码 - 修改生成登记证号逻辑,使用新的地市代码获取区域字典 - 优化代码结构,引入枚举类统一管理
parent c18cb166
......@@ -54,10 +54,7 @@ import com.yeejoin.amos.boot.module.jg.biz.utils.JsonUtils;
import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.ymt.api.entity.*;
import com.yeejoin.amos.boot.module.ymt.api.enums.ApplicationFormTypeEnum;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentCategoryEnum;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import com.yeejoin.amos.boot.module.ymt.api.enums.*;
import com.yeejoin.amos.boot.module.ymt.api.mapper.*;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.component.feign.utils.FeignUtil;
......@@ -1935,7 +1932,9 @@ public class CommonServiceImpl implements ICommonService {
if (!ValidationUtil.isEmpty(specialRegionCode)) { // 特殊的区域
city = specialRegionCode.getName();
} else { // 普通的地市
DataDictionary regionCodeDict = equipmentCategoryMapper.getOneDictByTypeAndExtend(EquipmentCategoryEnum.XZQH.getCode(), supervisoryCompanyCode);
// 根据接收机构查询对应父级地市code,用于生成登记证号
String cityCode = getCityCode(supervisoryCompanyCode);
DataDictionary regionCodeDict = equipmentCategoryMapper.getOneDictByTypeAndExtend(EquipmentCategoryEnum.XZQH.getCode(), cityCode);
city = regionCodeDict.getCode();
}
}
......@@ -1945,6 +1944,57 @@ public class CommonServiceImpl implements ICommonService {
return null;
}
public String getCityCode(String supervisoryCompanyCode) {
LinkedHashMap<String, Object> root = getCreatTree().get(0);
// 根据supervisoryCompanyCode递归匹配regulatorUnitTree,并从中记录级别等于prefecture-level的节点,返回其code
return findPrefectureLevelInTree(root, supervisoryCompanyCode);
}
private String findPrefectureLevelInTree(LinkedHashMap<String, Object> node, String targetCode) {
// 使用栈实现DFS遍历
// 节点栈
Deque<LinkedHashMap<String, Object>> nodeStack = new ArrayDeque<>();
// 路径栈
Deque<List<LinkedHashMap<String, Object>>> pathStack = new ArrayDeque<>();
nodeStack.push(node);
pathStack.push(new ArrayList<>());
while (!nodeStack.isEmpty()) {
LinkedHashMap<String, Object> current = nodeStack.pop();
List<LinkedHashMap<String, Object>> currentPath = pathStack.pop();
// 更新当前路径
List<LinkedHashMap<String, Object>> newPath = new ArrayList<>(currentPath);
newPath.add(current);
// 命中目标节点
if (targetCode.equals(current.get("companyCode"))) {
return findPrefectureInPath(newPath);
}
// 处理子节点
List<LinkedHashMap<String, Object>> children = (List<LinkedHashMap<String, Object>>) current.get("children");
if (!CollectionUtils.isEmpty(children)) {
for (int i = children.size()-1; i >= 0; i--) { // 保持原顺序需逆序压栈
nodeStack.push(children.get(i));
pathStack.push(new ArrayList<>(newPath));
}
}
}
return null;
}
private String findPrefectureInPath(List<LinkedHashMap<String, Object>> path) {
// 逆序查找最近的地级节点
for (int i = path.size()-1; i >= 0; i--) {
LinkedHashMap<String, Object> node = path.get(i);
if (CompanyLevelEnum.PREFECTURE_LEVEL.getCode().equals(node.get("level"))) {
return (String) node.get("companyCode");
}
}
return null;
}
/**
* 生成唯一使用登记编号
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment