Commit e0da842f authored by yangyang's avatar yangyang

fix(编辑企业信息): 新增手动刷新用户组的接口

parent ca21bc75
...@@ -495,4 +495,12 @@ public class TzsUserInfoController extends BaseController { ...@@ -495,4 +495,12 @@ public class TzsUserInfoController extends BaseController {
public ResponseModel<String> deletePersonSubtypeHistoricalData() { public ResponseModel<String> deletePersonSubtypeHistoricalData() {
return ResponseHelper.buildResponse(tzsUserInfoService.deletePersonSubtypeHistoricalData()); return ResponseHelper.buildResponse(tzsUserInfoService.deletePersonSubtypeHistoricalData());
} }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/refreshUserGroupInfo")
@ApiOperation(httpMethod = "POST", value = "同步人员信息", notes = "同步人员信息")
public ResponseModel<TzsUserInfoDto> refreshUserInfo(@RequestBody List<String> userIds) {
tzsUserInfoServiceImpl.refreshUserGroupInfo(userIds);
return ResponseHelper.buildResponse(null);
}
} }
...@@ -1079,6 +1079,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1079,6 +1079,7 @@ public class TzBaseEnterpriseInfoServiceImpl
@Override @Override
public TzBaseEnterpriseInfoDto updateCompanyInfoById(Map<String, Object> map, ReginParams reginParams) { public TzBaseEnterpriseInfoDto updateCompanyInfoById(Map<String, Object> map, ReginParams reginParams) {
log.info("根据ID修改企业信息 => {}, 更新人 => {}", map, RequestContext.getExeUserId()); log.info("根据ID修改企业信息 => {}, 更新人 => {}", map, RequestContext.getExeUserId());
RegUnitInfo olrRegUnitInfo = new RegUnitInfo();
try { try {
TzBaseEnterpriseInfo tzBaseEnterpriseInfo = new TzBaseEnterpriseInfo(); TzBaseEnterpriseInfo tzBaseEnterpriseInfo = new TzBaseEnterpriseInfo();
tzBaseEnterpriseInfo.setSequenceNbr(Long.valueOf(map.get("sequenceNbr").toString())); tzBaseEnterpriseInfo.setSequenceNbr(Long.valueOf(map.get("sequenceNbr").toString()));
...@@ -1137,6 +1138,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1137,6 +1138,7 @@ public class TzBaseEnterpriseInfoServiceImpl
if (ValidationUtil.isEmpty(regUnitInfo)) { if (ValidationUtil.isEmpty(regUnitInfo)) {
throw new BadRequest("未找到单位注册信息"); throw new BadRequest("未找到单位注册信息");
} }
BeanUtils.copyProperties(regUnitInfo, olrRegUnitInfo);
FeignClientResult<AgencyUserModel> userResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId()); FeignClientResult<AgencyUserModel> userResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId());
AgencyUserModel agencyUserModel = Optional.ofNullable(userResult).map(FeignClientResult::getResult).orElse(null); AgencyUserModel agencyUserModel = Optional.ofNullable(userResult).map(FeignClientResult::getResult).orElse(null);
if (ValidationUtil.isEmpty(agencyUserModel)) { if (ValidationUtil.isEmpty(agencyUserModel)) {
...@@ -1155,9 +1157,9 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1155,9 +1157,9 @@ public class TzBaseEnterpriseInfoServiceImpl
handleUnitType(map, regUnitInfo, agencyUserModel); handleUnitType(map, regUnitInfo, agencyUserModel);
String[] unitTypes = regUnitInfo.getUnitType().split(","); String[] unitTypes = regUnitInfo.getUnitType().split(",");
regUnitInfoService.saveOrUpdate(regUnitInfo);
// -- 20250627 调整为监管单位不能修改工商信息和资质
// -- 20250627 调整为监管单位不能修改工商信息和资质
regUnitInfoService.updateBySeq(regUnitInfo);
// 企业信息变更-同步修改企业下人员绑定设备类型 // 企业信息变更-同步修改企业下人员绑定设备类型
ArrayList<String> newData = new ArrayList<>(); ArrayList<String> newData = new ArrayList<>();
JSONArray objects = JSON.parseArray(tzBaseEnterpriseInfo.getEquipCategory()); JSONArray objects = JSON.parseArray(tzBaseEnterpriseInfo.getEquipCategory());
...@@ -1192,6 +1194,9 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1192,6 +1194,9 @@ public class TzBaseEnterpriseInfoServiceImpl
return null; return null;
} }
} catch (Exception e) { } catch (Exception e) {
if (!ValidationUtil.isEmpty(olrRegUnitInfo)) {
regUnitInfoService.updateBySeq(olrRegUnitInfo);
}
log.error("更新企业信息失败: ", e); log.error("更新企业信息失败: ", e);
throw new BadRequest("更新企业信息失败!"); throw new BadRequest("更新企业信息失败!");
} }
......
...@@ -45,6 +45,7 @@ import com.yeejoin.amos.boot.module.tcm.api.service.ITzsUserInfoService; ...@@ -45,6 +45,7 @@ import com.yeejoin.amos.boot.module.tcm.api.service.ITzsUserInfoService;
import com.yeejoin.amos.boot.module.tcm.api.vo.SortVo; import com.yeejoin.amos.boot.module.tcm.api.vo.SortVo;
import com.yeejoin.amos.boot.module.tcm.api.vo.TzsUserInfoVo; import com.yeejoin.amos.boot.module.tcm.api.vo.TzsUserInfoVo;
import com.yeejoin.amos.boot.module.tcm.api.vo.UserInfoVo; import com.yeejoin.amos.boot.module.tcm.api.vo.UserInfoVo;
import com.yeejoin.amos.boot.module.tcm.flc.api.entity.RegUnitInfo;
import com.yeejoin.amos.boot.module.tcm.flc.biz.service.impl.RegUnitInfoServiceImpl; import com.yeejoin.amos.boot.module.tcm.flc.biz.service.impl.RegUnitInfoServiceImpl;
import com.yeejoin.amos.component.feign.config.InnerInvokException; import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
...@@ -71,6 +72,7 @@ import org.springframework.util.ObjectUtils; ...@@ -71,6 +72,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
...@@ -2301,6 +2303,16 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -2301,6 +2303,16 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
} }
private void syncNewPost(TzsUserInfoDto tzsUserInfoDto) { private void syncNewPost(TzsUserInfoDto tzsUserInfoDto) {
ReginParams reginParams = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
if (ObjectUtils.isEmpty(reginParams)) {
return ;
}
Long companySeq = reginParams.getCompany().getSequenceNbr();
List<String> appCodesSet = reginParams.getUserModel().getAppCodes();
syncNewPost(tzsUserInfoDto, companySeq, appCodesSet);
}
private void syncNewPost(TzsUserInfoDto tzsUserInfoDto, Long companySeq, List<String> appCodesSet) {
System.out.println(tzsUserInfoDto); System.out.println(tzsUserInfoDto);
// tzs_user_info; // tzs_user_info;
if (ValidationUtil.isEmpty(tzsUserInfoDto.getAmosUserId())) { if (ValidationUtil.isEmpty(tzsUserInfoDto.getAmosUserId())) {
...@@ -2310,13 +2322,10 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -2310,13 +2322,10 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
if (userFeignClientResult == null || userFeignClientResult.getResult() == null) { if (userFeignClientResult == null || userFeignClientResult.getResult() == null) {
return; return;
} }
ReginParams reginParams = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
if (ObjectUtils.isEmpty(reginParams)) {
return ;
}
List<DataDictionary> dataDictionaries = iDataDictionaryService.lambdaQuery() List<DataDictionary> dataDictionaries = iDataDictionaryService.lambdaQuery()
.in(DataDictionary::getType, Arrays.asList("QYRYJS", "QYRYYHZ")) .in(DataDictionary::getType, Arrays.asList("QYRYJS", "QYRYYHZ"))
.eq(DataDictionary::getIsDelete, false).list(); .eq(DataDictionary::getIsDelete, false).list();
List<DataDictionary> qyrygwList = dataDictionaries.stream().filter(item -> "QYRYJS".equals(item.getType())).collect(Collectors.toList()); List<DataDictionary> qyrygwList = dataDictionaries.stream().filter(item -> "QYRYJS".equals(item.getType())).collect(Collectors.toList());
List<DataDictionary> qyryyhzList = dataDictionaries.stream().filter(item -> "QYRYYHZ".equals(item.getType())).collect(Collectors.toList()); List<DataDictionary> qyryyhzList = dataDictionaries.stream().filter(item -> "QYRYYHZ".equals(item.getType())).collect(Collectors.toList());
...@@ -2324,8 +2333,6 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -2324,8 +2333,6 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
String roles = qyrygwList.get(0).getCode(); String roles = qyrygwList.get(0).getCode();
String roleGroupCode = qyryyhzList.get(0).getCode(); String roleGroupCode = qyryyhzList.get(0).getCode();
Long companySeq = reginParams.getCompany().getSequenceNbr();
List<String> appCodesSet = reginParams.getUserModel().getAppCodes();
List<RoleModel> allRoleList = new ArrayList<>(); List<RoleModel> allRoleList = new ArrayList<>();
List<Long> roleIds = new ArrayList<>(); List<Long> roleIds = new ArrayList<>();
DataDictionary unitType = iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getCode, roles).eq(DataDictionary::getType, USER_ROLE)); DataDictionary unitType = iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getCode, roles).eq(DataDictionary::getType, USER_ROLE));
...@@ -2378,4 +2385,103 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -2378,4 +2385,103 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
} }
} }
} }
public void refreshAdminUserRole(List<TzsUserInfo> userInfos, List<String> userId) {
List<String> adminUserIdList;
if (ValidationUtil.isEmpty(userInfos)) {
adminUserIdList = userId;
} else {
List<String> amosUserIdList = userInfos.stream().map(TzsUserInfo::getAmosUserId).collect(Collectors.toList());
adminUserIdList = userId.stream().filter(id -> !amosUserIdList.contains(id)).collect(Collectors.toList());
}
if (ValidationUtil.isEmpty(adminUserIdList)) {
return;
}
List<RegUnitInfo> regUnitInfos = regUnitInfoService.lambdaQuery().in(RegUnitInfo::getAdminUserId, adminUserIdList).list();
List<String> useUnitCodes = regUnitInfos.stream().map(RegUnitInfo::getUnitCode).collect(Collectors.toList());
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);
}
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
agencyUserModel.setOrgRoles(orgRoles);
agencyUserModel.setOrgRoleSeqs(roleSeqMap);
userResult = Privilege.agencyUserClient.update(agencyUserModel, regUnitInfo.getAdminUserId());
System.out.println(userResult);
}
}
public void refreshUserGroupInfo(List<String> userId) {
if (ObjectUtils.isEmpty(userId)) {
return;
}
// 根据userId获取用户
List<TzsUserInfo> userInfos = tzsUserInfoMapper.selectList(new LambdaQueryWrapper<TzsUserInfo>()
.in(TzsUserInfo::getAmosUserId, userId));
refreshAdminUserRole(userInfos, userId);
if (ObjectUtils.isEmpty(userInfos)) {
return;
}
List<String> unitCodes = userInfos.stream().map(TzsUserInfo::getUnitCode).collect(Collectors.toList());
List<RegUnitInfo> regUnitInfos = regUnitInfoService.lambdaQuery().in(RegUnitInfo::getUnitCode, unitCodes).list();
String adminUserIds = regUnitInfos.stream().map(RegUnitInfo::getAdminUserId).filter(Objects::nonNull).collect(Collectors.joining(","));
List<AgencyUserModel> userList = Privilege.agencyUserClient.queryByIds(adminUserIds, true).getResult();
Map<String, AgencyUserModel> userModelMap = userList.stream().collect(Collectors.toMap(AgencyUserModel::getUserId, x -> x, (oldValue, newValue) -> newValue));
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;
}
Long companySeq = Long.valueOf(regUnitInfo.getAmosCompanySeq());
List<String> appCodesSet = adminUserModel.getAppCodes();
// 根据post同步平台的用户组
syncNewPost(tzsUserInfoDto, companySeq, appCodesSet);
}
}
} }
...@@ -62,6 +62,7 @@ import org.springframework.mock.web.MockMultipartFile; ...@@ -62,6 +62,7 @@ import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -1152,4 +1153,9 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -1152,4 +1153,9 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
} }
return regUnitInfoDto; return regUnitInfoDto;
} }
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public void updateBySeq(RegUnitInfo regUnitInfo) {
this.updateById(regUnitInfo);
}
} }
\ No newline at end of file
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