ソースを参照

赛事-关闭报名

lyq 5 ヶ月 前
コミット
091f960f05

+ 27 - 7
qmjszx-business/src/main/java/beilv/competition/service/impl/CompetitionServiceImpl.java

@@ -5,13 +5,15 @@ import beilv.common.utils.ShiroUtils;
 import beilv.competition.domain.Competition;
 import beilv.competition.mapper.CompetitionMapper;
 import beilv.competition.service.ICompetitionService;
-import beilv.stadium.domain.Stadium;
+import beilv.competition.task.CloseReg;
 import beilv.stadium.mapper.StadiumMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.util.Date;
 import java.util.List;
+import java.util.Timer;
 
 /**
  * 赛事发布Service业务层处理
@@ -21,6 +23,7 @@ import java.util.List;
  */
 @Service
 public class CompetitionServiceImpl implements ICompetitionService {
+
     @Autowired
     private CompetitionMapper competitionMapper;
 
@@ -32,6 +35,24 @@ public class CompetitionServiceImpl implements ICompetitionService {
     private final static String BAO_MING_JIE_SHU = "competiton_state_3";
     private final static String YI_GUAN_BI = "competiton_state_4";
 
+    @PostConstruct
+    public void init() {
+        // 找到所有报名中的赛事
+        Competition competition = new Competition();
+        competition.setCompetitionState("competiton_state_2");
+        List<Competition> competitionList = this.selectCompetitionList(competition);
+        competitionList.forEach(item -> {
+            Date date = new Date(item.getApplyStartTime().getTime() - (long) (item.getApplyBeforeTime() * 60 * 60 * 1000));
+            if (new Date().getTime() >= date.getTime()) {
+                item.setCompetitionState("competiton_state_3");
+                competitionMapper.updateCompetition(item);
+            } else {
+                Timer timer = new Timer();
+                timer.schedule(new CloseReg(competitionMapper, item.getId()), date);
+            }
+        });
+    }
+
     /**
      * 查询赛事发布
      *
@@ -113,24 +134,23 @@ public class CompetitionServiceImpl implements ICompetitionService {
         competition.setPublishName(ShiroUtils.getSysUser().getUserName());
         competition.setId(Integer.valueOf(id));
         competition.setCompetitionState(BAO_MING_ZHONG);
+        Timer timer = new Timer();
+        timer.schedule(new CloseReg(competitionMapper, Integer.parseInt(id)), new Date(competition.getApplyStartTime().getTime() - (long) (competition.getApplyBeforeTime() * 60 * 1000)));
         return competitionMapper.publishCompetition(competition);
     }
 
     @Override
     public int closeCompetitionById(String id) {
-
-        //查询是否存在为退款的订单
-        if(competitionMapper.selectStadumIsOpenById(id)){
+        // 查询是否存在为退款的订单
+        if (competitionMapper.selectStadumIsOpenById(id)) {
             //修改赛事状态
             Competition competition = new Competition();
             competition.setId(Integer.valueOf(id));
             competition.setCompetitionState(YI_GUAN_BI);
             return competitionMapper.publishCompetition(competition);
-        }else{
+        } else {
             return 0;
         }
-
-
     }
 
     @Override

+ 26 - 0
qmjszx-business/src/main/java/beilv/competition/task/CloseReg.java

@@ -0,0 +1,26 @@
+package beilv.competition.task;
+
+import beilv.competition.domain.Competition;
+import beilv.competition.mapper.CompetitionMapper;
+
+import java.util.TimerTask;
+
+public class CloseReg extends TimerTask {
+
+    private CompetitionMapper competitionMapper;
+
+    private Integer id;
+
+    public CloseReg(CompetitionMapper competitionMapper, Integer id) {
+        this.competitionMapper = competitionMapper;
+        this.id = id;
+    }
+
+    @Override
+    public void run() {
+        Competition competition = new Competition();
+        competition.setId(id);
+        competition.setCompetitionState("competiton_state_3");
+        this.competitionMapper.updateCompetition(competition);
+    }
+}