Commit adb3b64b authored by 刘林's avatar 刘林

fix(jg):证打印标记功能开发

parent 526b9bf0
......@@ -173,7 +173,7 @@
(select ui.COUNTY_NAME from idx_biz_jg_use_info ui WHERE ui.record = re.equ_id) AS equipCountyName,
(select ui.STREET_NAME from idx_biz_jg_use_info ui WHERE ui.record = re.equ_id) AS equipStreetName,
(select ui.ADDRESS from idx_biz_jg_use_info ui WHERE ui.record = re.equ_id) AS equipAddress,
useUnit.use_contact AS safetyManager,
useUnit.use_contact AS safetyManager,
useUnit.contact_phone AS safetyManagerPhone,
useUnit.use_code AS useCode,
installUnit.use_code AS installUnitCreditCode,
......
package com.yeejoin.amos.boot.module.jg.biz.edit.event.listener;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.FieldChangeMeta;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNoticeEq;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationManage;
import com.yeejoin.amos.boot.module.jg.biz.edit.event.BaseBizDataChangeEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgProjectContraptionServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeEqServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgUseRegistrationManageServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgUseRegistrationManageServiceImpl.*;
@Component
@Slf4j
@RequiredArgsConstructor
public class ChangeEquipImpactCertListener {
@Value("${change.log.deal.thread.number:1}")
private int threadNumber;
private final BlockingQueue<BaseBizDataChangeEvent> queue = new LinkedBlockingQueue<>();
private final JgUseRegistrationManageServiceImpl jgUseRegistrationManageService;
private final JgInstallationNoticeServiceImpl jgInstallationNoticeService;
private final IdxBizJgProjectContraptionServiceImpl jgProjectContraptionService;
private final JgInstallationNoticeEqServiceImpl jgInstallationNoticeEqService;
/**
* 事件监听:只把事件放入队列
*/
@TransactionalEventListener(BaseBizDataChangeEvent.class)
@Async
public void onEvent(BaseBizDataChangeEvent event) {
log.info("ChangeEquipImpactCertListener收到事件:{}", JSONObject.toJSONString(event));
queue.add(event);
}
/**
* 初始化线程池处理逻辑
*/
@PostConstruct
public void init() {
ExecutorService executorService = Executors.newFixedThreadPool(threadNumber);
IntStream.range(0, threadNumber).forEach(i -> executorService.execute(() -> {
while (true) {
try {
BaseBizDataChangeEvent event = queue.take();
handleEvent(event);
} catch (Exception e) {
log.error("处理事件失败", e);
}
}
}));
}
/**
* 根据 bizType 路由处理逻辑
*/
private JSONObject handleFieldChange(List<FieldChangeMeta> fieldChangeMetaList, JSONObject certificatePrintTag) {
Set<String> keysToJson = fieldChangeMetaList.stream()
.filter(v -> ChangeFieldWatchConstants.isWatched(v.getColumnKey()))
.peek(v -> log.info("字段 [{}] 是影响字段", v.getColumnKey()))
.flatMap(v -> ChangeFieldWatchConstants.getMatchedCategories(v.getColumnKey()).stream())
.flatMap(category -> {
switch (category) {
case "USE_CERT":
return Stream.of(CERTIFICATE_NORMAL, CERTIFICATE_NESTED);
case "USE_FLAG":
case "USE_FLAG_VEHICLE":
return Stream.of(USE_FLAG_NORMAL, USE_FLAG_NESTED);
case "PIPELINE_SUMMARY":
case "NOTICE":
return Stream.of(EXPORT_SUMMARY_TABLE);
case "USE_CYLINDER_SUMMARY":
return Stream.of(CERTIFICATE_NORMAL);
default:
log.warn("未知分类字段:[{}]", category);
return Stream.empty();
}
})
.collect(Collectors.toSet());
keysToJson.forEach(key -> {
Object value = certificatePrintTag.get(key);
if (value instanceof Number && ((Number) value).intValue() == 2) {
certificatePrintTag.put(key, 1);
}
});
return certificatePrintTag;
}
/**
* 根据 bizType 路由处理逻辑
*/
private JSONObject handleFieldChangeProject(List<FieldChangeMeta> fieldChangeMetaList, JSONObject certificatePrintTag) {
Set<String> keysToJson = fieldChangeMetaList.stream()
.filter(v -> ChangeFieldWatchConstants.isWatched(v.getColumnKey()))
.peek(v -> log.info("字段 [{}] 是影响字段", v.getColumnKey()))
.flatMap(v -> ChangeFieldWatchConstants.getMatchedCategories(v.getColumnKey()).stream())
.flatMap(category -> {
switch (category) {
case "NOTICE":
case "PIPELINE_SUMMARY":
return Stream.of(EXPORT_SUMMARY_TABLE);
default:
log.warn("未知分类字段:[{}]", category);
return Stream.empty();
}
})
.collect(Collectors.toSet());
keysToJson.forEach(key -> {
Object value = certificatePrintTag.get(key);
if (value instanceof Number && ((Number) value).intValue() == 2) {
certificatePrintTag.put(key, 1);
}
});
return certificatePrintTag;
}
/**
* 根据 bizType 路由处理逻辑
*/
private void handleEvent(BaseBizDataChangeEvent event) {
switch (event.getBizRelationData().getBizType()) {
case "JG_USAGE_REGISTRATION":// 使用登记
handleUsageRegistration(event);
break;
case "JG_INSTALLATION_NOTIFICATION":// 安装告知
handleInstallationNotice(event);
break;
case "JG_NEW_EQUIP":// 新增设备
handleNewEquipEdit(event);
break;
case "JG_NEW_PROJECT":// 新增装置
handleNewProjectEdit(event.getData(), event.getBizRelationData().getBizId());
break;
default:
log.warn("未识别的 bizType: {}", event.getBizRelationData().getBizType());
break;
}
}
private void handleUsageRegistration(BaseBizDataChangeEvent event) {
if (event.getBizRelationData().getBizIsFinished()){
JgUseRegistrationManage jgUseRegistrationManage = jgUseRegistrationManageService.lambdaQuery()
.eq(JgUseRegistrationManage::getApplyNo, event.getBizRelationData().getBizId())
.eq(JgUseRegistrationManage::getIsDelete, 0)
.one();
JSONObject certificatePrintTag = Optional.ofNullable(jgUseRegistrationManage.getCertificatePrintTag())
.map(JSONObject::parseObject).orElse(new JSONObject());
JSONObject tagJson = this.handleFieldChange(event.getData(), certificatePrintTag);
jgUseRegistrationManage.setCertificatePrintTag(JSONObject.toJSONString(tagJson));
jgUseRegistrationManageService.updateById(jgUseRegistrationManage);
String equId = Stream.concat(
Optional.ofNullable(event.getBizRelationData().getProjectContraptionIds()).orElse(Collections.emptySet()).stream(),
Optional.ofNullable(event.getBizRelationData().getRecords()).orElse(Collections.emptySet()).stream()
).findFirst().orElse(null);
if (event.getBizRelationData().getProjectContraptionIds() != null && !event.getBizRelationData().getProjectContraptionIds().isEmpty()) {
this.handleNewProjectEdit(event.getData(), equId);
}
if (event.getBizRelationData().getRecords() != null && !event.getBizRelationData().getRecords().isEmpty()) {
List<String> installationNoticeSeqList = jgInstallationNoticeEqService.lambdaQuery()
.eq(JgInstallationNoticeEq::getEquId, equId)
.list().stream()
.filter(Objects::nonNull)
.map(JgInstallationNoticeEq::getEquipTransferId)
.collect(Collectors.toList());
JgInstallationNotice installationNotice = installationNoticeSeqList.isEmpty() ? null : jgInstallationNoticeService.lambdaQuery()
.in(JgInstallationNotice::getSequenceNbr, installationNoticeSeqList)
.eq(JgInstallationNotice::getUseUnitCreditCode, jgUseRegistrationManage.getUseRegistrationCode())
.eq(JgInstallationNotice::getNoticeStatus, FlowStatusEnum.TO_BE_FINISHED.getCode())
.list().stream()
.findFirst().orElse(null);
if (installationNotice != null) {
JSONObject installationNoticePrintTag = Optional.ofNullable(installationNotice.getCertificatePrintTag())
.map(JSONObject::parseObject).orElse(new JSONObject());
JSONObject installationNoticeTagJson = this.handleFieldChangeProject(event.getData(), installationNoticePrintTag);
installationNotice.setCertificatePrintTag(JSONObject.toJSONString(installationNoticeTagJson));
jgInstallationNoticeService.updateById(installationNotice);
}
}
}
log.info("处理 useRegister 类型逻辑");
}
private void handleInstallationNotice(BaseBizDataChangeEvent event) {
log.info("处理 installationNotice 类型逻辑");
if (event.getBizRelationData().getBizIsFinished()){
JgInstallationNotice jgInstallationNotice = jgInstallationNoticeService.lambdaQuery()
.eq(JgInstallationNotice::getApplyNo, event.getBizRelationData().getBizId())
.eq(JgInstallationNotice::getIsDelete, 0)
.one();
JSONObject certificatePrintTag = Optional.ofNullable(jgInstallationNotice.getCertificatePrintTag())
.map(JSONObject::parseObject).orElse(new JSONObject());
JSONObject tagJson = this.handleFieldChangeProject(event.getData(), certificatePrintTag);
jgInstallationNotice.setCertificatePrintTag(JSONObject.toJSONString(tagJson));
jgInstallationNoticeService.updateById(jgInstallationNotice);
if (event.getBizRelationData().getProjectContraptionIds() != null && !event.getBizRelationData().getProjectContraptionIds().isEmpty()) {
String projectContraptionId = Optional.of(event.getBizRelationData().getProjectContraptionIds())
.map(ids -> ids.iterator().next())
.orElse("");
this.handleNewProjectEdit(event.getData(), projectContraptionId);
}
}
}
private void handleNewEquipEdit(BaseBizDataChangeEvent event) {
log.info("处理 handleNewEquipEdit 类型逻辑");
}
private void handleNewProjectEdit(List<FieldChangeMeta> fieldChangeMetaList, String projectContraptionId) {
log.info("处理 handleNewProjectEdit 类型逻辑");
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(projectContraptionId);
JSONObject certificatePrintTag = Optional.ofNullable(projectContraption.getCertificatePrintTag())
.map(JSONObject::parseObject).orElse(new JSONObject());
JSONObject tagJson = this.handleFieldChangeProject(fieldChangeMetaList, certificatePrintTag);
projectContraption.setCertificatePrintTag(JSONObject.toJSONString(tagJson));
jgProjectContraptionService.updateById(projectContraption);
}
}
package com.yeejoin.amos.boot.module.jg.biz.edit.event.listener;
import java.util.*;
public class ChangeFieldWatchConstants {
/**
* 台套-使用登记证影响字段
*/
public static final Set<String> USE_CERT_MONITORED_FIELDS =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"equDefine", "equCode", "useInnerCode", "factoryNum",
"province", "city", "county", "street", "address"
)));
/**
* 标志-台套-设备编辑影响字段
*/
public static final Set<String> USE_FLAG_MONITORED_FIELDS =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"equDefine", "equCode", "useInnerCode", "inspectOrgName", "nextInspectDate",
"emergencyTel", "maintenanceUnitName"
)));
/**
* 标志-车用气瓶-设备编辑影响字段
*/
public static final Set<String> USE_FLAG_VEHICLE_MONITORED_FIELDS =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"productName", "carNumber", "factoryNum", "gasNum", "volume", "fillingMedium", "inspectOrgName",
"nextInspectDate"
)));
/**
* 管道汇总表-设备编辑影响字段
*/
public static final Set<String> PIPELINE_SUMMARY_TABLE_MONITORED_FIELDS =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"pipeName", "pipelineNumber", "deviceLevel", "designUnitName", "uscUnitName", "workPressure", "workTemperature", "workMedium",
"uscDate", "useDate", "nominalDiameter", "wallThickness", "pipeLength", "pressure", "temperature",
"medium", "inspectConclusion", "inspectOrgName", "nextInspectDate", "remarks")));
/**
* 使用登记-气瓶汇总表-设备编辑影响字段
*/
public static final Set<String> USE_CYLINDER_SUMMARY_TABLE_MONITORED_FIELDS =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"equDefine", "factoryNum", "chargingMedium", "produceUnitName", "produceDate", "nominalWorkingPressure", "singleBottleVolume", "inspectDate",
"nextInspectDate", "useInnerCode")));
/**
* 安装告知-设备编辑影响字段
*/
public static final Set<String> NOTICE_MONITORED_FIELDS =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"equCode", "productName", "contactPhone", "installUnitName",
"equipType", "factoryNum", "produceUnitName", "produceLicenseNum", "province",
"city", "county", "street", "address"
)));
/**
* 所有分类映射
*/
private static final Map<String, Set<String>> FIELD_MAP;
static {
Map<String, Set<String>> map = new LinkedHashMap<>();
map.put("USE_CERT", USE_CERT_MONITORED_FIELDS);
map.put("USE_FLAG", USE_FLAG_MONITORED_FIELDS);
map.put("USE_FLAG_VEHICLE", USE_FLAG_VEHICLE_MONITORED_FIELDS);
map.put("PIPELINE_SUMMARY", PIPELINE_SUMMARY_TABLE_MONITORED_FIELDS);
map.put("USE_CYLINDER_SUMMARY", USE_CYLINDER_SUMMARY_TABLE_MONITORED_FIELDS);
map.put("NOTICE", NOTICE_MONITORED_FIELDS);
FIELD_MAP = Collections.unmodifiableMap(map);
}
/**
* 判断是否是任何一类监控字段
*/
public static boolean isWatched(String columnKey) {
for (Set<String> fieldSet : FIELD_MAP.values()) {
if (fieldSet.contains(columnKey)) {
return true;
}
}
return false;
}
/**
* 获取字段所属的所有分类
*/
public static Set<String> getMatchedCategories(String columnKey) {
Set<String> matched = new HashSet<>();
for (Map.Entry<String, Set<String>> entry : FIELD_MAP.entrySet()) {
if (entry.getValue().contains(columnKey)) {
matched.add(entry.getKey());
}
}
return matched;
}
}
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