From 1a65da0a6c765b07527082272c8d1afc5119a3fa Mon Sep 17 00:00:00 2001 From: skyouc <958836976@qq.com> Date: 星期六, 30 八月 2025 08:04:11 +0800 Subject: [PATCH] 接口对接修改 --- rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java | 125 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 121 insertions(+), 4 deletions(-) diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java index e51563e..d96d3df 100644 --- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java +++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java @@ -1,8 +1,20 @@ package com.vincent.rsf.server.manager.schedules; +import com.alibaba.fastjson.JSONArray; +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.vincent.rsf.framework.common.R; import com.vincent.rsf.framework.exception.CoolException; -import com.vincent.rsf.server.api.service.WcsService; +import com.vincent.rsf.server.api.config.RemotesInfoProperties; +import com.vincent.rsf.server.api.entity.CommonResponse; +import com.vincent.rsf.server.api.entity.constant.RcsConstant; +import com.vincent.rsf.server.api.entity.params.TaskItemParam; +import com.vincent.rsf.server.api.entity.params.WcsTaskParams; import com.vincent.rsf.server.api.utils.LocUtils; import com.vincent.rsf.server.common.constant.Constants; import com.vincent.rsf.server.manager.controller.params.LocToTaskParams; @@ -10,23 +22,27 @@ import com.vincent.rsf.server.manager.entity.*; import com.vincent.rsf.server.manager.service.*; import com.vincent.rsf.server.manager.service.impl.LocServiceImpl; -import com.vincent.rsf.server.manager.service.impl.TransferOrderServiceImpl; -import com.vincent.rsf.server.manager.utils.LocManageUtil; import com.vincent.rsf.server.system.constant.GlobalConfigCode; import com.vincent.rsf.server.system.constant.SerialRuleCode; import com.vincent.rsf.server.system.entity.Config; import com.vincent.rsf.server.system.service.ConfigService; import com.vincent.rsf.server.system.utils.SerialRuleUtils; import com.vincent.rsf.server.system.utils.SystemAuthUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; import java.util.*; import java.util.stream.Collectors; @@ -35,6 +51,7 @@ * @Author Ryan * 浠诲姟宸ヤ綔妗� */ +@Slf4j @Component public class TaskSchedules { @@ -68,6 +85,12 @@ private TransferOrderService transferOrderService; @Autowired private TransferService transferService; + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private RemotesInfoProperties.RcsApi rcsApi; /** * @param @@ -220,7 +243,9 @@ @Transactional(rollbackFor = Exception.class) public void taskToWCS() throws Exception { Long loginUserId = SystemAuthUtils.getLoginUserId(); - List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type); + List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPITY_IN.type + ,TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type, + TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type); List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id); List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() .in(Task::getTaskType, list) @@ -253,6 +278,7 @@ } } //TODO 璋冪敤涓嬪彂浠诲姟鎺ュ彛 + pubTaskToWcs(task); } } @@ -280,6 +306,97 @@ /** + * 涓嬪彂浠诲姟鑷砏CS + * @param task + */ + @Transactional(rollbackFor = Exception.class) + public void pubTaskToWcs(Task task) throws Exception{ + WcsTaskParams taskParams = new WcsTaskParams(); + TaskItemParam itemParam = new TaskItemParam(); + //浠诲姟绫诲瀷锛屼换鍔$紪鐮� + itemParam.setTaskType(RcsTaskType.getTypeDesc(task.getTaskType())) + .setSeqNum(task.getTaskCode()); + + //涓诲弬鏁� + taskParams.setBatch(task.getBarcode()); + + if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type ) + || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) { + + itemParam.setDestLoc(task.getTargLoc()) + .setOriSta(task.getOrgSite()); + } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type) + + || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type) + ) { + + itemParam.setOriLoc(task.getOrgLoc()) + .setDestSta(task.getTargSite()); + } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { + itemParam.setOriLoc(task.getOrgLoc()).setDestLoc(task.getTargLoc()); + } else { + itemParam.setOriSta(task.getOrgSite()).setDestSta(task.getTargSite()); + } + + List<TaskItemParam> items = Arrays.asList(itemParam); + + taskParams.setTaskList(items); + + /**浠诲姟涓嬪彂鎺ュ彛*/ + String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask; + + /**RCS鍩虹閰嶇疆閾炬帴*/ + log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl , JSONObject.toJSONString(taskParams)); + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + headers.add("api-version", "v2.0"); + HttpEntity httpEntity = new HttpEntity(taskParams, headers); + ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class); + log.info("浠诲姟涓嬪彂鍚庯紝鍝嶅簲缁撴灉锛� {}", exchange); + if (Objects.isNull(exchange.getBody())) { + throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒"); + } else { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.coercionConfigDefaults() + .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); + try { + CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); + if (result.getCode() == 200) { + if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type) + || task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { + if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode()) + .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) { + throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�"); + } + } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) { + if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode()) + .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) { + throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�"); + } + } + + } else { + throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒"); + } + } catch (JsonProcessingException e) { + throw new CoolException(e.getMessage()); + } + } + + } + + + /** * @param * @return * @author Ryan -- Gitblit v1.9.1