|
|
package com.yohoufo.order.service.impl.processor;
|
|
|
|
|
|
import com.google.common.base.Splitter;
|
|
|
import com.yohobuy.ufo.model.order.common.SkupStatus;
|
|
|
import com.yohobuy.ufo.model.order.req.BatchChangePriceReq;
|
|
|
import com.yohoufo.common.exception.GatewayException;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by chao.chen on 2018/11/21.
|
|
|
* 根据批次号来调价
|
|
|
*/
|
|
|
@Service
|
|
|
public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProcessor<BatchChangePriceReq> {
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Override
|
|
|
public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) throws GatewayException {
|
|
|
String skupList = req.getSkupList();
|
|
|
if (StringUtils.isBlank(skupList)) {
|
|
|
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
|
|
|
throw new UfoServiceException(400, "参数[skupList]为空");
|
|
|
}
|
|
|
return super.checkAndAcquire(req);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
protected List<Integer> getExpectedSkups(BatchChangePriceReq req) {
|
|
|
List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(req.getSkupList());
|
|
|
return skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected List<SellerOrderGoods> getRealSkupOrderGoodsList(BatchChangePriceReq req) {
|
|
|
Long batchNo = checkNAcquireBatchNo(req.getBatchNo());
|
|
|
SellerOrderGoods condition = new SellerOrderGoods();
|
|
|
condition.setBatchNo(batchNo);
|
|
|
//按照批次,同一个批次不需要有两个价格,需要排除支付中的订单
|
|
|
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,
|
|
|
BigDecimal newPrice,
|
|
|
Map<Integer, SkupDto> skupOfSalingMap) {
|
|
|
Assert.notEmpty(expectedSkups,"expectedSkups must not be empty");
|
|
|
Assert.notEmpty(skupOfSalingMap,"skupOfSalingMap must not be empty");
|
|
|
Map<Integer, SkupDto> map = new HashMap<>(expectedSkups.size());
|
|
|
|
|
|
for (Integer skup : expectedSkups) {
|
|
|
|
|
|
if (!skupOfSalingMap.containsKey(skup)) {
|
|
|
logger.warn("ChangePrice checkNeedProcessSkups skup is in other status , skup {}", skup);
|
|
|
throw new UfoServiceException(501, "部分商品不可调价");
|
|
|
}
|
|
|
|
|
|
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, "前后价格没有变化");
|
|
|
}
|
|
|
|
|
|
map.put(skup, skupOfSalingMap.get(skup));
|
|
|
}
|
|
|
|
|
|
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
private Long checkNAcquireBatchNo(String batchNoStr) {
|
|
|
Long batchNo = null;
|
|
|
boolean isIllegalBatchNo;
|
|
|
try {
|
|
|
isIllegalBatchNo = (StringUtils.isBlank(batchNoStr) || (batchNo = Long.valueOf(batchNoStr)) <= 0L);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
isIllegalBatchNo = true;
|
|
|
logger.warn("ChangePrice checkAndAcquire batchNoStr illegal , batchNoStr {}", batchNoStr, ex);
|
|
|
}
|
|
|
|
|
|
if (isIllegalBatchNo) {
|
|
|
throw new UfoServiceException(400, "参数[batchNoStr]非法");
|
|
|
}
|
|
|
return batchNo;
|
|
|
}
|
|
|
} |
|
|
//package com.yohoufo.order.service.impl.processor;
|
|
|
//
|
|
|
//import com.google.common.base.Splitter;
|
|
|
//import com.yohobuy.ufo.model.order.common.SkupStatus;
|
|
|
//import com.yohobuy.ufo.model.order.req.BatchChangePriceReq;
|
|
|
//import com.yohoufo.common.exception.GatewayException;
|
|
|
//import com.yohoufo.common.exception.UfoServiceException;
|
|
|
//import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
//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.springframework.beans.factory.annotation.Autowired;
|
|
|
//import org.springframework.stereotype.Service;
|
|
|
//import org.springframework.util.Assert;
|
|
|
//
|
|
|
//import java.math.BigDecimal;
|
|
|
//import java.util.Arrays;
|
|
|
//import java.util.HashMap;
|
|
|
//import java.util.List;
|
|
|
//import java.util.Map;
|
|
|
//import java.util.stream.Collectors;
|
|
|
//
|
|
|
///**
|
|
|
// * Created by chao.chen on 2018/11/21.
|
|
|
// * 根据批次号来调价
|
|
|
// */
|
|
|
//@Service
|
|
|
//public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProcessor<BatchChangePriceReq> {
|
|
|
//
|
|
|
// @Autowired
|
|
|
// private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
//
|
|
|
// @Override
|
|
|
// public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) throws GatewayException {
|
|
|
// String skupList = req.getSkupList();
|
|
|
// if (StringUtils.isBlank(skupList)) {
|
|
|
// logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
|
|
|
// throw new UfoServiceException(400, "参数[skupList]为空");
|
|
|
// }
|
|
|
// return super.checkAndAcquire(req);
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// @Override
|
|
|
// protected List<Integer> getExpectedSkups(BatchChangePriceReq req) {
|
|
|
// List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(req.getSkupList());
|
|
|
// return skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
|
|
|
// }
|
|
|
//
|
|
|
// @Override
|
|
|
// protected List<SellerOrderGoods> getRealSkupOrderGoodsList(BatchChangePriceReq req) {
|
|
|
// Long batchNo = checkNAcquireBatchNo(req.getBatchNo());
|
|
|
// SellerOrderGoods condition = new SellerOrderGoods();
|
|
|
// condition.setBatchNo(batchNo);
|
|
|
// //按照批次,同一个批次不需要有两个价格,需要排除支付中的订单
|
|
|
// 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,
|
|
|
// BigDecimal newPrice,
|
|
|
// Map<Integer, SkupDto> skupOfSalingMap) {
|
|
|
// Assert.notEmpty(expectedSkups,"expectedSkups must not be empty");
|
|
|
// Assert.notEmpty(skupOfSalingMap,"skupOfSalingMap must not be empty");
|
|
|
// Map<Integer, SkupDto> map = new HashMap<>(expectedSkups.size());
|
|
|
//
|
|
|
// for (Integer skup : expectedSkups) {
|
|
|
//
|
|
|
// if (!skupOfSalingMap.containsKey(skup)) {
|
|
|
// logger.warn("ChangePrice checkNeedProcessSkups skup is in other status , skup {}", skup);
|
|
|
// throw new UfoServiceException(501, "部分商品不可调价");
|
|
|
// }
|
|
|
//
|
|
|
// 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, "前后价格没有变化");
|
|
|
// }
|
|
|
//
|
|
|
// map.put(skup, skupOfSalingMap.get(skup));
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// return map;
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// private Long checkNAcquireBatchNo(String batchNoStr) {
|
|
|
// Long batchNo = null;
|
|
|
// boolean isIllegalBatchNo;
|
|
|
// try {
|
|
|
// isIllegalBatchNo = (StringUtils.isBlank(batchNoStr) || (batchNo = Long.valueOf(batchNoStr)) <= 0L);
|
|
|
//
|
|
|
// } catch (Exception ex) {
|
|
|
// isIllegalBatchNo = true;
|
|
|
// logger.warn("ChangePrice checkAndAcquire batchNoStr illegal , batchNoStr {}", batchNoStr, ex);
|
|
|
// }
|
|
|
//
|
|
|
// if (isIllegalBatchNo) {
|
|
|
// throw new UfoServiceException(400, "参数[batchNoStr]非法");
|
|
|
// }
|
|
|
// return batchNo;
|
|
|
// }
|
|
|
//} |
...
|
...
|
|