Commit dae3e29e hc

fix:代码优化

1 个父辈 a86ccf55
...@@ -62,213 +62,203 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager { ...@@ -62,213 +62,203 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public synchronized Map<String, String> reelToBox(Map<String, String> paramMap) throws Exception { public synchronized Map<String, String> reelToBox(Map<String, String> paramMap) throws Exception {
try { String boxStr = paramMap.get("boxStr").trim();
String boxStr = paramMap.get("boxStr").trim(); String rellCodeStr = paramMap.get("codeStr").trim();
String rellCodeStr = paramMap.get("codeStr").trim(); String gekouCodeStr = paramMap.get("binCodeStr").trim();
String gekouCodeStr = paramMap.get("binCodeStr").trim(); log.info("reelToBox : boxStr=" + boxStr + ",codeStr=" + rellCodeStr + ",binCodeStr=" + gekouCodeStr);
log.info("reelToBox : boxStr=" + boxStr + ",codeStr=" + rellCodeStr + ",binCodeStr=" + gekouCodeStr);
// boxStr = "C0700377A"; // boxStr = "C0700377A";
// codeStr = "1950090020044V&&2"; // codeStr = "1950090020044V&&2";
// binCodeStr = "C0700377-01"; // binCodeStr = "C0700377-01";
//解析料箱信息 //解析料箱信息
Barcode boxBarcode = codeResolve.resolveOneValideBarcode("=2x2=" + boxStr); Barcode boxBarcode = codeResolve.resolveOneValideBarcode("=2x2=" + boxStr);
if (boxBarcode == null) { if (boxBarcode == null) {
throw new Exception("不是有效的料箱条码"); throw new Exception("不是有效的料箱条码");
} }
addBackupObj(boxBarcode);
//解析料格信息 //解析料格信息
Barcode gekouBarcode = codeResolve.resolveOneValideBarcode("=2x2=" + gekouCodeStr); Barcode gekouBarcode = codeResolve.resolveOneValideBarcode("=2x2=" + gekouCodeStr);
if (gekouBarcode == null) { if (gekouBarcode == null) {
throw new Exception("不是有效的料格条码"); throw new Exception("不是有效的料格条码");
} }
addBackupObj(gekouBarcode);
//2.解析条码信息 //2.解析条码信息
CodeBarcode codeBarcode = CodeUtil.getCodeBarcode(rellCodeStr); CodeBarcode codeBarcode = CodeUtil.getCodeBarcode(rellCodeStr);
if (codeBarcode == null) { if (codeBarcode == null) {
throw new Exception("不是有效的物料条码"); throw new Exception("不是有效的物料条码");
} }
//1.判断料格信息与料箱信息是否匹配 //1.判断料格信息与料箱信息是否匹配
if (!gekouBarcode.getBarcode().startsWith(boxBarcode.getBarcode())) { if (!gekouBarcode.getBarcode().startsWith(boxBarcode.getBarcode())) {
throw new Exception(gekouCodeStr + "不是当前料箱:" + boxStr + "的格口"); throw new Exception(gekouCodeStr + "不是当前料箱:" + boxStr + "的格口");
} }
int binCodeNum = Integer.parseInt(gekouCodeStr.split("-")[1]); int binCodeNum = Integer.parseInt(gekouCodeStr.split("-")[1]);
//判断格口数量是否超出 //判断格口数量是否超出
int count = SpBoxUtil.GetBoxSubCount(boxBarcode.getBarcode()); int count = SpBoxUtil.GetBoxSubCount(boxBarcode.getBarcode());
if (binCodeNum > count) { if (binCodeNum > count) {
// throw new Exception(boxBarcode.getBarcode() + "最多格口数" + count + ",请扫描正确的格口码"); // throw new Exception(boxBarcode.getBarcode() + "最多格口数" + count + ",请扫描正确的格口码");
} }
//此格口为空 //此格口为空
if (ObjectUtil.isEmpty(gekouBarcode.getPartNumber()) || gekouBarcode.getPartNumber().equals(boxBarcode.getPartNumber())) { if (ObjectUtil.isEmpty(gekouBarcode.getPartNumber()) || gekouBarcode.getPartNumber().equals(boxBarcode.getPartNumber())) {
// 判断物料是否在其他格口
String currP= barcodeManager.getPNCurrGeKou( codeBarcode.getPartNumber());
if (ObjectUtil.isNotEmpty(currP)&&(!currP.equals(gekouCodeStr))) {
throw new Exception(codeBarcode.getPartNumber() + "已在"+currP+"中");
}
//是新格口物料
gekouBarcode.setPartNumber(codeBarcode.getPartNumber());
gekouBarcode.setAmount(0);
gekouBarcode.setOut(false);
} else if (gekouBarcode.getPartNumber().equals(codeBarcode.getPartNumber())) {
//pn已在此格口 // 判断物料是否在其他格口
} else { String currP= barcodeManager.getPNCurrGeKou( codeBarcode.getPartNumber());
//不匹配,直接返回 if (ObjectUtil.isNotEmpty(currP)&&(!currP.equals(gekouCodeStr))) {
throw new Exception(rellCodeStr + "的料号与隔口:" + gekouCodeStr + "的料号[" + gekouBarcode.getPartNumber() + "]不匹配"); throw new Exception(codeBarcode.getPartNumber() + "已在"+currP+"中");
} }
//判断有没有正在执行入库单 //是新格口物料
SpareNo spareNo = spareNoCache.getExecutIngSpareNo(); gekouBarcode.setPartNumber(codeBarcode.getPartNumber());
ReturnInventoryNo returnInventoryNo = returnNoCache.getExecutingOrderNo(); gekouBarcode.setAmount(0);
BaseNo baseNo = null; gekouBarcode.setOut(false);
boolean isOrderPutIn = false; } else if (gekouBarcode.getPartNumber().equals(codeBarcode.getPartNumber())) {
if (ObjectUtil.isAllEmpty(spareNo, returnInventoryNo)) {
//pn已在此格口
} else {
//不匹配,直接返回
throw new Exception(rellCodeStr + "的料号与隔口:" + gekouCodeStr + "的料号[" + gekouBarcode.getPartNumber() + "]不匹配");
}
//判断有没有正在执行入库单
SpareNo spareNo = spareNoCache.getExecutIngSpareNo();
ReturnInventoryNo returnInventoryNo = returnNoCache.getExecutingOrderNo();
BaseNo baseNo = null;
boolean isOrderPutIn = false;
if (ObjectUtil.isAllEmpty(spareNo, returnInventoryNo)) {
// return ResultBean.newErrorResult(-1,"","没有找到正在执行的入库单或者退库单"); // return ResultBean.newErrorResult(-1,"","没有找到正在执行的入库单或者退库单");
} else { } else {
baseNo = ObjectUtil.isEmpty(spareNo) ? returnInventoryNo : spareNo; baseNo = ObjectUtil.isEmpty(spareNo) ? returnInventoryNo : spareNo;
addBackupObj(baseNo);
//判断此料箱有没有待执行的出入库任务
//判断此料箱有没有待执行的出入库任务 List<String> needInPn = new ArrayList<>();
List<String> needInPn = new ArrayList<>(); for (Barcode barcode :
for (Barcode barcode : boxBarcode.getSubCodeList()) {
boxBarcode.getSubCodeList()) { String inNum = barcode.getExtraData("needInNum");
String inNum = barcode.getExtraData("needInNum"); if (ObjectUtil.isEmpty(inNum) || inNum.equals("0")) {
if (ObjectUtil.isEmpty(inNum) || inNum.equals("0")) { continue;
continue; } else {
} else { needInPn.add(barcode.getPartNumber());
needInPn.add(barcode.getPartNumber()); isOrderPutIn = true;
isOrderPutIn = true;
}
}
if (needInPn.size() > 0 && (!needInPn.contains(codeBarcode.getPartNumber()))) {
throw new Exception("有未完成的入库单任务,请先入入库单物料");
} }
} }
if (needInPn.size() > 0 && (!needInPn.contains(codeBarcode.getPartNumber()))) {
throw new Exception("有未完成的入库单任务,请先入入库单物料");
}
}
boolean finish = true; boolean finish = true;
//判断当前入库的是否和入库单一样 //判断当前入库的是否和入库单一样
if (isOrderPutIn) { if (isOrderPutIn) {
List<SpareNoDetail> detailList = baseNo.getDetailList(); List<SpareNoDetail> detailList = baseNo.getDetailList();
SpareNoDetail spareNoDetail = null; SpareNoDetail spareNoDetail = null;
for (SpareNoDetail detail : detailList) { for (SpareNoDetail detail : detailList) {
//如果相同的话,判断数量是否大于需求数量 //如果相同的话,判断数量是否大于需求数量
if (detail.getPartno().equals(codeBarcode.getPartNumber())) { if (detail.getPartno().equals(codeBarcode.getPartNumber())) {
if (detail.getAlrInQty() + codeBarcode.getQty() <= detail.getInQty()) { if (detail.getAlrInQty() + codeBarcode.getQty() <= detail.getInQty()) {
spareNoDetail = detail; spareNoDetail = detail;
break; break;
}
} }
} }
}
if (spareNoDetail == null) { if (spareNoDetail == null) {
throw new Exception(codeBarcode.getPartNumber() + "没有入退库需求,请检查是否存在或者不符合入退库数量"); throw new Exception(codeBarcode.getPartNumber() + "没有入退库需求,请检查是否存在或者不符合入退库数量");
} }
//数量加 //数量加
spareNoDetail.setAlrInQty(spareNoDetail.getAlrInQty() + codeBarcode.getQty()); spareNoDetail.setAlrInQty(spareNoDetail.getAlrInQty() + codeBarcode.getQty());
baseNo.updateDetailList(spareNoDetail); baseNo.updateDetailList(spareNoDetail);
log.info("开始判断是否完成入库单"); log.info("开始判断是否完成入库单");
for (SpareNoDetail noDetail : baseNo.getDetailList()) { for (SpareNoDetail noDetail : baseNo.getDetailList()) {
if (noDetail.getInQty() > noDetail.getAlrInQty()) { if (noDetail.getInQty() > noDetail.getAlrInQty()) {
log.info("入库未完成"); log.info("入库未完成");
finish = false; finish = false;
break; break;
}
log.info("入料noDetail.getInQty()" + noDetail.getInQty() + "noDetail.getAlrInQty()" + noDetail.getAlrInQty());
} }
log.info("入料noDetail.getInQty()" + noDetail.getInQty() + "noDetail.getAlrInQty()" + noDetail.getAlrInQty());
}
} }
// 寻找空库位 // 寻找空库位
StoragePos pos = SpBoxUtil.locOnePos(boxBarcode); StoragePos pos = SpBoxUtil.locOnePos(boxBarcode);
addBackupObj(pos);
// 将给pos赋值延迟到深拷贝库位对象之后 // 将给pos赋值延迟到深拷贝库位对象之后
// 开始放入料箱 // 开始放入料箱
gekouBarcode.setPartNumber(codeBarcode.getPartNumber()); gekouBarcode.setPartNumber(codeBarcode.getPartNumber());
gekouBarcode.setAmount(gekouBarcode.getAmount() + codeBarcode.getQty()); gekouBarcode.setAmount(gekouBarcode.getAmount() + codeBarcode.getQty());
boxBarcode.updateSubCodes(gekouBarcode); boxBarcode.updateSubCodes(gekouBarcode);
boxBarcode.setStatus(BARCODE_STATUS.OUT_NORMAL); boxBarcode.setStatus(BARCODE_STATUS.OUT_NORMAL);
if (pos == null){ if (pos == null){
throw new Exception(boxStr+"未找到可用的库位"); throw new Exception(boxStr+"未找到可用的库位");
} }
log.info("reelToBox 入库成功 : boxStr=" + boxStr + ",codeStr=" + rellCodeStr + ",binCodeStr=" + gekouCodeStr + ",数量:" + codeBarcode.getQty()+",当前数量:"+gekouBarcode.getAmount()); log.info("reelToBox 入库成功 : boxStr=" + boxStr + ",codeStr=" + rellCodeStr + ",binCodeStr=" + gekouCodeStr + ",数量:" + codeBarcode.getQty()+",当前数量:"+gekouBarcode.getAmount());
//6.生成入库任务 //6.生成入库任务
DataLog dataLog = new DataLog(); DataLog dataLog = new DataLog();
dataLog.setBarcode(rellCodeStr); dataLog.setBarcode(rellCodeStr);
dataLog.setPartNumber(codeBarcode.getPartNumber()); dataLog.setPartNumber(codeBarcode.getPartNumber());
dataLog.setOperator(SecurityUtils.getLoginUsername()); dataLog.setOperator(SecurityUtils.getLoginUsername());
dataLog.setStatus(OP_STATUS.FINISHED.name()); dataLog.setStatus(OP_STATUS.FINISHED.name());
dataLog.setPosName(gekouBarcode.getBarcode()); dataLog.setPosName(gekouBarcode.getBarcode());
dataLog.setNum(codeBarcode.getQty()); dataLog.setNum(codeBarcode.getQty());
dataLog.setType(OP.PUT_IN); dataLog.setType(OP.PUT_IN);
pos.setBarcode(boxBarcode); pos.setBarcode(boxBarcode);
pos.setUsed(true); pos.setUsed(true);
storagePosManager.save(pos); storagePosManager.save(pos);
barcodeManager.save(gekouBarcode); barcodeManager.save(gekouBarcode);
barcodeManager.save(boxBarcode); barcodeManager.save(boxBarcode);
Map<String,String> res=new HashMap<>(); Map<String,String> res=new HashMap<>();
res.put("PN",codeBarcode.getPartNumber()); res.put("PN",codeBarcode.getPartNumber());
res.put("InPutNum",codeBarcode.getQty()+""); res.put("InPutNum",codeBarcode.getQty()+"");
res.put("CurrNum",gekouBarcode.getAmount()+""); res.put("CurrNum",gekouBarcode.getAmount()+"");
res.put("Code",gekouBarcode.getBarcode()); res.put("Code",gekouBarcode.getBarcode());
taskService.updateFinishedTask(dataLog); taskService.updateFinishedTask(dataLog);
if (isOrderPutIn) { if (isOrderPutIn) {
if (baseNo.getClass().equals(SpareNo.class)) { if (baseNo.getClass().equals(SpareNo.class)) {
spareNoCache.addToMap(spareNo); spareNoCache.addToMap(spareNo);
spareNoManager.save(spareNo); spareNoManager.save(spareNo);
} else { } else {
returnNoCache.addToMap(returnInventoryNo); returnNoCache.addToMap(returnInventoryNo);
returnNoManager.save(returnInventoryNo); returnNoManager.save(returnInventoryNo);
}
} }
// 最后刷新不能回滚的 }
if (finish && isOrderPutIn) { // 最后刷新不能回滚的
// 调用入库接口 if (finish && isOrderPutIn) {
if (baseNo.getClass().equals(SpareNo.class)) { // 调用入库接口
dataLog.setSourceId(baseNo.getId()); if (baseNo.getClass().equals(SpareNo.class)) {
dataLog.setSourceName(((SpareNo) baseNo).getSpareNo()); dataLog.setSourceId(baseNo.getId());
List<SpareInHourseDetail> details = new ArrayList<>(); dataLog.setSourceName(((SpareNo) baseNo).getSpareNo());
for (SpareNoDetail detail : baseNo.getDetailList()) { List<SpareInHourseDetail> details = new ArrayList<>();
SpareInHourseDetail spareInHourseDetail = new SpareInHourseDetail(); for (SpareNoDetail detail : baseNo.getDetailList()) {
spareInHourseDetail.setInQty(detail.getInQty()); SpareInHourseDetail spareInHourseDetail = new SpareInHourseDetail();
spareInHourseDetail.setPartno(detail.getPartno()); spareInHourseDetail.setInQty(detail.getInQty());
String location = boxStr; spareInHourseDetail.setPartno(detail.getPartno());
String location = boxStr;
// String location = SpareNostatus.LOCATION_CODE.get(baseNo.getWhCode()); // String location = SpareNostatus.LOCATION_CODE.get(baseNo.getWhCode());
spareInHourseDetail.setLocationCode(location); spareInHourseDetail.setLocationCode(location);
// spareInHourseDetail.setLocationCode(binBarcode.getBarcode()); // spareInHourseDetail.setLocationCode(binBarcode.getBarcode());
details.add(spareInHourseDetail); details.add(spareInHourseDetail);
}
LuxsanSpApi.spareInHourse(new SpareInHourseRequest(baseNo.getDeptId(), baseNo.getNo(), baseNo.getWhCode(), details));
} }
LuxsanSpApi.spareInHourse(new SpareInHourseRequest(baseNo.getDeptId(), baseNo.getNo(), baseNo.getWhCode(), details));
} }
return res;
}catch (Exception e) {
// 回滚
rollBack();
throw new Exception(e.getMessage());
} }
return res;
} }
// 入料接口使用了对象锁,可以 // 入料接口使用了对象锁,可以
...@@ -276,6 +266,7 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager { ...@@ -276,6 +266,7 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager {
private BaseNo backupSpareNo; private BaseNo backupSpareNo;
private StoragePos backupPos; private StoragePos backupPos;
@Deprecated
public void addBackupObj(Object o) { public void addBackupObj(Object o) {
if (o instanceof Barcode) { if (o instanceof Barcode) {
backupBarcodes.add(DeepCopyUtil.deepCopy((Barcode) o)); backupBarcodes.add(DeepCopyUtil.deepCopy((Barcode) o));
...@@ -286,6 +277,7 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager { ...@@ -286,6 +277,7 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager {
} }
} }
@Deprecated
public void rollBack() throws Exception { public void rollBack() throws Exception {
try { try {
log.info("开始回滚"); log.info("开始回滚");
...@@ -311,10 +303,11 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager { ...@@ -311,10 +303,11 @@ public class SpBoxPutInManagerImpl implements SpBoxPutInManager {
log.info(String.format("库位[%s]回滚为"+backupPos, backupPos.getPosName())); log.info(String.format("库位[%s]回滚为"+backupPos, backupPos.getPosName()));
} }
}catch (Exception e) { }catch (Exception e) {
throw new Exception("回滚失败,失败原因:"+e.getMessage());
}finally {
backupBarcodes = new ArrayList<>(); backupBarcodes = new ArrayList<>();
backupPos = null; backupPos = null;
backupSpareNo = null; backupSpareNo = null;
throw new Exception("回滚失败,失败原因:"+e.getMessage());
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!