From 052ee1f9c0b9e2bc8bbd4cf135ae45fed7422023 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 28 十月 2024 10:36:28 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/TaskServiceImpl.java |  194 ++++++++++++++++++++++++++++++------------------
 1 files changed, 122 insertions(+), 72 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/TaskServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/TaskServiceImpl.java
index 2e9a36d..cce6d63 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/TaskServiceImpl.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/TaskServiceImpl.java
@@ -7,16 +7,12 @@
 import com.zy.acs.framework.common.SnowflakeIdWorker;
 import com.zy.acs.framework.exception.CoolException;
 import com.zy.acs.manager.common.exception.BusinessException;
-import com.zy.acs.manager.manager.entity.FuncSta;
-import com.zy.acs.manager.manager.entity.Loc;
-import com.zy.acs.manager.manager.entity.Sta;
-import com.zy.acs.manager.manager.entity.Task;
+import com.zy.acs.manager.core.domain.Lane;
+import com.zy.acs.manager.core.service.LaneService;
+import com.zy.acs.manager.manager.entity.*;
 import com.zy.acs.manager.manager.enums.*;
 import com.zy.acs.manager.manager.mapper.TaskMapper;
-import com.zy.acs.manager.manager.service.CodeService;
-import com.zy.acs.manager.manager.service.FuncStaService;
-import com.zy.acs.manager.manager.service.LocService;
-import com.zy.acs.manager.manager.service.TaskService;
+import com.zy.acs.manager.manager.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -33,9 +29,13 @@
     @Autowired
     private LocService locService;
     @Autowired
+    private StaService staService;
+    @Autowired
     private FuncStaService funcStaService;
     @Autowired
     private SnowflakeIdWorker snowflakeIdWorker;
+    @Autowired
+    private LaneService laneService;
 
     @Override
     public synchronized String generateSeqNum() {
@@ -75,80 +75,18 @@
     }
 
     @Override
