补充并发锁

This commit is contained in:
黎润豪 2026-04-03 11:27:19 +08:00
parent b6aeeaea34
commit ba22f1f257
1 changed files with 15 additions and 7 deletions

View File

@ -7,6 +7,8 @@ import com.chinaweal.aiccs.aicbizqy.entity.datamove.*;
import com.chinaweal.aiccs.aicbizqy.mapper.datamove.*; import com.chinaweal.aiccs.aicbizqy.mapper.datamove.*;
import com.chinaweal.aiccs.aiccs.system.entity.TRBaseCode; import com.chinaweal.aiccs.aiccs.system.entity.TRBaseCode;
import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService; import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.redis.RedisService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@ -48,17 +50,17 @@ public class CancelEntRemoveSchedule {
@Autowired @Autowired
private CaseCreInformationDataMoveMapper caseCreInformationMapper; private CaseCreInformationDataMoveMapper caseCreInformationMapper;
@Autowired @Autowired
private TRBaseCodeService trBaseCodeService; private TRBaseCodeService trBaseCodeService;
@Autowired
private RedisService redisService;
/** /**
* 移出原因码值 - 其他 * LOCK_KEY
*/ */
private static final String REMOVE_REASON_CODE = "08"; private static final String REDIS_LOCK = "CANCEL_ENT_LOCK";
/**
* 移出原因中文 - 主体注销自动移出
*/
private static final String REMOVE_REASON_CN = "主体注销,自动移出";
/** /**
* 默认移出机关代码 * 默认移出机关代码
*/ */
@ -74,9 +76,13 @@ public class CancelEntRemoveSchedule {
@Scheduled(cron = "${scheduling.cron.cancelEntRemove:-}") @Scheduled(cron = "${scheduling.cron.cancelEntRemove:-}")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void executeCancelEntRemove() { public void executeCancelEntRemove() {
if (redisService.exists(REDIS_LOCK)) {
log.info("其他节点已在执行注销主体自动移出任务,本次任务自动跳过");
return;
}
log.info("==========开始执行注销主体自动移出任务=========="); log.info("==========开始执行注销主体自动移出任务==========");
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
redisService.set(REDIS_LOCK, StringUtils.EMPTY, 3600);
try { try {
// 获取当天日期 // 获取当天日期
LocalDate today = LocalDate.now().minusDays(1); LocalDate today = LocalDate.now().minusDays(1);
@ -126,6 +132,8 @@ public class CancelEntRemoveSchedule {
} catch (Exception e) { } catch (Exception e) {
log.error("注销主体自动移出任务执行异常", e); log.error("注销主体自动移出任务执行异常", e);
throw e; throw e;
} finally {
redisService.remove(REDIS_LOCK);
} }
} }