自动化立体仓库 - WMS系统
chen.llin
9 天以前 817683f9935a6343e954ffe7fd0eeae46e55d29c
AGV下单
3个文件已修改
152 ■■■■ 已修改文件
src/main/java/com/zy/asrs/entity/AgvCallbackDto.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/handler/AgvHandler.java 129 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/constant/ApiInterfaceConstant.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/AgvCallbackDto.java
@@ -10,9 +10,14 @@
@Data
public class AgvCallbackDto {
    /**
     * 运单编号
     * 运单编号(兼容旧接口)
     */
    private String id;
    /**
     * 任务id(新接口使用)
     */
    private String taskId;
    /**
     * 运单类型
@@ -39,11 +44,16 @@
    private String toBin;
    /**
     * 分配AGV
     * 分配AGV(兼容旧接口)
     */
    private String robotName;
    /**
     * 机器人组(新接口使用)
     */
    private String robotGroup;
    /**
     * 在库口
     */
    private Boolean atPort;
src/main/java/com/zy/asrs/task/handler/AgvHandler.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.R;
import com.zy.asrs.entity.Task;
import com.zy.asrs.entity.TaskLog;
import com.zy.asrs.entity.WrkMast;
@@ -22,11 +21,8 @@
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
@@ -69,7 +65,7 @@
            // 呼叫agv
            String response = "";
            boolean success = false;
            String url = ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_CALL_CARRY_PATH;
            String url = ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_CREATE_TASK_PATH;
            String namespace = "";
            switch (task.getIoType()) {
                case 1:
@@ -91,9 +87,10 @@
            }
            String body = getRequest(task,namespace);
            try {
                // 使用仙工M4接口
                response = new HttpHandler.Builder()
                        .setUri(ApiInterfaceConstant.AGV_IP)
                        .setPath(ApiInterfaceConstant.AGV_CALL_CARRY_PATH)
                        .setPath(ApiInterfaceConstant.AGV_CREATE_TASK_PATH)
                        .setJson(body)
                        .build()
                        .doPost();
@@ -128,34 +125,36 @@
    }
    /**
     * 构造请求内容
     * 构造请求内容(仙工M4格式)
     */
    private String getRequest(Task task, String nameSpace) {
        JSONObject object = new JSONObject();
        object.put("entityName", "ContainerTransportOrder");
        JSONObject entityValue = new JSONObject();
        entityValue.put("id", task.getId());
        // taskId使用任务ID,格式:T + 任务ID
        object.put("taskId", "T" + task.getId());
        object.put("fromBin", task.getSourceStaNo());
        object.put("toBin", task.getStaNo());
        // robotGroup从invWh字段获取,如果没有则使用默认值
        String robotGroup = task.getInvWh();
        if (robotGroup == null || robotGroup.isEmpty()) {
            robotGroup = "Group-001"; // 默认机器人组
        }
        object.put("robotGroup", robotGroup);
        // kind根据任务类型映射
        String kind = "";
        switch (nameSpace) {
            case "入库":
                kind = "inBound";
                kind = "实托入库";
                break;
            case "出库":
                kind = "outBound";
                kind = "实托出库";
                break;
            case "转移":
                kind = "moveBound";
                kind = "货物转运";
                break;
            default:
                kind = "货物转运";
        }
        entityValue.put("kind", kind);
        entityValue.put("status", "Created");
        entityValue.put("priority", 0);
        entityValue.put("container", task.getBarcode());
        entityValue.put("fromBin", task.getSourceStaNo());
        entityValue.put("toBin", task.getStaNo());
        entityValue.put("emptyFlag", task.getIoType() == 10 ? 1 : 2); // 空托1,满托2 agv带着告诉输送线plc
        object.put("entityValue", entityValue.toJSONString());
        object.put("kind", kind);
        return object.toJSONString();
    }
@@ -225,4 +224,92 @@
            basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(endSite)), "S");
        }
    }
    /**
     * 取消AGV任务(仙工M4接口)
     * @param task 任务对象
     * @return 是否成功
     */
    public boolean cancelAgvTask(Task task) {
        if (!agvSendTask) {
            return false;
        }
        if (task == null || task.getId() == null) {
            log.error("取消AGV任务失败:任务或任务ID为空");
            return false;
        }
        String response = "";
        boolean success = false;
        String url = ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_CANCEL_TASK_PATH;
        String namespace = "";
        String kind = "";
        // 根据任务类型确定kind和namespace
        switch (task.getIoType()) {
            case 1:
            case 10:
            case 53:
            case 57:
                namespace = "入库";
                kind = "实托入库";
                break;
            case 3:
                namespace = "转移";
                kind = "货物转运";
                break;
            case 101:
            case 110:
            case 103:
            case 107:
                namespace = "出库";
                kind = "实托出库";
                break;
            default:
                kind = "货物转运";
        }
        // 构造取消任务请求
        JSONObject cancelRequest = new JSONObject();
        cancelRequest.put("taskId", "T" + task.getId());
        cancelRequest.put("kind", kind);
        String body = cancelRequest.toJSONString();
        try {
            response = new HttpHandler.Builder()
                    .setUri(ApiInterfaceConstant.AGV_IP)
                    .setPath(ApiInterfaceConstant.AGV_CANCEL_TASK_PATH)
                    .setJson(body)
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("code") != null && jsonObject.getInteger("code").equals(200)) {
                success = true;
                log.info(namespace + "取消AGV任务成功:{}", task.getId());
            } else {
                log.error(namespace + "取消AGV任务失败!!!url:{};request:{};response:{}", url, body, response);
            }
        } catch (Exception e) {
            log.error(namespace + "取消AGV任务异常", e);
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        namespace + "取消AGV任务",
                        url,
                        null,
                        "127.0.0.1",
                        body,
                        response,
                        success
                );
            } catch (Exception e) {
                log.error(namespace + "取消AGV任务保存接口日志异常:", e);
            }
        }
        return success;
    }
}
src/main/java/com/zy/common/constant/ApiInterfaceConstant.java
@@ -36,8 +36,13 @@
    public static final String AGV_IP = "http://127.0.0.1:8080/yhfzwms/open/asrs";
    /**
     * 呼叫AGV搬运
     * 仙工M4 - 创建任务(货物转运、实托入库,实托出库)
     */
    public static final String AGV_CALL_CARRY_PATH = "/api/entity/create/one";
    public static final String AGV_CREATE_TASK_PATH = "/api/agv/inbond";
    /**
     * 仙工M4 - 取消任务
     */
    public static final String AGV_CANCEL_TASK_PATH = "/api/agv/cancelTransport";
}