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/apis/wcs/schedule/ScheduleJobs.java |  259 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 175 insertions(+), 84 deletions(-)

diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java
index 35bf696..7ea4d15 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java
@@ -5,8 +5,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.zy.asrs.framework.exception.CoolException;
-import com.zy.asrs.wms.apis.wcs.entity.domain.Constant;
-import com.zy.asrs.wms.apis.wcs.entity.request.ConveyorStarParam;
+import com.zy.asrs.wms.apis.wcs.entity.domain.SystemProperties;
 import com.zy.asrs.wms.apis.wcs.entity.request.PublishTasksParam;
 import com.zy.asrs.wms.apis.wcs.entity.request.TaskDescribe;
 import com.zy.asrs.wms.apis.wcs.entity.request.TaskParam;
@@ -22,18 +21,14 @@
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.transaction.support.DefaultTransactionDefinition;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -42,55 +37,56 @@
 
     @Autowired
     private DataSourceTransactionManager transactionManager;
-
     @Autowired
     private TaskService taskService;
-
     @Autowired
     private RestTemplate restTemplate;
-
     @Autowired
     private WorkService workService;
 
 
     /***
-     * 閫氱煡ESS杈撻�佺嚎娴佸姩
+     * 鍏ュ簱浠诲姟---閫氱煡ESS杈撻�佺嚎娴佸姩
      */
-    //    @Scheduled(cron = "0/3 * * * * ? ")
+    @Scheduled(cron = "0/3 * * * * ? ")
+    @Transactional(rollbackFor = Exception.class)
     public void conveyorStart() {
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
-                .eq(Task::getTaskSts, TaskStsType.WCS_CONTAINER_RECEIVE.id).eq(Task::getStatus, 0));
+                .eq(Task::getTaskSts, TaskStsType.WCS_CONTAINER_RECEIVE.id).eq(Task::getStatus, 1));
         tasks.forEach(task -> {
             try {
-                ConveyorStarParam conveyorStarParam = new ConveyorStarParam();
-                conveyorStarParam.setSlotCode(task.getOriginLoc())
-                        .setContainerCode(task.getBarcode());
-                //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
-                MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-                // 璁剧疆璇锋眰鍙傛暟
-                params.add("params", JSONObject.toJSONString(conveyorStarParam));
-                log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam));
-                HttpHeaders headers = new HttpHeaders();
-                headers.add("Content-Type", "application/json");
-                HttpEntity httpEntity = new HttpEntity<>(params, headers);
-                // 璇锋眰
-                ResponseEntity<String> exchange = restTemplate.exchange(Constant.ISSUE_TASK_OF_PUTAWAY, HttpMethod.POST, httpEntity, String.class);
-                log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange);
-                if (exchange.getBody() == null) {
-                    throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
-                } else {
-                    CommonReponse commonReponse = JSON.toJavaObject(JSON.parseObject(exchange.getBody()), CommonReponse.class);
-                    if (commonReponse.getCode() == 0) {
-                        log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡"  + commonReponse.getMsg());
-                    } else {
-                        throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
-                    }
-                }
+//                ConveyorStarParam conveyorStarParam = new ConveyorStarParam();
+//                conveyorStarParam.setSlotCode(task.getOriginLoc())
+//                        .setContainerCode(task.getBarcode());
+//                //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
+//                MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
+//                // 璁剧疆璇锋眰鍙傛暟
+//                params.add("params", JSONObject.toJSONString(conveyorStarParam));
+//                log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam));
+//                HttpHeaders headers = new HttpHeaders();
+//                headers.add("Content-Type", "application/json");
+//                HttpEntity httpEntity = new HttpEntity<>(params, headers);
+//                // 璇锋眰
+//                ResponseEntity<String> exchange = restTemplate.exchange(Constant.CONVEYOR_START, HttpMethod.POST, httpEntity, String.class);
+//                log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange);
+//                if (exchange.getBody() == null) {
+//                    throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
+//                } else {
+//                    CommonReponse commonReponse = JSON.toJavaObject(JSON.parseObject(exchange.getBody()), CommonReponse.class);
+//                    if (commonReponse.getCode() == 0) {
+                        taskService.update(new LambdaUpdateWrapper<Task>()
+                                .eq(Task::getId, task.getId())
+                                .set(Task::getTaskSts, TaskStsType.WCS_CONVEYOR_START.id));
+//                        log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg());
+//                    } else {
+//                        throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
+//                    }
+//                }
             } catch (Exception ex) {
                 log.error(ex.getMessage());
             } finally {
                 //濡傛灉寮傚父淇敼绂佺敤鐘舵��
-                taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 1).eq(Task::getId, task.getId()));
+//                taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 0).eq(Task::getId, task.getId()));
             }
         });
 
