From 1c54a6ae33a15cf0c426e1e9c7ae07398a1e65e5 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期三, 02 四月 2025 15:17:54 +0800
Subject: [PATCH] Merge branch 'devlop' of http://47.97.1.152:5880/r/wms-master into devlop

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |  101 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 83 insertions(+), 18 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 cbe445e..69a060d 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,22 +1,27 @@
 package com.vincent.rsf.server.manager.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.vincent.rsf.server.api.entity.enums.OrderType;
 import com.vincent.rsf.server.api.entity.enums.TaskStsType;
 import com.vincent.rsf.framework.common.R;
 import com.vincent.rsf.framework.exception.CoolException;
-import com.vincent.rsf.server.manager.entity.WaitPakin;
-import com.vincent.rsf.server.manager.entity.WaitPakinItem;
+import com.vincent.rsf.server.api.entity.enums.TaskType;
+import com.vincent.rsf.server.manager.entity.*;
 import com.vincent.rsf.server.manager.mapper.TaskMapper;
-import com.vincent.rsf.server.manager.entity.Task;
-import com.vincent.rsf.server.manager.service.TaskService;
+import com.vincent.rsf.server.manager.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.vincent.rsf.server.manager.service.WaitPakinItemService;
-import com.vincent.rsf.server.manager.service.WaitPakinService;
+import com.vincent.rsf.server.manager.utils.LocManageUtil;
 import com.vincent.rsf.server.system.constant.SerialRuleCode;
+import com.vincent.rsf.server.system.enums.LocStsType;
 import com.vincent.rsf.server.system.utils.SerialRuleUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -26,19 +31,27 @@
 
     @Autowired
     private WaitPakinService waitPakinService;
-
+    @Autowired
+    private TaskItemService taskItemService;
     @Autowired
     private WaitPakinItemService waitPakinItemService;
+    @Autowired
+    private LocService locService;
+
+
+
 
     /**
+     * @param
+     * @param loginUserId
+     * @return
      * @author Ryan
      * @description 鐢熸垚浠诲姟鍒楄〃
-     * @param
-     * @return
      * @time 2025/3/29 15:59
      */
     @Override
-    public R generateTasks(List<WaitPakin> waitPakin) {
+    @Transactional(rollbackFor = Exception.class)
+    public synchronized R generateTasks(List<WaitPakin> waitPakin, Long loginUserId) {
         if (Objects.isNull(waitPakin) || waitPakin.isEmpty()) {
             throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
@@ -48,15 +61,67 @@
         if (waitPakins.isEmpty()) {
             throw new CoolException("缁勬嫋淇℃伅涓嶅瓨鍦紒锛�");
         }
-        /**鑾峰彇缁勬嫋鏄庣粏**/
-        List<WaitPakinItem> waitPakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, ids));
-        if (waitPakinItems.isEmpty()) {
-            throw new CoolException("鏁版嵁閿欒锛氱粍鎷栨槑缁嗕笉瀛樺湪");
-        }
-        Task task = new Task();
-        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
-        task.setTaskCode(ruleCode).setTaskStatus(TaskStsType.GENERATE_IN.id.shortValue());
+        waitPakins.forEach(pakin -> {
+            List<TaskItem> taskItems = new ArrayList<>();
+            String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
+            if (StringUtils.isBlank(ruleCode)) {
+                throw new CoolException("缂栫爜閿欒锛氳纭缂栫爜銆孲YS_TASK_CODE銆嶆槸鍚﹀凡鐢熸垚!!");
+            }
+            Task task = new Task();
+            task.setTaskCode(ruleCode)
+                    .setTaskStatus(TaskStsType.GENERATE_IN.id.shortValue())
+                    .setTaskType(TaskType.TASK_TYPE_IN.type.shortValue())
+                    .setTargLoc(LocManageUtil.getTargetLoc())
+                    .setBarcode(pakin.getBarcode())
+                    .setCreateBy(loginUserId)
+                    .setUpdateBy(loginUserId)
+                    .setTargSite(LocManageUtil.getTargetSite());
 
+            if (!this.save(task)) {
+                throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
+            }
+            if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, pakin.getCode())
+                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
+                throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
+            }
+
+            /**鑾峰彇缁勬嫋鏄庣粏**/
+            List<WaitPakinItem> waitPakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, pakin.getId()));
+            if (waitPakinItems.isEmpty()) {
+                throw new CoolException("鏁版嵁閿欒锛氱粍鎷栨槑缁嗕笉瀛樺湪");
+            }
+            waitPakinItems.forEach(item -> {
+                TaskItem taskItem = new TaskItem();
+                BeanUtils.copyProperties(item, taskItem);
+                taskItem.setTaskId(task.getId())
+                        .setOrderType(OrderType.ORDER_RECEIPT.type)
+                        .setSource(item.getId())
+                        .setCreateBy(loginUserId)
+                        .setUpdateBy(loginUserId)
+                        .setOrderId(item.getAsnId())
+                        .setOrderItemId(item.getAsnItemId());
+                taskItems.add(taskItem);
+            });
+            if (!taskItemService.saveBatch(taskItems)) {
+                throw new CoolException("浠诲姟鏄庣粏淇濆瓨澶辫触锛侊紒");
+            }
+        });
+
+        return R.ok("浠诲姟鐢熸垚瀹屾瘯锛�");
+    }
+
+    /**
+    * @author Ryan
+    * @description 瀹屾垚浠诲姟
+    * @param
+    * @return
+    * @time 2025/4/2 11:15
+    */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R completeTask(String id) {
         return null;
     }
+
+
 }

--
Gitblit v1.9.1