From 98d88ac8caf7f0991d741079474c262f1e252927 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期五, 06 三月 2026 08:14:54 +0800
Subject: [PATCH] 拣货过程中的出库库存匹配
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java | 345 +++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 263 insertions(+), 82 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
index 03ba701..0b19e52 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
@@ -1,14 +1,14 @@
package com.vincent.rsf.server.manager.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.vincent.rsf.framework.common.R;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.vincent.rsf.framework.exception.CoolException;
-import com.vincent.rsf.server.api.controller.params.TaskInParam;
+import com.vincent.rsf.server.api.controller.erp.params.TaskInParam;
import com.vincent.rsf.server.api.entity.dto.InTaskMsgDto;
import com.vincent.rsf.server.api.service.WcsService;
import com.vincent.rsf.server.api.utils.LocUtils;
-import com.vincent.rsf.server.api.utils.SlaveProperties;
import com.vincent.rsf.server.common.constant.Constants;
+import com.vincent.rsf.server.manager.controller.params.CheckLocQueryParams;
import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.enums.*;
@@ -19,6 +19,8 @@
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import lombok.Synchronized;
import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -29,6 +31,8 @@
@Service("locItemService")
public class LocItemServiceImpl extends ServiceImpl<LocItemMapper, LocItem> implements LocItemService {
+
+ Logger logger = LoggerFactory.getLogger(LocItemServiceImpl.class);
@Autowired
private LocService locService;
@@ -42,12 +46,19 @@
private DeviceSiteService deviceSiteService;
@Autowired
private WcsService wcsService;
+ @Autowired
+ private OutStockService outStockService;
+ @Autowired
+ private WaveService waveService;
+ @Autowired
+ private BasStationService basStationService;
/**
* 搴撳瓨鍑哄簱鐢熸垚鍑哄簱浠诲姟
* type: check 鐩樼偣, stock: 搴撳瓨鍑哄簱
*
+ * @param resouce
* @param map
* @param loginUserId
* @return
@@ -55,48 +66,89 @@
@Override
@Synchronized
@Transactional(rollbackFor = Exception.class)
- public R generateTask(LocToTaskParams map, Long loginUserId) {
- if (Objects.isNull(map.getSiteNo())) {
- throw new CoolException("绔欑偣涓嶈兘涓虹┖锛�");
- }
+ public synchronized void generateTask(Short resouce, LocToTaskParams map, Long loginUserId) throws Exception {
+ // 鍑哄簱鍙f湭浼犳椂榛樿 1001
+ String siteNo = StringUtils.isNotBlank(map.getSiteNo()) ? map.getSiteNo() : "1001";
if (Objects.isNull(map.getItems()) || map.getItems().isEmpty()) {
throw new CoolException("鏄庣粏涓嶈兘涓虹┖锛�");
}
-
- String siteNo = map.getSiteNo();
List<LocItem> items = map.getItems();
Map<Long, List<LocItem>> listMap = items.stream().collect(Collectors.groupingBy(LocItem::getLocId));
+ WkOrder order;
+ Wave wave;
+ if (!Objects.isNull(map.getSourceId())) {
+ if (map.getType().equals(Constants.TASK_TYPE_WAVE_OUT_STOCK)) {
+ order = new WkOrder();
+ wave = waveService.getById(map.getSourceId());
+ } else {
+ wave = new Wave();
+ order = outStockService.getById(map.getSourceId());
+ }
+ } else {
+ wave = new Wave();
+ order = new WkOrder();
+ }
+
listMap.keySet().forEach(key -> {
Task task = new Task();
Loc loc = locService.getById(key);
+ logger.info("搴撲綅锛�>{}", loc.getCode());
if (Objects.isNull(loc)) {
throw new CoolException("鏁版嵁閿欒锛氭墍閫夊簱瀛樹俊鎭笉瀛樺湪锛侊紒");
}
- loc.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
-
- if (!locService.updateById(loc)) {
- throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐ワ紒锛�");
+ // 鏀寔 F.鍦ㄥ簱 鎴� R.鍑哄簱棰勭害/鎷h揣涓� 鐘舵�佷笅鍒嗛厤锛堟嫞璐т腑鍙拷鍔犲悓搴撲綅璁㈠崟锛屽垎閰嶉噺涓嶈秴杩囧凡鍒嗛厤鍓╀綑锛�
+ if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)
+ && !loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)) {
+ throw new CoolException("搴撲綅:" + loc.getCode() + ",涓嶅浜嶧.鍦ㄥ簱鎴朢.鍑哄簱棰勭害鐘舵�侊紝涓嶅彲鎵ц鍑哄簱鍒嗛厤锛侊紒");
}
-
+ if (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+ loc.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+ if (!locService.updateById(loc)) {
+ throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐ワ紒锛�");
+ }
+ }
+ // 搴撲綅宸蹭负 R 鏃讹細璁$畻璇ュ簱浣嶅綋鍓嶄换鍔″凡鍒嗛厤閲忥紝鏂板垎閰嶄笉鑳借秴杩� (搴撲綅鏁伴噺 - 宸插垎閰�)
+ Map<String, Double> allocatedByKey = new HashMap<>();
+ List<Task> existTasks = new ArrayList<>();
+ if (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)) {
+ existTasks = taskService.list(new LambdaQueryWrapper<Task>()
+ .eq(Task::getOrgLoc, loc.getCode())
+ .in(Task::getTaskStatus, Arrays.asList(TaskStsType.GENERATE_OUT.id, TaskStsType.WAVE_SEED.id)));
+ for (Task t : existTasks) {
+ List<TaskItem> existItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, t.getId()));
+ for (TaskItem ti : existItems) {
+ String k = buildAllocKey(ti.getMatnrId(), ti.getBatch(), ti.getFieldsIndex());
+ allocatedByKey.put(k, allocatedByKey.getOrDefault(k, 0.0) + (ti.getAnfme() != null ? ti.getAnfme() : 0.0));
+ }
+ }
+ }
+ // 鏂欑鐮侊細浼樺厛鐢ㄥ簱浣嶏紱棰勭害鍑哄簱(R) 鏃惰嫢搴撲綅鏈粦瀹氬垯浠庡悓搴撲綅宸叉湁浠诲姟甯﹀嚭骞跺洖鍐欏簱浣嶏紱鍐嶅惁鍒欎粠鏈鍒嗛厤鏄庣粏甯﹀嚭
+ String barcodeToUse = StringUtils.isNotBlank(loc.getBarcode()) ? loc.getBarcode() : null;
+ if (barcodeToUse == null && !existTasks.isEmpty()) {
+ barcodeToUse = existTasks.get(0).getBarcode();
+ if (StringUtils.isNotBlank(barcodeToUse)) {
+ locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getId, loc.getId())
+ .set(Loc::getBarcode, barcodeToUse).set(Loc::getUpdateBy, loginUserId).set(Loc::getUpdateTime, new Date()));
+ }
+ }
+ if (barcodeToUse == null) {
+ List<LocItem> allocItems = listMap.get(key);
+ if (allocItems != null) {
+ barcodeToUse = allocItems.stream()
+ .map(LocItem::getBarcode)
+ .filter(StringUtils::isNotBlank)
+ .findFirst()
+ .orElse(null);
+ }
+ }
+ if (barcodeToUse == null) {
+ barcodeToUse = loc.getBarcode();
+ }
Task moveTask = new Task();
- if (!LocUtils.isShallowLoc(loc.getCode())) {
- //鑾峰彇娣卞簱浣嶅搴旀祬搴撲綅
- String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
- Loc one = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
- if (Objects.isNull(one)) {
- throw new CoolException("瀵瑰簲搴撲綅涓嶅瓨鍦紒锛�");
- }
- map.setOrgLoc(one.getCode());
- //浼樺厛鐢熸垚绉诲簱浠诲姟
- if (!one.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
- moveTask = genMoveTask(map, loginUserId);
- }
- }
-
String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
task.setOrgLoc(loc.getCode())
.setTaskCode(ruleCode)
- .setParentId(moveTask.getId())
+ .setResource(resouce)
.setTargSite(siteNo)
.setSort(Constants.TASK_SORT_DEFAULT_VALUE)
.setUpdateBy(loginUserId)
@@ -104,7 +156,8 @@
.setCreateTime(new Date())
.setUpdateTime(new Date())
.setTaskStatus(TaskStsType.GENERATE_OUT.id)
- .setBarcode(loc.getBarcode());
+ .setBarcode(barcodeToUse)
+ .setMemo(map.getMemo());
List<LocItem> locItems = this.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, key));
if (locItems.isEmpty()) {
@@ -112,33 +165,26 @@
}
Double orgQty = locItems.stream().mapToDouble(LocItem::getAnfme).sum();
- Double workQty = locItems.stream().mapToDouble(LocItem::getWorkQty).sum();
List<LocItem> locItemList = listMap.get(key);
Double outQty = locItemList.stream().mapToDouble(LocItem::getOutQty).sum();
- Task serviceOne = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, loc.getBarcode()));
- if (!Objects.isNull(serviceOne)) {
- throw new CoolException("鎵樼洏浠诲姟鎵ц涓紝涓嶈兘閲嶅鍒涘缓锛�");
- }
-
- if (map.getType().equals(Constants.TASK_TYPE_OUT_STOCK)) {
- Double useQty = Math.round((outQty + workQty) * 10000) / 10000.0;
- if (orgQty.compareTo(useQty) > 0) {
- //鎷f枡鍑哄簱
-
+ if (map.getType().equals(Constants.TASK_TYPE_OUT_STOCK)
+ || map.getType().equals(Constants.TASK_TYPE_ORDER_OUT_STOCK)
+ || map.getType().equals(Constants.TASK_TYPE_WAVE_OUT_STOCK)) {
+ if (orgQty.compareTo(outQty) > 0) {
+ //鎷f枡鍑哄簱 -- 鐩樼偣鍑哄簱
DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
.eq(DeviceSite::getSite, siteNo)
- .eq(DeviceSite::getChannel, loc.getChannel())
+ .eq(!Objects.isNull(loc.getChannel()),DeviceSite::getChannel, loc.getChannel())
.eq(DeviceSite::getType, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type));
if (Objects.isNull(deviceSite)) {
throw new CoolException("绔欑偣涓嶆敮鎸佹嫞鏂欏嚭搴擄紒锛�");
}
task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type).setWarehType(deviceSite.getDevice());
-
} else {
//鍏ㄦ澘鍑哄簱
DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
- .eq(DeviceSite::getChannel, loc.getChannel())
+ .eq(!Objects.isNull(loc.getChannel()), DeviceSite::getChannel, loc.getChannel())
.eq(DeviceSite::getSite, siteNo).eq(DeviceSite::getType, TaskType.TASK_TYPE_OUT.type));
if (Objects.isNull(deviceSite)) {
throw new CoolException("绔欑偣涓嶆敮鎸佸叏鏉垮嚭搴擄紒锛�");
@@ -149,49 +195,108 @@
} else if (map.getType().equals(Constants.TASK_TYPE_OUT_CHECK)) {
//鐩樼偣鍑哄簱
DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
- .eq(DeviceSite::getChannel, loc.getChannel())
+ .eq(!Objects.isNull(loc.getChannel()), DeviceSite::getChannel, loc.getChannel())
.eq(DeviceSite::getSite, siteNo)
.eq(DeviceSite::getType, TaskType.TASK_TYPE_CHECK_OUT.type));
if (Objects.isNull(deviceSite)) {
throw new CoolException("褰撳墠绔欑偣涓嶆敮鎸佺洏鐐瑰嚭搴擄紒锛�");
}
-
task.setTaskType(TaskType.TASK_TYPE_CHECK_OUT.type).setWarehType(deviceSite.getDevice());
}
if (!taskService.save(task)) {
throw new CoolException("浠诲姟鍒涘缓澶辫触锛侊紒");
}
+
+// if (!LocUtils.isShallowLoc(loc.getCode())) {
+// //鑾峰彇娣卞簱浣嶅搴旀祬搴撲綅
+// String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
+// Loc one = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
+// if (Objects.isNull(one)) {
+// throw new CoolException("瀵瑰簲搴撲綅涓嶅瓨鍦紒锛�");
+// }
+// Task workTask = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, one.getBarcode()));
+// if (Objects.isNull(workTask)) {
+// map.setOrgLoc(one.getCode());
+// //浼樺厛鐢熸垚绉诲簱浠诲姟
+// if (one.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+// moveTask = genMoveTask(map, loginUserId);
+// }
+// } else {
+// workTask.setSort(task.getSort() + 1).setParentId(task.getId());
+// if (!taskService.updateById(workTask)) {
+// throw new CoolException("浼樺厛绾т慨鏀瑰け璐ワ紒锛�");
+// }
+// }
+// }
+
+ if (!Objects.isNull(moveTask.getId())) {
+ moveTask.setParentId(task.getId()).setSort(moveTask.getSort() + 1);
+ if (!taskService.saveOrUpdate(moveTask)) {
+ throw new CoolException("浠诲姟淇℃伅淇敼澶辫触锛侊紒");
+ }
+ task.setParentId(moveTask.getId());
+ if (!taskService.updateById(task)) {
+ throw new CoolException("涓讳换鍔″叧鑱斿け璐ワ紒锛�");
+ }
+ }
+
List<TaskItem> taskItems = new ArrayList<>();
listMap.get(key).forEach(item -> {
- TaskItem taskItem = new TaskItem();
- BeanUtils.copyProperties(item, taskItem);
- taskItem.setTaskId(task.getId())
- .setAnfme(item.getOutQty())
- .setBatch(item.getBatch())
- .setUpdateBy(loginUserId)
- .setCreateBy(loginUserId)
- .setSource(item.getId())
- .setSourceId(item.getLocId())
- .setSourceCode(item.getLocCode())
- .setCreateTime(new Date())
- .setUpdateTime(new Date())
- .setOrderType(OrderType.ORDER_OUT.type)
- .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type));
- taskItems.add(taskItem);
-
- Double qty = Math.round((item.getWorkQty() + item.getOutQty()) * 10000) / 10000.0;
LocItem locItem = locItemService.getById(item.getId());
if (Objects.isNull(locItem)) {
throw new CoolException("搴撳瓨淇℃伅涓嶅瓨鍦紒");
}
-
if (item.getOutQty().compareTo(0.0) < 0) {
throw new CoolException("鍑哄簱鏁伴噷涓嶈兘灏忎簬0锛侊紒");
}
+ // 棰勭害鍑哄簱/鎷h揣涓拷鍔狅細鏂板垎閰嶉噺涓嶈兘瓒呰繃 (搴撲綅鏁伴噺 - 璇ョ墿鏂欏凡鍒嗛厤閲�)
+ Double allocQty = item.getOutQty();
+ if (!allocatedByKey.isEmpty()) {
+ String allocKey = buildAllocKey(locItem.getMatnrId(), locItem.getBatch(), locItem.getFieldsIndex());
+ Double already = allocatedByKey.getOrDefault(allocKey, 0.0);
+ Double available = Math.round((locItem.getAnfme() - already) * 1000000) / 1000000.0;
+ if (available.compareTo(0.0) <= 0) {
+ throw new CoolException("搴撲綅:" + loc.getCode() + " 璇ョ墿鏂欏凡鏃犲墿浣欏彲鍒嗛厤鏁伴噺锛屼笉鍙啀杩藉姞璁㈠崟锛�");
+ }
+ if (allocQty.compareTo(available) > 0) {
+ allocQty = available;
+ item.setOutQty(allocQty);
+ }
+ allocatedByKey.put(allocKey, already + allocQty);
+ }
+ TaskItem taskItem = new TaskItem();
+ BeanUtils.copyProperties(item, taskItem);
+ taskItem.setTaskId(task.getId())
+ .setAnfme(allocQty)
+ .setBatch(item.getBatch())
+ .setUpdateBy(loginUserId)
+ .setCreateBy(loginUserId)
+ .setCreateTime(new Date())
+ .setUpdateTime(new Date())
+ .setOrderType(OrderType.ORDER_OUT.type);
+ if (map.getType().equals(Constants.TASK_TYPE_ORDER_OUT_STOCK)) {
+ taskItem.setWkType(Short.parseShort(order.getWkType()))
+ .setSourceCode(order.getCode())
+ .setSourceId(order.getId())
+ .setOrderItemId(item.getOrderItemId());
+ } else if (map.getType().equals(Constants.TASK_TYPE_WAVE_OUT_STOCK)) {
+ taskItem.setSourceId(wave.getId())
+ .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_OTHER.type))
+ .setSourceCode(wave.getCode())
+ .setSource(item.getSource());
+ } else if (map.getType().equals(Constants.TASK_TYPE_OUT_CHECK) || map.getType().equals(Constants.TASK_TYPE_OUT_STOCK)) {
+ taskItem.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))
+ .setSource(item.getId())
+ .setSourceId(item.getLocId())
+ .setSourceCode(item.getLocCode());
+ }
+ taskItems.add(taskItem);
+
+ Double qty = Math.round((item.getWorkQty() != null ? item.getWorkQty() : 0.0) + allocQty) * 1000000.0 / 1000000.0;
if (locItem.getAnfme().compareTo(qty) < 0) {
- Double minusQty = Math.round((locItem.getAnfme() - locItem.getWorkQty()) * 10000) / 10000.0;
+ Double minusQty = Math.round((locItem.getAnfme() - (locItem.getWorkQty() != null ? locItem.getWorkQty() : 0.0)) * 1000000) / 1000000.0;
item.setWorkQty(minusQty);
} else {
item.setWorkQty(qty);
@@ -207,8 +312,6 @@
throw new CoolException("浠诲姟鏄庣粏鐢熸垚澶辫触锛侊紒");
}
});
-
- return R.ok("浠诲姟鐢熸垚瀹屾垚锛�!");
}
/**
@@ -224,40 +327,37 @@
if (Objects.isNull(map.getOrgLoc()) || StringUtils.isBlank(map.getOrgLoc())) {
throw new CoolException("婧愬簱浣嶄笉鑳戒负绌猴紒");
}
-
Loc orgLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, map.getOrgLoc()));
if (Objects.isNull(orgLoc)) {
throw new CoolException("婧愬簱浣嶄笉瀛樺湪锛侊紒");
}
-
- if (orgLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)
- || orgLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)
- || orgLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_X.type ) ) {
- throw new CoolException("婧愬簱浣嶆湁浠诲姟姝e湪鎵ц涓�...");
- }
-
+// if (orgLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)
+// || orgLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)
+// || orgLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_X.type ) ) {
+// throw new CoolException("婧愬簱浣嶆湁浠诲姟姝e湪鎵ц涓�...");
+// }
orgLoc.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
if (!locService.updateById(orgLoc)) {
throw new CoolException("鍑哄簱棰勭害澶辫触锛侊紒");
}
- Loc targetLoc = new Loc();
+ Loc targetLoc;
if (Objects.isNull(map.getTarLoc()) || StringUtils.isBlank(map.getTarLoc())) {
//鐩爣搴撲綅涓虹┖锛岃嚜鍔ㄨ幏鍙栨柊搴撲綅
DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
- .eq(DeviceSite::getType, TaskType.TASK_TYPE_LOC_MOVE.type)
- .eq(DeviceSite::getChannel, orgLoc.getChannel()), false);
+ .eq(DeviceSite::getType, TaskType.TASK_TYPE_LOC_MOVE.type)
+ .eq(!Objects.isNull(orgLoc.getChannel()), DeviceSite::getChannel, orgLoc.getChannel()), false);
if (Objects.isNull(deviceSite)) {
throw new CoolException("绔欑偣淇℃伅涓嶅瓨鍦紒锛�");
}
TaskInParam param = new TaskInParam();
param.setIoType(TaskType.TASK_TYPE_OUT.type)
.setOrgLoc(map.getOrgLoc())
- .setSourceStaNo(Integer.parseInt(deviceSite.getSite()))
+ .setSourceStaNo(deviceSite.getSite())
.setLocType1(Integer.parseInt(orgLoc.getType())
);
- InTaskMsgDto locNo = null;
+ InTaskMsgDto locNo;
try {
locNo = wcsService.getLocNo(param);
} catch (Exception e) {
@@ -288,8 +388,9 @@
.setUpdateBy(loginUserId)
.setSort(Constants.TASK_SORT_DEFAULT_VALUE)
.setUpdateTime(new Date())
- .setTaskStatus(TaskStsType.GENERATE_OUT.id)
- .setBarcode(orgLoc.getBarcode());
+ .setTaskStatus(TaskStsType.GENERATE_IN.id)
+ .setBarcode(orgLoc.getBarcode())
+ .setMemo(map.getMemo());
if (!taskService.save(task)) {
throw new CoolException("鏂板缓绉诲簱浠诲姟澶辫触锛侊紒");
@@ -319,4 +420,84 @@
}
return task;
}
+
+ /**
+ * 绌烘澘鍑哄簱锛氫粠鎸囧畾绌烘澘搴撲綅锛坲seStatus=D锛夌敓鎴� TASK_TYPE_EMPITY_OUT 浠诲姟鑷崇洰鏍囩珯鐐广��
+ * 闇�鍦ㄨ澶囩珯鐐逛腑閰嶇疆 type=110锛堢┖鏉垮嚭搴擄級鐨勭珯鐐硅矾寰勩��
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Task generateTaskEmpty(LocToTaskParams map, Long loginUserId) {
+ if (StringUtils.isBlank(map.getSiteNo())) {
+ throw new CoolException("鐩爣绔欑偣涓嶈兘涓虹┖锛�");
+ }
+ if (StringUtils.isBlank(map.getOrgLoc())) {
+ throw new CoolException("婧愬簱浣嶄笉鑳戒负绌猴紒");
+ }
+ if (!Constants.TASK_TYPE_OUT_STOCK_EMPTY.equals(map.getType())) {
+ throw new CoolException("绫诲瀷蹇呴』涓� empty锛堢┖鏉垮嚭搴擄級锛�");
+ }
+ Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, map.getOrgLoc()));
+ if (loc == null) {
+ throw new CoolException("婧愬簱浣嶄笉瀛樺湪锛�");
+ }
+ if (!LocStsType.LOC_STS_TYPE_D.type.equals(loc.getUseStatus())) {
+ throw new CoolException("搴撲綅 " + loc.getCode() + " 涓嶅浜庣┖鏉跨姸鎬侊紙D锛夛紝涓嶅彲鎵ц绌烘澘鍑哄簱锛�");
+ }
+ DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
+ .eq(DeviceSite::getSite, map.getSiteNo())
+ .eq(DeviceSite::getType, TaskType.TASK_TYPE_EMPITY_OUT.type)
+ .last("limit 1"));
+ if (deviceSite == null) {
+ throw new CoolException("绔欑偣涓嶆敮鎸佺┖鏉垮嚭搴撴垨鏈厤缃┖鏉垮嚭搴撹矾寰勶紒");
+ }
+ if (!locService.update(new LambdaUpdateWrapper<Loc>()
+ .eq(Loc::getId, loc.getId())
+ .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_R.type))) {
+ throw new CoolException("搴撲綅鍑哄簱棰勭害澶辫触锛�");
+ }
+ String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
+ if (StringUtils.isBlank(ruleCode)) {
+ throw new CoolException("缂栫爜閿欒锛氳纭鏄惁宸茬敓鎴愶紒");
+ }
+ Task task = new Task();
+ task.setTaskCode(ruleCode)
+ .setTaskStatus(TaskStsType.GENERATE_OUT.id)
+ .setTaskType(TaskType.TASK_TYPE_EMPITY_OUT.type)
+ .setWarehType(WarehType.WAREHOUSE_TYPE_CRN.val)
+ .setOrgLoc(loc.getCode())
+ .setTargSite(map.getSiteNo())
+ .setBarcode(loc.getBarcode())
+ .setSort(Constants.TASK_SORT_DEFAULT_VALUE)
+ .setCreateBy(loginUserId)
+ .setUpdateBy(loginUserId)
+ .setCreateTime(new Date())
+ .setUpdateTime(new Date())
+ .setMemo(map.getMemo());
+ if (!taskService.save(task)) {
+ throw new CoolException("绌烘澘鍑哄簱浠诲姟鍒涘缓澶辫触锛�");
+ }
+ logger.info("[绌烘澘鍑哄簱] 宸插垱寤轰换鍔�: {}, 婧愬簱浣�: {}, 鐩爣绔欑偣: {}", ruleCode, loc.getCode(), map.getSiteNo());
+ return task;
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/7/16
+ * @description: 鑾峰彇褰撳墠鐗╂枡鎵�鏈夊簱瀛樹俊鎭�
+ * @version 1.0
+ */
+ @Override
+ public List<LocItem> listByMatnr(CheckLocQueryParams matnr) {
+ LambdaQueryWrapper<LocItem> wrapper = new LambdaQueryWrapper<LocItem>()
+ .eq(StringUtils.isNotBlank(matnr.getLocCode()), LocItem::getLocCode, matnr.getLocCode())
+// .eq(StringUtils.isNotBlank(matnr.getChannel()), LocItem::getChannel, matnr.getChannel())
+ .in(!matnr.getMatnrCode().isEmpty(), LocItem::getMatnrCode, matnr.getMatnrCode());
+ return this.baseMapper.listByMatnr(LocStsType.LOC_STS_TYPE_F.type, matnr.getChannel(), wrapper);
+ }
+
+ /** 搴撲綅宸插垎閰嶉噺鎸夌墿鏂�+鎵规+绁ㄥ彿鑱氬悎鐨� key */
+ private static String buildAllocKey(Long matnrId, String batch, String fieldsIndex) {
+ return (matnrId != null ? matnrId : "") + "|" + (batch != null ? batch : "") + "|" + (fieldsIndex != null ? fieldsIndex : "");
+ }
}
--
Gitblit v1.9.1