Authored by chenchao

rebuild 4 opimized

... ... @@ -162,7 +162,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
int num = pcn.getNum();
BigDecimal salePrice = pcn.getPrdPrice();
String tips = null;
PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, true);
PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, true);
SkupType skupType = SkupType.getSkupType(req.getSkupType());
try {
sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
... ... @@ -912,14 +912,59 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
return confirmDesc;
}
private SellerOrderGoods rebuildNESReq(SellerOrderComputeReq req){
int uid = req.getUid();
if (uid <=0){
log.warn("in rebuildNESReq uid illegal, req {}", req);
throw new UfoServiceException(400, "参数uid非法");
}
int skup = req.getSkup();
if (skup<=0){
log.warn("in rebuildNESReq find illegal skup code, req {}", req);
throw new UfoServiceException(400, "参数skup非法");
}
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
if (Objects.isNull(psog)){
log.warn("in rebuildNESReq can not find skup in sys, req {}", req);
throw new UfoServiceException(400, "商品不存在");
}
Integer puid = psog.getUid();
if (!puid.equals(uid)){
log.warn("in rebuildNESReq can not find one hacker , req {} sys-uid {}", req, puid);
throw new UfoServiceException(400, "你是猴子么");
}
int storageId = psog.getId();
req.setNum(1);
req.setStorageId(storageId);
return psog;
}
/**
* compute Change Price4 NES(Not Entry Seller)
* @param req
* @return
*/
public SoldPrdComputeBo computeChangePrice4NES(SellerOrderComputeReq req){
return null;
log.info("in computeChangePrice4NES, req {}", req);
rebuildNESReq(req);
PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);
int uid = pcn.getUid();
Integer storageId = pcn.getStorageId();
int num = pcn.getNum();
BigDecimal salePrice = pcn.getPrdPrice();
String tips = null;
PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, true);
SkupType skupType = SkupType.getSkupType(req.getSkupType());
try {
sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
tips = ex.getErrorMessage();
}
boolean isSuper = sellerService.isSuperEntrySeller(uid);
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper, skupType);
spc.setTips(tips);
return spc;
}
/**
... ...
package com.yohoufo.order.service.impl.processor;
import com.yohoufo.common.exception.UfoServiceException;
import org.slf4j.Logger;
import java.math.BigDecimal;
/**
* Created by chao.chen on 2019/3/20.
*/
public abstract class AbsChangePricePrepareProcessor {
protected abstract Logger getLogger();
public void checkChangeNecessary(Integer skup, BigDecimal oldPrice, BigDecimal newPrice){
if (oldPrice.compareTo(newPrice) == 0) {
getLogger().warn("skup:{} goodsPrice:{} and newPrice:{} must not be equals",
skup, oldPrice, newPrice);
throw new UfoServiceException(401, "前后价格没有变化");
}
}
}
... ...
... ... @@ -17,7 +17,6 @@ import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SkupDto;
import com.yohoufo.order.service.impl.SellerService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -34,7 +33,7 @@ import java.util.stream.Collectors;
/**
* Created by jiexiang.wu on 2018/12/19.
*/
public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseChangeReq> {
public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseChangeReq> extends AbsChangePricePrepareProcessor{
protected final Logger logger = LoggerUtils.getSellerOrderLogger();
... ... @@ -89,7 +88,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
String tips = null;
PrdPrice prdPrice;
prdPrice = sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, req.isShowPriceError());
prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, req.isShowPriceError());
SkupType skupType = SkupType.getSkupType(req.getSkupType());
try {
sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
... ... @@ -177,4 +176,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
return sellerOrderGoodList.parallelStream().collect(Collectors.toMap(SellerOrderGoods::getId,
(sog)-> SkupDto.builder().skup(sog.getId()).sellerOrderGoods(sog).batchNo(sog.getBatchNo()).build()));
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.model.dto.SkupDto;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
... ... @@ -19,6 +20,10 @@ import java.util.*;
*/
@Service
public class AdjustPricePrepareProcessor extends AbstractChangePricePrepareProcessor<SellerBatchChangeReq> {
@Override
protected Logger getLogger() {
return logger;
}
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
... ... @@ -66,12 +71,7 @@ public class AdjustPricePrepareProcessor extends AbstractChangePricePrepareProce
throw new UfoServiceException(401, "当前价格不对");
}
if (sellerOrderGoods.getGoodsPrice().compareTo(newPrice) == 0) {
logger.warn("skup:{} goodsPrice:{} and newPrice:{} must not be equals",
skup, sellerOrderGoods.getGoodsPrice(), newPrice);
throw new UfoServiceException(401, "前后价格没有变化");
}
checkChangeNecessary(skup, sellerOrderGoods.getGoodsPrice(), newPrice);
map.put(skup, skupDto);
}
return map;
... ...
... ... @@ -10,6 +10,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SkupDto;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
... ... @@ -57,6 +58,9 @@ public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProce
return sellerOrderGoodsMapper.selectByBatchNo(condition, Arrays.asList(SkupStatus.CAN_SELL.getCode(), SkupStatus.SELL_OUT.getCode()));
}
@Override
protected Map<Integer, SkupDto> checkNeedProcessSkups(List<Integer> expectedSkups,
BigDecimal oldPrice,
... ... @@ -76,16 +80,9 @@ public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProce
SellerOrderGoods sellerOrderGoods = skupOfSalingMap.get(skup).getSellerOrderGoods();
//校验价格
if (sellerOrderGoods.getGoodsPrice().compareTo(newPrice) == 0) {
logger.warn("skup:{} goodsPrice:{} and newPrice:{} must not be equals",
skup, sellerOrderGoods.getGoodsPrice(), newPrice);
throw new UfoServiceException(401, "前后价格没有变化");
}
checkChangeNecessary(skup, sellerOrderGoods.getGoodsPrice(), newPrice);
map.put(skup, skupOfSalingMap.get(skup));
}
return map;
}
... ... @@ -106,4 +103,9 @@ public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProce
}
return batchNo;
}
@Override
protected Logger getLogger() {
return logger;
}
}
... ...
... ... @@ -135,7 +135,7 @@ public class SellerOrderPrepareProcessor {
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
PrdPrice prdPrice = checkPrice(storageId, salePrice, true);
PrdPrice prdPrice = checkPriceRange(storageId, salePrice, true);
try {
checkSuggestPrice(prdPrice, salePrice, skupType);
... ... @@ -192,9 +192,16 @@ public class SellerOrderPrepareProcessor {
public static final int TIPS_ERROR_CODE = 505;
public PrdPrice checkPrice(int storageId, BigDecimal prdPrice, boolean isShowError) {
/**
* 判定商品的价格上下限,skc维度,由平台控制
* @param storageId
* @param prdPrice
* @param isShowError
* @return
*/
public PrdPrice checkPriceRange(int storageId, BigDecimal prdPrice, boolean isShowError) {
PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in checkPrice, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
log.info("in checkPriceRange, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
BigDecimal minPrice = prdPriceRange.getMinPrice();
BigDecimal maxPrice = prdPriceRange.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
... ...