发表于: 2019-12-10 21:08:00

2 1252


一、今天完成的事

签到页面

package com.jnshu.checkin.controller;

import com.jnshu.checkin.service.CheckinService;
import com.jnshu.model.Student;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author Admin
* @PackageName com.jnshu.checkin.controller
* @ClassName academy-ctrl-wx-provider
* @Description
* @create 2019-12-10 11:21
*/
@RestController
@RequestMapping("/wx/checkin")
public class CheckinController {

   @Autowired
   CheckinService checkinService;

   /**
    * 获取签到信息
    * @param student
    * @return
    */
   @GetMapping("/u/getCheckin")
   private Student getCheckin(Student student){
       int totalCheck = checkinService.totalCheck(student.getId());
       student.setTotal_check(totalCheck);
       return checkinService.getStudent(student);
   }

   @Update("/u/checkin")
   private boolean checkin(Student student){

       return true;
   }
}

前台-影像部接口

package com.jnshu.video.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jnshu.model.Video;
import com.jnshu.video.service.WxVideoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
* @author Admin
* @PackageName com.jnshu.academyctrlwebclient.controller
* @ClassName ctrl
* @Description
* @create 2019-11-29 14:05
*/
@RestController
@RequestMapping("/wx/video/a")
public class WxVideoController {

   private static final Logger log= LogManager.getLogger(WxVideoController.class);

   @Autowired
   WxVideoService wxVideoService;

   /**
    * 获取列表
    * @param start
    * @return
    * @throws Exception
    */
   @GetMapping(value = "/u/videoList")
   private PageInfo<Video> getVideoList(@RequestParam(value = "start", defaultValue = "1") int start, Video video)throws Exception{
       PageHelper.startPage(start,10);
       List<Video> videoList = wxVideoService.selectVideoList(video);
       System.out.println(video.getTeacher_name()+"+++++++++++++++++++++++++++++++++++++++");
       System.out.println(video.getTeacher_id()+"+++++++++++++++++++++++++++++++++++++++");
       System.out.println(video.getTeacher_image()+"+++++++++++++++++++++++++++++++++++++++");
       return new PageInfo<>(videoList);
   }

   /**
    * 视频详情
    * @param id
    * @return
    */
   @GetMapping(value = "/u/video")
   private Video getVideo(Long id){
       return wxVideoService.queryVideoById(id);
   }


   /**
    * 收藏
    * @param vid
    * @param sid
    * @return
    */
   @PutMapping(value = "/u/video/updateCollection")
   private boolean updateCollection(Long vid,Long sid){
       if(wxVideoService.queryVideoCollection(vid, sid) == null){
           boolean status = wxVideoService.setVideoCollection(vid,sid);
           if(status){
               Video video = wxVideoService.queryVideoById(vid);
               Long collections =  video.getNumber_of_collections()+1L;
               wxVideoService.setCollection(vid,collections);
               return true;
           }
       }
       return false;
   }

   /**
    *
    * 取消收藏
    * @param vid
    * @param sid
    * @return
    */
   @DeleteMapping(value = "/u/video/cancelCollection")
   private boolean deleteCollection(Long vid,Long sid){
       boolean status = wxVideoService.delVideoCollection(vid,sid);
       if(status){
           Video video = wxVideoService.queryVideoById(vid);
           Long collections =  video.getNumber_of_collections()-1L;
           System.out.println("++++++++++++"+collections);
           wxVideoService.setCollection(vid,collections);
           return true;
       }
       return false;
   }

   /**
    * 点赞
    * @param like
    * @return boolen
    */
   @PutMapping(value = "/u/video")
   private boolean setLike(int like,Long id){
       Video video = wxVideoService.queryVideoById(id);
       if(like!=0){
           like = video.getNumber_of_likes()+1;
       }else {
           like = video.getNumber_of_likes()-1;
       }
       return wxVideoService.setLike(like,id);
   }
}

二、遇到的问题

解决bug

三、收获

什么是Quartz?

Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,完全由Java开发,可以用来执行定时任务,类似于java.util.Timer。但是相较于Timer, Quartz增加了很多功能:

持久性作业 - 就是保持调度定时的状态; 作业管理 - 对调度作业进行有效的管理; 大部分公司都会用到定时任务这个功能。 拿火车票购票来说,当你下单后,后台就会插入一条待支付的task(job),一般是30分钟,超过30min后就会执行这个job,去判断你是否支付,未支付就会取消此次订单;当你支付完成之后,后台拿到支付回调后就会再插入一条待消费的task(job),Job触发日期为火车票上的出发日期,超过这个时间就会执行这个job,判断是否使用等。

在我们实际的项目中,当Job过多的时候,肯定不能人工去操作,这时候就需要一个任务调度框架,帮我们自动去执行这些程序。那么该如何实现这个功能呢?

(1)首先我们需要定义实现一个定时功能的接口,我们可以称之为Task(或Job),如定时发送邮件的task(Job),重启机器的task(Job),优惠券到期发送短信提醒的task(Job),实现接口如下:

(2)有了任务之后,还需要一个能够实现触发任务去执行的触发器,触发器Trigger最基本的功能是指定Job的执行时间,执行间隔,运行次数等。

(3)有了Job和Trigger后,怎么样将两者结合起来呢?即怎样指定Trigger去执行指定的Job呢?这时需要一个Schedule,来负责这个功能的实现。

上面三个部分就是Quartz的基本组成部分:

调度器:Scheduler 任务:JobDetail 触发器:Trigger,包括SimpleTrigger和CronTrigger  

四、明天的计划

前台-签到



返回列表 返回列表
评论

    分享到