Authored by sailing-PC\sailing

optimized

... ... @@ -20,4 +20,11 @@ public interface SellerOrderGoodsMapper {
int updateByPrimaryKeySelective(SellerOrderGoods record);
int updateByPrimaryKey(SellerOrderGoods record);
int selectCntByUidStatusList(@Param("uid")int uid, @Param("statusList") List<Integer> statusList);
List<SellerOrderGoods> selectByUidStatusList(@Param("uid")int uid,
@Param("statusList") List<Integer> statusList,
@Param("offset")Integer offset,
@Param("limit")Integer limit);
}
\ No newline at end of file
... ...
... ... @@ -3,6 +3,9 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.SellerOrder;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface SellerOrderMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -21,4 +24,8 @@ public interface SellerOrderMapper {
int updateByPrimaryKey(SellerOrder record);
int updateByOrderCode(SellerOrder record);
List<SellerOrder> selectBySkups(@Param("skupList") Collection<Integer> skups);
}
\ No newline at end of file
... ...
... ... @@ -41,6 +41,24 @@
</if>
</select>
<sql id="sql_where_4_select_UidStatusList">
uid = #{uid,jdbcType=INTEGER}
<if test="statusList != null">
and status in
<foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
#{status, jdbcType=TINYINT}
</foreach>
</if>
</sql>
<select id="selectCntByUidStatusList" resultType="java.lang.Integer">
select count(*) from seller_order_goods where <include refid="sql_where_4_select_UidStatusList"/>
</select>
<select id="selectByUidStatusList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from seller_order_goods
where <include refid="sql_where_4_select_UidStatusList"/>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from seller_order_goods
... ...
... ... @@ -45,6 +45,17 @@
</select>
<select id="selectBySkups" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_order
where skup IN
<foreach collection="skupList" item="skup" open="(" separator="," close=")">
#{skup,jdbcType=INTEGER}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from seller_order
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -3,7 +3,9 @@ package com.yohoufo.order.common;
import com.yohoufo.order.constants.OrderDetailDesc;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum SkupStatus {
/**
... ... @@ -89,8 +91,17 @@ public enum SkupStatus {
}
static Map<Integer, SkupStatus> cache = new HashMap<>(16);
static {
for (SkupStatus v : values()){
cache.put(v.code, v);
}
}
public static SkupStatus getSkupStatus(int code){
return cache.get(code);
}
public int getCode() {
return code;
... ...
... ... @@ -48,7 +48,7 @@ public abstract class AbsOrderListService implements IOrderListService{
// check and init请求参数
List<Integer> statusQuery = initOrderListRequest(request);
TabType tabType = TabType.getTabType(request.getTabType());
TabType actor = request.getActor();
int total = getTotal(request.getUid(), statusQuery);
int limit = request.getLimit();
int currentTotal = 0;
... ... @@ -81,7 +81,7 @@ public abstract class AbsOrderListService implements IOrderListService{
List<OrderListInfo> data = Lists.newArrayList();
buyerOrderList.stream().forEach(buyerOrder -> {
OrderListInfo orderListInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder, tabType);
OrderListInfo orderListInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder, actor);
if (orderListInfo == null) return;
data.add(orderListInfo);
});
... ...
package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.sun.corba.se.spi.ior.IOR;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
... ... @@ -12,6 +13,7 @@ import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.PriceFormater;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
... ... @@ -19,10 +21,9 @@ import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.OrderListType;
import com.yohoufo.order.common.SellerOrderListType;
import com.yohoufo.order.common.*;
import com.yohoufo.order.model.AddressInfo;
import com.yohoufo.order.model.GoodsInfo;
import com.yohoufo.order.model.SellerOrderContext;
... ... @@ -47,7 +48,9 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/13.
... ... @@ -74,6 +77,15 @@ public class SellerOrderService extends AbsOrderListService implements IOrderLis
@Autowired
private UserProxyService userProxyService;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
... ... @@ -311,28 +323,86 @@ public class SellerOrderService extends AbsOrderListService implements IOrderLis
return PriceFormater.addCnCurrencySymbol(BigDecimalHelper.formatNumber(fee, BigDecimalHelper.FORMAT_TWOBITAFTERPOINT));
}
@Autowired
BuyerOrderMapper buyerOrderMapper;
@Autowired
BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Override
public OrderListInfoRsp getOrderList(OrderListRequest request){
int type;
if ((type=request.getType()) == SellerOrderListType.IN_SALE.getType()){
//todo
log.info("in seller getOrderList");
return null;
List<Integer> statusList = initOrderListRequest(request);
int total = sellerOrderGoodsMapper.selectCntByUidStatusList(request.getUid(), statusList);
int limit = request.getLimit();
int currentTotal = 0;
OrderListInfoRsp.OrderListInfoRspBuilder respBuilder = OrderListInfoRsp.builder()
.currPage(request.getPage())
.limit(limit)
.total(total)
.currTotal(currentTotal)
.pageSize((total % limit == 0) ? (total / limit) : (total / limit + 1));
if (total == 0){
return respBuilder.build();
}
int offset = (request.getPage() - 1) * limit;
List<SellerOrderGoods> sogList = sellerOrderGoodsMapper.selectByUidStatusList(request.getUid(),
statusList, offset, limit);
Map<Integer, SellerOrderGoods> skupSellerOrderGoodsMap = sogList.parallelStream()
.collect(Collectors.toMap(SellerOrderGoods::getId, (SellerOrderGoods sog)-> sog));
List<Integer> skupList = sogList.parallelStream().map(SellerOrderGoods::getId).collect(Collectors.toList());
List<SellerOrder> sellerOrders = sellerOrderMapper.selectBySkups(skupList);
List<OrderListInfo> data = sellerOrders.parallelStream()
.map(sellerOrder -> buildOrderListInfo(skupSellerOrderGoodsMap.get(sellerOrder.getSkup()), sellerOrder))
.collect(Collectors.toList());
OrderListInfoRsp orderListInfoRsp = respBuilder.data(data).currTotal(data.size()).build();
return orderListInfoRsp;
}else{
return super.getOrderList(request);
}
}
OrderListInfo buildOrderListInfo(SellerOrderGoods sellerOrderGoods,
SellerOrder buyerOrder) {
OrderListInfo orderListInfo = new OrderListInfo();
orderListInfo.setUid(buyerOrder.getUid());
orderListInfo.setOrderCode(buyerOrder.getOrderCode());
orderListInfo.setRealPrice(sellerOrderGoods.getGoodsPrice().toPlainString());
// 订单中状态显示
orderListInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
SkupStatus orderStatus = SkupStatus.getSkupStatus(orderListInfo.getStatus());
if (orderStatus == null){
log.warn("getOrderList orderStatus not exist, uid is {}, orderCode is {}, status is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode(), buyerOrder.getStatus());
return null;
}
orderListInfo.setStatuStr(orderStatus.getDetailShowDesc());
// 按钮显示
orderListInfo.setButtons(orderStatus.getListButtons());
// 当订单状态是待付款, 显示leftTime
if (orderListInfo.getStatus() == SellerOrderStatus.WAITING_PAY.getCode()){
orderListInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
}
orderListInfo.setSkup(sellerOrderGoods.getId());
//
com.yohoufo.order.response.GoodsInfo goodsInfo = new com.yohoufo.order.response.GoodsInfo();
goodsInfo.setColorName(sellerOrderGoods.getColorName());
goodsInfo.setProductName(sellerOrderGoods.getProductName());
goodsInfo.setGoodImg(sellerOrderGoods.getImageUrl());
goodsInfo.setSizeName(sellerOrderGoods.getSizeName());
goodsInfo.setGoodPrice(sellerOrderGoods.getGoodsPrice().toPlainString());
orderListInfo.setGoodsInfo(goodsInfo);
return orderListInfo;
}
@Override
protected List<Integer> initOrderListRequest(OrderListRequest request) {
if (request.getUid() < 0){
... ...