Authored by mali

Merge branch 'test6.9.8' of http://git.yoho.cn/ufo/ufo-platform into test6.9.8

@@ -3246,6 +3246,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService, ApplicationCon @@ -3246,6 +3246,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService, ApplicationCon
3246 3246
3247 resp.setDepositCode(deposit.getDepositCode()); 3247 resp.setDepositCode(deposit.getDepositCode());
3248 resp.setShelfCode(deposit.getShelfCode()); 3248 resp.setShelfCode(deposit.getShelfCode());
  3249 + resp.setDepositStatus(deposit.getStatus());
3249 if(null != deposit.getOutType()) { 3250 if(null != deposit.getOutType()) {
3250 String outTypeStr = ""; 3251 String outTypeStr = "";
3251 if(deposit.getOutType().intValue() == 1) { 3252 if(deposit.getOutType().intValue() == 1) {
1 package com.yoho.ufo.order.service.impl; 1 package com.yoho.ufo.order.service.impl;
2 2
  3 +import static org.junit.Assert.assertNotNull;
  4 +
3 import java.util.Arrays; 5 import java.util.Arrays;
4 import java.util.List; 6 import java.util.List;
5 import java.util.Map; 7 import java.util.Map;
6 import java.util.Map.Entry; 8 import java.util.Map.Entry;
7 import java.util.concurrent.ExecutorService; 9 import java.util.concurrent.ExecutorService;
8 import java.util.concurrent.Executors; 10 import java.util.concurrent.Executors;
  11 +import java.util.concurrent.TimeUnit;
9 import java.util.stream.Collectors; 12 import java.util.stream.Collectors;
10 13
11 import javax.annotation.Resource; 14 import javax.annotation.Resource;
@@ -14,6 +17,8 @@ import org.apache.commons.collections.CollectionUtils; @@ -14,6 +17,8 @@ import org.apache.commons.collections.CollectionUtils;
14 import org.apache.commons.lang3.StringUtils; 17 import org.apache.commons.lang3.StringUtils;
15 import org.apache.ibatis.annotations.Param; 18 import org.apache.ibatis.annotations.Param;
16 import org.elasticsearch.common.collect.Maps; 19 import org.elasticsearch.common.collect.Maps;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
17 import org.slf4j.helpers.MessageFormatter; 22 import org.slf4j.helpers.MessageFormatter;
18 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service; 24 import org.springframework.stereotype.Service;
@@ -21,10 +26,13 @@ import org.springframework.stereotype.Service; @@ -21,10 +26,13 @@ import org.springframework.stereotype.Service;
21 import com.alibaba.fastjson.JSONObject; 26 import com.alibaba.fastjson.JSONObject;
22 import com.google.common.collect.Lists; 27 import com.google.common.collect.Lists;
23 import com.yoho.core.rabbitmq.YhProducer; 28 import com.yoho.core.rabbitmq.YhProducer;
  29 +import com.yoho.core.rest.client.ServiceCaller;
24 import com.yoho.error.exception.ServiceException; 30 import com.yoho.error.exception.ServiceException;
  31 +import com.yoho.order.dal.BuyerOrderMapper;
25 import com.yoho.order.dal.OrderOperateRecordMapper; 32 import com.yoho.order.dal.OrderOperateRecordMapper;
26 import com.yoho.order.dal.SellerOrderGoodsMapper; 33 import com.yoho.order.dal.SellerOrderGoodsMapper;
27 import com.yoho.order.dal.StorageDepositMapper; 34 import com.yoho.order.dal.StorageDepositMapper;
  35 +import com.yoho.order.model.BuyerOrder;
28 import com.yoho.order.model.SellerOrderGoods; 36 import com.yoho.order.model.SellerOrderGoods;
29 import com.yoho.order.model.StorageDeposit; 37 import com.yoho.order.model.StorageDeposit;
30 import com.yoho.order.model.StorageDepositPickRsp; 38 import com.yoho.order.model.StorageDepositPickRsp;
@@ -39,17 +47,21 @@ import com.yoho.ufo.service.impl.UserHelper; @@ -39,17 +47,21 @@ import com.yoho.ufo.service.impl.UserHelper;
39 import com.yoho.ufo.service.impl.UserProxyService; 47 import com.yoho.ufo.service.impl.UserProxyService;
40 import com.yoho.ufo.service.model.PageResponseBO; 48 import com.yoho.ufo.service.model.PageResponseBO;
41 import com.yoho.ufo.util.DateUtil; 49 import com.yoho.ufo.util.DateUtil;
42 -import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;  
43 -import com.yohobuy.ufo.model.message.SmsMessageReq; 50 +import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
44 import com.yohobuy.ufo.model.order.common.OperateTypeEnum; 51 import com.yohobuy.ufo.model.order.common.OperateTypeEnum;
45 import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum; 52 import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
46 53
47 @Service 54 @Service
48 public class StorageDepositServiceImpl implements IStorageDepositService{ 55 public class StorageDepositServiceImpl implements IStorageDepositService{
49 56
  57 + private static final Logger LOGGER = LoggerFactory.getLogger(StorageDepositServiceImpl.class);
  58 +
50 @Autowired 59 @Autowired
51 private StorageDepositMapper storageDepositMapper; 60 private StorageDepositMapper storageDepositMapper;
52 61
  62 + @Autowired
  63 + private BuyerOrderMapper buyerOrderMapper;
  64 +
53 private static final Integer DEPOT_NO_NANJING=1;//南京 65 private static final Integer DEPOT_NO_NANJING=1;//南京
54 66
55 private final static ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); 67 private final static ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
@@ -72,6 +84,9 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -72,6 +84,9 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
72 @Resource(name = "yhProducer") 84 @Resource(name = "yhProducer")
73 private YhProducer yhProducer; 85 private YhProducer yhProducer;
74 86
  87 + @Autowired
  88 + private ServiceCaller serviceCaller;
  89 +
75 @Override 90 @Override
76 public Map<String, Integer> getCountByStatus(StorageDepositReq req){ 91 public Map<String, Integer> getCountByStatus(StorageDepositReq req){
77 Integer depotNo = null == req.getDepotNo() ? DEPOT_NO_NANJING : req.getDepotNo(); 92 Integer depotNo = null == req.getDepotNo() ? DEPOT_NO_NANJING : req.getDepotNo();
@@ -88,12 +103,25 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -88,12 +103,25 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
88 103
89 Map<String, Integer> resultMap = Maps.newHashMap(); 104 Map<String, Integer> resultMap = Maps.newHashMap();
90 for(int i=0; i<statusArr.length; i++) { 105 for(int i=0; i<statusArr.length; i++) {
91 - resultMap.put(statusArr[i], storageDepositMapper.selectCountByStatusAndDepotNo(Integer.parseInt(statusArr[i]), depotNo)); 106 + resultMap.put(convertStatusCntKeyName(statusArr[i]), storageDepositMapper.selectCountByStatusAndDepotNo(Integer.parseInt(statusArr[i]), depotNo));
92 } 107 }
93 108
94 return resultMap; 109 return resultMap;
95 } 110 }
96 111
  112 +
  113 + private String convertStatusCntKeyName(String statusStr) {
  114 + Integer status = Integer.parseInt(statusStr);
  115 + switch(status) {
  116 + case 0: return "storePending";
  117 + case 1: return "storeHasBeen";
  118 + case 2: return "storePicking";
  119 + case 3: return "storePicked";
  120 + case 4: return "storeDelivered";
  121 + default: return "";
  122 + }
  123 + }
  124 +
97 /** 125 /**
98 * 查询一天就会到期的库存 126 * 查询一天就会到期的库存
99 * @return 127 * @return
@@ -159,7 +187,11 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -159,7 +187,11 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
159 List<String> depositCodeList = Arrays.asList(depositCodeArr); 187 List<String> depositCodeList = Arrays.asList(depositCodeArr);
160 //1、校验商品是不是属于当前货位 188 //1、校验商品是不是属于当前货位
161 //2、校验商品状态是不是待寄存 189 //2、校验商品状态是不是待寄存
  190 + //3、校验订单存不存在
162 List<StorageDeposit> depositList = storageDepositMapper.selectByDepositCodeList(depositCodeList); 191 List<StorageDeposit> depositList = storageDepositMapper.selectByDepositCodeList(depositCodeList);
  192 + List<String> orderCodeList = depositList.stream().map(StorageDeposit::getOrderCode).collect(Collectors.toList());
  193 + List<BuyerOrder> orderList = buyerOrderMapper.selectBatchByOrderCode(convertStringToLongList(orderCodeList));
  194 + Map<String, BuyerOrder> orderMap = orderList.stream().collect(Collectors.toMap(BuyerOrder::getOrderCode, b->b));
163 for(StorageDeposit item : depositList) { 195 for(StorageDeposit item : depositList) {
164 if(StringUtils.isNotEmpty(item.getShelfCode()) && item.getShelfCode().equals(shelfCode)) { 196 if(StringUtils.isNotEmpty(item.getShelfCode()) && item.getShelfCode().equals(shelfCode)) {
165 throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"已属于当前货位"); 197 throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"已属于当前货位");
@@ -167,6 +199,9 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -167,6 +199,9 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
167 if(!item.getStatus().equals(StorageDepositStatusEnum.WAITING_IN.getCode())) { 199 if(!item.getStatus().equals(StorageDepositStatusEnum.WAITING_IN.getCode())) {
168 throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"不是待寄存状态"); 200 throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"不是待寄存状态");
169 } 201 }
  202 + if(null == orderMap.get(item.getOrderCode())) {
  203 + throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"对应的订单号不存在");
  204 + }
170 } 205 }
171 206
172 //保存绑定 207 //保存绑定
@@ -202,11 +237,26 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -202,11 +237,26 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
202 inboxService.sendSmsMessage(new SmsMessageReq()); 237 inboxService.sendSmsMessage(new SmsMessageReq());
203 //记录操作日志 238 //记录操作日志
204 saveOrderOperateRecord(item.getOrderCode(), userHelper, operateType, ""); 239 saveOrderOperateRecord(item.getOrderCode(), userHelper, operateType, "");
  240 + //清理缓存
  241 + asyncCallClearCache(item.getOwnerUid(), item.getProductId(), item.getStorageId());
205 } 242 }
206 243
207 return num; 244 return num;
208 } 245 }
209 246
  247 + private List<Long> convertStringToLongList(List<String> list){
  248 + List<Long> resultList = Lists.newArrayList();
  249 + if(CollectionUtils.isEmpty(list)) {
  250 + return resultList;
  251 + }
  252 +
  253 + for(String item : list) {
  254 + resultList.add(Long.parseLong(item));
  255 + }
  256 +
  257 + return resultList;
  258 + }
  259 +
210 @Override 260 @Override
211 public int finishPick(String shelfCode, String depositCodeStr) { 261 public int finishPick(String shelfCode, String depositCodeStr) {
212 String[] depositCodeArr = depositCodeStr.split(","); 262 String[] depositCodeArr = depositCodeStr.split(",");
@@ -225,11 +275,14 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -225,11 +275,14 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
225 275
226 //更改状态为已入库 276 //更改状态为已入库
227 int num = storageDepositMapper.batchUpdateStatusByDepositCodeList(StorageDepositStatusEnum.WAITING_OUT.getCode(), depositCodeList); 277 int num = storageDepositMapper.batchUpdateStatusByDepositCodeList(StorageDepositStatusEnum.WAITING_OUT.getCode(), depositCodeList);
228 - //记录操作日志 278 +
229 int operateType =OperateTypeEnum.DEPOIST_FINISH_PICK.getCode(); 279 int operateType =OperateTypeEnum.DEPOIST_FINISH_PICK.getCode();
230 UserHelper userHelper = new UserHelper(); 280 UserHelper userHelper = new UserHelper();
231 for(StorageDeposit item : depositList) { 281 for(StorageDeposit item : depositList) {
  282 + //记录操作日志
232 saveOrderOperateRecord(item.getOrderCode(), userHelper, operateType, ""); 283 saveOrderOperateRecord(item.getOrderCode(), userHelper, operateType, "");
  284 + //清理缓存
  285 + asyncCallClearCache(item.getOwnerUid(), item.getProductId(), item.getStorageId());
233 } 286 }
234 287
235 return num; 288 return num;
@@ -365,7 +418,7 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -365,7 +418,7 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
365 for(StorageDeposit item : list) { 418 for(StorageDeposit item : list) {
366 if(statusList.contains(item.getStatus())) { 419 if(statusList.contains(item.getStatus())) {
367 String status = item.getStatus().toString(); 420 String status = item.getStatus().toString();
368 - resultMap.put(status, resultMap.get(status) + 1); 421 + resultMap.put(convertStatusCntKeyName(status), resultMap.get(status) + 1);
369 } 422 }
370 } 423 }
371 424
@@ -407,6 +460,18 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ @@ -407,6 +460,18 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
407 } 460 }
408 } 461 }
409 462
  463 + private JSONObject asyncCallClearCache(Integer ownerUid, Integer productId, Integer storageId) {
  464 + String args = "ufo-gateway.clearUserDepositCache";
  465 + LOGGER.info("asyncCallClearCache call ufo-gateway enter storageId is {}, interface is {}", storageId, args);
  466 + DepositDetailBo bo = new DepositDetailBo();
  467 + bo.setOwnerUid(ownerUid);
  468 + bo.setProductId(productId);
  469 + bo.setStorageId(storageId);
  470 + JSONObject jsonObject = serviceCaller.asyncCall(args, bo, JSONObject.class).get(5, TimeUnit.SECONDS);
  471 + LOGGER.info("asyncCallClearCache call ufo-gateway storageId is {}, interface is {},result is {}", storageId, args, jsonObject);
  472 + return jsonObject;
  473 + }
  474 +
410 private String getReplacedContent(String content ,Object... params) { 475 private String getReplacedContent(String content ,Object... params) {
411 return MessageFormatter.arrayFormat(content, params).getMessage(); 476 return MessageFormatter.arrayFormat(content, params).getMessage();
412 } 477 }