From b003a49794f49a329e2702918ecfc8d14b371d0d Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期三, 04 三月 2026 14:51:25 +0800
Subject: [PATCH] 云仓WMS接口流程
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java | 380 ++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 299 insertions(+), 81 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
index f76d167..0bd3bb6 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -4,12 +4,14 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.DateUtils;
import com.vincent.rsf.server.api.config.RemotesInfoProperties;
+import com.vincent.rsf.server.api.controller.erp.params.InOutResultReportParam;
import com.vincent.rsf.server.api.controller.erp.params.TaskInParam;
import com.vincent.rsf.server.api.entity.CommonResponse;
import com.vincent.rsf.server.api.entity.constant.RcsConstant;
@@ -18,6 +20,7 @@
import com.vincent.rsf.server.api.entity.params.WcsTaskParams;
import com.vincent.rsf.server.api.service.WcsService;
import com.vincent.rsf.server.common.constant.Constants;
+import com.vincent.rsf.server.common.utils.QuantityUtils;
import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
import com.vincent.rsf.server.manager.controller.params.PakinItem;
import com.vincent.rsf.server.manager.enums.*;
@@ -25,6 +28,7 @@
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.api.utils.LocUtils;
import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams;
+import com.vincent.rsf.server.manager.entity.CloudWmsNotifyLog;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.mapper.TaskMapper;
import com.vincent.rsf.server.manager.service.*;
@@ -123,6 +127,10 @@
private RestTemplate restTemplate;
@Autowired
private RemotesInfoProperties.RcsApi rcsApi;
+ @Autowired
+ private CloudWmsNotifyLogService cloudWmsNotifyLogService;
+ @Autowired
+ private WarehouseService warehouseService;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -459,16 +467,18 @@
if (success.compareAndSet(false, true)) {
Long loginUserId = SystemAuthUtils.getLoginUserId();
for (Task task : tasks) {
- if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
- //1.鍏ュ簱
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)) {
+ //1.鍏ュ簱銆�54.骞舵澘鍐嶅叆搴�
complateInstock(task, loginUserId);
} else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
- //53.鎷f枡鍐嶅叆搴�
- //57.鐩樼偣鍐嶅叆搴�
+ //53.鎷f枡鍐嶅叆搴撱��57.鐩樼偣鍐嶅叆搴�
pickComplateInStock(task, loginUserId);
} else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
- //绉诲簱
+ //11.搴撴牸绉昏浇
moveInStock(task, loginUserId);
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
+ //10.绌烘澘鍏ュ簱锛氫笌鏅�氬叆搴撳叡鐢ㄤ竴涓畬鎴愰�昏緫锛堣嫢鏈夌粍鎵樺垯鏇存柊缁勬墭/搴撲綅骞朵笂鎶ヤ簯浠擄級
+ complateInstock(task, loginUserId);
}
}
}
@@ -721,7 +731,7 @@
@Override
@Transactional(rollbackFor = Exception.class)
public void moveToDeep(Long loginUserId, String curLoc) throws Exception {
- //娴呭簱浣嶏紝鍒ゆ柇娣卞搴旀繁搴撲綅鏄惁涓虹┖锛屽鏋滀负绌虹敓鎴愪竴涓Щ搴撲换鍔★紝灏嗘墭鐩橀�佸叆娣卞簱浣�
+ //娴呭簱浣嶏紝鍒ゆ柇娣卞搴旀繁搴撲綅鏄惁涓虹┖锛屽鏋滀负绌虹敓鎴愪竴涓Щ搴撲换鍔★紝灏嗘枡绠遍�佸叆娣卞簱浣�
String deepLoc = LocUtils.getDeepLoc(curLoc);
if (StringUtils.isBlank(deepLoc)) {
throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛橈紒");
@@ -804,7 +814,11 @@
.set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
}
-
+ // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氬簱鏍肩Щ杞藉畬鎴愬悗閫氱煡浜戜粨锛堜笌瀹氭椂浠诲姟闂幆涓�鑷达級
+ List<TaskItem> moveTaskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+ if (!moveTaskItems.isEmpty()) {
+ reportInOutResultToCloud(task, loc, moveTaskItems, null, true);
+ }
}
@@ -860,30 +874,37 @@
throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦紒锛�");
}
- List<LocItem> items = new ArrayList<>();
- for (TaskItem taskItem : taskItems) {
- LocItem locItem = new LocItem();
- LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
- .eq(LocItemWorking::getTaskId, taskItem.getTaskId())
- .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
- .eq(StringUtils.isNotEmpty(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
- .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
- if (Objects.isNull(locWorking)) {
- continue;
+ if (TaskType.TASK_TYPE_PICK_IN.type.equals(task.getTaskType())) {
+ // 鎷f枡鍐嶅叆搴擄細鍑哄簱鏃跺凡鍦� pickOrCheckTask 涓墸鍑忓師搴撲綅锛�1100 -> 1089.899锛夛紝
+ // 鍏ュ簱瀹屾垚鏃朵笉鍐嶅洖鍐�/绱姞搴撲綅鏄庣粏锛屼繚鎸� 1 鏉� 1089.899锛岄伩鍏嶅嚭鐜颁袱鏉� 1100
+ // 浠呮洿鏂板簱浣嶇姸鎬併�佹竻鐞� LocItemWorking銆佷换鍔$姸鎬佸強娴佹按
+ } else {
+ // 鐩樼偣鍏ュ簱绛夛細娌跨敤鍘熼�昏緫锛屼粠 LocItemWorking 鍥炲啓骞� saveBatch
+ List<LocItem> items = new ArrayList<>();
+ for (TaskItem taskItem : taskItems) {
+ LocItem locItem = new LocItem();
+ LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
+ .eq(LocItemWorking::getTaskId, taskItem.getTaskId())
+ .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
+ .eq(StringUtils.isNotEmpty(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
+ .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
+ if (Objects.isNull(locWorking)) {
+ continue;
+ }
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
+ locWorking.setAnfme(taskItem.getAnfme());
+ }
+ BeanUtils.copyProperties(locWorking, locItem);
+ locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
+ //鏁伴噺涓洪浂鐨勪笉鍏ュ簱
+ if (locItem.getAnfme().compareTo(0.0) > 0) {
+ items.add(locItem);
+ }
}
- if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
- locWorking.setAnfme(taskItem.getAnfme());
- }
- BeanUtils.copyProperties(locWorking, locItem);
- locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
- //鏁伴噺涓洪浂鐨勪笉鍏ュ簱
- if (locItem.getAnfme().compareTo(0.0) > 0) {
- items.add(locItem);
- }
- }
- if (!locItemService.saveBatch(items)) {
+ if (!items.isEmpty() && !locItemService.saveBatch(items)) {
// throw new CoolException("浣滀笟搴撳瓨鍥炲啓澶辫触锛侊紒");
+ }
}
TaskItem taskItem = taskItems.stream().findFirst().get();
@@ -896,7 +917,8 @@
if (!taskService.updateById(task)) {
throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
}
-
+ // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氭嫞鏂欏啀鍏ュ簱/鐩樼偣鍐嶅叆搴撳畬鎴愬悗閫氱煡浜戜粨锛堜笌瀹氭椂浠诲姟闂幆涓�鑷达級
+ reportInOutResultToCloud(task, loc, taskItems, null, true);
}
/**
@@ -952,7 +974,7 @@
batchNo = task.getTaskCode();
}
}
- log.info("浠诲姟宸蹭笅鍙戝埌RCS锛岄渶瑕佸彇娑圧CS浠诲姟 - 浠诲姟ID锛歿}锛屼换鍔$紪鍙凤細{}锛屼换鍔$姸鎬侊細{}锛屾墭鐩樼爜锛歿}",
+ log.info("浠诲姟宸蹭笅鍙戝埌RCS锛岄渶瑕佸彇娑圧CS浠诲姟 - 浠诲姟ID锛歿}锛屼换鍔$紪鍙凤細{}锛屼换鍔$姸鎬侊細{}锛屾枡绠辩爜锛歿}",
task.getId(), task.getTaskCode(), task.getTaskStatus(), task.getBarcode());
}
}
@@ -960,11 +982,19 @@
// 濡傛灉鏈変换鍔″凡涓嬪彂鍒癛CS锛屽厛璋冪敤RCS鍙栨秷鎺ュ彛
boolean rcsCancelSuccess = false;
if (!rcsTaskCodes.isEmpty()) {
- try {
- log.info("========== 寮�濮嬪彇娑圧CS浠诲姟 ==========");
- log.info("闇�瑕佸彇娑堢殑RCS浠诲姟缂栧彿锛歿}", rcsTaskCodes);
- String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
- log.info("RCS鍙栨秷浠诲姟璇锋眰鍦板潃锛歿}", rcsUrl);
+ // 妫�鏌� RCS API 閰嶇疆鏄惁鏈夋晥
+ if (rcsApi == null || StringUtils.isBlank(rcsApi.getHost()) || StringUtils.isBlank(rcsApi.getPort())) {
+ log.error("========== RCS浠诲姟鍙栨秷澶辫触 ==========");
+ log.error("RCS API 閰嶇疆鏃犳晥锛乭ost: {}, port: {}",
+ rcsApi != null ? rcsApi.getHost() : "null",
+ rcsApi != null ? rcsApi.getPort() : "null");
+ // 鍗充娇閰嶇疆鏃犳晥锛屼篃缁х画鎵ц浠诲姟鍒犻櫎鎿嶄綔
+ } else {
+ try {
+ log.info("========== 寮�濮嬪彇娑圧CS浠诲姟 ==========");
+ log.info("闇�瑕佸彇娑堢殑RCS浠诲姟缂栧彿锛歿}", rcsTaskCodes);
+ String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
+ log.info("RCS鍙栨秷浠诲姟璇锋眰鍦板潃锛歿}", rcsUrl);
// 濡傛灉娌℃湁鎵规缂栧彿锛屼娇鐢ㄧ涓�涓换鍔$紪鍙蜂綔涓烘壒娆$紪鍙�
if (StringUtils.isBlank(batchNo) && !rcsTaskCodes.isEmpty()) {
@@ -1010,12 +1040,13 @@
log.error("RCS鍙栨秷浠诲姟澶辫触锛歿}", result.getMsg());
throw new CoolException("RCS鍙栨秷浠诲姟澶辫触锛�" + result.getMsg());
}
- } catch (JsonProcessingException e) {
- log.error("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛歿}", e.getMessage(), e);
- throw new CoolException("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛�" + e.getMessage());
- } catch (Exception e) {
- log.error("RCS鍙栨秷浠诲姟寮傚父锛歿}", e.getMessage(), e);
- throw new CoolException("RCS鍙栨秷浠诲姟寮傚父锛�" + e.getMessage());
+ } catch (JsonProcessingException e) {
+ log.error("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛歿}", e.getMessage(), e);
+ throw new CoolException("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛�" + e.getMessage());
+ } catch (Exception e) {
+ log.error("RCS鍙栨秷浠诲姟寮傚父锛歿}", e.getMessage(), e);
+ throw new CoolException("RCS鍙栨秷浠诲姟寮傚父锛�" + e.getMessage());
+ }
}
}
@@ -1278,7 +1309,7 @@
// if (Objects.isNull(locInfo)) {
// throw new CoolException("鑾峰彇搴撲綅澶辫触锛侊紒");
// }
- //甯屾棩涓婃姤鐗╂湁鎯呭喌锛屼笉闇�瑕佽幏鍙栨柊搴撲綅
+ //涓婃姤鐗╂湁鎯呭喌锛屼笉闇�瑕佽幏鍙栨柊搴撲綅
task.setTargLoc(task.getOrgLoc())
.setOrgSite(task.getTargSite());
@@ -1287,12 +1318,71 @@
}
//鑾峰彇鍥犲綋鍓嶄换鍔″嚭搴撶殑鎵�鏈夌墿鏂欎俊鎭�
List<LocItemWorking> tempLocs = locItemWorkingService.list(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()));
- if (tempLocs.isEmpty()) {
- throw new CoolException("鏁版嵁閿欒锛屼綔涓氫腑搴撳瓨鏁版嵁涓㈠け锛侊紒");
- }
List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
if (taskItems.isEmpty()) {
throw new CoolException("鏁版嵁閿欒锛氫换鍔℃槑缁嗕负绌猴紒锛�");
+ }
+ // 涓庢煡璇竴鑷达細鑻ユ棤浣滀笟涓簱瀛樹絾瀛樺湪浠诲姟鏄庣粏锛岀敤浠诲姟鏄庣粏鍦ㄥ唴瀛樹腑鍏滃簳锛岄伩鍏嶁�滆兘鏌ュ埌鍗存棤娉曠‘璁も��
+ if (tempLocs.isEmpty()) {
+ tempLocs = taskItems.stream().map(ti -> {
+ LocItemWorking w = new LocItemWorking();
+ w.setTaskId(task.getId());
+ w.setFieldsIndex(ti.getFieldsIndex());
+ w.setAnfme(ti.getAnfme());
+ w.setMatnrId(ti.getMatnrId());
+ w.setMaktx(ti.getMaktx());
+ w.setMatnrCode(ti.getMatnrCode());
+ w.setSpec(ti.getSpec());
+ w.setBatch(ti.getBatch());
+ w.setUnit(ti.getUnit());
+ w.setModel(ti.getModel());
+ return w;
+ }).collect(Collectors.toList());
+ }
+
+ // 鎷f枡鍏ュ簱锛氬厛绠楀墿浣欐暟閲忓苟鏇存柊 taskItem.anfme锛屽凡鎷f暟閲� taskItem.qty = 鍘熷簱浣� - 鍓╀綑锛堜繚璇� 鏁伴噺=100銆佸凡鎷f暟閲�=1銆佸簱瀛樻槑缁�=100锛�
+ if (TaskType.TASK_TYPE_PICK_IN.type.equals(type)) {
+ log.debug("[鎷f枡鍏ュ簱] 寮�濮嬪鐞� taskId={}, taskCode={}, orgLoc={}, tempLocs.size={}, taskItems.size={}",
+ task.getId(), task.getTaskCode(), task.getOrgLoc(), tempLocs.size(), taskItems.size());
+ tempLocs.forEach(working -> {
+ taskItems.forEach(taskItem -> {
+ if (Objects.equals(taskItem.getFieldsIndex(), working.getFieldsIndex())) {
+ // 宸叉嫞鏁伴噺锛氫紭鍏堢敤 taskItem.qty锛涗负 0 鏃朵粠鍑哄簱鍗曟槑缁嗗彇 鎵ц鏁�(workQty) 鎴� 璁㈠崟鏁伴噺(anfme)锛岄伩鍏嶆墜鍔ㄥ畬缁撴湭濉� qty 瀵艰嚧涓嶆墸鍑�
+ Double pickedQty = taskItem.getQty() != null && QuantityUtils.isPositive(taskItem.getQty())
+ ? taskItem.getQty()
+ : 0.0;
+ log.debug("[鎷f枡鍏ュ簱] taskItemId={}, fieldsIndex={}, working.anfme={}, taskItem.qty={}, taskItem.orderItemId={}, pickedQty(鍒�)={}",
+ taskItem.getId(), taskItem.getFieldsIndex(), working.getAnfme(), taskItem.getQty(), taskItem.getOrderItemId(), pickedQty);
+ if (pickedQty <= 0 && taskItem.getOrderItemId() != null) {
+ WkOrderItem orderItem = asnOrderItemService.getById(taskItem.getOrderItemId());
+ log.debug("[鎷f枡鍏ュ簱] 鏌ュ嚭搴撳崟鏄庣粏 orderItemId={}, orderItem={}, workQty={}, anfme={}",
+ taskItem.getOrderItemId(), orderItem != null ? "瀛樺湪" : "null",
+ orderItem != null ? orderItem.getWorkQty() : null, orderItem != null ? orderItem.getAnfme() : null);
+ if (orderItem != null) {
+ if (orderItem.getWorkQty() != null && QuantityUtils.isPositive(orderItem.getWorkQty())) {
+ pickedQty = orderItem.getWorkQty();
+ } else if (orderItem.getAnfme() != null && QuantityUtils.isPositive(orderItem.getAnfme())) {
+ pickedQty = orderItem.getAnfme();
+ }
+ }
+ }
+ Double minQty = QuantityUtils.subtract(working.getAnfme(), pickedQty);
+ log.debug("[鎷f枡鍏ュ簱] 璁$畻鍚� pickedQty={}, minQty(鍓╀綑)={}, 灏嗘洿鏂� taskItem.anfme={}, taskItem.qty={}",
+ pickedQty, minQty, minQty, pickedQty);
+ if (QuantityUtils.isNonNegative(minQty)) {
+ taskItem.setAnfme(minQty);
+ taskItem.setQty(pickedQty);
+ if (!taskItemService.updateById(taskItem)) {
+ throw new CoolException("浠诲姟鏄庣粏淇敼澶辫触锛侊紒");
+ }
+ } else {
+ log.warn("[鎷f枡鍏ュ簱] minQty<0 鏈洿鏂� taskItem, taskItemId={}", taskItem.getId());
+ }
+ }
+ });
+ });
+ log.debug("[鎷f枡鍏ュ簱] 鍗冲皢鎵e噺搴撲綅 locId={}, locCode={}", loc.getId(), loc.getCode());
+ subtractLocItemByTaskItems(loc, taskItems, SystemAuthUtils.getLoginUserId());
}
tempLocs.forEach(working -> {
@@ -1300,19 +1390,19 @@
if (Objects.equals(taskItem.getFieldsIndex(), working.getFieldsIndex())) {
Double minQty = taskItem.getAnfme();
if (!task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
- // 璁$畻鍓╀綑鏁伴噺锛氫粠LocItemWorking涓噺鍘籘askItem鐨勬嫞鏂欐暟閲�
- minQty = Math.round((working.getAnfme() - taskItem.getQty()) * 1000000) / 1000000.0;
+ // 璁$畻鍓╀綑鏁伴噺
+ minQty = QuantityUtils.subtract(working.getAnfme(), taskItem.getQty());
}
- if (minQty.compareTo(0.0) >= 0) {
+ if (QuantityUtils.isNonNegative(minQty)) {
// 鏇存柊TaskItem鐨勫墿浣欐暟閲�
taskItem.setAnfme(minQty);
if (!taskItemService.updateById(taskItem)) {
throw new CoolException("浠诲姟鏄庣粏淇敼澶辫触锛侊紒");
}
- // 鏇存柊LocItemWorking鐨勫墿浣欐暟閲忥紙闈炵洏鐐瑰叆搴撴椂闇�瑕佹洿鏂帮級
+ // 鏇存柊LocItemWorking鐨勫墿浣欐暟閲忥紙闈炵洏鐐瑰叆搴撴椂闇�瑕佹洿鏂帮級锛涗粎鎸佷箙鍖栬褰曟墠鍐欏簱
if (!task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
working.setAnfme(minQty);
- if (!locItemWorkingService.updateById(working)) {
+ if (working.getId() != null && !locItemWorkingService.updateById(working)) {
throw new CoolException("浣滀笟搴撳瓨鏁伴噺鏇存柊澶辫触锛侊紒");
}
}
@@ -1367,6 +1457,10 @@
.setQty(0.0)
.setLocId(loc1.getId())
.setLocCode(loc1.getCode());
+ // 鎷f枡鍐嶅叆搴擄細鐩爣搴撲綅鏁伴噺搴斾负鍥炲簱鐨勫墿浣欐暟閲�(taskItem.anfme)锛屽嵆鍘熷簱浣嶅噺鎺夋湰娆℃嫞鍑哄悗鐨勬暟閲忥紙濡� 1000 鍑哄簱 10 鈫� 990锛�
+ if (TaskType.TASK_TYPE_PICK_IN.type.equals(task.getTaskType()) && taskItem.getAnfme() != null && taskItem.getAnfme().compareTo(0.0) > 0) {
+ itemWorking.setAnfme(taskItem.getAnfme());
+ }
workings.add(itemWorking);
});
@@ -1422,10 +1516,10 @@
}
return; // 璺宠繃鍚庣画澶勭悊
} else {
- // 搴撲綅鏄庣粏涓嶄负绌轰絾鐘舵�佷笉鏄疪锛岃褰曢敊璇絾涓嶆姏鍑哄紓甯革紝璁╁畾鏃朵换鍔$户缁鐞嗗叾浠栦换鍔�
+ // 搴撲綅鏄庣粏涓嶄负绌轰絾鐘舵�佷笉鏄疪锛岃烦杩囧鐞�
logger.error("浠诲姟{}鐨勫簱浣峽}鐘舵�佷负{}锛屼笉鏄疪.鍑哄簱棰勭害鐘舵�侊紝浣嗗簱浣嶆槑缁嗕笉涓虹┖锛岃烦杩囧鐞嗐�備换鍔$紪鐮侊細{}锛屽簱浣嶇紪鐮侊細{}",
task.getId(), loc.getCode(), loc.getUseStatus(), task.getTaskCode(), loc.getCode());
- return; // 璺宠繃澶勭悊锛岄伩鍏嶅紓甯镐腑鏂畾鏃朵换鍔�
+ return;
}
}
@@ -1450,10 +1544,10 @@
try {
// 鏍规嵁浠诲姟绫诲瀷鏇存柊搴撲綅鏄庣粏
if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
- // 鍏ㄧ増鍑哄簱锛氬垹闄ゆ墍鏈夊簱浣嶆槑缁�
- subtractLocItem(loc);
- } else {
- // 閮ㄥ垎鍑哄簱锛堝鎷f枡鍑哄簱锛夛細鏍规嵁TaskItem鏁伴噺鎵e噺搴撲綅鏄庣粏
+ // 鍏ㄧ増鍑哄簱锛氫笉鍒犻櫎搴撲綅鏄庣粏锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶅垹闄�
+ // subtractLocItem(loc); // 宸茬Щ闄わ紝鏀逛负鍦╟ompleteFullOutStock涓垹闄�
+ } else if (!TaskType.TASK_TYPE_PICK_AGAIN_OUT.type.equals(task.getTaskType())) {
+ // 閮ㄥ垎鍑哄簱锛堝鐩樼偣鍑哄簱锛夛細鏍规嵁TaskItem鏁伴噺鎵e噺搴撲綅鏄庣粏锛涙嫞鏂欏嚭搴撳湪鐢熸垚鎷f枡鍏ュ簱鍗曟椂鎵e噺
subtractLocItemByTaskItems(loc, taskItems, loginUserId);
}
} catch (Exception e) {
@@ -1513,6 +1607,8 @@
throw new CoolException(e.getMessage());
}
}
+
+ // 鏍规嵁浠诲姟绫诲瀷鏇存柊搴撲綅鐘舵��
if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
/**淇敼涓哄簱浣嶇姸鎬佷负S.棰勭害鍏ュ簱锛屼繚鐣欏師鏈夊簱浣�*/
if (!locService.update(new LambdaUpdateWrapper<Loc>()
@@ -1523,6 +1619,9 @@
.eq(Loc::getId, loc.getId()))) {
throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
}
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
+ // 鍏ㄧ増鍑哄簱锛氫笉鏇存柊搴撲綅鐘舵�佷负O锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶆洿鏂�
+ // 搴撲綅鐘舵�佷繚鎸佸師鏍凤紙R.鍑哄簱棰勭害鐘舵�侊級
} else {
/**淇敼涓哄簱浣嶇姸鎬佷负O.绌哄簱*/
if (!locService.update(new LambdaUpdateWrapper<Loc>()
@@ -1542,6 +1641,8 @@
.set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
}
+ // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氬嚭搴撳畬鎴愬悗閫氱煡浜戜粨
+ reportInOutResultToCloud(task, loc, taskItems, null, false);
// if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
// if (!this.update(new LambdaUpdateWrapper<Task>()
@@ -1687,6 +1788,15 @@
@Transactional(rollbackFor = Exception.class)
public void pubTaskToWcs(List<Task> tasks) {
/**浠诲姟涓嬪彂鎺ュ彛*/
+ // 妫�鏌� RCS API 閰嶇疆鏄惁鏈夋晥
+ if (rcsApi == null || StringUtils.isBlank(rcsApi.getHost()) || StringUtils.isBlank(rcsApi.getPort())) {
+ log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+ log.error("RCS API 閰嶇疆鏃犳晥锛乭ost: {}, port: {}",
+ rcsApi != null ? rcsApi.getHost() : "null",
+ rcsApi != null ? rcsApi.getPort() : "null");
+ return;
+ }
+
String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
for (Task task : tasks) {
@@ -1781,7 +1891,10 @@
// 涓烘瘡涓笉鍚岀殑搴撲綅鍒涘缓涓�涓猅askItemParam
for (String locCode : locCodes) {
TaskItemParam outItemParam = new TaskItemParam();
- outItemParam.setTaskNo(task.getTaskCode());
+ String taskNo = locCodes.size() > 1
+ ? task.getTaskCode() + "_" + locCode
+ : task.getTaskCode();
+ outItemParam.setTaskNo(taskNo);
outItemParam.setPriority(1);
outItemParam.setOriLoc(locCode);
outItemParam.setDestSta(task.getTargSite());
@@ -1870,7 +1983,7 @@
} catch (org.springframework.web.client.ResourceAccessException e) {
long endTime = System.currentTimeMillis();
log.error("========== RCS浠诲姟涓嬪彂璧勬簮璁块棶寮傚父 ==========");
- log.error("璇锋眰RCS-璧勬簮璁块棶寮傚父锛堝彲鑳藉寘鍚繛鎺ヨ秴鏃讹級锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}", (endTime - startTime), task.getTaskCode(), e);
+ log.error("璇锋眰RCS-璧勬簮璁块棶寮傚父锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}", (endTime - startTime), task.getTaskCode(), e);
log.error("璇锋眰RCS-璇锋眰鍦板潃锛歿}", pubTakUrl);
log.error("璇锋眰RCS-璇锋眰鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
// 妫�鏌ユ槸鍚︽槸杩炴帴瓒呮椂寮傚父
@@ -1887,16 +2000,15 @@
} catch (Exception e) {
long endTime = System.currentTimeMillis();
log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
- log.error("璇锋眰RCS-寮傚父锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}", (endTime - startTime), task.getTaskCode(), e);
- log.error("璇锋眰RCS-鍦板潃锛歿}", pubTakUrl);
- log.error("璇锋眰RCS-鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
String errorMsg = e.getMessage();
// 妫�鏌ユ槸鍚︽槸杩炴帴瓒呮椂鐩稿叧鐨勫紓甯�
if (errorMsg != null && (errorMsg.contains("Connection timed out") || errorMsg.contains("timed out") || errorMsg.contains("timeout"))) {
- log.error("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+ log.error("璇锋眰RCS-杩炴帴瓒呮椂寮傚父锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}锛岄敊璇俊鎭細{}-{}", (endTime - startTime), task.getTaskCode(), e, errorMsg);
} else {
- log.error("RCS浠诲姟涓嬪彂寮傚父锛佷换鍔$紪鐮侊細{}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+ log.error("璇锋眰RCS-寮傚父锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}锛岄敊璇俊鎭細{}-{}", (endTime - startTime), task.getTaskCode(), e, errorMsg);
}
+ log.error("璇锋眰RCS-鍦板潃锛歿}", pubTakUrl);
+ log.error("璇锋眰RCS-鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
continue;
}
@@ -2029,18 +2141,37 @@
@Transactional(rollbackFor = Exception.class)
public void subtractLocItemByTaskItems(Loc loc, List<TaskItem> taskItems, Long loginUserId) {
for (TaskItem taskItem : taskItems) {
- // 鏌ヨ瀵瑰簲鐨勫簱浣嶆槑缁�
- LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
+ LambdaQueryWrapper<LocItem> locItemWrapper = new LambdaQueryWrapper<LocItem>()
.eq(LocItem::getLocId, loc.getId())
- .eq(LocItem::getMatnrId, taskItem.getMatnrId())
- .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
- .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
+ .eq(LocItem::getMatnrId, taskItem.getMatnrId());
+ if (StringUtils.isNotBlank(taskItem.getBatch())) {
+ locItemWrapper.eq(LocItem::getBatch, taskItem.getBatch());
+ } else {
+ locItemWrapper.and(w -> w.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, ""));
+ }
+ if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) {
+ locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex());
+ } else {
+ locItemWrapper.and(w -> w.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, ""));
+ }
+ LocItem locItem = locItemService.getOne(locItemWrapper);
+
+ log.info("[鎷f枡鍏ュ簱-鎵e噺搴撲綅] taskItemId={}, locId={}, matnrId={}, batch={}, fieldsIndex={}, locItem={}, locItem.anfme={}, taskItem.qty={}, taskItem.anfme={}",
+ taskItem.getId(), loc.getId(), taskItem.getMatnrId(), taskItem.getBatch(), taskItem.getFieldsIndex(),
+ locItem != null ? "瀛樺湪" : "null", locItem != null ? locItem.getAnfme() : null, taskItem.getQty(), taskItem.getAnfme());
if (Objects.nonNull(locItem)) {
- // 璁$畻鎵e噺鍚庣殑鏁伴噺
- Double newAnfme = Math.round((locItem.getAnfme() - taskItem.getQty()) * 1000000) / 1000000.0;
-
- if (newAnfme.compareTo(0.0) <= 0) {
+ // 鎵e噺閲忥細浼樺厛鐢ㄦ湰娆℃嫞鏂欐暟閲� taskItem.getQty()锛涜嫢涓� 0 涓� taskItem.anfme 宸蹭负鍓╀綑鏁伴噺锛屽垯鎵e噺 = 鍘熷簱浣� - 鍓╀綑锛堢敤 BigDecimal 閬垮厤 Double 绮惧害闂锛�
+ Double deductQty = QuantityUtils.isPositive(taskItem.getQty())
+ ? taskItem.getQty()
+ : (taskItem.getAnfme() != null && QuantityUtils.compare(taskItem.getAnfme(), locItem.getAnfme()) < 0
+ ? QuantityUtils.subtract(locItem.getAnfme(), taskItem.getAnfme())
+ : 0.0);
+ Double newAnfme = QuantityUtils.subtract(locItem.getAnfme(), deductQty);
+ log.info("[鎷f枡鍏ュ簱-鎵e噺搴撲綅] locItemId={}, deductQty={}, 鍘焌nfme={}, newAnfme={}, 鎿嶄綔={}",
+ locItem.getId(), deductQty, locItem.getAnfme(), newAnfme, QuantityUtils.isNonPositive(newAnfme) ? "鍒犻櫎" : "鏇存柊");
+
+ if (QuantityUtils.isNonPositive(newAnfme)) {
// 鏁伴噺灏忎簬绛変簬0锛屽垹闄ゅ簱浣嶆槑缁�
locItemService.removeById(locItem.getId());
} else {
@@ -2052,6 +2183,9 @@
throw new CoolException("搴撲綅鏄庣粏鏁伴噺鎵e噺澶辫触锛侊紒");
}
}
+ } else {
+ log.warn("[鎷f枡鍏ュ簱-鎵e噺搴撲綅] 鏈煡鍒板簱浣嶆槑缁� locId={}, matnrId={}, batch={}, fieldsIndex={}锛屾湭鎵e噺",
+ loc.getId(), taskItem.getMatnrId(), taskItem.getBatch(), taskItem.getFieldsIndex());
}
}
}
@@ -2095,10 +2229,10 @@
List<TaskItem> items = orderMap.get(key);
//淇濆瓨鍏ュ嚭搴撴槑缁�
saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
- //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵�侊紙鍙湁褰搒ource涓嶄负null鏃舵墠闇�瑕佺Щ闄ゆ敹璐у尯搴撳瓨锛�
- if (Objects.nonNull(pakinItem.getSource())) {
- removeReceiptStock(pakinItem, loginUserId);
- }
+ // 鏀惰揣鍖哄凡鍋滅敤锛屼笉鍐嶇Щ鍑烘敹璐у尯搴撳瓨
+ // if (Objects.nonNull(pakinItem.getSource())) {
+ // removeReceiptStock(pakinItem, loginUserId);
+ // }
});
Set<Long> pkinItemIds = taskItems.stream().map(TaskItem::getSource).collect(Collectors.toSet());
@@ -2122,6 +2256,8 @@
if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
}
+ // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氬叆搴撳畬鎴愬悗閫氱煡浜戜粨
+ reportInOutResultToCloud(task, loc, taskItems, pkinItemIds, true);
}
/**
@@ -2181,12 +2317,26 @@
throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
}
LocItem item = new LocItem();
- LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
+ // 鏋勫缓鏌ヨ鏉′欢锛氶渶瑕佸悓鏃跺尮閰嶇墿鏂橧D銆佸簱浣岻D銆佹壒娆″拰绁ㄥ彿
+ LambdaQueryWrapper<LocItem> locItemWrapper = new LambdaQueryWrapper<LocItem>()
.eq(LocItem::getMatnrId, taskItem.getMatnrId())
- .eq(LocItem::getLocId, loc.getId())
- .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
- .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex())
- );
+ .eq(LocItem::getLocId, loc.getId());
+
+ // 鎵规鍖归厤锛氬鏋渢askItem鏈夋壒娆★紝鍒欏繀椤诲尮閰嶏紱濡傛灉taskItem娌℃湁鎵规锛屽垯鏌ヨ鎵规涓簄ull鎴栫┖瀛楃涓茬殑璁板綍
+ if (StringUtils.isNotBlank(taskItem.getBatch())) {
+ locItemWrapper.eq(LocItem::getBatch, taskItem.getBatch());
+ } else {
+ locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, ""));
+ }
+
+ // 绁ㄥ彿鍖归厤锛氬鏋渢askItem鏈夌エ鍙凤紝鍒欏繀椤诲尮閰嶏紱濡傛灉taskItem娌℃湁绁ㄥ彿锛屽垯鏌ヨ绁ㄥ彿涓簄ull鎴栫┖瀛楃涓茬殑璁板綍
+ if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) {
+ locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex());
+ } else {
+ locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, ""));
+ }
+
+ LocItem locItem = locItemService.getOne(locItemWrapper);
if (Objects.isNull(locItem)) {
// 搴撲綅鏄庣粏涓嶅瓨鍦紝鍒涘缓鏂扮殑搴撲綅鏄庣粏
BeanUtils.copyProperties(taskItem, item);
@@ -2276,4 +2426,72 @@
}
}
}
+
+ /**
+ * 9.1 鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙
+ * @param isInbound true 鍏ュ簱瀹屾垚锛宖alse 鍑哄簱瀹屾垚
+ * @param pkinItemIds 鍏ュ簱鏃剁粍鎵樻槑缁� ID 闆嗗悎锛岀敤浜庢煡 asnCode 浣滀负 orderNo锛涘嚭搴撴椂浼� null锛岀敤 taskItem.platOrderCode
+ */
+ private void reportInOutResultToCloud(Task task, Loc loc, List<TaskItem> taskItems, Set<Long> pkinItemIds, boolean isInbound) {
+ try {
+ String locId = isInbound ? task.getTargLoc() : task.getOrgLoc();
+ String wareHouseId = null;
+ if (loc.getWarehouseId() != null) {
+ Warehouse wh = warehouseService.getById(loc.getWarehouseId());
+ if (wh != null) {
+ wareHouseId = wh.getCode();
+ }
+ }
+ if (wareHouseId == null) {
+ log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙璺宠繃锛氫粨搴撶紪鐮佷负绌猴紝taskId={}", task.getId());
+ return;
+ }
+ Map<Long, String> sourceToOrderNo = new HashMap<>();
+ if (isInbound && pkinItemIds != null && !pkinItemIds.isEmpty()) {
+ List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getId, pkinItemIds));
+ for (WaitPakinItem p : pakinItems) {
+ if (p.getAsnCode() != null) {
+ sourceToOrderNo.put(p.getId(), p.getAsnCode());
+ }
+ }
+ }
+ ObjectMapper om = new ObjectMapper();
+ Date now = new Date();
+ for (TaskItem item : taskItems) {
+ String orderNo = isInbound ? sourceToOrderNo.get(item.getSource()) : (item.getPlatOrderCode() != null ? item.getPlatOrderCode() : item.getPlatWorkCode());
+ if (orderNo == null && isInbound) {
+ orderNo = item.getPlatOrderCode() != null ? item.getPlatOrderCode() : item.getPlatWorkCode();
+ }
+ if (orderNo == null || item.getMatnrCode() == null) {
+ continue;
+ }
+ InOutResultReportParam param = new InOutResultReportParam()
+ .setOrderNo(orderNo)
+ .setPlanNo(item.getPlatWorkCode())
+ .setLineId(item.getPlatItemId())
+ .setWareHouseId(wareHouseId)
+ .setLocId(locId)
+ .setMatNr(item.getMatnrCode())
+ .setQty(item.getAnfme() != null ? String.valueOf(item.getAnfme()) : "0")
+ .setBatch(item.getBatch());
+ try {
+ String requestBody = om.writeValueAsString(param);
+ CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog()
+ .setReportType(cloudWmsNotifyLogService.getReportTypeInOutResult())
+ .setRequestBody(requestBody)
+ .setNotifyStatus(cloudWmsNotifyLogService.getNotifyStatusPending())
+ .setRetryCount(0)
+ .setBizRef("taskId=" + task.getId() + ",orderNo=" + orderNo)
+ .setCreateTime(now)
+ .setUpdateTime(now);
+ cloudWmsNotifyLogService.fillFromConfig(notifyLog);
+ cloudWmsNotifyLogService.save(notifyLog);
+ } catch (JsonProcessingException e) {
+ log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙钀藉簱澶辫触锛堜笉褰卞搷涓绘祦绋嬶級锛宼askId={}锛宱rderNo={}锛歿}", task.getId(), orderNo, e.getMessage());
+ }
+ }
+ } catch (Exception e) {
+ log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙澶辫触锛宼askId={}锛宨sInbound={}锛歿}", task.getId(), isInbound, e.getMessage());
+ }
+ }
}
--
Gitblit v1.9.1