• 定时任务

  需求:按每日统计点赞数、评论数、热度的增加量(不是现有量)

1.每天零点执行:首先遍历出user的统计字段

然后插入到新创建的表中。

2.每天一点执行:根据时间段将两表的数据相减
创建增量字段,更新记录下来

package com.xgt.task;

import com.xgt.bean.StatisticsUserBean;
import com.xgt.bean.UserBean;
import com.xgt.dao.entity.StatisticsUser;
import com.xgt.dao.entity.User;
import com.xgt.service.StatisticsService;
import com.xgt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import java.util.List; /**
* Created by Administrator on 2017/8/14.
*/
@Component//当组件不好归类的时候,我们可以使用这个注解进行标注。
@Configurable//自动注入bean
@EnableScheduling//开启计划任务的支持。
public class StatisticsUserStorage {
@Autowired
private UserService userService;
@Autowired
private StatisticsService statisticsService;
@Scheduled(cron = "0 0 0 * * ?")//每天零点执行
private void initialStatistics(){
List<User> statisticsList = statisticsService.selectUserAsStatistics();
for (User statistics:statisticsList){
UserBean user = new UserBean();
user.setUserId(String.valueOf(statistics.getUserId()));
user.setHeat(statistics.getHeat());
user.setLikeCount(statistics.getLikeCount());
user.setShareTimes(statistics.getShareTimes());
statisticsService.insertStatistics(user);
} }
@Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点执行
private void generateStatistics(){
List<StatisticsUser> statisticsUserList = statisticsService.subtractTwoTables();
for (StatisticsUser statisticsUser:statisticsUserList){
StatisticsUserBean statisticsUserBean = new StatisticsUserBean();
statisticsUserBean.setLikeCountIncrement(statisticsUser.getLikeCountIncrement());
statisticsUserBean.setHeatIncrement(statisticsUser.getHeatIncrement());
statisticsUserBean.setShareTimesIncrement(statisticsUser.getShareTimesIncrement());
statisticsService.updateStatistics(statisticsUserBean);
}
}
}

Springboot+resteasy定时任务的更多相关文章

  1. 玩转SpringBoot之定时任务详解

    序言 使用SpringBoot创建定时任务非常简单,目前主要有以下三种创建方式: 一.基于注解(@Scheduled) 二.基于接口(SchedulingConfigurer) 前者相信大家都很熟悉, ...

  2. SpringBoot 配置定时任务

    SpringBoot启用定时任务,其内部集成了成熟的框架,因此我们可以很简单的使用它. 开启定时任务 @SpringBootApplication //设置扫描的组件的包 @ComponentScan ...

  3. SpringBoot - 添加定时任务

    SpringBoot 添加定时任务 EXample1: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spri ...

  4. springboot之定时任务

    定时线程 说到定时任务,通常会想到JDK自带的定时线程来执行,定时任务. 回顾一下定时线程池. public static ScheduledExecutorService newScheduledT ...

  5. SpringBoot整合定时任务和异步任务处理 3节课

    1.SpringBoot定时任务schedule讲解   定时任务应用场景: 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类        ...

  6. 十三、springboot集成定时任务(Scheduling Tasks)

    定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...

  7. SpringBoot创建定时任务

    之前总结过spring+quartz实现定时任务的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot创建定时任务则是相当简单. (1 ...

  8. springboot开启定时任务 添加定时任务 推送

    最近在自学Java的springboot框架,要用到定时推送消息.参考了网上的教程,自己调试,终于调好了.下面将网上的教程归纳下,总结复习下.  springboot开启定时任务  在SpringBo ...

  9. (入门SpringBoot)SpringBoot结合定时任务task(十)

    SpringBoot整合定时任务task 使用注解EnableScheduling在启动类上. 定义@Component作为组件被容器扫描. 表达式生成地址:http://cron.qqe2.com ...

随机推荐

  1. 有关Android插件化思考

    最近几年移动开发业界兴起了「 插件化技术 」的旋风,各个大厂都推出了自己的插件化框架,各种开源框架都评价自身功能优越性,令人目不暇接.随着公司业务快速发展,项目增多,开发资源却有限,如何能在有限资源内 ...

  2. 如是使用JS实现页面内容随机显示

    之前有个客户咨询我,因为他们公司的业务员有多个人,但公司网站的联系方式板块里只够放一个人的信息,所以就想能不能实现这个联系方式信息随机显示,对于业务或客服人员来说也能做到分配均匀公平.本文我们将和大家 ...

  3. bash脚本编程---循环

    bash为过程式编程语言 代码执行顺序: 1.顺序执行:逐条执行 2.选择执行:代码有一个分支,条件满足时才会执行                       两个或以上的分支,只会执行其中一个满足条 ...

  4. runtime实现对象存储型数据库——LHDB

    前言 最近在GitHub上看了一份关于基于runtime封装的对象存储型数据库的开源代码,觉得非常值得分享记录一下,在IOS中对数据库的操作一般通过CoreData和SQLite,CoreData 虽 ...

  5. (转)java提高篇(一)-----理解java的三大特性之封装

    从大二接触java开始,到现在也差不多三个年头了.从最基础的HTML.CSS到最后的SSH自己都是一步一个脚印走出来的,其中开心过.失落过.寂寞过.虽然是半道出家但是经过自己的努力也算是完成了“学业” ...

  6. Python学习记录----IDE安装

    摘要: 安装eric5 一 确定python版本 安装的最新版本:python3.3 下载连接:http://www.python.org/getit/ 二 确定pyqt版本 安装的最新版本:PyQt ...

  7. java核心技术面试整理

    [前方高能,是这半年BAT,京东,远景,华为,中兴以及苏研发中心被问到的Java公共问题的一个整理] ------------------------------------------------- ...

  8. SSE再学习:灵活运用SIMD指令6倍提升Sobel边缘检测的速度(4000*3000的24位图像时间由180ms降低到30ms)。

    这半年多时间,基本都在折腾一些基本的优化,有很多都是十几年前的技术了,从随大流的角度来考虑,研究这些东西在很多人看来是浪费时间了,即不能赚钱,也对工作能力提升无啥帮助.可我觉得人类所谓的幸福,可以分为 ...

  9. python列表反转

    使用reverse来让列表反转特别方便, 没事自己写了几种方式 In [59]: def reverse(nums): length = len(nums) for i in range(length ...

  10. ue4 C++ 编程 通过三个点的位置算出夹角

    const FVector2D& Pt1 = 第一个点的位置; const FVector2D& Pt2 = 第二个点的位置; float EdgeRadians1 = FMath:: ...