| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.api.controller.params.AgvCallBackParam; |
| | | import com.zy.api.controller.params.AgvCarriesParam; |
| | | import com.zy.api.controller.params.AgvRequestParam; |
| | | import com.zy.api.entity.CallAgvParams; |
| | | import com.zy.api.enums.OrderType; |
| | | import com.zy.api.service.AgvScheduleService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | .contains(task.getIoType())) { |
| | | // 入库 |
| | | task.setWrkSts(TaskStatusType.AGV_TASK_ISSUED_IN.type); |
| | | } else if (Arrays.asList(TaskIOType.ALL_OUT.type, TaskIOType.PICK_OUT.type, TaskIOType.MERGE_OUT.type) |
| | | } else if (Arrays.asList(TaskIOType.ALL_OUT.type, TaskIOType.PICK_OUT.type, TaskIOType.MERGE_OUT.type, TaskIOType.EMPTY_OUT.type) |
| | | .contains(task.getIoType())) { |
| | | // 出库 |
| | | task.setWrkSts(TaskStatusType.AGV_TASK_ISSUED_OUT.type); |
| | | } |
| | | |
| | | if (!taskService.updateById(task)) { |
| | | throw new CoolException("任务状态更新失败!!"); |
| | | HIKResultDTO hikResultDTO = sendAgvTask(params, HIKApiConstant.TASK_SUBMIT); |
| | | |
| | | if (hikResultDTO.isSuccess()) { |
| | | if (!taskService.updateById(task)) { |
| | | throw new CoolException("任务状态更新失败!!"); |
| | | } |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 获取自定义请求头 |
| | | * |
| | | * @return java.util.Map<java.lang.String, java.lang.Object> |
| | | * @author Ryan |
| | | * @date 2025/12/29 9:11 |
| | | */ |
| | | private Map<String, Object> getHeaderParam() { |
| | | Map<String, Object> headerParam = new HashMap<>(); |
| | | //设置请求连接的Token |
| | | headerParam.put("X-LR-REQUEST-ID", new Date().getTime() + ""); |
| | | return headerParam; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R callback(CallAgvParams params) { |
| | | public R callback(AgvCallBackParam params) { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getWrkNo())) { |
| | | if (Objects.isNull(params.getRobotTaskCode())) { |
| | | return R.error("任务号不能为空!!"); |
| | | } |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("wrk_no", params.getWrkNo())); |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("wrk_no", params.getRobotTaskCode())); |
| | | if (Objects.isNull(task)) { |
| | | return R.error("任务信息不存在!!"); |
| | | } |
| | | |
| | | // if (!Arrays.asList(TaskStatusType.AGV_TASK_ISSUED_IN.type, TaskStatusType.AGV_TASK_ISSUED_OUT.type).contains(task.getIoType())) { |
| | | // return R.error(""); |
| | | // } |
| | | // |
| | | if (Arrays.asList(TaskIOType.ALL_IN.type, TaskIOType.PICK_IN.type, TaskIOType.MERGE_IN.type) |
| | | .contains(task.getIoType())) { |
| | | // 入库 |
| | | if (params.getStatus().equals("RUNNING")) { |
| | | if (params.getExtra().getValues().getMethod().equals("start")) { |
| | | task.setWrkSts(TaskStatusType.AGV_TASK_RUNNING_IN.type); |
| | | } else if (params.getStatus().equals("FINISHED")){ |
| | | } else if (params.getExtra().getValues().getMethod().equals("end")){ |
| | | task.setWrkSts(TaskStatusType.AGV_TASK_FINISHED_IN.type); |
| | | |
| | | } |
| | | } else if (Arrays.asList(TaskIOType.ALL_OUT.type, TaskIOType.PICK_OUT.type, TaskIOType.MERGE_OUT.type) |
| | | } else if (Arrays.asList(TaskIOType.ALL_OUT.type, TaskIOType.PICK_OUT.type, TaskIOType.MERGE_OUT.type, TaskIOType.EMPTY_OUT.type) |
| | | .contains(task.getIoType())) { |
| | | // 出库 |
| | | if (params.getStatus().equals("RUNNING")) { |
| | | // 出库p |
| | | if (params.getExtra().getValues().getMethod().equals("start")) { |
| | | task.setWrkSts(TaskStatusType.AGV_TASK_RUNNING_OUT.type); |
| | | } else if (params.getStatus().equals("FINISHED")){ |
| | | } else if (params.getExtra().getValues().getMethod().equals("end")){ |
| | | task.setWrkSts(TaskStatusType.AGV_TASK_FINISHED_OUT.type); |
| | | } |
| | | } |
| | |
| | | if (!taskService.updateById(task)) { |
| | | throw new CoolException("状态修改失败!!"); |
| | | } |
| | | |
| | | return R.ok("执行完成 !!"); |
| | | } |
| | | |
| | | public HIKResultDTO sendAgvTask(HIKApiDTO haiKangApiDTO, String path) { |
| | | public HIKResultDTO sendAgvTask(CallAgvParams param, String path) { |
| | | HIKResultDTO result = new HIKResultDTO(); |
| | | ForwardAGVTaskDTO forwardAGVTaskParam = new ForwardAGVTaskDTO(); |
| | | forwardAGVTaskParam.setReqCode(UUID.randomUUID().toString().replace("-", "")); |
| | | forwardAGVTaskParam.setClientCode("IWMS"); |
| | | forwardAGVTaskParam.setTaskTyp(haiKangApiDTO.getTaskType()); |
| | | forwardAGVTaskParam.setCtnrTyp(haiKangApiDTO.getCtnrType()); |
| | | forwardAGVTaskParam.setPriority(haiKangApiDTO.getPriority()); |
| | | List<ForwardAGVTaskDTO.PositionCodePaths> positionCodePathsList = new ArrayList<>(); |
| | | positionCodePathsList |
| | | .add(new ForwardAGVTaskDTO.PositionCodePaths(haiKangApiDTO.getOrg(), haiKangApiDTO.getOrgType())); |
| | | positionCodePathsList |
| | | .add(new ForwardAGVTaskDTO.PositionCodePaths(haiKangApiDTO.getTar(), haiKangApiDTO.getTarType())); |
| | | forwardAGVTaskParam.setPositionCodePath(positionCodePathsList); |
| | | String body = JSON.toJSONString(forwardAGVTaskParam); |
| | | AgvRequestParam requestParam = new AgvRequestParam(); |
| | | requestParam.setTaskType(param.getTaskType()); |
| | | List<AgvCarriesParam> agvCarriesParams = new ArrayList<>(); |
| | | |
| | | AgvCarriesParam carriesParam = new AgvCarriesParam(); |
| | | carriesParam.setSeq(0); |
| | | carriesParam.setCode(param.getOrgSite()); |
| | | |
| | | agvCarriesParams.add(carriesParam); |
| | | |
| | | AgvCarriesParam carriesParam2 = new AgvCarriesParam(); |
| | | carriesParam2.setSeq(1); |
| | | carriesParam2.setCode(param.getTarSite()); |
| | | |
| | | agvCarriesParams.add(carriesParam2); |
| | | |
| | | requestParam.setRobotTaskCode(param.getWrkNo()); |
| | | requestParam.setTargetRoute(agvCarriesParams); |
| | | |
| | | String body = JSON.toJSONString(requestParam); |
| | | String response = ""; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(HIKApiConstant.AGV_IP) |
| | | .setPath(path) |
| | | .setHeaders(getHeaderParam()) |
| | | .setJson(body) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(0)) { |
| | | if (jsonObject.getString("code").equals("SUCCESS")) { |
| | | result.setSuccess(true); |
| | | } else { |
| | | result.setMessage(jsonObject.getString("message")); |