@@ -98,51 +94,22 @@
 
 
     /***
-     * 姣忛殧3绉掞紝鑾峰彇搴撲腑鐘舵�佷负銆庝换鍔″畬鎴愩�忎笖鐘舵�併�巗ucess銆忕殑璁㈠崟
-     * 骞跺皢浠诲姟鍙樹负鍘嗗彶妗�
-     */
-    //    @Scheduled(cron = "0/3 * * * * ? ")
-    @Transactional
-    public void completeTaskSchedule() {
-        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
-                        .eq(Task::getTaskType, 1)
-                        .eq(Task::getTaskSts, TaskStsType.WCS_PUTAWAY_SUCESS)
-                        .eq(Task::getExcudeStatus, "sucess"))
-                .stream().sorted(Comparator.comparing(Task::getTaskSts))
-                .collect(Collectors.toList());
-
-        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
-        // TODO 鍗曚釜鎵ц澶辫触鍚庯紝 鍔犲叆澶辫触鍒楄〃锛屾坊鍔犲け璐ュ鐞嗗瓧娈碉紝閬垮厤閲嶅鏌ヨ璋冪敤
-//        def.setName("SomeTxName");
-        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
-        TransactionStatus status = transactionManager.getTransaction(def);
-        try {
-            tasks.forEach(task -> {
-                workService.completeTask(task.getId());
-            });
-            // execute your business logic here
-            //db operation
-        } catch (Exception ex) {
-            transactionManager.rollback(status);
-            throw ex;
-        }
-
-    }
-
-
-    /***
-     * 姣忛殧10绉掞紝鍒锋柊褰撳墠閫氱煡妗e垪琛紝涓嬪彂寰呭叆搴撹鍗曡嚦ESS
+     * 鍏ュ簱浠诲姟---涓嬪彂鍏ュ簱浠诲姟
+     * 姣忛殧3绉掞紝鍒锋柊褰撳墠閫氱煡妗e垪琛紝涓嬪彂寰呭叆搴撹鍗曡嚦ESS
      * 鏌ヨ褰撳墠浠诲姟鍒楄〃锛�
      */
-//    @Scheduled(cron = "0/3 * * * * ? ")
+    @Scheduled(cron = "0/3 * * * * ? ")
     @Transactional(rollbackFor = Exception.class)
     public void waitPakinSchedule() {
         //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭叆搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒�
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
-                        .eq(Task::getTaskType, 1)
-                        .eq(Task::getTaskSts, TaskStsType.GENERATE_IN))
+//                        .eq(Task::getTaskType, 1)
+                        .eq(Task::getTaskSts, TaskStsType.GENERATE_IN.id))
                 .stream().sorted(Comparator.comparing(Task::getTaskSts))
                 .collect(Collectors.toList());
+        if (tasks.size() == 0) {
+            return;
+        }
 
         // 鏁版嵁缁勮
         PublishTasksParam tasksParam = new PublishTasksParam();
@@ -165,25 +132,24 @@
         });
 
         tasksParam.setTaskType("putaway");
