Commit cb7b73c3 LN

增加锁定物料代码

1 个父辈 90744313
package com.neotel.smfcore.common.bean;
import lombok.Data;
@Data
public class ReelLockPosInfo {
/**
* 条码信息
*/
private String barcode;
/**
* 料仓cid
*/
private String cid;
/**
* 锁定的库位
*/
private String lockPosName;
/**
* 锁定的库位Id
*/
private String lockPosId;
}
package com.neotel.smfcore.common.utils;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.common.bean.ReelLockPosInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.*;
@Component
public class ReelLockPosUtil {
@Autowired
private DataCache autodataCache;
private static DataCache dataCache;
protected static Logger log = LogManager.getLogger(ReelLockPosUtil.class);
/**
* 料盘锁定库位信息,用于包装料分配到其他料仓
*/
private static String REEL_LOCK_POS_MAP_KEY = "reelLocKPosMap";
/**
* 料盘锁定库位信息,用于包装料分配到其他料仓
*/
private static Map<String, ReelLockPosInfo> reelLocKPosMap;
@PostConstruct
public void init() {
dataCache = autodataCache;
reelLocKPosMap=dataCache.getCache(REEL_LOCK_POS_MAP_KEY);
if(reelLocKPosMap==null){
reelLocKPosMap=new HashMap<String,ReelLockPosInfo>(){};
}
}
/**
* 添加条码锁定库位信息
*
* @param reelLockPosInfo
*/
public static synchronized ReelLockPosInfo addReelLockPosInfo(ReelLockPosInfo reelLockPosInfo) {
log.info("为[" + reelLockPosInfo.getBarcode() + "]锁定库位[" + reelLockPosInfo.getLockPosName() + "]");
ReelLockPosInfo oldLocInfo = reelLocKPosMap.get(reelLockPosInfo.getBarcode());
if (oldLocInfo != null && oldLocInfo.getLockPosName() != null) {
log.info("[" + oldLocInfo.getBarcode() + "]已有锁定库位[" + oldLocInfo.getLockPosName() + "],返回之前锁定的库位");
return oldLocInfo;
}
for (ReelLockPosInfo locInfo : reelLocKPosMap.values()) {
if (locInfo.getLockPosId().equals(reelLockPosInfo.getLockPosId()) && !locInfo.getBarcode().equals(reelLockPosInfo.getBarcode())) {
log.info("为[" + reelLockPosInfo.getBarcode() + "]锁定库位[" + reelLockPosInfo.getLockPosName() + "]时,库位已被[" + locInfo.getBarcode() + "]锁定");
return null;
}
}
reelLocKPosMap.put(reelLockPosInfo.getBarcode(), reelLockPosInfo);
dataCache.updateCache(REEL_LOCK_POS_MAP_KEY, reelLocKPosMap);
return reelLockPosInfo;
}
public static ReelLockPosInfo getLockPosInfoByCode(String barcode) {
if (org.apache.logging.log4j.util.Strings.isNotBlank(barcode)) {
for (ReelLockPosInfo reelLockPosInfo : reelLocKPosMap.values()) {
String lockBarcode = reelLockPosInfo.getBarcode();
if (org.apache.logging.log4j.util.Strings.isNotBlank(lockBarcode)) {
if (lockBarcode.equals(barcode)) {
return reelLockPosInfo;
}
}
}
}
return null;
}
/**
* 清理条码锁定库位信息
*/
public static void removeReelLockPosInfo(String barcode) {
reelLocKPosMap.remove(barcode);
dataCache.updateCache(REEL_LOCK_POS_MAP_KEY, reelLocKPosMap);
}
/**
* 获取条码锁定的库位Id
*
* @param barcode 条码信息
* @return
*/
public static String getReelLockPosId(String barcode) {
ReelLockPosInfo lockPosInfo = reelLocKPosMap.get(barcode);
if (lockPosInfo != null) {
return lockPosInfo.getLockPosId();
}
return "";
}
/**
* 获取所有锁定的库位Id列表
*/
public static Set<String> getAllLockPosIds() {
Set<String> lockPosIds = new HashSet<>();
for (ReelLockPosInfo reelLockPosInfo : reelLocKPosMap.values()) {
lockPosIds.add(reelLockPosInfo.getLockPosId());
}
return lockPosIds;
}
}
......@@ -4,6 +4,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.ReelLockPosUtil;
import com.neotel.smfcore.common.utils.StorageConstants;
import com.neotel.smfcore.core.barcode.bean.CodeBean;
import com.neotel.smfcore.core.barcode.enums.COMPONENT_TYPE;
......@@ -188,8 +189,14 @@ public class BaseDeviceHandler implements IDeviceHandler {
}
} else {
//String codeBoxId = statusBean.getCodeBoxId();
storagePos = findLineEmptyPosForPutIn(storage, barcodeSave);
String lockPosId = ReelLockPosUtil.getReelLockPosId(barcodeSave.getBarcode());
if(!Strings.isNullOrEmpty(lockPosId)){
//已经有锁定的库位
storagePos = storagePosManager.get(lockPosId);
log.info(barcodeSave.getBarcode() + "入库时查找到锁定的库位["+storagePos.getPosName()+"]");
}else{
storagePos = findLineEmptyPosForPutIn(storage, barcodeSave);
}
}
......@@ -203,6 +210,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
}
}
ReelLockPosUtil.removeReelLockPosInfo(barcodeSave.getBarcode());
return taskService.addPutInTaskToExecute(storage, barcodeSave, storagePos);
}
}
......@@ -467,6 +475,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
updatePosExecuteTime(posName,executeTime);
}
log.info(task.getBarcode() + "入仓位[" + task.getPosName() + "]完成,执行时间["+executeTime+"]秒");
ReelLockPosUtil.removeReelLockPosInfo(task.getBarcode());
DataLog cancelTask = taskService.findFinishedTask(cid, posName);
if (cancelTask != null && cancelTask.isCancel()) {
//将相同库位已经取消的任务从完成队列里删除
......
......@@ -4,7 +4,9 @@ package com.neotel.smfcore.core.device.rest;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.neotel.smfcore.common.bean.ReelLockPosInfo;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.ReelLockPosUtil;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.barcode.utils.CodeResolve;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
......@@ -107,9 +109,6 @@ public class DeviceController {
String lastPosId=request.getParameter("lastPosId");
lineMsg = "";
// if(Strings.isNullOrEmpty(cids)){
// cids = "line-ac-11,line-ac-12";
// }
log.info("流水线["+cids+"]获取["+rfid+"]["+code+"]的入库库位");
Map<String,Object> resultMap = Maps.newHashMap();
......@@ -216,44 +215,42 @@ public class DeviceController {
okMsg = "["+rfid+"]["+barcode.getBarcode()+"]锁定库位["+pos.getPosName()+"]";
// ReelLockPosInfo oldLockInfo = QisdaCache.getLockPosInfoByRfidLoc(rfid, rfidLoc);
// if(oldLockInfo != null){
// if(!oldLockInfo.getBarcode().equals(barcode.getBarcode())){
// String result = "-1";
// okMsg = rfid+"["+ rfidLoc +"]["+barcode.getBarcode()+"]锁定库位["+pos.getPosName()+"],清理旧有锁定信息";
// resultMap.put("result",result);
// resultMap.put("msg",okMsg);
// //已经锁定过库位,但不是同一个条码,需要把对应位置的锁定信息清理掉
// //QisdaCache.removeReelLockPosInfo(barcode.getBarcode());
// List<ReelLockPosInfo> lockPosInfoList = QisdaCache.getShelfLockPosInfo(rfid);
// for (ReelLockPosInfo reelLockPosInfo : lockPosInfoList) {
// QisdaCache.removeReelLockPosInfo(reelLockPosInfo.getBarcode());
// log.info("清理料架"+reelLockPosInfo.getRfid()+"["+reelLockPosInfo.getRfidLoc()+"]上物料["+reelLockPosInfo.getBarcode()+"]锁定的库位");
// }
// }
// }
//log.info(okMsg + oldLockInfo);
// ReelLockPosInfo reelLocInfo = new ReelLockPosInfo();
// reelLocInfo.setBarcode(barcode.getBarcode());
// reelLocInfo.setCid(theStorage.getCid());
// reelLocInfo.setLockPosName(pos.getPosName());
// reelLocInfo.setLockPosId(pos.getId());
// reelLocInfo.setRfid(rfid);
// reelLocInfo.setRfidLoc(rfidLoc);
// reelLocInfo = QisdaCache.addReelLockPosInfo(reelLocInfo);
// if(reelLocInfo == null){
// errorMsg = "库位已被锁定,暂停入库";
// lineMsg = errorMsg;
// resultMap.put("result","99");
// resultMap.put("msg",errorMsg);
// return resultMap;
// }else{
ReelLockPosInfo oldLockInfo = ReelLockPosUtil.getLockPosInfoByCode(barcode.getBarcode());
if(oldLockInfo != null){
if(!oldLockInfo.getBarcode().equals(barcode.getBarcode())){
String result = "-1";
okMsg = rfid+"["+ rfidLoc +"]["+barcode.getBarcode()+"]锁定库位["+pos.getPosName()+"],清理旧有锁定信息";
resultMap.put("result",result);
resultMap.put("msg",okMsg);
//已经锁定过库位,但不是同一个条码,需要把对应位置的锁定信息清理掉
ReelLockPosUtil.removeReelLockPosInfo(oldLockInfo.getBarcode());
log.info("清理锁定库位:库位号["+oldLockInfo.getLockPosName()+"]上物料["+oldLockInfo.getBarcode()+"]锁定的库位");
}
}
log.info(okMsg + oldLockInfo);
ReelLockPosInfo reelLocInfo = new ReelLockPosInfo();
reelLocInfo.setBarcode(barcode.getBarcode());
reelLocInfo.setCid(theStorage.getCid());
reelLocInfo.setLockPosName(pos.getPosName());
reelLocInfo.setLockPosId(pos.getId());
reelLocInfo = ReelLockPosUtil.addReelLockPosInfo(reelLocInfo);
if(reelLocInfo == null){
errorMsg = "库位已被锁定,暂停入库";
lineMsg = errorMsg;
resultMap.put("result","99");
resultMap.put("msg",errorMsg);
return resultMap;
}else{
resultMap.put("pos",pos.getPosName());
resultMap.put("barcode",barcode.getBarcode());
resultMap.put("cid",theStorage.getCid());
// }
}
}else{
resultMap.put("result","104");
......
......@@ -4,6 +4,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.ReelLockPosUtil;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.common.utils.StorageConstants;
import com.neotel.smfcore.core.barcode.enums.COMPONENT_TYPE;
......@@ -399,7 +400,7 @@ public class TaskService {
public Collection<String> excludePosIds() {
//排除掉正在执行的仓位
Collection<DataLog> allTasks = taskMap.values();
Collection<String> operatingPosIds = new HashSet<>();
Collection<String> operatingPosIds = ReelLockPosUtil.getAllLockPosIds();
for (DataLog task : allTasks) {
String posId = task.getPosId();
if (!Strings.isNullOrEmpty(posId)) {
......@@ -557,31 +558,31 @@ public class TaskService {
}
// String lockPosId = QisdaCache.getReelLockPosId(barcode.getBarcode());
// StoragePos pos = null;
// if(!Strings.isNullOrEmpty(lockPosId)){
// //已有锁定库位
// pos = storagePosManager.get(lockPosId);
//
// if(pos != null ){
// if(pos.getW() < barcode.getPlateSize() || pos.getH() < barcode.getHeight()){
// log.info("条码["+barcode.getBarcode()+"]尺寸已改变,无法放入已锁定库位["+pos.getPosName()+"],重新查找库位");
// pos = null;
// }else{
// Barcode posBarcode = pos.getBarcode();
// if(posBarcode == null){
// log.info("条码["+barcode.getBarcode()+"]已锁定库位["+pos.getPosName()+"],返回锁定中的库位");
// }else{
// log.info("条码["+barcode.getBarcode()+"]已锁定库位["+pos.getPosName()+"]中已有物料["+posBarcode.getBarcode()+"],重新查找库位");
// pos = null;
// }
// }
// }
// }
String lockPosId = ReelLockPosUtil.getReelLockPosId(barcode.getBarcode());
StoragePos pos = null;
if(!Strings.isNullOrEmpty(lockPosId)){
//已有锁定库位
pos = storagePosManager.get(lockPosId);
if(pos != null ){
if(pos.getW() < barcode.getPlateSize() || pos.getH() < barcode.getHeight()){
log.info("条码["+barcode.getBarcode()+"]尺寸已改变,无法放入已锁定库位["+pos.getPosName()+"],重新查找库位");
pos = null;
}else{
Barcode posBarcode = pos.getBarcode();
if(posBarcode == null){
log.info("条码["+barcode.getBarcode()+"]已锁定库位["+pos.getPosName()+"],返回锁定中的库位");
}else{
log.info("条码["+barcode.getBarcode()+"]已锁定库位["+pos.getPosName()+"]中已有物料["+posBarcode.getBarcode()+"],重新查找库位");
pos = null;
}
}
}
}
// if(pos != null){
// return pos;
// }
if(pos != null){
return pos;
}
//可用的料仓(在线,且可以放入)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!