10 changed files with 144 additions and 23 deletions
@ -0,0 +1,70 @@
|
||||
package com.biutag.supervision.job; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.biutag.supervision.constants.enums.WorkStatusEnum; |
||||
import com.biutag.supervision.pojo.entity.SupRiskPersonal; |
||||
import com.biutag.supervision.pojo.entity.SupRiskPersonalSupRecord; |
||||
import com.biutag.supervision.pojo.entity.SupTask; |
||||
import com.biutag.supervision.service.SupRiskPersonalService; |
||||
import com.biutag.supervision.service.SupRiskPersonalSupRecordService; |
||||
import com.biutag.supervision.service.SupTaskService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.LocalDateTime; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wxc |
||||
* @date 2025/7/9 |
||||
*/ |
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
@Component |
||||
public class RiskJob { |
||||
|
||||
|
||||
private final SupRiskPersonalService riskPersonalService; |
||||
private final SupRiskPersonalSupRecordService riskPersonalSupRecordService; |
||||
private final SupTaskService taskService; |
||||
|
||||
// 每10分钟执行一次
|
||||
@Scheduled(fixedRate = 600000) |
||||
public void updateHandleTimeout() { |
||||
LocalDateTime now = LocalDateTime.now(); |
||||
List<SupRiskPersonal> list = riskPersonalService.list(new LambdaQueryWrapper<SupRiskPersonal>().eq(SupRiskPersonal::getWorkStatus, WorkStatusEnum.done.name())); |
||||
for (SupRiskPersonal riskPersonal : list) { |
||||
SupTask task = taskService.getById(riskPersonal.getTaskId()); |
||||
|
||||
Duration duration = Duration.between(now, task.getCreateTime()); |
||||
// 4小时、1天、30天
|
||||
long minutes = duration.toMinutes(); |
||||
long util = 240; |
||||
if ("4小时".equals(riskPersonal.getControlTimeInterval())) { |
||||
util = 240; |
||||
} |
||||
if ("1天".equals(riskPersonal.getControlTimeInterval())) { |
||||
util = 1440; |
||||
} |
||||
if ("4小时".equals(riskPersonal.getControlTimeInterval())) { |
||||
util = 43200; |
||||
} |
||||
// 取余数
|
||||
long remainder = minutes % util; |
||||
if (!riskPersonalSupRecordService.exists(new LambdaQueryWrapper<SupRiskPersonalSupRecord>() |
||||
.eq(SupRiskPersonalSupRecord::getTaskId, riskPersonal.getTaskId()) |
||||
.eq(SupRiskPersonalSupRecord::getIdCode, riskPersonal.getIdCode()) |
||||
.between(SupRiskPersonalSupRecord::getSupTime, now.minusMinutes(remainder), now))) { |
||||
// 状态更新为未督察
|
||||
riskPersonalService.update(new LambdaUpdateWrapper<SupRiskPersonal>().eq(SupRiskPersonal::getIdCode, riskPersonal.getIdCode()) |
||||
.set(SupRiskPersonal::getWorkStatus, WorkStatusEnum.todo.name())); |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue