package com.zy.api.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.R; import com.core.exception.CoolException; import com.zy.api.entity.CallAgvParams; import com.zy.api.enums.OrderType; import com.zy.api.service.AgvScheduleService; import com.zy.asrs.entity.LocCache; import com.zy.asrs.entity.Task; import com.zy.asrs.entity.result.ForwardAGVTaskDTO; import com.zy.asrs.entity.result.HIKApiDTO; import com.zy.asrs.entity.result.HIKResultDTO; import com.zy.asrs.enums.LocStsType; import com.zy.asrs.enums.TaskIOType; import com.zy.asrs.service.ApiLogService; import com.zy.asrs.service.LocCacheService; import com.zy.asrs.service.TaskService; import com.zy.asrs.service.impl.LocCacheServiceImpl; import com.zy.common.constant.HIKApiConstant; import com.zy.common.utils.HttpHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.UUID; @Slf4j @Service public class AgvScheduleServiceImpl implements AgvScheduleService { @Autowired private ApiLogService apiLogService; @Autowired private TaskService taskService; @Autowired private LocCacheService locCacheService; /** * @author Ryan * @date 2025/11/3 * @description: 呼叫AGV搬运 * @version 1.0 */ @Override public R callAgvCarry(CallAgvParams params) { if (params.getType().equals(OrderType.ORDER_OUT.type)) { //缓存区出库 } else if (params.getType().equals(OrderType.ORDER_IN.type)) { //缓存区入库 } else { } return R.ok(); } @Override public R callback(CallAgvParams params) { //TODO 1. 搬运完成,修改站点库位状态 if (params.getType().equals(OrderType.ORDER_OUT.type)) { //出库单 if (params.getStatus().equals("RUNING")) { LocCache locCache = locCacheService.selectOne(new EntityWrapper().eq("loc_no", params.getOrgLoc())); if (Objects.isNull(locCache)) { throw new CoolException("库位信息不存在!!"); } if (!locCache.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) { locCache.setLocSts(LocStsType.LOC_STS_TYPE_O.type); } } else if (params.getStatus().equals("FINISHED")) { Task task = taskService.selectOne(new EntityWrapper().eq("wrk_no", params.getWrkNo())); if (Objects.isNull(task)) { throw new CoolException("任务信息不存在!!"); } if (!taskService.updateById(task)) { throw new CoolException("任务状态更新失败!!"); } } } else { //入库单 } return null; } public HIKResultDTO sendAgvTask(HIKApiDTO haiKangApiDTO, 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 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); String response = ""; try { response = new HttpHandler.Builder() .setUri(HIKApiConstant.AGV_IP) .setPath(path) .setJson(body) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); if (jsonObject.getInteger("code").equals(0)) { result.setSuccess(true); } else { result.setMessage(jsonObject.getString("message")); log.error("发送agv任务失败!!!url:{};request:{};response:{}", HIKApiConstant.AGV_IP + path, body, response); } // {"code":"1","data":"","interrupt":false,"message":"重复提交","msgErrCode":"0x3a80D012","reqCode":"fa92b49481a44627ae4d80c1400f28f6"} } catch (Exception e) { result.setMessage(e.getMessage()); log.error("发送agv任务异常", e); } finally { try { // 保存接口日志 apiLogService.save( "发送agv任务", HIKApiConstant.AGV_IP + path, null, "127.0.0.1", body, response, result.isSuccess() ); } catch (Exception e) { log.error("", e); } } return result; } }