张延森 4 years ago
parent
commit
7232b00402

+ 2
- 0
src/main/java/com/xiaoniu/niucai/mapper/TaMatchMapper.java View File

@@ -18,4 +18,6 @@ import java.util.List;
18 18
 @Mapper
19 19
 public interface TaMatchMapper extends BaseMapper<TaMatch> {
20 20
     List<TaMatch> getLastOpenAndUndoMatch(@Param("days") int days) throws Exception;
21
+
22
+    List<TaMatch> getLastExcAndUndoMatch(@Param("hours") int hours) throws Exception;
21 23
 }

+ 2
- 0
src/main/java/com/xiaoniu/niucai/service/ITaCustomerBettingSportService.java View File

@@ -16,4 +16,6 @@ import java.util.List;
16 16
 public interface ITaCustomerBettingSportService extends IService<TaCustomerBettingSport> {
17 17
 
18 18
     List<TaCustomerBettingSport> getListByBetting(Integer bettingId, Integer itemNo) throws Exception;
19
+
20
+    boolean updateExcDrawnOdds(Integer bettingId, Integer itemNo) throws Exception;
19 21
 }

+ 2
- 0
src/main/java/com/xiaoniu/niucai/service/ITaMatchService.java View File

@@ -13,4 +13,6 @@ import com.xiaoniu.niucai.entity.TaMatch;
13 13
  */
14 14
 public interface ITaMatchService extends IService<TaMatch> {
15 15
     void checkAndSetSportPrize() throws Exception;
16
+
17
+    void checkExcMatches() throws Exception;
16 18
 }

+ 12
- 0
src/main/java/com/xiaoniu/niucai/service/impl/TaCustomerBettingSportServiceImpl.java View File

@@ -1,6 +1,7 @@
1 1
 package com.xiaoniu.niucai.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
4 5
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 6
 import com.xiaoniu.niucai.service.ITaCustomerBettingSportService;
6 7
 import com.xiaoniu.niucai.entity.TaCustomerBettingSport;
@@ -29,4 +30,15 @@ public class TaCustomerBettingSportServiceImpl extends ServiceImpl<TaCustomerBet
29 30
 
30 31
         return list(queryWrapper);
31 32
     }
33
+
34
+    @Override
35
+    public boolean updateExcDrawnOdds(Integer bettingId, Integer itemNo) throws Exception {
36
+        UpdateWrapper<TaCustomerBettingSport> updateWrapper = new UpdateWrapper<>();
37
+        updateWrapper.set("odds_drawn", 1);
38
+        updateWrapper.set("is_winning", 1);
39
+        updateWrapper.eq("betting_id", bettingId);
40
+        updateWrapper.eq("item_no", itemNo);
41
+
42
+        return update(updateWrapper);
43
+    }
32 44
 }

+ 48
- 0
src/main/java/com/xiaoniu/niucai/service/impl/TaMatchServiceImpl.java View File

@@ -71,6 +71,7 @@ public class TaMatchServiceImpl extends ServiceImpl<TaMatchMapper, TaMatch> impl
71 71
                 taMatch.setOpeningStatus(SportOpeningStatusEnum.FINISHED.getCode());
72 72
                 updateById(taMatch);
73 73
             } catch (Exception e) {
74
+                e.printStackTrace();
74 75
                 // TODO 比如错误日志记录
75 76
                 taMatch.setOpeningStatus(SportOpeningStatusEnum.READY.getCode());
76 77
                 updateById(taMatch);
@@ -78,6 +79,53 @@ public class TaMatchServiceImpl extends ServiceImpl<TaMatchMapper, TaMatch> impl
78 79
         }
79 80
     }
80 81
 
82
+    /**
83
+     * 如果有比赛取消或者异常。那么等待 36 小时。
84
+     * 如果 36 小时之后还是异常。那么本场比赛赔率按 1 算
85
+     * @throws Exception
86
+     */
87
+    @Override
88
+    public void checkExcMatches() throws Exception {
89
+        List<TaMatch> matchList = taMatchMapper.getLastExcAndUndoMatch(36);
90
+        if (null == matchList || matchList.size() == 0) {
91
+            log.info("未检测到有待处理的异常比赛");
92
+            return;
93
+        }
94
+
95
+        for (TaMatch taMatch : matchList) {
96
+            try {
97
+                taMatch.setOpeningStatus(SportOpeningStatusEnum.DOING.getCode());
98
+                updateById(taMatch);
99
+                validateExcMatch(taMatch);
100
+                taMatch.setOpeningStatus(SportOpeningStatusEnum.FINISHED.getCode());
101
+                updateById(taMatch);
102
+            } catch (Exception e) {
103
+                e.printStackTrace();
104
+                // TODO 比如错误日志记录
105
+                taMatch.setOpeningStatus(SportOpeningStatusEnum.READY.getCode());
106
+                updateById(taMatch);
107
+            }
108
+        }
109
+    }
110
+
111
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
112
+    private void validateExcMatch(TaMatch taMatch) throws Exception {
113
+        // 获取当前比赛的投注列表
114
+        List<TaCustomerBettingItem> bettingItemList = iTaCustomerBettingItemService.getByMatch(taMatch);
115
+        if (null == bettingItemList || bettingItemList.size() == 0) {
116
+            return;
117
+        }
118
+
119
+        for (TaCustomerBettingItem item: bettingItemList) {
120
+            item.setIsWinning(true);
121
+            item.setOpeningStatus(SportOpeningStatusEnum.FINISHED.getCode());
122
+            iTaCustomerBettingItemService.updateById(item);
123
+
124
+            // 更新赔率为 1
125
+            iTaCustomerBettingSportService.updateExcDrawnOdds(item.getBettingId(), item.getItemNo());
126
+        }
127
+    }
128
+
81 129
     /**
82 130
      * 校验比赛
83 131
      * @param taMatch

+ 9
- 1
src/main/java/com/xiaoniu/niucai/task/Lottery.java View File

@@ -30,12 +30,20 @@ public class Lottery {
30 30
             log.error("校验数字彩开奖结果错误: {}", e.getMessage());
31 31
         }
32 32
 
33
-        // 体彩
33
+        // 体彩中奖
34 34
         try {
35 35
             iTaMatchService.checkAndSetSportPrize();
36 36
         } catch (Exception e) {
37 37
             e.printStackTrace();
38 38
             log.error("校验体彩开奖结果错误: {}", e.getMessage());
39 39
         }
40
+
41
+        // 体彩异常比赛
42
+        try {
43
+            iTaMatchService.checkExcMatches();
44
+        } catch (Exception e) {
45
+            e.printStackTrace();
46
+            log.error("校验异常比赛错误: {}", e.getMessage());
47
+        }
40 48
     }
41 49
 }

+ 13
- 0
src/main/resources/mapper/TaMatchMapper.xml View File

@@ -14,4 +14,17 @@
14 14
         ORDER BY
15 15
             t.match_id ASC
16 16
     </select>
17
+
18
+    <select id="getLastExcAndUndoMatch" resultType="com.xiaoniu.niucai.entity.TaMatch">
19
+        SELECT
20
+            *
21
+        FROM
22
+        ta_match t
23
+        WHERE
24
+            t.`status` &gt; 3
25
+            AND t.opening_status = 0
26
+            AND CONCAT(t.match_date, ' ', t.match_time) &lt; DATE_FORMAT( DATE_SUB(now(), INTERVAL #{hours} HOUR), '%Y-%m-%d %H:%i' )
27
+        ORDER BY
28
+            t.match_id ASC
29
+    </select>
17 30
 </mapper>