-
         // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌
         //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
         MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
         // 璁剧疆璇锋眰鍙傛暟
         params.add("params", JSONObject.toJSONString(tasksParam));
-        log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_PUTAWAY, JSONObject.toJSONString(tasksParam));
+        log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", "http://192.168.2.200:9046/task/create", JSONObject.toJSONString(tasksParam));
         HttpHeaders headers = new HttpHeaders();
         headers.add("Content-Type", "application/json");
         HttpEntity httpEntity = new HttpEntity<>(params, headers);
         // 璇锋眰
-        ResponseEntity<String> exchange = restTemplate.exchange(Constant.ISSUE_TASK_OF_PUTAWAY, HttpMethod.POST, httpEntity, String.class);
+        ResponseEntity<String> exchange = restTemplate.exchange("http://192.168.2.200:9046/task/create", HttpMethod.POST, httpEntity, String.class);
         log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange);
         if (exchange.getBody() == null) {
             throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒");
         } else {
             CommonReponse reponse = (CommonReponse) JSON.parse(exchange.getBody());
             if (reponse.getCode() == 0) {
-                //璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓��
+                //  璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓��
                 tasks.forEach(task -> {
                     taskService.update(new LambdaUpdateWrapper<Task>()
                             .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_IN.id)
@@ -196,10 +162,135 @@
         }
     }
 
-    /***
-     * 姣忛殧10绉掓墽琛岋紝鍒锋柊褰撳墠浠诲姟鍒楄〃锛屼笅鍙戜换鍔″埌ESS
-     */
-    public void flowNotify() {
 
+    /**
+     * //fixme 寮冪敤
+     * 鍑哄簱浠诲姟---閫氱煡瀹瑰櫒娴佸姩
+     * 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负COMPLETE_OUT鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎
+     */
+//    @Scheduled(cron = "0/5 * * * * ? ")
+    @Transactional(rollbackFor = Exception.class)
+    public void conveyorToNotify() {
+        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
+                .eq(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id).eq(Task::getStatus, 1));
+
+        // 杩橀渶瑕佸啀淇敼
+        tasks.forEach(task -> {
+//            try {
+//                ConveyorStarParam conveyorStarParam = new ConveyorStarParam();
+//                conveyorStarParam.setSlotCode(task.getOriginLoc())
+//                        .setContainerCode(task.getBarcode());
+//                if (task.getTaskType() == 101) { //浠诲姟绫诲瀷涓�101鍏ㄧ洏鍑哄簱锛岀洿鎺ュ彇涓嬪鍣紝浼�200
+//                    conveyorStarParam.setDirection("200");
+//                } else if (task.getTaskType() == 103) { //濡傛灉涓轰换鍔$被鍨嬩负103锛岄渶璧板洖搴撴搷浣滐紝浼�100
+//                    conveyorStarParam.setDirection("100");
+//                }
+//                //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
+//                MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
+//                // 璁剧疆璇锋眰鍙傛暟
+//                params.add("params", JSONObject.toJSONString(conveyorStarParam));
+//                log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam));
+//                HttpHeaders headers = new HttpHeaders();
+//                headers.add("Content-Type", "application/json");
+//                HttpEntity httpEntity = new HttpEntity<>(params, headers);
+//                // 璇锋眰
+//                ResponseEntity<String> exchange = restTemplate.exchange(Constant.CONVEYOR_START, HttpMethod.POST, httpEntity, String.class);
+//                log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange);
+//                if (exchange.getBody() == null) {
+//                    throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
+//                } else {
+//                    CommonReponse commonReponse = JSON.toJavaObject(JSON.parseObject(exchange.getBody()), CommonReponse.class);
+//                    if (commonReponse.getCode() == 0) {
+                        //娴佸姩閫氱煡涓嬪彂瀹屾垚鍚庯紝淇敼浠诲姟鐘舵�佷负杈撻�佺嚎娴佸姩涓�傘��
+//                        taskService.update(new LambdaUpdateWrapper<Task>()
+//                                .eq(Task::getId, task.getId())
+//                                .set(Task::getTaskSts, TaskStsType.COMPLETE_OUT.id));
+
+//                        log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg());
+//                    } else {
+//                        throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
+//                    }
+//                }
+//            } catch (Exception ex) {
+//                log.error(ex.getMessage());
+//            } finally {
+//                //濡傛灉寮傚父淇敼绂佺敤鐘舵��
+//                taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 0)
+//                        .set(Task::getUpdateTime, new Date())
+//                        .eq(Task::getId, task.getId()));
+//            }
+        });
+    }
+
+
+    /**
+     * 鍑哄簱浠诲姟--- 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负GENERATE_OUT鐨勪换鍔★紝涓嬪彂浠诲姟鑷矱SS
+     * //TODO  鍑哄簱浠诲姟鍒嗕袱绉嶏細
+     * //TODO 1. 姝e父鍑哄簱鍚庯紝娓呴櫎浠诲姟锛�
+     * //TODO 2. 鍑哄簱鍚庤繕鏈夊簱瀛橈紝闇�瑕佹坊鍔犲鍣ㄥ洖搴撴搷浣�
+     */
+    @Scheduled(cron = "0/3 * * * * ? ")
+    @Transactional(rollbackFor = Exception.class)
+    public void waveToTask() {
+        //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭嚭搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒�
+        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
+                        .ge(Task::getTaskType, 101) //TODO 濡備綍纭鏄�101锛岃繕鏄�103
+                        .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT.id));
+        if (tasks.isEmpty()) {
+            return;
+        }
+        tasks.stream().sorted(Comparator.comparing(Task::getTaskSts))
+                .collect(Collectors.toList());
+
+        // 鏁版嵁缁勮
+        PublishTasksParam tasksParam = new PublishTasksParam();
+        //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛�
+        tasks.forEach(task -> {
+            List<TaskParam> params = new ArrayList<>();
+            TaskParam param = new TaskParam();
+            //璁剧疆瀹瑰櫒缂栫爜
+            param.setTaskCode(task.getTaskNo());
+            List<TaskDescribe> taskDescribes = new ArrayList<>();
+            TaskDescribe describe = new TaskDescribe();
+            //璁剧疆鐩爣搴撲綅锛岀珯鐐�
+            describe.setContainerCode(task.getBarcode())
+                    .setToLocationCode(task.getTargetLoc())
+                    .setToStationCode(task.getTargetSite());
+            taskDescribes.add(describe);
+            param.setTaskDescribe(taskDescribes);
+            params.add(param);
+            tasksParam.setTasks(params);
+        });
+
+        tasksParam.setTaskType("carry");
+        // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌
+        //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
+        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
+        SystemProperties properties = new SystemProperties();
+        // 璁剧疆璇锋眰鍙傛暟
+        params.add("params", JSONObject.toJSONString(tasksParam));
+        log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", properties.getBaseHost() + properties.getIssueTaskOfEvent(), JSONObject.toJSONString(tasksParam));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        HttpEntity httpEntity = new HttpEntity<>(params, headers);
+        // 璇锋眰
+        ResponseEntity<String> exchange = restTemplate.exchange(properties.getBaseHost() + properties.getIssueTaskOfEvent(), HttpMethod.POST, httpEntity, String.class);
+        log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange);
+        if (exchange.getBody() == null) {
+            throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒");
+        } else {
+            CommonReponse reponse = (CommonReponse) JSON.parse(exchange.getBody());
+            if (reponse.getCode() == 0) {
+                //璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓��
+                tasks.forEach(task -> {
+                    taskService.update(new LambdaUpdateWrapper<Task>()
+                            .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT.id)
+                            .eq(Task::getId, task.getId()));
+                });
+            } else {
+                // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬�
+                throw new CoolException(reponse.getMsg());
+            }
+        }
     }
 }

--
Gitblit v1.9.1