commit
This commit is contained in:
@@ -67,7 +67,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
|||||||
String accessToken = getDmpAccessToken();
|
String accessToken = getDmpAccessToken();
|
||||||
List<JSONObject> rawDataList = distinctDmpUnits(pullDmpUnits(getDmpUnitUrl(), accessToken));
|
List<JSONObject> rawDataList = distinctDmpUnits(pullDmpUnits(getDmpUnitUrl(), accessToken));
|
||||||
Set<String> parentCodes = rawDataList.stream()
|
Set<String> parentCodes = rawDataList.stream()
|
||||||
.map(v -> v.getStr("LSDWH"))
|
.map(this::getNormalizedParentCode)
|
||||||
.filter(StrUtil::isNotBlank)
|
.filter(StrUtil::isNotBlank)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存或更新单位。
|
* 保存或更新单位。
|
||||||
* DWDM 对应系统单位 id/unitcode,DWMC 对应名称,LSDWH 对应父级单位号,DWCC 对应单位层级。
|
* DWDM 对应系统单位 id/unitcode,DWMC 对应名称,LSDWH 对应父级单位号,DWCC 对应信息中心原始单位层级。
|
||||||
*/
|
*/
|
||||||
private void saveOrUpdateUnit(JSONObject raw, Set<String> parentCodes) {
|
private void saveOrUpdateUnit(JSONObject raw, Set<String> parentCodes) {
|
||||||
String unitCode = raw.getStr("DWDM");
|
String unitCode = raw.getStr("DWDM");
|
||||||
@@ -200,7 +200,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String parentId = getParentId(unitCode, raw.getStr("LSDWH"));
|
String parentId = getParentId(unitCode, getNormalizedParentCode(raw));
|
||||||
Sys_unit unit = fetch(unitCode);
|
Sys_unit unit = fetch(unitCode);
|
||||||
if (unit == null) {
|
if (unit == null) {
|
||||||
unit = new Sys_unit();
|
unit = new Sys_unit();
|
||||||
@@ -220,14 +220,16 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据接口字段给系统单位赋值。
|
* 根据接口字段给系统单位赋值。
|
||||||
* DWYXBS 表示单位是否有效,DWCC 表示单位层次;当前项目用 unitTypeCode=1 识别业务可选单位。
|
* DWYXBS 表示单位是否有效,DWCC 表示信息中心原始单位层次;
|
||||||
|
* 系统内置根单位占用一级层级,因此保存时统一将 DWCC 加一。
|
||||||
*/
|
*/
|
||||||
private void setUnitValue(Sys_unit unit, JSONObject raw, String parentId, Set<String> parentCodes) {
|
private void setUnitValue(Sys_unit unit, JSONObject raw, String parentId, Set<String> parentCodes) {
|
||||||
String unitCode = raw.getStr("DWDM");
|
String unitCode = raw.getStr("DWDM");
|
||||||
String unitName = raw.getStr("DWMC");
|
String unitName = raw.getStr("DWMC");
|
||||||
String aliasName = StrUtil.blankToDefault(raw.getStr("DWJC"), unitName);
|
String aliasName = StrUtil.blankToDefault(raw.getStr("DWJC"), unitName);
|
||||||
Integer unitLevel = raw.getInt("DWCC");
|
Integer rawUnitLevel = raw.getInt("DWCC");
|
||||||
boolean availableBusinessUnit = "是".equals(raw.getStr("DWYXBS")) && Integer.valueOf(2).equals(unitLevel);
|
Integer unitLevel = getNormalizedUnitLevel(raw);
|
||||||
|
boolean availableBusinessUnit = "是".equals(raw.getStr("DWYXBS")) && Integer.valueOf(2).equals(rawUnitLevel);
|
||||||
|
|
||||||
unit.setParentId(parentId);
|
unit.setParentId(parentId);
|
||||||
unit.setName(unitName);
|
unit.setName(unitName);
|
||||||
@@ -242,12 +244,15 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算父级单位号。
|
* 计算父级单位号。
|
||||||
* LSDWH 为空、等于自身或本地不存在该父级时按根级处理,避免错误父级影响单位树保存。
|
* LSDWH 为空、等于自身或本地不存在该父级时按根级处理;系统根单位 0 允许直接作为父级。
|
||||||
*/
|
*/
|
||||||
private String getParentId(String unitCode, String parentCode) {
|
private String getParentId(String unitCode, String parentCode) {
|
||||||
if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode)) {
|
if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
if ("0".equals(parentCode)) {
|
||||||
|
return parentCode;
|
||||||
|
}
|
||||||
Sys_unit parentUnit = fetch(parentCode);
|
Sys_unit parentUnit = fetch(parentCode);
|
||||||
return parentUnit == null ? "" : parentCode;
|
return parentUnit == null ? "" : parentCode;
|
||||||
}
|
}
|
||||||
@@ -266,7 +271,26 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> 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) {
|
private int getUnitLevel(JSONObject raw) {
|
||||||
return raw.getInt("DWCC", 0);
|
return raw.getInt("DWCC", 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user