...
|
...
|
@@ -7,7 +7,6 @@ import com.yoho.quartz.domain.JobProcessResult; |
|
|
import com.yoho.quartz.job.YhJob;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.constants.ConfirmDesc;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.common.utils.PageHelper;
|
|
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
...
|
...
|
@@ -19,8 +18,10 @@ import com.yohoufo.dal.order.model.BuyerOrderGoods; |
|
|
import com.yohoufo.dal.order.model.OrdersPay;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.order.model.dto.DTNode;
|
|
|
import com.yohoufo.order.model.dto.PreSaleOrderConfig;
|
|
|
import com.yohoufo.order.service.cache.OrderCacheService;
|
|
|
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
|
|
|
import com.yohoufo.order.service.impl.MetaConfigService;
|
|
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import lombok.experimental.Builder;
|
...
|
...
|
@@ -30,6 +31,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
...
|
...
|
@@ -64,6 +66,9 @@ public class PreSaleOrderJob implements YhJob { |
|
|
@Autowired
|
|
|
private InBoxFacade inBoxFacade;
|
|
|
|
|
|
@Autowired
|
|
|
private MetaConfigService metaConfigService;
|
|
|
|
|
|
|
|
|
private static final long CACHE_EXPIRED_TIME = 24*3600L;
|
|
|
|
...
|
...
|
@@ -77,6 +82,7 @@ public class PreSaleOrderJob implements YhJob { |
|
|
int cnt = buyerOrderViewMapper.selectAllCntByAttr(status, oa);
|
|
|
|
|
|
if (cnt==0){
|
|
|
logger.info("in PreSaleOrderJob.process no paid pre-sale order");
|
|
|
return null;
|
|
|
}
|
|
|
final int pageSize = 10;
|
...
|
...
|
@@ -85,20 +91,22 @@ public class PreSaleOrderJob implements YhJob { |
|
|
Integer lastId = null;
|
|
|
|
|
|
List<BuyerOrder> bos;
|
|
|
|
|
|
//TODO 第35天 自动超时取消
|
|
|
|
|
|
// 查询条件 预售 + 支付完成(待卖家发货)+ 支付时间到当前时间的差值在(0,35] 单位:天
|
|
|
|
|
|
//TODO 第31天开始 到34天,通知剩余发货时间
|
|
|
List<BuyerOrder> over35DaysBOs = new ArrayList<>(cnt);
|
|
|
List<BuyerOrderWrapper> from30To34BOs = new ArrayList<>(cnt);
|
|
|
final int currentSencond = DateUtil.getCurrentTimeSecond();
|
|
|
|
|
|
PreSaleOrderConfig psoc = metaConfigService.getPreSaleOrderConfig();
|
|
|
PreSaleOrderConfig.Range cancelRange = psoc.getAutoCancelRange(),
|
|
|
noticeRange = psoc.getNoticeRange();
|
|
|
int minCancelTR;
|
|
|
final int secondsOfCancelDays = secondsFromTimeRange(minCancelTR=cancelRange.getMin(), cancelRange.getTimeUnit()),
|
|
|
secondsOfNoticeDays = secondsFromTimeRange(noticeRange.getMin(), noticeRange.getTimeUnit());
|
|
|
for(int i=0; i<pageTotal; i++){
|
|
|
bos = buyerOrderViewMapper.selectAllByAttr(status, oa, lastId, pageSize);
|
|
|
if (Objects.nonNull(bos)){
|
|
|
Node node = processSub(bos, currentSencond);
|
|
|
Node node = processSub(bos, currentSencond, secondsOfCancelDays, secondsOfNoticeDays);
|
|
|
over35DaysBOs.addAll(node.over35DaysBOs);
|
|
|
from30To34BOs.addAll(node.from30To34BOs);
|
|
|
lastId = node.lastId;
|
...
|
...
|
@@ -121,9 +129,9 @@ public class PreSaleOrderJob implements YhJob { |
|
|
Integer times = orderCacheService.getOrderDeliverNoticeTimes(orderCode, nowDateStr);
|
|
|
if (times==null){
|
|
|
//todo 发送通知
|
|
|
int leftTime = 35*3600 - needNoticBO.diffSeconds;
|
|
|
int leftTime = calLeftTime(minCancelTR ,needNoticBO.diffSeconds);
|
|
|
DTNode node = DTNode.calBySeconds(leftTime);
|
|
|
//todo 35天走配置
|
|
|
//35天走配置
|
|
|
int leftHours = node.days * 24 + node.hours + node.minutes/30;
|
|
|
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
|
|
|
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
|
...
|
...
|
@@ -138,10 +146,18 @@ public class PreSaleOrderJob implements YhJob { |
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private int calLeftTime(int minCancelTR, int diffSeconds){
|
|
|
int leftTime = minCancelTR*24*3600 - diffSeconds;
|
|
|
if (leftTime<0){
|
|
|
leftTime = new BigDecimal(leftTime).abs().intValue();
|
|
|
}
|
|
|
return leftTime;
|
|
|
}
|
|
|
|
|
|
static final int secondsOf35Days = secondsOfDays(35), secondsOf31Days = secondsOfDays(31);
|
|
|
|
|
|
Node processSub(List<BuyerOrder> bos, int currentSencond){
|
|
|
|
|
|
|
|
|
Node processSub(List<BuyerOrder> bos, int currentSencond, int secondsOfCancelDays, int secondsOfNoticeDays){
|
|
|
BuyerOrder lastBO = null;
|
|
|
Node node = new Node(bos.size());
|
|
|
List<BuyerOrder> over35DaysBOs = node.over35DaysBOs;
|
...
|
...
|
@@ -157,11 +173,11 @@ public class PreSaleOrderJob implements YhJob { |
|
|
Integer payTime = op.getCreateTime();
|
|
|
int diff = currentSencond-payTime;
|
|
|
//超过35天
|
|
|
if (diff>=secondsOf35Days){
|
|
|
if (diff>=secondsOfCancelDays){
|
|
|
over35DaysBOs.add(orderCodes2BoMap.get(op.getOrderCode()));
|
|
|
}else {
|
|
|
//超过30天(第31天),不到35天
|
|
|
if (diff>=secondsOf31Days) {
|
|
|
if (diff>=secondsOfNoticeDays) {
|
|
|
BuyerOrder buyerOrder = orderCodes2BoMap.get(op.getOrderCode());
|
|
|
BuyerOrderWrapper bow = BuyerOrderWrapper.builder().buyerOrder(buyerOrder)
|
|
|
.diffSeconds(diff).build();
|
...
|
...
|
@@ -188,6 +204,23 @@ public class PreSaleOrderJob implements YhJob { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private static int secondsFromTimeRange(int time, TimeUnit timeUnit){
|
|
|
int seconds = 0;
|
|
|
switch (timeUnit){
|
|
|
case DAYS:
|
|
|
seconds = secondsOfDays(time);
|
|
|
break;
|
|
|
case HOURS:
|
|
|
seconds = secondsOfHours(time);
|
|
|
break;
|
|
|
}
|
|
|
return seconds;
|
|
|
}
|
|
|
|
|
|
private static int secondsOfHours(int hours){
|
|
|
return hours * 3600;
|
|
|
}
|
|
|
|
|
|
private static int secondsOfDays(int days){
|
|
|
return days * 24 * 3600;
|
|
|
}
|
...
|
...
|
|