Commit 6763ef31 authored by suhuiguang's avatar suhuiguang

Merge branch 'develop_tzs_register' of…

Merge branch 'develop_tzs_register' of http://39.100.92.250:5000/moa/amos-boot-biz into develop_tzs_register
parents 3fb61c16 8851fb12
......@@ -18,4 +18,6 @@ public class TZSCommonConstant {
public static final String CITY = "CITY";
public static final String REGION = "REGION";
public static final String STREET = "STREET";
public static final String PLATFORM_FEIGN_RESULT_KEY_COMPANY = "compnay";
}
......@@ -60,7 +60,7 @@
</if>
<if test="type == 'supervision'">
AND tjcr.instance_id <![CDATA[<>]]> ''
AND tjcr.receive_company_code = #{companyCode}
AND tjcr.receive_org_code = #{companyCode}
</if>
<if test="type == 'enterprise'">
AND tjcr.use_unit_code = #{dto.useUnitCode}
......
......@@ -135,7 +135,7 @@
AND (isn.receive_company_code = #{companyCode} or isn.transfer_to_user_ids like concat('%',#{userId},'%'))
</if>
<if test="type == 'company'">
AND (isn.install_unit_credit_code = #{param.useUnitCreditCode} or isn.transfer_to_user_ids like
AND (isn.install_unit_credit_code = #{companyCode} or isn.transfer_to_user_ids like
concat('%',#{userId},'%'))
</if>
<if test="orgCode != null and orgCode != ''">
......
......@@ -97,19 +97,19 @@
</foreach>
</if>
<if test="type == 'supervision'">
AND (tjtn.receive_company_code = #{orgCode} or tjtn.transfer_to_user_ids like
AND (tjtn.receive_company_code = #{companyCode} or tjtn.transfer_to_user_ids like
concat('%',#{param.transferToUserIds},'%'))
AND tjtn.instance_id <![CDATA[<>]]> ''
</if>
<if test="type == 'company'">
AND (tjtn.install_unit_credit_code = #{orgCode} or tjtn.transfer_to_user_ids like
AND (tjtn.install_unit_credit_code = #{companyCode} or tjtn.transfer_to_user_ids like
concat('%',#{param.transferToUserIds},'%'))
</if>
<if test="type == 'testAdmin'">
((AND tjtn.receive_company_code = #{orgCode}
((AND tjtn.receive_company_code = #{companyCode}
AND tjtn.instance_id <![CDATA[<>]]> '')
or
AND tjtn.install_unit_credit_code = #{orgCode})
AND tjtn.install_unit_credit_code = #{companyCode})
</if>
<if test="orgCode != null and orgCode != ''">
AND tjtn.instance_id <![CDATA[<>]]> ''
......
......@@ -96,5 +96,7 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI
List<String> selectCompanyBySupervisionOrgCode(String oldOrgCode);
void updateRedundantSupervisionOrgCode(String newOrgCode, String oldOrgCode);
void updateRedundantSupervisionOrgCodeUnit(String newOrgCode, String oldOrgCode);
void updateRedundantSupervisionOrgCodeStatistics(String newOrgCode, String oldOrgCode);
}
......@@ -263,50 +263,13 @@
where supervise_org_code LIKE CONCAT(#{oldOrgCode}, '%')
</select>
<update id="updateRedundantSupervisionOrgCode">
<update id="updateRedundantSupervisionOrgCodeUnit">
update tz_base_enterprise_info
set supervise_org_code = replace(supervise_org_code, #{oldOrgCode}, #{newOrgCode})
where supervise_org_code like concat(#{oldOrgCode}, '%');
update tz_base_enterprise_info
set org_code = replace(org_code, #{oldOrgCode}, #{newOrgCode})
where org_code like concat(#{oldOrgCode}, '%');
--三项制度因为会定时生成统计数据(刚好在层级调整后生成了统计数据,此时再单位层级树再调整会原有,根据该表的唯一约束会提示更新冲突),所以需要特殊处理(如果目标数据存在则不更新,并删除旧的统计数据)
WITH update_data AS (
SELECT
ctid,
REPLACE(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode}) AS new_code,
plan_type,
check_date
FROM tzs_three_systems
WHERE supervisory_unit_org_code LIKE concat(#{oldOrgCode}, '%')
),
conflicts AS (
SELECT u.ctid
FROM update_data u
JOIN tzs_three_systems t ON
t.supervisory_unit_org_code = u.new_code
AND t.plan_type = u.plan_type
AND t.check_date = u.check_date
),
updated AS (
UPDATE tzs_three_systems t
SET supervisory_unit_org_code = REPLACE(t.supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
FROM update_data u
WHERE t.ctid = u.ctid
AND t.ctid NOT IN (SELECT ctid FROM conflicts)
RETURNING t.ctid
)
DELETE FROM tzs_three_systems
WHERE supervisory_unit_org_code LIKE concat(#{oldOrgCode}, '%')
AND ctid NOT IN (SELECT ctid FROM updated);
update tzs_two_staffing
set supervisory_unit_orgcode = replace(supervisory_unit_orgcode, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_orgcode like concat(#{oldOrgCode}, '%');
update biz_jg_equipment_category_data
set org_branch_code = replace(org_branch_code, #{oldOrgCode}, #{newOrgCode})
where org_branch_code like concat(#{oldOrgCode}, '%');
update tzs_jg_vehicle_information
set org_branch_code = replace(org_branch_code, #{oldOrgCode}, #{newOrgCode})
......@@ -382,22 +345,6 @@
set org_code = replace(org_code, #{oldOrgCode}, #{newOrgCode})
where org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_dispatch_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_maintenance_unit_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_rescue_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_use_unit_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_feedback_suggestions
set supervise_org_code = replace(supervise_org_code, #{oldOrgCode}, #{newOrgCode})
where supervise_org_code like concat(#{oldOrgCode}, '%');
......@@ -409,4 +356,68 @@
set risk_disposal_unit_org_code = replace(risk_disposal_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where risk_disposal_unit_org_code like concat(#{oldOrgCode}, '%');
</update>
<update id="updateRedundantSupervisionOrgCodeStatistics">
--三项制度因为会定时生成统计数据(刚好在层级调整后生成了统计数据,此时再单位层级树再调整会原有,根据该表的唯一约束会提示更新冲突),所以需要特殊处理(如果目标数据存在则不更新,并删除旧的统计数据)
WITH potential_updates AS (
SELECT
ctid,
supervisory_unit_org_code AS old_code,
REPLACE(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode}) AS new_code,
plan_type,
check_date
FROM tzs_three_systems
WHERE supervisory_unit_org_code LIKE concat (#{oldOrgCode}, '%' )
),
conflict_check AS (
SELECT
pu.*,
EXISTS (
SELECT 1 FROM tzs_three_systems t
WHERE t.supervisory_unit_org_code = pu.new_code
AND t.plan_type = pu.plan_type
AND t.check_date = pu.check_date
) AS has_conflict
FROM potential_updates pu
),
updated AS (
UPDATE tzs_three_systems t
SET supervisory_unit_org_code = cc.new_code
FROM conflict_check cc
WHERE t.ctid = cc.ctid
AND NOT cc.has_conflict
RETURNING t.ctid, cc.old_code
)
DELETE FROM tzs_three_systems t
WHERE EXISTS (
SELECT 1 FROM conflict_check cc
WHERE cc.ctid = t.ctid
AND cc.has_conflict
AND t.supervisory_unit_org_code = cc.old_code
);
update tzs_two_staffing
set supervisory_unit_orgcode = replace(supervisory_unit_orgcode, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_orgcode like concat(#{oldOrgCode}, '%');
update biz_jg_equipment_category_data
set org_branch_code = replace(org_branch_code, #{oldOrgCode}, #{newOrgCode})
where org_branch_code like concat(#{oldOrgCode}, '%');
update tzs_alert_dispatch_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_maintenance_unit_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_rescue_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
update tzs_alert_use_unit_statistics
set supervisory_unit_org_code = replace(supervisory_unit_org_code, #{oldOrgCode}, #{newOrgCode})
where supervisory_unit_org_code like concat(#{oldOrgCode}, '%');
</update>
</mapper>
......@@ -3,15 +3,15 @@ package com.yeejoin.amos.boot.module.tcm.biz.controller;
import com.yeejoin.amos.boot.module.tcm.biz.service.impl.HistoryDataDealServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
import java.util.Map;
/**
* @author Administrator
*/
......@@ -47,11 +47,12 @@ public class HistoryDataDealController {
return ResponseHelper.buildResponse(historyDataDealService.unitOrgCodeUpdate(oldOrgCode, newOrgCode));
}
@Deprecated
@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));
@PostMapping(value = "/handleCompanyHisOrgCode")
@ApiOperation(httpMethod = "PUT", value = "监管单位层级调整后,业务表(企业、设备、统计等)冗余的所有旧orgCode替换为新orgCode,不更新平台表", notes = "监管单位层级调整后,业务表(企业、设备、统计等)冗余的所有旧orgCode替换为新orgCode,不更新平台表")
public ResponseModel<String> handleCompanyHisOrgCode(@RequestBody List<Map<String, Object>> orgCodeMap) {
return ResponseHelper.buildResponse(historyDataDealService.handleCompanyHisOrgCode(orgCodeMap));
}
}
......@@ -14,7 +14,6 @@ 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;
......@@ -79,7 +78,6 @@ public class PlatformUserTopicMessage extends EmqxListener {
log.info("平台推送消息同步完成");
}
@Async
protected void processOrgCodeUpdateMessage(MqttMessage message) {
try {
if (ValidationUtil.isEmpty(message)) {
......@@ -95,7 +93,6 @@ public class PlatformUserTopicMessage extends EmqxListener {
}
}
@Async
protected void processOpMessage(MqttMessage message) {
try {
if (ValidationUtil.isEmpty(message)) {
......
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.entity.TzsUserPermission;
import com.yeejoin.amos.boot.module.tcm.api.entity.TzBaseEnterpriseInfo;
import com.yeejoin.amos.boot.module.tcm.api.entity.TzsUserInfo;
......@@ -14,11 +15,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.*;
/**
* @author Administrator
......@@ -135,8 +134,23 @@ public class HistoryDataDealServiceImpl {
* @return
*/
@Transactional(rollbackFor = Exception.class)
public String handleCompanyHisOrgCode(String newOrgCode, String oldOrgCode) {
baseEnterpriseInfoService.refreshCompanyOrgCode(null, newOrgCode, oldOrgCode);
public String handleCompanyHisOrgCode(List<Map<String, Object>> orgCodeMap) {
log.info("用企业新orgCode替换各个表缓存orgCode开始");
if (ValidationUtil.isEmpty(orgCodeMap)) {
return "error";
}
orgCodeMap.forEach(map -> {
String newOrgCode = map.get("newOrgCode").toString();
String oldOrgCode = map.get("oldOrgCode").toString();
//1. 处理平台旧orgCode本身错误数据
@SuppressWarnings("unchecked")
HashMap<String, Object> platformCompanyInfo = (HashMap<String, Object>) Privilege.companyClient.queryByOrgcode(oldOrgCode).getResult();
CompanyModel parentModel = JSON.parseObject(JSON.toJSONString(platformCompanyInfo.get(TZSCommonConstant.PLATFORM_FEIGN_RESULT_KEY_COMPANY)), CompanyModel.class);
parentModel.setOrgCode(newOrgCode);
Privilege.companyClient.update(parentModel, parentModel.getSequenceNbr());
//2. 处理业务表旧orgCode错误数据
baseEnterpriseInfoService.refreshCompanyOrgCode(null, newOrgCode, oldOrgCode);
});
return "success";
}
}
......@@ -53,6 +53,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -1393,6 +1394,7 @@ public class TzBaseEnterpriseInfoServiceImpl
* @date 2025/7/3 14:03
*/
@Override
@Async
public void refreshCompanyInfo(JSONObject dataResult, String method) {
try {
CompanyBo companyBo = JSON.parseObject(dataResult.toJSONString(), CompanyBo.class);
......@@ -1443,6 +1445,7 @@ public class TzBaseEnterpriseInfoServiceImpl
*/
@Override
@Transactional
@Async
public void refreshCompanyOrgCode(JSONObject dataResult, String newOrgCode, String oldOrgCode) {
try {
if (!ValidationUtil.isEmpty(newOrgCode) && !ValidationUtil.isEmpty(oldOrgCode) && !newOrgCode.equals(oldOrgCode)) {
......@@ -1450,8 +1453,10 @@ public class TzBaseEnterpriseInfoServiceImpl
List<String> companySeqList = tzBaseEnterpriseInfoMapper.selectCompanyBySupervisionOrgCode(oldOrgCode);
// 2. 查询旧属地监管部门orgCode对应的所有设备
List<String> equipmentRecordList = tzBaseEnterpriseInfoMapper.selectEquipmentBySupervisionOrgCode(oldOrgCode);
// 3. 更新其他业务表冗余的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCode(newOrgCode, oldOrgCode);
// 3. 3.1 更新单位及业务表的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeUnit(newOrgCode, oldOrgCode);
// 3.2 更新业务表统计表冗余的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeStatistics(newOrgCode, oldOrgCode);
// 4. 发送数据刷新事件 - 内存分页处理
// 处理企业数据
publishDataRefreshEvents(companySeqList, DataRefreshEvent.DataType.enterprise, 1000);
......
......@@ -47,8 +47,7 @@ public enum EquipmentCategoryEnum {
public static Map<String, String> getName = new HashMap<>();
public static Map<String, String> getCode = new HashMap<>();
public static Map<String, String> getValue = new HashMap<>();
public static Map<String, String> getCityCode = new HashMap<>();
public static final Map<String, String> getCodeValueMap = new HashMap<>();
public static final Map<String, String> getCityCodeValue = new HashMap<>();
private static final Map<String, String> valueToCodeMap = new HashMap<>();
static {
......@@ -57,9 +56,8 @@ public enum EquipmentCategoryEnum {
getCode.put(e.value, e.code);
getValue.put(e.value, e.code);
if (e.cityCode != null) {
getCityCode.put(e.cityCode, e.code);
getCityCodeValue.put(e.cityCode, e.value);
}
getCodeValueMap.put(e.code, e.value);
valueToCodeMap.put("96333_" + e.value, e.getValue() + e.getCode());
}
}
......@@ -68,9 +66,4 @@ public enum EquipmentCategoryEnum {
public static String getCodeByValue(String value) {
return valueToCodeMap.get(value);
}
// 根据code获取对应的value
public static String getValueByCode(String code) {
return getCodeValueMap.get(code);
}
}
......@@ -921,7 +921,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
if (firstAvailableCode != null) {
elevatorCode.setLength(0);
elevatorCode.append(prefix).append(firstAvailableCode);
// firstAvailableCode 不足5位,前面补0
elevatorCode.append(prefix).append(String.format("%05d", firstAvailableCode.longValue()));
} else {
//// 获取补零位长度
// String elevatorCode1 = elevatorOtherInfo.getCode().substring(2);
......@@ -2789,33 +2790,34 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
}
// 对应关系转化
// city --> EquipmentCategoryEnum.code --> EquipmentCategoryEnum.value
// city/county --> EquipmentCategoryEnum.value
private String cityCodeTo96333CodePrefix(String city, String county, String isNotXixian) {
String code = EquipmentCategoryEnum.getCityCode.get(city);
if (StringUtils.isEmpty(code)) {
throw new RuntimeException("未匹配到对应的cityCode:" + city);
}
String prefixCode = "";
prefixCode = EquipmentCategoryEnum.getCityCodeValue.get(city);
// 西咸
if (XIAN.equals(city) && "0".equals(isNotXixian)) {
return EquipmentCategoryEnum.XXCSM.getValue();
prefixCode = EquipmentCategoryEnum.XXCSM.getValue();
}
// 杨陵
if (YANG_LING.equals(county)) {
return EquipmentCategoryEnum.YLCSM.getValue();
prefixCode = EquipmentCategoryEnum.YLCSM.getValue();
}
// 韩城
if (HAN_CHENG.equals(county)) {
return EquipmentCategoryEnum.HCCSM.getValue();
prefixCode = EquipmentCategoryEnum.HCCSM.getValue();
}
// 神木
if (SHEN_MU.equals(county)) {
return EquipmentCategoryEnum.SMCSM.getValue();
prefixCode = EquipmentCategoryEnum.SMCSM.getValue();
}
// 府谷
if (FU_GU.equals(county)) {
return EquipmentCategoryEnum.FGCSM.getValue();
prefixCode = EquipmentCategoryEnum.FGCSM.getValue();
}
if (StringUtils.isEmpty(prefixCode)) {
throw new RuntimeException("未匹配到对应的cityCode/countyCode:" + city + "/" + county);
}
return EquipmentCategoryEnum.getValueByCode(code);
return prefixCode;
}
}
\ 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