From 0215b398a204449d28d42f77362327e408b2f823 Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期三, 03 十二月 2025 15:03:31 +0800
Subject: [PATCH] 代码优化去掉try cache抛出
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java | 77 +++++++++++++++++---------------------
1 files changed, 34 insertions(+), 43 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 e2e4833..90e474e 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
@@ -453,25 +453,21 @@
* @throws Exception
*/
@Override
- public void complateInTask(List<Task> tasks) throws Exception {
+ public void complateInTask(List<Task> tasks) {
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);
+ 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);
}
}
}
@@ -707,7 +703,7 @@
* @param loginUserId
*/
@Transactional(rollbackFor = Exception.class)
- public void pickComplateInStock(Task task, Long loginUserId) throws Exception {
+ public void pickComplateInStock(Task task, Long loginUserId) {
if (Objects.isNull(task)) {
return;
}
@@ -746,7 +742,7 @@
locWorking.setAnfme(taskItem.getAnfme());
}
BeanUtils.copyProperties(locWorking, locItem);
- locItem.setWorkQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
+ locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
items.add(locItem);
}
@@ -1075,7 +1071,6 @@
TaskItem taskItem = taskItems.stream().findFirst().get();
taskItem.setMatnrId(working.getMatnrId())
.setMaktx(working.getMaktx())
- .setMatnrId(working.getMatnrId())
.setMatnrCode(working.getMatnrCode())
.setSpec(working.getSpec())
.setAnfme(working.getAnfme())
@@ -1585,12 +1580,9 @@
if (taskItems.isEmpty()) {
throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦紒锛�");
}
- try {
- //鏇存柊搴撲綅鏄庣粏
- saveLocItem(taskItems, task.getId(), loginUserId);
- } catch (Exception e) {
- throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
- }
+
+ //鏇存柊搴撲綅鏄庣粏
+ saveLocItem(taskItems, task.getId(), loginUserId);
/**瀵逛换鍔℃槑缁嗘寜缁勬嫋鏄庣粏杩涜鍒嗙粍*/
Map<Long, List<TaskItem>> orderMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
@@ -1600,15 +1592,10 @@
throw new CoolException("鏁版嵁閿欒锛氱粍鎷栨暟鎹笉瀛樺湪锛岃鑱旂郴绠$悊鍛橈紒锛�");
}
List<TaskItem> items = orderMap.get(key);
- try {
- //淇濆瓨搴撳瓨鏄庣粏
- saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
- //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵��
- removeReceiptStock(pakinItem, loginUserId);
- } catch (Exception e) {
- logger.error("<UNK>", e);
- throw new CoolException(e.getMessage());
- }
+ //淇濆瓨鍏ュ嚭搴撴槑缁�
+ saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
+ //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵��
+ removeReceiptStock(pakinItem, loginUserId);
});
/**淇敼搴撲綅鐘舵�佷负F.鍦ㄥ簱*/
if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).eq(Loc::getCode, task.getTargLoc()))) {
@@ -1666,7 +1653,7 @@
* @time 2025/4/15 15:28
*/
@Transactional(rollbackFor = Exception.class)
- public synchronized void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) throws Exception {
+ public synchronized void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) {
Task task = this.getById(taskId);
if (Objects.isNull(task)) {
throw new CoolException("浠诲姟涓嶅瓨鍦�!!");
@@ -1682,8 +1669,8 @@
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()));
+ .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
+ .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
if (Objects.isNull(locItem)) {
BeanUtils.copyProperties(taskItem, item);
item.setLocCode(loc.getCode())
@@ -1692,16 +1679,20 @@
.setUpdateBy(loginUserId)
.setWkType(taskItem.getWkType())
.setType(taskItem.getOrderType());
- locItems.add(item);
+ if (!locItemService.saveOrUpdate(item)) {
+ throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
+ }
} else {
- locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 100) / 100.0)
- .setUpdateTime(new Date());
- locItems.add(locItem);
+ logger.error("褰撳墠绁ㄥ彿:" + locItem.getFieldsIndex() + " 宸插湪搴撳唴锛岃妫�鏌ュ悗鍐嶆搷浣滐紒锛�");
+// throw new CoolException("褰撳墠绁ㄥ彿宸插湪搴撳唴锛岃妫�鏌ュ悗鍐嶆搷浣滐紒锛�");
+// locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 1000000) / 1000000.0)
+// .setUpdateTime(new Date());
+// if (!locItemService.saveOrUpdate(locItem)) {
+// throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
+// }
}
});
- if (!locItemService.saveBatch(locItems)) {
- throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
- }
+
}
/**
--
Gitblit v1.9.1