Authored by wujiexiang

调价校验 重构

... ... @@ -62,7 +62,7 @@ public class BidAndSuggestPrice {
private void validateBidPriceConfig(BigDecimal prdPrice, BigDecimal minBidPrice) {
if (prdPrice.subtract(minBidPrice).doubleValue() < 0D) {
log.warn("BidPrice validate,prdPrice:{} < minBidPrice:{}", prdPrice, minBidPrice);
throw new UfoServiceException(501, "出价请大于等于" + minBidPrice.toPlainString());
throw new UfoServiceException(501, "出价请大于等于" + minBidPrice.intValue());
}
}
... ...
... ... @@ -71,7 +71,7 @@ public class BuyerBidPriceService {
BidOrderChangePriceContext context = buildBidOrderChangePriceContext(request);
//校验
validate(context, false);
context.validate(false);
//构建参数
BuyerBidPublishRequest req = BuyerBidPublishRequest.builder().uid(request.getUid()).storageId(context.sellerOrderGoods.getStorageId())
... ... @@ -87,7 +87,7 @@ public class BuyerBidPriceService {
int uid = request.getUid();
BidOrderChangePriceContext context = buildBidOrderChangePriceContext(request);
//校验
validate(context, true);
context.validate(true);
//构建参数
BuyerBidPublishRequest req = BuyerBidPublishRequest.builder().uid(uid)
.storageId(context.sellerOrderGoods.getStorageId())
... ... @@ -102,7 +102,7 @@ public class BuyerBidPriceService {
int uid = request.getUid();
BidOrderChangePriceContext context = buildBidOrderChangePriceContext(request);
//校验
validate(context, true);
context.validate(true);
int oldSkup = context.sellerOrderGoods.getId();
logger.info("[{}] will change price,orderCode:{},oldSkup:{}", uid, context.buyerOrder.getOrderCode(), oldSkup);
... ... @@ -191,55 +191,12 @@ public class BuyerBidPriceService {
request.getPrice(), bidOrderMetaBo.getDay());
}
private void validate(BidOrderChangePriceContext context,boolean validateBidPrice) {
if (validateBidPrice) {
validateSamePrice(context.buyerOrder, context.newPrice, context.sellerOrderGoods.getGoodsPrice());
}
validateBuyerOrderStatus(context.buyerOrder);
validateWaitingChangePriceRecord(context.buyerOrder);
}
/**
* 校验价格是否相同
*
* @param newPrice
* @param oldPrice
*/
private void validateSamePrice(BuyerOrder buyerOrder, BigDecimal newPrice, BigDecimal oldPrice) {
if (newPrice.compareTo(oldPrice) == 0) {
logger.warn("price is not change,orderCode:{},newPrice:{},oldPrice:{}", buyerOrder.getOrderCode());
throw new UfoServiceException(401, "价格未变化");
}
}
/**
* 只有求购中的订单才能调价
*/
private void validateBuyerOrderStatus(BuyerOrder buyerOrder) {
if (buyerOrder.getStatus().intValue() != OrderStatus.BIDING.getCode()) {
logger.warn("buyerOrder status is not biding, orderCode is {}", buyerOrder.getOrderCode());
throw new ServiceException(ServiceError.ORDER_NULL);
}
}
/**
* 校验变价记录表
*/
private void validateWaitingChangePriceRecord(BuyerOrder buyerOrder) {
List<BuyerChangePriceRecord> buyerChangePriceRecords = buyerChangePriceRecordService.queryWaitingRecordsByPreOrderCode(buyerOrder.getOrderCode());
if (CollectionUtils.isNotEmpty(buyerChangePriceRecords)) {
logger.warn("orderCode exist waiting deal change price record,orderCode:{}", buyerOrder.getOrderCode());
throw new UfoServiceException(401, "有未完成的调价");
}
}
private void recordChangePriceDetail(BidOrderChangePriceContext context, BidPublishResult bidPublishResult) {
buyerChangePriceRecordService.addWaitingRecord(context.buyerOrder.getOrderCode(),
context.sellerOrderGoods.getId(), bidPublishResult.getOrderCode(), bidPublishResult.getSkup());
}
private static class BidOrderChangePriceContext {
private class BidOrderChangePriceContext {
public BuyerOrder buyerOrder;
public SellerOrderGoods sellerOrderGoods;
public Pair<AddressInfo, AddressInfo> userAddressPair;
... ... @@ -258,5 +215,44 @@ public class BuyerBidPriceService {
this.newPrice = newPrice;
this.day = day;
}
public void validate(boolean mustChangePrice) {
if (mustChangePrice) {
validatePriceChanged(sellerOrderGoods.getGoodsPrice());
}
validateBuyerOrderStatus();
validateWaitingChangePriceRecord();
}
/**
* 校验价格是否相同
*/
private void validatePriceChanged(BigDecimal oldPrice) {
if (newPrice.compareTo(oldPrice) == 0) {
logger.warn("price is not change,orderCode:{},newPrice:{},oldPrice:{}", buyerOrder.getOrderCode());
throw new UfoServiceException(401, "价格未变化");
}
}
/**
* 只有求购中的订单才能调价
*/
private void validateBuyerOrderStatus() {
if (buyerOrder.getStatus().intValue() != OrderStatus.BIDING.getCode()) {
logger.warn("buyerOrder status is not biding, orderCode is {}", buyerOrder.getOrderCode());
throw new UfoServiceException(500, "非求购状态,不允许调价");
}
}
/**
* 校验变价记录表
*/
private void validateWaitingChangePriceRecord() {
List<BuyerChangePriceRecord> buyerChangePriceRecords = buyerChangePriceRecordService.queryWaitingRecordsByPreOrderCode(buyerOrder.getOrderCode());
if (CollectionUtils.isNotEmpty(buyerChangePriceRecords)) {
logger.warn("orderCode exist waiting deal change price record,orderCode:{}", buyerOrder.getOrderCode());
throw new UfoServiceException(401, "有未完成的调价");
}
}
}
}
... ...