From e046dba174365eb8934ee1e4206f09821145e876 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 21 八月 2025 13:23:22 +0800
Subject: [PATCH] no message

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java |  374 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 242 insertions(+), 132 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 9cdc611..f0174de 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
@@ -1,21 +1,43 @@
 package com.zy.asrs.wms.apis.wcs.schedule;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.zy.asrs.wms.asrs.entity.Task;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.cfg.CoercionAction;
+import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
+import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wms.apis.wcs.entity.domain.SystemProperties;
+import com.zy.asrs.wms.apis.wcs.entity.request.ConveyorStarParam;
+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;
+import com.zy.asrs.wms.apis.wcs.entity.response.CommonReponse;
+import com.zy.asrs.wms.asrs.entity.*;
+import com.zy.asrs.wms.asrs.entity.dto.OrderOutMergeDto;
+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.TaskService;
-import com.zy.asrs.wms.asrs.service.WorkService;
+import com.zy.asrs.wms.asrs.service.*;
+import com.zy.asrs.wms.asrs.service.impl.LocServiceImpl;
+import com.zy.asrs.wms.utils.Utils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+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.annotation.Transactional;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
-import java.util.Comparator;
-import java.util.List;
+import javax.annotation.Resource;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -30,7 +52,22 @@
     private RestTemplate restTemplate;
     @Autowired
     private WorkService workService;
-
+    @Resource
+    private SystemProperties properties;
+    @Autowired
+    private LocServiceImpl locService;
+    @Autowired
+    private LocDetlService locDetlService;
+    @Autowired
+    private TaskDetlService taskDetlService;
+    @Autowired
+    private LocDetlFieldService locDetlFieldService;
+    @Autowired
+    private TaskDetlFieldService taskDetlFieldService;
+    @Autowired
+    private CacheSiteService cacheSiteService;
+    @Autowired
+    private OperationPortService operationPortService;
 
     /***
      * 鍏ュ簱浠诲姟---閫氱煡ESS杈撻�佺嚎娴佸姩
@@ -39,46 +76,116 @@
     @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, 1));
+                .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.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) {
+                ConveyorStarParam conveyorStarParam = new ConveyorStarParam();
+                conveyorStarParam.setSlotCode(task.getOriginSite())
+                        .setContainerCode(task.getBarcode())
+                        .setDirection("100");
+                // 鍘熷鎶ユ枃
+                log.info("閫氱煡ESS杈撻�佺嚎娴佸姩璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", "http://192.168.2.200:9046/conveyor/moveContainer", JSONObject.toJSONString(conveyorStarParam));
+                HttpHeaders headers = new HttpHeaders();
+                headers.add("Content-Type", "application/json");
+                headers.add("api-version", "v2.0");
+                HttpEntity httpEntity = new HttpEntity<>(conveyorStarParam, headers);
+                // 璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
+                ResponseEntity<String> exchange = restTemplate.exchange("http://192.168.2.200:9046/conveyor/moveContainer", HttpMethod.POST, httpEntity, String.class);
+                log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange);
+                if (exchange.getBody() == null) {
+                    throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
+                } else {
+                    ObjectMapper objectMapper = new ObjectMapper();
+                    objectMapper.coercionConfigDefaults()
+                            .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+                    CommonReponse commonReponse = objectMapper.readValue(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("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
-//                    }
-//                }
+                    } else {
+                        throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒");
+                    }
+                }
             } catch (Exception ex) {
                 log.error(ex.getMessage());
-            } finally {
-                //濡傛灉寮傚父淇敼绂佺敤鐘舵��
-//                taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 0).eq(Task::getId, task.getId()));
             }
         });
 
     }
 
+    /**
+     * 鐢熸垚鑷姩鐩樼偣浠诲姟
+     */
+//    @Scheduled(cron = "0/50 * * * * ?")
+//    @Transactional(rollbackFor = Exception.class)
+    public void genCheckTask() {
+        Loc locs = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocStsId, LocStsType.F.val()).orderByAsc(Loc::getLocNo).last("limit 1"));
+        if (Objects.isNull(locs)) {
+            return;
+        }
+        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().select(Task::getId).eq(Task::getTaskType, 107L));
+        if (!tasks.isEmpty() && tasks.size() >= 4) {
+            //榛樿鐢熸垚鍥涗釜鐩樼偣浠诲姟锛岃秴杩�4涓紝鍋滄鐢熸垚鐩樼偣浠诲姟;
+            return;
+        }
+        OperationPort operationPort = operationPortService.getOne(new LambdaQueryWrapper<OperationPort>().last("ORDER BY RAND() LIMIT 1;"));
+        if (operationPort == null || Objects.isNull(operationPort)) {
+            throw new CoolException("浣滀笟鍙d笉瀛樺湪");
+        }
+        Task task = new Task();
+        task.setTaskNo(workService.generateTaskNo(TaskStsType.GENERATE_OUT.id));
+        task.setTaskSts(TaskStsType.GENERATE_OUT.id);
+        task.setTaskType(107L); //榛樿107鐩樼偣浠诲姟锛岀洏鐐逛换鍔℃病鏈夛紝鎸�103澶勭悊
+        task.setIoPri(workService.generateIoPri(TaskStsType.GENERATE_OUT.id));
+        task.setOriginLoc(locs.getLocNo());
+        task.setTargetSite(operationPort.getFlag());
+        task.setBarcode(locs.getBarcode());
+
+        if (!taskService.save(task)) {
+            throw new CoolException("浠诲姟鐢熸垚澶辫触锛侊紒");
+        }
+
+        List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, locs.getId()));
+        if (locDetls.isEmpty()) {
+            throw new CoolException("鏄庣粏涓嶅瓨鍦紒锛�");
+        }
+
+        for (LocDetl locDetl : locDetls) {
+            TaskDetl taskDetl = new TaskDetl();
+            taskDetl.sync(locDetl);
+            taskDetl.setId(null);
+            taskDetl.setTaskId(task.getId());
+            taskDetl.setTaskNo(task.getTaskNo());
+            taskDetl.setAnfme(locDetl.getAnfme());
+            taskDetl.setStock(locDetl.getAnfme());
+            taskDetl.setWaveId(null);
+            taskDetl.setWaveNo(null);
+            taskDetl.setOrderId(null);
+            taskDetl.setOrderNo(null);
+            if (!taskDetlService.save(taskDetl)) {
+                throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+            }
+
+            List<LocDetlField> locDetlFields = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId()));
+            for (LocDetlField locDetlField : locDetlFields) {
+                TaskDetlField taskDetlField = new TaskDetlField();
+                taskDetlField.sync(locDetlField);
+                taskDetlField.setId(null);
+                taskDetlField.setDetlId(taskDetl.getId());
+                if (!taskDetlFieldService.save(taskDetlField)) {
+                    throw new CoolException("鏄庣粏鎵╁睍鐢熸垚澶辫触");
+                }
+            }
+        }
+
+        if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getId, locs.getId())
+                .set(Loc::getUpdateTime, new Date())
+                .set(Loc::getLocStsId, LocStsType.R.val()))) {
+            throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+        }
+    }
 
     /***
      * 鍏ュ簱浠诲姟---涓嬪彂鍏ュ簱浠诲姟
@@ -87,75 +194,82 @@
      */
     @Scheduled(cron = "0/3 * * * * ? ")
     @Transactional(rollbackFor = Exception.class)
