张延森 4 years ago
parent
commit
1286457c1a

+ 2
- 1
src/main/java/com/xiaoniu/niucai/service/impl/TaCustomerBettingServiceImpl.java View File

@@ -39,7 +39,8 @@ public class TaCustomerBettingServiceImpl extends ServiceImpl<TaCustomerBettingM
39 39
         QueryWrapper<TaCustomerBetting> queryWrapper = new QueryWrapper<>();
40 40
         queryWrapper.eq("lottery_id", lottery.getLotteryId());
41 41
         queryWrapper.eq("issue_no", lotteryResult.getIssueNo());
42
-        queryWrapper.eq("is_open", false);
42
+        queryWrapper.eq("is_drawn", 1);
43
+        queryWrapper.eq("is_open", 0);
43 44
         queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
44 45
 
45 46
         List<TaCustomerBetting> list = list(queryWrapper);

+ 132
- 152
src/main/java/com/xiaoniu/niucai/service/impl/TaLotteryResultServiceImpl.java View File

@@ -53,9 +53,9 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
53 53
     @Override
54 54
     @Transactional(rollbackFor = Exception.class)
55 55
     public void checkAndSetLotteryPrize() throws Exception {
56
-        LocalDateTime now = LocalDateTime.now();
57
-        String today = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
58
-        int weekDay = now.getDayOfWeek().getValue();
56
+        LocalDateTime yestoday = LocalDateTime.now().minusDays(1); // DateUtils.str2LocalDateTime("2020-10-26 00:00", "yyyy-MM-dd HH:mm"); //
57
+        String today = yestoday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
58
+        int weekDay = yestoday.getDayOfWeek().getValue();
59 59
         List<TdLotteryOnSale> onSaleList = iTdLotteryOnSaleService.getByWeekDay(weekDay);
60 60
         if (null == onSaleList || onSaleList.size() == 0) {
61 61
             log.info(today + "未找到有开售设置");
@@ -127,17 +127,16 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
127 127
         return result;
128 128
     }
129 129
 
130
+    @Transactional(rollbackFor = Exception.class)
130 131
     private void validLotteryCustomer(TdLottery lottery, List<TdLotteryPrize> prizeSettings, TaLotteryResult lotteryResult, TaCustomerBetting customerBetting) throws Exception {
131 132
         TaBettingPlan taBettingPlan = customerBetting.getBettingPlan();
132 133
         if (null == taBettingPlan) {
133
-            log.error(String.format("ID %s 的投注没有投注方案", customerBetting.getBettingId()));
134
-            return;
134
+            throw new Exception(String.format("ID %s 的投注没有投注方案", customerBetting.getBettingId()));
135 135
         }
136 136
 
137 137
         if (null == taBettingPlan.getItemList() || taBettingPlan.getItemList().size() == 0
138 138
                 || null == customerBetting.getItemList() || customerBetting.getItemList().size() == 0) {
139
-            log.error(String.format("ID %s 的投注没有投注明细", customerBetting.getBettingId()));
140
-            return;
139
+            throw new Exception(String.format("ID %s 的投注没有投注明细", customerBetting.getBettingId()));
141 140
         }
142 141
 
143 142
         int winTotalCharges = 0;
@@ -147,181 +146,162 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
147 146
             // 中奖金额
148 147
             int winAmount = 0;
149 148
 
150
-            try {
151
-                TaCustomerBettingItem bettingItem = getBettingItemMap(customerBetting.getItemList(), item);
152
-                if (bettingItem == null) {
153
-                    log.error(String.format("ID %s 的投注查询映射投注明细失败", customerBetting.getBettingId()));
154
-                    continue;
155
-                }
156
-
157
-                // 排列三直选, 排列五 都是依靠比对数字位是否一致来决定是否中奖的
158
-                if (lottery.getLotteryId().equals("p5")) {
159
-                    isWinning = BizUtils.checkPrizeNumStrict(lotteryResult.getFirstResult().split(","), item.getFirstNums().split(","));
160
-                    if (isWinning) {
161
-                        TaLotteryResultDetail resultDetail = lotteryResult.getDetailList().get(0);
162
-                        if (null == resultDetail) {
163
-                            log.error(String.format("第 %s 期排列五结果明细未抓取", lotteryResult.getIssueNo()));
164
-                            continue;
165
-                        }
149
+            TaCustomerBettingItem bettingItem = getBettingItemMap(customerBetting.getItemList(), item);
150
+            if (bettingItem == null) {
151
+                throw new Exception(String.format("ID %s 的投注查询映射投注明细失败", customerBetting.getBettingId()));
152
+            }
166 153
 
167
-                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
168
-                    }
169
-                } else if (lottery.getLotteryId().equals("p3")) {
170
-                    String[] bingoNums = lotteryResult.getFirstResult().split(",");
171
-                    if (bingoNums.length != 3) {
172
-                        log.error(String.format("第 %s 期排列三抓取结果不正确", lotteryResult.getIssueNo()));
173
-                        continue;
154
+            // 排列三直选, 排列五 都是依靠比对数字位是否一致来决定是否中奖的
155
+            if (lottery.getLotteryId().equals("p5")) {
156
+                isWinning = BizUtils.checkPrizeNumStrict(lotteryResult.getResult().split(","), item.getFirstNums().split(","));
157
+                if (isWinning) {
158
+                    TaLotteryResultDetail resultDetail = lotteryResult.getDetailList().get(0);
159
+                    if (null == resultDetail) {
160
+                        throw new Exception(String.format("第 %s 期排列五结果明细未抓取", lotteryResult.getIssueNo()));
174 161
                     }
175 162
 
176
-                    String level = "直选";
177
-                    if ("组选3".equals(item.getPlayWay())) {
178
-                        level = "组三";
179
-                    } else if ("组选6".equals(item.getPlayWay())) {
180
-                        level = "组六";
181
-                    }
163
+                    winAmount = Math.round(Float.parseFloat(resultDetail.getMoney().replaceAll(",", "")) * 100);
164
+                }
165
+            } else if (lottery.getLotteryId().equals("p3")) {
166
+                String[] bingoNums = lotteryResult.getResult().split(",");
167
+                if (bingoNums.length != 3) {
168
+                    throw new Exception(String.format("第 %s 期排列三抓取结果不正确", lotteryResult.getIssueNo()));
169
+                }
182 170
 
183
-                    TaLotteryResultDetail resultDetail = filterResultDetail(lotteryResult.getDetailList(), level);
184
-                    if (null == resultDetail) {
185
-                        log.error(String.format("第 %s 期排列三结果明细未抓取", lotteryResult.getIssueNo()));
186
-                        continue;
187
-                    }
171
+//                String level = "直选";
172
+//                if ("组选3".equals(item.getPlayWay())) {
173
+//                    level = "组选三";
174
+//                } else if ("组选6".equals(item.getPlayWay())) {
175
+//                    level = "组选六";
176
+//                }
177
+
178
+                String stdP0 = "直选";
179
+                String stdP3 = "组选3";
180
+                String stdP6 = "组选6";
181
+                String level = StringUtils.ifNull(item.getPlayWay(), stdP0);
182
+
183
+                TaLotteryResultDetail resultDetail = filterResultDetail(lotteryResult.getDetailList(), level);
184
+                if (null == resultDetail) {
185
+                    throw new Exception(String.format("第 %s 期排列三结果明细未抓取", lotteryResult.getIssueNo()));
186
+                }
188 187
 
189
-                    // 直选是通过比对数字来校验中奖
190
-                    if ("直选".equals(level)) {
191
-                        isWinning = BizUtils.checkPrizeNumStrict(bingoNums, item.getFirstNums().split(","));
192
-                        if (isWinning) {
193
-                            winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
188
+                // 直选是通过比对数字来校验中奖
189
+                if (stdP0.equals(level)) {
190
+                    isWinning = BizUtils.checkPrizeNumStrict(bingoNums, item.getFirstNums().split(","));
191
+                    if (isWinning) {
192
+                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney().replaceAll(",", "")) * 100);
193
+                    }
194
+                } else {
195
+                    // 出现2次的号码
196
+                    boolean hasTwiceNum = bingoNums[0].equals(bingoNums[1])
197
+                            || bingoNums[0].equals(bingoNums[2])
198
+                            || bingoNums[1].equals(bingoNums[2]);
199
+
200
+                    // 如果存在出现2次的号码, 只有可能中组选三, 否则只有可能中组选6
201
+                    if (!hasTwiceNum) {
202
+                        if (stdP6.equals(level)) {
203
+                            isWinning = item.getFirstNums().contains(bingoNums[0])
204
+                                    && item.getFirstNums().contains(bingoNums[1])
205
+                                    && item.getFirstNums().contains(bingoNums[2]);
206
+                            if (isWinning) {
207
+                                winAmount = Math.round(Float.parseFloat(resultDetail.getMoney().replaceAll(",", "")) * 100);
208
+                            }
194 209
                         }
195 210
                     } else {
196
-                        // 出现2次的号码
197
-                        boolean hasTwiceNum = bingoNums[0].equals(bingoNums[1])
198
-                                || bingoNums[0].equals(bingoNums[2])
199
-                                || bingoNums[1].equals(bingoNums[2]);
200
-
201
-                        // 如果存在出现2次的号码, 只有可能中组选三, 否则只有可能中组选6
202
-                        if (!hasTwiceNum) {
203
-                            if ("组六".equals(level)) {
211
+                        if (stdP3.equals(level)) {
212
+                            // 如果是复式
213
+                            if (item.getIsMulti()) {
204 214
                                 isWinning = item.getFirstNums().contains(bingoNums[0])
205 215
                                         && item.getFirstNums().contains(bingoNums[1])
206 216
                                         && item.getFirstNums().contains(bingoNums[2]);
207 217
                                 if (isWinning) {
208
-                                    winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
218
+                                    winAmount = Math.round(Float.parseFloat(resultDetail.getMoney().replaceAll(",", "")) * 100);
209 219
                                 }
210
-                            }
211
-                        } else {
212
-                            if ("组三".equals(level)) {
213
-                                // 如果是复式
214
-                                if (item.getIsMulti()) {
215
-                                    isWinning = item.getFirstNums().contains(bingoNums[0])
216
-                                            && item.getFirstNums().contains(bingoNums[1])
217
-                                            && item.getFirstNums().contains(bingoNums[2]);
218
-                                    if (isWinning) {
219
-                                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
220
-                                    }
221
-                                } else {
222
-                                    // 投注号
223
-                                    String[] buyNums = item.getFirstNums().split(",");
224
-                                    // 由小到大排序
225
-                                    Arrays.sort(bingoNums);
226
-                                    Arrays.sort(buyNums);
227
-
228
-                                    isWinning = BizUtils.checkPrizeNumStrict(bingoNums, buyNums);
229
-                                    if (isWinning) {
230
-                                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
231
-                                    }
220
+                            } else {
221
+                                // 投注号
222
+                                String[] buyNums = item.getFirstNums().split(",");
223
+                                // 由小到大排序
224
+                                Arrays.sort(bingoNums);
225
+                                Arrays.sort(buyNums);
226
+
227
+                                isWinning = BizUtils.checkPrizeNumStrict(bingoNums, buyNums);
228
+                                if (isWinning) {
229
+                                    winAmount = Math.round(Float.parseFloat(resultDetail.getMoney().replaceAll(",", "")) * 100);
232 230
                                 }
233 231
                             }
234 232
                         }
235 233
                     }
234
+                }
236 235
 
237
-                } else {
238
-                    // 大乐透  双色球
239
-                    String firstNums = item.getFirstNums();
240
-                    if (StringUtils.isEmpty(firstNums)) {
241
-                        log.error(String.format("ID %s 的投注明细无前区内容", customerBetting.getBettingId()));
242
-                        continue;
243
-                    }
236
+            } else {
237
+                // 大乐透  双色球
238
+                String firstNums = item.getFirstNums();
239
+                if (StringUtils.isEmpty(firstNums)) {
240
+                    throw new Exception(String.format("ID %s 的投注明细无前区内容", customerBetting.getBettingId()));
241
+                }
244 242
 
245
-                    String firstDanNums = item.getFirstDan();
246
-                    if (StringUtils.isEmpty(firstDanNums)) {
247
-                        firstDanNums = "";
248
-                    }
243
+                String firstDanNums = item.getFirstDan();
249 244
 
250
-                    // 前区中奖数
251
-                    int firstSameNums = BizUtils.getSameNums(
252
-                            lotteryResult.getFirstResult().split(","),
253
-                            firstNums.split(","),
254
-                            firstDanNums.split(",")
255
-                    );
256
-
257
-                    String secondNums = item.getFirstNums();
258
-                    if (StringUtils.isEmpty(secondNums)) {
259
-                        log.error(String.format("ID %s 的投注明细无后区内容", customerBetting.getBettingId()));
260
-                        continue;
261
-                    }
245
+                // 前区中奖数
246
+                int firstSameNums = BizUtils.getSameNums(
247
+                        lotteryResult.getFirstResult().split(","),
248
+                        firstNums.split(","),
249
+                        StringUtils.isEmpty(firstDanNums) ? null : firstDanNums.split(",")
250
+                );
262 251
 
263
-                    String secondDanNums = item.getFirstDan();
264
-                    if (StringUtils.isEmpty(secondDanNums)) {
265
-                        secondDanNums = "";
266
-                    }
252
+                String secondNums = item.getSecondNums();
253
+                if (StringUtils.isEmpty(secondNums)) {
254
+                    throw new Exception(String.format("ID %s 的投注明细无后区内容", customerBetting.getBettingId()));
255
+                }
267 256
 
268
-                    // 后区中奖数
269
-                    int secondSameNums = BizUtils.getSameNums(
270
-                            lotteryResult.getSecondResult().split(","),
271
-                            secondNums.split(","),
272
-                            secondDanNums.split(","));
273
-
274
-                    // 选择结果
275
-                    String curNums = String.format("%d-%d", firstSameNums, secondSameNums);
276
-
277
-                    boolean needContinue = false;
278
-                    TdLotteryPrize bingo = null;
279
-                    for(TdLotteryPrize prize : prizeSettings) {
280
-                        if (StringUtils.isEmpty(prize.getBingoRule())) {
281
-                            log.error(String.format("彩种 %s 的中奖结果规则未维护", lottery.getLotteryId()));
282
-                            needContinue = true;
283
-                            break;
284
-                        }
257
+                String secondDanNums = item.getSecondDan();
285 258
 
286
-                        if (prize.getBingoRule().contains(curNums)) {
287
-                            bingo = prize;
288
-                            break;
289
-                        }
259
+                // 后区中奖数
260
+                int secondSameNums = BizUtils.getSameNums(
261
+                        lotteryResult.getSecondResult().split(","),
262
+                        secondNums.split(","),
263
+                        StringUtils.isEmpty(secondDanNums) ? null : secondDanNums.split(",")
264
+                );
265
+
266
+                // 选择结果
267
+                String curNums = String.format("%d-%d", firstSameNums, secondSameNums);
268
+
269
+                TdLotteryPrize bingo = null;
270
+                for(TdLotteryPrize prize : prizeSettings) {
271
+                    if (StringUtils.isEmpty(prize.getBingoRule())) {
272
+                        throw new Exception(String.format("彩种 %s 的中奖结果规则未维护", lottery.getLotteryId()));
290 273
                     }
291 274
 
292
-                    if (needContinue) {
293
-                        continue;
275
+                    if (prize.getBingoRule().contains(curNums)) {
276
+                        bingo = prize;
277
+                        break;
294 278
                     }
279
+                }
295 280
 
296
-                    if (null != bingo) {
297
-                        log.info(String.format("恭喜 %s 购买 %s 中了 %s", customerBetting.getCustomerId(), lottery.getLotteryId(), bingo.getLevel()));
298
-                        isWinning = true;
299
-                        bettingItem.setWinLevel(bingo.getLevel());
300
-                        TaLotteryResultDetail resultDetail = filterResultDetail(lotteryResult.getDetailList(), bingo.getLevel());
301
-                        if (null == resultDetail) {
302
-                            log.error(String.format("彩种 %s 的中奖结果明细未成功抓取", lottery.getLotteryId()));
303
-                            continue;
304
-                        }
281
+                if (null != bingo) {
282
+                    log.info(String.format("恭喜 %s 购买 %s 中了 %s", customerBetting.getCustomerId(), lottery.getLotteryId(), bingo.getLevel()));
283
+                    isWinning = true;
284
+                    bettingItem.setWinLevel(bingo.getLevel());
285
+                    TaLotteryResultDetail resultDetail = filterResultDetail(lotteryResult.getDetailList(), bingo.getLevel());
286
+                    if (null == resultDetail) {
287
+                        throw new Exception(String.format("彩种 %s 的中奖结果明细未成功抓取", lottery.getLotteryId()));
288
+                    }
305 289
 
306
-                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
307
-                        // 是否追加
308
-                        boolean isAdd = customerBetting.getIsAdd();
309
-                        if (isAdd && !StringUtils.isEmpty(resultDetail.getXMoney())) {
310
-                            winAmount += Math.round(Float.parseFloat(resultDetail.getXMoney()) * 100);
311
-                        }
290
+                    winAmount = Math.round(Float.parseFloat(resultDetail.getMoney().replaceAll(",", "")) * 100);
291
+                    // 是否追加
292
+                    boolean isAdd = customerBetting.getIsAdd();
293
+                    if (isAdd && !StringUtils.isEmpty(resultDetail.getXMoney())) {
294
+                        winAmount += Math.round(Float.parseFloat(resultDetail.getXMoney().replaceAll(",", "")) * 100);
312 295
                     }
313 296
                 }
314
-
315
-                winTotalCharges += winAmount;
316
-                bettingItem.setIsOpen(true);
317
-                bettingItem.setOpeningDate(DateUtils.today());
318
-                bettingItem.setIsWinning(isWinning);
319
-                bettingItem.setWinAmount(winAmount);
320
-                iTaCustomerBettingItemService.updateById(bettingItem);
321
-            } catch (Exception e) {
322
-                e.printStackTrace();
323
-                continue;
324 297
             }
298
+
299
+            winTotalCharges += winAmount;
300
+            bettingItem.setIsOpen(true);
301
+            bettingItem.setOpeningDate(DateUtils.today());
302
+            bettingItem.setIsWinning(isWinning);
303
+            bettingItem.setWinAmount(winAmount);
304
+            iTaCustomerBettingItemService.updateById(bettingItem);
325 305
         }
326 306
 
327 307
         if (winTotalCharges > 0) {

+ 4
- 1
src/main/java/com/xiaoniu/niucai/service/impl/TaMatchServiceImpl.java View File

@@ -9,6 +9,7 @@ import com.xiaoniu.niucai.enums.SportOpeningStatusEnum;
9 9
 import com.xiaoniu.niucai.mapper.TaCustomerBettingMapper;
10 10
 import com.xiaoniu.niucai.service.*;
11 11
 import com.xiaoniu.niucai.mapper.TaMatchMapper;
12
+import lombok.extern.slf4j.Slf4j;
12 13
 import org.springframework.beans.factory.annotation.Autowired;
13 14
 import org.springframework.stereotype.Service;
14 15
 import org.springframework.transaction.annotation.Propagation;
@@ -25,6 +26,7 @@ import java.util.List;
25 26
  * @author admin
26 27
  * @since 2020-09-02
27 28
  */
29
+@Slf4j
28 30
 @Service
29 31
 public class TaMatchServiceImpl extends ServiceImpl<TaMatchMapper, TaMatch> implements ITaMatchService {
30 32
     @Autowired
@@ -55,14 +57,15 @@ public class TaMatchServiceImpl extends ServiceImpl<TaMatchMapper, TaMatch> impl
55 57
     public void checkAndSetSportPrize() throws Exception {
56 58
         List<TaMatch> matchList = taMatchMapper.getLastOpenAndUndoMatch(3);
57 59
         if (null == matchList || matchList.size() == 0) {
60
+            log.info("未检测到有待处理的竞彩比赛");
58 61
             return;
59 62
         }
60 63
 
61 64
         for (TaMatch taMatch : matchList) {
62 65
             try {
66
+                validateMatch(taMatch);
63 67
                 taMatch.setOpeningStatus(SportOpeningStatusEnum.DOING.getCode());
64 68
                 updateById(taMatch);
65
-                validateMatch(taMatch);
66 69
             } catch (Exception e) {
67 70
                 // TODO 比如错误日志记录
68 71
                 taMatch.setOpeningStatus(SportOpeningStatusEnum.READY.getCode());

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

@@ -20,7 +20,7 @@ public class Lottery {
20 20
     /**
21 21
      * 开奖轮询
22 22
      */
23
-    @Scheduled(cron = "* 0/3 * * * ? ")
23
+    @Scheduled(cron = "* 0/2 * * * ? ")
24 24
     public void lotteryOpenCheck() {
25 25
         // 数字彩
26 26
         try {

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

@@ -8,9 +8,9 @@
8 8
         FROM
9 9
             ta_match t
10 10
         WHERE
11
-            t.`status` &gt; 1
11
+            t.`status` = 3
12 12
             AND t.opening_status = 0
13
-            AND t.match_date >= DATE_FORMAT( CURRENT_DATE - #{days}, '%Y-%m-%d' )
13
+            AND t.match_date &gt;= DATE_FORMAT( CURRENT_DATE - #{days}, '%Y-%m-%d' )
14 14
         ORDER BY
15 15
             t.match_id ASC
16 16
     </select>