Commit d3b83848 by 陶湘宇

配置文件控制定时器运行

parent 4b121214
...@@ -21,7 +21,7 @@ import cn.hutool.core.net.NetUtil; ...@@ -21,7 +21,7 @@ import cn.hutool.core.net.NetUtil;
@MapperScan({"cn.timer.api.dao"}) // 扫描的mapper @MapperScan({"cn.timer.api.dao"}) // 扫描的mapper
@ComponentScan(basePackages = {"cn.timer.api"}) @ComponentScan(basePackages = {"cn.timer.api"})
@SpringBootApplication @SpringBootApplication
@EnableScheduling //@EnableScheduling
@EnableTransactionManagement @EnableTransactionManagement
public class Application { public class Application {
......
package cn.timer.api.config.schedule;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class SchedulerCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
System.out.println("是否启动定时器"+context.getEnvironment().getProperty("enable.scheduling"));
return Boolean.valueOf(context.getEnvironment().getProperty("enable.scheduling"));
}
}
\ No newline at end of file
...@@ -5,7 +5,10 @@ import java.text.SimpleDateFormat; ...@@ -5,7 +5,10 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import cn.timer.api.config.schedule.SchedulerCondition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -21,15 +24,18 @@ import cn.timer.api.controller.kqgl.ClockInTool; ...@@ -21,15 +24,18 @@ import cn.timer.api.controller.kqgl.ClockInTool;
* 消息定时器 * 消息定时器
* *
*/ */
@Slf4j
@Configuration // 1.主要用于标记配置类,兼备Component的效果。 @Configuration // 1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务 //@EnableScheduling // 2.开启定时任务
public class NewsTaskTiming { public class NewsTaskTiming {
@Autowired @Autowired
private AlicloudSMS sms; private AlicloudSMS sms;
@Conditional(SchedulerCondition.class) //定时器开关
@Scheduled(cron = "0 0 8 * * ?")//早上八点 @Scheduled(cron = "0 0 8 * * ?")//早上八点
public void MessageAlert() throws ParseException { public void MessageAlert() throws ParseException {
log.info("消息定时器启动");
//当前时间 //当前时间
String nowdate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();// String nowdate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();//
......
...@@ -6,6 +6,7 @@ import cn.timer.api.bean.insure.InsurePolicy; ...@@ -6,6 +6,7 @@ import cn.timer.api.bean.insure.InsurePolicy;
import cn.timer.api.bean.insure.InsureUser; import cn.timer.api.bean.insure.InsureUser;
import cn.timer.api.bean.yggl.YgglMainEmp; import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.exception.CustomException; import cn.timer.api.config.exception.CustomException;
import cn.timer.api.config.schedule.SchedulerCondition;
import cn.timer.api.dao.insure.InsurePolicyMapper; import cn.timer.api.dao.insure.InsurePolicyMapper;
import cn.timer.api.dao.insure.InsureUserMapper; import cn.timer.api.dao.insure.InsureUserMapper;
import cn.timer.api.dao.yggl.YgglMainEmpMapper; import cn.timer.api.dao.yggl.YgglMainEmpMapper;
...@@ -13,6 +14,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -13,6 +14,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -29,7 +31,7 @@ import java.util.stream.Collectors; ...@@ -29,7 +31,7 @@ import java.util.stream.Collectors;
* @Date 2022/5/5 11:20 * @Date 2022/5/5 11:20
*/ */
@Configuration //1.主要用于标记配置类,兼备Component的效果。 @Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务 //@EnableScheduling // 2.开启定时任务
@Slf4j @Slf4j
public class InsureTaskTiming { public class InsureTaskTiming {
@Autowired @Autowired
...@@ -37,11 +39,12 @@ public class InsureTaskTiming { ...@@ -37,11 +39,12 @@ public class InsureTaskTiming {
@Autowired @Autowired
private YgglMainEmpMapper ygglMainEmpMapper; private YgglMainEmpMapper ygglMainEmpMapper;
@Conditional(SchedulerCondition.class) //定时器开关
@Scheduled(cron = "0/1 0 0 * * ?")//每月第一天 @Scheduled(cron = "0/1 0 0 * * ?")//每月第一天
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateInsureStatusTask(){ public void updateInsureStatusTask(){
try { try {
log.info("保单定时器");
Date now = DateUtil.date(); Date now = DateUtil.date();
/*获取正常的保单*/ /*获取正常的保单*/
List<InsurePolicy> insurePolicyList = InsurePolicy.builder().build().selectList(new QueryWrapper<InsurePolicy>().lambda().eq(InsurePolicy::getStatus, "1").lt(InsurePolicy::getPolicyDateEnd, now)); List<InsurePolicy> insurePolicyList = InsurePolicy.builder().build().selectList(new QueryWrapper<InsurePolicy>().lambda().eq(InsurePolicy::getStatus, "1").lt(InsurePolicy::getPolicyDateEnd, now));
......
...@@ -10,8 +10,10 @@ import java.util.Date; ...@@ -10,8 +10,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import cn.timer.api.config.schedule.SchedulerCondition;
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.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -61,7 +63,7 @@ import cn.timer.api.utils.DateUtil; ...@@ -61,7 +63,7 @@ import cn.timer.api.utils.DateUtil;
* 考勤报表汇总数据 * 考勤报表汇总数据
*/ */
@Configuration //1.主要用于标记配置类,兼备Component的效果。 @Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务 //@EnableScheduling // 2.开启定时任务
@Slf4j @Slf4j
public class AttendanceTaskTiming{ public class AttendanceTaskTiming{
...@@ -93,13 +95,14 @@ public class AttendanceTaskTiming{ ...@@ -93,13 +95,14 @@ public class AttendanceTaskTiming{
// @Scheduled(cron = "0 */2 * * * ?") // @Scheduled(cron = "0 */2 * * * ?")
// @Scheduled(cron = "0 25 11 * * ?") // @Scheduled(cron = "0 25 11 * * ?")
@Conditional(SchedulerCondition.class) //定时器开关
@Scheduled(cron = "0 0 8,12,16,20 * * ?")//每天上午8、12点,下午16点,20点 执行 @Scheduled(cron = "0 0 8,12,16,20 * * ?")//每天上午8、12点,下午16点,20点 执行
public void AttendanceTask() throws ParseException { public void AttendanceTask() throws ParseException {
boolean implement = true; boolean implement = true;
//逻辑 //逻辑
if(implement) { if(implement) {
log.info("AttendanceTask考勤数据统计开始");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, 0); c.add(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
......
...@@ -10,7 +10,10 @@ import java.util.Date; ...@@ -10,7 +10,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import cn.timer.api.config.schedule.SchedulerCondition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -59,8 +62,9 @@ import cn.timer.api.utils.DateUtil; ...@@ -59,8 +62,9 @@ import cn.timer.api.utils.DateUtil;
/** /**
* @author Yl123 上月数据 * @author Yl123 上月数据
*/ */
@Slf4j
@Configuration //1.主要用于标记配置类,兼备Component的效果。 @Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务 //@Conditional(SchedulerCondition.class) //定时器开关
public class LastMonthtimingExport { public class LastMonthtimingExport {
@Autowired @Autowired
private KqglMainKqzMapper kqglmainkqzmapper; private KqglMainKqzMapper kqglmainkqzmapper;
...@@ -89,12 +93,13 @@ public class LastMonthtimingExport { ...@@ -89,12 +93,13 @@ public class LastMonthtimingExport {
private static String lastDay; private static String lastDay;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
@Conditional(SchedulerCondition.class) //定时器开关
// @Scheduled(cron = "0 55 11 * * ?") // @Scheduled(cron = "0 55 11 * * ?")
@Scheduled(cron = "0 0 4,20 * * ?")//每天上午4点,下午20点 执行 @Scheduled(cron = "0 0 4,20 * * ?")//每天上午4点,下午20点 执行
public void LastMonthtimingAttendanceTask() throws ParseException { public void LastMonthtimingAttendanceTask() throws ParseException {
log.info("=======================================上月数据定时任务开始=======================================");
//获取前月的最后一天 //获取前月的最后一天
Calendar cale = Calendar.getInstance(); Calendar cale = Calendar.getInstance();
cale.set(Calendar.DAY_OF_MONTH,0);//设置为1号,当前日期既为本月第一天 cale.set(Calendar.DAY_OF_MONTH,0);//设置为1号,当前日期既为本月第一天
......
...@@ -13,9 +13,12 @@ import java.util.Locale; ...@@ -13,9 +13,12 @@ import java.util.Locale;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.timer.api.bean.xcgl.XcglAssoXzdadx; import cn.timer.api.bean.xcgl.XcglAssoXzdadx;
import cn.timer.api.bean.xcgl.XcglAssoXzdaz; import cn.timer.api.bean.xcgl.XcglAssoXzdaz;
import cn.timer.api.config.schedule.SchedulerCondition;
import cn.timer.api.dao.xcgl.XcglAssoXzdadxMapper; import cn.timer.api.dao.xcgl.XcglAssoXzdadxMapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -65,16 +68,18 @@ import javax.annotation.Resource; ...@@ -65,16 +68,18 @@ import javax.annotation.Resource;
*/ */
//@Component //@Component
//@Lazy //@Lazy
@Slf4j
@Configuration //1.主要用于标记配置类,兼备Component的效果。 @Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务 //@EnableScheduling // 2.开启定时任务
public class SalaryTaskTiming{ public class SalaryTaskTiming{
// 薪酬管理-定薪 // 薪酬管理-定薪
@Resource @Resource
private XcglAssoXzdadxMapper xcglassoxzdadxmapper; private XcglAssoXzdadxMapper xcglassoxzdadxmapper;
//3.添加定时任务 每天凌晨1点执行一次 @Conditional(SchedulerCondition.class) //定时器开关
@Scheduled(cron = "0 0 1 * * ?") @Scheduled(cron = "0 0 1 * * ?") //3.添加定时任务 每天凌晨1点执行一次
public void AttendanceTask() throws ParseException { public void AttendanceTask() throws ParseException {
log.info("调薪记录生效定时任务");
// 使用状态(0:使用中;1:历史, 2: 未生效) // 使用状态(0:使用中;1:历史, 2: 未生效)
// 当前日期 // 当前日期
String curDate = DateUtil.getStringFormat(new Date().getTime()); String curDate = DateUtil.getStringFormat(new Date().getTime());
......
...@@ -101,7 +101,7 @@ spring: ...@@ -101,7 +101,7 @@ spring:
protocol: smtp protocol: smtp
host: smtp.163.com host: smtp.163.com
username: youlingrc123@163.com username: youlingrc123@163.com
password: RIMBNJJQNKYNVUWL password: youlingrc189
default-encoding: utf-8 default-encoding: utf-8
properties: properties:
mail: mail:
...@@ -164,8 +164,8 @@ pagehelper: ...@@ -164,8 +164,8 @@ pagehelper:
#showSql #showSql
logging: logging:
level: level:
root: ERROR root: INFO
cn.timer.api.dao: error cn.timer.api.dao: info
pattern: pattern:
console: '--%p--%m%n' console: '--%p--%m%n'
......
spring: spring:
profiles: profiles:
active: dev active: pro
#active: '@environment@' #active: '@environment@'
enable:
scheduling: false
# 我是合同证照 # 我是合同证照
[cn.timer.api.utils] [cn.timer.api.utils]
TimerUtil.start = 0/10 0 0 0 0 1/5 TimerUtil.start = 0/10 0 0 0 0 1/5
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
<!--用来指定日志文件的上限大小,那么到了这个值,就会删除旧的日志 --> <!--用来指定日志文件的上限大小,那么到了这个值,就会删除旧的日志 -->
<!--<totalSizeCap>1GB</totalSizeCap> --> <!--<totalSizeCap>1GB</totalSizeCap> -->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize> <maxFileSize>1024MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy> </timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy> </rollingPolicy>
<!--日志输出编码格式化 --> <!--日志输出编码格式化 -->
......
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