diff --git a/src/main/java/com/budwk/app/sys/services/impl/SysDataUnitPullServiceImpl.java b/src/main/java/com/budwk/app/sys/services/impl/SysDataUnitPullServiceImpl.java index 4445a995..c42ecf15 100644 --- a/src/main/java/com/budwk/app/sys/services/impl/SysDataUnitPullServiceImpl.java +++ b/src/main/java/com/budwk/app/sys/services/impl/SysDataUnitPullServiceImpl.java @@ -67,7 +67,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl implem String accessToken = getDmpAccessToken(); List rawDataList = distinctDmpUnits(pullDmpUnits(getDmpUnitUrl(), accessToken)); Set parentCodes = rawDataList.stream() - .map(v -> v.getStr("LSDWH")) + .map(this::getNormalizedParentCode) .filter(StrUtil::isNotBlank) .collect(Collectors.toSet()); @@ -192,7 +192,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl implem /** * 保存或更新单位。 - * DWDM 对应系统单位 id/unitcode,DWMC 对应名称,LSDWH 对应父级单位号,DWCC 对应单位层级。 + * DWDM 对应系统单位 id/unitcode,DWMC 对应名称,LSDWH 对应父级单位号,DWCC 对应信息中心原始单位层级。 */ private void saveOrUpdateUnit(JSONObject raw, Set parentCodes) { String unitCode = raw.getStr("DWDM"); @@ -200,7 +200,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl implem return; } - String parentId = getParentId(unitCode, raw.getStr("LSDWH")); + String parentId = getParentId(unitCode, getNormalizedParentCode(raw)); Sys_unit unit = fetch(unitCode); if (unit == null) { unit = new Sys_unit(); @@ -220,14 +220,16 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl implem /** * 根据接口字段给系统单位赋值。 - * DWYXBS 表示单位是否有效,DWCC 表示单位层次;当前项目用 unitTypeCode=1 识别业务可选单位。 + * DWYXBS 表示单位是否有效,DWCC 表示信息中心原始单位层次; + * 系统内置根单位占用一级层级,因此保存时统一将 DWCC 加一。 */ private void setUnitValue(Sys_unit unit, JSONObject raw, String parentId, Set parentCodes) { String unitCode = raw.getStr("DWDM"); String unitName = raw.getStr("DWMC"); String aliasName = StrUtil.blankToDefault(raw.getStr("DWJC"), unitName); - Integer unitLevel = raw.getInt("DWCC"); - boolean availableBusinessUnit = "是".equals(raw.getStr("DWYXBS")) && Integer.valueOf(2).equals(unitLevel); + Integer rawUnitLevel = raw.getInt("DWCC"); + Integer unitLevel = getNormalizedUnitLevel(raw); + boolean availableBusinessUnit = "是".equals(raw.getStr("DWYXBS")) && Integer.valueOf(2).equals(rawUnitLevel); unit.setParentId(parentId); unit.setName(unitName); @@ -242,12 +244,15 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl implem /** * 计算父级单位号。 - * LSDWH 为空、等于自身或本地不存在该父级时按根级处理,避免错误父级影响单位树保存。 + * LSDWH 为空、等于自身或本地不存在该父级时按根级处理;系统根单位 0 允许直接作为父级。 */ private String getParentId(String unitCode, String parentCode) { if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode)) { return ""; } + if ("0".equals(parentCode)) { + return parentCode; + } Sys_unit parentUnit = fetch(parentCode); return parentUnit == null ? "" : parentCode; } @@ -266,7 +271,26 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl implem } /** - * DWCC 为单位层次,排序时用于尽量先处理父级单位,便于后续子级找到父节点。 + * 信息中心一级单位应挂在系统根单位 0 下,其余单位沿用接口返回的 LSDWH。 + */ + private String getNormalizedParentCode(JSONObject raw) { + Integer rawUnitLevel = raw.getInt("DWCC"); + if (Integer.valueOf(1).equals(rawUnitLevel)) { + return "0"; + } + return raw.getStr("LSDWH"); + } + + /** + * 系统内置根单位占用一级层级,信息中心单位层次入库时统一加一。 + */ + private Integer getNormalizedUnitLevel(JSONObject raw) { + Integer rawUnitLevel = raw.getInt("DWCC"); + return rawUnitLevel == null ? null : rawUnitLevel + 1; + } + + /** + * DWCC 为信息中心单位层次,排序时用于尽量先处理父级单位,便于后续子级找到父节点。 */ private int getUnitLevel(JSONObject raw) { return raw.getInt("DWCC", 0);