Authored by chenchao

new calculate method 4 list timeout

... ... @@ -91,7 +91,10 @@ public class SellerController {
}
/**
* 入驻超级卖家阈值配置
* @return
*/
@RequestMapping(params = "method=ufo.seller.entryThresholds")
@ResponseBody
public ApiResponse getEntryThresholds() {
... ... @@ -101,7 +104,11 @@ public class SellerController {
}
/**
* 入驻的普通卖家当钱包金额满足5000,可以直接申请为超级卖家
* @param uid
* @return
*/
@RequestMapping(params = "method=ufo.seller.applySuperEnter")
@ResponseBody
public ApiResponse applySuperEnter(@RequestParam("uid") Integer uid) {
... ...
package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.ButtonShow;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.QiniuLiveRecord;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.utils.BuyerOrderUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/19.
*/
public abstract class AbsOrderListService extends AbsOrderViewService implements IOrderListService{
private final Logger logger = LoggerFactory.getLogger(getClass());
abstract List<Integer> initOrderListRequest(OrderListRequest request);
abstract int getTotal(int uid, List<Integer> statusQuery);
abstract List<BuyerOrder> getOrderList(int uid, List<Integer> statusQuery, int offset, int limit);
abstract List<BuyerOrderGoods> getOrderGoodsList(int uid, List<Long> orderCodeList);
abstract List<SellerOrderGoods> getBaseOrderGoodsList(List<Integer> skups);
/**
* 获取鉴定视频
* @param buyerOrderList
* @return
*/
abstract Map<Long,String> getAppraiseVideo(List<BuyerOrder> buyerOrderList);
/**
* 订单列表
* @param request
* @return
*/
@Override
public PageResp<OrderListInfo> getOrderList(OrderListRequest request){
// check and init请求参数
List<Integer> statusQuery = initOrderListRequest(request);
TabType actor = request.getActor();
int total = getTotal(request.getUid(), statusQuery);
int limit = request.getLimit();
PageResp.PageRespBuilder respBuilder = PageResp.builder()
.page(request.getPage())
.pageSize(limit)
.total(total)
.pagetotal((total % limit == 0) ? (total / limit) : (total / limit + 1));
if (total == 0){
return respBuilder.build();
}
int offset = (request.getPage() - 1) * limit;
List<BuyerOrder> buyerOrderList = getOrderList(request.getUid(), statusQuery, offset, limit);
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
//TODO 可以提前计算 total offset limit三者之间的关系,减少一次网络I
if (CollectionUtils.isEmpty(orderCodeList)){
return respBuilder.build();
}
// buyer_order_goods ===> skup+商品成交价 1:1
List<BuyerOrderGoods> buyerOrderGoodsList = getOrderGoodsList(request.getUid(), orderCodeList);
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream()
.collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity(), (key1, key2) -> key2));
List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
// seller_order_goods ===> 商品信息
List<SellerOrderGoods> sellerOrderGoodsList = getBaseOrderGoodsList(skups);
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
Map<Long,String> appraiseVideo = getAppraiseVideo(buyerOrderList);
List<OrderListInfo> data = Lists.newArrayList();
buyerOrderList.stream().forEach(buyerOrder -> {
OrderListInfo orderListInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder, actor, appraiseVideo);
if (orderListInfo == null) return;
data.add(orderListInfo);
});
PageResp orderListInfoRsp = respBuilder.data(data).build();
return orderListInfoRsp;
}
/**
* 获取返回结果
* @param buyerOrderGoodsMap
* @param sellerOrderGoodsMap
* @param buyerOrder
* @return
*/
OrderListInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
BuyerOrder buyerOrder,
TabType tabType,
Map<Long,String> appraiseVideo) {
/**
* 1.查询 buyer_order
* 2.查询 buyer_order_goods ==> skup
* 3.查询 seller_order_goods
*/
OrderListInfo orderListInfo = new OrderListInfo();
Integer buyerUid;
Long orderCode;
orderListInfo.setUid(buyerUid=buyerOrder.getUid());
orderListInfo.setBuyerUid(buyerUid);
orderListInfo.setSellerUid(buyerOrder.getSellerUid());
orderListInfo.setOrderCode(orderCode=buyerOrder.getOrderCode());
orderListInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
boolean isOffline = BuyerOrderUtils.isOffline(buyerOrder.getAttributes());
orderListInfo.setIsOffline(isOffline ? "Y" : "N");
// 订单中状态显示
orderListInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
OrderStatus orderStatus = OrderStatus.getOrderStatus(orderListInfo.getStatus());
if (orderStatus == null){
logger.warn("getOrderList orderStatus not exist, uid is {}, orderCode is {}, status is {}",
buyerUid,orderCode, buyerOrder.getStatus());
return null;
}
orderListInfo.setStatuStr(orderStatus.getStatusStr(tabType));
// 当订单状态是待付款, 显示leftTime
Integer leftTime = getLeftTime(tabType, buyerUid, orderCode, buyerOrder.getStatus(), buyerOrder.getCreateTime());
orderListInfo.setLeftTime(leftTime);
// 按钮显示
List<ButtonShowBo> buttonShowBos = orderStatus.getListButtons(tabType);
orderListInfo.setButtons(formatButtons(buyerOrder, buttonShowBos == null ? new ArrayList<>() : new ArrayList<>(buttonShowBos), ViewType.LIST));
// 当剩余时间小于0
if (!CollectionUtils.isEmpty(orderListInfo.getButtons())){
if (orderListInfo.getLeftTime() != null && orderListInfo.getLeftTime() <= 0){
orderListInfo.getButtons().removeIf(x-> x!=null && ButtonShow.NOW_BUY.getCode().equals(x.getCode()));
}
}
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
if (buyerOrderGoods == null){
logger.warn("getOrderList buyer goods not exist, uid is {}, orderCode is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode());
return null;
}
orderListInfo.setSkup(buyerOrderGoods.getSkup());
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
if (sellerOrderGoods == null){
logger.warn("getOrderList seller goods not exist, uid is {}, orderCode is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode());
return null;
}
GoodsInfo goodsInfo = new GoodsInfo();
goodsInfo.setColorName(sellerOrderGoods.getColorName());
goodsInfo.setProductName((isOffline ? "【门店订单】" : "") + sellerOrderGoods.getProductName());
goodsInfo.setGoodImg(ImageUrlAssist.getAllProductPicUrl(sellerOrderGoods.getImageUrl(), "goodsimg", "center", "d2hpdGU="));
goodsInfo.setSizeName(sellerOrderGoods.getSizeName());
goodsInfo.setGoodPrice(buyerOrderGoods.getGoodsPrice() == null ? "" :buyerOrderGoods.getGoodsPrice().toPlainString());
goodsInfo.setStorageId(sellerOrderGoods.getStorageId());
goodsInfo.setProductId(sellerOrderGoods.getProductId());
goodsInfo.setSkup(buyerOrderGoods.getSkup());
orderListInfo.setGoodsInfo(goodsInfo);
orderListInfo.setSecendLevelCreateTime(buyerOrder.getCreateTime());
orderListInfo.setCreateTime(DateUtil.formatDate(buyerOrder.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
setAddressInfo(orderListInfo);
orderListInfo.setAppraiseVideoUrl(appraiseVideo.get(buyerOrder.getOrderCode()));
//
orderListInfo.setPayTimeLimit(OrderInfo.PAY_TIME_SECOND);
return orderListInfo;
}
abstract void setAddressInfo(OrderListInfo orderListInfo);
protected abstract void resetDynamicProporties(List<OrderListInfo> list,int type);
}
package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.ButtonShow;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.utils.BuyerOrderUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/19.
*/
public abstract class AbsOrderListService extends AbsOrderViewService implements IOrderListService{
private final Logger logger = LoggerFactory.getLogger(getClass());
abstract List<Integer> initOrderListRequest(OrderListRequest request);
abstract int getTotal(int uid, List<Integer> statusQuery);
abstract List<BuyerOrder> getOrderList(int uid, List<Integer> statusQuery, int offset, int limit);
abstract List<BuyerOrderGoods> getOrderGoodsList(int uid, List<Long> orderCodeList);
abstract List<SellerOrderGoods> getBaseOrderGoodsList(List<Integer> skups);
/**
* 获取鉴定视频
* @param buyerOrderList
* @return
*/
abstract Map<Long,String> getAppraiseVideo(List<BuyerOrder> buyerOrderList);
/**
* 订单列表
* @param request
* @return
*/
@Override
public PageResp<OrderListInfo> getOrderList(OrderListRequest request){
// check and init请求参数
List<Integer> statusQuery = initOrderListRequest(request);
TabType actor = request.getActor();
int total = getTotal(request.getUid(), statusQuery);
int limit = request.getLimit();
PageResp.PageRespBuilder respBuilder = PageResp.builder()
.page(request.getPage())
.pageSize(limit)
.total(total)
.pagetotal((total % limit == 0) ? (total / limit) : (total / limit + 1));
if (total == 0){
return respBuilder.build();
}
int offset = (request.getPage() - 1) * limit;
List<BuyerOrder> buyerOrderList = getOrderList(request.getUid(), statusQuery, offset, limit);
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
//TODO 可以提前计算 total offset limit三者之间的关系,减少一次网络I
if (CollectionUtils.isEmpty(orderCodeList)){
return respBuilder.build();
}
// buyer_order_goods ===> skup+商品成交价 1:1
List<BuyerOrderGoods> buyerOrderGoodsList = getOrderGoodsList(request.getUid(), orderCodeList);
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream()
.collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity(), (key1, key2) -> key2));
List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
// seller_order_goods ===> 商品信息
List<SellerOrderGoods> sellerOrderGoodsList = getBaseOrderGoodsList(skups);
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
Map<Long,String> appraiseVideo = getAppraiseVideo(buyerOrderList);
List<OrderListInfo> data = Lists.newArrayList();
buyerOrderList.stream().forEach(buyerOrder -> {
OrderListInfo orderListInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder, actor, appraiseVideo);
if (orderListInfo == null) return;
data.add(orderListInfo);
});
PageResp orderListInfoRsp = respBuilder.data(data).build();
return orderListInfoRsp;
}
/**
* 获取返回结果
* @param buyerOrderGoodsMap
* @param sellerOrderGoodsMap
* @param buyerOrder
* @return
*/
OrderListInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
BuyerOrder buyerOrder,
TabType tabType,
Map<Long,String> appraiseVideo) {
/**
* 1.查询 buyer_order
* 2.查询 buyer_order_goods ==> skup
* 3.查询 seller_order_goods
*/
OrderListInfo orderListInfo = new OrderListInfo();
Integer buyerUid;
Long orderCode;
orderListInfo.setUid(buyerUid=buyerOrder.getUid());
orderListInfo.setBuyerUid(buyerUid);
orderListInfo.setSellerUid(buyerOrder.getSellerUid());
orderListInfo.setOrderCode(orderCode=buyerOrder.getOrderCode());
orderListInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
boolean isOffline = BuyerOrderUtils.isOffline(buyerOrder.getAttributes());
orderListInfo.setIsOffline(isOffline ? "Y" : "N");
// 订单中状态显示
orderListInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
OrderStatus orderStatus = OrderStatus.getOrderStatus(orderListInfo.getStatus());
if (orderStatus == null){
logger.warn("getOrderList orderStatus not exist, uid is {}, orderCode is {}, status is {}",
buyerUid,orderCode, buyerOrder.getStatus());
return null;
}
orderListInfo.setStatuStr(orderStatus.getStatusStr(tabType));
// 当订单状态是待付款, 显示leftTime
//Integer leftTime = getLeftTime(tabType, buyerUid, orderCode, buyerOrder.getStatus(), buyerOrder.getCreateTime());
TimeoutBo timeoutBo = calTimeout(tabType, buyerUid, orderCode, buyerOrder.getStatus(), buyerOrder.getCreateTime());
Integer leftTime = timeoutBo.getLeftTime();
orderListInfo.setLeftTime(leftTime);
orderListInfo.setTimeLimit(timeoutBo.getTimelimit());
// 按钮显示
List<ButtonShowBo> buttonShowBos = orderStatus.getListButtons(tabType);
orderListInfo.setButtons(formatButtons(buyerOrder, buttonShowBos == null ? new ArrayList<>() : new ArrayList<>(buttonShowBos), ViewType.LIST));
// 当剩余时间小于0
if (!CollectionUtils.isEmpty(orderListInfo.getButtons())){
if (orderListInfo.getLeftTime() != null && orderListInfo.getLeftTime() <= 0){
orderListInfo.getButtons().removeIf(x-> x!=null && ButtonShow.NOW_BUY.getCode().equals(x.getCode()));
}
}
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
if (buyerOrderGoods == null){
logger.warn("getOrderList buyer goods not exist, uid is {}, orderCode is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode());
return null;
}
orderListInfo.setSkup(buyerOrderGoods.getSkup());
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
if (sellerOrderGoods == null){
logger.warn("getOrderList seller goods not exist, uid is {}, orderCode is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode());
return null;
}
GoodsInfo goodsInfo = new GoodsInfo();
goodsInfo.setColorName(sellerOrderGoods.getColorName());
goodsInfo.setProductName((isOffline ? "【门店订单】" : "") + sellerOrderGoods.getProductName());
goodsInfo.setGoodImg(ImageUrlAssist.getAllProductPicUrl(sellerOrderGoods.getImageUrl(), "goodsimg", "center", "d2hpdGU="));
goodsInfo.setSizeName(sellerOrderGoods.getSizeName());
goodsInfo.setGoodPrice(buyerOrderGoods.getGoodsPrice() == null ? "" :buyerOrderGoods.getGoodsPrice().toPlainString());
goodsInfo.setStorageId(sellerOrderGoods.getStorageId());
goodsInfo.setProductId(sellerOrderGoods.getProductId());
goodsInfo.setSkup(buyerOrderGoods.getSkup());
orderListInfo.setGoodsInfo(goodsInfo);
orderListInfo.setSecendLevelCreateTime(buyerOrder.getCreateTime());
orderListInfo.setCreateTime(DateUtil.formatDate(buyerOrder.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
setAddressInfo(orderListInfo);
orderListInfo.setAppraiseVideoUrl(appraiseVideo.get(buyerOrder.getOrderCode()));
return orderListInfo;
}
abstract void setAddressInfo(OrderListInfo orderListInfo);
protected abstract void resetDynamicProporties(List<OrderListInfo> list,int type);
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.BuyerOrder;
... ... @@ -10,6 +11,10 @@ import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.wrapper.BuyerOrderTimeoutWrapper;
import com.yohoufo.order.service.wrapper.SellerOrderTimeoutWrapper;
import com.yohoufo.order.utils.BuyerOrderUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -31,6 +36,8 @@ public abstract class AbsOrderViewService {
@Autowired
private BuyerCancelCompensateComputeHandler buyerCancelCompensateComputeHandler;
@Autowired
OrderCodeGenerator orderCodeGenerator;
abstract Logger getLogger();
... ... @@ -124,6 +131,81 @@ public abstract class AbsOrderViewService {
return detailDesc;
}
private BuyerOrder buildBuyerOrder4Timeout(Integer uid, Long orderCode, Integer orderStatus, Integer createTime){
BuyerOrder qbo = new BuyerOrder();
qbo.setUid(uid);
qbo.setOrderCode(orderCode);
qbo.setStatus(orderStatus);
qbo.setCreateTime(createTime);
return qbo;
}
TimeoutBo calTimeout(TabType actor, Integer uid, Long orderCode, Integer orderStatus, Integer createTime){
boolean isBuyer = actor.equals(TabType.BUY);
boolean isSeller = actor.equals(TabType.SELL);
TimeoutBo timeoutBo = new TimeoutBo();
if (isBuyer){
boolean isPaid = OrderStatus.HAS_PAYED.getCode() == orderStatus;
boolean isWaitingPay = OrderStatus.WAITING_PAY.getCode() == orderStatus;
if (isPaid){
BuyerOrder qbo = buildBuyerOrder4Timeout(uid,orderCode,orderStatus,createTime);
timeoutBo = new BuyerOrderTimeoutWrapper(qbo, ordersPayService::getDeliverLeftTime)
.calDeliverLeftTime();
}
if (isWaitingPay){
BuyerOrder qbo = buildBuyerOrder4Timeout(uid,orderCode,orderStatus,createTime);
timeoutBo = new BuyerOrderTimeoutWrapper(qbo).calPayLeftTime(actor);
}
}
if (isSeller){
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
if (codeMeta!=null) {
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
boolean isWaitingPay;
boolean isPaid;
//查看买家
if (orderCodeType == OrderCodeType.BUYER_TYPE) {
isWaitingPay = orderStatus == OrderStatus.WAITING_PAY.getCode();
if (isWaitingPay) {
timeoutBo = new SellerOrderTimeoutWrapper()
.orderCodeType(orderCodeType)
.orderStatus(orderStatus)
.createTime(createTime)
.calculatePayLeftTime();
}
isPaid = orderStatus == OrderStatus.HAS_PAYED.getCode();
if (isPaid){
BuyerOrder qbo = buildBuyerOrder4Timeout(uid,orderCode,orderStatus,createTime);
timeoutBo = new BuyerOrderTimeoutWrapper(qbo, ordersPayService::getDeliverLeftTime)
.calDeliverLeftTime();
}
}
//查看卖家
if (orderCodeType == OrderCodeType.SELLER_TYPE) {
isWaitingPay = orderStatus == SkupStatus.CAN_NOT_SELL.getCode();
if (isWaitingPay) {
timeoutBo = new SellerOrderTimeoutWrapper()
.orderCodeType(orderCodeType)
.orderStatus(orderStatus)
.createTime(createTime)
.calculatePayLeftTime();
}
}
}
}
Integer leftTime = timeoutBo.getLeftTime();
if (leftTime != null && leftTime<0){
timeoutBo.setLeftTime(0);
}
return timeoutBo;
}
@Deprecated
Integer getLeftTime(TabType actor, Integer uid, Long orderCode, Integer orderStatus, Integer createTime){
Integer leftTime =null;
Integer payLeftTime = getPayLeftTime(actor, orderStatus,
... ... @@ -149,6 +231,15 @@ public abstract class AbsOrderViewService {
return leftTime;
}
/**
* 请移步至
* @see {@link SellerOrderTimeoutWrapper#calculatePayLeftTime()}
* @param orderCodeType
* @param orderStatus
* @param createTime
* @return
*/
@Deprecated
Integer getPayLeftTime4Seller(OrderCodeType orderCodeType, Integer orderStatus, int createTime){
if (orderCodeType == null){
return null;
... ... @@ -186,7 +277,8 @@ public abstract class AbsOrderViewService {
Integer getDeliverLeftTime(int buyerUid, long orderCode, Integer orderStatus){
Integer leftTime = null;
if (OrderStatus.HAS_PAYED.getCode() == orderStatus){
leftTime = ordersPayService.getDeliverLeftTime(buyerUid, orderCode);
TimeoutBo timeoutBo = ordersPayService.getDeliverLeftTime(buyerUid, orderCode);
leftTime = timeoutBo.getLeftTime();
}
return leftTime;
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl;
import com.google.common.collect.Maps;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.ButtonShow;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.common.TabType;
... ... @@ -128,9 +129,14 @@ public class BuyerOrderListServiceImpl extends AbsOrderListService implements IO
if(CollectionUtils.isNotEmpty(list)){
processButtons(list);
list.forEach(oli -> {
Integer leftTime = getLeftTime(TabType.BUY, oli.getUid(), oli.getOrderCode(), oli.getStatus(),
//Integer leftTime = getLeftTime(TabType.BUY, oli.getUid(), oli.getOrderCode(), oli.getStatus(),
// oli.getSecendLevelCreateTime());
TimeoutBo timeoutBo = calTimeout(TabType.BUY, oli.getUid(), oli.getOrderCode(), oli.getStatus(),
oli.getSecendLevelCreateTime());
oli.setLeftTime(leftTime);
Integer leftTime = timeoutBo.getLeftTime();
oli.setLeftTime(leftTime);
oli.setTimeLimit(timeoutBo.getTimelimit());
if (oli.getLeftTime()!=null && oli.getLeftTime()<=0){
oli.getButtons().removeIf(x-> x!=null && ButtonShow.NOW_BUY.getCode().equals(x.getCode()));
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.constants.TimeoutCase;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.OrdersPayMapper;
import com.yohoufo.dal.order.model.OrdersPay;
... ... @@ -16,11 +18,20 @@ public class OrdersPayService {
@Autowired
private OrdersPayMapper ordersPayMapper;
public Integer getDeliverLeftTime(int buyerUid, long orderCode){
public TimeoutBo getDeliverLeftTime(int buyerUid, long orderCode){
OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(orderCode, buyerUid);
if (ordersPay == null){
return null;
}
return DelayTime.MINUTES_36_HOURS * 60 - (DateUtil.getCurrentTimeSecond()-ordersPay.getCreateTime());
int timelimit = DelayTime.MINUTES_36_HOURS * 60;
Integer createTime = ordersPay.getCreateTime();
int left = timelimit - (DateUtil.getCurrentTimeSecond()-createTime);
TimeoutBo timeoutBo = new TimeoutBo();
timeoutBo.setLeftTime(left);
timeoutBo.setStartTime(createTime);
timeoutBo.setTimelimit(timelimit);
timeoutBo.setTimeoutCase(TimeoutCase.DELIVER);
return timeoutBo;
}
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
... ... @@ -31,6 +32,7 @@ import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.wrapper.SellerOrderTimeoutWrapper;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -272,8 +274,13 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
.build();
// 待付款时 或待发货,剩余时间
Integer leftTime = getPayLeftTime4Seller(OrderCodeType.SELLER_TYPE,
skupStatus.getCode(), order.getCreateTime());
//Integer leftTime = getPayLeftTime4Seller(OrderCodeType.SELLER_TYPE, skupStatus.getCode(), order.getCreateTime());
TimeoutBo timeoutBo = new SellerOrderTimeoutWrapper()
.createTime(order.getCreateTime())
.orderCodeType(OrderCodeType.SELLER_TYPE)
.orderStatus(skupStatus.getCode())
.calculatePayLeftTime();
Integer leftTime = timeoutBo.getLeftTime();
statusDetail.setLeftTime(leftTime);
return statusDetail;
... ... @@ -366,7 +373,13 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
return ActionStatusHold.getSellerOrderIsPaidStatusList().contains(skupStatus.getCode()) ? 1 : 0;
}
/**
* 当卖家查看买家订单时才会调用
* @param buyerOrder
* @param orderStatus
* @param tabType
* @return
*/
@Override
protected OrderDetailInfo.StatusDetail getStatusDetail(BuyerOrder buyerOrder,OrderStatus orderStatus, TabType tabType) {
OrderDetailInfo.StatusDetail statusDetail = OrderDetailInfo.StatusDetail.builder()
... ... @@ -401,7 +414,12 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
Integer orderStatus = orderDetailInfo.getStatusDetail().getStatus();
if (codeMeta!=null) {
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
Integer leftTime = getPayLeftTime4Seller(orderCodeType, orderStatus, orderDetailInfo.getSecendLevelCreateTime());
//Integer leftTime = getPayLeftTime4Seller(orderCodeType, orderStatus, orderDetailInfo.getSecendLevelCreateTime());
TimeoutBo timeoutBo = new SellerOrderTimeoutWrapper().createTime(orderDetailInfo.getSecendLevelCreateTime())
.orderCodeType(orderCodeType)
.orderStatus(orderStatus)
.calculatePayLeftTime();
Integer leftTime = timeoutBo.getLeftTime();
orderDetailInfo.getStatusDetail().setLeftTime(leftTime);
if (leftTime!=null && leftTime<=0){
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
... ... @@ -30,6 +31,7 @@ import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.wrapper.SellerOrderTimeoutWrapper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -70,8 +72,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
@Autowired
private ProductProxyService productProxyService;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@Autowired
private SkupListService skupListService;
... ... @@ -182,7 +183,13 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
Integer orderStatus = oli.getStatus();
if (codeMeta!=null){
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
oli.setLeftTime(getPayLeftTime4Seller(orderCodeType, orderStatus, oli.getSecendLevelCreateTime()));
TimeoutBo timeoutBo = new SellerOrderTimeoutWrapper().createTime(oli.getSecendLevelCreateTime())
.orderCodeType(orderCodeType)
.orderStatus(orderStatus)
.calculatePayLeftTime();
oli.setLeftTime(timeoutBo.getLeftTime());
oli.setTimeLimit(timeoutBo.getTimelimit());
//oli.setLeftTime(getPayLeftTime4Seller(orderCodeType, orderStatus, oli.getSecendLevelCreateTime()));
}
... ... @@ -278,7 +285,6 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
if (SHOW_OVER_FLOW_PRICE_STATUS.contains(skupStatus.getCode())){
orderListInfo.setTips(overPriceTipsMap.get(OrderAssist.overFlowPriceKey(sellerOrderGoods.getStorageId(), sellerOrderGoods.getGoodsPrice())));
}
orderListInfo.setPayTimeLimit(OrderInfo.SELLER_PAY_TIMEOUT);
return orderListInfo;
}
... ...
... ... @@ -421,7 +421,6 @@ public class SkupListService {
productInfo.setStorageNumDesc(psogOfMerge.getStorageNum() + "个商品库存");
}
orderListInfo.setGoodsInfo(productInfo);
orderListInfo.setPayTimeLimit(OrderInfo.SELLER_PAY_TIMEOUT);
return orderListInfo;
}
... ...
package com.yohoufo.order.service.wrapper;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohoufo.common.utils.DateUtil;
import org.slf4j.Logger;
import java.util.function.BiFunction;
/**
* Created by chao.chen on 2019/1/23.
*/
public abstract class AbsTimeoutWrapper {
Logger logger;
BiFunction<Integer,Long,TimeoutBo> deliverLeftTimeDS ;
protected int calLeftTime(int timeout, int creatTime){
int payExpire = timeout - (DateUtil.getCurrentTimeSecond() - creatTime);
if (payExpire < 0){
payExpire = 0;
}
return payExpire;
}
}
... ...
package com.yohoufo.order.service.wrapper;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.constants.TimeoutCase;
import com.yohoufo.dal.order.model.BuyerOrder;
import org.slf4j.Logger;
import java.util.function.BiFunction;
/**
* Created by chao.chen on 2019/1/23.
*/
public class BuyerOrderTimeoutWrapper extends AbsTimeoutWrapper{
private BuyerOrder buyerOrder;
private BuyerOrderTimeoutWrapper(){
throw new RuntimeException("what r u doing?");
}
public BuyerOrderTimeoutWrapper(BuyerOrder buyerOrder, BiFunction<Integer,Long,TimeoutBo> deliverLeftTimeDS){
this.buyerOrder = buyerOrder;
this.deliverLeftTimeDS = deliverLeftTimeDS;
}
public BuyerOrderTimeoutWrapper(BuyerOrder buyerOrder){
this.buyerOrder = buyerOrder;
}
public BuyerOrderTimeoutWrapper logger(Logger logger){
this.logger = logger;
return this;
}
public TimeoutBo calDeliverLeftTime(){
int buyerUid = buyerOrder.getUid();
long orderCode = buyerOrder.getOrderCode();
Integer orderStatus = buyerOrder.getStatus();
TimeoutBo timeoutBo = new TimeoutBo();
if (OrderStatus.HAS_PAYED.getCode() == orderStatus){
timeoutBo = deliverLeftTimeDS.apply(buyerUid, orderCode);
}
return timeoutBo;
}
public TimeoutBo calPayLeftTime(TabType actor){
Integer orderStatus = buyerOrder.getStatus();
int createTime = buyerOrder.getCreateTime();
boolean isBuyer = actor.equals(TabType.BUY);
boolean isSeller = actor.equals(TabType.SELL);
Integer leftTime = null;
int timeout = OrderInfo.PAY_TIME_SECOND;
boolean isFiredCal = (isBuyer && orderStatus == OrderStatus.WAITING_PAY.getCode())
|| (isSeller && orderStatus == SkupStatus.CAN_NOT_SELL.getCode());
if(isFiredCal){
leftTime = calLeftTime(timeout, createTime);
}
TimeoutBo timeoutBo = new TimeoutBo();
timeoutBo.setLeftTime(leftTime);
timeoutBo.setTimelimit(timeout);
timeoutBo.setStartTime(createTime);
timeoutBo.setTimeoutCase(TimeoutCase.PAY);
return timeoutBo;
}
}
... ...
package com.yohoufo.order.service.wrapper;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.constants.TimeoutCase;
/**
* Created by chao.chen on 2019/1/23.
*
* @author chao.chen
* @since yohobuy version 6.8.5
*/
public class SellerOrderTimeoutWrapper extends AbsTimeoutWrapper{
private OrderCodeType orderCodeType;
private Integer orderStatus;
private int createTime;
public SellerOrderTimeoutWrapper orderCodeType(OrderCodeType orderCodeType){
this.orderCodeType = orderCodeType;
return this;
}
public SellerOrderTimeoutWrapper orderStatus(Integer orderStatus){
this.orderStatus = orderStatus;
return this;
}
public SellerOrderTimeoutWrapper createTime(int createTime){
this.createTime = createTime;
return this;
}
/**
*
* @return
*/
public TimeoutBo calculatePayLeftTime(){
if (orderCodeType == null){
return null;
}
Integer leftTime = null;
Integer timeout = OrderInfo.PAY_TIME_SECOND;
boolean isWaitingPay = false;
//查看买家
if (orderCodeType == OrderCodeType.BUYER_TYPE){
isWaitingPay = orderStatus == OrderStatus.WAITING_PAY.getCode();
if (isWaitingPay){
timeout = OrderInfo.PAY_TIME_SECOND;
}
}
//查看卖家
if (orderCodeType == OrderCodeType.SELLER_TYPE){
isWaitingPay = orderStatus == SkupStatus.CAN_NOT_SELL.getCode();
if (isWaitingPay)timeout = OrderInfo.SELLER_PAY_TIMEOUT;
}
if(isWaitingPay){
leftTime = calLeftTime(timeout, createTime);
}
TimeoutBo timeoutBo = new TimeoutBo();
timeoutBo.setLeftTime(leftTime);
timeoutBo.setTimelimit(timeout);
timeoutBo.setStartTime(createTime);
timeoutBo.setTimeoutCase(TimeoutCase.PAY);
return timeoutBo;
}
}
... ...