Authored by tanling

急速发货

1 package com.yohoufo.order.controller; 1 package com.yohoufo.order.controller;
2 2
3 import com.google.common.base.Throwables; 3 import com.google.common.base.Throwables;
4 -import com.yohobuy.ufo.model.order.req.FastDeliveryAdjustPriceReq;  
5 -import com.yohobuy.ufo.model.order.req.FastDeliveryBatchOnShelfReq;  
6 -import com.yohobuy.ufo.model.order.req.FastDeliveryDownShelfReq;  
7 -import com.yohobuy.ufo.model.order.req.FastDeliveryGetShelfReq; 4 +import com.yohobuy.ufo.model.order.req.*;
8 import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfResp; 5 import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfResp;
  6 +import com.yohobuy.ufo.model.response.StorageInfoResp;
9 import com.yohoufo.common.ApiResponse; 7 import com.yohoufo.common.ApiResponse;
10 import com.yohoufo.common.annotation.IgnoreSession; 8 import com.yohoufo.common.annotation.IgnoreSession;
11 import com.yohoufo.common.annotation.IgnoreSignature; 9 import com.yohoufo.common.annotation.IgnoreSignature;
@@ -18,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody; @@ -18,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody;
18 import org.springframework.web.bind.annotation.RequestMapping; 16 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.bind.annotation.RestController; 17 import org.springframework.web.bind.annotation.RestController;
20 18
  19 +import java.util.List;
  20 +
21 /** 21 /**
22 * 急速发货第三方对接接口 22 * 急速发货第三方对接接口
23 */ 23 */
@@ -101,6 +101,20 @@ public class ErpFastDeliveryController { @@ -101,6 +101,20 @@ public class ErpFastDeliveryController {
101 101
102 102
103 /** 103 /**
  104 + * 获取货号的各尺寸的最低价
  105 + * @param req
  106 + * @return
  107 + */
  108 + @IgnoreSignature
  109 + @IgnoreSession
  110 + @RequestMapping("/getLowestPrice")
  111 + public ApiResponse getLowestPrice(@RequestBody FastDeliveryLeastPriceReq req){
  112 +
  113 + List<StorageInfoResp> result = erpFastDeliveryService.getLeastPriceByProductCode(req);
  114 + return new ApiResponse.ApiResponseBuilder().data(result).code(200).build();
  115 + }
  116 +
  117 + /**
104 * 查询上架商品信息 118 * 查询上架商品信息
105 * @param req 119 * @param req
106 * @return 120 * @return
1 package com.yohoufo.order.service; 1 package com.yohoufo.order.service;
2 2
3 -import com.yohobuy.ufo.model.order.req.FastDeliveryAdjustPriceReq;  
4 -import com.yohobuy.ufo.model.order.req.FastDeliveryBatchOnShelfReq;  
5 -import com.yohobuy.ufo.model.order.req.FastDeliveryDownShelfReq;  
6 -import com.yohobuy.ufo.model.order.req.FastDeliveryGetShelfReq; 3 +import com.yohobuy.ufo.model.order.req.*;
7 import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfResp; 4 import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfResp;
  5 +import com.yohobuy.ufo.model.response.StorageInfoResp;
8 import com.yohoufo.common.ApiResponse; 6 import com.yohoufo.common.ApiResponse;
9 7
  8 +import java.util.List;
  9 +
10 public interface IErpFastDeliveryService { 10 public interface IErpFastDeliveryService {
11 11
12 /** 12 /**
@@ -33,4 +33,12 @@ public interface IErpFastDeliveryService { @@ -33,4 +33,12 @@ public interface IErpFastDeliveryService {
33 * @param req 33 * @param req
34 */ 34 */
35 FastDeliveryGetShelfResp getShelfInfo(FastDeliveryGetShelfReq req); 35 FastDeliveryGetShelfResp getShelfInfo(FastDeliveryGetShelfReq req);
  36 +
  37 +
  38 + /**
  39 + * 获取某个货号的最低价
  40 + * @param productCode
  41 + * @return
  42 + */
  43 + List<StorageInfoResp> getLeastPriceByProductCode(FastDeliveryLeastPriceReq req);
36 } 44 }
@@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl; @@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.google.common.collect.Lists; 4 import com.google.common.collect.Lists;
5 import com.yohobuy.ufo.model.ProductInfo; 5 import com.yohobuy.ufo.model.ProductInfo;
  6 +import com.yohobuy.ufo.model.enums.StorageCheckEnum;
