定时任务Scheduled

package com.ruoyi;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
 * 启动程序
 * 
 * @author ruoyi
 */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@MapperScan("com.ruoyi.file2.web.dao,com.ruoyi.file3.dao,com.ruoyi.file3.log.dao,com.ruoyi.file3.storage.local.LocalStorageProcessor")
@EnableAsync
public class RuoYiApplication
{
    public static void main(String[] args)
    {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(RuoYiApplication.class, args);
        System.out.println("(♥◠‿◠)ノ゙  VR项目启动成功   ლ(´ڡ`ლ)゙  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }

    /**
     * 文件上传配置
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize(DataSize.parse("1000MB")); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(DataSize.parse("1000MB"));
        return factory.createMultipartConfig();
    }

}
@RestController
@RequestMapping("/videoInfoRecords/videoInfoRecords")
@EnableScheduling
public class VideoInfoRecordsController extends BaseController {
    @Autowired
    private IVideoInfoRecordsService videoInfoRecordsService;

    /**
     * 时长超过三十秒,该条观看记录结束
     */
    @Scheduled(cron = "*/1 * * * * ?") //每个1秒进行查询
    public void updateWatchVideoStatus() {
        VideoInfoRecords videoInfoRecords = new VideoInfoRecords();
        videoInfoRecords.setStatus("未退出");
        List<VideoInfoRecords> list = videoInfoRecordsService.selectVideoInfoRecordsList(videoInfoRecords);
        for (VideoInfoRecords infoRecords : list) {
            //如果更新时间大于时间30S,则更改状态
            Date updateTime = infoRecords.getUpdateTime();
            long diffTime = System.currentTimeMillis() - updateTime.getTime(); //获得是毫秒间隔
            if(diffTime>30000){
                infoRecords.getId();
                infoRecords.setStatus("已退出");
                videoInfoRecordsService.updateVideoInfoRecords(infoRecords);
            }
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值