From 83b51a5a0774ea8ecb9a06304af3b956a21307c8 Mon Sep 17 00:00:00 2001
From: pjb <123456>
Date: 星期六, 08 三月 2025 09:06:55 +0800
Subject: [PATCH] CUT库条码T开头,截取后10位

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java |  116 +++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 78 insertions(+), 38 deletions(-)

diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java
index fb9cc2e..fb292e4 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java
@@ -1,6 +1,7 @@
 package com.zy.asrs.wms.asrs.timer;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
 import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
 import com.zy.asrs.framework.exception.CoolException;
@@ -8,6 +9,7 @@
 import com.zy.asrs.wms.asrs.entity.enums.LocStsType;
 import com.zy.asrs.wms.asrs.entity.enums.TaskStsType;
 import com.zy.asrs.wms.asrs.service.*;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -17,6 +19,7 @@
 import java.util.Date;
 import java.util.List;
 
+@Slf4j
 @Component
 public class TaskTimer {
 
@@ -56,9 +59,15 @@
     @Autowired
     private OrderDetlService orderDetlService;
 
+    @Autowired
+    private CacheSiteService cacheSiteService;
 
-//    @Scheduled(cron = "0/3 * * * * ? ")
-    @Transactional
+
+    /**
+     * 鍏ュ簱鎵ц浠诲姟
+     */
+    @Scheduled(cron = "0/3 * * * * ? ")
+    @Transactional(rollbackFor = Exception.class)
     public void inExecute() {
         InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
         try {
@@ -98,8 +107,31 @@
         }
     }
 
+
+    /**
+     * // fixme 鑸嶅純
+     * 1. 瀹氭椂鎷夊彇闇�瑕佹墽琛屽洖搴撲换鍔″垪琛ㄦ暟鎹紝
+     * 2. 鍒犻櫎鍘熷搴撲綅鏄庣粏锛屽師濮嬪簱浣嶇姸鎬佺疆鎴怬.绌哄簱
+     * 3.
+     */
 //    @Scheduled(cron = "0/3 * * * * ? ")
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
+    public void rollbackStock() {
+        //鑾峰彇闇�瑕佹墽琛屽洖搴撶殑浠诲姟锛屾洿鏂板簱瀛樹俊鎭�
+        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskType, 53).eq(Task::getTaskSts, TaskStsType.WCS_CONVEYOR_START.id));
+        if (tasks.isEmpty()) {
+            return;
+        }
+        tasks.forEach(task -> {
+            //鍒犻櫎鍘熷搴撲綅鏄庣粏锛岀姸鎬佺疆涓篛.绌哄簱
+            executeTask103(task);
+        });
+        //todo 闇�娣诲姞涓�涓换鍔$姸鎬佹垨涓存椂鐘舵�侊紝鍚﹀垯浼氫竴鐩磋疆寰紝绋嬪簭鎶ラ敊锛堝簱浣嶇姸鎬佷笉澶勪簬R.鍑哄簱棰勭害锛�
+    }
+
+
+    @Scheduled(cron = "0/10 * * * * ? ")
+    @Transactional(rollbackFor = Exception.class)
     public void outExecute() {
         InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
         try {
@@ -111,7 +143,7 @@
             for (Task task : list) {
                 //鍚屾鏁版嵁
                 switch (task.getTaskType().intValue()) {
-                    case 101://鍑哄簱
+                    case 101://鍑哄簱xx
                         executeTask101(task);
                         break;
                     case 103://鎷f枡
@@ -120,13 +152,11 @@
                     default:
                         throw new CoolException("鏈煡浠诲姟绫诲瀷");
                 }
-
                 task.setTaskSts(TaskStsType.UPDATED_OUT.id);//200.搴撳瓨鏇存柊瀹屾垚
                 if (!taskService.updateById(task)) {
                     throw new CoolException("搴撳瓨鏇存柊澶辫触");
                 }
             }
-
         } catch (Exception e) {
             e.printStackTrace();
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -138,7 +168,6 @@
     //鍏ュ簱
     private void executeTask1(Task task) {
         Long hostId = task.getHostId();
-
         Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId));
         if (loc == null) {
             throw new CoolException("搴撲綅涓嶅瓨鍦�");
@@ -189,7 +218,6 @@
                 }
             }
         }
-
         //缁勬墭閫氱煡妗h浆鍘嗗彶妗�
         List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()).eq(WaitPakin::getHostId, hostId));
         if (waitPakins.isEmpty()) {
@@ -198,6 +226,7 @@
         for (WaitPakin waitPakin : waitPakins) {
             WaitPakinLog waitPakinLog = new WaitPakinLog();
             waitPakinLog.sync(waitPakin);
+            waitPakinLog.setId(null);
             if (!waitPakinLogService.save(waitPakinLog)) {
                 throw new CoolException("缁勬墭閫氱煡妗h浆鍘嗗彶妗eけ璐�");
             }
@@ -289,10 +318,13 @@
 
     }
 
+    /**
+     * 鎷f枡鍐嶅叆搴擄紝鏍规嵁浠诲姟鐩爣搴撲綅锛岀敓鎴愭柊搴撳瓨淇℃伅
+     * @param task
+     */
     //鎷f枡鍐嶅叆搴�
     private void executeTask53(Task task) {
         Long hostId = task.getHostId();
-
         Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId));
         if (loc == null) {
             throw new CoolException("搴撲綅涓嶅瓨鍦�");
@@ -305,6 +337,7 @@
         loc.setLocStsId(LocStsType.F.val());
         loc.setUpdateTime(new Date());
         loc.setBarcode(task.getBarcode());
+
         if (!locService.updateById(loc)) {
             throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
         }
@@ -314,37 +347,35 @@
             throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦�");
         }
 
