| | |
| | | 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.framework.exception.CoolException;
|
| | | 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;
|
| | | import com.zy.asrs.wms.apis.wcs.entity.response.CommonReponse;
|
| | | import com.zy.asrs.wms.asrs.entity.Task;
|
| | | 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 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.Collection;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.List;
|
| | | import java.util.*;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | @Slf4j
|
| | |
| | | .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();
|
| | | //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 请求失败需确认是否存在部分成功的情况,部分成功需要单独刷新成功的任务档状态
|
| | | // throw new CoolException(reponse.getMsg());
|
| | | // }
|
| | | // }
|
| | | } else {
|
| | | // TODO 请求失败需确认是否存在部分成功的情况,部分成功需要单独刷新成功的任务档状态
|
| | | throw new CoolException(reponse.getMsg());
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|