Commit 04001f88 authored by wangyihao's avatar wangyihao

添加 定时任务 动态配置

parent c77e605f
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.setIsAvailable(1);
Store store = new Store();
store.setIsShopping(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.setIsAvailable(0);
for (Store list : storeList) {
if (date.getTime() > list.getMatureTime().getTime()) {
list.setIsShopping(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分钟执行一次。结束。");
}
}
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