张延森 4 年 前
コミット
74d77bb9f8

+ 3
- 0
src/main/java/com/yunzhi/niucai/entity/TaCustomerBettingItem.java ファイルの表示

@@ -51,6 +51,9 @@ public class TaCustomerBettingItem implements Serializable {
51 51
     @ApiModelProperty(value = "中奖金额 单位分")
52 52
     private Integer winAmount;
53 53
 
54
+    @ApiModelProperty("开奖状态 0未处理,1处理中,2已结束")
55
+    private Integer openingStatus;
56
+
54 57
     @ApiModelProperty(value = "创建时间")
55 58
     private LocalDateTime createDate;
56 59
 

+ 3
- 0
src/main/java/com/yunzhi/niucai/entity/TaCustomerBettingSport.java ファイルの表示

@@ -51,6 +51,9 @@ public class TaCustomerBettingSport implements Serializable {
51 51
     @ApiModelProperty(value = "打单赔率")
52 52
     private String oddsPrinted;
53 53
 
54
+    @ApiModelProperty(value = "是否中奖")
55
+    private Boolean isWinning;
56
+
54 57
     @ApiModelProperty(value = "创建时间")
55 58
     private LocalDateTime createDate;
56 59
 

+ 3
- 0
src/main/java/com/yunzhi/niucai/entity/TaMatch.java ファイルの表示

@@ -138,6 +138,9 @@ public class TaMatch implements Serializable {
138 138
     @ApiModelProperty("彩种")
139 139
     private String lotteryId;
140 140
 
141
+    @ApiModelProperty("开奖状态 0未处理,1处理中,2已结束")
142
+    private Integer openingStatus;
143
+
141 144
     /**
142 145
      * 赔率
143 146
      */

+ 16
- 0
src/main/java/com/yunzhi/niucai/enums/SportOpeningStatusEnum.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.niucai.enums;
2
+
3
+
4
+import lombok.AllArgsConstructor;
5
+import lombok.Getter;
6
+
7
+@Getter
8
+@AllArgsConstructor
9
+public enum SportOpeningStatusEnum implements BaseEnum {
10
+    READY(0, "未处理"),
11
+    DOING(1, "处理中"),
12
+    FINISHED(2, "已完成");
13
+
14
+    private Integer code;
15
+    private String desc;
16
+}

+ 4
- 0
src/main/java/com/yunzhi/niucai/mapper/TaCustomerBettingItemMapper.java ファイルの表示

@@ -3,6 +3,9 @@ package com.yunzhi.niucai.mapper;
3 3
 import com.yunzhi.niucai.entity.TaCustomerBettingItem;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
6 9
 
7 10
 /**
8 11
  * <p>
@@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface TaCustomerBettingItemMapper extends BaseMapper<TaCustomerBettingItem> {
17 20
 
21
+    List<TaCustomerBettingItem> getUnDealItems(@Param("matchId") Integer matchId) throws Exception;
18 22
 }

+ 2
- 0
src/main/java/com/yunzhi/niucai/mapper/TaMatchMapper.java ファイルの表示

@@ -28,4 +28,6 @@ public interface TaMatchMapper extends BaseMapper<TaMatch> {
28 28
     List<TaMatch> getMixedMatch(@Param("lottery") String lottery, @Param("status") Integer status) throws Exception;
29 29
 
30 30
     List<TaMatch> getLastResult() throws Exception;
31
+
32
+    List<TaMatch> getLastOpenAndUndoMatch(@Param("days") int days) throws Exception;
31 33
 }

+ 4
- 0
src/main/java/com/yunzhi/niucai/service/ITaCustomerBettingItemService.java ファイルの表示

@@ -2,6 +2,9 @@ package com.yunzhi.niucai.service;
2 2
 
3 3
 import com.yunzhi.niucai.entity.TaCustomerBettingItem;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.yunzhi.niucai.entity.TaMatch;
6
+
7
+import java.util.List;
5 8
 
6 9
 /**
7 10
  * <p>
@@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 16
  */
14 17
 public interface ITaCustomerBettingItemService extends IService<TaCustomerBettingItem> {
15 18
 
19
+    List<TaCustomerBettingItem> getUnDealItems(TaMatch taMatch) throws Exception;
16 20
 }

+ 3
- 0
src/main/java/com/yunzhi/niucai/service/ITaCustomerBettingSportService.java ファイルの表示

@@ -3,6 +3,8 @@ package com.yunzhi.niucai.service;
3 3
 import com.yunzhi.niucai.entity.TaCustomerBettingSport;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 客户投注竞彩明细  服务类
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 15
  */
14 16
 public interface ITaCustomerBettingSportService extends IService<TaCustomerBettingSport> {
15 17
 
18
+    List<TaCustomerBettingSport> getListByBetting(Integer bettingId, Integer itemNo) throws Exception;
16 19
 }

+ 11
- 0
src/main/java/com/yunzhi/niucai/service/impl/TaCustomerBettingItemServiceImpl.java ファイルの表示

@@ -1,11 +1,15 @@
1 1
 package com.yunzhi.niucai.service.impl;
2 2
 
3 3
 import com.yunzhi.niucai.entity.TaCustomerBettingItem;
4
+import com.yunzhi.niucai.entity.TaMatch;
4 5
 import com.yunzhi.niucai.mapper.TaCustomerBettingItemMapper;
5 6
 import com.yunzhi.niucai.service.ITaCustomerBettingItemService;
6 7
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8
+import org.springframework.beans.factory.annotation.Autowired;
7 9
 import org.springframework.stereotype.Service;
8 10
 
11
+import java.util.List;
12
+
9 13
 /**
10 14
  * <p>
11 15
  * 客户投注明细  服务实现类
@@ -17,4 +21,11 @@ import org.springframework.stereotype.Service;
17 21
 @Service
18 22
 public class TaCustomerBettingItemServiceImpl extends ServiceImpl<TaCustomerBettingItemMapper, TaCustomerBettingItem> implements ITaCustomerBettingItemService {
19 23
 
24
+    @Autowired
25
+    TaCustomerBettingItemMapper taCustomerBettingItemMapper;
26
+
27
+    @Override
28
+    public List<TaCustomerBettingItem> getUnDealItems(TaMatch taMatch) throws Exception {
29
+        return taCustomerBettingItemMapper.getUnDealItems(taMatch.getMatchId());
30
+    }
20 31
 }

+ 12
- 0
src/main/java/com/yunzhi/niucai/service/impl/TaCustomerBettingSportServiceImpl.java ファイルの表示

@@ -1,11 +1,14 @@
1 1
 package com.yunzhi.niucai.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.yunzhi.niucai.entity.TaCustomerBettingSport;
4 5
 import com.yunzhi.niucai.mapper.TaCustomerBettingSportMapper;
5 6
 import com.yunzhi.niucai.service.ITaCustomerBettingSportService;
6 7
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 8
 import org.springframework.stereotype.Service;
8 9
 
10
+import java.util.List;
11
+
9 12
 /**
10 13
  * <p>
11 14
  * 客户投注竞彩明细  服务实现类
@@ -17,4 +20,13 @@ import org.springframework.stereotype.Service;
17 20
 @Service
18 21
 public class TaCustomerBettingSportServiceImpl extends ServiceImpl<TaCustomerBettingSportMapper, TaCustomerBettingSport> implements ITaCustomerBettingSportService {
19 22
 
23
+    @Override
24
+    public List<TaCustomerBettingSport> getListByBetting(Integer bettingId, Integer itemNo) throws Exception {
25
+        QueryWrapper<TaCustomerBettingSport> queryWrapper = new QueryWrapper<>();
26
+        queryWrapper.eq("betting_id", bettingId);
27
+        queryWrapper.eq("item_no", itemNo);
28
+        queryWrapper.orderByAsc("create_date");
29
+
30
+        return list(queryWrapper);
31
+    }
20 32
 }

+ 2
- 0
src/main/java/com/yunzhi/niucai/service/impl/TaLotteryResultServiceImpl.java ファイルの表示

@@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
14 14
 import lombok.extern.slf4j.Slf4j;
15 15
 import org.springframework.beans.factory.annotation.Autowired;
16 16
 import org.springframework.stereotype.Service;
17
+import org.springframework.transaction.annotation.Transactional;
17 18
 
18 19
 import java.time.LocalDateTime;
19 20
 import java.time.format.DateTimeFormatter;
@@ -78,6 +79,7 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
78 79
      * 校验客户是否中奖, 如果中奖,则进行中奖相关更新
79 80
      * @throws Exception
80 81
      */
82
+    @Transactional(rollbackFor = Exception.class)
81 83
     public void checkAndSetLotteryPrize() throws Exception {
82 84
         LocalDateTime now = LocalDateTime.now();
83 85
         String today = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

+ 88
- 5
src/main/java/com/yunzhi/niucai/service/impl/TaMatchServiceImpl.java ファイルの表示

@@ -2,17 +2,17 @@ package com.yunzhi.niucai.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.yunzhi.niucai.common.DateUtils;
5
-import com.yunzhi.niucai.entity.TaMatch;
6
-import com.yunzhi.niucai.entity.TaMatchOdds;
7
-import com.yunzhi.niucai.entity.TaMatchWay;
5
+import com.yunzhi.niucai.entity.*;
6
+import com.yunzhi.niucai.enums.SportOpeningStatusEnum;
8 7
 import com.yunzhi.niucai.enums.SportStatusEnum;
9 8
 import com.yunzhi.niucai.mapper.TaMatchMapper;
10 9
 import com.yunzhi.niucai.mapper.TaMatchOddsMapper;
11
-import com.yunzhi.niucai.service.ITaMatchService;
10
+import com.yunzhi.niucai.service.*;
12 11
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13
-import com.yunzhi.niucai.service.ITaMatchWayService;
14 12
 import org.springframework.beans.factory.annotation.Autowired;
15 13
 import org.springframework.stereotype.Service;
14
+import org.springframework.transaction.annotation.Propagation;
15
+import org.springframework.transaction.annotation.Transactional;
16 16
 
17 17
 import java.util.ArrayList;
18 18
 import java.util.HashMap;
@@ -33,6 +33,15 @@ public class TaMatchServiceImpl extends ServiceImpl<TaMatchMapper, TaMatch> impl
33 33
     @Autowired
34 34
     ITaMatchWayService iTaMatchWayService;
35 35
 
36
+    @Autowired
37
+    ITaCustomerBettingService iTaCustomerBettingService;
38
+
39
+    @Autowired
40
+    ITaCustomerBettingItemService iTaCustomerBettingItemService;
41
+
42
+    @Autowired
43
+    ITaCustomerBettingSportService iTaCustomerBettingSportService;
44
+
36 45
     @Autowired
37 46
     TaMatchMapper taMatchMapper;
38 47
 
@@ -77,4 +86,78 @@ public class TaMatchServiceImpl extends ServiceImpl<TaMatchMapper, TaMatch> impl
77 86
     public List<TaMatch> getLastResult() throws Exception {
78 87
         return taMatchMapper.getLastResult();
79 88
     }
89
+
90
+    /**
91
+     * 体彩是否中奖
92
+     * @throws Exception
93
+     */
94
+    public void checkAndSetSportPrize() throws Exception {
95
+        List<TaMatch> matchList = taMatchMapper.getLastOpenAndUndoMatch(3);
96
+        if (null == matchList || matchList.size() == 0) {
97
+            return;
98
+        }
99
+
100
+        for (TaMatch taMatch : matchList) {
101
+            try {
102
+                taMatch.setOpeningStatus(SportOpeningStatusEnum.DOING.getCode());
103
+                updateById(taMatch);
104
+
105
+                String lotteryId = taMatch.getLotteryId();
106
+                switch (lotteryId) {
107
+                    case "football":
108
+                        setFootballPrize(taMatch);
109
+                        break;
110
+                    case "basketball":
111
+                        setBasketballPrize(taMatch);
112
+                        break;
113
+                    default:
114
+                        break;
115
+                }
116
+
117
+            } catch (Exception e) {
118
+                // TODO 比如错误日志记录
119
+                taMatch.setOpeningStatus(SportOpeningStatusEnum.READY.getCode());
120
+                updateById(taMatch);
121
+            }
122
+        }
123
+    }
124
+
125
+    /**
126
+     * 足球开奖
127
+     * @param taMatch
128
+     * @throws Exception
129
+     */
130
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
131
+    private void setFootballPrize(TaMatch taMatch) throws Exception {
132
+        // 获取当前比赛的投注列表
133
+        List<TaCustomerBettingItem> bettingItemList = iTaCustomerBettingItemService.getUnDealItems(taMatch);
134
+        if (null == bettingItemList || bettingItemList.size() == 0) {
135
+            return;
136
+        }
137
+
138
+        for (TaCustomerBettingItem item: bettingItemList) {
139
+            // 主记录
140
+            TaCustomerBetting betting = iTaCustomerBettingService.getById(item.getBettingId());
141
+            // 投注列表
142
+            List<TaCustomerBettingSport> bettingSportList = iTaCustomerBettingSportService.getListByBetting(item.getBettingId(), item.getItemNo());
143
+
144
+            for (TaCustomerBettingSport bettingSport : bettingSportList) {
145
+
146
+            }
147
+        }
148
+    }
149
+
150
+    /**
151
+     * 篮球开奖
152
+     * @param taMatch
153
+     * @throws Exception
154
+     */
155
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
156
+    private void setBasketballPrize(TaMatch taMatch) throws Exception {
157
+
158
+    }
159
+
160
+    private boolean isWining(TaMatch taMatch, TaCustomerBettingSport bettingSport) {
161
+        return false;
162
+    }
80 163
 }

+ 10
- 0
src/main/resources/mapper/TaCustomerBettingItemMapper.xml ファイルの表示

@@ -2,4 +2,14 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.yunzhi.niucai.mapper.TaCustomerBettingItemMapper">
4 4
 
5
+    <select id="getUnDealItems" resultType="com.yunzhi.niucai.entity.TaCustomerBettingItem">
6
+        SELECT
7
+            t.*
8
+        FROM
9
+            ta_customer_betting_item t
10
+        INNER JOIN ta_betting_plan_item s ON t.plan_item_no = s.item_no
11
+        WHERE
12
+            t.opening_status = 0
13
+            AND s.match_id = #{matchId};
14
+    </select>
5 15
 </mapper>

+ 12
- 0
src/main/resources/mapper/TaMatchMapper.xml ファイルの表示

@@ -28,4 +28,16 @@
28 28
             ) s
29 29
         GROUP BY s.lottery_id
30 30
     </select>
31
+    <select id="getLastOpenAndUndoMatch" resultType="com.yunzhi.niucai.entity.TaMatch">
32
+        SELECT
33
+            *
34
+        FROM
35
+            ta_match t
36
+        WHERE
37
+            t.`status` &gt; 1
38
+            AND t.opening_status = 0
39
+            AND t.match_date >= DATE_FORMAT( CURRENT_DATE - #{days}, '%Y-%m-%d' )
40
+        ORDER BY
41
+            t.match_id ASC
42
+    </select>
31 43
 </mapper>