-    public void waitPakinSchedule() {
+    public void waitPakinSchedule() throws JsonProcessingException {
         //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭叆搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒�
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
 //                        .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();
-//        //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("putaway");
-//        // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌
-//        //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴
-//        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-//        // 璁剧疆璇锋眰鍙傛暟
-//        params.add("params", JSONObject.toJSONString(tasksParam));
-//        log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_EVENT, 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_EVENT, 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) {
-                //璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓��
+        PublishTasksParam tasksParam = new PublishTasksParam();
+        //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛�
+        tasks.forEach(task -> {
+            List<TaskParam> params = new ArrayList<>();
+            TaskParam param = new TaskParam();
+            param.setTaskCode(task.getTaskNo());
+
+            // 澶勭悊搴撲綅鏄犲皠
+            String[] parts = task.getTargetLoc().split("-");
+            String formatLocNo = String.format("A-%03d-%03d-%02d",
+                    Integer.parseInt(parts[0]),
+                    Integer.parseInt(parts[1]),
+                    Integer.parseInt(parts[2]));
+            TaskDescribe describe = new TaskDescribe();
+            //璁剧疆鐩爣搴撲綅锛岀珯鐐�
+            describe.setContainerCode(task.getBarcode())
+                    .setToLocationCode(formatLocNo)
+                    .setToStationCode(task.getTargetSite());
+
+            param.setTaskDescribe(describe);
+            params.add(param);
+            tasksParam.setTasks(params);
+        });
+
+        tasksParam.setTaskType("putaway");
+        // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌
+        log.info("涓嬪彂鍏ュ簱浠诲姟璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", "http://192.168.2.200:9046/task/create", JSONObject.toJSONString(tasksParam));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        HttpEntity httpEntity = new HttpEntity<>(tasksParam, headers);
+        // 璇锋眰
+        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 {
+            ObjectMapper objectMapper = new ObjectMapper();
+            CommonReponse reponse = objectMapper.readValue(exchange.getBody(), CommonReponse.class);
+            if (reponse.getCode() == 0) {
+                //  璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓��
                 tasks.forEach(task -> {
                     taskService.update(new LambdaUpdateWrapper<Task>()
                             .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_IN.id)
                             .eq(Task::getBarcode, task.getBarcode()));
                 });
-//            } else {
-//                // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬�
-//                throw new CoolException(reponse.getMsg());
-//            }
-//        }
+            } else {
+                // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬�
+                throw new CoolException(reponse.getMsg());
+            }
+        }
     }
 
 
     /**
+     * //fixme 寮冪敤
      * 鍑哄簱浠诲姟---閫氱煡瀹瑰櫒娴佸姩
-     * 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负WCS_EXECUTE_OUT_ARRIVED鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎
+     * 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负COMPLETE_OUT鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎
      */
