• 定时任务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);
                }
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
  • 相关阅读:
    计算机网络基础 ARP协议 详详解----看完我的总结你就不用看别人的了!
    数据结构详细笔记——栈与队列
    SSH服务
    时序预测 | MATLAB实现WOA-CNN-LSTM-Attention时间序列预测(SE注意力机制)
    噪声系数与插入损耗
    Linux调试器——gdb的使用
    随想录一刷Day41——动态规划
    深度学习pytorch之hub模块
    【资源推荐】一站式机器学习学习资料
    docker介绍及入门举例
  • 原文地址:https://blog.csdn.net/m0_56095048/article/details/138190023