From e02018eaabd58ce60cf0f46d9c507922250fa700 Mon Sep 17 00:00:00 2001 From: Comair <1464848666@qq.com> Date: Mon, 21 Apr 2025 10:33:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=8F=E5=AE=A0=E6=96=B0=E5=A2=9E=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-test.yml | 2 + .../java/com/shkj/wcs/plc/PlcEventTask.java | 3 + .../shkj/wcs/third/workbinWcs/WCSUtil.java | 311 ++++++++++++++++++ .../workbinWcs/dto/WcsCreateTaskHeader.java | 2 +- .../dto/WcsIncomingTrayCheckBody.java | 43 +++ 5 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/WCSUtil.java create mode 100644 shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsIncomingTrayCheckBody.java diff --git a/shkj-admin/src/main/resources/application-test.yml b/shkj-admin/src/main/resources/application-test.yml index 4f7abd0..0192dd4 100644 --- a/shkj-admin/src/main/resources/application-test.yml +++ b/shkj-admin/src/main/resources/application-test.yml @@ -86,6 +86,8 @@ spring: max-wait: -1ms third: + # 中科WCS接口 + wcsIncomingTrayCheckUrl: http://127.0.0.1:8081/api/toWzWcs/wcsIncomingTrayCheck # agv接口 agvCreateTaskUrl: http://127.0.0.1:8081/rest/common/createTask agvStatesUrl: http://127.0.0.1:8081/rest/robots/states diff --git a/shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java b/shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java index a9279f9..709beb7 100644 --- a/shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java +++ b/shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java @@ -423,6 +423,9 @@ public class PlcEventTask { // return; // } + + //调取WZ-WCS + //读取托盘条码内容 String barcodeValueOne = pointMap.get(onePalletAddress).toString(); log.info("1楼请求入库时,读取的条码内容:" + barcodeValueOne); diff --git a/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/WCSUtil.java b/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/WCSUtil.java new file mode 100644 index 0000000..7cce6ef --- /dev/null +++ b/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/WCSUtil.java @@ -0,0 +1,311 @@ +package com.shkj.wcs.third.workbinWcs; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSONObject; +import com.shkj.common.constant.RedisConstant; +import com.shkj.common.core.domain.Result; +import com.shkj.plc.sdk.device.PLCReadAndWrite; +import com.shkj.plc.sdk.device.PlcOperate; +import com.shkj.system.service.ISysParameterService; +import com.shkj.wcs.bo.AGVStatesBo; +import com.shkj.wcs.bo.AGVUploadStatusBo; +import com.shkj.wcs.domain.WcsPlcConnect; +import com.shkj.wcs.domain.WcsPlcProperty; +import com.shkj.wcs.mapper.BusinDataTaskMapper; +import com.shkj.wcs.plc.PlcInit; +import com.shkj.wcs.service.IWcsPlcConnectService; +import com.shkj.wcs.service.IWcsPlcPropertyService; +import com.shkj.wcs.third.rcs.dto.RcsCancelTaskDto; +import com.shkj.wcs.third.rcs.dto.RcsCreateTaskDto; +import com.shkj.wcs.third.rcs.dto.RcsIdList; +import com.shkj.wcs.third.rcs.dto.RcsThirdResult; +import com.shkj.wms.bo.AGVMoveBo; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * AGV 接口文档 + * + * @author zjx + * @date 2023/04/08 + */ +@Slf4j +@Component +public class WCSUtil { + + @Value("${third.wcsIncomingTrayCheckUrl:}") + private String wcsIncomingTrayCheckUrl; + + @Value("${third.agvCancelTaskUrl:}") + private String agvCancelTaskUrl; + + @Value("${third.agvStatesUrl:}") + private String agvStatesUrl; + + @Value("${third.queryAckByTaskUrl:}") + private String queryAckByTaskUrl; + + @Autowired + BusinDataTaskMapper businDataTaskMapper; + + @Resource + RedisTemplate redisTemplate; + + @Autowired + IWcsPlcPropertyService iWcsPlcPropertyService; + + @Autowired + PLCReadAndWrite plcReadAndWrite; + + @Autowired + ISysParameterService isysParameterService; + + @Autowired + IWcsPlcConnectService iWcsPlcConnectService; + + + @Autowired + PlcInit plcInit; + + + /** + * 设置头部信息 + * + * @return {@code Map} + */ + public Map getHeaderMap() { + Map headerMap = new HashMap<>(1); + headerMap.put("authorization", "mrbase64 mrrest:YWRtaW4mYWRtaW4="); + return headerMap; + } + + + /** + * 创建任务 + * wcs系统通过此接口向rcs系统下发创建任务指令 + * + * @param dto dto + * @return {@code Result} + */ + public Result rcsCreateTask(RcsCreateTaskDto dto) { + String json = JSONObject.toJSONString(dto); + try { + Map headerMap = getHeaderMap(); + String res = HttpRequest.post(agvCreateTaskUrl) + .addHeaders(headerMap) + .body(json) + .execute().body(); + Result result = parseThirdRcsResult(res); + return result; + } catch (Exception e) { + e.printStackTrace(); + log.error("createTask 方法出错了 = {}", e.getMessage()); + return Result.err().msg(e.getMessage()); + } + } + /** + * 创建任务 + * wcs系统通过此接口向rcs系统下发创建任务指令 + * + * @param dto dto + * @return {@code Result} + */ + public Result wcsIncomingTrayCheck(Wcs dto) { + String json = JSONObject.toJSONString(dto); + try { + Map headerMap = getHeaderMap(); + String res = HttpRequest.post(agvCreateTaskUrl) + .addHeaders(headerMap) + .body(json) + .execute().body(); + Result result = parseThirdRcsResult(res); + return result; + } catch (Exception e) { + e.printStackTrace(); + log.error("createTask 方法出错了 = {}", e.getMessage()); + return Result.err().msg(e.getMessage()); + } + } + + + /** + * 放行任务 + * wcs系统通过此接口向rcs系统下发放行任务指令 + * + * @param dto dto + * @return {@code Result} + */ + public Result queryAck(RcsCreateTaskDto dto) { + String json = JSONObject.toJSONString(dto); + try { + Map headerMap = getHeaderMap(); + String res = HttpRequest.post(queryAckByTaskUrl) + .addHeaders(headerMap) + .body(json) + .execute().body(); + return parseThirdRcsResult(res); + } catch (Exception e) { + e.printStackTrace(); + log.error("放行 方法出错了 = {}", e.getMessage()); + return Result.err().msg(e.getMessage()); + } + } + + public Result parseThirdRcsResult(String res) { + try { + res = res.trim(); + RcsThirdResult thirdResult = JSONObject.parseObject(res, RcsThirdResult.class); + if (thirdResult == null) { + // 添加到异常中去 + return Result.err().msg(res); + } + if (!RcsThirdResult.isOk(thirdResult)) { + return Result.err().msg(res); + } + return Result.ok(); + } catch (Exception e) { + log.error("parseThirdRcsResult res = {} e = {}", res, e); + return Result.err().msg(res); + } + } + + /** + * 任务取消 + * 上游系统调⽤此接⼝,将已下发待处理的任务取消 + * + * @param /rest/tasks/del + * @return {@code Result} + */ + public Result rcsTaskCancel(RcsCancelTaskDto dto) { + String json = JSONObject.toJSONString(dto); + + try { + Map headerMap = getHeaderMap(); + String res = HttpRequest.post(agvCancelTaskUrl) + .addHeaders(headerMap) + .body(json) + .execute().body(); + + return parseThirdRcsResult(res); + } catch (Exception e) { + e.printStackTrace(); + log.error("rcs taskCancel 方法出错了 = {}", e.getMessage()); + return Result.err().msg(e.getMessage()); + } + } + + + /** + * AGV搬运 + * + * @param bo + * @return {@link Result}<{@link Boolean}> + */ + public Result moveByAGV(AGVMoveBo bo) { + RcsCreateTaskDto dto = new RcsCreateTaskDto(); + dto.setMapId(1); + dto.setTaskType(bo.getTaskType()); + dto.setTaskId(bo.getTaskId().toString()); + //库位编号 + List idList = new ArrayList<>(); + List points = bo.getPoints(); + for (String point : points) { + RcsIdList rcsIdList = new RcsIdList(); + rcsIdList.setId(point); + log.error(point); + idList.add(rcsIdList); + } + dto.setTargets(idList); + return rcsCreateTask(dto); +// return Result.ok(); + } + + /** + * 获取AGV实时状态信息 + * + * @param mapId bo + * @return {@code Result} + */ + public Result rcsRobotsStates(String mapId) { + String json = JSONObject.toJSONString(mapId); + try { + Map headerMap = getHeaderMap(); + String res = HttpRequest.post(agvStatesUrl) + .addHeaders(headerMap) + .body(json) + .execute().body(); + //获取AGV状态信息 推送前端及存储数据库及存储redis TODO + return parseThirdRcsResult(res); + } catch (Exception e) { + e.printStackTrace(); + log.error("createTask 方法出错了 = {}", e.getMessage()); + return Result.err().msg(e.getMessage()); + } + } + + + /** + * AGV上报任务每一步状态 + * + * @param bo bo + * @return {@code Result} + */ + public Result uploadAgvTaskStatus(AGVUploadStatusBo bo) { + + + + Long plcId = (Long) redisTemplate.opsForValue().get(RedisConstant.redistaskPlc + bo.getTaskId().toString()); + + //根据plcId获取plc信息 + WcsPlcConnect wcsplc = (WcsPlcConnect) redisTemplate.opsForValue().get(RedisConstant.redisPlcConnect + plcId); + + List propertyList = iWcsPlcPropertyService.getWcsPlcPropertyByPlcId(plcId); + String writeTaskId = ""; + String valueType = ""; + for (WcsPlcProperty wcsPlcProperty : propertyList) { + //AGV取走完成 + if (wcsPlcProperty.getPointType().equals("7")) { + writeTaskId = wcsPlcProperty.getAddress(); + valueType = wcsPlcProperty.getValueType(); + } + } + + Map writeMap = new HashMap<>(1); + writeMap.put(valueType, "true"); + Map allMap = new HashMap<>(1); + allMap.put(writeTaskId, writeMap); + + Map readMap = new HashMap<>(1); + readMap.put(writeTaskId, valueType); + + PlcOperate plcOperate = plcInit.getPlcOperateByIp(wcsplc.getPlcIp()); + //回填plc状态 + PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite(); + //首先读取任务编号,同目前返回的任务编号是否一致,如果一致则回填状态; + Map stringObjectMap = plcReadAndWrite.readPlcData(plcOperate, JSONObject.toJSONString(readMap)); + //if(stringObjectMap.get(writeTaskId).equals(bo.getTaskId())){ + plcReadAndWrite.execWrite(plcOperate, JSONObject.toJSONString(allMap)); + //} + return Result.ok(); + } + + + /** + * AGV上报任务每一步状态 + * + * @param + * @return {@code Result} + */ + public Result uploadAgvTaskStatusTmp(AGVUploadStatusBo bo) { + return Result.ok(); + } +} diff --git a/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsCreateTaskHeader.java b/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsCreateTaskHeader.java index d09d93b..b22f2be 100644 --- a/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsCreateTaskHeader.java +++ b/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsCreateTaskHeader.java @@ -10,5 +10,5 @@ import java.io.Serializable; @NoArgsConstructor @Accessors(chain = true) public class WcsCreateTaskHeader implements Serializable { - private String businessType = "commonTask"; + private String businessType; } diff --git a/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsIncomingTrayCheckBody.java b/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsIncomingTrayCheckBody.java new file mode 100644 index 0000000..3278b85 --- /dev/null +++ b/shkj-wms/src/main/java/com/shkj/wcs/third/workbinWcs/dto/WcsIncomingTrayCheckBody.java @@ -0,0 +1,43 @@ +package com.shkj.wcs.third.workbinWcs.dto; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +@Data +@NoArgsConstructor +@Accessors(chain = true) +public class WcsIncomingTrayCheckBody implements Serializable { + + /** + * 托盘码 + */ + @NotBlank(message = "托盘码不得为空") + private String trayCode; + + + /** + * 任务类型 + * 出库:1 + * 入库:2 + * 同层同巷道移库:3 + */ + @NotBlank(message = "任务类型不得为空") + private String taskType; + + + /** + * 时间 包括毫秒 + */ + private String createDt; + + /** + * 新增:1 + */ + private String bussinessType; + + +}