6 import com.yohobuy.ufo.model.order.bo.SellerBo; 7 import com.yohobuy.ufo.model.order.bo.SellerBo;
7 import com.yohobuy.ufo.model.order.common.OrderStatus; 8 import com.yohobuy.ufo.model.order.common.OrderStatus;
8 import com.yohobuy.ufo.model.order.common.SellerFuncEnum; 9 import com.yohobuy.ufo.model.order.common.SellerFuncEnum;
@@ -14,8 +15,12 @@ import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfResp; @@ -14,8 +15,12 @@ import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfResp;
14 import com.yohobuy.ufo.model.order.resp.OrderListInfo; 15 import com.yohobuy.ufo.model.order.resp.OrderListInfo;
15 import com.yohobuy.ufo.model.order.resp.PageResp; 16 import com.yohobuy.ufo.model.order.resp.PageResp;
16 import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo; 17 import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
  18 +import com.yohobuy.ufo.model.request.product.ProductRequestBo;
17 import com.yohobuy.ufo.model.response.ProductDetailResp; 19 import com.yohobuy.ufo.model.response.ProductDetailResp;
  20 +import com.yohobuy.ufo.model.response.StorageCheckResp;
  21 +import com.yohobuy.ufo.model.response.StorageInfoResp;
18 import com.yohoufo.common.exception.UfoServiceException; 22 import com.yohoufo.common.exception.UfoServiceException;
  23 +import com.yohoufo.common.utils.StringUtil;
19 import com.yohoufo.dal.order.*; 24 import com.yohoufo.dal.order.*;
20 import com.yohoufo.dal.order.model.*; 25 import com.yohoufo.dal.order.model.*;
21 import com.yohoufo.order.common.BillTradeStatus; 26 import com.yohoufo.order.common.BillTradeStatus;
@@ -145,6 +150,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -145,6 +150,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
145 req.setPage(1); 150 req.setPage(1);
146 } 151 }
147 152
  153 + checkFastDeliveryAuth(req.getUid());
  154 +
