Commit 26a9063d authored by yangyang's avatar yangyang

feat(tcm): 更新企业注册逻辑

- 修改了企业类型判断逻辑,改为全部企业类型生成对接数据账号 - 添加了同步平台ORG_CODE的方法 - 优化了代码结构,提高了可读性和可维护性
parent c935701d
package com.yeejoin.amos.boot.module.tcm.biz.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
public class ExecuteThreadPoolConfig {
private static final Integer CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors() + 1;
private static final Integer MAX_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 2 + 1;
private static final Integer TASK_QUEUE_CAPACITY = Runtime.getRuntime().availableProcessors();
private static final Integer TASK_KEEP_ALIVE_TIME = 60 * 3;
@Bean(name = "tcmTaskExecutor")
public ThreadPoolTaskExecutor executeThreadPoolConfig() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(CORE_POOL_SIZE);
executor.setMaxPoolSize(MAX_POOL_SIZE);
executor.setQueueCapacity(TASK_QUEUE_CAPACITY);
executor.setThreadNamePrefix("tcmTaskExecutor-");
// 设置线程保持活跃的时间(默认:60 * 3)
executor.setKeepAliveSeconds(TASK_KEEP_ALIVE_TIME);
// 设置任务拒绝策略 通过主线程知行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
}
......@@ -15,6 +15,7 @@ import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RequestContextWrapper;
import com.yeejoin.amos.boot.module.common.api.dto.UserPermissionDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.BaseUnitLicenceDto;
import com.yeejoin.amos.boot.module.tcm.api.dto.EquEnterDto;
......@@ -52,6 +53,8 @@ import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
......@@ -63,6 +66,7 @@ import org.typroject.tyboot.core.restful.exception.instance.TooManyRequests;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -124,6 +128,10 @@ public class TzBaseEnterpriseInfoServiceImpl
private static final Map<String ,String> JYJC_CERT_MAP = new HashMap<>();
@Autowired
@Qualifier("tcmTaskExecutor")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
/**
* 公司类型下的资质类型map:key为登录人的公司类型、value为包含的资质枚举
*/
......@@ -1175,22 +1183,10 @@ public class TzBaseEnterpriseInfoServiceImpl
boolean b = tzBaseEnterpriseInfoService.updateById(tzBaseEnterpriseInfo);
if (b) {
CompanyModel updateModel;
try {
updateModel = Privilege.companyClient.queryByCompanyCode(String.valueOf(map.get("useCode"))).getResult();
HashMap<String, Object> parentMessage = (HashMap<String, Object>) Privilege.companyClient.queryByOrgcode(String.valueOf(map.get("superviseOrgCode"))).getResult();
// 目前平台返回key为compnay(存在拼写错误)
CompanyModel parentModel = JSON.parseObject(JSON.toJSONString(parentMessage.get("compnay")), CompanyModel.class);
updateModel.setParentId(parentModel.getSequenceNbr());
updateModel.setCompanyType(regUnitInfo.getUnitType());// 更新单位类型
Privilege.companyClient.update(updateModel, updateModel.getSequenceNbr());
} catch (Exception e) {
throw new BadRequest("操作失败!");
}
updateUnit(map, regUnitInfo, agencyUserModel, updateModel);
CompanyModel updateModel = updateCompany(map, regUnitInfo, agencyUserModel);
updateUnit(map, regUnitInfo, agencyUserModel, updateModel);// slow
updateUserInfo(newData, String.valueOf(map.get("useCode")));
asyncPlatformCompany(map, agencyUserModel);
asyncPlatformCompany(map, agencyUserModel);// slow
redisUtil.del(RedisKey.buildReginRoleKey(agencyUserModel.getUserId()));
TzBaseEnterpriseInfoDto tzBaseEnterpriseInfoDto = new TzBaseEnterpriseInfoDto();
BeanUtils.copyProperties(tzBaseEnterpriseInfo, tzBaseEnterpriseInfoDto);
......@@ -1206,6 +1202,27 @@ public class TzBaseEnterpriseInfoServiceImpl
return userInfoService.personalInfoUpdateById((Map<String, Object>) map.get("raw"));
}
private CompanyModel updateCompany(Map<String, Object> map, RegUnitInfo regUnitInfo, AgencyUserModel agencyUserModel) {
CompanyModel updateModel;
try {
updateModel = Privilege.companyClient.queryByCompanyCode(String.valueOf(map.get("useCode"))).getResult();
HashMap<String, Object> parentMessage = (HashMap<String, Object>) Privilege.companyClient.queryByOrgcode(String.valueOf(map.get("superviseOrgCode"))).getResult();
// 目前平台返回key为compnay(存在拼写错误)
CompanyModel parentModel = JSON.parseObject(JSON.toJSONString(parentMessage.get("compnay")), CompanyModel.class);
updateModel.setParentId(parentModel.getSequenceNbr());
updateModel.setCompanyType(regUnitInfo.getUnitType());// 更新单位类型
FeignClientResult<CompanyModel> companyResult = Privilege.companyClient.update(updateModel, updateModel.getSequenceNbr());
log.info("更新单位类型结果:{}", companyResult);
if (companyResult == null || companyResult.getStatus() != 200) {
throw new BadRequest("更新单位类型失败!");
}
return updateModel;
} catch (Exception e) {
throw new BadRequest("更新单位类型失败!");
}
}
private void handleUnitType(Map<String, Object> map, RegUnitInfo regUnitInfo, AgencyUserModel agencyUserModel) {
Object unitTypeCodesObj = map.get("unitTypeCodes");
if (!(unitTypeCodesObj instanceof List<?>)) {
......@@ -1312,8 +1329,37 @@ public class TzBaseEnterpriseInfoServiceImpl
}
private void asyncPlatformCompany(Map<String, Object> map, AgencyUserModel agencyUserModel) {
String useCode = String.valueOf(map.get("useCode"));
// 同步平台ORG_CODE
System.out.println(map);
// Privilege.companyClient.update();
LambdaQueryWrapper<TzsUserInfo> lambda = new QueryWrapper<TzsUserInfo>().lambda();
lambda.eq(TzsUserInfo::getUnitCode, useCode);
lambda.isNotNull(TzsUserInfo::getAmosUserId);
List<TzsUserInfo> tzsUserInfos = tzsUserInfoMapper.selectList(lambda);
if (!ValidationUtil.isEmpty(tzsUserInfos)) {
String userIds = tzsUserInfos.stream().map(TzsUserInfo::getAmosUserId).collect(Collectors.joining(","));
FeignClientResult<List<AgencyUserModel>> agencyUserClientResult = Privilege.agencyUserClient.queryByIds(userIds, false);
List<AgencyUserModel> agencyUserModels = agencyUserClientResult.getResult();
for (AgencyUserModel userModel : agencyUserModels) {
FeignClientResult<AgencyUserModel> userResult = Privilege.agencyUserClient.update(userModel, userModel.getUserId());
System.out.println(userResult);
}
}
// 异步刷新历史数据
String token = RequestContext.getToken();
String appKey = RequestContext.getAppKey();
String product = RequestContext.getProduct();
threadPoolTaskExecutor.execute(() -> {
RequestContext.setToken(token);
RequestContext.setAppKey(appKey);
RequestContext.setProduct(product);
// todo 调用刷新历史数据接口
try {
} finally {
RequestContext.clean();
}
});
}
}
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