Commit 05353820 authored by tianbo's avatar tianbo

feat(jg): 添加设备报废安全追溯问题处理功能

- 在设备报废取消流程中添加发送更新设备安全追溯问题消息的功能 - 在SafetyProblemEventHandlerFactory中注册SBBF和SBBFCX事件处理器 - 修改SafetyProblemTracingServiceImpl的deleteBySourceId方法支持批量删除 - 新增recoverProblemBySourceId方法用于恢复已删除的安全追溯问题 - 在SafetyProblemTypeEnum中添加设备报废和设备报废撤销枚举类型
parent c82ed146
......@@ -21,7 +21,9 @@ public enum SafetyProblemTypeEnum {
XKCQ("5", "3", "许可超期", "企业许可超期", "safetyProblemTracing/xk/cq", null),
ZZCQ("6", "9", "资质超期", "人员资质超期", "safetyProblemTracing/zz/cq", null),
SJNXCQ("7", "5", "超设计年限", "设备超设计年限", "safetyProblemTracing/synx/cq", null),
SJNXDJ("8", "5", "超设计年限登记", "超设计年限登记", "safetyProblemTracing/synx/dj", null);
SJNXDJ("8", "5", "超设计年限登记", "超设计年限登记", "safetyProblemTracing/synx/dj", null),
SBBF("9", "4", "设备报废", "设备办理报废业务", "safetyProblemTracing/sb/bf", null),
SBBFCX("10", "4", "设备报废撤销", "设备办理报废业务撤销", "safetyProblemTracing/sb/bfcx", null);
/**
* 数据主键
......
......@@ -210,6 +210,7 @@ public class DataHandlerController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "PUT", value = "历史安全追溯问题闭环【维保备案】【检验超期】", notes = "历史安全追溯问题闭环【维保备案】【检验超期】")
@PutMapping(value = "/safeTraceabilityClosedLoop")
@Deprecated
public ResponseModel<String> safeTraceabilityClosedLoop() {
return ResponseHelper.buildResponse(dataHandlerService.safeTraceabilityClosedLoop());
}
......
......@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* WBCQEventHandler 类实现了 SafetyProblemEventHandler 接口,
* JYBJEventHandler 类实现了 SafetyProblemEventHandler 接口,
* 用于处理检验报检安全问题闭环。
*/
@Component
......
......@@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* WBCQEventHandler 类实现了 SafetyProblemEventHandler 接口,
* JYCQEventHandler 类实现了 SafetyProblemEventHandler 接口,
* 用于处理检验超期安全问题事件。
*/
@Component
......
......@@ -38,6 +38,10 @@ public class SafetyProblemEventHandlerFactory {
return new SJNXCQEventHandler(safetyProblemTracingService);
} else if (topic.startsWith(SafetyProblemTypeEnum.SJNXDJ.getTopic())) {
return new SJNXDJEventHandler(equipmentProblemStrategy);
} else if (topic.startsWith(SafetyProblemTypeEnum.SBBF.getTopic())) {
return new SBBFEventHandler(safetyProblemTracingService);
} else if (topic.startsWith(SafetyProblemTypeEnum.SBBFCX.getTopic())) {
return new SBBFCXEventHandler(safetyProblemTracingService);
} else {
// 其他策略类的创建
throw new IllegalArgumentException("Unsupported topic: " + topic);
......
package com.yeejoin.amos.boot.module.jg.biz.refresh.handler;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.module.common.api.entity.TzsDataRefreshMessage;
import com.yeejoin.amos.boot.module.common.api.service.IDataRefreshHandler;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
......@@ -36,7 +37,7 @@ public class EquipmentSafetyProblemRefreshHandler implements IDataRefreshHandler
String record = message.getDataId();
switch (DataRefreshEvent.Operation.valueOf(message.getOperation())) {
case DELETE:
safetyProblemTracingService.deleteBySourceId(record, "问题源被删除");
safetyProblemTracingService.deleteBySourceId(Lists.newArrayList(record), "问题源被删除");
break;
case INSERT:
case UPDATE:
......@@ -52,5 +53,6 @@ public class EquipmentSafetyProblemRefreshHandler implements IDataRefreshHandler
default:
log.error("unknown operation: {}", message.getOperation());
}
log.info("设备更新安全追溯问题结束,设备id:{}", message.getDataId());
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -55,8 +56,11 @@ import com.yeejoin.amos.feign.workflow.model.ActWorkflowStartDTO;
import com.yeejoin.amos.feign.workflow.model.ProcessTaskDTO;
import com.yeejoin.amos.feign.workflow.model.TaskResultDTO;
import io.seata.spring.annotation.GlobalTransactional;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -65,12 +69,14 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
......@@ -87,7 +93,7 @@ import static java.util.stream.Collectors.toSet;
@Service
public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgScrapCancel, JgScrapCancelMapper> implements IJgScrapCancelService, ICompensateFlowDataOfRedis<JgScrapCancel> {
Logger logger = LoggerFactory.getLogger(JgScrapCancelServiceImpl.class);
private static final String SUBMIT_TYPE_FLOW = "1";
private static final String PAGE_KEY = "jgScrapCancelAdd";
private static final String template = "%s发起%s%s业务申请,【申请单号:%s】";
......@@ -134,6 +140,9 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
private EventPublisher eventPublisher;
@Autowired
private EmqKeeper emqKeeper;
@Autowired
private PieLineDataChangeServiceImpl pipelineDataChangeService;
@Autowired
......@@ -1161,6 +1170,18 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
lambdaEq.select(JgScrapCancelEq::getEquId);
List<String> records = jgScrapCancelEqService.list(lambdaEq).stream().map(JgScrapCancelEq::getEquId).collect(Collectors.toList());
eventPublisher.publish(new DataRefreshEvent(this, records, DataRefreshEvent.DataType.equipment.name(), DataRefreshEvent.Operation.UPDATE));
// 发送更新设备安全追溯问题消息
if (CollectionUtil.isNotEmpty(records)) {
try {
JSONArray jsonArray = new JSONArray();
jsonArray.addAll(records);
emqKeeper.getMqttClient().publish(SafetyProblemTypeEnum.SBBF.getTopic(), jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8), 2, false);
} catch (MqttException e) {
logger.error("发送设备报废消息失败---->{}", e.getMessage());
throw new RuntimeException(e);
}
}
}
private List<String> updateInfoOther(JgScrapCancel jgScrapCancel, String routePath) {
......
......@@ -266,23 +266,25 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
/**
* 根据sourceId删除安全追溯问题
*
* @param sourceId 问题源id
* @param deleteReason
* @param sourceIds 问题源id
* @param deleteReason 删除原因
*/
@Transactional
public void deleteBySourceId(String sourceId, String deleteReason) {
List<SafetyProblemTracing> safetyProblemTracings = this.baseMapper.selectList(new LambdaQueryWrapper<SafetyProblemTracing>().eq(SafetyProblemTracing::getSourceId, sourceId));
public void deleteBySourceId(List<String> sourceIds, String deleteReason) {
List<SafetyProblemTracing> safetyProblemTracings = this.baseMapper.selectList(
new LambdaQueryWrapper<SafetyProblemTracing>().in(SafetyProblemTracing::getSourceId, sourceIds)
.eq(SafetyProblemTracing::getIsDelete, false));
if (!ValidationUtil.isEmpty(safetyProblemTracings)) {
List<SafetyProblemTracing> deleteList = Lists.newArrayList();
safetyProblemTracings.forEach(item -> {
// 设备问题标记为删除状态,删除原因为问题源被删除。但处理状态保留
// 设备问题标记为删除状态。但处理状态保留
item.setIsDelete(true);
JSONObject extraInfo = new JSONObject();
extraInfo.put("deleteReason", deleteReason);
item.setExtraInfo(extraInfo.toJSONString());
deleteList.add(item);
});
this.updateBatchById(deleteList);
// 批量更新
this.updateBatchById(safetyProblemTracings);
}
}
......@@ -371,4 +373,26 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
records.forEach(record -> fieldMap.put(record, MapUtil.of("problemStatus", SafetyProblemStatusEnum.HANDLED.getCode())));
return fieldMap;
}
@Transactional
public void recoverProblemBySourceId(List<String> sourceIds) {
// 查询条件:sourceId 在列表中,且 extraInfo 包含 deleteReason 为设备报废的记录
String deleteReasonJson = "\"deleteReason\":" + SafetyProblemTypeEnum.SBBF.getName();
List<SafetyProblemTracing> safetyProblemTracings = this.baseMapper.selectList(
new LambdaQueryWrapper<SafetyProblemTracing>()
.in(SafetyProblemTracing::getSourceId, sourceIds)
.like(SafetyProblemTracing::getExtraInfo, deleteReasonJson));
if (!ValidationUtil.isEmpty(safetyProblemTracings)) {
safetyProblemTracings.forEach(item -> {
// 设备问题恢复为未删除状态。
item.setIsDelete(false);
JSONObject extraInfo = new JSONObject();
extraInfo.put("deleteReason", null);
item.setExtraInfo(extraInfo.toJSONString());
});
// 批量更新
this.updateBatchById(safetyProblemTracings);
}
}
}
\ 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