|
|
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.SellerOrderBatchCancelReq;
|
|
|
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.SkupDto;
|
|
|
import lombok.Data;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by chao.chen on 2018/11/22.
|
|
|
*/
|
|
|
@Service
|
|
|
public class SellerBatchCancelPrepareProcessor {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Data
|
|
|
public static class DataNode{
|
|
|
Long batchNo;
|
|
|
|
|
|
List<Integer> needOffShelveSkups;
|
|
|
|
|
|
Map<Integer, SkupDto> tskupMap;
|
|
|
|
|
|
public DataNode(Long batchNo, List<Integer> needOffShelveSkups, Map<Integer, SkupDto> tskupMap) {
|
|
|
this.batchNo = batchNo;
|
|
|
this.needOffShelveSkups = needOffShelveSkups;
|
|
|
this.tskupMap = tskupMap;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public DataNode checkAndAcquire(SellerOrderBatchCancelReq req){
|
|
|
int uid = req.getUid();
|
|
|
if (uid <= 0){
|
|
|
logger.warn("batch off shelve checkAndAcquire uid illegal , req {}", req);
|
|
|
throw new UfoServiceException(400, "参数[uid]错误");
|
|
|
}
|
|
|
|
|
|
if(!sellerOrderPrepareProcessor.checkIsEntry(uid)){
|
|
|
logger.warn("batch off shelve checkAndAcquire uid is not entry shop , req {}", req);
|
|
|
throw new UfoServiceException(400, "您不是入驻商家");
|
|
|
}
|
|
|
|
|
|
String skupList = req.getSkupList();
|
|
|
if (StringUtils.isBlank(skupList)){
|
|
|
logger.warn("batch off shelve checkAndAcquire uid illegal , req {}", req);
|
|
|
throw new UfoServiceException(400, "参数[skupList]为空");
|
|
|
}
|
|
|
//考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉;
|
|
|
//不做过滤导致后面的数量 扣费检查都可能不对
|
|
|
List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList);
|
|
|
List<Integer> needOffShelveSkups = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
|
|
|
//check batch no
|
|
|
Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req);
|
|
|
|
|
|
//检查
|
|
|
Map<Integer, SkupDto> skupMap = checkNeedProcessSkups(needOffShelveSkups,req);
|
|
|
DataNode node = new DataNode(batchNo, needOffShelveSkups, skupMap);
|
|
|
return node;
|
|
|
}
|
|
|
|
|
|
final static List<Integer> CAN_OFF_STATUS = Arrays.asList(SkupStatus.CAN_SELL.getCode());
|
|
|
|
|
|
private Map<Integer, SkupDto> checkNeedProcessSkups(List<Integer> needChangePriceSkupList, SellerOrderBatchCancelReq req){
|
|
|
|
|
|
List<SellerOrderGoods> sellerOrderGoodList = sellerOrderGoodsMapper.selectBySkupsNStatus(needChangePriceSkupList, CAN_OFF_STATUS);
|
|
|
if (CollectionUtils.isEmpty(sellerOrderGoodList)){
|
|
|
logger.warn("batch off shelve checkAndAcquire not find skups by batchNo, req {}", req);
|
|
|
throw new UfoServiceException(501, "商品不存在");
|
|
|
}
|
|
|
List<Integer> skups = sellerOrderGoodList.parallelStream().map(SellerOrderGoods::getId).collect(Collectors.toList());
|
|
|
logger.info("batch off shelve price checkExistWaitingBuyerPay req {} skups in db {}", req, skups);
|
|
|
|
|
|
return sellerOrderGoodList.parallelStream().collect(Collectors.toMap(SellerOrderGoods::getId,
|
|
|
(sog)-> SkupDto.builder().skup(sog.getId()).sellerOrderGoods(sog).batchNo(sog.getBatchNo()).build()));
|
|
|
}
|
|
|
|
|
|
private Long checkNAcquireBatchNo(String batchNoStr, SellerOrderBatchCancelReq req){
|
|
|
Long batchNo = null;
|
|
|
boolean isIllegalBatchNo;
|
|
|
try {
|
|
|
isIllegalBatchNo = (StringUtils.isBlank(batchNoStr) || (batchNo = Long.valueOf(batchNoStr)) <= 0L);
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
isIllegalBatchNo = true;
|
|
|
logger.warn("batch off shelve checkAndAcquire batchNoStr illegal , req {}", req, ex);
|
|
|
}
|
|
|
|
|
|
if (isIllegalBatchNo){
|
|
|
throw new UfoServiceException(400, "参数[batchNoStr]非法");
|
|
|
}
|
|
|
return batchNo;
|
|
|
}
|
|
|
} |
...
|
...
|
|