|
|
package com.yoho.ufo.order.service.impl;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.yoho.ufo.util.DateUtil;
|
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.order.dal.StorageDepositMapper;
|
|
|
import com.yoho.order.model.StorageDeposit;
|
|
|
import com.yoho.order.model.StorageDepositPickRsp;
|
|
|
import com.yoho.order.model.StorageDepositReq;
|
|
|
import com.yoho.order.model.StorageDepositRsp;
|
|
|
import com.yoho.ufo.order.service.IStorageDepositService;
|
|
|
import com.yoho.ufo.service.model.PageResponseBO;
|
|
|
import com.yoho.ufo.util.DateUtil;
|
|
|
import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
|
|
|
|
|
|
@Service
|
|
|
public class StorageDepositServiceImpl implements IStorageDepositService{
|
...
|
...
|
@@ -82,6 +87,138 @@ public class StorageDepositServiceImpl implements IStorageDepositService{ |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponseBO<StorageDepositPickRsp> queryDepositPickListByStatus(StorageDepositReq req){
|
|
|
req.setDepotNo(null == req.getDepotNo() ? DEPOT_NO_NANJING : req.getDepotNo());
|
|
|
if(StringUtils.isNotEmpty(req.getQueryStr())) {
|
|
|
return queryDepositPickListByQueryStr(req.getQueryStr(), req.getStatus(), req.getDepotNo());
|
|
|
}
|
|
|
|
|
|
int total = storageDepositMapper.selectShelfCodeCnt(req.getDepotNo(), req.getStatus());
|
|
|
if(total == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
List<String> shelfCodeList = storageDepositMapper.selectShelfCodeList(req);
|
|
|
List<StorageDeposit> depositList = storageDepositMapper.selectByShelfCodeList(shelfCodeList);
|
|
|
Map<String, List<StorageDeposit>> depositMap = depositList.stream().collect(Collectors.groupingBy(StorageDeposit::getShelfCode));
|
|
|
List<StorageDepositPickRsp> rspList = buildStorageDepositPickRsp(depositMap);
|
|
|
|
|
|
PageResponseBO<StorageDepositPickRsp> result=new PageResponseBO<>();
|
|
|
result.setPage(req.getPage());
|
|
|
result.setList(rspList);
|
|
|
result.setSize(req.getSize());
|
|
|
result.setTotal(total);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int batchBindShelfCode(String shelfCode, String depositCodeStr) {
|
|
|
String[] depositCodeArr = depositCodeStr.split(",");
|
|
|
List<String> depositCodeList = Arrays.asList(depositCodeArr);
|
|
|
//1、校验商品是不是属于当前货位
|
|
|
//2、校验商品状态是不是待寄存
|
|
|
List<StorageDeposit> depositList = storageDepositMapper.selectByDepositCodeList(depositCodeList);
|
|
|
for(StorageDeposit item : depositList) {
|
|
|
if(StringUtils.isNotEmpty(item.getShelfCode()) && item.getShelfCode().equals(shelfCode)) {
|
|
|
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"已属于当前货位");
|
|
|
}
|
|
|
if(!item.getStatus().equals(StorageDepositStatusEnum.WAITING_IN.getCode())) {
|
|
|
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"不是待寄存状态");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//保存绑定
|
|
|
int num = storageDepositMapper.batchBindShelfCode(shelfCode, depositCodeList);
|
|
|
if(num > 0) {
|
|
|
//更改状态为已入库
|
|
|
num = storageDepositMapper.batchUpdateStatusByDepositCodeList(StorageDepositStatusEnum.HAS_IN.getCode(), depositCodeList);
|
|
|
}
|
|
|
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int finishPick(String shelfCode, String depositCodeStr) {
|
|
|
String[] depositCodeArr = depositCodeStr.split(",");
|
|
|
List<String> depositCodeList = Arrays.asList(depositCodeArr);
|
|
|
//1、校验商品是不是属于当前货位
|
|
|
//2、校验商品状态是不是待拣货
|
|
|
List<StorageDeposit> depositList = storageDepositMapper.selectByDepositCodeList(depositCodeList);
|
|
|
for(StorageDeposit item : depositList) {
|
|
|
if(StringUtils.isNotEmpty(item.getShelfCode()) && !item.getShelfCode().equals(shelfCode)) {
|
|
|
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"不属于当前货位");
|
|
|
}
|
|
|
if(!item.getStatus().equals(StorageDepositStatusEnum.WAITING_QUERY.getCode())) {
|
|
|
throw new ServiceException(400, "寄存码:"+item.getDepositCode()+"不是待拣货状态");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//更改状态为已入库
|
|
|
return storageDepositMapper.batchUpdateStatusByDepositCodeList(StorageDepositStatusEnum.WAITING_OUT.getCode(), depositCodeList);
|
|
|
}
|
|
|
|
|
|
private PageResponseBO<StorageDepositPickRsp> queryDepositPickListByQueryStr(String queryStr, Integer status, Integer depotNo){
|
|
|
//先按订单号来查
|
|
|
StorageDepositReq req = new StorageDepositReq();
|
|
|
req.setOrderCode(queryStr);
|
|
|
req.setDepotNo(depotNo);
|
|
|
req.setStatus(status);
|
|
|
req.setSize(100);
|
|
|
List<StorageDeposit> depositList = storageDepositMapper.selectByCondition(req);
|
|
|
if(CollectionUtils.isEmpty(depositList)){//再按寄存码来查
|
|
|
depositList = Lists.newArrayList();
|
|
|
req = new StorageDepositReq();
|
|
|
req.setDepositCode(queryStr);
|
|
|
req.setDepotNo(depotNo);
|
|
|
req.setStatus(status);
|
|
|
req.setSize(100);
|
|
|
List<StorageDeposit> list = storageDepositMapper.selectByCondition(req);
|
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
|
depositList.addAll(list);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(CollectionUtils.isEmpty(depositList)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
StorageDepositPickRsp rsp = new StorageDepositPickRsp();
|
|
|
rsp.setShelfCode(depositList.get(0).getShelfCode());
|
|
|
StorageDepositRsp depositRsp = new StorageDepositRsp();
|
|
|
depositRsp.setDepositCode(depositList.get(0).getDepositCode());
|
|
|
depositRsp.setOrderCode(depositList.get(0).getOrderCode());
|
|
|
rsp.setList(Lists.newArrayList(depositRsp));
|
|
|
|
|
|
PageResponseBO<StorageDepositPickRsp> result=new PageResponseBO<>();
|
|
|
result.setPage(1);
|
|
|
result.setList(Lists.newArrayList(rsp));
|
|
|
result.setSize(depositList.size());
|
|
|
result.setTotal(depositList.size());
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private List<StorageDepositPickRsp> buildStorageDepositPickRsp(Map<String, List<StorageDeposit>> depositMap){
|
|
|
List<StorageDepositPickRsp> rspList = Lists.newArrayList();
|
|
|
for(Entry<String, List<StorageDeposit>> entry : depositMap.entrySet()) {
|
|
|
StorageDepositPickRsp rsp = new StorageDepositPickRsp();
|
|
|
rsp.setShelfCode(entry.getKey());
|
|
|
List<StorageDepositRsp> list = Lists.newArrayList();
|
|
|
for(StorageDeposit item : entry.getValue()) {
|
|
|
StorageDepositRsp depositRsp = new StorageDepositRsp();
|
|
|
depositRsp.setDepositCode(item.getDepositCode());
|
|
|
depositRsp.setOrderCode(item.getOrderCode());
|
|
|
list.add(depositRsp);
|
|
|
}
|
|
|
rsp.setList(list);
|
|
|
rspList.add(rsp);
|
|
|
}
|
|
|
return rspList;
|
|
|
|
|
|
}
|
|
|
|
|
|
private PageResponseBO<StorageDepositRsp> queryDepositListByQueryStrAndStatus(String queryStr, Integer status, Integer depotNo){
|
|
|
//先按订单号来查
|
|
|
StorageDepositReq req = new StorageDepositReq();
|
...
|
...
|
|