|
@@ -7,7 +7,6 @@ import com.yoho.quartz.domain.JobProcessResult; |
|
@@ -7,7 +7,6 @@ import com.yoho.quartz.domain.JobProcessResult; |
7
|
import com.yoho.quartz.job.YhJob;
|
7
|
import com.yoho.quartz.job.YhJob;
|
8
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
8
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
9
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
9
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
10
|
-import com.yohobuy.ufo.model.order.constants.ConfirmDesc;
|
|
|
11
|
import com.yohoufo.common.utils.DateUtil;
|
10
|
import com.yohoufo.common.utils.DateUtil;
|
12
|
import com.yohoufo.common.utils.PageHelper;
|
11
|
import com.yohoufo.common.utils.PageHelper;
|
13
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
12
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
@@ -19,8 +18,10 @@ import com.yohoufo.dal.order.model.BuyerOrderGoods; |
|
@@ -19,8 +18,10 @@ import com.yohoufo.dal.order.model.BuyerOrderGoods; |
19
|
import com.yohoufo.dal.order.model.OrdersPay;
|
18
|
import com.yohoufo.dal.order.model.OrdersPay;
|
20
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
19
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
21
|
import com.yohoufo.order.model.dto.DTNode;
|
20
|
import com.yohoufo.order.model.dto.DTNode;
|
|
|
21
|
+import com.yohoufo.order.model.dto.PreSaleOrderConfig;
|
22
|
import com.yohoufo.order.service.cache.OrderCacheService;
|
22
|
import com.yohoufo.order.service.cache.OrderCacheService;
|
23
|
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
|
23
|
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
|
|
|
24
|
+import com.yohoufo.order.service.impl.MetaConfigService;
|
24
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
25
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
25
|
import com.yohoufo.order.utils.LoggerUtils;
|
26
|
import com.yohoufo.order.utils.LoggerUtils;
|
26
|
import lombok.experimental.Builder;
|
27
|
import lombok.experimental.Builder;
|
|
@@ -30,6 +31,7 @@ import org.springframework.stereotype.Service; |
|
@@ -30,6 +31,7 @@ import org.springframework.stereotype.Service; |
30
|
|
31
|
|
31
|
import java.math.BigDecimal;
|
32
|
import java.math.BigDecimal;
|
32
|
import java.util.*;
|
33
|
import java.util.*;
|
|
|
34
|
+import java.util.concurrent.TimeUnit;
|
33
|
import java.util.function.Function;
|
35
|
import java.util.function.Function;
|
34
|
import java.util.stream.Collectors;
|
36
|
import java.util.stream.Collectors;
|
35
|
|
37
|
|
|
@@ -64,6 +66,9 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -64,6 +66,9 @@ public class PreSaleOrderJob implements YhJob { |
64
|
@Autowired
|
66
|
@Autowired
|
65
|
private InBoxFacade inBoxFacade;
|
67
|
private InBoxFacade inBoxFacade;
|
66
|
|
68
|
|
|
|
69
|
+ @Autowired
|
|
|
70
|
+ private MetaConfigService metaConfigService;
|
|
|
71
|
+
|
67
|
|
72
|
|
68
|
private static final long CACHE_EXPIRED_TIME = 24*3600L;
|
73
|
private static final long CACHE_EXPIRED_TIME = 24*3600L;
|
69
|
|
74
|
|
|
@@ -77,6 +82,7 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -77,6 +82,7 @@ public class PreSaleOrderJob implements YhJob { |
77
|
int cnt = buyerOrderViewMapper.selectAllCntByAttr(status, oa);
|
82
|
int cnt = buyerOrderViewMapper.selectAllCntByAttr(status, oa);
|
78
|
|
83
|
|
79
|
if (cnt==0){
|
84
|
if (cnt==0){
|
|
|
85
|
+ logger.info("in PreSaleOrderJob.process no paid pre-sale order");
|
80
|
return null;
|
86
|
return null;
|
81
|
}
|
87
|
}
|
82
|
final int pageSize = 10;
|
88
|
final int pageSize = 10;
|
|
@@ -85,20 +91,22 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -85,20 +91,22 @@ public class PreSaleOrderJob implements YhJob { |
85
|
Integer lastId = null;
|
91
|
Integer lastId = null;
|
86
|
|
92
|
|
87
|
List<BuyerOrder> bos;
|
93
|
List<BuyerOrder> bos;
|
88
|
-
|
|
|
89
|
//TODO 第35天 自动超时取消
|
94
|
//TODO 第35天 自动超时取消
|
90
|
-
|
|
|
91
|
// 查询条件 预售 + 支付完成(待卖家发货)+ 支付时间到当前时间的差值在(0,35] 单位:天
|
95
|
// 查询条件 预售 + 支付完成(待卖家发货)+ 支付时间到当前时间的差值在(0,35] 单位:天
|
92
|
-
|
|
|
93
|
//TODO 第31天开始 到34天,通知剩余发货时间
|
96
|
//TODO 第31天开始 到34天,通知剩余发货时间
|
94
|
List<BuyerOrder> over35DaysBOs = new ArrayList<>(cnt);
|
97
|
List<BuyerOrder> over35DaysBOs = new ArrayList<>(cnt);
|
95
|
List<BuyerOrderWrapper> from30To34BOs = new ArrayList<>(cnt);
|
98
|
List<BuyerOrderWrapper> from30To34BOs = new ArrayList<>(cnt);
|
96
|
final int currentSencond = DateUtil.getCurrentTimeSecond();
|
99
|
final int currentSencond = DateUtil.getCurrentTimeSecond();
|
97
|
-
|
100
|
+ PreSaleOrderConfig psoc = metaConfigService.getPreSaleOrderConfig();
|
|
|
101
|
+ PreSaleOrderConfig.Range cancelRange = psoc.getAutoCancelRange(),
|
|
|
102
|
+ noticeRange = psoc.getNoticeRange();
|
|
|
103
|
+ int minCancelTR;
|
|
|
104
|
+ final int secondsOfCancelDays = secondsFromTimeRange(minCancelTR=cancelRange.getMin(), cancelRange.getTimeUnit()),
|
|
|
105
|
+ secondsOfNoticeDays = secondsFromTimeRange(noticeRange.getMin(), noticeRange.getTimeUnit());
|
98
|
for(int i=0; i<pageTotal; i++){
|
106
|
for(int i=0; i<pageTotal; i++){
|
99
|
bos = buyerOrderViewMapper.selectAllByAttr(status, oa, lastId, pageSize);
|
107
|
bos = buyerOrderViewMapper.selectAllByAttr(status, oa, lastId, pageSize);
|
100
|
if (Objects.nonNull(bos)){
|
108
|
if (Objects.nonNull(bos)){
|
101
|
- Node node = processSub(bos, currentSencond);
|
109
|
+ Node node = processSub(bos, currentSencond, secondsOfCancelDays, secondsOfNoticeDays);
|
102
|
over35DaysBOs.addAll(node.over35DaysBOs);
|
110
|
over35DaysBOs.addAll(node.over35DaysBOs);
|
103
|
from30To34BOs.addAll(node.from30To34BOs);
|
111
|
from30To34BOs.addAll(node.from30To34BOs);
|
104
|
lastId = node.lastId;
|
112
|
lastId = node.lastId;
|
|
@@ -121,9 +129,9 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -121,9 +129,9 @@ public class PreSaleOrderJob implements YhJob { |
121
|
Integer times = orderCacheService.getOrderDeliverNoticeTimes(orderCode, nowDateStr);
|
129
|
Integer times = orderCacheService.getOrderDeliverNoticeTimes(orderCode, nowDateStr);
|
122
|
if (times==null){
|
130
|
if (times==null){
|
123
|
//todo 发送通知
|
131
|
//todo 发送通知
|
124
|
- int leftTime = 35*3600 - needNoticBO.diffSeconds;
|
132
|
+ int leftTime = calLeftTime(minCancelTR ,needNoticBO.diffSeconds);
|
125
|
DTNode node = DTNode.calBySeconds(leftTime);
|
133
|
DTNode node = DTNode.calBySeconds(leftTime);
|
126
|
- //todo 35天走配置
|
134
|
+ //35天走配置
|
127
|
int leftHours = node.days * 24 + node.hours + node.minutes/30;
|
135
|
int leftHours = node.days * 24 + node.hours + node.minutes/30;
|
128
|
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
|
136
|
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
|
129
|
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
|
137
|
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
|
|
@@ -138,10 +146,18 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -138,10 +146,18 @@ public class PreSaleOrderJob implements YhJob { |
138
|
return null;
|
146
|
return null;
|
139
|
}
|
147
|
}
|
140
|
|
148
|
|
|
|
149
|
+ private int calLeftTime(int minCancelTR, int diffSeconds){
|
|
|
150
|
+ int leftTime = minCancelTR*24*3600 - diffSeconds;
|
|
|
151
|
+ if (leftTime<0){
|
|
|
152
|
+ leftTime = new BigDecimal(leftTime).abs().intValue();
|
|
|
153
|
+ }
|
|
|
154
|
+ return leftTime;
|
|
|
155
|
+ }
|
141
|
|
156
|
|
142
|
- static final int secondsOf35Days = secondsOfDays(35), secondsOf31Days = secondsOfDays(31);
|
|
|
143
|
|
157
|
|
144
|
- Node processSub(List<BuyerOrder> bos, int currentSencond){
|
158
|
+
|
|
|
159
|
+
|
|
|
160
|
+ Node processSub(List<BuyerOrder> bos, int currentSencond, int secondsOfCancelDays, int secondsOfNoticeDays){
|
145
|
BuyerOrder lastBO = null;
|
161
|
BuyerOrder lastBO = null;
|
146
|
Node node = new Node(bos.size());
|
162
|
Node node = new Node(bos.size());
|
147
|
List<BuyerOrder> over35DaysBOs = node.over35DaysBOs;
|
163
|
List<BuyerOrder> over35DaysBOs = node.over35DaysBOs;
|
|
@@ -157,11 +173,11 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -157,11 +173,11 @@ public class PreSaleOrderJob implements YhJob { |
157
|
Integer payTime = op.getCreateTime();
|
173
|
Integer payTime = op.getCreateTime();
|
158
|
int diff = currentSencond-payTime;
|
174
|
int diff = currentSencond-payTime;
|
159
|
//超过35天
|
175
|
//超过35天
|
160
|
- if (diff>=secondsOf35Days){
|
176
|
+ if (diff>=secondsOfCancelDays){
|
161
|
over35DaysBOs.add(orderCodes2BoMap.get(op.getOrderCode()));
|
177
|
over35DaysBOs.add(orderCodes2BoMap.get(op.getOrderCode()));
|
162
|
}else {
|
178
|
}else {
|
163
|
//超过30天(第31天),不到35天
|
179
|
//超过30天(第31天),不到35天
|
164
|
- if (diff>=secondsOf31Days) {
|
180
|
+ if (diff>=secondsOfNoticeDays) {
|
165
|
BuyerOrder buyerOrder = orderCodes2BoMap.get(op.getOrderCode());
|
181
|
BuyerOrder buyerOrder = orderCodes2BoMap.get(op.getOrderCode());
|
166
|
BuyerOrderWrapper bow = BuyerOrderWrapper.builder().buyerOrder(buyerOrder)
|
182
|
BuyerOrderWrapper bow = BuyerOrderWrapper.builder().buyerOrder(buyerOrder)
|
167
|
.diffSeconds(diff).build();
|
183
|
.diffSeconds(diff).build();
|
|
@@ -188,6 +204,23 @@ public class PreSaleOrderJob implements YhJob { |
|
@@ -188,6 +204,23 @@ public class PreSaleOrderJob implements YhJob { |
188
|
}
|
204
|
}
|
189
|
}
|
205
|
}
|
190
|
|
206
|
|
|
|
207
|
+ private static int secondsFromTimeRange(int time, TimeUnit timeUnit){
|
|
|
208
|
+ int seconds = 0;
|
|
|
209
|
+ switch (timeUnit){
|
|
|
210
|
+ case DAYS:
|
|
|
211
|
+ seconds = secondsOfDays(time);
|
|
|
212
|
+ break;
|
|
|
213
|
+ case HOURS:
|
|
|
214
|
+ seconds = secondsOfHours(time);
|
|
|
215
|
+ break;
|
|
|
216
|
+ }
|
|
|
217
|
+ return seconds;
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ private static int secondsOfHours(int hours){
|
|
|
221
|
+ return hours * 3600;
|
|
|
222
|
+ }
|
|
|
223
|
+
|
191
|
private static int secondsOfDays(int days){
|
224
|
private static int secondsOfDays(int days){
|
192
|
return days * 24 * 3600;
|
225
|
return days * 24 * 3600;
|
193
|
}
|
226
|
}
|