Commit ff5e1cd8 authored by tianbo's avatar tianbo

perf(tcm): 优化设备监管单位变更性能

- 增加日志记录,监控关键步骤的执行时间
parent 0dcd2d84
...@@ -1463,10 +1463,12 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1463,10 +1463,12 @@ public class TzBaseEnterpriseInfoServiceImpl
List<String> companySeqList = tzBaseEnterpriseInfoMapper.selectCompanyBySupervisionOrgCode(oldOrgCode); List<String> companySeqList = tzBaseEnterpriseInfoMapper.selectCompanyBySupervisionOrgCode(oldOrgCode);
// 2. 查询旧属地监管部门orgCode对应的所有设备 // 2. 查询旧属地监管部门orgCode对应的所有设备
List<String> equipmentRecordList = tzBaseEnterpriseInfoMapper.selectEquipmentBySupervisionOrgCode(oldOrgCode); List<String> equipmentRecordList = tzBaseEnterpriseInfoMapper.selectEquipmentBySupervisionOrgCode(oldOrgCode);
log.info("start-查询旧属地监管部门orgCode对应的所有设备equipmentRecordList:{},companySeqList:{}", equipmentRecordList.size(), companySeqList.size());
// 3. 3.1 更新单位及业务表的监管单位orgCode // 3. 3.1 更新单位及业务表的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeUnit(newModel.getString("companyName"), newOrgCode, oldOrgCode); tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeUnit(newModel.getString("companyName"), newOrgCode, oldOrgCode);
// 3.2 更新业务表统计表冗余的监管单位orgCode // 3.2 更新业务表统计表冗余的监管单位orgCode
tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeStatistics(newOrgCode, oldOrgCode); tzBaseEnterpriseInfoMapper.updateRedundantSupervisionOrgCodeStatistics(newOrgCode, oldOrgCode);
log.info("end-查询旧属地监管部门orgCode对应的所有设备equipmentRecordList:{},companySeqList:{}", equipmentRecordList.size(), companySeqList.size());
// 4. 更新idx_biz_view_jg_all es设备信息 // 4. 更新idx_biz_view_jg_all es设备信息
updateEquipmentJgAllEs(newOrgCode, oldOrgCode, equipmentRecordList, newModel.getString("companyName")); updateEquipmentJgAllEs(newOrgCode, oldOrgCode, equipmentRecordList, newModel.getString("companyName"));
// 5. 发送数据刷新事件 - 内存分页处理 // 5. 发送数据刷新事件 - 内存分页处理
...@@ -1485,6 +1487,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1485,6 +1487,7 @@ public class TzBaseEnterpriseInfoServiceImpl
private void updateEquipmentJgAllEs(String newOrgCode, String oldOrgCode, List<String> equipmentRecordList, String supervisionName) { private void updateEquipmentJgAllEs(String newOrgCode, String oldOrgCode, List<String> equipmentRecordList, String supervisionName) {
log.info("开始更新idx_biz_view_jg_all es设备属地监管部门信息,新orgCode{}, 旧orgCode:{}", newOrgCode, oldOrgCode); log.info("开始更新idx_biz_view_jg_all es设备属地监管部门信息,新orgCode{}, 旧orgCode:{}", newOrgCode, oldOrgCode);
if (!ValidationUtil.isEmpty(equipmentRecordList)) { if (!ValidationUtil.isEmpty(equipmentRecordList)) {
log.info("待更新equipmentRecordList数量:{}", equipmentRecordList.size());
int batchSize = 1000; int batchSize = 1000;
for (int i = 0; i < equipmentRecordList.size(); i += batchSize) { for (int i = 0; i < equipmentRecordList.size(); i += batchSize) {
int endIndex = Math.min(i + batchSize, equipmentRecordList.size()); int endIndex = Math.min(i + batchSize, equipmentRecordList.size());
...@@ -1503,6 +1506,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1503,6 +1506,7 @@ public class TzBaseEnterpriseInfoServiceImpl
}); });
if (!updatedCategories.isEmpty()) { if (!updatedCategories.isEmpty()) {
log.info("待更新updatedCategories数量:{}", updatedCategories.size());
esEquipmentCategory.saveAll(updatedCategories); esEquipmentCategory.saveAll(updatedCategories);
} }
} }
...@@ -1524,11 +1528,13 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1524,11 +1528,13 @@ public class TzBaseEnterpriseInfoServiceImpl
int endIndex = Math.min(i + batchSize, updatedEsDtoList.size()); int endIndex = Math.min(i + batchSize, updatedEsDtoList.size());
List<ESEquipmentCategoryDto> subList = updatedEsDtoList.subList(i, endIndex); List<ESEquipmentCategoryDto> subList = updatedEsDtoList.subList(i, endIndex);
esEquipmentCategory.saveAll(subList); esEquipmentCategory.saveAll(subList);
log.info("es jgAll表本批次更新数据{}条", subList.size());
} }
for (int i = 0; i < esRecordList.size(); i += batchSize) { for (int i = 0; i < esRecordList.size(); i += batchSize) {
int endIndex = Math.min(i + batchSize, esRecordList.size()); int endIndex = Math.min(i + batchSize, esRecordList.size());
List<String> subList = esRecordList.subList(i, endIndex); List<String> subList = esRecordList.subList(i, endIndex);
tzBaseEnterpriseInfoMapper.updateEquipmentSupervisionOrgCode(newOrgCode, supervisionName, subList); tzBaseEnterpriseInfoMapper.updateEquipmentSupervisionOrgCode(newOrgCode, supervisionName, subList);
log.info("数据库supervision表本批次更新数据{}条", subList.size());
} }
} }
log.info("更新数据库设备有属地监管部门,数据库无属地监管部门的设备结束"); log.info("更新数据库设备有属地监管部门,数据库无属地监管部门的设备结束");
...@@ -1549,6 +1555,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1549,6 +1555,7 @@ public class TzBaseEnterpriseInfoServiceImpl
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override @Override
public void afterCommit() { public void afterCommit() {
log.info("开始发布数据刷新事件");
int total = dataIds.size(); int total = dataIds.size();
int pages = (total + batchSize - 1) / batchSize; // 计算总页数 int pages = (total + batchSize - 1) / batchSize; // 计算总页数
...@@ -1559,7 +1566,9 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1559,7 +1566,9 @@ public class TzBaseEnterpriseInfoServiceImpl
if (!ValidationUtil.isEmpty(subList)) { if (!ValidationUtil.isEmpty(subList)) {
try { try {
log.info("开始发布数据刷新事件列表size:{}", subList.size());
emqKeeper.getMqttClient().publish(String.format(TZSCommonConstant.DATA_REFRESH_TOPIC, dataType.name(), DataRefreshEvent.Operation.UPDATE), JSONObject.toJSONString(subList).getBytes(StandardCharsets.UTF_8), 2, false); emqKeeper.getMqttClient().publish(String.format(TZSCommonConstant.DATA_REFRESH_TOPIC, dataType.name(), DataRefreshEvent.Operation.UPDATE), JSONObject.toJSONString(subList).getBytes(StandardCharsets.UTF_8), 2, false);
log.info("发布数据刷新事件列表结束");
} catch (MqttException e) { } catch (MqttException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -1571,6 +1580,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -1571,6 +1580,7 @@ public class TzBaseEnterpriseInfoServiceImpl
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
log.info("发布数据刷新事件结束");
} }
}); });
} }
......
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