Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
store-system
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
luoyangfei
store-system
Commits
04001f88
Commit
04001f88
authored
Nov 16, 2018
by
wangyihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 定时任务 动态配置
parent
c77e605f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
16 deletions
+51
-16
StoreTimeTask.java
.../main/java/cn/com/fqy/common/timedTask/StoreTimeTask.java
+51
-16
No files found.
2code/server/store-system/src/main/java/cn/com/fqy/common/timedTask/StoreTimeTask.java
View file @
04001f88
package
cn
.
com
.
fqy
.
common
.
timedTask
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -7,7 +8,13 @@ import javax.annotation.Resource;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.scheduling.Trigger
;
import
org.springframework.scheduling.TriggerContext
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.SchedulingConfigurer
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
org.springframework.scheduling.support.CronTrigger
;
import
org.springframework.stereotype.Component
;
import
cn.com.fqy.common.Operator
;
...
...
@@ -16,40 +23,68 @@ import cn.com.fqy.common.constants.Constant;
import
cn.com.fqy.core.model.Query
;
import
cn.com.fqy.core.model.Store
;
import
cn.com.fqy.core.service.StoreService
;
import
cn.com.fqy.core.service.SysParamService
;
@Component
public
class
StoreTimeTask
{
@EnableScheduling
public
class
StoreTimeTask
implements
SchedulingConfigurer
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
StoreTimeTask
.
class
);
public
static
String
cron
;
@Resource
private
StoreService
storeService
;
@Resource
private
SysParamService
sysParamService
;
@Override
public
void
configureTasks
(
ScheduledTaskRegistrar
taskRegistrar
)
{
cron
=
sysParamService
.
getParamValueByParamKey
(
"QUARTZ_TASK"
);
Runnable
task
=
new
Runnable
()
{
@Override
public
void
run
()
{
// 任务逻辑代码部分.
store
();
}
};
Trigger
trigger
=
new
Trigger
()
{
@Override
public
Date
nextExecutionTime
(
TriggerContext
triggerContext
)
{
// 任务触发,可修改任务的执行周期.
// 每一次任务触发,都会执行这里的方法一次,重新获取下一次的执行时间
cron
=
sysParamService
.
getParamValueByParamKey
(
"QUARTZ_TASK"
);
CronTrigger
trigger
=
new
CronTrigger
(
cron
);
Date
nextExec
=
trigger
.
nextExecutionTime
(
triggerContext
);
return
nextExec
;
}
};
taskRegistrar
.
addTriggerTask
(
task
,
trigger
);
}
@Scheduled
(
cron
=
"* 0/30
* * * ?"
)
// @Scheduled(cron = "0/10 *
* * * ?")
public
void
store
()
{
log
.
info
(
"+++++++++++++++++++++++++++++++++++++++每分钟执行一次。开始。"
);
Store
store
=
new
Store
();
store
.
setIs
Available
(
1
);
Store
store
=
new
Store
();
store
.
setIs
Shopping
(
1
);
store
.
setIsAuditing
(
1
);
store
.
setIsDeleted
(
0
);
List
<
Store
>
storeList
=
storeService
.
getStoreList
(
new
Query
(
store
));
if
(
storeList
.
size
()>
0
&&
storeList
!=
null
)
{
List
<
Store
>
storeList
=
storeService
.
getStoreList
(
new
Query
(
store
));
if
(
storeList
.
size
()
>
0
&&
storeList
!=
null
)
{
Date
date
=
new
Date
();
for
(
Store
list:
storeList
)
{
if
(
date
.
getTime
()>
list
.
getMatureTime
().
getTime
())
{
list
.
setIs
Available
(
0
);
for
(
Store
list
:
storeList
)
{
if
(
date
.
getTime
()
>
list
.
getMatureTime
().
getTime
())
{
list
.
setIs
Shopping
(
0
);
Operator
op
=
new
Operator
();
ResultInfo
<
Store
>
result
=
storeService
.
updateStore
(
list
,
op
);
if
(
result
.
getCode
().
equals
(
"1"
))
{
ResultInfo
<
Store
>
result
=
storeService
.
updateStore
(
list
,
op
);
if
(
result
.
getCode
().
equals
(
"1"
))
{
result
.
setCode
(
Constant
.
SUCCESS
);
}
else
{
}
else
{
result
.
setCode
(
Constant
.
FAIL
);
}
}
}
}
else
{
}
else
{
log
.
info
(
"++++++++++++++++++++++++++++++++++++++++没有值。"
);
}
log
.
info
(
"++++++++++++++++++++++++++++++++++++++++每30分钟执行一次。结束。"
);
log
.
info
(
"++++++++++++++++++++++++++++++++++++++++每10分钟执行一次。结束。"
);
}
}
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