-    @Transactional
-    public void operateTaskSts(Integer taskId, Boolean finish) {
-        Task task = this.getById(taskId);
-        Loc oriLoc = null; Loc destLoc = null;
-        Sta oriSta = null; Sta destSta = null;
-        Date now = new Date();
-        TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
-        switch (Objects.requireNonNull(typeType)) {
-            case LOC_TO_LOC:
-                oriLoc = locService.getById(task.getOriLoc());
-                destLoc = locService.getById(task.getDestLoc());
-
-                oriLoc.setLocSts(finish?LocStsType.IDLE.val():LocStsType.STOCK.val());
-                oriLoc.setUpdateTime(now);
-                if (!locService.updateById(oriLoc)) {
-                    throw new BusinessException("Loc [" + task.getOriLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
-                }
-
-                destLoc.setLocSts(finish?LocStsType.STOCK.val():LocStsType.IDLE.val());
-                destLoc.setUpdateTime(now);
-                if (!locService.updateById(destLoc)) {
-                    throw new BusinessException("Loc [" + task.getDestLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
-                }
-                break;
-            case LOC_TO_STA:
-                oriLoc = locService.getById(task.getOriLoc());
-                oriLoc.setLocSts(finish?LocStsType.IDLE.val():LocStsType.STOCK.val());
-                oriLoc.setUpdateTime(now);
-                if (!locService.updateById(oriLoc)) {
-                    throw new BusinessException("Loc [" + task.getOriLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
-                }
-                break;
-            case STA_TO_LOC:
-                destLoc = locService.getById(task.getDestLoc());
-                destLoc.setLocSts(finish?LocStsType.STOCK.val():LocStsType.IDLE.val());
-                destLoc.setUpdateTime(now);
-                if (!locService.updateById(destLoc)) {
-                    throw new BusinessException("Loc [" + task.getDestLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
-                }
-                break;
-            case STA_TO_STA:
-                break;
-            case TO_CHARGE:
-            case TO_STANDBY:
-                FuncSta funcSta = funcStaService.getByCodeAndType(task.getDestCode(), FuncStaType.query(typeType).toString());
-                if (!finish) {
-                    funcSta.setState(FuncStaStateType.IDLE.toString());
-                    funcSta.setUpdateTime(now);
-                    if (!funcStaService.updateById(funcSta)) {
-                        throw new BusinessException("FuncSta [" + funcSta.getName() + "] 鏇存柊鐘舵�佸け璐� 锛侊紒锛�");
-                    }
-                }
-                break;
-            default:
-                break;
-        }
-        task.setTaskSts(TaskStsType.COMPLETE.val());
-        task.setUpdateTime(now);
-        if (!this.updateById(task)) {
-            throw new BusinessException(task.getSeqNum() + "浠诲姟鏇存柊鐘舵�佸け璐�");
-        }
-    }
-
-    @Override
     public List<Map<String, Object>> selectStatByLastSevenDays() {
         return this.baseMapper.selectStatByLastSevenDays();
     }
 
     @Override
+    @Transactional
     public Boolean complete(Long taskId, Long userId) {
         Task task = this.getById(taskId);
         if (null == task) {
             return Boolean.FALSE;
         }
+        this.maintainLocSts(task, Boolean.TRUE);
 
         task.setTaskSts(TaskStsType.COMPLETE.val());
         task.setUpdateTime(new Date());
@@ -160,11 +98,13 @@
     }
 
     @Override
+    @Transactional
     public Boolean cancel(Long taskId, Long userId) {
         Task task = this.getById(taskId);
         if (null == task) {
             return Boolean.FALSE;
         }
+        this.maintainLocSts(task, Boolean.FALSE);
 
         task.setTaskSts(TaskStsType.CANCEL.val());
         task.setUpdateTime(new Date());
@@ -175,5 +115,115 @@
         return Boolean.TRUE;
     }
 
+    @Override
+    public Lane checkoutOriginLane(Task task) {
+        Long codeId = null;
+        TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
+        switch (Objects.requireNonNull(typeType)) {
+            case LOC_TO_LOC:
+            case LOC_TO_STA:
+                codeId = locService.getById(task.getOriLoc()).getCode();
+                break;
+            case STA_TO_LOC:
+            case STA_TO_STA:
+                codeId = staService.getById(task.getOriSta()).getCode();
+                break;
+            default:
+                break;
+        }
+
+        if (null == codeId) {
+            return null;
+        }
+        return laneService.search(codeService.getById(codeId).getData());
+    }
+
+    @Override
+    public Lane checkoutDestinationLane(Task task) {
+        Long codeId = null;
+        TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
+        switch (Objects.requireNonNull(typeType)) {
+            case LOC_TO_LOC:
+            case STA_TO_LOC:
+                codeId = locService.getById(task.getDestLoc()).getCode();
+                break;
+            case LOC_TO_STA:
+            case STA_TO_STA:
+                codeId = staService.getById(task.getDestSta()).getCode();
+                break;
+            default:
+                break;
+        }
+
+        if (null == codeId) {
+            return null;
+        }
+        return laneService.search(codeService.getById(codeId).getData());
+    }
+
+    @Override
+    public List<Task> findTasksByLaneHash(String laneHash) {
+        if (Cools.isEmpty(laneHash)) {
+            return new ArrayList<>();
+        }
+        return this.list(new LambdaQueryWrapper<Task>().eq(Task::getOriLaneHash, laneHash).or().eq(Task::getDestLaneHash, laneHash));
+    }
+
+    @Transactional
+    public void maintainLocSts(Task task, Boolean complete) {
+        Loc oriLoc = null; Loc destLoc = null;
+        Sta oriSta = null; Sta destSta = null;
+        Date now = new Date();
+        TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
+        switch (Objects.requireNonNull(typeType)) {
+            case LOC_TO_LOC:
+                oriLoc = locService.getById(task.getOriLoc());
+                destLoc = locService.getById(task.getDestLoc());
+
+                oriLoc.setLocSts(complete?LocStsType.IDLE.val():LocStsType.STOCK.val());
+                oriLoc.setUpdateTime(now);
+                if (!locService.updateById(oriLoc)) {
+                    throw new BusinessException("Loc [" + task.getOriLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
+                }
+
+                destLoc.setLocSts(complete?LocStsType.STOCK.val():LocStsType.IDLE.val());
+                destLoc.setUpdateTime(now);
+                if (!locService.updateById(destLoc)) {
+                    throw new BusinessException("Loc [" + task.getDestLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
+                }
+                break;
+            case LOC_TO_STA:
+                oriLoc = locService.getById(task.getOriLoc());
+                oriLoc.setLocSts(complete?LocStsType.IDLE.val():LocStsType.STOCK.val());
+                oriLoc.setUpdateTime(now);
+                if (!locService.updateById(oriLoc)) {
+                    throw new BusinessException("Loc [" + task.getOriLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
+                }
+                break;
+            case STA_TO_LOC:
+                destLoc = locService.getById(task.getDestLoc());
+                destLoc.setLocSts(complete?LocStsType.STOCK.val():LocStsType.IDLE.val());
+                destLoc.setUpdateTime(now);
+                if (!locService.updateById(destLoc)) {
+                    throw new BusinessException("Loc [" + task.getDestLoc$() + "] 搴撲綅淇敼鐘舵�佸け璐� 锛侊紒锛�");
+                }
+                break;
+            case STA_TO_STA:
+                break;
+            case TO_CHARGE:
+            case TO_STANDBY:
+                FuncSta funcSta = funcStaService.getByCodeAndType(task.getDestCode(), FuncStaType.query(typeType).toString());
+                if (!complete) {
+                    funcSta.setState(FuncStaStateType.IDLE.toString());
+                    funcSta.setUpdateTime(now);
+                    if (!funcStaService.updateById(funcSta)) {
+                        throw new BusinessException("FuncSta [" + funcSta.getName() + "] 鏇存柊鐘舵�佸け璐� 锛侊紒锛�");
+                    }
+                }
+                break;
+            default:
+                break;
+        }
+    }
 
 }

--
Gitblit v1.9.1