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
resp.setDepositCode(deposit.getDepositCode());
resp.setShelfCode(deposit.getShelfCode());
resp.setDepositStatus(deposit.getStatus());
if(null != deposit.getOutType()) {
String outTypeStr = "";
if(deposit.getOutType().intValue() == 1) {
... ...
package com.yoho.ufo.order.service.impl;
import static org.junit.Assert.assertNotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
... ... @@ -14,6 +17,8 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.elasticsearch.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -21,10 +26,13 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.core.rabbitmq.YhProducer;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.exception.ServiceException;
import com.yoho.order.dal.BuyerOrderMapper;
import com.yoho.order.dal.OrderOperateRecordMapper;
import com.yoho.order.dal.SellerOrderGoodsMapper;
import com.yoho.order.dal.StorageDepositMapper;
import com.yoho.order.model.BuyerOrder;
import com.yoho.order.model.SellerOrderGoods;
import com.yoho.order.model.StorageDeposit;
import com.yoho.order.model.StorageDepositPickRsp;
... ... @@ -39,17 +47,21 @@ import com.yoho.ufo.service.impl.UserHelper;
import com.yoho.ufo.service.impl.UserProxyService;
import com.yoho.ufo.service.model.PageResponseBO;
import com.yoho.ufo.util.DateUtil;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.message.SmsMessageReq;
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
import com.yohobuy.ufo.model.order.common.OperateTypeEnum;
import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
@Service
public class StorageDepositServiceImpl implements IStorageDepositService{
private static final Logger LOGGER = LoggerFactory.getLogger(StorageDepositServiceImpl.class);
@Autowired
private StorageDepositMapper storageDepositMapper;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
private static final Integer DEPOT_NO_NANJING=1;//南京
private final static ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
... ... @@ -72,6 +84,9 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
@Resource(name = "yhProducer")
private YhProducer yhProducer;
@Autowired
private ServiceCaller serviceCaller;
@Override
public Map<String, Integer> getCountByStatus(StorageDepositReq req){
Integer depotNo = null == req.getDepotNo() ? DEPOT_NO_NANJING : req.getDepotNo();
... ... @@ -88,11 +103,24 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
Map<String, Integer> resultMap = Maps.newHashMap();
for(int i=0; i<statusArr.length; i++) {
resultMap.put(statusArr[i], storageDepositMapper.selectCountByStatusAndDepotNo(Integer.parseInt(statusArr[i]), depotNo));
resultMap.put(convertStatusCntKeyName(statusArr[i]), storageDepositMapper.selectCountByStatusAndDepotNo(Integer.parseInt(statusArr[i]), depotNo));
}
return resultMap;
}
private String convertStatusCntKeyName(String statusStr) {
Integer status = Integer.parseInt(statusStr);
switch(status) {
case 0: return "storePending";
case 1: return "storeHasBeen";
case 2: return "storePicking";
case 3: return "storePicked";
case 4: return "storeDelivered";
default: return "";
}
}
/**
* 查询一天就会到期的库存
... ... @@ -159,7 +187,11 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
List<String> depositCodeList = Arrays.asList(depositCodeArr);
//1、校验商品是不是属于当前货位
//2、校验商品状态是不是待寄存
//3、校验订单存不存在
List<StorageDeposit> depositList = storageDepositMapper.selectByDepositCodeList(depositCodeList);
List<String> orderCodeList = depositList.stream().map(StorageDeposit::getOrderCode).collect(Collectors.toList());
List<BuyerOrder> orderList = buyerOrderMapper.selectBatchByOrderCode(convertStringToLongList(orderCodeList));
Map<String, BuyerOrder> orderMap = orderList.stream().collect(Collectors.toMap(BuyerOrder::getOrderCode, b->b));
for(StorageDeposit item : depositList) {
if(StringUtils.isNotEmpty(item.getShelfCode()) && item.getShelfCode().equals(shelfCode)) {
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"已属于当前货位");
... ... @@ -167,6 +199,9 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
if(!item.getStatus().equals(StorageDepositStatusEnum.WAITING_IN.getCode())) {
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"不是待寄存状态");
}
if(null == orderMap.get(item.getOrderCode())) {
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"对应的订单号不存在");
}
}
//保存绑定
... ... @@ -202,11 +237,26 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
inboxService.sendSmsMessage(new SmsMessageReq());
//记录操作日志
saveOrderOperateRecord(item.getOrderCode(), userHelper, operateType, "");
//清理缓存
asyncCallClearCache(item.getOwnerUid(), item.getProductId(), item.getStorageId());
}
return num;
}
private List<Long> convertStringToLongList(List<String> list){
List<Long> resultList = Lists.newArrayList();
if(CollectionUtils.isEmpty(list)) {
return resultList;
}
for(String item : list) {
resultList.add(Long.parseLong(item));
}
return resultList;
}
@Override
public int finishPick(String shelfCode, String depositCodeStr) {
String[] depositCodeArr = depositCodeStr.split(",");
... ... @@ -225,11 +275,14 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
//更改状态为已入库
int num = storageDepositMapper.batchUpdateStatusByDepositCodeList(StorageDepositStatusEnum.WAITING_OUT.getCode(), depositCodeList);
//记录操作日志
int operateType =OperateTypeEnum.DEPOIST_FINISH_PICK.getCode();
UserHelper userHelper = new UserHelper();
for(StorageDeposit item : depositList) {
//记录操作日志
saveOrderOperateRecord(item.getOrderCode(), userHelper, operateType, "");
//清理缓存
asyncCallClearCache(item.getOwnerUid(), item.getProductId(), item.getStorageId());
}
return num;
... ... @@ -365,7 +418,7 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
for(StorageDeposit item : list) {
if(statusList.contains(item.getStatus())) {
String status = item.getStatus().toString();
resultMap.put(status, resultMap.get(status) + 1);
resultMap.put(convertStatusCntKeyName(status), resultMap.get(status) + 1);
}
}
... ... @@ -407,6 +460,18 @@ public class StorageDepositServiceImpl implements IStorageDepositService{
}
}
private JSONObject asyncCallClearCache(Integer ownerUid, Integer productId, Integer storageId) {
String args = "ufo-gateway.clearUserDepositCache";
LOGGER.info("asyncCallClearCache call ufo-gateway enter storageId is {}, interface is {}", storageId, args);
DepositDetailBo bo = new DepositDetailBo();
bo.setOwnerUid(ownerUid);
bo.setProductId(productId);
bo.setStorageId(storageId);
JSONObject jsonObject = serviceCaller.asyncCall(args, bo, JSONObject.class).get(5, TimeUnit.SECONDS);
LOGGER.info("asyncCallClearCache call ufo-gateway storageId is {}, interface is {},result is {}", storageId, args, jsonObject);
return jsonObject;
}
private String getReplacedContent(String content ,Object... params) {
return MessageFormatter.arrayFormat(content, params).getMessage();
}
... ...