Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
d3b83848
Commit
d3b83848
authored
Sep 02, 2023
by
陶湘宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置文件控制定时器运行
parent
4b121214
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
59 additions
and
21 deletions
+59
-21
src/main/java/cn/timer/api/Application.java
+1
-1
src/main/java/cn/timer/api/config/schedule/SchedulerCondition.java
+14
-0
src/main/java/cn/timer/api/controller/htzz/atttimer/NewsTaskTiming.java
+8
-2
src/main/java/cn/timer/api/controller/insure/task/InsureTaskTiming.java
+5
-2
src/main/java/cn/timer/api/controller/kqgl/ClockInController.java
+0
-0
src/main/java/cn/timer/api/controller/kqgl/atttimer/AttendanceTaskTiming.java
+5
-2
src/main/java/cn/timer/api/controller/kqgl/atttimer/LastMonthtimingExport.java
+10
-5
src/main/java/cn/timer/api/controller/xcgl/atttimer/SalaryTaskTiming.java
+8
-3
src/main/resources/application-pro.yml
+3
-3
src/main/resources/application.yml
+3
-1
src/main/resources/config/cron.setting
+1
-1
src/main/resources/logback-spring.xml
+1
-1
No files found.
src/main/java/cn/timer/api/Application.java
View file @
d3b83848
...
...
@@ -21,7 +21,7 @@ import cn.hutool.core.net.NetUtil;
@MapperScan
({
"cn.timer.api.dao"
})
// 扫描的mapper
@ComponentScan
(
basePackages
=
{
"cn.timer.api"
})
@SpringBootApplication
@EnableScheduling
//
@EnableScheduling
@EnableTransactionManagement
public
class
Application
{
...
...
src/main/java/cn/timer/api/config/schedule/SchedulerCondition.java
0 → 100644
View file @
d3b83848
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
src/main/java/cn/timer/api/controller/htzz/atttimer/NewsTaskTiming.java
View file @
d3b83848
...
...
@@ -5,7 +5,10 @@ import java.text.SimpleDateFormat;
import
java.util.Date
;
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.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -21,15 +24,18 @@ import cn.timer.api.controller.kqgl.ClockInTool;
* 消息定时器
*
*/
@Slf4j
@Configuration
// 1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling
// 2.开启定时任务
//
@EnableScheduling // 2.开启定时任务
public
class
NewsTaskTiming
{
@Autowired
private
AlicloudSMS
sms
;
@Conditional
(
SchedulerCondition
.
class
)
//定时器开关
@Scheduled
(
cron
=
"0 0 8 * * ?"
)
//早上八点
public
void
MessageAlert
()
throws
ParseException
{
log
.
info
(
"消息定时器启动"
);
//当前时间
String
nowdate
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
new
Date
()).
toString
();
//
...
...
src/main/java/cn/timer/api/controller/insure/task/InsureTaskTiming.java
View file @
d3b83848
...
...
@@ -6,6 +6,7 @@ import cn.timer.api.bean.insure.InsurePolicy;
import
cn.timer.api.bean.insure.InsureUser
;
import
cn.timer.api.bean.yggl.YgglMainEmp
;
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.InsureUserMapper
;
import
cn.timer.api.dao.yggl.YgglMainEmpMapper
;
...
...
@@ -13,6 +14,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -29,7 +31,7 @@ import java.util.stream.Collectors;
* @Date 2022/5/5 11:20
*/
@Configuration
//1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling
// 2.开启定时任务
//
@EnableScheduling // 2.开启定时任务
@Slf4j
public
class
InsureTaskTiming
{
@Autowired
...
...
@@ -37,11 +39,12 @@ public class InsureTaskTiming {
@Autowired
private
YgglMainEmpMapper
ygglMainEmpMapper
;
@Conditional
(
SchedulerCondition
.
class
)
//定时器开关
@Scheduled
(
cron
=
"0/1 0 0 * * ?"
)
//每月第一天
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateInsureStatusTask
(){
try
{
log
.
info
(
"保单定时器"
);
Date
now
=
DateUtil
.
date
();
/*获取正常的保单*/
List
<
InsurePolicy
>
insurePolicyList
=
InsurePolicy
.
builder
().
build
().
selectList
(
new
QueryWrapper
<
InsurePolicy
>().
lambda
().
eq
(
InsurePolicy:
:
getStatus
,
"1"
).
lt
(
InsurePolicy:
:
getPolicyDateEnd
,
now
));
...
...
src/main/java/cn/timer/api/controller/kqgl/ClockInController.java
View file @
d3b83848
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/controller/kqgl/atttimer/AttendanceTaskTiming.java
View file @
d3b83848
...
...
@@ -10,8 +10,10 @@ import java.util.Date;
import
java.util.List
;
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.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -61,7 +63,7 @@ import cn.timer.api.utils.DateUtil;
* 考勤报表汇总数据
*/
@Configuration
//1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling
// 2.开启定时任务
//
@EnableScheduling // 2.开启定时任务
@Slf4j
public
class
AttendanceTaskTiming
{
...
...
@@ -93,13 +95,14 @@ public class AttendanceTaskTiming{
// @Scheduled(cron = "0 */2 * * * ?")
// @Scheduled(cron = "0 25 11 * * ?")
@Conditional
(
SchedulerCondition
.
class
)
//定时器开关
@Scheduled
(
cron
=
"0 0 8,12,16,20 * * ?"
)
//每天上午8、12点,下午16点,20点 执行
public
void
AttendanceTask
()
throws
ParseException
{
boolean
implement
=
true
;
//逻辑
if
(
implement
)
{
log
.
info
(
"AttendanceTask考勤数据统计开始"
);
Calendar
c
=
Calendar
.
getInstance
();
c
.
add
(
Calendar
.
MONTH
,
0
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
//设置为1号,当前日期既为本月第一天
...
...
src/main/java/cn/timer/api/controller/kqgl/atttimer/LastMonthtimingExport.java
View file @
d3b83848
...
...
@@ -10,7 +10,10 @@ import java.util.Date;
import
java.util.List
;
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.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -59,8 +62,9 @@ import cn.timer.api.utils.DateUtil;
/**
* @author Yl123 上月数据
*/
@Slf4j
@Configuration
//1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling
// 2.开启定时任务
//@Conditional(SchedulerCondition.class) //定时器开关
public
class
LastMonthtimingExport
{
@Autowired
private
KqglMainKqzMapper
kqglmainkqzmapper
;
...
...
@@ -89,12 +93,13 @@ public class LastMonthtimingExport {
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 0 4,20 * * ?"
)
//每天上午4点,下午20点 执行
@Scheduled
(
cron
=
"0 0 4,20 * * ?"
)
//每天上午4点,下午20点 执行
public
void
LastMonthtimingAttendanceTask
()
throws
ParseException
{
log
.
info
(
"=======================================上月数据定时任务开始======================================="
);
//获取前月的最后一天
Calendar
cale
=
Calendar
.
getInstance
();
cale
.
set
(
Calendar
.
DAY_OF_MONTH
,
0
);
//设置为1号,当前日期既为本月第一天
...
...
src/main/java/cn/timer/api/controller/xcgl/atttimer/SalaryTaskTiming.java
View file @
d3b83848
...
...
@@ -13,9 +13,12 @@ import java.util.Locale;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.timer.api.bean.xcgl.XcglAssoXzdadx
;
import
cn.timer.api.bean.xcgl.XcglAssoXzdaz
;
import
cn.timer.api.config.schedule.SchedulerCondition
;
import
cn.timer.api.dao.xcgl.XcglAssoXzdadxMapper
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -65,16 +68,18 @@ import javax.annotation.Resource;
*/
//@Component
//@Lazy
@Slf4j
@Configuration
//1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling
// 2.开启定时任务
//
@EnableScheduling // 2.开启定时任务
public
class
SalaryTaskTiming
{
// 薪酬管理-定薪
@Resource
private
XcglAssoXzdadxMapper
xcglassoxzdadxmapper
;
//3.添加定时任务 每天凌晨1点执行一次
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
@Conditional
(
SchedulerCondition
.
class
)
//定时器开关
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
//3.添加定时任务 每天凌晨1点执行一次
public
void
AttendanceTask
()
throws
ParseException
{
log
.
info
(
"调薪记录生效定时任务"
);
// 使用状态(0:使用中;1:历史, 2: 未生效)
// 当前日期
String
curDate
=
DateUtil
.
getStringFormat
(
new
Date
().
getTime
());
...
...
src/main/resources/application-pro.yml
View file @
d3b83848
...
...
@@ -101,7 +101,7 @@ spring:
protocol
:
smtp
host
:
smtp.163.com
username
:
youlingrc123@163.com
password
:
RIMBNJJQNKYNVUWL
password
:
youlingrc189
default-encoding
:
utf-8
properties
:
mail
:
...
...
@@ -164,8 +164,8 @@ pagehelper:
#showSql
logging
:
level
:
root
:
ERROR
cn.timer.api.dao
:
error
root
:
INFO
cn.timer.api.dao
:
info
pattern
:
console
:
'
--%p--%m%n'
...
...
src/main/resources/application.yml
View file @
d3b83848
spring
:
profiles
:
active
:
dev
active
:
pro
#active: '@environment@'
enable
:
scheduling
:
false
src/main/resources/config/cron.setting
View file @
d3b83848
# 我是合同证照
[cn.timer.api.utils]
TimerUtil.start = 0/10 0 0 0 0 1/5
TimerUtil.start = 0/10 0 0 0 0 1/5
src/main/resources/logback-spring.xml
View file @
d3b83848
...
...
@@ -69,7 +69,7 @@
<!--用来指定日志文件的上限大小,那么到了这个值,就会删除旧的日志 -->
<!--<totalSizeCap>1GB</totalSizeCap> -->
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
10
0
MB
</maxFileSize>
<maxFileSize>
10
24
MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!--日志输出编码格式化 -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment