소스 검색

Merge branch 'master' into feature-blank

liying 7 년 전
부모
커밋
ce11f3682a

+ 1 - 14
sql/cinema.sql

@@ -358,17 +358,4 @@ UNLOCK TABLES;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 
--- Dump completed on 2019-04-24 21:20:52
-
--- 定时任务
-show variables like '%sche%';
-set global event_scheduler =1;
-CREATE PROCEDURE cancel ()
-  update ticket SET  state =2 WHERE minute(timediff(now(),time))>15 and state=0;
-create event if not exists e_cancel
-  on schedule every 30 second
-  on completion preserve
-do call cancel();
-
-alter event e_cancel ON
-COMPLETION PRESERVE ENABLE;
+-- Dump completed on 2019-04-24 21:20:52

+ 2 - 0
src/main/java/com/example/cinema/CinemaApplication.java

@@ -2,7 +2,9 @@ package com.example.cinema;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
+@EnableScheduling
 @SpringBootApplication
 public class CinemaApplication {
 

+ 4 - 0
src/main/java/com/example/cinema/data/sales/TicketMapper.java

@@ -3,6 +3,7 @@ package com.example.cinema.data.sales;
 import com.example.cinema.po.Ticket;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.scheduling.annotation.Scheduled;
 
 import java.util.List;
 
@@ -27,5 +28,8 @@ public interface TicketMapper {
     Ticket selectTicketById(int id);
 
     List<Ticket> selectTicketByUser(int userId);
+
+    @Scheduled(cron = "0/1 * * * * ?")
+    void cleanExpiredTicket();
 }
 

+ 4 - 0
src/main/resources/dataImpl/sales/TicketMapper.xml

@@ -52,4 +52,8 @@
         <result column="time" property="time"></result>
     </resultMap>
 
+    <update id="cleanExpiredTicket">
+        update ticket SET  state =2 WHERE minute(timediff(now(),time))>15 and state=0;
+    </update>
+
 </mapper>