|  |  | 
 |  |  | package com.zy.asrs.wms.apis.wcs.services.Impl;
 | 
 |  |  | 
 | 
 |  |  | 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.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.common.R;
 | 
 |  |  | import com.zy.asrs.framework.exception.CoolException;
 | 
 |  |  | import com.zy.asrs.wms.apis.wcs.entity.domain.SystemProperties;
 | 
 |  |  | 
 |  |  | import com.zy.asrs.wms.asrs.service.*;
 | 
 |  |  | import io.jsonwebtoken.lang.Collections;
 | 
 |  |  | import lombok.extern.slf4j.Slf4j;
 | 
 |  |  | import org.slf4j.Logger;
 | 
 |  |  | import org.slf4j.LoggerFactory;
 | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
 |  |  | import org.springframework.http.HttpEntity;
 | 
 |  |  | import org.springframework.http.HttpHeaders;
 | 
 |  |  | 
 |  |  |             return R.error("容器码任务错误!!");
 | 
 |  |  |         }
 | 
 |  |  |         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) {
 | 
 |  |  |             //流动通知下发完成后,修改任务状态为输送线流动中。。
 | 
 |  |  |             //TODO 判断任务是否为103拣料出库,103拣料流动后修改为4(RCS容器流动任务已下发)
 | 
 |  |  |             if (task.getTaskType() == 103) {
 | 
 |  |  |                 //TODO 需找海柔确认是否需要重新调用入库接口
 | 
 |  |  |                 //更新库存信息,修改任务状态为4 (RCS容器流动任务已下发)
 | 
 |  |  |                 workService.pickTask(task.getId());
 | 
 |  |  | //                taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskSts, TaskStsType.WCS_CONVEYOR_START))
 | 
 |  |  |             } else {
 | 
 |  |  |                 taskService.update(new LambdaUpdateWrapper<Task>()
 | 
 |  |  |                         .eq(Task::getId, task.getId())
 | 
 |  |  |                         .set(Task::getTaskSts, TaskStsType.COMPLETE_OUT.id));
 | 
 |  |  |             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 || task.getTaskType() == 107) { //如果为任务类型为103,需走回库操作,传100
 | 
 |  |  |                     conveyorStarParam.setDirection("100");
 | 
 |  |  |                 }
 | 
 |  |  |                 //调用三方接口,将任务推送至ESS平台
 | 
 |  |  |                 MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
 | 
 |  |  |                 // 设置请求参数
 | 
 |  |  |                 params.add("params", JSONObject.toJSONString(conveyorStarParam));
 | 
 |  |  |                 log.info("请求地址:{},请求参数:{}", HttpEssUtils.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(HttpEssUtils.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) {
 | 
 |  |  |                         //流动通知下发完成后,修改任务状态为输送线流动中。。
 | 
 |  |  |                         if (task.getTaskType() == 103 || task.getTaskType() == 107) {
 | 
 |  |  |                             //更新库存信息,修改任务状态为4 (RCS容器流动任务已下发)
 | 
 |  |  |                             workService.pickTask(task.getId());
 | 
 |  |  |             //                taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskSts, TaskStsType.WCS_CONVEYOR_START))
 | 
 |  |  |                         } else {
 | 
 |  |  |                             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());
 | 
 |  |  |             }
 | 
 |  |  | //                        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()));
 | 
 |  |  | //            }
 | 
 |  |  |         });
 | 
 |  |  |         return R.ok();
 | 
 |  |  |     }
 |