using ServiceCenter.Extensions; using ServiceCenter.Logs; using ServiceCenter.Redis; using ServiceCenter.WebApi; using WCS.WorkEngineering.WebApi.Models.AGV; using WCS.WorkEngineering.WebApi.Models.AGV.Request; using WCS.WorkEngineering.WebApi.Models.AGV.Response; using WCS.WorkEngineering.WebApi.Models.WCS.Response; using WCS.WorkEngineering.WebApi.Models.WMS.Request; using WCS.WorkEngineering.WebApi.Models.WMS.Response; namespace WCS.WorkEngineering.WebApi.Controllers { /// /// AGV接口 /// public static class AgvApi { private static string _AgvUrl = null!; /// /// AGV地址 /// public static string AgvUrl { get { _AgvUrl ??= RedisHub.Default.Check("AgvUrl"); if (string.IsNullOrEmpty(_AgvUrl)) { throw new KnownException($"请在Redis配置AgvUrl", LogLevelEnum.High); } return _AgvUrl; } } #region 任务单生成 ///// ///// 盘条入库 ///// ///// 取货机台 ///// 容器编码 ///// WMS任务号 ///// 优先级 ///// //public static GenAgvSchedulingTaskResponse 盘条入库( string position, string ctnrCode, string taskCode, string priority) //{ // return GenAgvSchedulingTask("iwms_third", ctnrCode,"4", new List() // { // new positionCodeClass(){ //取货机台 // positionCode=position, // type="00" // }, // new positionCodeClass(){ //巷道分配点 // positionCode="DD3", // type="00" // }, // new positionCodeClass(){ //预分配终点 // positionCode="JT1", // type="00" // } // }, priority, taskCode, "PT05", "1"); //} //public static GenAgvSchedulingTaskResponse 叫料出库(string ctnrCode, string position, string taskCode, string priority) //{ // return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() // { // new positionCodeClass(){ //取货机台 // positionCode=position, // type="00" // }, // new positionCodeClass(){ //巷道分配点 // positionCode="DD3", // type="00" // } // }, priority, taskCode, "PT04", "1"); //} //public static GenAgvSchedulingTaskResponse 搬运(string ctnrCode, string position, string taskCode, string priority) //{ // return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() // { // new positionCodeClass(){ //取货机台 // positionCode=position, // type="00" // }, // new positionCodeClass(){ //放货站点 // positionCode="JT4", // type="00" // } // }, priority, taskCode, "PT04", "1"); //} //public static GenAgvSchedulingTaskResponse 搬运_wms(string ctnrCode, string position, string taskCode, string priority) //{ // return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() // { // new positionCodeClass(){ //取货机台 // positionCode="JT1", // type="00" // }, // new positionCodeClass(){ //放货站点 // positionCode=position, // type="00" // } // }, priority, taskCode, "PT03", "1"); //} ///// ///// Agv任务单生成接口 ///// ///// 客户端编号 ///// 容器编号 ///// 容器类型 ///// 路径 ///// 优先级 ///// 任务单号 ///// 任务类型 ///// 合金任务模板 ///// ///// //public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode,string ctnrCode,string ctnrTyp, List positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy) //{ // var res = APICaller.CallApi2("http://10.16.237.230:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest // { // clientCode = clienCode, // ctnrCode = ctnrCode, // ctnrTyp = ctnrTyp, // interfaceName = "genAgvSchedulingTask", // positionCodePath = positionCodePath, // priority = priority, // reqCode = Guid.NewGuid().ToString().Replace("-", ""), // taskCode = taskCode, // taskTyp = taskType, // hjTaskTy = hjTaskTy, // tokenCode = "56898661ea976b748f328cefa6960434", // }); // if (res.code != AgvResponseCode.Success) // { // throw new KnownException(res.message, LogLevelEnum.High); // } // return res; //} #endregion 任务单生成 #region 任务单生成测试 /// /// 盘条入库 /// /// 取货位置 /// 下个位置 /// 终点位置 /// 容器编码 /// agv任务号 /// 优先级 /// public static GenAgvSchedulingTaskResponse 盘条入库(string position1,string position2,string position3, string ctnrCode, string taskCode, string priority) { return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() { new positionCodeClass(){ //取货机台 positionCode=position1, type="00" }, new positionCodeClass(){ //巷道分配点 positionCode=position2, type="00" }, new positionCodeClass(){ //预分配终点 positionCode=position3, type="00" } }, priority, taskCode, "ZTGT30", "1"); } /// /// 缓存区到出库口 /// /// 容器编码 /// 取货位置 /// 放货位置 /// 任务号 /// 优先级 /// public static GenAgvSchedulingTaskResponse 搬运_wmsEnd(string ctnrCode, string position1, string position2, string taskCode, string priority) { return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() { new positionCodeClass(){ //取货机台 positionCode=position1, type="00" }, new positionCodeClass(){ //放货站点 positionCode=position2, type="00" } }, priority, taskCode, "PT02", "1"); } public static GenAgvSchedulingTaskResponse 搬运_wmsStart(string ctnrCode, string position1, string position2, string taskCode, string priority) { return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() { new positionCodeClass(){ //取货机台 positionCode=position1, type="00" }, new positionCodeClass(){ //放货站点 positionCode=position2, type="00" } }, priority, taskCode, "PT03", "1"); } //取放都校验 public static GenAgvSchedulingTaskResponse 搬运(string ctnrCode, string position1, string position2, string taskCode, string priority) { return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() { new positionCodeClass(){ //取货机台 positionCode=position1, type="00" }, new positionCodeClass(){ //放货站点 positionCode=position2, type="00" } }, priority, taskCode, "PT04", "1"); } public static GenAgvSchedulingTaskResponse 出库搬运_wms(string ctnrCode, string position1, string position2, string taskCode, string priority) { return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() { new positionCodeClass(){ //取货机台 positionCode=position1, type="00" }, new positionCodeClass(){ //放货站点 positionCode=position2, type="00" } }, priority, taskCode, "PT05", "1"); } /// /// 叫料出库 /// /// 容器编码 /// 取货位置 /// 放货位置 /// 任务号 /// 优先级 /// public static GenAgvSchedulingTaskResponse 叫料出库(string ctnrCode, string position1, string position2, string taskCode, string priority) { return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List() { new positionCodeClass(){ //取货机台 positionCode=position1, type="00" }, new positionCodeClass(){ //取货机台 positionCode="DD4", type="00" }, new positionCodeClass(){ //放货站台 positionCode=position2, type="00" } }, priority, taskCode, "PT05", "1"); } /// /// Agv任务单生成接口 /// /// 客户端编号 /// 容器编号 /// 容器类型 /// 路径 /// 优先级 /// 任务单号 /// 任务类型 /// 合金任务模板 /// /// public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode, string ctnrCode, string ctnrTyp, List positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy) { var res = APICaller.CallApi2("http://10.16.237.230:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest { clientCode = clienCode, ctnrCode = ctnrCode, ctnrTyp = ctnrTyp, interfaceName = "genAgvSchedulingTask", positionCodePath = positionCodePath, priority = priority, reqCode = Guid.NewGuid().ToString().Replace("-", ""), taskCode = taskCode, taskTyp = taskType, hjTaskTy = hjTaskTy, tokenCode = "56898661ea976b748f328cefa6960434", }); if (res.code != AgvResponseCode.Success) { throw new KnownException(res.message, LogLevelEnum.High); } return res; } #endregion #region 继续执行任务 /// /// 继续执行任务 /// /// AGV任务号 /// 下一个地址 /// 接口返回结果 /// public static ContinueTaskResponse ContinueTask(string taskCode, string nextPositionCode) { var res = APICaller.CallApi2("http://10.16.237.230:8181/rcms/services/rest/hikRpcService/continueTask", new ContinueTaskRequest { reqCode = Guid.NewGuid().ToString().Replace("-", ""), taskCode = taskCode, nextPositionCode = new positionCodeClass() { positionCode = nextPositionCode, type = "00" } }); if (res.code != AgvResponseCode.Success) { throw new KnownException(res.message, LogLevelEnum.High); } return res; } #endregion /// /// 取消任务 /// /// AGV任务号 /// /// public static CancelTaskResponse CancelAgvTask(string AGVtaskCode) { var res = APICaller.CallApi2(AgvUrl + "/rcms/services/rest/hikRpcService/cancelTask", new CancelTaskRequest { reqCode = Guid.NewGuid().ToString().Replace("-", ""), taskCode = AGVtaskCode, forceCancel = "0", }); if (res.code != AgvResponseCode.Success) { throw new KnownException(res.message, LogLevelEnum.High); } return res; } /// /// AGV取消任务验证 /// /// /// /// 需要取消任务的AGV任务号 /// public static CancelTaskResponse? CancelAgvTask(SRes sRes, int id, string agvTask) { try { var res = AgvApi.CancelAgvTask(agvTask); return res; } catch (Exception ex) { sRes.ResDataList.Add(new HandleTaskResponse() { IsSuccess = false, TaskNo = id, Message = $"AGV错误:{ex.Message}", }); return null; } } } }