| | |
| | | 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;
|
| | |
| | | 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.Date;
|
| | | import java.util.List;
|
| | | import java.util.*;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | @Slf4j
|
| | |
| | | /***
|
| | | * 入库任务---通知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.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.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::getTaskType, TaskStsType.WCS_CONVEYOR_START.id));
|
| | | log.info(task.getTaskNo() + "下发流动通知" + commonReponse.getMsg());
|
| | | } else {
|
| | | throw new CoolException("下发流动通知失败!!");
|
| | | }
|
| | | }
|
| | | .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()));
|
| | | }
|
| | | });
|
| | |
|
| | |
| | |
|
| | |
|
| | | /***
|
| | | * 入库任务---每隔3秒,刷新当前通知档列表,下发待入库订单至ESS
|
| | | * 入库任务---下发入库任务
|
| | | * 每隔3秒,刷新当前通知档列表,下发待入库订单至ESS
|
| | | * 查询当前任务列表,
|
| | | */
|
| | | // @Scheduled(cron = "0/3 * * * * ? ")
|
| | | @Scheduled(cron = "0/3 * * * * ? ")
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void waitPakinSchedule() {
|
| | | //获取当前任务档中,所有为待入库状态的任务档,按时间升序排列
|
| | | 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();
|
| | |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
| | | // 设置请求参数
|
| | | params.add("params", JSONObject.toJSONString(tasksParam));
|
| | | log.info("请求地址:{},请求参数:{}", Constant.ISSUE_TASK_OF_EVENT, 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_EVENT, 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)
|
| | |
| | |
|
| | |
|
| | | /**
|
| | | * 出库任务--- 每隔3秒,获取当前出库任务列表状态为WCS_EXECUTE_OUT_ARRIVED的任务,并通知ESS流动输送线
|
| | | * */
|
| | | // @Scheduled(cron = "0/3 * * * * ? ")
|
| | | * //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_ARRIVED.id).eq(Task::getStatus, 0));
|
| | | 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) {
|
| | | //流动通知下发完成后,修改任务状态为输送线流动中。。
|
| | | if (task.getTaskType() == 101) {
|
| | | taskService.update(new LambdaUpdateWrapper<Task>()
|
| | | .eq(Task::getId, task.getId())
|
| | | .set(Task::getTaskType, TaskStsType.COMPLETE_OUT.id));
|
| | | } else {
|
| | | taskService.update(new LambdaUpdateWrapper<Task>()
|
| | | .eq(Task::getId, task.getId())
|
| | | .set(Task::getTaskType, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id));
|
| | | }
|
| | | .eq(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id).eq(Task::getStatus, 1));
|
| | |
|
| | | 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)
|
| | | .set(Task::getUpdateTime, new Date())
|
| | | .eq(Task::getId, task.getId()));
|
| | | }
|
| | | // 还需要再修改
|
| | | 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()));
|
| | | // }
|
| | | });
|
| | | }
|
| | |
|
| | |
| | | * //TODO 1. 正常出库后,清除任务,
|
| | | * //TODO 2. 出库后还有库存,需要添加容器回库操作
|
| | | */
|
| | | //@Scheduled(cron = "0/3 * * * * ? ")
|
| | | @Scheduled(cron = "0/3 * * * * ? ")
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void waveToTask() {
|
| | | //获取当前任务档中,所有为待出库状态的任务档,按时间升序排列
|
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
|
| | | .eq(Task::getTaskType, 101) //TODO 如何确认是101,还是103
|
| | | .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT))
|
| | | .stream().sorted(Comparator.comparing(Task::getTaskSts))
|
| | | .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());
|
| | |
|
| | | // 数据组装
|
| | |
| | | // TODO 多任务多订单,统一调度,是否会出现部分成功,部分失败的情况
|
| | | //调用三方接口,将任务推送至ESS平台
|
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
| | | SystemProperties properties = new SystemProperties();
|
| | | // 设置请求参数
|
| | | params.add("params", JSONObject.toJSONString(tasksParam));
|
| | | log.info("请求地址:{},请求参数:{}", Constant.ISSUE_TASK_OF_EVENT, 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(Constant.ISSUE_TASK_OF_EVENT, HttpMethod.POST, httpEntity, String.class);
|
| | | ResponseEntity<String> exchange = restTemplate.exchange(properties.getBaseHost() + properties.getIssueTaskOfEvent(), HttpMethod.POST, httpEntity, String.class);
|
| | | log.info("下发任务 返回结果:{}", exchange);
|
| | | if (exchange.getBody() == null) {
|
| | | throw new CoolException("下发任务失败!!");
|
| | |
| | | tasks.forEach(task -> {
|
| | | taskService.update(new LambdaUpdateWrapper<Task>()
|
| | | .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT.id)
|
| | | .eq(Task::getBarcode, task.getBarcode()));
|
| | | .eq(Task::getId, task.getId()));
|
| | | });
|
| | | } else {
|
| | | // TODO 请求失败需确认是否存在部分成功的情况,部分成功需要单独刷新成功的任务档状态
|