Commit 8209023b authored by cq990612's avatar cq990612

优化代码结构

parent 43ce33f1
package cn.wisenergy.web.config.auto;
/**
* @Authotr:陈奇
* @QQ1799796883
*/
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.mapper.WorkSubmitAdoptMapper;
import cn.wisenergy.mapper.WorkTimeOrderMapper;
import cn.wisenergy.model.app.WorkSubmitAdopt;
import cn.wisenergy.model.app.WorkTimeOrder;
import cn.wisenergy.model.enums.StatusEnum;
import cn.wisenergy.service.WorkCollectService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* 自动审批定时器
*/
@Slf4j
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
public class Examine {
@Autowired
private WorkTimeOrderMapper workTimeOrderMapper;
@Autowired
private WorkCollectService workCollectService;
@Autowired
private static WorkSubmitAdoptMapper workSubmitAdoptMapper;
private final static Integer COMPLETED = StatusEnum.COMPLETED.getCode();
private final static Integer RE_SUBMIT = StatusEnum.RE_SUBMIT.getCode();
private final static Integer AUTOMATIC_AUDIT = StatusEnum.AUTOMATIC_AUDIT.getCode();
// 每天凌晨自动审核
@Scheduled(cron = "0 0 0 * * ?" )
public void autoExamine() {
log.info("admin[]config[]auto[]Examine[]autoExamine");
// 获取系统默认值
WorkSubmitAdopt workSubmitAdopt = workSubmitAdoptMapper.selectById(1);
Integer autoAdopt = workSubmitAdopt.getSubmitTime();
// 更新work_time_order表
Date yesterdayDate = getAutoExamineDay(autoAdopt);
Date now = DateUtil.getToday();
QueryWrapper<WorkTimeOrder> wrapper = new QueryWrapper<>();
wrapper.in("status", COMPLETED, RE_SUBMIT);
wrapper.le("work_day", yesterdayDate);
List<WorkTimeOrder> workTimeOrders = workTimeOrderMapper.selectList(wrapper);
UpdateWrapper<WorkTimeOrder> wtoWrapper = new UpdateWrapper<>();
wtoWrapper.in("status", COMPLETED, RE_SUBMIT);
wtoWrapper.le("work_day", yesterdayDate);
WorkTimeOrder workTimeOrder1 = new WorkTimeOrder();
workTimeOrder1.setStatus(AUTOMATIC_AUDIT);
workTimeOrder1.setModifyTime(now);
int wtoRow = workTimeOrderMapper.update(workTimeOrder1, wtoWrapper);
System.out.println("一共审核:" + wtoRow + "条工单");
// 更新work_collect表
workCollectService.updateByWorkTimeOrder(workTimeOrders);
}
public static Date getAutoExamineDay(Integer day) {
day = -day;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, day);
Date start = c.getTime();
String qyt = format.format(start);
System.out.println(qyt);
return DateUtil.convertStrToDate(qyt, "yyyy-MM-dd");
}
}
package cn.wisenergy.web.config.auto;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.mapper.WorkTimeOrderMapper;
import cn.wisenergy.model.app.WorkSubmitAdopt;
import cn.wisenergy.model.app.WorkTimeOrder;
import cn.wisenergy.model.enums.StatusEnum;
import cn.wisenergy.service.WorkCollectService;
import cn.wisenergy.service.WorkSubmitAdoptService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.config.TriggerTask;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Component
@Configuration
@EnableScheduling
public class Trigger implements SchedulingConfigurer {
@Autowired
private WorkTimeOrderMapper workTimeOrderMapper;
@Autowired
private WorkCollectService workCollectService;
@Autowired
private WorkSubmitAdoptService workSubmitAdoptService;
private final static Integer COMPLETED = StatusEnum.COMPLETED.getCode();
private final static Integer RE_SUBMIT = StatusEnum.RE_SUBMIT.getCode();
private final static Integer AUTOMATIC_AUDIT = StatusEnum.AUTOMATIC_AUDIT.getCode();
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
TriggerTask trigerTask = new TriggerTask(
() -> {
//这里写业务方法
WorkSubmitAdopt workSubmitAdopt = workSubmitAdoptService.getById(1);
Integer autoAdopt = workSubmitAdopt.getSubmitTime();
// 更新work_time_order表
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, -autoAdopt);
Date start = c.getTime();
String qyt= format.format(start);
Date yesterdayDate = DateUtil.convertStrToDate(qyt, "yyyy-MM-dd");
Date now = DateUtil.getToday();
QueryWrapper<WorkTimeOrder> wrapper = new QueryWrapper<>();
wrapper.in("status", COMPLETED,RE_SUBMIT);
wrapper.le("work_day", yesterdayDate);
List<WorkTimeOrder> workTimeOrders = workTimeOrderMapper.selectList(wrapper);
UpdateWrapper<WorkTimeOrder> wtoWrapper = new UpdateWrapper<>();
wtoWrapper.in("status", COMPLETED,RE_SUBMIT);
wtoWrapper.le("work_day", yesterdayDate);
WorkTimeOrder workTimeOrder1 = new WorkTimeOrder();
workTimeOrder1.setStatus(AUTOMATIC_AUDIT);
workTimeOrder1.setModifyTime(now);
int wtoRow = workTimeOrderMapper.update(workTimeOrder1, wtoWrapper);
System.out.println("一共审核:" + wtoRow + "条工单");
// 更新work_collect表
workCollectService.updateByWorkTimeOrder(workTimeOrders);
}
, triggerContext -> {
Integer autoAdopt = workSubmitAdoptService.getById(1).getAutoAdopt();
String time = "0 0 0 */" + autoAdopt + " * ?";
//返回执行的周期
return new CronTrigger(time).nextExecutionTime(triggerContext);
});
scheduledTaskRegistrar.addTriggerTask(trigerTask);
}
}
......@@ -3,7 +3,7 @@ server:
uri-encoding: UTF-8
max-threads: 1000
min-spare-threads: 30
port: 8080
port: 8086
connection-timeout: 5000ms
spring:
......
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