Your Name il y a 4 ans
Parent
révision
dfe7c2fc92

+ 1
- 0
src/main/java/com/yunzhi/niucai/common/ArrayUtils.java Voir le fichier

@@ -88,4 +88,5 @@ public class ArrayUtils {
88 88
     public static <T> int indexOf(T[] src, T search) {
89 89
         return Arrays.asList(src).indexOf(search);
90 90
     }
91
+
91 92
 }

+ 88
- 36
src/main/java/com/yunzhi/niucai/service/impl/TaLotteryResultServiceImpl.java Voir le fichier

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
17 17
 
18 18
 import java.time.LocalDateTime;
19 19
 import java.time.format.DateTimeFormatter;
20
+import java.util.Arrays;
20 21
 import java.util.List;
21 22
 
22 23
 /**
@@ -96,7 +97,7 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
96 97
 
97 98
             // 中奖设置
98 99
             List<TdLotteryPrize> prizeSettings = iTdLotteryPrizeService.getByLottery(lottery);
99
-            if (null == prizeSettings && prizeSettings.size() == 0) {
100
+            if (null == prizeSettings || prizeSettings.size() == 0) {
100 101
                 log.error(String.format("彩种 %s 没有开奖相关设置", lotteryId));
101 102
                 continue;
102 103
             }
@@ -150,7 +151,7 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
150 151
 //                    }
151 152
                 } catch (Exception e) {
152 153
                     e.printStackTrace();
153
-                    continue;
154
+                    // continue;
154 155
                 }
155 156
             }
156 157
         }
@@ -171,6 +172,11 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
171 172
 
172 173
         int winTotalCharges = 0;
173 174
         for (TaBettingPlanItem item : taBettingPlan.getItemList()) {
175
+            // 是否中奖
176
+            boolean isWinning = false;
177
+            // 中奖金额
178
+            int winAmount = 0;
179
+
174 180
             try {
175 181
                 TaCustomerBettingItem bettingItem = getBettingItemMap(customerBetting.getItemList(), item);
176 182
                 if (bettingItem == null) {
@@ -178,28 +184,25 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
178 184
                     continue;
179 185
                 }
180 186
 
181
-                String firstNums = item.getFirstNums();
182
-                if (StringUtils.isEmpty(firstNums)) {
183
-                    log.error(String.format("ID %s 的投注明细无前区内容", customerBetting.getBettingId()));
184
-                    continue;
185
-                }
186
-
187
-                // 中奖金额
188
-                int winAmount = 0;
189
-                // 是否中奖
190
-                boolean isWinning = false;
191
-
192
-                // 排列五
187
+                // 排列三直选, 排列五 都是依靠比对数字位是否一致来决定是否中奖的
193 188
                 if (lottery.getLotteryId().equals(CommConstants.LOTTERY_P5)) {
194
-                    TaLotteryResultDetail resultDetail = lotteryResult.getDetailList().get(0);
195
-                    isWinning = BizUtils.checkPrizeNumStrict(lotteryResult.getFirstResult().split(","), firstNums.split(","));
189
+                    isWinning = BizUtils.checkPrizeNumStrict(lotteryResult.getFirstResult().split(","), item.getFirstNums().split(","));
196 190
                     if (isWinning) {
191
+                        TaLotteryResultDetail resultDetail = lotteryResult.getDetailList().get(0);
192
+                        if (null == resultDetail) {
193
+                            log.error(String.format("第 %s 期排列五结果明细未抓取", lotteryResult.getIssueNo()));
194
+                            continue;
195
+                        }
196
+
197 197
                         winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
198
-                        bettingItem.setWinAmount(winAmount);
199 198
                     }
200
-
201
-                // 排列三
202 199
                 } else if (lottery.getLotteryId().equals(CommConstants.LOTTERY_P3)) {
200
+                    String[] bingoNums = lotteryResult.getFirstResult().split(",");
201
+                    if (bingoNums.length != 3) {
202
+                        log.error(String.format("第 %s 期排列三抓取结果不正确", lotteryResult.getIssueNo()));
203
+                        continue;
204
+                    }
205
+
203 206
                     String level = "直选";
204 207
                     if ("组选3".equals(item.getPlayWay())) {
205 208
                         level = "组三";
@@ -208,22 +211,67 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
208 211
                     }
209 212
 
210 213
                     TaLotteryResultDetail resultDetail = filterResultDetail(lotteryResult.getDetailList(), level);
211
-                    switch (level) {
212
-                        case "直选":
213
-                            isWinning = BizUtils.checkPrizeNumStrict(lotteryResult.getFirstResult().split(","), firstNums.split(","));
214
-                            break;
215
-                        case "组三":
216
-
217
-                            break;
218
-                        case "组六":
219
-                            break;
214
+                    if (null == resultDetail) {
215
+                        log.error(String.format("第 %s 期排列三结果明细未抓取", lotteryResult.getIssueNo()));
216
+                        continue;
220 217
                     }
221 218
 
222
-                    if (isWinning) {
223
-                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
224
-                        bettingItem.setWinAmount(winAmount);
219
+                    // 直选是通过比对数字来校验中奖
220
+                    if ("直选".equals(level)) {
221
+                        isWinning = BizUtils.checkPrizeNumStrict(bingoNums, item.getFirstNums().split(","));
222
+                        if (isWinning) {
223
+                            winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
224
+                        }
225
+                    } else {
226
+                        // 出现2次的号码
227
+                        boolean hasTwiceNum = bingoNums[0].equals(bingoNums[1])
228
+                                || bingoNums[0].equals(bingoNums[2])
229
+                                || bingoNums[1].equals(bingoNums[2]);
230
+
231
+                        // 如果存在出现2次的号码, 只有可能中组选三, 否则只有可能中组选6
232
+                        if (!hasTwiceNum) {
233
+                            if ("组六".equals(level)) {
234
+                                isWinning = item.getFirstNums().contains(bingoNums[0])
235
+                                        && item.getFirstNums().contains(bingoNums[1])
236
+                                        && item.getFirstNums().contains(bingoNums[2]);
237
+                                if (isWinning) {
238
+                                    winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
239
+                                }
240
+                            }
241
+                        } else {
242
+                            if ("组三".equals(level)) {
243
+                                // 如果是复式
244
+                                if (item.getIsMulti()) {
245
+                                    isWinning = item.getFirstNums().contains(bingoNums[0])
246
+                                            && item.getFirstNums().contains(bingoNums[1])
247
+                                            && item.getFirstNums().contains(bingoNums[2]);
248
+                                    if (isWinning) {
249
+                                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
250
+                                    }
251
+                                } else {
252
+                                    // 投注号
253
+                                    String[] buyNums = item.getFirstNums().split(",");
254
+                                    // 由小到大排序
255
+                                    Arrays.sort(bingoNums);
256
+                                    Arrays.sort(buyNums);
257
+
258
+                                    isWinning = BizUtils.checkPrizeNumStrict(bingoNums, buyNums);
259
+                                    if (isWinning) {
260
+                                        winAmount = Math.round(Float.parseFloat(resultDetail.getMoney()) * 100);
261
+                                    }
262
+                                }
263
+                            }
264
+                        }
225 265
                     }
266
+
226 267
                 } else {
268
+                    // 大乐透  双色球
269
+                    String firstNums = item.getFirstNums();
270
+                    if (StringUtils.isEmpty(firstNums)) {
271
+                        log.error(String.format("ID %s 的投注明细无前区内容", customerBetting.getBettingId()));
272
+                        continue;
273
+                    }
274
+
227 275
                     String firstDanNums = item.getFirstDan();
228 276
                     if (StringUtils.isEmpty(firstDanNums)) {
229 277
                         firstDanNums = "";
@@ -248,7 +296,10 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
248 296
                     }
249 297
 
250 298
                     // 后区中奖数
251
-                    int secondSameNums = BizUtils.getSameNums(lotteryResult.getSecondResult().split(","), secondNums.split(","), secondDanNums.split(","));
299
+                    int secondSameNums = BizUtils.getSameNums(
300
+                            lotteryResult.getSecondResult().split(","),
301
+                            secondNums.split(","),
302
+                            secondDanNums.split(","));
252 303
 
253 304
                     // 选择结果
254 305
                     String curNums = String.format("%d-%d", firstSameNums, secondSameNums);
@@ -257,7 +308,7 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
257 308
                     TdLotteryPrize bingo = null;
258 309
                     for(TdLotteryPrize prize : prizeSettings) {
259 310
                         if (StringUtils.isEmpty(prize.getBingoRule())) {
260
-                            log.error(String.format("彩种 %s 中奖结果规则未维护", lottery.getLotteryId()));
311
+                            log.error(String.format("彩种 %s 中奖结果规则未维护", lottery.getLotteryId()));
261 312
                             needContinue = true;
262 313
                             break;
263 314
                         }
@@ -272,14 +323,13 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
272 323
                         continue;
273 324
                     }
274 325
 
275
-                    bettingItem.setIsOpen(true);
276 326
                     if (null != bingo) {
277 327
                         log.info(String.format("恭喜 %s 购买 %s 中了 %s", customerBetting.getCustomerId(), lottery.getLotteryId(), bingo.getLevel()));
278 328
                         isWinning = true;
279 329
                         bettingItem.setWinLevel(bingo.getLevel());
280 330
                         TaLotteryResultDetail resultDetail = filterResultDetail(lotteryResult.getDetailList(), bingo.getLevel());
281 331
                         if (null == resultDetail) {
282
-                            log.error("大乐透的中奖结果明细未成功抓取");
332
+                            log.error(String.format("彩种 %s 的中奖结果明细未成功抓取", lottery.getLotteryId()));
283 333
                             continue;
284 334
                         }
285 335
 
@@ -292,9 +342,11 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
292 342
                     }
293 343
                 }
294 344
 
345
+                winTotalCharges += winAmount;
346
+                bettingItem.setIsOpen(true);
347
+                bettingItem.setOpeningDate(DateUtils.today());
295 348
                 bettingItem.setIsWinning(isWinning);
296 349
                 bettingItem.setWinAmount(winAmount);
297
-                winTotalCharges += winAmount;
298 350
                 iTaCustomerBettingItemService.updateById(bettingItem);
299 351
             } catch (Exception e) {
300 352
                 e.printStackTrace();