-    @Scheduled(cron = "0/5 * * * * ? ")
+//    @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_ARRIVED.id).eq(Task::getStatus, 1));
+                .eq(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id).eq(Task::getStatus, 1));
 
         // 杩橀渶瑕佸啀淇敼
         tasks.forEach(task -> {
@@ -184,10 +298,10 @@
 //                } 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.WAVE_SEED.id));
+            //娴佸姩閫氱煡涓嬪彂瀹屾垚鍚庯紝淇敼浠诲姟鐘舵�佷负杈撻�佺嚎娴佸姩涓�傘��
+//                        taskService.update(new LambdaUpdateWrapper<Task>()
+//                                .eq(Task::getId, task.getId())
+//                                .set(Task::getTaskSts, TaskStsType.COMPLETE_OUT.id));
 
 //                        log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg());
 //                    } else {
@@ -214,62 +328,58 @@
      */
     @Scheduled(cron = "0/3 * * * * ? ")
     @Transactional(rollbackFor = Exception.class)
-    public void waveToTask() {
+    public void waveToTask() throws JsonProcessingException {
         //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭嚭搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒�
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
-                        .ge(Task::getTaskType, 101) //TODO 濡備綍纭鏄�101锛岃繕鏄�103
-                        .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT.id))
-                .stream().sorted(Comparator.comparing(Task::getTaskSts))
-                .collect(Collectors.toList());
+                .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<>();
-//        // 璁剧疆璇锋眰鍙傛暟
-//        params.add("params", JSONObject.toJSONString(tasksParam));
-//        log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_EVENT, 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_EVENT, 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) {
+        PublishTasksParam tasksParam = new PublishTasksParam();
+        List<TaskParam> params = new ArrayList<>();
+        //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛�
+        tasks.forEach(task -> {
+            TaskParam param = new TaskParam();
+            //璁剧疆瀹瑰櫒缂栫爜
+            param.setTaskCode(task.getTaskNo());
+            TaskDescribe describe = new TaskDescribe();
+            //璁剧疆鐩爣搴撲綅锛岀珯鐐�
+            describe.setContainerCode(task.getBarcode())
+                    .setToLocationCode(task.getTargetLoc())
+                    .setToStationCode(task.getTargetSite());
+            param.setTaskDescribe(describe);
+            params.add(param);
+        });
+        tasksParam.setTasks(params);
+        tasksParam.setTaskType("carry");
+        log.info("鍑哄簱浠诲姟涓嬪彂璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", properties.getBaseHost() + properties.getEssReceiveTask(), JSONObject.toJSONString(tasksParam));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        HttpEntity httpEntity = new HttpEntity<>(tasksParam, headers);
+        // 璇锋眰
+        ResponseEntity<String> exchange = restTemplate.exchange(properties.getBaseHost() + properties.getEssReceiveTask(), HttpMethod.POST, httpEntity, String.class);
+        log.info("鍑哄簱浠诲姟涓嬪彂 杩斿洖缁撴灉锛歿}", exchange);
+        if (exchange.getBody() == null) {
+            throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒");
+        } else {
+            ObjectMapper objectMapper = new ObjectMapper();
+            CommonReponse reponse = objectMapper.readValue(exchange.getBody(), CommonReponse.class);
+            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());
-//            }
-//        }
+            } else {
+                // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬�
+                throw new CoolException(reponse.getMsg());
+            }
+        }
     }
 }

--
Gitblit v1.9.1