Authored by chenchao

add tips

... ... @@ -5,6 +5,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo;
import com.yohoufo.common.constant.ExpressInfoConstant;
... ... @@ -23,15 +24,19 @@ import com.yohoufo.order.model.response.GoodsInfo;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
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 org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
... ... @@ -74,12 +79,18 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
@Autowired
private UserProxyService userProxyService;
@Autowired
private ProductProxyService productProxyService;
@Autowired
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
private static List<SkupStatus> noNeedShowOrderCode = Arrays.asList(SkupStatus.CAN_NOT_SELL,SkupStatus.CAN_SELL,
SkupStatus.SELF_CANCEL_PAY, SkupStatus.TIMEOUT_CANCEL,
SkupStatus.SELLER_CANCEL_SELL, SkupStatus.YOHO_CANCEL_SELL);
private static final List<Long> SELLER_TYPES = Arrays.asList(OrderCodeType.SELLER_TYPE.getType(),
OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType());
private static final List<Long> SELLER_TYPES = Arrays.asList(OrderCodeType.SELLER_TYPE.getType());
@Override
public OrderDetailInfo getOrderDetail(OrderRequest orderRequest) {
int uid;
... ... @@ -277,6 +288,22 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
return orderCode;
}
private String buildOverPriceTips(int storageId, BigDecimal prdPrice){
final String defaultResult = "";
try{
ProductProxyService.PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
logger.info("in buildOverPriceTips, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(prdPriceRange.getSuggestMaxPrice(), prdPrice);
return isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;
}catch (Exception ex){
logger.warn("in buildOverPriceTips storageId {},prdPrice {}", storageId, prdPrice, ex);
return defaultResult;
}
}
private OrderDetailInfo buildOrderDetail(SellerOrder order, SkupStatus skupStatus,
SellerOrderGoods sellerOrderGoods, AddressInfo addressInfo,
SellerType sellerType
... ... @@ -289,8 +316,11 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
orderDetailInfo.setUserAddress(addressInfo);
//卖家
assembleSoldPrdCompute(orderDetailInfo, order.getUid(), sellerOrderGoods.getId());
String tips = buildOverPriceTips(sellerOrderGoods.getStorageId(), sellerOrderGoods.getGoodsPrice());
OrderDetailInfo.StatusDetail statusDetail = getStatusDetail(order, skupStatus);
if (StringUtils.isNotBlank(tips)){
statusDetail.setDetailDesc(tips);
}
orderDetailInfo.setStatusDetail(statusDetail);
GoodsInfo goodsInfo = getGoodsInfo(sellerOrderGoods);
orderDetailInfo.setGoodsInfo(goodsInfo);
... ... @@ -307,6 +337,7 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
orderDetailInfo.setIsPaid(getIsPaid(skupStatus));
orderDetailInfo.setSecendLevelCreateTime(order.getCreateTime());
orderDetailInfo.setCreateTime(DateUtil.formatDate(order.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
return orderDetailInfo;
}
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
... ... @@ -20,14 +21,17 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
... ... @@ -99,14 +103,15 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
sogList.stream().forEach(item -> {
item.setImageUrl(ImageUrlAssist.getAllProductPicUrl(item.getImageUrl(), "goodsimg", "center", "d2hpdGU="));
});
Map<Integer,String> overPriceTipsMap = buildOverPriceTipsMap(sogList);
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 ;
data = sellerOrders.parallelStream()
.map(sellerOrder -> buildOrderListInfo(skupSellerOrderGoodsMap.get(sellerOrder.getSkup()), sellerOrder, sellerType))
.map(sellerOrder -> buildOrderListInfo(skupSellerOrderGoodsMap.get(sellerOrder.getSkup()),
sellerOrder, sellerType, overPriceTipsMap))
.filter(oli -> Objects.nonNull(oli))
.collect(Collectors.toList());
... ... @@ -139,8 +144,43 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
}
}
@Autowired
private ProductProxyService productProxyService;
@Autowired
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
/**
* todo 需要商品提供批量接口,减少db net IO, 目前的工期太短,后期再优化
* @param sogList
* @return
*/
private Map<Integer,String> buildOverPriceTipsMap(List<SellerOrderGoods> sogList){
Map<Integer,String> map = new HashMap<>(sogList.size());
for(SellerOrderGoods sog : sogList) {
int storageId = sog.getStorageId();
if (map.containsKey(storageId)){
continue;
}
BigDecimal prdPrice = sog.getGoodsPrice();
final String defaultResult = "";
String value;
try {
ProductProxyService.PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in buildOverPriceTipsMap, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(prdPriceRange.getSuggestMaxPrice(), prdPrice);
value = isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;
} catch (Exception ex) {
log.warn("in buildOverPriceTipsMap storageId {},prdPrice {}", storageId, prdPrice, ex);
value = defaultResult;
}
map.put(storageId, value);
}
return map;
}
OrderListInfo buildOrderListInfo(SellerOrderGoods sellerOrderGoods,
SellerOrder sellerOrder, SellerType st) {
SellerOrder sellerOrder, SellerType st, Map<Integer,String> overPriceTipsMap) {
OrderListInfo orderListInfo = new OrderListInfo();
Long orderCode;
... ... @@ -157,7 +197,6 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
// 订单中状态显示
orderListInfo.setStatus(skupStatus.getCode());
orderListInfo.setStatuStr(skupStatus.getDesc());
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
//异常扯淡,兼容老数据,
final SellerType lst = (st == SellerType.ENTRY
&& OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType() == sellerOrder.getPayment()) ?
... ... @@ -186,6 +225,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
orderListInfo.setGoodsInfo(goodsInfo);
orderListInfo.setSecendLevelCreateTime(sellerOrder.getCreateTime());
orderListInfo.setCreateTime(DateUtil.formatDate(sellerOrder.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
orderListInfo.setTips(overPriceTipsMap.get(sellerOrderGoods.getStorageId()));
return orderListInfo;
}
... ...
... ... @@ -112,7 +112,8 @@ public class ChangePricePrepareProcessor {
return ChangePricePrepareDTO.builder().salePrice(salePrice).skupList(needChangePriceSkupList).build();
return ChangePricePrepareDTO.builder().salePrice(salePrice)
.skupList(needChangePriceSkupList).build();
}
private BigDecimal calDiffOfEM(BigDecimal sourceEM, BigDecimal targetEM){
... ...
... ... @@ -180,6 +180,10 @@ public class SellerOrderPrepareProcessor {
}
}
public boolean isOverSuggestMaxPrice(BigDecimal suggestMaxPrice, BigDecimal prdPrice){
return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0;
}
public void checkPrice(int storageId, BigDecimal prdPrice, boolean validateMaxPrice) throws GatewayException {
ProductProxyService.PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in checkPrice, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
... ... @@ -195,7 +199,7 @@ public class SellerOrderPrepareProcessor {
throw new GatewayException(501, "您的出价过高");
}
BigDecimal suggestMaxPrice = prdPriceRange.getSuggestMaxPrice();
if (Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0){
if (isOverSuggestMaxPrice(suggestMaxPrice, prdPrice)){
log.warn("in computePublishPrd,prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
throw new GatewayException(501, "您的出价已超出建议售价,此商品将不会给顾客展示!");
}
... ...
... ... @@ -4,6 +4,7 @@ import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.product.model.ProductInfo;
import com.yohoufo.product.request.StoragePriceBo;
... ... @@ -70,13 +71,13 @@ public class ProductProxyService {
private BigDecimal suggestMinPrice;
}
public PrdPrice getPrdPriceRange(int storageId) throws GatewayException {
public PrdPrice getPrdPriceRange(int storageId){
StorageDataResp storage = getStorageData(storageId);
Integer productId=null;
if (Objects.isNull(storage) || Objects.isNull(productId=storage.getProductId()) || productId == 0){
logger.warn("in getPrdPriceRange wrong, storageId {},productId {}",
storageId, productId);
throw new GatewayException(501, "查无商品");
throw new UfoServiceException(501, "查无商品");
}
ProductDetailResp resp = ufoServiceCaller.call("ufo.product.baseInfo", productId);
... ... @@ -90,7 +91,7 @@ public class ProductProxyService {
|| productInfo.getMaxPrice().doubleValue() == 0D){
logger.warn("in getPrdPriceRange wrong,storageId {}, productId {}, productInfo {}",
storageId, productId, productInfo);
throw new GatewayException(501, "无法比对商品价格限制");
throw new UfoServiceException(501, "无法比对商品价格限制");
}
PrdPrice prdPrice = new PrdPrice();
prdPrice.minPrice = leastPrice;
... ...