Commit e5df3ad7 authored by tianbo's avatar tianbo

refactor(amos-boot): 优化单位 orgCode 变更处理逻辑

- 添加处理单位 orgCode 变更的接口和实现 - 更新平台消息同步逻辑,支持 orgCode 变更消息处理 - 优化企业、设备等业务表中的 orgCode 更新操作
parent 8ec77984
......@@ -578,7 +578,7 @@
</select>
<select id="getListPageCount" resultType="long">
SELECT <![CDATA[/*+ set(query_dop 16)*/]]> COUNT(DISTINCT ur.sequence_nbr)
SELECT <![CDATA[/*+ use_cplan tablescan(ur) tablescan(re) tablescan(jri) tablescan(other) set(query_dop 16)*/]]> COUNT(DISTINCT ur.sequence_nbr)
FROM tzs_jg_use_registration ur
LEFT JOIN tzs_jg_use_registration_eq re ON ur.sequence_nbr = re.equip_transfer_id
LEFT JOIN idx_biz_jg_register_info jri ON re.equ_id = jri."RECORD"
......
package com.yeejoin.amos.boot.module.tcm.api.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 平台操作接口类型枚举
*
***/
@Getter
@AllArgsConstructor
public enum PlatformOpMethodTypeEnum {
INSERT("insert", "插入"),
UPDATE("update", "更新"),
DELETE("delete", "删除");
private String code;
private String name;
public static PlatformOpMethodTypeEnum getEnumByCode(String code) {
for (PlatformOpMethodTypeEnum status : PlatformOpMethodTypeEnum.values()) {
if (status.getCode().equals(code)) {
return status;
}
}
return null;
}
}
package com.yeejoin.amos.boot.module.tcm.api.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 平台操作接口类型枚举
*
***/
@Getter
@AllArgsConstructor
public enum PlatformOpTopicEnum {
OPERATION_LOG("/amos/operation/log", "平台操作日志主题"),
COMPANY_ORG_CODE_UPDATE("amos/company/orgCode/update", "单位orgCode变更主题");
private String topic;
private String desc;
public static PlatformOpTopicEnum getEnumByCode(String code) {
for (PlatformOpTopicEnum status : PlatformOpTopicEnum.values()) {
if (status.getTopic().equals(code)) {
return status;
}
}
return null;
}
}
......@@ -61,6 +61,15 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI
Map<String, Object> getProblemInfoBySourceId(@Param("sourceId")String sourceId);
/**
* 批量更新企业单位orgCode
* @param superviseOrgName 新监管单位名称
* @param oldSuperviseOrgCode 旧监管单位orgCode
* @param preSuperviseOrgCode 新监管单位orgCode
* @param oldOrgCode 企业旧orgCode
* @param preOrgCode 企业新orgCode
* @param sequenceNbr 企业表id
*/
void updateSubCompanyOrgCode(@Param("superviseOrgName") String superviseOrgName, @Param("oldSuperviseOrgCode") String oldSuperviseOrgCode, @Param("preSuperviseOrgCode") String preSuperviseOrgCode,
@Param("oldOrgCode") String oldOrgCode, @Param("preOrgCode") String preOrgCode, @Param("sequenceNbr") Long sequenceNbr);
......@@ -81,5 +90,11 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI
* @param oldOrgCode 单位旧orgCode
* @param newOrgCode 单位新orgCode
*/
void updateUnitOrgCode(@Param("oldOrgCode") String oldOrgCode, @Param("newOrgCode") String newOrgCode);
void updateUnitOrgCode(@Param("oldOrgCode") String oldOrgCode, @Param("newOrgCode") String newOrgCode, @Param("useCode") String useCode);
List<String> selectEquipmentBySupervisionOrgCode(String oldOrgCode);
List<String> selectCompanyBySupervisionOrgCode(String oldOrgCode);
void updateRedundantSupervisionOrgCode(String newOrgCode, String oldOrgCode);
}
......@@ -49,4 +49,6 @@ public interface IEquipmentCategoryService {
* 企业设备树查询
*/
List<Map<String, Object>> unitEquipTree();
void deleteRegulatorUnitTree();
}
......@@ -11,7 +11,6 @@ import com.yeejoin.amos.boot.module.tcm.api.entity.BaseUnitLicence;
import com.yeejoin.amos.boot.module.tcm.api.entity.PageParam;
import com.yeejoin.amos.boot.module.tcm.api.entity.TzBaseEnterpriseInfo;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
......@@ -60,6 +59,8 @@ public interface ITzBaseEnterpriseInfoService extends IService<TzBaseEnterpriseI
TzIndividualityDto personalInfoUpdateById(Map<String, Object> map);
void refreshCompanyInfo(JSONObject dataResult);
void refreshCompanyInfo(JSONObject dataResult, String method);
void refreshCompanyOrgCode(JSONObject dataResult, String newOrgCode, String oldOrgCode);
}
......@@ -47,4 +47,11 @@ public class HistoryDataDealController {
return ResponseHelper.buildResponse(historyDataDealService.unitOrgCodeUpdate(oldOrgCode, newOrgCode));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PutMapping(value = "/handleCompanyHisOrgCode")
@ApiOperation(httpMethod = "PUT", value = "监管单位层级调整后,业务表(企业、设备、统计等)冗余的所有旧orgCode替换为新orgCode", notes = "监管单位层级调整后,业务表(企业、设备、统计等)冗余的所有旧orgCode替换为新orgCode")
public ResponseModel<String> handleCompanyHisOrgCode(@RequestParam String newOrgCode, @RequestParam String oldOrgCode) {
return ResponseHelper.buildResponse(historyDataDealService.handleCompanyHisOrgCode(newOrgCode, oldOrgCode));
}
}
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
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.enums.PlatformOpTopicEnum;
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;
......@@ -13,12 +14,15 @@ import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Objects;
@Component
@Slf4j
......@@ -29,9 +33,16 @@ public class PlatformUserTopicMessage extends EmqxListener {
@Value("${amos.operation.log}")
private String amosOperationLog;
@Value("${amos.orgCode.update:amos/company/orgCode/update}")
private String amosOrgCodeUpdateTopic;
@Value("${spring.application.name}")
private String applicationName;
@PostConstruct
void init() throws Exception {
emqKeeper.subscript(amosOperationLog, 2, this);
emqKeeper.subscript(buildShareTopic(amosOrgCodeUpdateTopic), 2, this);
}
@Value("${amos.agency.code}")
......@@ -54,30 +65,63 @@ public class PlatformUserTopicMessage extends EmqxListener {
@Override
public void processMessage(String topic, MqttMessage message) {
platformTokenService.setRequestContext();
JSONObject jsonObject = JSON.parseObject(message.toString());
JSONObject result = jsonObject.getJSONObject("result");
JSONArray dataResultList = new JSONArray();
JSONObject dataResult = new JSONObject();
if (result.get("result") instanceof JSONArray) {
dataResultList = JSON.parseArray(result.get("result").toString());
// 处理 dataList
} else {
// 处理 data
dataResult = result.getJSONObject("result");
log.info("平台推送消息开始同步");
switch (Objects.requireNonNull(PlatformOpTopicEnum.getEnumByCode(topic))) {
case OPERATION_LOG:
// 处理 平台操作日志
processOpMessage(message);
break;
case COMPANY_ORG_CODE_UPDATE:
// 处理 单位orgCode变更
processOrgCodeUpdateMessage(message);
break;
}
String path = result.getString("path");
String agencyCode = jsonObject.getString("agencyCode");
if (!amosAgencyCode.equals(agencyCode)) {
return;
log.info("平台推送消息同步完成");
}
@Async
protected void processOrgCodeUpdateMessage(MqttMessage message) {
try {
if (ValidationUtil.isEmpty(message)) {
return;
}
JSONObject jsonObject = JSON.parseObject(message.toString());
String newOrgCode = jsonObject.getString("newOrgCode");
String oldOrgCode = jsonObject.getString("oldOrgCode");
tzBaseEnterpriseInfoService.refreshCompanyOrgCode(jsonObject, newOrgCode, oldOrgCode);
} catch (Exception e) {
log.info("平台同步消息失败:{}", e.getMessage());
e.printStackTrace();
}
}
@Async
protected void processOpMessage(MqttMessage message) {
try {
if (StringUtils.isNotEmpty(path)) {
if (ValidationUtil.isEmpty(message)) {
return;
}
JSONObject jsonObject = JSON.parseObject(message.toString());
JSONObject result = jsonObject.getJSONObject("result");
JSONArray dataResultList = null;
JSONObject dataResult = null;
if (!ValidationUtil.isEmpty(result) && result.get("result") instanceof JSONArray) {
dataResultList = JSON.parseArray(result.get("result").toString());
} else if (!ValidationUtil.isEmpty(result) && result.get("result") instanceof JSONObject) {
dataResult = result.getJSONObject("result");
}
String path = result.getString("path");
String method = jsonObject.getString("methodName");
String agencyCode = jsonObject.getString("agencyCode");
if (!amosAgencyCode.equals(agencyCode)) {
return;
}
if (!ValidationUtil.isEmpty(dataResult) && StringUtils.isNotEmpty(path)) {
if (path.contains("company")) {
if ("监管机构".equals(dataResult.get("companyType"))) {
equipmentCategoryService.creatTree();
equipmentCategoryService.deleteRegulatorUnitTree();
}
tzBaseEnterpriseInfoService.refreshCompanyInfo(dataResult);
tzBaseEnterpriseInfoService.refreshCompanyInfo(dataResult, method);
} else if (path.contains("agencyuser")) {
regUnitInfoService.updateAdminInfo(dataResult);
}
......@@ -86,6 +130,9 @@ public class PlatformUserTopicMessage extends EmqxListener {
log.info("平台同步消息失败:{}", e.getMessage());
e.printStackTrace();
}
log.info("平台推送消息同步完成");
}
private String buildShareTopic(String topic) {
return "$share/" + applicationName + "/" + topic;
}
}
......@@ -16,6 +16,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
......@@ -33,6 +34,7 @@ public class PrivilegeCompanyUpdateAddListener extends EmqxListener {
Logger logger = LoggerFactory.getLogger(PrivilegeCompanyUpdateAddListener.class);
@Autowired
@Lazy
TzBaseEnterpriseInfoServiceImpl tzBaseEnterpriseInfoService;
@Autowired
......
......@@ -308,6 +308,13 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
}
/**
* 删除缓存中管辖机构树
*/
public void deleteRegulatorUnitTree() {
redisUtils.del(REGULATOR_UNIT_TREE);
}
/**
* 将管辖机构树中children为[]的修改为null
*
* @param result
......
......@@ -126,4 +126,17 @@ public class HistoryDataDealServiceImpl {
log.info("用企业新orgCode替换各个表缓存orgCode结束");
return true;
}
/**
* 监管单位层级调整后,业务表(企业、设备、统计等)冗余的所有旧orgCode替换为新orgCode
*
* @param newOrgCode 新orgCode
* @param oldOrgCode 旧orgCode
* @return
*/
@Transactional(rollbackFor = Exception.class)
public String handleCompanyHisOrgCode(String newOrgCode, String oldOrgCode) {
baseEnterpriseInfoService.refreshCompanyOrgCode(null, newOrgCode, oldOrgCode);
return "success";
}
}
......@@ -81,6 +81,7 @@ import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
......@@ -134,6 +135,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
@Autowired
DataDictionaryServiceImpl iDataDictionaryService;
@Autowired
@Lazy
TzBaseEnterpriseInfoServiceImpl baseEnterpriseInfoService;
@Autowired
TzsBaseIndividualityServiceImpl individualityService;
......
......@@ -17,6 +17,7 @@ import com.yeejoin.amos.boot.biz.common.utils.QRCodeUtil;
import com.yeejoin.amos.boot.biz.common.utils.TreeParser;
import com.yeejoin.amos.boot.biz.common.workflow.feign.WorkflowFeignService;
import com.yeejoin.amos.boot.module.common.api.entity.OrgUsr;
import com.yeejoin.amos.boot.module.common.api.enums.UnitDataSourceEnum;
import com.yeejoin.amos.boot.module.common.api.enums.UnitTypeNewEnum;
import com.yeejoin.amos.boot.module.common.biz.event.CommonPublisher;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
......@@ -32,13 +33,15 @@ import com.yeejoin.amos.boot.module.tcm.api.enums.CompanyLevelEnum;
import com.yeejoin.amos.boot.module.tcm.api.enums.EnterpriseEnums;
import com.yeejoin.amos.boot.module.tcm.api.mapper.TzBaseEnterpriseInfoMapper;
import com.yeejoin.amos.boot.module.tcm.api.mapper.TzsBaseInstitutionMapper;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.*;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.BaseUnitLicenceServiceImpl;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.EquipmentCategoryServiceImpl;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.StartPlatformTokenService;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.TzBaseEnterpriseInfoServiceImpl;
import com.yeejoin.amos.boot.module.tcm.biz.utils.RedisUtil;
import com.yeejoin.amos.boot.module.tcm.flc.api.dto.RegUnitIcDto;
import com.yeejoin.amos.boot.module.tcm.flc.api.dto.RegUnitInfoDto;
import com.yeejoin.amos.boot.module.tcm.flc.api.entity.RegUnitIc;
import com.yeejoin.amos.boot.module.tcm.flc.api.entity.RegUnitInfo;
import com.yeejoin.amos.boot.module.common.api.enums.UnitDataSourceEnum;
import com.yeejoin.amos.boot.module.tcm.flc.api.feign.AccessFeignService;
import com.yeejoin.amos.boot.module.tcm.flc.api.feign.IdxFeignService;
import com.yeejoin.amos.boot.module.tcm.flc.api.feign.UgpServiceFeignClient;
......@@ -60,6 +63,7 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
......@@ -113,6 +117,7 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
RegUnitIcServiceImpl regUnitIcService;
@Autowired
@Lazy
TzBaseEnterpriseInfoServiceImpl tzBaseEnterpriseInfoService;
@Autowired
......
......@@ -19,7 +19,6 @@ import com.yeejoin.amos.boot.module.ymt.api.entity.PageParam;
import com.yeejoin.amos.boot.module.ymt.api.entity.SpeUseUnit;
import com.yeejoin.amos.boot.module.ymt.api.entity.TzBaseEnterpriseInfo;
import com.yeejoin.amos.boot.module.ymt.api.mapper.TzBaseEnterpriseInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.service.IBaseUnitLicenceService;
import com.yeejoin.amos.boot.module.ymt.api.service.ITzBaseEnterpriseInfoService;
import com.yeejoin.amos.boot.module.ymt.biz.utils.RedisUtil;
import com.yeejoin.amos.boot.module.ymt.flc.api.dto.RegUnitIcDto;
......@@ -34,8 +33,6 @@ import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.privilege.model.IdPasswordAuthModel;
import com.yeejoin.amos.feign.privilege.util.DesUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......
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