using Newtonsoft.Json; using WIDESEA_Comm.LogInfo; using WIDESEA_Common; using WIDESEA_Core.EFDbContext; using WIDESEA_Entity.DomainModels; using WIDESEA_Entity.ToAGV; using WIDESEA_WMS.Common; using WIDESEA_WMS.Common.AGVTask; using WIDESEA_WMS.IRepositories; using WIDESEA_WMS.Repositories; namespace WIDESEA_WMS { public partial class ToAGVServer { /// /// 修改任务状态 /// /// /// public static AGVRespone UpdateTaskState(string json) { VOLContext context = new VOLContext(); Idt_agvtaskRepository repository = new dt_agvtaskRepository(context); AGVRespone respone = new AGVRespone(); UpdateTasteInfo tasteInfo = new(); string remark = "AGV反馈任务状态:"; try { if (string.IsNullOrEmpty(json) || json == "null") throw new Exception("未获取到请求参数数据"); tasteInfo = JsonConvert.DeserializeObject(json); if (tasteInfo == null) throw new Exception("请求参数格式不对!"); if (string.IsNullOrEmpty(tasteInfo.TASK_NO)) throw new Exception("未获取到任务号!"); var task = repository.FindFirst(x => x.agv_tasknum == tasteInfo.TASK_NO); if (task == null) throw new Exception("未找到任务,任务ID:" + tasteInfo.TASK_NO); if (tasteInfo.TASK_State < 1 || tasteInfo.TASK_State > 4) throw new Exception("未定义的任务状态:" + tasteInfo.TASK_State); var StateName = Enum.GetName(typeof(AGVTaskStateEnum), tasteInfo.TASK_State); if (task.agv_taskstate == StateName && task.agv_taskstate != AGVTaskStateEnum.Complete1.ToString()) { respone.success = 2; respone.Message = tasteInfo.TASK_NO + ":重复调用,任务状态为:" + tasteInfo.TASK_State; return respone; } #region 判断任务状态 //List list = new List() { AGVTaskStateEnum.Executing.ToString(), AGVTaskStateEnum.Complete.ToString(), AGVTaskStateEnum.Executing1.ToString(), AGVTaskStateEnum.Complete1.ToString() }; //var index = list.IndexOf(task.agv_taskstate) + 1; //if (tasteInfo.TASK_State < index) // throw new Exception("任务状态更新异常!当前任务状态为:" + index + ";请求更新状态为:" + tasteInfo.TASK_State); #endregion task.agv_taskstate = StateName; if (tasteInfo.TASK_State == (int)AGVTaskStateEnum.Executing) { remark = remark + "起点执行中"; task.agv_executingBeginTime = DateTime.Now; } else if (tasteInfo.TASK_State == (int)AGVTaskStateEnum.Complete) { remark = remark + "起点已完成"; HandleTask.AutoUpdateHCJState(task); task.agv_executingEndTime = DateTime.Now; } else if (tasteInfo.TASK_State == (int)AGVTaskStateEnum.Executing1) { remark = remark + "终点执行中"; task.agv_completeBeginTime = DateTime.Now; } var count = repository.Update(task, true); if (count < 1) throw new Exception("任务状态更新失败!任务ID:" + tasteInfo.TASK_NO + ";任务状态:" + tasteInfo.TASK_State); if (tasteInfo.TASK_State == (int)AGVTaskStateEnum.Complete1) { remark = remark + "终点已完成"; task.agv_finishedtime = DateTime.Now; #region 同步MES出入库信息 HandleTask_Mes.UploadMESInfo(task); #endregion HandleTask.Updateinventory(task); HandleTask.AutoUpdateHCJState(task); HandleTask.AddHtyTask(task); } respone.success = 1; return respone; } catch (Exception ex) { respone.success = 3; respone.Message = ex.Message; } finally { WriteWMSLog.LogAdd(tasteInfo.TASK_NO, respone.success == 1 ? "成功 " : "失败", "WMS", "AGV", json, JsonConvert.SerializeObject(respone), remark, "UpdateTaskState", respone.Message); } return respone; } } }