feat: 优化拉取接口
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.config.DataCenterProperties;
|
||||
@@ -13,6 +15,7 @@ import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
@@ -38,6 +41,7 @@ import java.util.stream.Collectors;
|
||||
public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implements SysDataUnitPullService {
|
||||
|
||||
private static final String DMP_UNIT_KEY = "unit";
|
||||
private static final int BATCH_SIZE = 500;
|
||||
|
||||
@Inject
|
||||
private DataCenterProperties dataCenterProperties;
|
||||
@@ -59,14 +63,21 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void updateUnits(List<String> unitIds) {
|
||||
Sys_unit root = DataCenterUtil.findRootUnit(query(Cnd.NEW()));
|
||||
List<Sys_unit> localUnits = query(Cnd.NEW());
|
||||
Sys_unit root = DataCenterUtil.findRootUnit(localUnits);
|
||||
Map<String, Sys_unit> unitMap = localUnits.stream()
|
||||
.collect(Collectors.toMap(Sys_unit::getId, unit -> unit));
|
||||
Set<String> existingUnitIds = new HashSet<>(unitMap.keySet());
|
||||
Map<String, Sys_unit> changedUnits = new LinkedHashMap<>();
|
||||
List<Sql> pathUpdates = new ArrayList<>();
|
||||
List<JSONObject> rawDataList = distinctDmpUnits(DataCenterUtil.pullData(getDmpUnitUrl()));
|
||||
if (rawDataList.isEmpty()) {
|
||||
throw new BaseException("当前未获取到单位数据,中止本次同步");
|
||||
log.warn("当前未获取到有效单位数据,跳过本次机构同步");
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isBlank(root.getPath())) {
|
||||
root.setPath(getUnitPath(""));
|
||||
dao().updateIgnoreNull(root);
|
||||
root.setPath(getUnitPath("", unitMap));
|
||||
changedUnits.put(root.getId(), root);
|
||||
}
|
||||
Set<String> parentCodes = rawDataList.stream()
|
||||
.map(raw -> getNormalizedParentCode(raw, root.getId()))
|
||||
@@ -75,7 +86,32 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
|
||||
rawDataList.stream()
|
||||
.sorted(Comparator.comparingInt(this::getUnitLevel))
|
||||
.forEach(raw -> saveOrUpdateUnit(raw, parentCodes, root));
|
||||
.forEach(raw -> {
|
||||
try {
|
||||
prepareUnit(raw, parentCodes, root, unitMap, changedUnits, pathUpdates);
|
||||
} catch (Exception e) {
|
||||
log.warn("单位同步失败,跳过当前机构,单位编码: {},上级编码: {},原因: {}", raw.getStr("DWDM"), raw.getStr("LSDWDM"), e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
List<Sys_unit> insertUnits = new ArrayList<>();
|
||||
List<Sys_unit> updateUnits = new ArrayList<>();
|
||||
for (Sys_unit unit : changedUnits.values()) {
|
||||
if (existingUnitIds.contains(unit.getId())) {
|
||||
updateUnits.add(unit);
|
||||
} else {
|
||||
insertUnits.add(unit);
|
||||
}
|
||||
}
|
||||
for (List<Sys_unit> batch : ListUtil.split(insertUnits, BATCH_SIZE)) {
|
||||
dao().fastInsert(batch);
|
||||
}
|
||||
for (List<Sys_unit> batch : ListUtil.split(updateUnits, BATCH_SIZE)) {
|
||||
dao().updateIgnoreNull(batch);
|
||||
}
|
||||
for (List<Sql> batch : ListUtil.split(pathUpdates, BATCH_SIZE)) {
|
||||
dao().execute(batch.toArray(new Sql[0]));
|
||||
}
|
||||
|
||||
dao().execute(Sqls.create("update sys_unit u left join (select parentId, count(*) as childCount from sys_unit where parentId is not null and id<>parentId group by parentId) children on children.parentId=u.id set u.hasChildren=(children.childCount is not null)"));
|
||||
|
||||
@@ -100,23 +136,30 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
private List<JSONObject> distinctDmpUnits(List<JSONObject> rawDataList) {
|
||||
Map<String, JSONObject> unitMap = new LinkedHashMap<>();
|
||||
for (JSONObject raw : rawDataList) {
|
||||
String unitCode = raw.getStr("DWDM");
|
||||
if (StrUtil.isBlank(unitCode)) {
|
||||
throw new BaseException("单位接口存在缺少 DWDM 的记录");
|
||||
try {
|
||||
String unitCode = raw.getStr("DWDM");
|
||||
if (StrUtil.isBlank(unitCode)) {
|
||||
log.warn("单位接口记录缺少 DWDM,跳过当前机构,ROW_ID: {}", raw.get("ROW_ID"));
|
||||
continue;
|
||||
}
|
||||
if (raw.getInt("DWCC") == null || raw.getInt("DWCC") < 1) {
|
||||
log.warn("单位{}的 DWCC 无效,跳过当前机构,DWCC: {}", unitCode, raw.get("DWCC"));
|
||||
continue;
|
||||
}
|
||||
unitMap.putIfAbsent(unitCode, raw);
|
||||
} catch (Exception e) {
|
||||
log.warn("单位接口记录解析失败,跳过当前机构,单位编码: {},原因: {}", raw == null ? null : raw.get("DWDM"), e.getMessage());
|
||||
}
|
||||
if (raw.getInt("DWCC") == null || raw.getInt("DWCC") < 1) {
|
||||
throw new BaseException("单位{}的 DWCC 无效", unitCode);
|
||||
}
|
||||
unitMap.putIfAbsent(unitCode, raw);
|
||||
}
|
||||
return new ArrayList<>(unitMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或更新单位。
|
||||
* 在内存中整理待新增、更新的单位及关联人员路径变更。
|
||||
* DWDM 对应系统单位 id/unitcode,DWMC 对应名称,LSDWDM 对应父级单位号,DWCC 对应信息中心原始单位层级。
|
||||
*/
|
||||
private void saveOrUpdateUnit(JSONObject raw, Set<String> parentCodes, Sys_unit root) {
|
||||
private void prepareUnit(JSONObject raw, Set<String> parentCodes, Sys_unit root,
|
||||
Map<String, Sys_unit> unitMap, Map<String, Sys_unit> changedUnits, List<Sql> pathUpdates) {
|
||||
String unitCode = raw.getStr("DWDM");
|
||||
if (StrUtil.isBlank(unitCode)) {
|
||||
return;
|
||||
@@ -125,35 +168,38 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
if (root.getId().equals(unitCode)) {
|
||||
throw new BaseException("接口单位{}与本地顶级机构编号冲突,中止同步", unitCode);
|
||||
}
|
||||
String parentId = getParentId(unitCode, getNormalizedParentCode(raw, root.getId()), root.getId());
|
||||
Sys_unit unit = fetch(unitCode);
|
||||
if (unit == null) {
|
||||
unit = new Sys_unit();
|
||||
String parentId = getParentId(unitCode, getNormalizedParentCode(raw, root.getId()), root.getId(), unitMap);
|
||||
Sys_unit existing = unitMap.get(unitCode);
|
||||
Sys_unit unit = existing == null ? new Sys_unit() : BeanUtil.copyProperties(existing, Sys_unit.class);
|
||||
setUnitValue(unit, raw, parentId, parentCodes);
|
||||
if (existing == null) {
|
||||
unit.setId(unitCode);
|
||||
unit.setUnitcode(unitCode);
|
||||
unit.setPath(getUnitPath(parentId));
|
||||
setUnitValue(unit, raw, parentId, parentCodes);
|
||||
dao().fastInsert(unit);
|
||||
unit.setPath(getUnitPath(parentId, unitMap));
|
||||
} else {
|
||||
if (!parentId.equals(unit.getParentId()) || StrUtil.isBlank(unit.getPath())) {
|
||||
String oldPath = unit.getPath();
|
||||
String newPath = getUnitPath(parentId);
|
||||
if (!parentId.equals(existing.getParentId()) || StrUtil.isBlank(existing.getPath())) {
|
||||
String oldPath = existing.getPath();
|
||||
String newPath = getUnitPath(parentId, unitMap);
|
||||
if (StrUtil.isNotBlank(oldPath)) {
|
||||
if (newPath.startsWith(oldPath)) {
|
||||
throw new BaseException("单位{}不能移动到自身的下级单位", unitCode);
|
||||
}
|
||||
dao().execute(Sqls.create("update sys_unit set path=concat(@newPath, substring(path, @start)) where path like @prefix")
|
||||
pathUpdates.add(Sqls.create("update sys_user set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
.setParam("newPath", newPath).setParam("start", oldPath.length() + 1).setParam("prefix", oldPath + "%"));
|
||||
dao().execute(Sqls.create("update sys_user set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
.setParam("newPath", newPath).setParam("start", oldPath.length() + 1).setParam("prefix", oldPath + "%"));
|
||||
dao().execute(Sqls.create("update sys_user_source set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
pathUpdates.add(Sqls.create("update sys_user_source set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
.setParam("newPath", newPath).setParam("start", oldPath.length() + 1).setParam("prefix", oldPath + "%"));
|
||||
for (Sys_unit child : unitMap.values()) {
|
||||
if (StrUtil.isNotBlank(child.getPath()) && child.getPath().startsWith(oldPath)) {
|
||||
child.setPath(newPath + child.getPath().substring(oldPath.length()));
|
||||
changedUnits.put(child.getId(), child);
|
||||
}
|
||||
}
|
||||
}
|
||||
unit.setPath(newPath);
|
||||
}
|
||||
setUnitValue(unit, raw, parentId, parentCodes);
|
||||
dao().updateIgnoreNull(unit);
|
||||
}
|
||||
unitMap.put(unitCode, unit);
|
||||
changedUnits.put(unitCode, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,9 +228,9 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
* 计算父级单位号。
|
||||
* 异常父级仅允许沿用本地已修正的关系,并确认父级链最终到达顶级机构。
|
||||
*/
|
||||
private String getParentId(String unitCode, String parentCode, String rootId) {
|
||||
if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode) || fetch(parentCode) == null) {
|
||||
Sys_unit existing = fetch(unitCode);
|
||||
private String getParentId(String unitCode, String parentCode, String rootId, Map<String, Sys_unit> unitMap) {
|
||||
if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode) || !unitMap.containsKey(parentCode)) {
|
||||
Sys_unit existing = unitMap.get(unitCode);
|
||||
parentCode = existing == null ? null : existing.getParentId();
|
||||
}
|
||||
String ancestorId = parentCode;
|
||||
@@ -194,7 +240,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
if (StrUtil.isBlank(ancestorId) || !visited.add(ancestorId)) {
|
||||
throw new BaseException("单位{}的上级机构无效或存在循环,无法确定归属", unitCode);
|
||||
}
|
||||
Sys_unit ancestor = fetch(ancestorId);
|
||||
Sys_unit ancestor = unitMap.get(ancestorId);
|
||||
if (ancestor == null) {
|
||||
throw new BaseException("单位{}的上级机构{}不存在", unitCode, ancestorId);
|
||||
}
|
||||
@@ -207,16 +253,26 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
* 根据父级 path 生成当前单位 path。
|
||||
* 父级为空时生成根节点 path,父级存在时在父级 path 下生成子节点 path。
|
||||
*/
|
||||
private String getUnitPath(String parentId) {
|
||||
private String getUnitPath(String parentId, Map<String, Sys_unit> unitMap) {
|
||||
String parentPath = "";
|
||||
if (StrUtil.isNotBlank(parentId)) {
|
||||
Sys_unit parentUnit = fetch(parentId);
|
||||
Sys_unit parentUnit = unitMap.get(parentId);
|
||||
if (parentUnit == null || StrUtil.isBlank(parentUnit.getPath())) {
|
||||
throw new BaseException("父机构{}不存在或路径为空", parentId);
|
||||
}
|
||||
parentPath = parentUnit.getPath();
|
||||
}
|
||||
return getSubPath("sys_unit", "path", parentPath);
|
||||
int maxIndex = 0;
|
||||
for (Sys_unit unit : unitMap.values()) {
|
||||
String path = unit.getPath();
|
||||
if (StrUtil.isNotBlank(path) && path.startsWith(parentPath) && path.length() == parentPath.length() + 4) {
|
||||
maxIndex = Math.max(maxIndex, Integer.parseInt(path.substring(parentPath.length())));
|
||||
}
|
||||
}
|
||||
if (maxIndex >= 9999) {
|
||||
throw new BaseException("父机构{}的子级路径编码已用尽", parentId);
|
||||
}
|
||||
return parentPath + StrUtil.padPre(String.valueOf(maxIndex + 1), 4, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+35
-9
@@ -5,7 +5,6 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.event.role.RoleEventMsg;
|
||||
import com.budwk.app.base.event.role.RoleEventPublisher;
|
||||
import com.budwk.app.base.utils.ConditionGroupUtil;
|
||||
@@ -19,6 +18,7 @@ import com.budwk.app.sys.utils.DataCenterUtil;
|
||||
import com.budwk.app.zhgh.democratic.proposal.models.ProposalConfig;
|
||||
import com.budwk.app.zhgh.staffmanage.member.constant.MemberChangeOrigin;
|
||||
import com.budwk.app.zhgh.staffmanage.member.constant.MemberChangeType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
@@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||
* 增量更新系统用户数据
|
||||
*/
|
||||
@IocBean
|
||||
@Slf4j
|
||||
public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateService {
|
||||
|
||||
@Inject
|
||||
@@ -66,38 +67,59 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
||||
var unitMap = sysUnits.stream().collect(java.util.stream.Collectors.toMap(Sys_unit::getId, v -> v));
|
||||
List<Sys_unit> insertUnits = new ArrayList<>();
|
||||
Sys_unit root = null;
|
||||
for (Sys_user_source source : userSources) {
|
||||
int nextUnitPathIndex = 0;
|
||||
for (var iterator = userSources.iterator(); iterator.hasNext();) {
|
||||
Sys_user_source source = iterator.next();
|
||||
if (StrUtil.isBlank(source.getUnitId())) {
|
||||
throw new BaseException("人员{}缺少所属机构编号", source.getLoginname());
|
||||
log.warn("人员{}缺少所属机构编号,跳过当前人员增量更新", source.getLoginname());
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
Sys_unit unit = unitMap.get(source.getUnitId());
|
||||
if (unit == null) {
|
||||
if (StrUtil.isBlank(source.getUnitName())) {
|
||||
throw new BaseException("人员{}所属机构{}缺少名称,无法补建", source.getLoginname(), source.getUnitId());
|
||||
log.warn("人员{}所属机构{}缺少名称,无法补建,跳过当前人员增量更新", source.getLoginname(), source.getUnitId());
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (root == null) {
|
||||
root = DataCenterUtil.findRootUnit(sysUnits);
|
||||
if (StrUtil.isBlank(root.getPath())) {
|
||||
root.setPath(sysUnitService.getSubPath("sys_unit", "path", ""));
|
||||
dao.updateIgnoreNull(root);
|
||||
}
|
||||
String nextUnitPath = sysUnitService.getSubPath("sys_unit", "path", root.getPath());
|
||||
nextUnitPathIndex = Integer.parseInt(nextUnitPath.substring(root.getPath().length()));
|
||||
}
|
||||
unit = new Sys_unit();
|
||||
unit.setId(source.getUnitId());
|
||||
unit.setUnitcode(source.getUnitId());
|
||||
unit.setName(source.getUnitName());
|
||||
unit.setUnitLevel(2);
|
||||
unit.setUnitTypeCode(1);
|
||||
sysUnitService.save(unit, root.getId());
|
||||
unit.setParentId(root.getId());
|
||||
unit.setPath(root.getPath() + StrUtil.padPre(String.valueOf(nextUnitPathIndex++), 4, '0'));
|
||||
unitMap.put(unit.getId(), unit);
|
||||
insertUnits.add(unit);
|
||||
}
|
||||
if (StrUtil.isBlank(unit.getPath())) {
|
||||
throw new BaseException("人员{}所属机构{}的路径为空", source.getLoginname(), unit.getId());
|
||||
log.warn("人员{}所属机构{}的路径为空,跳过当前人员增量更新", source.getLoginname(), unit.getId());
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
source.setUnitName(unit.getName());
|
||||
source.setUnitPath(unit.getPath());
|
||||
}
|
||||
|
||||
if (!insertUnits.isEmpty()) {
|
||||
dao.fastInsert(insertUnits);
|
||||
root.setHasChildren(true);
|
||||
dao.updateIgnoreNull(root);
|
||||
}
|
||||
|
||||
if (userSources.isEmpty() && insertUnits.isEmpty()) {
|
||||
return "本次没有新增人员或单位。";
|
||||
}
|
||||
|
||||
//加入到系统用户表
|
||||
List<Sys_user> sysUsers = BeanUtil.copyToList(userSources, Sys_user.class);
|
||||
for (Sys_user sysUser : sysUsers) {
|
||||
@@ -143,8 +165,12 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
||||
|
||||
// 6.1 更新提案的校领导角色,发送订阅
|
||||
ProposalConfig config = dao.fetch(ProposalConfig.class, Cnd.where("delFlag", "=", false).desc("updatedAt"));
|
||||
for (String unitId : config.getSchoolLeaderUnitIds()) {
|
||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||
if (config == null || config.getSchoolLeaderUnitIds() == null || config.getSchoolLeaderUnitIds().isEmpty()) {
|
||||
log.warn("未配置提案校领导单位,跳过校领导角色刷新,继续完成人员增量更新");
|
||||
} else {
|
||||
for (String unitId : config.getSchoolLeaderUnitIds()) {
|
||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||
}
|
||||
}
|
||||
|
||||
if (sysUsers.isEmpty() && insertUnits.isEmpty()) {
|
||||
|
||||
@@ -147,21 +147,31 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
for (String sourceUnitId : sourceUnitIds) {
|
||||
Sys_unit unit = unitMap.get(sourceUnitId);
|
||||
if (unit == null) {
|
||||
throw new BaseException("人员单位号{}在机构同步后仍不存在,中止本次同步", sourceUnitId);
|
||||
log.warn("人员单位号{}在机构同步后仍不存在,跳过单位归属处理,保留原单位号入库", sourceUnitId);
|
||||
continue;
|
||||
}
|
||||
Set<String> visited = new HashSet<>();
|
||||
while (!rootId.equals(unit.getId()) && !Integer.valueOf(2).equals(unit.getUnitLevel())) {
|
||||
if (!visited.add(unit.getId())) {
|
||||
throw new BaseException("人员单位{}存在循环父级", sourceUnitId);
|
||||
log.warn("人员单位{}存在循环父级,跳过单位归属处理,保留原单位号入库", sourceUnitId);
|
||||
tertiaryUnitIds.remove(sourceUnitId);
|
||||
unit = null;
|
||||
break;
|
||||
}
|
||||
if (Integer.valueOf(3).equals(unit.getUnitLevel())) {
|
||||
tertiaryUnitIds.put(sourceUnitId, unit.getId());
|
||||
}
|
||||
unit = unitMap.get(unit.getParentId());
|
||||
if (unit == null || rootId.equals(unit.getId())) {
|
||||
throw new BaseException("人员单位{}缺少有效的二级上级机构", sourceUnitId);
|
||||
log.warn("人员单位{}缺少有效的二级上级机构,跳过单位归属处理,保留原单位号入库", sourceUnitId);
|
||||
tertiaryUnitIds.remove(sourceUnitId);
|
||||
unit = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unit == null) {
|
||||
continue;
|
||||
}
|
||||
if (!sourceUnitId.equals(unit.getId())) {
|
||||
tertiaryParentUnitIds.put(sourceUnitId, unit.getId());
|
||||
}
|
||||
@@ -212,17 +222,19 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
}
|
||||
String sourceUnitId = raw.getStr("SZDWDM");
|
||||
if (StrUtil.isBlank(sourceUnitId)) {
|
||||
throw new BaseException("人员{}缺少所属机构编号 SZDWDM", sysUser.getLoginname());
|
||||
log.warn("人员{}缺少所属机构编号 SZDWDM,跳过单位信息补充,保留原数据入库", sysUser.getLoginname());
|
||||
}
|
||||
String parentUnitId = tertiaryParentUnitIds.get(sourceUnitId);
|
||||
sysUser.setUnitId(StrUtil.blankToDefault(parentUnitId, sourceUnitId));
|
||||
sysUser.setThreeUnitId(tertiaryUnitIds.get(sourceUnitId));
|
||||
Sys_unit unit = resolvedUnitMap.get(sysUser.getUnitId());
|
||||
if (unit == null || StrUtil.isBlank(unit.getPath())) {
|
||||
throw new BaseException("人员{}所属机构不存在或路径为空", sysUser.getLoginname());
|
||||
if (unit != null) {
|
||||
sysUser.setUnitName(unit.getName());
|
||||
sysUser.setUnitPath(unit.getPath());
|
||||
if (StrUtil.isBlank(unit.getPath())) {
|
||||
log.warn("人员{}所属单位{}路径为空,保留当前单位信息继续入库", sysUser.getLoginname(), unit.getId());
|
||||
}
|
||||
}
|
||||
sysUser.setUnitName(unit.getName());
|
||||
sysUser.setUnitPath(unit.getPath());
|
||||
|
||||
// 设置拉取时间
|
||||
sysUser.setPullTime(nowDate);
|
||||
|
||||
@@ -27,8 +27,10 @@ import java.util.Map;
|
||||
public class DataCenterUtil {
|
||||
|
||||
public static Sys_unit findRootUnit(List<Sys_unit> units) {
|
||||
boolean hasZeroUnit = units.stream().anyMatch(unit -> "0".equals(unit.getId()));
|
||||
List<Sys_unit> roots = units.stream().filter(unit ->
|
||||
StrUtil.isBlank(unit.getParentId())
|
||||
|| ("0".equals(unit.getParentId()) && !hasZeroUnit)
|
||||
|| (unit.getId().equals(unit.getParentId())
|
||||
&& (unit.getUnitLevel() == null || unit.getUnitLevel() <= 1))).toList();
|
||||
if (roots.size() != 1) {
|
||||
|
||||
@@ -48,8 +48,8 @@ layout("/layouts/platform.html"){
|
||||
<el-card shadow="never">
|
||||
<table-tool label="系统当前用户数据">
|
||||
<!--<el-button type="primary" size="mini" @click="updateDataDict" icon="el-icon-refresh">更新【码表】数据</el-button>-->
|
||||
<el-button type="primary" size="mini" @click="updateUnits" icon="el-icon-refresh">更新【单位】数据</el-button>
|
||||
<el-button type="primary" size="mini" @click="openUpdate" icon="el-icon-refresh">更新【人员】数据</el-button>
|
||||
<el-button type="primary" size="mini" @click="updateUnits" icon="el-icon-refresh" :loading="unitUpdateLoading" :disabled="unitUpdateLoading || updateLoading">更新【单位】数据</el-button>
|
||||
<el-button type="primary" size="mini" @click="openUpdate" icon="el-icon-refresh" :loading="updateLoading" :disabled="unitUpdateLoading || updateLoading">更新【人员】数据</el-button>
|
||||
</table-tool>
|
||||
<el-table :key="tableKey" :data="tableData" @sort-change="pageOrder" header-align="center">
|
||||
<el-table-column type="index" width="70" label="序号" fixed="left"></el-table-column>
|
||||
@@ -147,6 +147,7 @@ layout("/layouts/platform.html"){
|
||||
}
|
||||
},
|
||||
updateLoading: false,
|
||||
unitUpdateLoading: false,
|
||||
unitOptions: [],
|
||||
changeTypeData: [],
|
||||
enableAdvancedConditions: false,
|
||||
@@ -174,12 +175,22 @@ layout("/layouts/platform.html"){
|
||||
methods: {
|
||||
// 更新单位数据
|
||||
updateUnits() {
|
||||
if (this.unitUpdateLoading || this.updateLoading) return
|
||||
this.$confirm("确定要更新单位数据吗?", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(() => {
|
||||
this.$axios.post("/platform/sys/data/user/update/updateUnits")
|
||||
if (this.unitUpdateLoading || this.updateLoading) return
|
||||
this.$set(this, "unitUpdateLoading", true)
|
||||
const loading = this.$loading({
|
||||
fullscreen: true,
|
||||
lock: true,
|
||||
text: "正在更新单位数据,请稍候",
|
||||
spinner: "el-icon-loading",
|
||||
background: "rgba(0, 0, 0, 0.5)"
|
||||
})
|
||||
return this.$axios.post("/platform/sys/data/user/update/updateUnits")
|
||||
.then((resp) => {
|
||||
if (resp.code === 0) {
|
||||
this.$message.success("更新成功")
|
||||
@@ -187,7 +198,11 @@ layout("/layouts/platform.html"){
|
||||
this.$message.error(resp.msg)
|
||||
}
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
loading.close()
|
||||
this.$set(this, "unitUpdateLoading", false)
|
||||
})
|
||||
}).catch(() => {})
|
||||
|
||||
},
|
||||
// 更新码表数据
|
||||
@@ -226,6 +241,7 @@ layout("/layouts/platform.html"){
|
||||
return null
|
||||
},
|
||||
openUpdate() {
|
||||
if (this.unitUpdateLoading || this.updateLoading) return
|
||||
this.updateDialog = true
|
||||
this.updateLoading = false
|
||||
this.$nextTick(() => {
|
||||
@@ -250,7 +266,7 @@ layout("/layouts/platform.html"){
|
||||
},
|
||||
execUpdate() {
|
||||
// 人员更新未结束时不再打开确认框或提交重复请求。
|
||||
if (this.updateLoading) return
|
||||
if (this.unitUpdateLoading || this.updateLoading) return
|
||||
if (!this.updateFromData.pullTime) {
|
||||
this.$message.warning("请选择数据源时间")
|
||||
return
|
||||
@@ -271,7 +287,7 @@ layout("/layouts/platform.html"){
|
||||
type: "warning"
|
||||
})
|
||||
.then(() => {
|
||||
if (this.updateLoading) return
|
||||
if (this.unitUpdateLoading || this.updateLoading) return
|
||||
this.$set(this, "updateLoading", true)
|
||||
// 遮罩覆盖人员更新弹窗及页面,明确提示处理中并阻止重复操作。
|
||||
const loading = this.$loading({
|
||||
|
||||
Reference in New Issue
Block a user