Authored by TANLING

批量下架

... ... @@ -94,7 +94,27 @@ public class ErpFastDeliveryController {
logger.info("singleDownSelf param {}", req);
boolean result = erpFastDeliveryService.singleDownSelf(req);
boolean result = erpFastDeliveryService.batchDownSelf(req);
String msg = "下架成功";
if (!result) {
msg = "下架失败";
}
return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(msg).build();
}
/**
* 批量下架
* @param req
* @return
*/
@IgnoreSignature
@IgnoreSession
@RequestMapping("/batchDownSelf")
public ApiResponse batchDownSelf(@RequestBody FastDeliveryDownShelfReq req){
logger.info("batchDownSelf param {}", req);
boolean result = erpFastDeliveryService.batchDownSelf(req);
String msg = "下架成功";
if (!result) {
msg = "下架失败";
... ...
... ... @@ -46,6 +46,13 @@ public interface IErpFastDeliveryService {
/**
* 批量下架
* @param req
*/
public boolean batchDownSelf(FastDeliveryDownShelfReq req);
/**
* 获取货号尺寸信息
* @param req
* @return
... ...
... ... @@ -334,7 +334,7 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
/**
* 获取某个货号的最低价
* @param productCode
* @param req
* @return
*/
public List<StorageInfoResp> getLeastPriceByProductCode(FastDeliveryLeastPriceReq req){
... ... @@ -400,6 +400,36 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
return result.successCnt > 0 ? true : false;
}
/**
* 批量下架
* @param req
*/
public boolean batchDownSelf(FastDeliveryDownShelfReq req){
if (req.getUid() < 0){
logger.warn("uid is empty");
throw new UfoServiceException(400, "参数[uid]不合法");
}
if (CollectionUtils.isEmpty(req.getSkups())){
logger.warn("skups is empty");
throw new UfoServiceException(401, "参数[skups]不合法");
}
checkFastDeliveryAuth(req.getUid());
SkupDownShelfPrepareDto skupDtoMap = sellerDownShelfPrepareProcessor.getDownShelfFastDeliveryPreDto(req.getSkups());
SellerTaskDTO<SkupDownShelfPrepareDto> taskDTO = new SellerTaskDTO(req.getUid(),
SellerWalletDetail.Type.SELLER_OFF.getValue(),
sellerDownShelfTaskHandler,
JSON.toJSONString(req),
skupDtoMap);
SellerTaskResult result = sellerTaskProcessor.process(taskDTO);
return result.successCnt > 0 ? true : false;
}
/**
* 单个下架
* @param req
... ... @@ -418,7 +448,7 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
checkFastDeliveryAuth(req.getUid());
SkupDownShelfPrepareDto skupDtoMap = sellerDownShelfPrepareProcessor.getDownShelfPreDto(req.getSkup());
SkupDownShelfPrepareDto skupDtoMap = sellerDownShelfPrepareProcessor.getDownShelfFastDeliveryPreDto(Lists.newArrayList(req.getSkup()));
SellerTaskDTO<SkupDownShelfPrepareDto> taskDTO = new SellerTaskDTO(req.getUid(),
SellerWalletDetail.Type.SELLER_OFF.getValue(),
sellerDownShelfTaskHandler,
... ...
... ... @@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
... ... @@ -82,23 +83,35 @@ public class SellerDownShelfPrepareProcessor {
/**
* 获取skup对应的商品信息
* @param skup
* @param skups
* @return
*/
public SkupDownShelfPrepareDto getDownShelfPreDto(int skup){
public SkupDownShelfPrepareDto getDownShelfFastDeliveryPreDto(List<Integer> skups){
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
if (sog == null || (sog.getStatus() != null && !CAN_OFF_STATUS.contains(sog.getStatus()))){
logger.warn("getSellerOrderGoodInfo has buyed, skup {}", skup);
List<SellerOrderGoods> sogs = sellerOrderGoodsMapper.selectBySkups(skups);
if (CollectionUtils.isEmpty(sogs)){
logger.warn("getDownShelfFastDeliveryPreDto order goods not exist");
throw new UfoServiceException(501, "商品已被下单购买");
}
// 过滤出状态=出售中的商品
List<SellerOrderGoods> canSellSellerOrderGoods = sogs.stream().filter(x->x.getStatus()==SkupStatus.CAN_SELL.getCode()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(canSellSellerOrderGoods)){
logger.warn("getDownShelfFastDeliveryPreDto can sell order goods not exist");
throw new UfoServiceException(501, "商品已被下单购买");
}
// 根据skup转成普通的map
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = canSellSellerOrderGoods.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity(), (key1, key2) -> key2));
Map<Integer, SkupDto> skupMap = Maps.newHashMap();
skupMap.put(sog.getId(), SkupDto.builder().skup(sog.getId()).sellerOrderGoods(sog).batchNo(sog.getBatchNo()).build());
for (Integer skup : sellerOrderGoodsMap.keySet()){
skupMap.put(skup, SkupDto.builder().skup(skup).sellerOrderGoods(sellerOrderGoodsMap.get(skup)).batchNo(sellerOrderGoodsMap.get(skup).getBatchNo()).build());
}
SkupDownShelfPrepareDto sdspDto = SkupDownShelfPrepareDto.builder()
.idSkupMap(skupMap)
.skupType(SkupType.getSkupType(sog.getAttributes()))
.skupType(SkupType.FAST_DELIVERY)
.build();
return sdspDto;
}
... ...