Commit d99fa404 authored by suhuiguang's avatar suhuiguang

1.redis缓存的流程数据在事务回滚后可能和数据库数据不一致问题处理

parent 5f8aa960
package com.yeejoin.amos.boot.module.jg.biz.service;
/**
* @author Administrator
* redis 数据补偿
*/
public interface ICompensateFlowDataOfRedis<T> {
/**
* 补偿redis数据
* @param t 参数
*/
default void doCompensate(T t) {
if (beforeCheck(t)) {
compensate(t);
}
}
/**
* 补偿前校验
* @param t 参数
* @return 是否检验通过
*/
boolean beforeCheck(T t);
/**
* 补偿实现
* @param t 参数
*/
void compensate(T t);
}
......@@ -38,6 +38,7 @@ import com.yeejoin.amos.boot.module.jg.biz.event.CancellationEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.service.ICmWorkflowService;
import com.yeejoin.amos.boot.module.jg.biz.service.ICompensateFlowDataOfRedis;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgConstructionInfoService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgUseInfoService;
import com.yeejoin.amos.boot.module.jg.biz.utils.CodeUtil;
......@@ -98,7 +99,7 @@ import static com.alibaba.fastjson.JSON.parseArray;
*/
@Service
@Slf4j
public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationNoticeDto, JgInstallationNotice, JgInstallationNoticeMapper> implements IJgInstallationNoticeService {
public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationNoticeDto, JgInstallationNotice, JgInstallationNoticeMapper> implements IJgInstallationNoticeService, ICompensateFlowDataOfRedis<JgInstallationNotice> {
private static final String SUBMIT_TYPE_FLOW = "1";
private static final String PROCESS_DEFINITION_KEY = "installationNotificationNew";
......@@ -211,6 +212,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
if (Objects.isNull(notice)) {
return null;
}
// 流程数据补偿 防止redis缓存数据存在与数据库不一致问题
this.doCompensate(notice);
Map<String, Object> installationInfo = BeanUtil.beanToMap(notice, false, true);
installationInfo.put("province", notice.getProvince() + "_" + notice.getProvinceName());
......@@ -312,6 +315,13 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
}
}
private void compensateFlowDataOfRedis(JgInstallationNotice notice) {
if(notice.getInstanceId() != null && !notice.getNoticeStatus().equals(String.valueOf(FlowStatusEnum.TO_BE_FINISHED.getCode())) &&!notice.getNoticeStatus().equals(String.valueOf(FlowStatusEnum.TO_BE_DISCARD.getCode()))){
commonService.saveExecuteFlowData2Redis(notice.getInstanceId(), this.buildInstanceRuntimeData(notice));
}
}
private List<Map<String, Object>> getEquipListMaps(Iterable<ESEquipmentCategoryDto> equips) {
List<Map<String, Object>> arrayList = new ArrayList<>();
equips.forEach(equip -> {
......@@ -1726,4 +1736,15 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
jgInstallationNoticeEqService.updateBatchById(jgInstallationNoticeEqs);
return Boolean.TRUE;
}
@Override
public boolean beforeCheck(JgInstallationNotice notice) {
return notice.getInstanceId() != null && !notice.getNoticeStatus().equals(String.valueOf(FlowStatusEnum.TO_BE_FINISHED.getCode())) &&!notice.getNoticeStatus().equals(String.valueOf(FlowStatusEnum.TO_BE_DISCARD.getCode()));
}
@Override
public void compensate(JgInstallationNotice notice) {
commonService.saveExecuteFlowData2Redis(notice.getInstanceId(), this.buildInstanceRuntimeData(notice));
}
}
\ No newline at end of file
......@@ -38,6 +38,7 @@ import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.feign.WorkFlowFeignService;
import com.yeejoin.amos.boot.module.jg.biz.service.ICommonService;
import com.yeejoin.amos.boot.module.jg.biz.service.ICompensateFlowDataOfRedis;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgInspectionDetectionInfoService;
import com.yeejoin.amos.boot.module.jg.biz.utils.CodeUtil;
import com.yeejoin.amos.boot.module.ymt.api.common.StringUtil;
......@@ -107,7 +108,7 @@ import static java.util.stream.Collectors.toList;
*/
@Service
@Slf4j
public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationDto, JgUseRegistration, JgUseRegistrationMapper> implements IJgUseRegistrationService {
public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationDto, JgUseRegistration, JgUseRegistrationMapper> implements IJgUseRegistrationService, ICompensateFlowDataOfRedis<JgUseRegistration> {
private static final String DEFINITION_KEY = "useRegistration";
private final List<String> NOT_FLOWING_STATE = Arrays.asList("使用单位待提交", "一级受理已驳回", "使用单位已撤回", "已作废");
......@@ -1685,6 +1686,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
public Map<String, Object> getDetail(String record, Long sequenceNbr) {
if (!ObjectUtils.isEmpty(sequenceNbr)) {
JgUseRegistration jgUseRegistration = this.getBaseMapper().selectById(sequenceNbr);
this.doCompensate(jgUseRegistration);
LambdaQueryWrapper<JgRegistrationHistory> lambda = new QueryWrapper<JgRegistrationHistory>().lambda();
lambda.eq(JgRegistrationHistory::getCurrentDocumentId, sequenceNbr);
JgRegistrationHistory jgRegistrationHistory = jgRegistrationHistoryService.getBaseMapper().selectOne(lambda);
......@@ -3360,4 +3362,13 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
return true;
}
@Override
public boolean beforeCheck(JgUseRegistration jgUseRegistration) {
return jgUseRegistration.getInstanceId() != null && !jgUseRegistration.getStatus().equals(FlowStatusEnum.TO_BE_FINISHED.getName()) && !jgUseRegistration.getStatus().equals(FlowStatusEnum.TO_BE_DISCARD.getName());
}
@Override
public void compensate(JgUseRegistration jgUseRegistration) {
commonService.saveExecuteFlowData2Redis(jgUseRegistration.getInstanceId(), this.buildInstanceRuntimeData(jgUseRegistration));
}
}
\ 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