定时任务
来源:互联网 发布:2016黑马java百度网盘 编辑:程序博客网 时间:2024/06/05 13:22
<!-- 注册bean -->
<bean id="expireJob" class="lb.rest.timer.ExpireJob"></bean>
<bean id="siteSettleJob" class="lb.rest.timer.SiteSettleJob"></bean>
<bean id="interestsJob" class="lb.rest.timer.InterestsJob"></bean>
<bean id="shouldPayableJob" class="lb.rest.timer.ShouldPayableJob"></bean>
<!-- 开启任务调度 -->
<task:scheduled-tasks>
<task:scheduled ref="interestsJob" method="run" cron="0 0 1 * * ?" />
<!--
<task:scheduled ref="expireJob" method="run" cron="0 30 1 * * ?" />
-->
<task:scheduled ref="expireJob" method="run" cron="0 0 3 * * ?" />
<task:scheduled ref="siteSettleJob" method="run" cron="0 0 2 * * ?" />
<task:scheduled ref="shouldPayableJob" method="run" cron="0 0 */6 * * ?" />
</task:scheduled-tasks>
<context:component-scan base-package="lb.rest.timer"/>
////////////////////////////////////////////////////////////////
package lb.rest.timer;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.springframework.beans.factory.annotation.Autowired;
import com.mlb.exception.WebApiException;
import fc.wpf.rest.web.bean.ReturnInfo;
import lb.rest.bank.db.dao.InterestDao;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class InterestsJob {
@Autowired
private InterestDao interestDao;
public ReturnInfo run() {
log.info("定时任务开始!");
try {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
Date nowDate = new Date();
Date strBeginDate = this.getDate(nowDate, -1);
Date beginDate = sf.parse(sf.format(strBeginDate));
Date endDate = sf.parse(sf.format(nowDate));
log.info("利息计算的期间------起始时间:{},结束时间:{}",beginDate,endDate);
interestDao.calculateInterest(beginDate,endDate);
} catch(WebApiException w){
return new ReturnInfo(w.getMessage(),1000,null,false);
}catch (Exception e) {
e.printStackTrace();
return ReturnInfo.Faild;
}
return ReturnInfo.Faild;
}
/*计算获取时间
* beginDate 起始时间
* inrDate 增加或减少时间 -inrDate表示减少时间
*/
private Date getDate(Date beginDate,int inrDate){
if(beginDate != null){
Calendar calendar = new GregorianCalendar();
calendar.setTime(beginDate);
calendar.add(Calendar.DATE,inrDate);
Date afterDate=calendar.getTime();
return afterDate;
}else{
return new Date();
}
}
}
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 定时任务
- 遇见Lost connection to MySQL server at 'reading initial communication packet',system error:0的解决办法
- mybatis oracle获取插入的主键
- 数据结构第九周项目一-二叉树算法库
- css字符编码
- 关于二进制算法和运算符++,-- 的理解
- 定时任务
- Java项目问题集锦
- shiro 重写 token 配置到xml中
- 排序算法【java实现】(二)冒泡排序和简单选择排序
- 用例图
- pyspark使用anaconda后spark-submit方法
- java爬虫代理
- 色彩表示与编码
- linux OOM killer分析