Authored by tanling

订单列表

package com.yohoufo.order.common;
public enum ButtonShow {
CANCEL_ORDER("cancel_order","取消订单"),
NOW_BUY("now_buy", "立即支付"),
CONFIRM_DELIVERY("confirm_delivery", "确认收货"),
SHOW_DETAIL("show_detail", "查看详情"),
BUY_AGAIN("buy_again", "再次购买"),
DEL_ORDER("del_order", "删除"),
SHOW_EXPRESS("show_express", "查看物流"),
;
String code;
String value;
ButtonShow(String code,String value) {
this.code = code;
this.value = value;
}
}
... ...
... ... @@ -31,12 +31,12 @@ public enum OrderListType {
String desc;
List<Integer> status;
List<Integer> statusQuery;
OrderListType(int type, String desc, List<Integer> status) {
OrderListType(int type, String desc, List<Integer> statusQuery) {
this.type = type;
this.desc = desc;
this.status = status;
this.statusQuery = statusQuery;
}
/**
... ... @@ -57,11 +57,7 @@ public enum OrderListType {
return type;
}
public String getDesc() {
return desc;
}
public List<Integer> getStatus() {
return status;
public List<Integer> getStatusQuery() {
return statusQuery;
}
}
... ...
package com.yohoufo.order.common;
import java.util.Arrays;
import java.util.List;
public enum OrderStatus {
// 14:支付前取消,15:超时未支付取消,16:已支付,卖家发货前取消;17:客服取消
WAITING_PAY(0, "未付款"),
HAS_PAYED(1, "已付款"),
SELLER_SEND_OUT(2, "商品调拨中(卖家发货,可查物流)"),
PLATFORM_CHECKING(3, "有货平台鉴定中"),
WAITING_RECEIVE(4, "待收货"),
DONE(5, "已完成"),
SELLER_CANCEL_BEFORE_PAY(10, "买家付款前卖家取消"),
SELLER_CANCEL_AFTER_PAY(11, "买家付款后卖家取消"),
SEND_OUT_TIMEOUT(12, "超时未发货取消"),
CHECKING_FAKE(13, "鉴定不通过取消"),
BUYER_CANCEL_BEFORE_PAY(14, "支付前取消"),
BUYER_CANCEL_TIMEOUT(15, "超时未支付取消"),
CUSTOMER_SERVICE(17, "客服取消")
WAITING_PAY(0,
"未付款",
"待付款",
Arrays.asList(ButtonShow.CANCEL_ORDER, ButtonShow.NOW_BUY)),
HAS_PAYED(1,
"已付款",
"商品调拨中",
Arrays.asList(ButtonShow.SHOW_DETAIL)),
SELLER_SEND_OUT(2,
"商品调拨中(卖家发货,可查物流)",
"商品调拨中",
Arrays.asList(ButtonShow.SHOW_DETAIL)),
PLATFORM_CHECKING(3,
"有货平台鉴定中",
"有货平台鉴定中",
Arrays.asList(ButtonShow.SHOW_DETAIL)),
WAITING_RECEIVE(4,
"待收货",
"待收货",
Arrays.asList(ButtonShow.SHOW_EXPRESS, ButtonShow.CONFIRM_DELIVERY)),
DONE(5,
"已完成",
"交易成功",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
SELLER_CANCEL_BEFORE_PAY(10,
"买家付款前卖家取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
SELLER_CANCEL_AFTER_PAY(11,
"买家付款后卖家取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
SEND_OUT_TIMEOUT(12,
"超时未发货取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
CHECKING_FAKE(13,
"鉴定不通过取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
BUYER_CANCEL_BEFORE_PAY(14,
"支付前取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
BUYER_CANCEL_TIMEOUT(15,
"超时未支付取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
CUSTOMER_SERVICE(17,
"客服取消",
"交易失败",
Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER))
;
int code;
String desc;
OrderStatus(int code, String desc) {
String listStatusStr;
List<ButtonShow> buttonList;
/**
*
* @param code db中code
* @param desc db中code的含义
* @param listStatusStr 订单列表中状态显示
* @param buttonList 订单列表显示的按钮
*/
OrderStatus(int code, String desc, String listStatusStr, List<ButtonShow> buttonList) {
this.code = code;
this.desc = desc;
this.listStatusStr = listStatusStr;
this.buttonList = buttonList;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
public List<ButtonShow> getButtonList() {
return buttonList;
}
public String getListStatusStr() {
return listStatusStr;
}
public static OrderStatus getOrderStatus(int code){
for(OrderStatus v : values()){
if(v.code == code){
return v;
}
}
return null;
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.controller;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.request.OrderListRequest;
import com.yohoufo.order.response.OrderInfoListRsp;
import com.yohoufo.order.service.IBuyerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -34,11 +35,14 @@ public class BuyerOrderController {
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "limit", required = false, defaultValue = "10") int limit) {
OrderListRequest orderListRequest = new OrderListRequest();
orderListRequest.setUid(uid);
orderListRequest.setType(type);
orderListRequest.setPage(page);
orderListRequest.setLimit(limit);
return null;
OrderListRequest orderListRequest = OrderListRequest.builder()
.uid(uid)
.type(type)
.page(page)
.limit(limit)
.build();
OrderInfoListRsp orderInfoListRsp = buyerOrderService.getOrderList(orderListRequest);
return new ApiResponse.ApiResponseBuilder().code(200).data(orderInfoListRsp).message("订单列表").build();
}
}
... ...
package com.yohoufo.order.response;
import com.yohoufo.order.common.ButtonShow;
import lombok.Data;
import java.util.List;
@Data
public class OrderInfo {
... ... @@ -32,4 +35,17 @@ public class OrderInfo {
*
*/
int leftTime;
int status;
/**
* 列表中状态显示
*/
String statuStr;
/**
* 按钮显示
*/
List<ButtonShow> buttons;
}
... ...
package com.yohoufo.order.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderInfoListRsp {
List<OrderInfo> data;
// 页码
private int currPage;
// 每页记录数
private int limit;
// 总记录数
private int total;
// 当前页记录数
private int currTotal;
// 页数
private int pageSize;
}
... ...
package com.yohoufo.order.service;
import com.yohoufo.order.request.OrderListRequest;
import com.yohoufo.order.response.OrderInfoListRsp;
public interface IBuyerOrderService {
/**
* 订单列表
* @param request
* @return
*/
public OrderInfoListRsp getOrderList(OrderListRequest request);
}
... ...
package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
... ... @@ -10,8 +12,10 @@ 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.common.OrderListType;
import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.request.OrderListRequest;
import com.yohoufo.order.response.OrderInfo;
import com.yohoufo.order.response.OrderInfoListRsp;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.SkupStatus;
... ... @@ -52,29 +56,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
SellerOrderGoodsMapper sellerOrderGoodsMapper;
public void getOrderList(OrderListRequest request){
/**
* 订单列表
* @param request
* @return
*/
public OrderInfoListRsp getOrderList(OrderListRequest request){
if (request.getUid() < 0){
logger.warn("getOrderList uid is {}", request.getUid());
throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
}
// check and init请求参数
List<Integer> statusQuery = initOrderListRequest(request);
OrderListType orderListType = OrderListType.getOrderListType(request.getType());
if (orderListType == null){
logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
request.setPage(request.getPage() > 0 ? request.getPage() : 1);
request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), orderListType.getStatus());
int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), statusQuery);
int limit = request.getLimit();
int offset = (request.getPage() - 1) * limit;
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), orderListType.getStatus(),offset, limit);
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), statusQuery,offset, limit);
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
... ... @@ -82,41 +79,101 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList);
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity()));
List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
// seller_order_goods ===> 商品信息
List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skups);
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
List<OrderInfo> data = Lists.newArrayList();
buyerOrderList.stream().forEach(buyerOrder -> {
OrderInfo orderInfo = new OrderInfo();
orderInfo.setOrderCode(buyerOrder.getOrderCode());
orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
OrderInfo orderInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder);
if (orderInfo == null) return;
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
if (buyerOrderGoods == null){
return;
}
orderInfo.setSkup(buyerOrderGoods.getSkup());
data.add(orderInfo);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
orderInfo.setProductName(sellerOrderGoods.getProductName());
orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
orderInfo.setColorName(sellerOrderGoods.getColorName());
orderInfo.setSizeName(sellerOrderGoods.getSizeName());
// 订单状态显示
});
// 按钮显示
OrderInfoListRsp orderInfoListRsp = OrderInfoListRsp.builder()
.data(data)
.currPage(request.getPage())
.limit(limit)
.total(total)
.currTotal(data.size())
.pageSize((total % limit == 0) ? (total / limit) : (total / limit + 1)).build();
return orderInfoListRsp;
}
/**
* 获取返回结果
* @param buyerOrderGoodsMap
* @param sellerOrderGoodsMap
* @param buyerOrder
* @return
*/
private OrderInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
BuyerOrder buyerOrder) {
/**
* 1.查询 buyer_order
* 2.查询 buyer_order_goods ==> skup
* 3.查询 seller_order_goods
*/
OrderInfo orderInfo = new OrderInfo();
orderInfo.setOrderCode(buyerOrder.getOrderCode());
orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
// 订单中状态显示
orderInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
OrderStatus orderStatus = OrderStatus.getOrderStatus(orderInfo.getStatus());
orderInfo.setStatuStr(orderStatus == null ? "" : orderStatus.getListStatusStr());
// 按钮显示
orderInfo.setButtons(orderStatus == null ? Lists.newArrayList() : orderStatus.getButtonList());
// 当订单状态是待付款, 显示leftTime
if (orderInfo.getStatus() == OrderStatus.WAITING_PAY.getCode()){
orderInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
}
});
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
if (buyerOrderGoods == null){
return null;
}
orderInfo.setSkup(buyerOrderGoods.getSkup());
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
if (sellerOrderGoods == null){
return null;
}
orderInfo.setProductName(sellerOrderGoods.getProductName());
orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
orderInfo.setColorName(sellerOrderGoods.getColorName());
orderInfo.setSizeName(sellerOrderGoods.getSizeName());
return orderInfo;
}
/**
* 根据type获取 指定的状态
* @param request
* @return
*/
private List<Integer> initOrderListRequest(OrderListRequest request) {
if (request.getUid() < 0){
logger.warn("getOrderList uid is {}", request.getUid());
throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
}
OrderListType orderListType = OrderListType.getOrderListType(request.getType());
if (orderListType == null){
logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
request.setPage(request.getPage() > 0 ? request.getPage() : 1);
request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
return orderListType.getStatusQuery();
}
}
... ...