Commit bd210c83 LN

入库单查找料箱生成出库任务

1 个父辈 f351910f
......@@ -98,4 +98,8 @@ public interface IStoragePosManager extends IBaseManager<StoragePos> {
void batchUpdatePosEnabled(List<String> idList, boolean enabled);
List<StoragePos> findPosByIdList(List<String> idList);
StoragePos findBoxPNInStorages(List<String> storageIdList, String pn, Collection<String> excludePosIds, CHECKOUT_TYPE checkOutType ) ;
StoragePos findEmptyBoxToPutIn(List<String> storageIdList, String pn, Collection<String> excludePosIds, CHECKOUT_TYPE checkOutType ) ;
}
......@@ -890,4 +890,69 @@ public class StoragePosManagerImpl implements IStoragePosManager {
Query query = new Query(Criteria.where("id").in(idList));
return storagePosDao.findByQuery(query);
}
@Override
public StoragePos findBoxPNInStorages(List<String> storageIdList, String pn, Collection<String> excludePosIds, CHECKOUT_TYPE checkOutType ) {
Criteria c = Criteria.where("id").nin(excludePosIds);
c = c.and("enabled").is(true);//可用
c.and("used").is(true);
c.and("barcode").exists(true);//已使用有料箱
c.and("barcode.status").is(BARCODE_STATUS.IN_STORE);
if (storageIdList != null) {
c = c.and("storageId").in(storageIdList);
}
if (ObjectUtil.isNotEmpty(pn)) {
c.and("barcode.subCodeList.partNumber").is(pn);
}
// if (ObjectUtil.isNotEmpty(warehouseCode)) {
// c.and("barcode.subCodeList.warehouseCode").is(warehouseCode);
// }
// if (ObjectUtil.isNotEmpty(brand)) {
// c.and("barcode.subCodeList.provider").is(brand);
// }
// if (isOut){
// c.and("barcode.subCodeList.isOut").is(isOut);
// }
//Sort sort = getSortByCheckOutType(checkOutType);
Sort sort = Sort.by(Sort.Direction.ASC, "barcode.subCodeList.createDate","barcode.subCodeList.amount"/*,"canCheckOutTime", "barcode.usedCount"*/);
Query q = new Query(c);
q.with(sort);
StoragePos pos = storagePosDao.findOne(q);
if (pos == null) {
log.info("使用" + checkOutType + " 策略出库 partNumber=" + pn + ",库存未找到PN ");
} else {
log.info("使用" + checkOutType + " 策略出库 partNumber=" + pn + ",找到PN【" + pos.getPosName() + "】 ");
}
return pos;
}
@Override
public StoragePos findEmptyBoxToPutIn(List<String> storageIdList, String pn, Collection<String> excludePosIds, CHECKOUT_TYPE checkOutType ) {
Criteria c = Criteria.where("id").nin(excludePosIds);
c = c.and("enabled").is(true);//可用
c.and("used").is(true);
c.and("barcode").exists(true);//已使用有料箱
c.and("barcode.status").is(BARCODE_STATUS.IN_STORE);
if (storageIdList != null) {
c = c.and("storageId").in(storageIdList);
}
if (ObjectUtil.isNotEmpty(pn)) {
c.and("barcode.subCodeList.partNumber").is(pn);
}
Sort sort = Sort.by(Sort.Direction.ASC, "barcode.subCodeList.createDate", "barcode.subCodeList.amount"/*,"canCheckOutTime", "barcode.usedCount"*/);
Query q = new Query(c);
q.with(sort);
String proName = "subCodeList." + (6 - 1);
q.addCriteria(Criteria.where(proName).exists(false));
StoragePos pos = storagePosDao.findOne(q);
if (pos == null) {
log.info("使用" + checkOutType + " 策略出库 partNumber=" + pn + ",库存未找到PN ");
} else {
log.info("使用" + checkOutType + " 策略出库 partNumber=" + pn + ",找到PN【" + pos.getPosName() + "】 ");
}
return pos;
}
}
......@@ -79,10 +79,12 @@ public class SpReturnInventoryController {
if (returnInventoryNo == null) {
return ResultBean.newErrorResult(-1, "", "未找到对应的退库单信息");
}
String exeResult = returnNoCache.Execute(returnInventoryNo);
if(ObjectUtil.isNotEmpty(exeResult)){
return ResultBean.newErrorResult(-1, "", "执行退库单失败:"+exeResult);
}
returnInventoryNo.setSpareStatus(SpareNostatus.EXECUTING_STATUS);
returnNoCache.addToMap(returnInventoryNo);
returnNoManager.save(returnInventoryNo);
return ResultBean.newOkResult("");
}
......
......@@ -95,9 +95,13 @@ public class SpSpareNoController {
if (spareNo == null) {
return ResultBean.newErrorResult(-1, "", "未找到对应的入库单信息");
}
spareNo.setSpareStatus(SpareNostatus.EXECUTING_STATUS);
spareNoCache.addToMap(spareNo);
spareNoManager.save(spareNo);
String exeResult = spareNoCache.Execute(spareNo);
if(ObjectUtil.isNotEmpty(exeResult)){
return ResultBean.newErrorResult(-1, "", "执行退库单失败:"+exeResult);
}
// spareNo.setSpareStatus(SpareNostatus.EXECUTING_STATUS);
// spareNoCache.addToMap(spareNo);
// spareNoManager.save(spareNo);
return ResultBean.newOkResult("");
}
......
package com.neotel.smfcore.custom.luxsan_sp.util;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.core.barcode.enums.BARCODE_STATUS;
import com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.enums.OP;
import com.neotel.smfcore.core.device.enums.OP_STATUS;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.custom.luxsan_sp.api.bean.result.GetReturnInventoryResult;
import com.neotel.smfcore.custom.luxsan_sp.bean.ReturnInventoryNo;
import com.neotel.smfcore.custom.luxsan_sp.bean.SpareNo;
import com.neotel.smfcore.custom.luxsan_sp.bean.SpareNoDetail;
import com.neotel.smfcore.custom.luxsan_sp.enums.SpareNostatus;
import com.neotel.smfcore.custom.luxsan_sp.service.manager.IReturnNoManager;
import com.neotel.smfcore.custom.luxsan_sp.service.manager.IUnclaimedManager;
import lombok.extern.slf4j.Slf4j;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Slf4j
public class ReturnNoCache {
public ReturnNoCache(ApplicationContext applicationContext) {
......@@ -31,18 +41,18 @@ public class ReturnNoCache {
@Autowired
private IReturnNoManager returnNoManager;
Map<String, ReturnInventoryNo> cacheMap = new ConcurrentHashMap<>();
Map<String, ReturnInventoryNo> cacheMap = new ConcurrentHashMap<>();
public void addToMap(ReturnInventoryNo returnInventoryNo){
public void addToMap(ReturnInventoryNo returnInventoryNo) {
cacheMap.put(returnInventoryNo.getOrderNo(), returnInventoryNo);
}
public ReturnInventoryNo getByOrderNo(String orderNo) {
ReturnInventoryNo returnInventoryNo = cacheMap.get(orderNo);
if (returnInventoryNo == null){
if (returnInventoryNo == null) {
returnInventoryNo = returnNoManager.getByOrderNo(orderNo);
if (returnInventoryNo != null){
if (returnInventoryNo != null) {
cacheMap.put(returnInventoryNo.getOrderNo(), returnInventoryNo);
}
}
......@@ -50,7 +60,7 @@ public class ReturnNoCache {
}
public String getExecutingOrderNoStr(){
public String getExecutingOrderNoStr() {
for (ReturnInventoryNo returnInventoryNo : cacheMap.values()) {
if (ObjectUtil.isNotNull(returnInventoryNo) && returnInventoryNo.isExecuting()) {
return returnInventoryNo.getOrderNo();
......@@ -59,7 +69,7 @@ public class ReturnNoCache {
return null;
}
public ReturnInventoryNo getExecutingOrderNo(){
public ReturnInventoryNo getExecutingOrderNo() {
for (ReturnInventoryNo returnInventoryNo : cacheMap.values()) {
if (ObjectUtil.isNotNull(returnInventoryNo) && returnInventoryNo.isExecuting()) {
return returnInventoryNo;
......@@ -89,4 +99,143 @@ public class ReturnNoCache {
cacheMap.put(orderNo, returnInventoryNo);
returnNoManager.save(returnInventoryNo);
}
@Autowired
private IStoragePosManager storagePosManager;
@Autowired
private IBarcodeManager barcodeManager;
@Autowired
private DataCache dataCache;
@Autowired
private TaskService taskService;
/**
*
*/
public synchronized String Execute(ReturnInventoryNo returnNo) {
try {
if (returnNo.getSpareStatus().equals(SpareNostatus.EXECUTING_STATUS)) {
return "已在执行中";
}
String orderNo=returnNo.getOrderNo();
log.info("开始执行ReturnInventoryNo[" +orderNo + "] ");
List<StoragePos> needOutPos = new ArrayList<>();
List<String> storageIdList = new ArrayList<>();
for (Storage storage : dataCache.getAllStorage().values()) {
storageIdList.add(storage.getId());
}
for (SpareNoDetail detail : returnNo.getDetailList()) {
String pn = detail.getPartno();
Collection<String> excludePosIds = taskService.excludePosIds();
//根据pn查找
StoragePos pos = storagePosManager.findBoxPNInStorages(storageIdList, pn, excludePosIds, dataCache.getCheckOutType());
if (pos != null) {
Barcode boxBarcode = pos.getBarcode();
for (Barcode subBarcode :
boxBarcode.getSubCodeList()) {
if (subBarcode.getPartNumber().equals(pn)) {
subBarcode.setOut(false);
subBarcode.updateExtraData("needInNum", detail.getInQty() + "");
log.info("入库单" + orderNo+ ", Pn=" + pn + ",查找到库位号=" + pos.getPosName() + ",料箱号=" + boxBarcode.getBarcode() + ",格口号=" + subBarcode.getBarcode() + ",需要入库数量=" + detail.getInQty());
}
}
boxBarcode.setOut(false);
boxBarcode.setStatus(BARCODE_STATUS.IN_STORE);
needOutPos.add(pos);
} else {
Barcode newPn = new Barcode();
newPn.setPn(pn);
newPn.setAmount(0);
newPn.setInitialAmount(0);
newPn.setOut(false);
newPn.updateExtraData("needInNum", detail.getInQty() + "");
//查找准备出库的料箱中是否有空格口
StoragePos emptyPos = needOutPos.stream()
.filter(emptyP -> (emptyP.getBarcode().getSubCodeList().size() < 6))
.findFirst()
.orElse(null);
Barcode emptyBox = null;
if (emptyPos != null) {
//使用此格口
emptyBox = emptyPos.getBarcode();
newPn.setBarcode(emptyBox.getBarcode() + "-" + emptyBox.getSubCodeList().size());
newPn = barcodeManager.saveBarcode(newPn);
List<Barcode> subL = emptyBox.getSubCodeList();
subL.add(newPn);
emptyBox.setSubCodeList(subL);
log.info("入库单" + orderNo + ", Pn=" + pn + ",使用料箱的空格口=" + pos.getPosName() + ",料箱号=" + emptyBox.getBarcode() + ",格口号=" + newPn.getBarcode() + ",需要入库数量=" + detail.getInQty());
} else {
//寻找一个空格口
excludePosIds = taskService.excludePosIds();
emptyPos = storagePosManager.findEmptyBoxToPutIn(storageIdList, pn, excludePosIds, dataCache.getCheckOutType());
emptyBox = emptyPos.getBarcode();
if (pos != null) {
newPn.setBarcode(emptyBox.getBarcode() + "-" + emptyBox.getSubCodeList().size());
newPn = barcodeManager.saveBarcode(newPn);
List<Barcode> subL = emptyBox.getSubCodeList();
subL.add(newPn);
emptyBox.setSubCodeList(subL);
emptyBox.setOut(false);
emptyBox.setStatus(BARCODE_STATUS.IN_STORE);
needOutPos.add(pos);
log.info("入库单" + orderNo + ", Pn=" + pn + ",查找到有空格口料箱=" + pos.getPosName() + ",料箱号=" + emptyBox.getBarcode() + ",格口号=" + newPn.getBarcode() + ",需要入库数量=" + detail.getInQty());
} else {
log.info("入库单" + orderNo + ", Pn=" + pn + ",未找到可用的空料箱=");
}
}
}
}
//开始生成出库任务
int index = 1;
for (StoragePos pos : needOutPos
) {
Barcode barcode = pos.getBarcode();
log.info("入库单" + orderNo + ", 为库位=" + pos.getPosName() + ",料箱=" + barcode.getBarcode() + "生成出库任务:" + index);
barcodeManager.saveBarcode(barcode);
storagePosManager.save(pos);
Storage storage = dataCache.getStorageById(pos.getStorageId());
log.info(pos.getPosName() + "出库,料箱号为:" + barcode.getBarcode());
DataLog task = new DataLog(storage, barcode, pos);
task.setSourceId(returnNo.getId());
task.setSourceName(orderNo);
task.setSubSourceId(barcode.getLockName());
task.setSubSourceInfo(barcode.getLockName());
task.setLoc("s1");
task.setType(OP.CHECKOUT);
task.setCreator(SecurityUtils.getCurrentUsername());
task.setStatus(OP_STATUS.WAIT.name());
try {
taskService.addTaskToExecute(task);
} catch (Exception e) {
e.getMessage();
}
index++;
}
returnNo.setSpareStatus(SpareNostatus.EXECUTING_STATUS);
addToMap(returnNo);
returnNoManager.save(returnNo);
} catch (Exception exception) {
log.error("执行ReturnInventoryNo 出错: " + exception.toString());
}
return "";
}
}
package com.neotel.smfcore.custom.luxsan_sp.util;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.core.barcode.enums.BARCODE_STATUS;
import com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.enums.OP;
import com.neotel.smfcore.core.device.enums.OP_STATUS;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.custom.luxsan_sp.api.bean.result.GetSpareNoDetail;
import com.neotel.smfcore.custom.luxsan_sp.api.bean.result.GetSpareNoResult;
import com.neotel.smfcore.custom.luxsan_sp.bean.SpareNo;
import com.neotel.smfcore.custom.luxsan_sp.bean.SpareNoDetail;
import com.neotel.smfcore.custom.luxsan_sp.enums.SpareNostatus;
import com.neotel.smfcore.custom.luxsan_sp.service.manager.IReturnNoManager;
import com.neotel.smfcore.custom.luxsan_sp.service.manager.ISpareNoManager;
import lombok.extern.slf4j.Slf4j;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Slf4j
public class SpareNoCache {
public SpareNoCache(ApplicationContext applicationContext) {
......@@ -103,4 +114,144 @@ public class SpareNoCache {
spareNoManager.save(spareNo);
}
@Autowired
private IStoragePosManager storagePosManager;
@Autowired
private IBarcodeManager barcodeManager;
@Autowired
private DataCache dataCache;
@Autowired
private TaskService taskService;
/**
*
*/
public synchronized String Execute(SpareNo spareNo) {
try {
if (spareNo.getSpareStatus().equals(SpareNostatus.EXECUTING_STATUS)) {
return "已在执行中";
}
String orderNo=spareNo.getSpareNo();
log.info("开始执行ReturnInventoryNo[" +orderNo + "] ");
List<StoragePos> needOutPos = new ArrayList<>();
List<String> storageIdList = new ArrayList<>();
for (Storage storage : dataCache.getAllStorage().values()) {
storageIdList.add(storage.getId());
}
for (SpareNoDetail detail : spareNo.getDetailList()) {
String pn = detail.getPartno();
Collection<String> excludePosIds = taskService.excludePosIds();
//根据pn查找
StoragePos pos = storagePosManager.findBoxPNInStorages(storageIdList, pn, excludePosIds, dataCache.getCheckOutType());
if (pos != null) {
Barcode boxBarcode = pos.getBarcode();
for (Barcode subBarcode :
boxBarcode.getSubCodeList()) {
if (subBarcode.getPartNumber().equals(pn)) {
subBarcode.setOut(false);
subBarcode.updateExtraData("needInNum", detail.getInQty() + "");
log.info("入库单" + orderNo+ ", Pn=" + pn + ",查找到库位号=" + pos.getPosName() + ",料箱号=" + boxBarcode.getBarcode() + ",格口号=" + subBarcode.getBarcode() + ",需要入库数量=" + detail.getInQty());
}
}
boxBarcode.setOut(false);
boxBarcode.setStatus(BARCODE_STATUS.IN_STORE);
needOutPos.add(pos);
} else {
Barcode newPn = new Barcode();
newPn.setPn(pn);
newPn.setAmount(0);
newPn.setInitialAmount(0);
newPn.setOut(false);
newPn.updateExtraData("needInNum", detail.getInQty() + "");
//查找准备出库的料箱中是否有空格口
StoragePos emptyPos = needOutPos.stream()
.filter(emptyP -> (emptyP.getBarcode().getSubCodeList().size() < 6))
.findFirst()
.orElse(null);
Barcode emptyBox = null;
if (emptyPos != null) {
//使用此格口
emptyBox = emptyPos.getBarcode();
newPn.setBarcode(emptyBox.getBarcode() + "-" + emptyBox.getSubCodeList().size());
newPn = barcodeManager.saveBarcode(newPn);
List<Barcode> subL = emptyBox.getSubCodeList();
subL.add(newPn);
emptyBox.setSubCodeList(subL);
log.info("入库单" + orderNo + ", Pn=" + pn + ",使用料箱的空格口=" + pos.getPosName() + ",料箱号=" + emptyBox.getBarcode() + ",格口号=" + newPn.getBarcode() + ",需要入库数量=" + detail.getInQty());
} else {
excludePosIds = taskService.excludePosIds();
//寻找一个空格口
emptyPos = storagePosManager.findEmptyBoxToPutIn(storageIdList, pn, excludePosIds, dataCache.getCheckOutType());
emptyBox = emptyPos.getBarcode();
if (pos != null) {
newPn.setBarcode(emptyBox.getBarcode() + "-" + emptyBox.getSubCodeList().size());
newPn = barcodeManager.saveBarcode(newPn);
List<Barcode> subL = emptyBox.getSubCodeList();
subL.add(newPn);
emptyBox.setSubCodeList(subL);
emptyBox.setOut(false);
emptyBox.setStatus(BARCODE_STATUS.IN_STORE);
needOutPos.add(pos);
log.info("入库单" + orderNo + ", Pn=" + pn + ",查找到有空格口料箱=" + pos.getPosName() + ",料箱号=" + emptyBox.getBarcode() + ",格口号=" + newPn.getBarcode() + ",需要入库数量=" + detail.getInQty());
} else {
log.info("入库单" + orderNo + ", Pn=" + pn + ",未找到可用的空料箱=");
}
}
}
}
//开始生成出库任务
int index = 1;
for (StoragePos pos : needOutPos
) {
Barcode barcode = pos.getBarcode();
log.info("入库单" + orderNo + ", 为库位=" + pos.getPosName() + ",料箱=" + barcode.getBarcode() + "生成出库任务:" + index);
barcodeManager.saveBarcode(barcode);
storagePosManager.save(pos);
Storage storage = dataCache.getStorageById(pos.getStorageId());
log.info(pos.getPosName() + "出库,料箱号为:" + barcode.getBarcode());
DataLog task = new DataLog(storage, barcode, pos);
task.setSourceId(spareNo.getId());
task.setSourceName(orderNo);
task.setSubSourceId(barcode.getLockName());
task.setSubSourceInfo(barcode.getLockName());
task.setType(OP.CHECKOUT);
task.setCreator(SecurityUtils.getCurrentUsername());
task.setLoc("s1");
task.setStatus(OP_STATUS.WAIT.name());
try {
taskService.addTaskToExecute(task);
} catch (Exception e) {
e.getMessage();
}
index++;
}
spareNo.setSpareStatus(SpareNostatus.EXECUTING_STATUS);
addToMap(spareNo);
spareNoManager.save(spareNo);
} catch (Exception exception) {
log.error("执行ReturnInventoryNo 出错: " + exception.toString());
}
return "";
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!