ソースを参照

增加定时任务

zhangyang 2 年 前
コミット
7a158f1ef2

+ 23 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SpringTaskConfig.java

@@ -0,0 +1,23 @@
+package com.ruoyi.web.controller.common;
+
+
+import com.ruoyi.system.mapper.PoTetherMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.util.Date;
+
+@Configuration
+@EnableScheduling
+public class SpringTaskConfig {
+    @Autowired
+    PoTetherMapper poTetherMapper;
+
+    @Scheduled(cron = "0/5 * * * * ?")
+    public  void cron() {
+      Integer i =  poTetherMapper.updateSellStatus();
+      System.out.println(i);
+    }
+}

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PoTetherMapper.java

@@ -156,4 +156,6 @@ public interface PoTetherMapper extends BaseMapper<PoTether>
      * @param tetherVo
      */
     void updateShowTimeEnd(TetherVo tetherVo);
+
+    Integer updateSellStatus();
 }

+ 8 - 0
ruoyi-system/src/main/resources/mapper/system/PoTetherMapper.xml

@@ -296,5 +296,13 @@
         </trim>
         where tether_id = #{tetherId}
     </update>
+
+    <update id="updateSellStatus">
+        update po_tether set sell_status =
+            case when now() > show_time_end then 2
+                 when show_time_start > now() then 1
+                 when now() > show_time_start and show_time_end > now() then 0
+                 END;
+    </update>
 </mapper>