Authored by chenchao

optimized

package com.yohoufo.order.model.dto;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import java.math.BigDecimal;
/**
* Created by chao.chen on 2019/4/12.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SingleChangePricePrepareDTO {
private SellerOrderGoods psog;
private SellerOrder sellerOrder;
private PrdPrice prdPrice;
private BigDecimal salePrice;
private SellerOrderComputeResult computeResult;
private SkupType skupType;
private String priceOverFlowTips;
}
... ...
package com.yohoufo.order.service.seller.processor;
package com.yohoufo.order.service.seller.changePrice;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
... ... @@ -17,12 +17,16 @@ 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.Payment;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SingleChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SkupDto;
import com.yohoufo.order.model.request.PrdQueryReq;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.service.seller.processor.ChangePriceCommonPrepareProcessor;
import com.yohoufo.order.service.seller.processor.PriceComputePrepareProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -38,7 +42,8 @@ import java.util.Objects;
import java.util.stream.Collectors;
/**
* NES -> not entry seller
* NES -> not entry seller paid
* 非入驻时支付的商品
* Created by chao.chen on 2019/3/21.
*/
@Service
... ... @@ -79,7 +84,7 @@ public class NESChangePricePrepareProcessor {
}
}
public ChangePricePrepareDTO checkAndAcquire(NESChangePriceReq req){
public SingleChangePricePrepareDTO checkAndAcquire(NESChangePriceReq req){
int uid = req.getUid();
if (uid <= 0){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
... ... @@ -96,12 +101,18 @@ public class NESChangePricePrepareProcessor {
throw new UfoServiceException(400, "商品不存在");
}
Integer puid = psog.getUid();
if (!puid.equals(uid)){
logger.warn("in ChangePrice can not find one hacker , req {} sys-uid {}", req, puid);
throw new UfoServiceException(400, "你是猴子么");
}
//check payment type
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
if (Payment.WALLET.getCode() == sellerOrder.getPayment()){
logger.warn("in ChangePrice seller order paid by wallet, req {}", req);
throw new UfoServiceException(400, "请移步库存管理中变价");
}
//check whether exists waiting pay order of skup
SkupDto skupOfUnChange = checkExistWaitingBuyerPay(psog);
//检查是否有买家下单
... ... @@ -124,27 +135,15 @@ public class NESChangePricePrepareProcessor {
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice, pcc);
//check income
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
//calculate different of earnest Money
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(psog.getId());
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal diffEarnestMoney = BigDecimalHelper.calDiff(sourceEM,targetEM);
//build one skup Map
Map<Integer, SkupDto> skupMap = Maps.newHashMapWithExpectedSize(1);
SkupDto skupDto = SkupDto.builder().sellerOrder(sellerOrder).sellerOrderGoods(psog).build();
skupMap.put(skup, skupDto);
return ChangePricePrepareDTO.builder()
.baseSellerOrderGoods(psog)
.skupMap(skupMap)
return SingleChangePricePrepareDTO.builder()
.sellerOrder(sellerOrder)
.psog(psog)
.prdPrice(prdPrice)
.salePrice(salePrice)
.diffEarnestMoney(diffEarnestMoney)
.computeResult(computeResult)
.preEarnestMoney(sourceEM)
.preSalePrice(preSalePrice)
.tips(tips)
.skupType(skupType)
.priceOverFlowTips(tips)
.build();
}
... ...
package com.yohoufo.order.service.seller.processor;
package com.yohoufo.order.service.seller.changePrice;
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.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.model.NESCPOrderContext;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SkupDto;
import com.yohoufo.order.model.request.PrdQueryReq;
import com.yohoufo.order.model.dto.SingleChangePricePrepareDTO;
import com.yohoufo.order.service.impl.SellerAddressService;
import com.yohoufo.order.service.impl.SkupService;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.service.seller.PublishProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -34,6 +25,7 @@ import java.math.BigDecimal;
import java.util.Objects;
/**
* 单个非钱包支付(非入驻时上架)skup变价
* Created by chao.chen on 2019/3/22.
*/
@Service
... ... @@ -41,17 +33,6 @@ public class NESChangePricePublishProcessor
implements PublishProcessor<NESChangePriceReq, SellerOrderContext> {
final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
PriceComputePrepareProcessor priceComputePrepareProcessor;
@Autowired
OrderComputeProvider orderComputeProvider;
@Autowired
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
@Autowired
private SellerAddressService sellerAddressService;
... ... @@ -60,10 +41,8 @@ public class NESChangePricePublishProcessor
private SkupService skupService;
@Autowired
SellerOrderMapper sellerOrderMapper;
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
@Autowired
private ChangePriceCommonPrepareProcessor changePriceCommonPrepareProcessor;
@Override
public NESCPOrderContext buildPublishCtx(NESChangePriceReq im) {
... ... @@ -71,58 +50,26 @@ public class NESChangePricePublishProcessor
}
private NESCPOrderContext buildSellerOrderContext(NESChangePriceReq req) {
int uid = req.getUid();
if (uid <= 0){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
throw new UfoServiceException(400, "参数[uid]错误");
}
int skup = req.getSkup();
if (skup<=0){
logger.warn("in ChangePrice find illegal skup code, req {}", req);
throw new UfoServiceException(400, "参数skup非法");
}
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
if (Objects.isNull(psog)){
logger.warn("in ChangePrice can not find skup in sys, req {}", req);
throw new UfoServiceException(400, "商品不存在");
}
//check payment type
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
if (Payment.WALLET.getCode() == sellerOrder.getPayment()){
logger.warn("in ChangePrice seller order paid by wallet, req {}", req);
throw new UfoServiceException(400, "请移步库存管理中变价");
}
SingleChangePricePrepareDTO scppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
SkupType skupType = scppDto.getSkupType();
Integer puid = psog.getUid();
if (!puid.equals(uid)){
logger.warn("in ChangePrice can not find one hacker , req {} sys-uid {}", req, puid);
throw new UfoServiceException(400, "你是猴子么");
}
//check whether exists waiting pay order of skup
SkupDto skupOfUnChange = nesChangePricePrepareProcessor.checkExistWaitingBuyerPay(psog);
//检查是否有买家下单
nesChangePricePrepareProcessor.checkGoodsStatus(psog);
SkupType skupType = SkupType.getSkupType(psog.getAttributes());
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice(), skupType);
BigDecimal preSalePrice = psog.getGoodsPrice();
//check old price vs new price
changePriceCommonPrepareProcessor.checkChangeNecessary(skup, preSalePrice, salePrice);
PrdPrice prdPrice;
SellerOrderGoods psog = scppDto.getPsog();
int storageId = psog.getStorageId();
PrdQueryReq pqr = PrdQueryReq.builder()
.uid(uid).prdPrice(salePrice).storageId(storageId).build();
prdPrice = priceComputePrepareProcessor.checkPriceRange(pqr, true);
String tips = priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
// compute every fee from price
SellerOrderComputeResult pcc = OrderAssist.buildPersonalComputeConfig(prdPrice);
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice, pcc);
//check income
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
SellerOrder sellerOrder = scppDto.getSellerOrder();
BigDecimal salePrice = scppDto.getSalePrice();
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, salePrice, skupType);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
logger.warn("in buildSellerOrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
goodsInfo.setTargetSkupStatus(SkupStatus.CAN_NOT_SELL);
SellerOrderComputeResult computeResult = scppDto.getComputeResult();
String tips = scppDto.getPriceOverFlowTips();
//the address of send back 2 seller
AddressInfo hiddenBackAddress = sellerAddressService.getHiddenAddressInfo(uid, skup);
... ... @@ -140,15 +87,7 @@ public class NESChangePricePublishProcessor
context.setBackHiddenAddress(hiddenBackAddress);
//
context.setSkupType(skupType);
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, salePrice, skupType);
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
logger.warn("in buildSellerOrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
goodsInfo.setTargetSkupStatus(SkupStatus.CAN_NOT_SELL);
context.setSoldProduct(goodsInfo);
logger.info("in build not entry Seller Order Context , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
... ...
... ... @@ -16,13 +16,11 @@ import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.NESCPOrderContext;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SingleChangePricePrepareDTO;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.impl.SellerOrderCancelService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.ResourcesProxyService;
import com.yohoufo.order.service.seller.processor.NESChangePricePrepareProcessor;
import com.yohoufo.order.service.seller.processor.NESChangePricePublishProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -100,7 +98,7 @@ public class NotEntrySellerChangePriceService{
*/
public SoldPrdComputeBo computeChangePrice(NESChangePriceReq req){
logger.info("in NotEntrySellerChangePriceService.computeChangePrice, req {}", req);
ChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
SingleChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
Map<String,String> tipsConfig = resourcesProxyService.getServiceTipsConfig();
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(cppDto.getComputeResult(), tipsConfig);
... ...