Commit 9a5617fb authored by 刘林's avatar 刘林

fix(jg):设备履历信息修改

parent e14724af
package com.yeejoin.amos.boot.module.jg.biz.edit.event.listener;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jg.api.converter.EquDefineConverter;
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;
......@@ -11,9 +14,12 @@ import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeEqSe
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.entity.IdxBizJgUseInfo;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgUseInfoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
......@@ -28,6 +34,7 @@ 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.*;
import static org.apache.commons.lang3.StringUtils.defaultString;
@Component
@Slf4j
......@@ -43,6 +50,7 @@ public class ChangeEquipImpactCertListener {
private final JgInstallationNoticeServiceImpl jgInstallationNoticeService;
private final IdxBizJgProjectContraptionServiceImpl jgProjectContraptionService;
private final JgInstallationNoticeEqServiceImpl jgInstallationNoticeEqService;
private final IdxBizJgUseInfoMapper useInfoMapper;
/**
* 事件监听:只把事件放入队列
......@@ -75,36 +83,93 @@ public class ChangeEquipImpactCertListener {
/**
* 根据 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 -> {
private void handleFieldChange(List<FieldChangeMeta> fieldChangeMetaList, JgUseRegistrationManage manage) {
JSONObject certificatePrintTag = Optional.ofNullable(manage.getCertificatePrintTag())
.map(JSONObject::parseObject)
.orElse(new JSONObject());
Set<String> keysToJson = new HashSet<>();
for (FieldChangeMeta meta : fieldChangeMetaList) {
String columnKey = meta.getColumnKey();
if (!ChangeFieldWatchConstants.isWatched(columnKey)) {
continue;
}
log.info("字段 [{}] 是影响字段", columnKey);
for (String category : ChangeFieldWatchConstants.getMatchedCategories(columnKey)) {
switch (category) {
case "USE_CERT":
return Stream.of(CERTIFICATE_NORMAL, CERTIFICATE_NESTED);
this.updateUseCertField(manage, meta);
keysToJson.addAll(Arrays.asList("CERTIFICATE_NORMAL", "CERTIFICATE_NESTED"));
break;
case "USE_FLAG":
case "USE_FLAG_VEHICLE":
return Stream.of(USE_FLAG_NORMAL, USE_FLAG_NESTED);
keysToJson.addAll(Arrays.asList("USE_FLAG_NORMAL", "USE_FLAG_NESTED"));
break;
case "PIPELINE_SUMMARY":
case "NOTICE":
return Stream.of(EXPORT_SUMMARY_TABLE);
keysToJson.add("EXPORT_SUMMARY_TABLE");
break;
case "USE_CYLINDER_SUMMARY":
return Stream.of(CERTIFICATE_NORMAL);
keysToJson.add("CERTIFICATE_NORMAL");
break;
default:
log.warn("未知分类字段:[{}]", category);
return Stream.empty();
}
})
.collect(Collectors.toSet());
keysToJson.forEach(key -> {
}
}
for (String key : keysToJson) {
Object value = certificatePrintTag.get(key);
if (value instanceof Number && ((Number) value).intValue() == 2) {
certificatePrintTag.put(key, 1);
}
});
return certificatePrintTag;
}
manage.setCertificatePrintTag(JSONObject.toJSONString(certificatePrintTag));
jgUseRegistrationManageService.updateById(manage);
}
private void updateUseCertField(JgUseRegistrationManage manage, FieldChangeMeta meta) {
String columnKey = meta.getColumnKey();
String afterValue = Objects.toString(meta.getColumnNewValue(), null);
if (StringUtils.isBlank(afterValue)) {
return;
}
switch (columnKey) {
case "equDefine":
manage.setEquDefineCode(afterValue);
manage.setEquDefine(EquDefineConverter.getKeyByValue(afterValue));
break;
case "useOrgCode":
manage.setUseRegistrationCode(afterValue);
break;
case "city":
case "county":
case "street":
case "address":
if (!"unit".equals(manage.getManageType())) {
updateEquUseAddressByChangeId(manage, meta.getChangeId());
}
break;
default:
log.warn("未处理的USE_CERT字段:[{}]", columnKey);
break;
}
}
private void updateEquUseAddressByChangeId(JgUseRegistrationManage manage, Object changeId) {
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(changeId));
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
if (useInfo != null) {
String fullAddress = String.join("",
defaultString(useInfo.getProvinceName()),
defaultString(useInfo.getCityName()),
defaultString(useInfo.getCountyName()),
defaultString(useInfo.getStreetName()),
defaultString(useInfo.getAddress())
);
manage.setEquUseAddress(fullAddress);
} else {
log.warn("未找到对应的使用信息记录,ChangeId: {}", changeId);
}
}
/**
......@@ -164,11 +229,7 @@ public class ChangeEquipImpactCertListener {
.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);
this.handleFieldChange(event.getData(), jgUseRegistrationManage);
String equId = Stream.concat(
Optional.ofNullable(event.getBizRelationData().getProjectContraptionIds()).orElse(Collections.emptySet()).stream(),
Optional.ofNullable(event.getBizRelationData().getRecords()).orElse(Collections.emptySet()).stream()
......
......@@ -108,21 +108,22 @@ public class ChangeLogInsertListener {
).findFirst().orElse(null);
String businessTypeName = BusinessTypeEnum
.findNameByEnumName(changeLog.getBizType()).orElse("设备编辑");
jgResumeInfoService.createWithModel(JgResumeInfoDto.builder()
.applyNo(event.getBizRelationData().getBizId())
.businessType(businessTypeName)
.businessId(event.getBizRelationData().getBizId())
.equId(equId)
.resumeType("1")
.changeContent("设备编辑")
.changeLogId(String.valueOf(changeLog.getSequenceNbr()))
.approvalUnit(event.getBizRelationData().getUnitName())
.approvalUnitCode(event.getBizRelationData().getUnitCode())
.createUserName(event.getBizRelationData().getRecUserName())
.createUserId(event.getRequestContext().getExcutedUserId())
.status("正常")
.routePath(routePath)
.build());
JgResumeInfoDto resumeInfoDto = new JgResumeInfoDto();
resumeInfoDto.setApplyNo(event.getBizRelationData().getBizId());
resumeInfoDto.setBusinessType(businessTypeName);
resumeInfoDto.setBusinessId(event.getBizRelationData().getBizId());
resumeInfoDto.setEquId(equId);
resumeInfoDto.setResumeType("1");
resumeInfoDto.setChangeContent("设备编辑");
resumeInfoDto.setChangeLogId(String.valueOf(changeLog.getSequenceNbr()));
resumeInfoDto.setApprovalUnit(event.getBizRelationData().getUnitName());
resumeInfoDto.setApprovalUnitCode(event.getBizRelationData().getUnitCode());
resumeInfoDto.setRecDate(new Date());
resumeInfoDto.setRecUserName(event.getBizRelationData().getRecUserName());
resumeInfoDto.setRecUserId(event.getRequestContext().getExcutedUserId());
resumeInfoDto.setStatus("正常");
resumeInfoDto.setRoutePath(routePath);
jgResumeInfoService.createWithModel(resumeInfoDto);
} catch (Exception e){
log.error(e.getMessage(), e);
}
......
......@@ -102,9 +102,13 @@ public class JgBizChangeLogServiceImpl extends BaseService<JgBizChangeLogDto, Jg
if (!ValidationUtil.isEmpty(source.get("columnType")) && !"String".equals(source.get("columnType"))) {
Object before = source.get("beforeData");
Object after = source.get("afterData");
Object displayOldValue = source.get("displayOldValue");
Object displayNewValue = source.get("displayNewValue");
if (Objects.toString(before, "").trim().startsWith("[") && Objects.toString(after, "").trim().startsWith("[")) {
source.put("beforeData", JSONObject.parseArray(Objects.toString(before, "")));
source.put("afterData", JSONObject.parseArray(Objects.toString(after, "")));
source.put("displayOldValue", JSONObject.parseArray(Objects.toString(displayOldValue, "")));
source.put("displayNewValue", JSONObject.parseArray(Objects.toString(displayNewValue, "")));
}
}
list.add(source);
......
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