using AngleSharp.Io; using Mapster; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using WIDESEA_Comm; using WIDESEA_Comm.AGVTask; using WIDESEA_Core; using WIDESEA_Core.Const; using WIDESEA_Core.Helper; using WIDESEA_Model.Models; using WIDESEA_StorageBasicRepository; using WIDESEA_StorageTaskRepository; namespace WIDESEA_StoragIntegrationServices { public partial class ToAGVService { /// /// AGV回调接口 /// /// /// public AGVResponBase agvCallback(object taskRespon) { AGVResponBase response = null; ContainerTask task = new ContainerTask(); try { task = JsonConvert.DeserializeObject(taskRespon.ToString()); if (task == null) { LogFactory.GetLog("AGV任务回调").Info(true, $"回调失败,未能读取到agv调取参数"); } if (task.method.ToString() == "outbin2") //AGV取料完成 { Dt_CZInfo_mes CZInfotlist = _task_CZInfoRepository.QueryFirst(x => x.CurrentStatue == "4"); if (CZInfotlist != null) { CZInfotlist.CurrentStatue = "5"; _task_CZInfoRepository.UpdateData(CZInfotlist); } WCS_Set("3022"); //不管是否有写入成功,都完成agv任务 return response = new AGVResponBase { code = "0", message = "成功", reqCode = task.reqCode }; } if (task.method.ToString() == "end") //AGV任务结束反馈 { //并进行修改任务为完成 Dt_CZInfo_mes CZInfotlist = _task_CZInfoRepository.QueryFirst(x => x.CurrentStatue == "5"); //调取输送线接口,反馈输送线完成信号 WCS_Set(CZInfotlist.AGVaddres); if(CZInfotlist != null) { CZInfotlist.CurrentStatue = "6"; _task_CZInfoRepository.UpdateData(CZInfotlist); Dt_CZInfo_mes_hty stockInfo_Hty = CZInfotlist.Adapt(); _CZInfo_Mes_HtyRepository.AddData(stockInfo_Hty); _task_CZInfoRepository.DeleteData(CZInfotlist); } //回调 return response = new AGVResponBase { code = "0", message = "成功", reqCode = task.reqCode }; } LogFactory.GetLog("AGV任务回调").Info(true, $"回调成功"); return response; } catch (Exception ex) { LogFactory.GetLog("AGV任务回调").Info(true, $"回调失败,错误信息:{ex.Message}"); return response = new AGVResponBase { code = "1", message = $"失败,原因:{ex.Message}", reqCode = task.reqCode }; } } public bool WCS_Set(string CutAddress) { try { //调取wcs接口,写入输送线信号 SetPlcResponState var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue; var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.SetPlcResponState)?.ConfigValue; if (ReceiveByWMSTask == null || ipAddress == null) { throw new Exception("WMS IP 未配置"); } var wmsIpAddrss = ipAddress + ReceiveByWMSTask; var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(CutAddress)); //http://localhost:9291/api/Task/ReceiveTask, if (respon != null) { WebResponseContent respone = JsonConvert.DeserializeObject(respon.ToString()); if (respone.Status) { return true; } else { return false; } } else { return false; } } catch (Exception ex) { return false; throw; } } } }