|
@@ -1,15 +1,21 @@
|
1
|
1
|
package com.yunzhi.niucai.service.impl;
|
2
|
2
|
|
3
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
|
-import com.yunzhi.niucai.entity.TaLotteryResult;
|
5
|
|
-import com.yunzhi.niucai.entity.TdLottery;
|
|
4
|
+import com.yunzhi.niucai.common.CommConstants;
|
|
5
|
+import com.yunzhi.niucai.entity.*;
|
6
|
6
|
import com.yunzhi.niucai.enums.StatusEnum;
|
7
|
7
|
import com.yunzhi.niucai.mapper.TaLotteryResultMapper;
|
|
8
|
+import com.yunzhi.niucai.service.ITaCustomerBettingService;
|
8
|
9
|
import com.yunzhi.niucai.service.ITaLotteryResultService;
|
9
|
10
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
11
|
+import com.yunzhi.niucai.service.ITdLotteryOnSaleService;
|
|
12
|
+import com.yunzhi.niucai.service.ITdLotteryService;
|
|
13
|
+import lombok.extern.slf4j.Slf4j;
|
10
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
15
|
import org.springframework.stereotype.Service;
|
12
|
16
|
|
|
17
|
+import java.time.LocalDateTime;
|
|
18
|
+import java.time.format.DateTimeFormatter;
|
13
|
19
|
import java.util.List;
|
14
|
20
|
|
15
|
21
|
/**
|
|
@@ -20,8 +26,19 @@ import java.util.List;
|
20
|
26
|
* @author yansen
|
21
|
27
|
* @since 2020-08-27
|
22
|
28
|
*/
|
|
29
|
+@Slf4j
|
23
|
30
|
@Service
|
24
|
31
|
public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMapper, TaLotteryResult> implements ITaLotteryResultService {
|
|
32
|
+
|
|
33
|
+ @Autowired
|
|
34
|
+ ITdLotteryService iTdLotteryService;
|
|
35
|
+
|
|
36
|
+ @Autowired
|
|
37
|
+ ITdLotteryOnSaleService iTdLotteryOnSaleService;
|
|
38
|
+
|
|
39
|
+ @Autowired
|
|
40
|
+ ITaCustomerBettingService iTaCustomerBettingService;
|
|
41
|
+
|
25
|
42
|
@Autowired
|
26
|
43
|
TaLotteryResultMapper taLotteryResultMapper;
|
27
|
44
|
|
|
@@ -36,8 +53,107 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
|
36
|
53
|
queryWrapper.eq("lottery_id", tdLottery.getLotteryId());
|
37
|
54
|
queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
|
38
|
55
|
queryWrapper.orderByDesc("opening_date");
|
39
|
|
- queryWrapper.last("limti 1");
|
|
56
|
+ queryWrapper.last("limit 1");
|
|
57
|
+
|
|
58
|
+ return getOne(queryWrapper);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ /**
|
|
62
|
+ * 校验客户是否中奖, 如果中奖,则进行中奖相关更新
|
|
63
|
+ * @throws Exception
|
|
64
|
+ */
|
|
65
|
+ public void checkAndSetLotteryPrize() throws Exception {
|
|
66
|
+ LocalDateTime now = LocalDateTime.now();
|
|
67
|
+ String today = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
68
|
+ int weekDay = now.getDayOfWeek().getValue();
|
|
69
|
+ List<TdLotteryOnSale> onSaleList = iTdLotteryOnSaleService.getByWeekDay(weekDay);
|
|
70
|
+ if (null == onSaleList || onSaleList.size() == 0) {
|
|
71
|
+ log.info(today + "未找到有开奖设置");
|
|
72
|
+ return;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ for (TdLotteryOnSale onSale : onSaleList) {
|
|
76
|
+ String lotteryId = onSale.getLotteryId();
|
|
77
|
+ log.info(String.format("彩种 %s %s 开奖, 开始检测中奖人员", lotteryId, today));
|
|
78
|
+
|
|
79
|
+ // 彩种字典
|
|
80
|
+ TdLottery lottery = iTdLotteryService.getById(lotteryId);
|
|
81
|
+
|
|
82
|
+ // 当前彩种的开奖结果
|
|
83
|
+ TaLotteryResult lotteryResult = getLotteryResultBy(onSale.getLotteryId(), today);
|
|
84
|
+ if (null == lotteryResult) {
|
|
85
|
+ log.error(String.format("彩种 %s 未抓取到开奖结果", lotteryId));
|
|
86
|
+ continue;
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ switch (lotteryId) {
|
|
90
|
+ case CommConstants.LOTTERY_LOTTERY:
|
|
91
|
+ validLotteryCustomer(lottery, lotteryResult);
|
|
92
|
+ break;
|
|
93
|
+ case CommConstants.LOTTERY_P3:
|
|
94
|
+ validP3Customer(lottery, lotteryResult);
|
|
95
|
+ break;
|
|
96
|
+ case CommConstants.LOTTERY_P5:
|
|
97
|
+ validP5Customer(lottery, lotteryResult);
|
|
98
|
+ break;
|
|
99
|
+ case CommConstants.LOTTERY_DOUBLE:
|
|
100
|
+ validDoubleCustomer(lottery, lotteryResult);
|
|
101
|
+ break;
|
|
102
|
+ case CommConstants.LOTTERY_FOOTBALL:
|
|
103
|
+ validFootballCustomer(lottery, lotteryResult);
|
|
104
|
+ break;
|
|
105
|
+ case CommConstants.LOTTERY_BASKETBALL:
|
|
106
|
+ validBasketballCustomer(lottery, lotteryResult);
|
|
107
|
+ break;
|
|
108
|
+ default:
|
|
109
|
+ break;
|
|
110
|
+ }
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ private void validLotteryCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
|
|
115
|
+ List<TaCustomerBetting> customerBettingList = iTaCustomerBettingService.getAllUnOpenBettingsBy(lottery, lotteryResult);
|
|
116
|
+ if (null == customerBettingList || customerBettingList.size() == 0) {
|
|
117
|
+ log.info(String.format("大乐透 %s 期无人投注", lotteryResult.getIssueNo()));
|
|
118
|
+ return;
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ for (TaCustomerBetting customerBetting : customerBettingList) {
|
|
122
|
+ TaBettingPlan taBettingPlan = customerBetting.getBettingPlan();
|
|
123
|
+ if (null == taBettingPlan) {
|
|
124
|
+ log.error(String.format("ID %s 的投注没有投注方案", customerBetting.getBettingId()));
|
|
125
|
+ continue;
|
|
126
|
+ }
|
40
|
127
|
|
|
128
|
+ if (null == taBettingPlan.getItemList() || taBettingPlan.getItemList().size() == 0) {
|
|
129
|
+ log.error(String.format("ID %s 的投注没有投注明细", customerBetting.getBettingId()));
|
|
130
|
+ continue;
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ private void validP3Customer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ private void validP5Customer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ private void validDoubleCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ private void validFootballCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ private void validBasketballCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ public TaLotteryResult getLotteryResultBy(String lotteryId, String openingDate) throws Exception {
|
|
153
|
+ QueryWrapper<TaLotteryResult> queryWrapper = new QueryWrapper<>();
|
|
154
|
+ queryWrapper.eq("lottery_id", lotteryId);
|
|
155
|
+ queryWrapper.eq("opening_date", openingDate);
|
|
156
|
+ queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
|
41
|
157
|
return getOne(queryWrapper);
|
42
|
158
|
}
|
43
|
159
|
}
|