|
@@ -0,0 +1,64 @@
|
|
|
+package com.free.schedule;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.free.controller.TransferApplyController;
|
|
|
+import com.free.entity.ChatRecord;
|
|
|
+import com.free.entity.TransferApply;
|
|
|
+import com.free.service.ChatRecordService;
|
|
|
+import com.free.service.TransferApplyService;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@EnableScheduling
|
|
|
+public class ClearTransferApply {
|
|
|
+ @Autowired
|
|
|
+ private TransferApplyService transferApplyService;
|
|
|
+ @Autowired
|
|
|
+ private ChatRecordService chatRecordService;
|
|
|
+ /** 自动关闭时间: 10分钟 */
|
|
|
+ private Long limit = 10L;
|
|
|
+ // 每2分整执行一次
|
|
|
+ @Scheduled(cron = "0 0/2 * * * ? ")
|
|
|
+ public void schedule() {
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ String nowTimeStr = df.format(nowTime);
|
|
|
+ log.info("当前执行任务的线程号ID===>{}", Thread.currentThread().getId()); // 日志输出
|
|
|
+ log.info("当前执行任务时间===>{}", nowTimeStr); // 日志输出
|
|
|
+ // 查询受理但是没有结束的转人工申请
|
|
|
+ // QueryWrapper applyQw = new QueryWrapper<>();
|
|
|
+ // applyQw.eq("is_agree", TransferApplyController.TransferApplyAgree);
|
|
|
+ // applyQw.eq("is_close", TransferApplyController.TransferApplyNotClose);
|
|
|
+ // List<TransferApply> agreeNotCloseApplyList = transferApplyService.list(applyQw);
|
|
|
+ // // 查询这些没结束的转人工申请, 最后一次发言时间
|
|
|
+ // for (TransferApply i : agreeNotCloseApplyList) {
|
|
|
+ // QueryWrapper chatRecordQw = new QueryWrapper<>();
|
|
|
+ // chatRecordQw.eq("apply_id", i.getId());
|
|
|
+ // chatRecordQw.orderByDesc("time");
|
|
|
+ // ChatRecord chatRecord = chatRecordService.getOne(chatRecordQw);
|
|
|
+ // LocalDateTime chat_time = chatRecord.getTime();
|
|
|
+ // chat_time.plusMinutes(limit);
|
|
|
+ // // 判断, 最后的发言时间 + 自动关闭时间的10分钟 是否在当前时间之前:
|
|
|
+ // // 在当前时间之前: 不处理,未超时
|
|
|
+ // // 不在当前时间之前: 超过自动关闭的时间,直接关闭
|
|
|
+ // boolean isBefore = nowTime.isBefore(chat_time);
|
|
|
+ // if (!isBefore) {
|
|
|
+ // TransferApply closeData = new TransferApply();
|
|
|
+ // closeData.setId(i.getId());
|
|
|
+ // closeData.setIs_close(TransferApplyController.TransferApplyClose);
|
|
|
+ // transferApplyService.updateById(closeData);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+}
|