From 8b8c347b921846ed07b310bba2d7646333bf98cb Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期三, 26 十一月 2025 13:09:50 +0800
Subject: [PATCH] 任务下发功能优化
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java | 509 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 399 insertions(+), 110 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 1365f70..484ccf4 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
@@ -1,10 +1,21 @@
package com.vincent.rsf.server.manager.service.impl;
+import com.alibaba.fastjson.JSONObject;
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.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.server.api.controller.params.TaskInParam;
+import com.vincent.rsf.framework.common.DateUtils;
+import com.vincent.rsf.server.api.config.RemotesInfoProperties;
+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;
import com.vincent.rsf.server.api.entity.dto.InTaskMsgDto;
+import com.vincent.rsf.server.api.entity.params.TaskItemParam;
+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.manager.controller.params.LocToTaskParams;
@@ -18,23 +29,34 @@
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vincent.rsf.server.manager.utils.LocManageUtil;
+import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.constant.SerialRuleCode;
import com.vincent.rsf.server.manager.enums.LocStsType;
+import com.vincent.rsf.server.system.entity.Config;
+import com.vincent.rsf.server.system.service.ConfigService;
+import com.vincent.rsf.server.system.service.impl.ConfigServiceImpl;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import com.vincent.rsf.server.system.utils.SystemAuthUtils;
import lombok.Synchronized;
+import lombok.extern.slf4j.Slf4j;
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.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
+@Slf4j
@Service("taskService")
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
@@ -92,6 +114,14 @@
private CheckDiffService checkDiffService;
@Autowired
private CheckDiffItemService checkDiffItemService;
+ @Autowired
+ private BasContainerService basContainerService;
+ @Autowired
+ private ConfigService configService;
+ @Autowired
+ private RestTemplate restTemplate;
+ @Autowired
+ private RemotesInfoProperties.RcsApi rcsApi;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -286,7 +316,7 @@
if (Objects.isNull(deviceSite)) {
throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
}
- DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(Integer.valueOf(deviceSite.getSite())));
+ DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(deviceSite.getSite()));
if (Cools.isEmpty(deviceBind)) {
throw new CoolException("搴撲綅瑙勫垯鏈煡");
}
@@ -304,8 +334,13 @@
throw new CoolException("璇锋鏌ョ粍鎷栫姸鎬佹槸鍚﹀畬鎴愶紒锛�");
}
waitPakins.forEach(pakin -> {
+ BasContainer container = basContainerService.getOne(new LambdaUpdateWrapper<BasContainer>()
+ .eq(BasContainer::getCode, pakin.getBarcode()));
+ if (Objects.isNull(container)) {
+ throw new CoolException("瀹瑰櫒鏈淮鎶ゅ叆搴擄紝璇风淮鎶ゅ悗鍐嶆搷浣滐紒锛�");
+ }
/**鑾峰彇搴撲綅*/
- String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId());
+ String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId(), container.getContainerType());
if (Cools.isEmpty(targetLoc)) {
throw new CoolException("璇ョ珯鐐瑰搴斿簱鍖烘湭鎵惧埌搴撲綅");
}
@@ -346,6 +381,18 @@
if (!this.save(task)) {
throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
}
+ BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+ .eq(BasStation::getStationName, deviceSite.getSite()));
+ if (Objects.isNull(station) || !station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦ㄦ垨绔欑偣涓嶅浜庣┖搴撶姸鎬侊紒锛�");
+ }
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+ }
+
+
if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
.set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
@@ -405,22 +452,27 @@
* @param tasks
* @throws Exception
*/
- @Synchronized
@Override
- @Transactional(rollbackFor = Exception.class)
public void complateInTask(List<Task> tasks) throws Exception {
- Long loginUserId = SystemAuthUtils.getLoginUserId();
- for (Task task : tasks) {
- if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
- //1.鍏ュ簱
- 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.鐩樼偣鍐嶅叆搴�
- pickComplateInStock(task, loginUserId);
- } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
- //绉诲簱
- moveInStock(task, loginUserId);
+ AtomicBoolean success = new AtomicBoolean(false);
+ if (success.compareAndSet(false, true)) {
+ Long loginUserId = SystemAuthUtils.getLoginUserId();
+ for (Task task : tasks) {
+ try {
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
+ //1.鍏ュ簱
+ 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.鐩樼偣鍐嶅叆搴�
+ pickComplateInStock(task, loginUserId);
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ //绉诲簱
+ moveInStock(task, loginUserId);
+ }
+ } catch (Exception ex) {
+ log.error(ex.getMessage(), ex);
+ }
}
}
}
@@ -590,7 +642,7 @@
//鏇存柊搴撲綅鏄庣粏
saveLocItem(taskItems, task.getId(), loginUserId);
} catch (Exception e) {
- throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
+ throw new CoolException("浠诲姟鍙凤細" + task.getTaskCode() + "搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
}
if (!locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, task.getOrgLoc()))) {
@@ -635,20 +687,15 @@
*/
@Synchronized
@Override
- @Transactional(rollbackFor = Exception.class)
- public void completeTask(List<Task> tasks) throws Exception {
+ public void completeTask(List<Task> tasks) {
Long loginUserId = SystemAuthUtils.getLoginUserId();
for (Task task : tasks) {
//鍑哄簱浠诲姟
- if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
- //鍏ㄦ墭鍑哄簱
+ try {
complateOutStock(task, loginUserId);
- } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) {
- //鎷f枡鍑哄簱
- complateOutStock(task, loginUserId);
- } else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
- //鐩樼偣鍑哄簱
- complateOutStock(task, loginUserId);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+// throw new CoolException(e.getMessage());
}
}
}
@@ -668,10 +715,9 @@
if (Objects.isNull(loc)) {
throw new CoolException("搴撳瓨涓嶅瓨鍦紒锛�");
}
- if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) {
- throw new CoolException("褰撳墠搴撲綅鐘舵�佷笉澶勪簬S.鍏ュ簱棰勭害锛屼笉鍙墽琛屽叆搴撴搷浣滐紒");
- }
-
+// if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) {
+// throw new CoolException("褰撳墠搴撲綅鐘舵�佷笉澶勪簬S.鍏ュ簱棰勭害锛屼笉鍙墽琛屽叆搴撴搷浣滐紒");
+// }
loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
.setBarcode(task.getBarcode())
.setUpdateBy(loginUserId).setUpdateTime(new Date());
@@ -690,6 +736,7 @@
LocItem locItem = new LocItem();
LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
.eq(LocItemWorking::getTaskId, taskItem.getTaskId())
+ .eq(LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
.eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
.eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
if (Objects.isNull(locWorking)) {
@@ -711,9 +758,7 @@
//淇濆瓨鍏ュ嚭搴撴祦姘�
saveStockItems(taskItems, task, null, null, taskItem.getWkType(), taskItem.getOrderType(), loginUserId);
- if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
- throw new CoolException("浣滀笟涓簱瀛樺垹闄ゅけ璐ワ紒锛�");
- }
+ locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()));
task.setTaskStatus(TaskStsType.UPDATED_IN.id).setUpdateTime(new Date()).setUpdateBy(loginUserId);
if (!taskService.updateById(task)) {
@@ -775,7 +820,6 @@
} else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, Arrays.asList(ids)));
if (!taskItems.isEmpty()) {
-
taskItems.forEach(taskItem -> {
if (!checkOrderItemService.update(new LambdaUpdateWrapper<WkOrderItem>()
.eq(WkOrderItem::getId, taskItem.getOrderItemId())
@@ -855,7 +899,7 @@
if (Objects.isNull(waveItem)) {
throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
}
- Double workQty = Math.round((waveItem.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
+ Double workQty = Math.round((waveItem.getWorkQty() - item.getAnfme()) * 100) / 100.0;
waveItem.setWorkQty(workQty).setExceStatus(WaveItemExceStatus.WAVE_ITEM_EXCE_STATUS_UN.val);
if (!waveItemService.updateById(waveItem)) {
throw new CoolException("娉㈡鏄庣粏鏇存柊澶辫触锛侊紒");
@@ -879,7 +923,7 @@
if (Objects.isNull(wkOrder)) {
throw new CoolException("鏁版嵁閿欒锛氬崟鎹凡涓嶅瓨鍦紒锛�");
}
- Double workQty = Math.round((wkOrder.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
+ Double workQty = Math.round((wkOrder.getWorkQty() - item.getAnfme()) * 100) / 100.0;
wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)
.setWorkQty(workQty.compareTo(0.00) > 0 ? workQty : 0.00)
@@ -894,7 +938,7 @@
throw new CoolException("鏁版嵁閿欒锛氬崟鎹槑缁嗗凡涓嶅瓨鍦紒锛�");
}
- Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
+ Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 100) / 100.0;
orderItem.setWorkQty(workItmQty);
if (!outStockItemService.updateById(orderItem)) {
@@ -977,7 +1021,7 @@
.setTaskStatus(TaskStsType.GENERATE_IN.id);
TaskInParam param = new TaskInParam();
- param.setSourceStaNo(Integer.parseInt(task.getTargSite()))
+ param.setSourceStaNo(task.getTargSite())
.setIoType(type)
.setLocType1(Integer.parseInt(loc.getType()));
//鑾峰彇鏂板簱浣�
@@ -986,7 +1030,8 @@
if (Objects.isNull(locInfo)) {
throw new CoolException("鑾峰彇搴撲綅澶辫触锛侊紒");
}
- task.setTargLoc(locInfo.getLocNo());
+ task.setTargLoc(locInfo.getLocNo())
+ .setOrgSite(task.getTargSite());
if (!this.updateById(task)) {
throw new CoolException("浠诲姟鐘舵�佹洿鏂板け璐ワ紒锛�");
@@ -1003,10 +1048,10 @@
tempLocs.forEach(working -> {
taskItems.forEach(taskItem -> {
- if (taskItem.getMatnrId().equals(working.getMatnrId())) {
+ if (taskItem.getId().equals(working.getMatnrId()) && taskItem.getFieldsIndex().equals(working.getFieldsIndex())) {
Double minQty = taskItem.getAnfme();
if (!task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
- minQty = Math.round((working.getAnfme() - taskItem.getAnfme()) * 10000) / 10000.0;
+ minQty = Math.round((working.getAnfme() - taskItem.getAnfme()) * 100) / 100.0;
}
if (minQty.compareTo(0.0) > 0) {
taskItem.setAnfme(minQty);
@@ -1015,18 +1060,16 @@
}
} else {
if (!taskItemService.removeById(taskItem)) {
- throw new CoolException("浠诲姟鏄庣粏淇敼澶辫触锛侊紒");
+ log.error("浠诲姟鏄庣粏淇敼澶辫触锛侊紒");
}
}
}
-
-
});
});
- List<Long> matnrIds = taskItems.stream().map(TaskItem::getMatnrId).collect(Collectors.toList());
+ List<String> matnrIds = taskItems.stream().map(TaskItem::getFieldsIndex).collect(Collectors.toList());
//鍒犻櫎涓庝换鍔℃槑缁嗛噸澶嶇殑搴撳瓨淇℃伅锛屼互浠诲姟鏄庣粏涓哄噯
List<LocItemWorking> itemWorkings = tempLocs.stream()
- .filter(working -> !matnrIds.contains(working.getMatnrId()))
+ .filter(working -> !matnrIds.contains(working.getFieldsIndex()))
.collect(Collectors.toList());
itemWorkings.forEach(working -> {
TaskItem taskItem = taskItems.stream().findFirst().get();
@@ -1036,6 +1079,7 @@
.setMatnrCode(working.getMatnrCode())
.setSpec(working.getSpec())
.setAnfme(working.getAnfme())
+ .setQty(0.0)
.setBatch(working.getBatch())
.setFieldsIndex(working.getFieldsIndex())
.setUnit(working.getUnit())
@@ -1056,10 +1100,14 @@
List<LocItemWorking> workings = new ArrayList<>();
List<TaskItem> items = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
items.forEach(taskItem -> {
- LocItemWorking itemWorking = new LocItemWorking();
- BeanUtils.copyProperties(taskItem, itemWorking);
- itemWorking.setTaskId(task.getId()).setLocId(loc1.getId()).setLocCode(loc1.getCode());
- workings.add(itemWorking);
+ if (taskItem.getAnfme() > 0) {
+ LocItemWorking itemWorking = new LocItemWorking();
+ BeanUtils.copyProperties(taskItem, itemWorking);
+ itemWorking.setTaskId(task.getId())
+ .setLocId(loc1.getId())
+ .setLocCode(loc1.getCode());
+ workings.add(itemWorking);
+ }
});
if (!locItemWorkingService.saveBatch(workings)) {
@@ -1143,24 +1191,28 @@
if (Objects.isNull(waveItem)) {
throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
}
- try {
- saveOutStockItem(maps.get(key), null, waveItem, null, loginUserId);
- } catch (Exception e) {
- throw new CoolException(e.getMessage());
- }
- } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val) || task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) {
- WkOrderItem orderItem = new WkOrderItem();
- if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) {
- CheckDiffItem diffItem = checkDiffItemService.getById(key);
- } else {
- orderItem = asnOrderItemService.getById(key);
-
- }
+// try {
+// saveOutStockItem(maps.get(key), null, waveItem, null, loginUserId);
+// } catch (Exception e) {
+// throw new CoolException(e.getMessage());
+// }
+ } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) {
+ WkOrderItem orderItem = asnOrderItemService.getById(key);
if (Objects.isNull(orderItem)) {
throw new CoolException("鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
}
try {
- saveOutStockItem(maps.get(key), orderItem, null, null, loginUserId);
+ saveOutStockItem(maps.get(key), orderItem, loginUserId);
+ } catch (Exception e) {
+ throw new CoolException(e.getMessage());
+ }
+ } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) {
+ WkOrderItem orderItem = asnOrderItemService.getById(key);
+ if (Objects.isNull(orderItem)) {
+ throw new CoolException("鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
+ }
+ try {
+ saveOutStockItem(maps.get(key), null, null, orderItem, loginUserId);
} catch (Exception e) {
throw new CoolException(e.getMessage());
}
@@ -1186,27 +1238,35 @@
throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
}
- 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>()
- .eq(Task::getId, task.getId())
- .set(Task::getUpdateBy, loginUserId)
- .set(Task::getUpdateTime, new Date())
- .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
- throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
- }
- } else {
- if (!this.update(new LambdaUpdateWrapper<Task>()
- .eq(Task::getId, task.getId())
- .set(Task::getUpdateBy, loginUserId)
- .set(Task::getUpdateTime, new Date())
- .set(Task::getTaskStatus, TaskStsType.UPDATED_OUT.id))) {
- throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
- }
- //鍏ㄦ澘鍑哄簱锛屽垹闄や复鏃跺簱瀛�
- if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
- throw new CoolException("涓存椂搴撳瓨娓呴櫎澶辫触锛侊紒");
- }
+ if (!this.update(new LambdaUpdateWrapper<Task>()
+ .eq(Task::getId, task.getId())
+ .set(Task::getUpdateBy, loginUserId)
+ .set(Task::getUpdateTime, new Date())
+ .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
+ throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
}
+
+// 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>()
+// .eq(Task::getId, task.getId())
+// .set(Task::getUpdateBy, loginUserId)
+// .set(Task::getUpdateTime, new Date())
+// .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
+// throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
+// }
+// } else {
+// if (!this.update(new LambdaUpdateWrapper<Task>()
+// .eq(Task::getId, task.getId())
+// .set(Task::getUpdateBy, loginUserId)
+// .set(Task::getUpdateTime, new Date())
+// .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
+// throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
+// }
+//// //鍏ㄦ澘鍑哄簱锛屽垹闄や复鏃跺簱瀛�
+//// if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
+//// throw new CoolException("涓存椂搴撳瓨娓呴櫎澶辫触锛侊紒");
+//// }
+// }
}
@@ -1217,7 +1277,7 @@
* @version 1.0
*/
@Transactional(rollbackFor = Exception.class)
- public void saveOutStockItem(List<TaskItem> taskItems, CheckDiffItem diffItem, Long loginUserId) {
+ public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem diffItem, Long loginUserId) {
try {
saveOutStockItem(taskItems, null, null, diffItem, loginUserId);
} catch (Exception e) {
@@ -1231,8 +1291,9 @@
* @description: 鍑哄簱淇℃伅淇濆瓨鑷冲簱瀛樻槑缁嗚〃
* @version 1.0
*/
+ @Override
@Transactional(rollbackFor = Exception.class)
- public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem orderItem, WaveItem waveItem, CheckDiffItem diffItem, Long loginUserId) throws Exception {
+ public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem orderItem, WaveItem waveItem, WkOrderItem diffItem, Long loginUserId) throws Exception {
Stock stock = new Stock();
String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
if (StringUtils.isBlank(ruleCode)) {
@@ -1243,20 +1304,26 @@
.setUpdateBy(loginUserId)
.setUpdateTime(new Date())
.setAnfme(sum);
- if (Objects.isNull(waveItem)) {
- stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))
- .setMemo("搴撳瓨鍑哄簱锛屾棤鍗曟嵁淇℃伅锛侊紒")
- .setType(OrderType.ORDER_OUT.type);
+ if (!Objects.isNull(waveItem)) {
+ //TODO 鐢熸垚娉㈡鏃堕渶瑕佸皢娉㈡鍙峰啓鍏ュ崟鎹紝閫氳繃鐗╂枡锛屾壒娆★紝鍔ㄦ�佸瓧娈电瓑鍞竴鍊煎弽鏌ュ崟鎹俊鎭�
+ stock.setSourceId(waveItem.getId()).setType(OrderType.ORDER_OUT.type);
} else if (!Objects.isNull(orderItem) && StringUtils.isNotBlank(orderItem.getId() + "")) {
WkOrder wkOrder = asnOrderService.getById(orderItem.getOrderId());
+ Double qty = Math.round((wkOrder.getQty() + sum) * 100) / 100.0;
+ wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val)
+ .setQty(qty);
+ if (!asnOrderService.updateById(wkOrder)) {
+ throw new CoolException("鍑哄簱鍗曟洿鏂板け璐ワ紒锛�");
+ }
stock.setWkType(Short.parseShort(wkOrder.getWkType()))
.setType(OrderType.ORDER_OUT.type);
} else if (!Objects.isNull(diffItem)) {
stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_CHECK.type))
.setType(OrderType.ORDER_CHECK.type);
} else {
- //TODO 鐢熸垚娉㈡鏃堕渶瑕佸皢娉㈡鍙峰啓鍏ュ崟鎹紝閫氳繃鐗╂枡锛屾壒娆★紝鍔ㄦ�佸瓧娈电瓑鍞竴鍊煎弽鏌ュ崟鎹俊鎭�
- stock.setSourceId(waveItem.getId()).setType(OrderType.ORDER_OUT.type);
+ stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))
+ .setMemo("搴撳瓨鍑哄簱锛屾棤鍗曟嵁淇℃伅锛侊紒")
+ .setType(OrderType.ORDER_OUT.type);
}
if (!stockService.save(stock)) {
throw new CoolException("搴撳瓨淇濆瓨澶辫触锛侊紒");
@@ -1277,8 +1344,207 @@
if (!stockItemService.saveBatch(stockItems)) {
throw new CoolException("搴撳瓨淇敼鏋跺け璐ワ紒锛�");
}
-
}
+
+
+ /**
+ * 鎵嬪姩涓嬪彂鎵ц浠诲姟
+ * @author Ryan
+ * @date 2025/11/22 13:45
+ * @param ids
+ * @return com.vincent.rsf.framework.common.R
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public R menualExceTask(List<Long> ids) {
+ if (Objects.isNull(ids) || ids.isEmpty()) {
+ return R.error("浠诲姟缂栫爜涓嶈兘涓虹┖锛侊紒");
+ }
+ List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
+ List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
+ .in(Task::getId, ids)
+ .in(Task::getTaskStatus, integers)
+ .orderByDesc(Task::getSort));
+ if (tasks.isEmpty()) {
+ return R.error("浠诲姟宸插湪鎵ц涓紒锛�");
+ }
+ Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_CHECK_ORDERS));
+ if (!Objects.isNull(config) && !Objects.isNull(config.getVal())) {
+ if (Boolean.parseBoolean(config.getVal())) {
+ return R.error("鑷姩鐢熸垚浠诲姟宸插紑鍚紝鏃犻渶鎵嬪姩涓嬪彂锛侊紒");
+ }
+ }
+
+ taskService.pubTaskToWcs(tasks);
+
+ return R.ok();
+ }
+
+
+ /**
+ * 涓嬪彂浠诲姟鑷砏CS
+ *
+ * @param tasks
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void pubTaskToWcs(List<Task> tasks) {
+ WcsTaskParams taskParams = new WcsTaskParams();
+ List<TaskItemParam> items = new ArrayList<>();
+ tasks.forEach(task -> {
+ TaskItemParam itemParam = new TaskItemParam();
+ //浠诲姟绫诲瀷锛屼换鍔$紪鐮�
+ itemParam.setTaskType(RcsTaskType.getTypeDesc(task.getTaskType()))
+ .setSeqNum(task.getTaskCode());
+ //涓诲弬鏁�
+ taskParams.setBatch(task.getBarcode());
+ BasStation station = null;
+ if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
+ if (Objects.isNull(station)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+ }
+ }
+
+ /**鍒ゆ柇鏄惁鍏夌數绔欑偣锛岄潪鍏夊簵绔欑偣闇�绠℃帶绔欑偣鐘舵��*/
+ if (!Objects.isNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+ }
+ } else if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type) {
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+ }
+ }
+ }
+
+ /**绉诲簱鍙傛暟*/
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ itemParam.setOriLoc(task.getOrgLoc()).setDestLoc(task.getTargLoc());
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
+ /**鍏ㄦ澘鍏ュ簱鍙傛暟*/
+ itemParam.setDestLoc(task.getTargLoc())
+ .setOriSta(task.getOrgSite());
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)) {
+ /**鎷f枡/鐩樼偣鍏ュ簱鍙傛暟*/
+ itemParam.setDestLoc(task.getTargLoc())
+ .setOriSta(task.getTargSite());
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)) {
+ /**鍑哄簱鍙傛暟*/
+ itemParam.setOriLoc(task.getOrgLoc())
+ .setDestSta(task.getTargSite());
+ } else {
+ /**绔欑偣闂寸Щ搴撳弬鏁�*/
+ itemParam.setOriSta(task.getOrgSite()).setDestSta(task.getTargSite());
+
+ BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
+ if (Objects.isNull(curSta)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+ }
+ if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ if (!curSta.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+ throw new CoolException("褰撳墠绔欑偣涓嶆槸F.鍦ㄥ簱鐘舵�侊紒锛�");
+ }
+ }
+ if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+ throw new CoolException("鐩爣绔欑偣涓嶆槸O.绌洪棽鐘舵�侊紒锛�");
+ }
+ }
+ }
+ items.add(itemParam);
+ });
+ taskParams.setTaskList(items);
+ /**浠诲姟涓嬪彂鎺ュ彛*/
+ String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
+ /**RCS鍩虹閰嶇疆閾炬帴*/
+ log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl, JSONObject.toJSONString(taskParams));
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("Content-Type", "application/json");
+ headers.add("api-version", "v2.0");
+ HttpEntity httpEntity = new HttpEntity(taskParams, headers);
+ ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class);
+ log.info("浠诲姟涓嬪彂鍚庯紝鍝嶅簲缁撴灉锛� {}", exchange);
+ if (Objects.isNull(exchange.getBody())) {
+ throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+ } else {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.coercionConfigDefaults()
+ .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+ CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+ if (result.getCode() == 200) {
+ tasks.forEach(task -> {
+
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+
+ BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
+ if (Objects.isNull(curSta)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+ }
+
+ if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
+ .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) {
+ throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ }
+ /**鎺掗櫎绉诲簱鍔熻兘*/
+ if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍑哄簱棰勭害*/
+ if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ curSta.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+ if (!basStationService.updateById(curSta)) {
+ throw new CoolException("绔欑偣棰勭害澶辫触锛侊紒");
+ }
+ }
+ }
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) {
+ BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
+ if (Objects.isNull(curSta)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+ }
+
+ if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
+ .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) {
+ throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ }
+ /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍏ュ簱棰勭害*/
+ if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ curSta.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+ if (!basStationService.updateById(curSta)) {
+ throw new CoolException("绔欑偣棰勭害澶辫触锛侊紒");
+ }
+ }
+ }
+ });
+ } else {
+ log.error(JSONObject.toJSONString(result));
+// throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+ }
+ } catch (JsonProcessingException e) {
+ throw new CoolException(e.getMessage());
+ }
+ }
+
+ }/**
+
/**
* @author Ryan
@@ -1300,7 +1566,7 @@
* @version 1.0
*/
@Transactional(rollbackFor = Exception.class)
- public void complateInstock(Task task, Long loginUserId) {
+ public synchronized void complateInstock(Task task, Long loginUserId) {
if (Objects.isNull(task)) {
return;
}
@@ -1361,14 +1627,14 @@
* @time 2025/4/30 16:32
*/
@Transactional(rollbackFor = Exception.class)
- public void removeReceiptStock(WaitPakinItem pakinItem, Long loginUserId) {
+ public synchronized void removeReceiptStock(WaitPakinItem pakinItem, Long loginUserId) {
WarehouseAreasItem itemServiceOne = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>()
.eq(WarehouseAreasItem::getId, pakinItem.getSource()));
if (Objects.isNull(itemServiceOne)) {
throw new CoolException("鏁版嵁閿欒锛氳鏌ョ湅璇疯揣鍖哄簱瀛樻槸鍚﹀瓨鍦紒锛�");
}
- Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 10000) / 10000.0;
- Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 10000) / 10000.0;
+ Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 100) / 100.0;
+ Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 100) / 100.0;
itemServiceOne.setWorkQty(workQty).setQty(qty);
if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
@@ -1399,7 +1665,7 @@
* @time 2025/4/15 15:28
*/
@Transactional(rollbackFor = Exception.class)
- public void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) throws Exception {
+ public synchronized void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) throws Exception {
Task task = this.getById(taskId);
if (Objects.isNull(task)) {
throw new CoolException("浠诲姟涓嶅瓨鍦�!!");
@@ -1408,14 +1674,29 @@
List<LocItem> locItems = new ArrayList<>();
items.forEach(taskItem -> {
Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()), false);
+ if (Objects.isNull(loc)) {
+ throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
+ }
LocItem item = new LocItem();
- BeanUtils.copyProperties(taskItem, item);
- item.setLocCode(loc.getCode()).setId(null)
- .setLocId(loc.getId())
- .setUpdateBy(loginUserId)
- .setWkType(taskItem.getWkType())
- .setType(taskItem.getOrderType());
- locItems.add(item);
+ LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
+ .eq(LocItem::getMatnrId, taskItem.getMatnrId())
+ .eq(LocItem::getLocId, loc.getId())
+ .eq(StringUtils.isNoneBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
+ .eq(StringUtils.isNoneBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
+ if (Objects.isNull(locItem)) {
+ BeanUtils.copyProperties(taskItem, item);
+ item.setLocCode(loc.getCode())
+ .setId(null)
+ .setLocId(loc.getId())
+ .setUpdateBy(loginUserId)
+ .setWkType(taskItem.getWkType())
+ .setType(taskItem.getOrderType());
+ locItems.add(item);
+ } else {
+ locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 100) / 100.0)
+ .setUpdateTime(new Date());
+ locItems.add(locItem);
+ }
});
if (!locItemService.saveBatch(locItems)) {
throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
@@ -1430,8 +1711,7 @@
* @return
*/
@Transactional(rollbackFor = Exception.class)
- public void saveStockItems(List<TaskItem> items, Task task, Long id, String code, Short wkType, String type, Long loginUserId) throws
- Exception {
+ public synchronized void saveStockItems(List<TaskItem> items, Task task, Long id, String code, Short wkType, String type, Long loginUserId) {
Stock stock = new Stock();
String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
if (StringUtils.isBlank(ruleCode)) {
@@ -1476,5 +1756,14 @@
if (!stockItemService.saveBatch(stockItems)) {
throw new CoolException("搴撳瓨淇敼鏋跺け璐ワ紒锛�");
}
+
+ WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, code));
+ if (!Objects.isNull(order)) {
+// Double qty = Math.round((order.getQty() + sum) * 10000) / 10000.0;
+ order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_EXCE.val);
+ if (!asnOrderService.updateById(order)) {
+ throw new CoolException("鍏ュ簱鍗曠姸鎬佷慨鏀瑰け璐ワ紒锛�");
+ }
+ }
}
}
--
Gitblit v1.9.1