-        //娣诲姞搴撳瓨鏄庣粏
+        //淇敼搴撳瓨鏄庣粏
         for (TaskDetl taskDetl : taskDetls) {
             double anfme = taskDetl.getStock() - taskDetl.getAnfme();
             if (anfme <= 0) {
-                continue;
-            }
+                LocDetl  locdetl =  locDetlService.getOne(new LambdaQueryWrapper<LocDetl>()
+                        .eq(LocDetl::getLocId, loc.getId())
+                        .eq(LocDetl::getBatch, taskDetl.getBatch())
+                        .eq(LocDetl::getMatId, taskDetl.getMatId()));
 
-            LocDetl locDetl = new LocDetl();
-            locDetl.setLocId(loc.getId());
-            locDetl.setLocNo(loc.getLocNo());
-            locDetl.setMatId(taskDetl.getMatId());
-            locDetl.setMatnr(taskDetl.getMat$().getMatnr());
-            locDetl.setOrderNo(taskDetl.getOrderNo());
-            locDetl.setBatch(taskDetl.getBatch());
-            locDetl.setAnfme(anfme);
-            locDetl.setHostId(hostId);
-            if (!locDetlService.save(locDetl)) {
-                throw new CoolException("鎻掑叆搴撳瓨鏄庣粏澶辫触");
-            }
+                List<LocDetlField> detlFields = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locdetl.getId()).eq(LocDetlField::getHostId, hostId));
+                if (!detlFields.isEmpty()) {
+                    if (!locDetlFieldService.removeBatchByIds(detlFields)) {
+                        throw new CoolException("鍒犻櫎鏄庣粏鎵╁睍瀛楁澶辫触");
+                    }
+                }
 
-            //娣诲姞搴撳瓨鏄庣粏鎵╁睍瀛楁
-            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId));
-            for (TaskDetlField detlField : detlFields) {
-                LocDetlField locDetlField = new LocDetlField();
-                locDetlField.setDetlId(locDetl.getId());
-                locDetlField.setFieldId(detlField.getFieldId());
-                locDetlField.setName(detlField.getName());
-                locDetlField.setValue(detlField.getValue());
-                locDetlField.setHostId(hostId);
-                if (!locDetlFieldService.save(locDetlField)) {
-                    throw new CoolException("鎻掑叆鏄庣粏鎵╁睍瀛楁澶辫触");
+                if (!locDetlService.removeById(locdetl)) {
+                    throw new CoolException("搴撳瓨鏄庣粏鍒犻櫎澶辫触!!");
+                }
+            } else {
+                LocDetl  locdetl =  locDetlService.getOne(new LambdaQueryWrapper<LocDetl>()
+                        .eq(LocDetl::getLocId, loc.getId())
+                        .eq(LocDetl::getBatch, taskDetl.getBatch())
+                        .eq(LocDetl::getMatId, taskDetl.getMatId()));
+                locdetl.setWorkQty(0.0);
+                locdetl.setAnfme(anfme);
+
+                if (!locDetlService.updateById(locdetl)) {
+                    throw new CoolException("搴撳瓨鏄庣粏鏇存柊澶辫触锛侊紒");
                 }
             }
         }
@@ -353,7 +384,8 @@
     //鍑哄簱
     private void executeTask101(Task task) {
         Long hostId = task.getHostId();
-        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
+//        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
         if (loc == null) {
             throw new CoolException("搴撲綅涓嶅瓨鍦�");
         }
@@ -385,14 +417,21 @@
         }
     }
 
+    /**
+     * 灏嗗師鏈夊簱瀛樻槑缁嗗垹闄�
+     * 搴撳瓨鐘舵�佽缃负绌哄簱鐘舵��
+     * @param task
+     */
     //鎷f枡鍑哄簱
     private void executeTask103(Task task) {
         Long hostId = task.getHostId();
-        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
+        //FIXME 鏆傛椂娉ㄩ噴HOSTID绛涢�夋潯浠�
+//        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
         if (loc == null) {
             throw new CoolException("搴撲綅涓嶅瓨鍦�");
         }
-        if (loc.getLocStsId() != LocStsType.R.val()) {
+        if (loc.getLocStsId() != LocStsType.S.val()) {
             throw new CoolException("搴撲綅鐘舵�佷笉澶勪簬R.鍑哄簱棰勭害");
         }
         List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId());
@@ -405,6 +444,7 @@
         if (!locService.updateById(loc)) {
             throw new CoolException("搴撲綅鐘舵�佹洿鏂板け璐�");
         }
+
         List<LocDetl> detlList = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, loc.getId()).eq(LocDetl::getHostId, hostId));
         //鍒犻櫎搴撳瓨鏄庣粏
         for (LocDetl locDetl : detlList) {

--
Gitblit v1.9.1