Authored by chenchao

compute by skup type

... ... @@ -231,7 +231,8 @@ public class SellerOrderController {
public ApiResponse batchChangePrice(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "price", required = true)String price,
@RequestParam(name = "batchNo", required = true)String batchNo,
@RequestParam(name = "skupList", required = true)String skupList
@RequestParam(name = "skupList", required = true)String skupList,
@RequestParam(name="skupType", defaultValue = DEFAULT_SKUP_TYPE, required = false) Integer skupType
) throws GatewayException {
... ... @@ -241,6 +242,7 @@ public class SellerOrderController {
req.setShowPriceError(true);
req.setBatchNo(batchNo);
req.setSkupList(skupList);
req.setSkupType(skupType);
logger.info("in ufo.sellerOrder.batchChangePrice, req {}", req);
BatchChangePriceResp result = sellerOrderService.batchChangePrice(req);
... ... @@ -269,7 +271,8 @@ public class SellerOrderController {
@RequestParam(name="price", required = true)String price,
@RequestParam(name = "batchNo", required = false)String batchNo,
@RequestParam(name = "skupList", required = false)String skupList,
@RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException {
@RequestParam(name="num", defaultValue = "1", required = false)int num,
@RequestParam(name="skupType", defaultValue = DEFAULT_SKUP_TYPE, required = false) Integer skupType) throws GatewayException {
BatchChangePriceReq req = new BatchChangePriceReq();
req.setStorageId(storage_id);
... ... @@ -278,6 +281,7 @@ public class SellerOrderController {
req.setBatchNo(batchNo);
req.setSkupList(skupList);
req.setShowPriceError(false);
req.setSkupType(skupType);
logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req);
SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
... ... @@ -303,7 +307,9 @@ public class SellerOrderController {
@RequestParam(name = "old_price") BigDecimal old_price,
@RequestParam(name = "new_price") String new_price,
@RequestParam(name = "product_id") int product_id,
@RequestParam(name = "num") int num) throws GatewayException {
@RequestParam(name = "num") int num,
@RequestParam(name="skupType", defaultValue = DEFAULT_SKUP_TYPE, required = false) Integer skupType
) throws GatewayException {
SellerBatchChangeReq req = new SellerBatchChangeReq();
req.setStorageId(storage_id);
req.setUid(uid);
... ... @@ -312,6 +318,7 @@ public class SellerOrderController {
req.setProductId(product_id);
req.setNum(num);
req.setShowPriceError(false);
req.setSkupType(skupType);
logger.info("in ufo.sellerOrder.computeAdjustPrice, req {}", req);
try {
SoldPrdComputeBo computeBo = sellerOrderService.computeAdjustPrice(req);
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.service.handler;
import com.yohoufo.order.model.dto.EarnestMoney;
import com.yohoufo.order.model.dto.ServiceFeeRate;
import com.yohoufo.order.service.seller.AbsSellerOrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
... ... @@ -11,7 +12,7 @@ import java.math.BigDecimal;
* Created by chenchao on 2018/9/14.
*/
@Component
public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler{
public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler {
/**
* 相对独立 不涉及到计算其他费用
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.*;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.*;
import com.yohoufo.common.alarm.EventBusPublisher;
... ... @@ -47,6 +48,8 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -77,7 +80,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private SellerOrderComputeHandler computeHandler;
private OrderComputeProvider orderComputeProvider;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
... ... @@ -167,7 +170,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
tips = ex.getErrorMessage();
}
boolean isSuper = sellerService.isSuperEntrySeller(uid);
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper);
SkupType skupType = SkupType.getSkupType(req.getSkupType());
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper, skupType);
spc.setTips(tips);
return spc;
}
... ... @@ -508,7 +512,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
}
private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, BigDecimal prdPrice, boolean isSuper){
private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num,
BigDecimal prdPrice, boolean isSuper,
SkupType skupType){
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
/**
* 验证是否是入驻商家
... ...
package com.yohoufo.order.service.impl.processor;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SellerBaseChangeReq;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
... ... @@ -14,9 +15,10 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
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.handler.SellerOrderComputeHandler;
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;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -48,7 +50,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
@Autowired
private SellerOrderComputeHandler computeHandler;
private OrderComputeProvider orderComputeProvider;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
... ... @@ -68,20 +70,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
throw new UfoServiceException(400, "您不是入驻商家");
}
// String skupList = req.getSkupList();
// if (StringUtils.isBlank(skupList)){
// logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
// throw new UfoServiceException(400, "参数[skupList]为空");
// }
//考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉;
//不做过滤导致后面的数量 扣费检查都可能不对
// List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList);
// List<Integer> needChangePriceSkupList = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
//check batch no
// Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req);
//检查是否有买家下单,返回的是可售 待买家付款的skup
Map<Integer, SkupDto> skupOfSalingMap = checkExistWaitingBuyerPay(req);
... ... @@ -93,9 +81,6 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
int sampleSkup = sampleSkupDto.getSkup();
SellerOrderGoods sampleSog = sampleSkupDto.getSellerOrderGoods();
BigDecimal preSalePrice = sampleSog.getGoodsPrice();
// if (preSalePrice.compareTo(salePrice) == 0){
// throw new UfoServiceException(401, "前后价格没有变化");
// }
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup);
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
... ... @@ -110,6 +95,8 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
tips = ex.getErrorMessage();
}
// compute every fee from price
SkupType skupType = SkupType.getSkupType(req.getSkupType());
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice);
int num = skupMap.size();
//作为入驻商户 检查钱包
... ...
... ... @@ -2,11 +2,13 @@ package com.yohoufo.order.service.impl.processor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SellerWalletType;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
... ... @@ -14,15 +16,14 @@ import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohobuy.ufo.model.GoodsSize;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -45,7 +46,7 @@ public class SellerOrderPrepareProcessor {
private ProductProxyService productProxyService;
@Autowired
private SellerOrderComputeHandler computeHandler;
private OrderComputeProvider orderComputeProvider;
@Autowired
private SellerWalletMapper sellerWalletMapper;
... ... @@ -137,16 +138,17 @@ public class SellerOrderPrepareProcessor {
}catch (UfoServiceException ex){
context.setPriceOverFlowTips( ex.getErrorMessage());
}
//
SkupType skupType = SkupType.getSkupType(req.getSkupType());
context.setSkupType(skupType);
// compute every fee from price
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice());
checkIncome(storageId, computeResult.getIncome());
log.info("in buildSellerOrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
//
SkupType skupType = SkupType.getSkupType(req.getSkupType());
context.setSkupType(skupType);
return context;
}
... ... @@ -303,6 +305,8 @@ public class SellerOrderPrepareProcessor {
goodsInfo.setStorageNum(storageNum);
// compute every fee from price
SkupType skupType = SkupType.IN_STOCK;
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice());
log.info("in buildImportPrdCxt , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
... ...
... ... @@ -16,7 +16,7 @@ import java.math.BigDecimal;
/**
* Created by chao.chen on 2019/2/1.
*/
public abstract class AbsSellerOrderComputeHandler {
public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandler{
protected Logger logger = LoggerUtils.getSellerOrderLogger();
... ... @@ -34,7 +34,7 @@ public abstract class AbsSellerOrderComputeHandler {
@Value("${order.seller.packageFee:5}")
private Double packageFee ;
@Override
public SellerOrderComputeResult compute(BigDecimal prdPrice){
//保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200))
... ...
package com.yohoufo.order.service.seller;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import java.math.BigDecimal;
/**
* Created by chao.chen on 2019/2/1.
*/
public interface OrderComputeHandler {
SellerOrderComputeResult compute(BigDecimal prdPrice);
}
... ...
package com.yohoufo.order.service.seller;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by chao.chen on 2019/2/1.
*/
@Service
public class OrderComputeProvider implements ApplicationContextAware {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
private Map<String, OrderComputeHandler> cache;
public OrderComputeHandler findBySkupType(SkupType skupType){
OrderComputeHandler och = cache.get(skupType.orderComputeHandlerClzName());
logger.info("in findBySkupType skupType {} OrderComputeHandler {}", skupType, och);
return och;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, OrderComputeHandler> allOCHMap = applicationContext.getBeansOfType(OrderComputeHandler.class);
cache = allOCHMap;
//check
SkupType[] sta = SkupType.values();
List<SkupType> errorST = new ArrayList<>(sta.length);
for(SkupType st : sta){
if(null == findBySkupType(st)){
errorST.add(st);
logger.warn("init check SkupType.orderComputeHandlerClzName set error SkupType {}", st);
}
}
if (CollectionUtils.isNotEmpty(errorST)){
throw new Error("SkupType.orderComputeHandlerClzName incorrect");
}
}
}
... ...
... ... @@ -10,7 +10,7 @@ import java.math.BigDecimal;
* Created by chao.chen on 2019/2/1.
*/
@Component
public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandler {
public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler {
@Override
protected EarnestMoney calEarnestMoney(BigDecimal prdPrice) {
//TODO 根据配置(来自于数据库或缓存 zk ,某一种数据存储方式)
... ...