Commit 6eb94bc0 authored by yangyang's avatar yangyang

feat(tcm): 实现平台编辑单位信息后的数据同步

- 在 TzBaseEnterpriseInfo 模型中添加 orgCode 字段 - 新增 TzBaseEnterpriseInfoMapper 接口中的 updateSubCompanyOrgCode 方法 - 在 ITzBaseEnterpriseInfoService 接口中添加 refreshCompanyInfo 方法 - 实现 TzBaseEnterpriseInfoServiceImpl 中的 refreshCompanyInfo 方法 - 在 PlatformUserTopicMessage 中调用 refreshCompanyInfo 方法处理公司信息更新
parent 9cba217c
......@@ -208,4 +208,9 @@ public class TzBaseEnterpriseInfo extends BaseEntity {
*/
@TableField(value = "create_date")
protected Date createDate;
/**
* 组织机构
*/
@TableField(value = "org_code")
protected String orgCode;
}
......@@ -8,6 +8,7 @@ import com.yeejoin.amos.boot.module.tcm.api.dto.TzBaseEnterpriseInfoDto;
import com.yeejoin.amos.boot.module.tcm.api.entity.TzBaseEnterpriseInfo;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.util.Map;
......@@ -60,4 +61,9 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI
List<Map<String, Object>> getEquipType(@Param("type")String type);
Map<String, Object> getProblemInfoBySourceId(@Param("sourceId")String sourceId);
@Update ("update tz_base_enterprise_info set SUPERVISE_ORG_CODE = REPLACE(SUPERVISE_ORG_CODE, #{oldSuperviseOrgCode}, #{preSuperviseOrgCode}), ORG_CODE = REPLACE(ORG_CODE, #{oldOrgCode}, #{preOrgCode}) where ORG_CODE LIKE concat(#{oldOrgCode}, '%')")
void updateSubCompanyOrgCode(@Param("oldSuperviseOrgCode") String oldSuperviseOrgCode, @Param("preSuperviseOrgCode") String preSuperviseOrgCode,
@Param("oldOrgCode") String oldOrgCode, @Param("preOrgCode") String preOrgCode);
}
package com.yeejoin.amos.boot.module.tcm.api.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
......@@ -59,4 +60,6 @@ public interface ITzBaseEnterpriseInfoService extends IService<TzBaseEnterpriseI
TzIndividualityDto personalInfoUpdateById(Map<String, Object> map);
void refreshCompanyInfo(JSONObject dataResult);
}
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tcm.api.service.IEquipmentCategoryService;
import com.yeejoin.amos.boot.module.tcm.api.service.ITzBaseEnterpriseInfoService;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.StartPlatformTokenService;
import com.yeejoin.amos.boot.module.tcm.flc.api.service.IRegUnitInfoService;
import lombok.extern.slf4j.Slf4j;
......@@ -47,6 +48,9 @@ public class PlatformUserTopicMessage extends EmqxListener {
@Autowired
StartPlatformTokenService platformTokenService;
@Autowired
ITzBaseEnterpriseInfoService tzBaseEnterpriseInfoService;
@Override
public void processMessage(String topic, MqttMessage message) {
platformTokenService.setRequestContext();
......@@ -60,7 +64,8 @@ public class PlatformUserTopicMessage extends EmqxListener {
}
try {
if (StringUtils.isNotEmpty(path)) {
if (path.contains("company") && !"company".equals(dataResult.get("level"))) {
if (path.contains("company")) {
tzBaseEnterpriseInfoService.refreshCompanyInfo(dataResult);
// equipmentCategoryService.creatTree();
} else if (path.contains("agencyuser")) {
regUnitInfoService.updateAdminInfo(dataResult);
......
......@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
......@@ -229,8 +230,12 @@ public class TzBaseEnterpriseInfoServiceImpl
List<String> certTypeList = Arrays.asList(Optional.ofNullable(COMPANY_TYPE_CERT_TYPE_MAP.get(companyType))
.orElse("")
.split(","));
// 充装、检验检测、制造、设计、安改维
unitLicencesCollect = unitLicencesCollect.stream()
.filter(unit -> unit.getCertTypeCode() != null && certTypeList.contains(unit.getCertTypeCode()))
.filter(unit -> unit.getCertTypeCode() != null && (certTypeList.contains(unit.getCertTypeCode())
|| "1235".equals(unit.getCertTypeCode())
|| "1236".equals(unit.getCertTypeCode()))
)
.collect(Collectors.toList());
}
if (!ValidationUtil.isEmpty(unitLicencesCollect)) {
......@@ -1179,7 +1184,6 @@ public class TzBaseEnterpriseInfoServiceImpl
updateUserInfo(newData, useCode);
// 同步平台并且刷新历史数据
asyncPlatformAndRefreshHistoricalData(useCode);
TzBaseEnterpriseInfoDto tzBaseEnterpriseInfoDto = new TzBaseEnterpriseInfoDto();
BeanUtils.copyProperties(tzBaseEnterpriseInfo, tzBaseEnterpriseInfoDto);
// 更新完成后清理缓存
......@@ -1327,7 +1331,7 @@ public class TzBaseEnterpriseInfoServiceImpl
* @author yangyang
* @date 2025/7/1 14:50
*/
private void asyncPlatformAndRefreshHistoricalData(String useCode) {
public void asyncPlatformAndRefreshHistoricalData(String useCode) {
// 同步平台ORG_CODE
LambdaQueryWrapper<TzsUserInfo> lambda = new QueryWrapper<TzsUserInfo>().lambda();
lambda.eq(TzsUserInfo::getUnitCode, useCode);
......@@ -1360,13 +1364,53 @@ public class TzBaseEnterpriseInfoServiceImpl
}
}
}
// todo 调用刷新历史数据接口
} catch (Exception e) {
log.error("异步刷新企业用户信息发生异常", e);
} finally {
RequestContext.clean();
}
});
}
/**
* 平台编辑单位信息后, 异步通知, 刷新tz_base_enterprise_info表org_code
*
*
* @param dataResult dataResult
* @author yangyang
* @date 2025/7/3 14:03
*/
@Override
public void refreshCompanyInfo(JSONObject dataResult) {
try {
CompanyBo companyBo = JSON.parseObject(dataResult.toJSONString(), CompanyBo.class);
// 调用平台获取子单位
FeignClientResult<List<CompanyModel>> result = Privilege.companyClient.queryListByOrgCode(companyBo.getOrgCode());
if (result == null || result.getResult() == null) {
log.error("平台获取子单位失败");
return;
}
List<CompanyModel> companyModels = result.getResult();
List<String> useCodes = companyModels.stream().map(CompanyModel::getCompanyCode).filter(Objects::nonNull).collect(Collectors.toList());
if (!ValidationUtil.isEmpty(companyBo.getCompanyCode())) {
useCodes.add(companyBo.getCompanyCode());
}
List<TzBaseEnterpriseInfo> tzBaseEnterpriseInfos = tzBaseEnterpriseInfoMapper.selectList(new QueryWrapper<TzBaseEnterpriseInfo>().in("use_code", useCodes));
// privilege_company 有触发器更新,只需要更新 tz_base_enterprise_info
if (!ValidationUtil.isEmpty(tzBaseEnterpriseInfos)) {
for (TzBaseEnterpriseInfo tzBaseEnterpriseInfo : tzBaseEnterpriseInfos) {
String oldOrgCode = tzBaseEnterpriseInfo.getOrgCode(); // 旧的org_code
String preOrgCode = companyBo.getOrgCode();// 新的org_code
String oldSuperviseOrgCode = tzBaseEnterpriseInfo.getSuperviseOrgCode();
String preSuperviseOrgCode = companyBo.getOrgCode().replace("*" + companyBo.getCompanyOrgCode(), "");
// 更新 tz_base_enterprise_info
tzBaseEnterpriseInfoMapper.updateSubCompanyOrgCode(oldSuperviseOrgCode, preSuperviseOrgCode, oldOrgCode, preOrgCode);
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("刷新企业信息发生异常", e);
}
}
}
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