Commit d0e6fe5e authored by yangyang's avatar yangyang

refactor(amos-boot-module-tcm): 添加空列表判断

- 使用 try-catch包裹可能抛出异常的代码,提高稳定性 - 优化日志输出,记录成功和失败的情况
parent 8693f8c0
......@@ -2402,46 +2402,53 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
List<RegUnitInfo> regUnitInfos = regUnitInfoService.lambdaQuery().in(RegUnitInfo::getAdminUserId, adminUserIdList).list();
List<String> useUnitCodes = regUnitInfos.stream().map(RegUnitInfo::getUnitCode).collect(Collectors.toList());
if (ValidationUtil.isEmpty(useUnitCodes)) {
return;
}
List<TzBaseEnterpriseInfo> enterpriseInfos = baseEnterpriseInfoService.lambdaQuery().in(TzBaseEnterpriseInfo::getUseUnitCode, useUnitCodes).list();
Map<String, TzBaseEnterpriseInfo> enterpriseInfoMap = enterpriseInfos.stream().collect(Collectors.toMap(TzBaseEnterpriseInfo::getUseUnitCode, x -> x, (oldValue, newValue) -> newValue));
for (RegUnitInfo regUnitInfo : regUnitInfos) {
String useCode = regUnitInfo.getUnitCode();
CompanyModel companyInfo = Privilege.companyClient.queryByCompanyCode(useCode).getResult();
Set<String> appCodesSet = new HashSet<>();
Map<Long, List<Long>> roleSeqMap = new HashMap<>();
Map<Long, List<RoleModel>> orgRoles = new HashMap<>();
List<RoleModel> userRoleList = new ArrayList<>();
List<Long> roleIds = new ArrayList<>();
FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null);
List<RoleModel> roleModels = roleListResult.getResult();
List<DataDictionary> unitTypeList = regUnitInfoService.setAndGetUnitTypeList();
TzBaseEnterpriseInfo baseEnterpriseInfo = enterpriseInfoMap.get(regUnitInfo.getUnitCode());
String[] unitTypes = baseEnterpriseInfo.getUnitType().split("#");
FeignClientResult<AgencyUserModel> userResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId());
AgencyUserModel agencyUserModel = userResult.getResult();
Map<String, DataDictionary> dataDictionaryMap = unitTypeList.stream().collect(Collectors.toMap(DataDictionary::getName, Function.identity(), (k1, k2) -> k1));
for (String type : unitTypes) {
DataDictionary unitType = dataDictionaryMap.get(type);
String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : "";
String[] appCodes = appCode.split(",");
Collections.addAll(appCodesSet, appCodes);
userRoleList.addAll(roleModels.stream()
.filter(r -> unitType.getExtend().contains(r.getSequenceNbr().toString())).collect(Collectors.toList()));
userRoleList.forEach(r -> {
if (!roleIds.contains(r.getSequenceNbr())) {
roleIds.add(r.getSequenceNbr());
}
});
roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds);
orgRoles.put(companyInfo.getSequenceNbr(), userRoleList);
}
try {
CompanyModel companyInfo = Privilege.companyClient.queryByCompanyCode(useCode).getResult();
Set<String> appCodesSet = new HashSet<>();
Map<Long, List<Long>> roleSeqMap = new HashMap<>();
Map<Long, List<RoleModel>> orgRoles = new HashMap<>();
List<RoleModel> userRoleList = new ArrayList<>();
List<Long> roleIds = new ArrayList<>();
FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null);
List<RoleModel> roleModels = roleListResult.getResult();
List<DataDictionary> unitTypeList = regUnitInfoService.setAndGetUnitTypeList();
TzBaseEnterpriseInfo baseEnterpriseInfo = enterpriseInfoMap.get(regUnitInfo.getUnitCode());
String[] unitTypes = baseEnterpriseInfo.getUnitType().split("#");
FeignClientResult<AgencyUserModel> userResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId());
AgencyUserModel agencyUserModel = userResult.getResult();
Map<String, DataDictionary> dataDictionaryMap = unitTypeList.stream().collect(Collectors.toMap(DataDictionary::getName, Function.identity(), (k1, k2) -> k1));
for (String type : unitTypes) {
DataDictionary unitType = dataDictionaryMap.get(type);
String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : "";
String[] appCodes = appCode.split(",");
Collections.addAll(appCodesSet, appCodes);
userRoleList.addAll(roleModels.stream()
.filter(r -> unitType.getExtend().contains(r.getSequenceNbr().toString())).collect(Collectors.toList()));
userRoleList.forEach(r -> {
if (!roleIds.contains(r.getSequenceNbr())) {
roleIds.add(r.getSequenceNbr());
}
});
roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds);
orgRoles.put(companyInfo.getSequenceNbr(), userRoleList);
}
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
agencyUserModel.setOrgRoles(orgRoles);
agencyUserModel.setOrgRoleSeqs(roleSeqMap);
userResult = Privilege.agencyUserClient.update(agencyUserModel, regUnitInfo.getAdminUserId());
System.out.println(userResult);
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
agencyUserModel.setOrgRoles(orgRoles);
agencyUserModel.setOrgRoleSeqs(roleSeqMap);
Privilege.agencyUserClient.update(agencyUserModel, regUnitInfo.getAdminUserId());
log.info("更新企业管理员:{} 成功", useCode);
} catch (Exception e) {
log.warn("更新企业管理员:{} 失败, 错误原因: {}", useCode, e.getMessage());
}
}
}
......@@ -2469,21 +2476,25 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
Map<String, RegUnitInfo> regUnitInfoMap = regUnitInfos.stream().collect(Collectors.toMap(RegUnitInfo::getUnitCode, x -> x, (oldValue, newValue) -> newValue));
for (TzsUserInfo userInfo : userInfos) {
// 更新人员信息同步平台
TzsUserInfoDto tzsUserInfoDto = new TzsUserInfoDto();
Bean.toModel(userInfo, tzsUserInfoDto);
RegUnitInfo regUnitInfo = regUnitInfoMap.get(tzsUserInfoDto.getUnitCode());
if (regUnitInfo == null || StringUtils.isEmpty(regUnitInfo.getAdminUserId())) {
continue;
}
AgencyUserModel adminUserModel = userModelMap.get(regUnitInfo.getAdminUserId());
if (adminUserModel == null) {
continue;
try {
// 更新人员信息同步平台
TzsUserInfoDto tzsUserInfoDto = new TzsUserInfoDto();
Bean.toModel(userInfo, tzsUserInfoDto);
RegUnitInfo regUnitInfo = regUnitInfoMap.get(tzsUserInfoDto.getUnitCode());
if (regUnitInfo == null || StringUtils.isEmpty(regUnitInfo.getAdminUserId())) {
continue;
}
AgencyUserModel adminUserModel = userModelMap.get(regUnitInfo.getAdminUserId());
if (adminUserModel == null) {
continue;
}
Long companySeq = Long.valueOf(regUnitInfo.getAmosCompanySeq());
List<String> appCodesSet = adminUserModel.getAppCodes();
// 根据post同步平台的用户组
syncNewPost(tzsUserInfoDto, companySeq, appCodesSet);
} catch (Exception e) {
log.warn("更新企业管理员:{} 失败, 错误原因: {}", userInfo, e.getMessage());
}
Long companySeq = Long.valueOf(regUnitInfo.getAmosCompanySeq());
List<String> appCodesSet = adminUserModel.getAppCodes();
// 根据post同步平台的用户组
syncNewPost(tzsUserInfoDto, companySeq, appCodesSet);
}
}
}
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