From a3917dfa5f40fb653046a03ea2acde81992f554e Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期三, 02 四月 2025 16:10:25 +0800
Subject: [PATCH] no message

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |   99 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 66 insertions(+), 33 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 d3ef48a..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,25 +1,25 @@
 package com.vincent.rsf.server.manager.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.vincent.rsf.framework.common.SpringUtils;
+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.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.service.LocService;
-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;
@@ -31,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("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
@@ -53,40 +61,65 @@
         if (waitPakins.isEmpty()) {
             throw new CoolException("缁勬嫋淇℃伅涓嶅瓨鍦紒锛�");
         }
-        /**鑾峰彇缁勬嫋鏄庣粏**/
-        List<WaitPakinItem> waitPakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, ids));
-        if (waitPakinItems.isEmpty()) {
-            throw new CoolException("鏁版嵁閿欒锛氱粍鎷栨槑缁嗕笉瀛樺湪");
-        }
-        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
-        if (StringUtils.isBlank(ruleCode)) {
-            throw new CoolException("缂栫爜閿欒锛氳纭缂栫爜銆孲YS_TASK_CODE銆嶆槸鍚﹀凡鐢熸垚!!");
-        }
-
-        List<Task> tasks = new ArrayList<>();
-        List<TaskItem> taskItems = new ArrayList<>();
         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())
-                    .setTaskStatus(TaskType.TASK_TYPE_IN.type.shortValue())
+                    .setTaskType(TaskType.TASK_TYPE_IN.type.shortValue())
                     .setTargLoc(LocManageUtil.getTargetLoc())
                     .setBarcode(pakin.getBarcode())
+                    .setCreateBy(loginUserId)
+                    .setUpdateBy(loginUserId)
                     .setTargSite(LocManageUtil.getTargetSite());
-            tasks.add(task);
+
+            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("浠诲姟鏄庣粏淇濆瓨澶辫触锛侊紒");
+            }
         });
 
-        if (!this.saveBatch(tasks)) {
-            throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
-        }
+        return R.ok("浠诲姟鐢熸垚瀹屾瘯锛�");
+    }
 
-        //TODO  淇濆瓨浠诲姟妗f槑缁�
-        waitPakinItems.forEach(item -> {
-            TaskItem taskItem = new TaskItem();
-
-            taskItems.add(taskItem);
-        });
-
+    /**
+    * @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