Authored by chenchao

add overflow price tips when compute sale price

package com.yohoufo.order.service.concurrent;
import java.util.concurrent.ForkJoinPool;
import com.yohoufo.order.service.proxy.InBoxThreadFactory;
import java.util.concurrent.*;
/**
* Created by chao.chen on 2018/11/20.
... ... @@ -8,14 +10,22 @@ import java.util.concurrent.ForkJoinPool;
public class ThreadPoolFactory {
static class GoodKids{
private volatile static ForkJoinPool forkJoinPool ;
private static ForkJoinPool forkJoinPool ;
private static ThreadPoolExecutor threadpool ;
static {
forkJoinPool = new ForkJoinPool(6);
threadpool = new ThreadPoolExecutor(4, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new InBoxThreadFactory("buyer-cancel-order"));
}
}
public static ForkJoinPool getForkJoinPool(){
return GoodKids.forkJoinPool;
}
public static ThreadPoolExecutor getBuyerCancelThreadPool(){
return GoodKids.threadpool;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.sun.jmx.snmp.tasks.ThreadService;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -11,7 +12,10 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.event.BeforeDepotReceiveEvent;
import com.yohoufo.order.event.BeforeSellerDeliverEvent;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.service.proxy.InBoxThreadFactory;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -20,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.util.concurrent.*;
/**
* Created by chao.chen on 2018/11/13.
... ... @@ -43,6 +48,12 @@ public class BuyerOrderCancelService {
@Autowired
private CouponProxyService couponProxyService;
@Autowired
private IPaymentService paymentService;
public void cancel(BeforeSellerDeliverEvent bsdEvent){
OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeSellerDeliverBCCN();
... ... @@ -63,9 +74,11 @@ public class BuyerOrderCancelService {
//TODO 整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
//(转账)瓜分指定赔偿款给卖家和平台
//(退费)扣除赔偿款,计算剩余的货款,退给买家
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask();
ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
}
}
... ... @@ -95,6 +108,13 @@ public class BuyerOrderCancelService {
}
}
class BuyerCancelAfterProcessTask implements Callable{
@Override
public Object call() throws Exception {
return null;
}
}
/**
* 退还优惠券
... ...
... ... @@ -14,6 +14,7 @@ import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.PageHelper;
... ... @@ -165,8 +166,18 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
throw new GatewayException(400, "非法数字");
}
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
return buildSoldPrdComputeBo(uid, num, prdPrice);
String tips = null;
try {
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
}catch (Exception ex){
if (ex instanceof UfoServiceException && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
tips = ((UfoServiceException) ex).getMessage();
}
}
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, prdPrice);
spc.setTips(tips);
return spc;
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SellerWalletType;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.SellerWalletMapper;
... ... @@ -184,24 +185,26 @@ public class SellerOrderPrepareProcessor {
return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0;
}
public void checkPrice(int storageId, BigDecimal prdPrice, boolean validateMaxPrice) throws GatewayException {
public static final int TIPS_ERROR_CODE = 505;
public void checkPrice(int storageId, BigDecimal prdPrice, boolean validateMaxPrice) {
ProductProxyService.PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in checkPrice, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
BigDecimal minPrice = prdPriceRange.getMinPrice();
BigDecimal maxPrice = prdPriceRange.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
throw new GatewayException(501, "您的出价过低");
throw new UfoServiceException(501, "您的出价过低");
}
if (validateMaxPrice && prdPrice.subtract(maxPrice).doubleValue() > 0D){
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
throw new GatewayException(501, "您的出价过高");
throw new UfoServiceException(501, "您的出价过高");
}
BigDecimal suggestMaxPrice = prdPriceRange.getSuggestMaxPrice();
if (isOverSuggestMaxPrice(suggestMaxPrice, prdPrice)){
log.warn("in computePublishPrd,prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
throw new GatewayException(501, "您的出价已超出建议售价,此商品将不会给顾客展示!");
throw new UfoServiceException(TIPS_ERROR_CODE, "您的出价已超出建议售价,此商品将不会给顾客展示!");
}
}
... ...
... ... @@ -23,6 +23,14 @@ public class InBoxThreadFactory implements ThreadFactory {
"-thread-";
}
public InBoxThreadFactory(String bizName) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = "pool-" + bizName + "-processor-" +
poolNumber.getAndIncrement() +
"-thread-";
}
@Override
public Thread newThread(Runnable r) {
... ...