148 int total = sellerOrderGoodsMapper.selectCntByMulti(req.getUid(), req.getStatus(), req.getSkup(), 155 int total = sellerOrderGoodsMapper.selectCntByMulti(req.getUid(), req.getStatus(), req.getSkup(),
149 req.getOrderCode(), req.getStartTime(), req.getEndTime()); 156 req.getOrderCode(), req.getStartTime(), req.getEndTime());
150 if (total == 0) { 157 if (total == 0) {
@@ -296,6 +303,28 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -296,6 +303,28 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
296 303
297 304
298 /** 305 /**
  306 + * 获取某个货号的最低价
  307 + * @param productCode
  308 + * @return
  309 + */
  310 + public List<StorageInfoResp> getLeastPriceByProductCode(FastDeliveryLeastPriceReq req){
  311 +
  312 + if (req.getUid() < 0){
  313 + logger.warn("uid is empty");
  314 + throw new UfoServiceException(400, "参数[uid]不合法");
  315 + }
  316 +
  317 + if (StringUtils.isBlank(req.getProductCode())){
  318 + logger.warn("productCode is empty");
  319 + throw new UfoServiceException(400, "参数[productCode]不合法");
  320 + }
  321 +
  322 + checkFastDeliveryAuth(req.getUid());
  323 +
  324 + return productProxyService.getLowestPrice(req.getProductCode());
  325 + }
  326 +
  327 + /**
299 * 单个调价 328 * 单个调价
300 * @param req 329 * @param req
301 * @return 330 * @return
@@ -317,6 +346,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -317,6 +346,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
317 throw new UfoServiceException(402, "参数[newPrice]不合法"); 346 throw new UfoServiceException(402, "参数[newPrice]不合法");
318 } 347 }
319 348
  349 + checkFastDeliveryAuth(req.getUid());
  350 +
320 ChangePricePrepareDTO cppDto = adjustPricePrepareProcessor.getChangePricePreDto(req); 351 ChangePricePrepareDTO cppDto = adjustPricePrepareProcessor.getChangePricePreDto(req);
321 SellerTaskDTO<ChangePricePrepareDTO> taskDTO = null; 352 SellerTaskDTO<ChangePricePrepareDTO> taskDTO = null;
322 if (cppDto.getSalePrice().compareTo(cppDto.getPreSalePrice()) > 0) { 353 if (cppDto.getSalePrice().compareTo(cppDto.getPreSalePrice()) > 0) {
@@ -355,6 +386,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -355,6 +386,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
355 throw new UfoServiceException(401, "参数[skup]不合法"); 386 throw new UfoServiceException(401, "参数[skup]不合法");
356 } 387 }
357 388
  389 + checkFastDeliveryAuth(req.getUid());
  390 +
358 SkupDownShelfPrepareDto skupDtoMap = sellerDownShelfPrepareProcessor.getDownShelfPreDto(req.getSkup()); 391 SkupDownShelfPrepareDto skupDtoMap = sellerDownShelfPrepareProcessor.getDownShelfPreDto(req.getSkup());
359 SellerTaskDTO<SkupDownShelfPrepareDto> taskDTO = new SellerTaskDTO(req.getUid(), 392 SellerTaskDTO<SkupDownShelfPrepareDto> taskDTO = new SellerTaskDTO(req.getUid(),
360 SellerWalletDetail.Type.SELLER_OFF.getValue(), 393 SellerWalletDetail.Type.SELLER_OFF.getValue(),
@@ -372,39 +405,47 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -372,39 +405,47 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
372 // 检查入口参数 405 // 检查入口参数
373 checkBatchOnShelf(req); 406 checkBatchOnShelf(req);
374 407
375 - // 检查用户权限(批量上架权限)  
376 - int uid = req.getUid();  
377 - SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(req.getUid());  
378 - SellerBo sellerBo = sellerWrapper.buildSellerBo();  
379 - if (!sellerBo.isFastDeliverySuper()){  
380 - logger.warn("batchOnShelf not legal super, uid {} ", uid);  
381 - throw new UfoServiceException(501, "用户权限不合法!");  
382 - }  
383 - sellerWrapper = sellerWrapper.attachSellerLevelFunc((sw)->sellerFuncService.getSellerLevelFunc(sw));  
384 - sellerAuthCheckService.checkAuth(sellerBo, null, SellerFuncEnum.BATCH_PUBLISH); 408 + // 检查用户权限(急速发货权限)
  409 + SellerWrapper sellerWrapper = checkFastDeliveryAuth(req.getUid());
385 410
386 - // 检查货号and尺寸是否存在  
387 - List<ProductInfoReq> productInfoReqList = req.getProductInfos().stream().map(x -> {  
388 - ProductInfoReq productInfoReq = new ProductInfoReq();  
389 - productInfoReq.setProductCode(x.getProductCode());  
390 - productInfoReq.setSizeName(x.getSizeName());  
391 - return productInfoReq;  
392 - }).distinct().collect(Collectors.toList()); 411 + // 检查批量上架权限
  412 + sellerWrapper = sellerWrapper.attachSellerLevelFunc((sw)->sellerFuncService.getSellerLevelFunc(sw));
  413 + sellerAuthCheckService.checkAuth(sellerWrapper.buildSellerBo(), null, SellerFuncEnum.BATCH_PUBLISH);
  414 +
  415 + // 检查货号&尺寸 --> storageId
  416 + List<StorageCheckResp> storageCheckRespList = productProxyService.getStorageInfoList(buildStorageReq(req));
  417 + StorageCheckResp storageResp = storageCheckRespList.stream().filter(x->x.getStatus()!= StorageCheckEnum.PRODUCT_SIZE_MATCH.getType()).findAny().get();
  418 + if (storageResp != null){
  419 + logger.warn("productCode {} and sizeName {} invalidate", storageResp.getProductCode(), storageResp.getSizeName());
  420 + throw new UfoServiceException(400, "["+getProductCodeSizeNameKey(storageResp.getProductCode(),storageResp.getSizeName())+"]"+storageResp.getStatusStr());
  421 + }
393 422
394 - // 调用商品服务获取到商品的storageId  
395 - // 无法获取则异常 423 + Map<String,StorageCheckResp> storageMap = storageCheckRespList.stream().collect(Collectors.toMap(k->getProductCodeSizeNameKey(k.getProductCode(),k.getSizeName()), v->v));
396 424
397 // 上架 425 // 上架
398 List<ProductImportTranItemBo> responseList = Lists.newArrayList(); 426 List<ProductImportTranItemBo> responseList = Lists.newArrayList();
  427 +
  428 + // 上架的代码(和之前同)
399 for(FastDeliveryBatchOnShelfReq.ProductInfo productInfo : req.getProductInfos()){ 429 for(FastDeliveryBatchOnShelfReq.ProductInfo productInfo : req.getProductInfos()){
400 - Integer storageId = productInfo.getStorageId();  
401 - BigDecimal salePrice = productInfo.getConvertedPrice();  
402 - int storageNum = productInfo.getNum();  
403 - ImPrdNode node = ImPrdNode.builder().uid(uid) 430 +
  431 + StorageCheckResp storage = storageMap.get(storageMap.get(getProductCodeSizeNameKey(productInfo.getProductCode(), productInfo.getSizeName())));
  432 + if (storage == null){
  433 + logger.warn("productCode {} and sizeName {}. storageId not exist.", productInfo.getProductCode(), productInfo.getSizeName());
  434 + throw new UfoServiceException(403, "货号和尺寸对应的storageId不存在");
  435 + }
  436 +
  437 + productInfo.setStorageId(storage.getStorageId());
  438 +
  439 + ImPrdNode node = ImPrdNode.builder().uid(req.getUid())
404 .sellerWrapper(sellerWrapper) 440 .sellerWrapper(sellerWrapper)
405 - .storageId(storageId).salePrice(salePrice).storageNum(storageNum).productCode(productInfo.getProductCode()).sizeName(productInfo.getSizeName()) 441 + .storageId(productInfo.getStorageId())
  442 + .salePrice(productInfo.getConvertedPrice())
  443 + .storageNum(productInfo.getNum())
  444 + .productCode(productInfo.getProductCode())
  445 + .sizeName(productInfo.getSizeName())
406 .skupType(SkupType.FAST_DELIVERY.getCode()) 446 .skupType(SkupType.FAST_DELIVERY.getCode())
407 .build(); 447 .build();
  448 +
408 int successNum=0; 449 int successNum=0;
409 try{ 450 try{
410 SellerOrderSubmitHandler.ForkJoinResult fjr = importPublishExcutor.publishOne(node); 451 SellerOrderSubmitHandler.ForkJoinResult fjr = importPublishExcutor.publishOne(node);
@@ -413,7 +454,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -413,7 +454,8 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
413 responseList.add(buildShelfResp(req, productInfo, successNum)); 454 responseList.add(buildShelfResp(req, productInfo, successNum));
414 }catch(Exception ex){ 455 }catch(Exception ex){
415 logger.warn("in batchOnShelf.publishOne fail, uid {} productCode {} sizeName {} storageId {} salePrice {} storageNum {}", 456 logger.warn("in batchOnShelf.publishOne fail, uid {} productCode {} sizeName {} storageId {} salePrice {} storageNum {}",
416 - uid, productInfo.getProductCode(), productInfo.getSizeName(), storageId, salePrice, storageNum); 457 + req.getUid(), productInfo.getProductCode(), productInfo.getSizeName(), productInfo.getStorageId(),
  458 + productInfo.getConvertedPrice(), productInfo.getNum());
417 } 459 }
418 } 460 }
419 461
@@ -426,6 +468,45 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService { @@ -426,6 +468,45 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
426 468
427 } 469 }
428 470
  471 +
  472 +
  473 +
  474 + private String getProductCodeSizeNameKey(String productCode, String sizeName){
  475 +
  476 + StringBuilder sb = new StringBuilder();
  477 + sb.append(productCode);
  478 + sb.append("_");
  479 + sb.append(sizeName);
  480 + return sb.toString();
  481 +
  482 + }
  483 + private List<ProductRequestBo> buildStorageReq(FastDeliveryBatchOnShelfReq req) {
  484 + return req.getProductInfos().stream().map(x -> {
  485 + ProductRequestBo productInfoReq = new ProductRequestBo();
  486 + productInfoReq.setProductCode(x.getProductCode());
  487 + productInfoReq.setSizeName(x.getSizeName());
  488 + return productInfoReq;
  489 + }).distinct().collect(Collectors.toList());
  490 + }
  491 +
  492 +
  493 + /**
  494 + * 检查极速发货用户权限
  495 + * @param uid
  496 + * @return
  497 + */
  498 + public SellerWrapper checkFastDeliveryAuth(int uid){
  499 +
  500 + SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
  501 + SellerBo sellerBo = sellerWrapper.buildSellerBo();
  502 + if (!sellerBo.isFastDeliverySuper()){
  503 + logger.warn("checkFastDeliveryAuth not legal super, uid {} ", uid);
  504 + throw new UfoServiceException(501, "用户权限不合法!");
  505 + }
  506 +
  507 + return sellerWrapper;
  508 + }
  509 +
429 private ProductImportTranItemBo buildShelfResp(FastDeliveryBatchOnShelfReq req, FastDeliveryBatchOnShelfReq.ProductInfo productInfo, int successNum) { 510 private ProductImportTranItemBo buildShelfResp(FastDeliveryBatchOnShelfReq req, FastDeliveryBatchOnShelfReq.ProductInfo productInfo, int successNum) {
430 // 构造结果对象 最终结果插入到 商品服务的product_import_tran_item表中 511 // 构造结果对象 最终结果插入到 商品服务的product_import_tran_item表中
431 ProductImportTranItemBo productImportTranItemBo = new ProductImportTranItemBo(); 512 ProductImportTranItemBo productImportTranItemBo = new ProductImportTranItemBo();
@@ -10,8 +10,10 @@ import com.yohobuy.ufo.model.order.constants.SkupType; @@ -10,8 +10,10 @@ import com.yohobuy.ufo.model.order.constants.SkupType;
10 import com.yohobuy.ufo.model.request.StoragePriceBo; 10 import com.yohobuy.ufo.model.request.StoragePriceBo;
11 import com.yohobuy.ufo.model.request.product.PriceTrendBO; 11 import com.yohobuy.ufo.model.request.product.PriceTrendBO;
12 import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo; 12 import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
  13 +import com.yohobuy.ufo.model.request.product.ProductRequestBo;
13 import com.yohobuy.ufo.model.request.product.SecondhandInfoReqBo; 14 import com.yohobuy.ufo.model.request.product.SecondhandInfoReqBo;
14 import com.yohobuy.ufo.model.response.ProductDetailResp; 15 import com.yohobuy.ufo.model.response.ProductDetailResp;
  16 +import com.yohobuy.ufo.model.response.StorageCheckResp;
15 import com.yohobuy.ufo.model.response.StorageDataResp; 17 import com.yohobuy.ufo.model.response.StorageDataResp;
16 import com.yohobuy.ufo.model.response.StorageInfoResp; 18 import com.yohobuy.ufo.model.response.StorageInfoResp;
17 import com.yohoufo.common.ApiResponse; 19 import com.yohoufo.common.ApiResponse;
@@ -164,16 +166,37 @@ public class ProductProxyService extends AbsProxyService{ @@ -164,16 +166,37 @@ public class ProductProxyService extends AbsProxyService{
164 return new HashMap<>(); 166 return new HashMap<>();
165 } 167 }
166 168
  169 + public List<StorageCheckResp> getStorageInfoList(List<ProductRequestBo> requestBos){
  170 + try{
  171 + return ufoServiceCaller.call("ufo.product.storage", requestBos);
  172 + }catch (Exception e){
  173 + logger.warn("getStorageInfoList requestBos {}", requestBos);
  174 + }
  175 +
  176 + return null;
  177 + }
  178 +
167 public Map<Integer, ProductInfo> getProductCodeList(List<Integer> storageIdList){ 179 public Map<Integer, ProductInfo> getProductCodeList(List<Integer> storageIdList){
168 180
169 try{ 181 try{
170 return ufoServiceCaller.call("ufo.product.list.data", storageIdList); 182 return ufoServiceCaller.call("ufo.product.list.data", storageIdList);
171 }catch (Exception e){ 183 }catch (Exception e){
172 - logger.warn("getProductCode storageIdList {}", storageIdList); 184 + logger.warn("getProductCodeList storageIdList {}", storageIdList);
173 } 185 }
174 186
175 return null; 187 return null;
  188 + }
176 189
  190 +
  191 + public List<StorageInfoResp> getLowestPrice(String productCode){
  192 +
  193 + try{
  194 + return ufoServiceCaller.call("ufo.product.storage.leastOnSalePrice", productCode);
  195 + }catch (Exception e){
  196 + logger.warn("getLowestPrice getLowestPrice {}", productCode);
  197 + }
  198 +
  199 + return null;
177 } 200 }
178 201
179 public PrdPrice getPrdPriceRange(Integer uid, 202 public PrdPrice getPrdPriceRange(Integer uid,