using Microsoft.EntityFrameworkCore; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using WIDESEA_Common; using WIDESEA_Common.LoctionEnum; using WIDESEA_Common.Tools; using WIDESEA_Core.EFDbContext; using WIDESEA_Entity.DomainModels; using WIDESEA_Entity.DomainModels.CacheTask.WIDESEA_Entity.DomainModels; using WIDESEA_Services.IRepositories; using WIDESEA_Services.Repositories; using WIDESEA_Services.Services; using WIDESEA_WCS.WCSClient; namespace WIDESEA_WCS.SchedulerExecute.AGV { public partial class AGVSchedulerExecute { private static int _readUpdateAGVTaskSignalsotext1 = 0; public static void UpdateAgvTaskText(PLCClient plcClient) { //if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotext1, 1) == 0) //{ //} try { if (plcClient == null) { return; } VOLContext context = new VOLContext(); Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(context); Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context); Idt_agvtask_htyRepository agvtask_HtyRepository = new dt_agvtask_htyRepository(context); Ibase_ware_locationRepository locationRepository = new base_ware_locationRepository(context); Ibill_group_stockRepository group_StockRepository = new bill_group_stockRepository(context); Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(context); Idt_containerRepository containerRepository = new dt_containerRepository(context); IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(context); Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(context); Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep); int taskFbInteractive = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveR.ToString()));//0初始,1请求更新状态 int taskFbInteractiveW = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString()));//0初始,1更新完成 string taskIdtext = plcClient.ReadValue(TaskDBName.taskIDFb.ToString()).ToString();//任务ID //0初始状态 1 RCS更新了一条任务状态 if (1 == taskFbInteractive && taskFbInteractiveW == 0) { string taskId = plcClient.ReadValue(TaskDBName.taskIDFb.ToString()).ToString();//任务ID if (taskId.Contains("\b")) { taskId = taskId.Remove(0, 1); } int taskState = int.Parse(plcClient.ReadValue(TaskDBName.taskStatusFb.ToString()).ToString());//1起点执行中,2起点已完成,3终点执行中,4终点已完成 if (0 == taskState)//无含义 { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); return; } WriteLog.GetLog().Write($"{plcClient.PLCName}任务号" + taskId + "任务状态" + taskState + "taskFbInteractive" + taskFbInteractive + "taskFbInteractiveW" + taskFbInteractiveW + $" {DateTime.Now}", "AGV更新任务状态"); dt_agvtask agvTask = agvtaskRepository.Find(r => r.agv_tasknum == taskId).FirstOrDefault(); if (agvTask == null) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); return; } if (1 == taskState)//任务起点执行中 { if (agvTask != null) { if (agvTask.agv_taskstate == AGVTaskStateEnum.Executing.ToString()) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } #region 编写对应项目的业务逻辑 //Task task = Task.Run(() => //{ //}); if (null == agvTask) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); WriteLog.GetLog().Write("起点执行失败未找到任务,ID:" + taskId + "," + DateTime.Now + "", "AGV更新任务状态"); return; //throw new Exception("起点执行失败未找到任务,ID:" + taskId); } agvTask.agv_taskstate = AGVTaskStateEnum.Executing.ToString(); if (agvTask.agv_realesstime == null) { agvTask.agv_realesstime = DateTime.Now; } int isOk = agvtaskRepository.Update(agvTask, true); if (isOk == 0) { agvTask.agv_taskstate = AGVTaskStateEnum.Abnormal.ToString(); isOk = agvtaskRepository.Update(agvTask, true); } #endregion //WriteLog.GetLog().Write("车号上报,,任务号:" + agvTask.agv_tasknum + " 反馈时间:" + DateTime.Now + "", "AGV更新任务状态"); plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } else { break; } } } //else //{ // WriteLog.GetLog().Write($"任务号:{taskId},AGV任务列表未找到此条任务 时间: {DateTime.Now}", "AGV任务反馈1"); // WriteLog.GetLog().Write("起点执行失败未找到任务,ID:" + taskId + "," + DateTime.Now + "", "AGV更新任务状态"); // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // for (int i = 0; i < 5; i++) // { // Thread.Sleep(150); // var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); // if (agvnumber != 1) // { // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // } // else // { // break; // } // } //} } else if (2 == taskState)//任务起点已完成 { if (agvTask != null) { if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString()) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } #region 编写对应项目的业务逻辑 //Task.Run(() => //{ //}); if (null == agvTask) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); WriteLog.GetLog().Write("WCS写入AGV任务号,当前任务号不存在任务列表里," + taskId + DateTime.Now + "任务起点完成状态确认1", "AGV更新任务状态"); return; } agvTask.agv_taskstate = AGVTaskStateEnum.Complete.ToString(); int isOk = agvtaskRepository.Update(agvTask, true); if (isOk == 0) { agvTask.agv_taskstate = AGVTaskStateEnum.Abnormal.ToString(); isOk = agvtaskRepository.Update(agvTask, true); } if (agvTask.agv_remark.Contains("PDA库房叫料任务") || agvTask.agv_remark.Contains("PDA产线叫料任务")) { base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_fromaddress); if (pda_Location == null) { return; } dt_container container = containerRepository.FindFirst(d => d.container_sn == agvTask.agv_barcode && d.container_barcode == pda_Location.L_Code); if (container != null) { containerRepository.Delete(container, true); pda_Location.L_Task = 2; pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString(); pdaloctionRepository.Update(pda_Location, true); } } else if (agvTask.agv_remark.Contains("PDA回流任务")) { base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_fromaddress); if (pda_Location == null) { return; } pda_Location.L_Task = 2; pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString(); pdaloctionRepository.Update(pda_Location, true); } else if (agvTask.agv_remark.Contains("铝壳缓存架任务")) { dt_stationinfo dt_Stationinfo = stationinfoRepository.FindFirst(d => d.stationCode == agvTask.agv_fromaddress); if (dt_Stationinfo == null) { return; } dt_Stationinfo.task = false; int a = stationinfoRepository.Update(dt_Stationinfo, x => new { x.task }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{dt_Stationinfo.stationCode},货位修改失败", $"货位修改失败"); } } #endregion plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } else { break; } } } //else //{ // WriteLog.GetLog().Write($"任务号:{taskId},AGV任务列表未找到此条任务 时间: {DateTime.Now}", "AGV任务反馈2"); // WriteLog.GetLog().Write("WCS写入AGV任务号,当前任务号不存在任务列表里," + taskId + DateTime.Now + "任务起点完成状态确认1", "AGV更新任务状态"); // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // for (int i = 0; i < 5; i++) // { // Thread.Sleep(150); // var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); // if (agvnumber != 1) // { // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // } // else // { // break; // } // } // WriteLog.GetLog().Write("WCS写入AGV任务号" + taskId + DateTime.Now + "任务起点完成状态确认1", "AGV更新任务状态"); //} } else if (3 == taskState)//任务终点执行中 { if (agvTask != null) { #region 编写对应项目的业务逻辑 //Task.Run(() => //{ //}); if (agvTask.agv_taskstate == AGVTaskStateEnum.Executing1.ToString()) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); WriteLog.GetLog().Write("WCS再次写入AGV任务号" + taskId + "," + DateTime.Now + "任务终点执行中状态确认1", "AGV更新任务状态"); } else { agvTask.agv_taskstate = AGVTaskStateEnum.Executing1.ToString(); int isOk = agvtaskRepository.Update(agvTask, true); if (isOk == 0) { agvTask.agv_taskstate = AGVTaskStateEnum.Abnormal.ToString(); isOk = agvtaskRepository.Update(agvTask, true); } if (agvTask.agv_fromaddress.Contains("HCJ")) { base_ware_location location = locationRepository.FindFirst(x => x.upper_code == agvTask.agv_fromaddress); if (!agvTask.agv_remark.Contains("切卷上料回空")) { location.geartype = "暂无"; } location.update_time = DateTime.Now; location.logic_col = 0; location.task = 2; location.logic_row = "0"; int a = locationRepository.Update(location, x => new { x.logic_col, x.task, x.logic_row, x.update_time, x.geartype }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); } } } #endregion plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } else { break; } } } //else //{ // WriteLog.GetLog().Write($"任务号:{taskId},AGV任务列表未找到此条任务 时间: {DateTime.Now}", "AGV任务反馈3"); // WriteLog.GetLog().Write("WCS写入AGV任务号,当前任务号不存在任务列表里," + taskId + "," + DateTime.Now + "任务终点完成状态确认1", "AGV更新任务状态"); // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // for (int i = 0; i < 5; i++) // { // Thread.Sleep(150); // var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); // if (agvnumber != 1) // { // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // } // else // { // break; // } // } //} } else if (4 == taskState)//任务终点完成 { if (agvTask != null) { #region 编写对应项目的业务逻辑 //Task.Run(() => //{ //}); agvTask.agv_taskstate = AGVTaskStateEnum.Complete1.ToString(); int isOk = agvtaskRepository.Update(agvTask, true); if (isOk == 0) { agvTask.agv_taskstate = AGVTaskStateEnum.Abnormal.ToString(); isOk = agvtaskRepository.Update(agvTask, true); } agvtask_HtyRepository.AddTaskHistory(agvTask, AGVTaskStateEnum.TaskState_Finished.ToString()); agvtaskRepository.Delete(agvTask, true); base_ware_location location = locationRepository.FindFirst(x => x.upper_code == agvTask.agv_toaddress); if (agvTask.agv_remark.Contains("辊分下料任务")) { if (location != null) { if (location.upper_code.Contains("ZJ-GFHCJ10-")) { string locnum = location.upper_code.Remove(11); dt_agvtask Agvtask = agvtaskRepository.FindFirst(d => d.agv_tasknum != agvTask.agv_tasknum && d.agv_toaddress.Contains(locnum)); if (Agvtask == null) { location.logic_col = 0; location.task = 2; int a = locationRepository.Update(location, d => new { d.logic_col, d.task, }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); } //freeDB.Update(_Location2).UpdateColumns(t => new { t.location_state, t.logic_col, t.task, t.update_time }).ExecuteAffrows(); } } else { string locnum = location.upper_code.Remove(10); dt_agvtask Agvtask = agvtaskRepository.FindFirst(d => d.agv_tasknum != agvTask.agv_tasknum && d.agv_toaddress.Contains(locnum)); if (Agvtask == null) { location.logic_col = 0; location.task = 2; int a = locationRepository.Update(location, d => new { d.logic_col, d.task, }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); } } } } else if (location == null) { string NUM = ""; if (agvTask.agv_toaddress.Contains("ZJ-GFHCJ10-")) { NUM = agvTask.agv_toaddress.Remove(11) + "4"; } else { NUM = agvTask.agv_toaddress.Remove(10) + "4"; } string TNUM = ""; if (agvTask.agv_toaddress.Contains("ZJ-GFHCJ10-")) { TNUM = agvTask.agv_toaddress.Remove(11); } else { TNUM = agvTask.agv_toaddress.Remove(10); } base_ware_location loc_gf = locationRepository.FindFirst(t => t.upper_code == NUM); if (loc_gf != null) { string locnum = TNUM; dt_agvtask Agvtask = agvtaskRepository.FindFirst(d => d.agv_tasknum != agvTask.agv_tasknum && d.agv_toaddress.Contains(locnum)); if (Agvtask == null) { //WriteLog.GetLog().Write($"是否除了{Agvtask.agv_tasknum},还有这个货架的任务,结果:{Agvtask}", $"辊分下料任务反馈"); loc_gf.logic_col = 0; loc_gf.task = 2; int a = locationRepository.Update(loc_gf, d => new { d.logic_col, d.task, }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); } } } else { WriteLog.GetLog().Write($"货位信息未找到;{NUM}的货位", $"辊分下料任务反馈"); WriteLog.GetLog().Write($"-----------------------------------", $"辊分下料任务反馈"); } } } else if (location != null) { if (agvTask.agv_remark.Contains("辊分下料呼叫")) { location.logic_col = 1; location.task = 2; location.update_time = DateTime.Now; int a = locationRepository.Update(location, d => new { d.logic_col, d.task, d.update_time, }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); } } else if (agvTask.agv_toaddress.Contains("HCJ")) { if (location.upper_code.Contains("FJ-BCHCJ37") || location.upper_code.Contains("FJ-BCHCJ36") || location.upper_code.Contains("ZJ-BCHCJ35") || location.upper_code.Contains("ZJ-BCHCJ34")) { location.logic_row = "TSJXL-BCK"; location.logic_col = 1; } else if (location.upper_code.Contains("FJ-BCHCJ35") || location.upper_code.Contains("FJ-BCHCJ34") || location.upper_code.Contains("ZJ-BCHCJ33") || location.upper_code.Contains("ZJ-BCHCJ32")) { location.logic_row = "TBXL-BCK"; location.logic_col = 1; } else if (agvTask.agv_fromaddress.Contains("FJ-BCHCJ37") || agvTask.agv_fromaddress.Contains("ZJ-BCHCJ35")) { location.logic_row = "TSJXL-BCK"; location.logic_col = 0; } else if (agvTask.agv_fromaddress.Contains("FJ-BCHCJ35") || agvTask.agv_fromaddress.Contains("ZJ-BCHCJ33")) { location.logic_row = "TBXL-BCK"; location.logic_col = 0; } else { if (!agvTask.agv_remark.Contains("切卷上料呼叫")) { location.geartype = "暂无"; } location.logic_row = "0"; location.logic_col = 0; } location.task = 2; int a = locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); } } } else if (agvTask.agv_remark.Contains("PDA库房叫料任务")) { base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_toaddress); if (pda_Location == null) { return; } //库房叫料等于库存转移 dt_container dt_Container = new dt_container() { container_id = Guid.NewGuid(), container_sn = agvTask.agv_barcode, container_barcode = pda_Location.L_Code, container_materielid = agvTask.agv_materielid, container_state = "FullBox",//满箱 container_creator = "WCS", container_createtime = DateTime.Now }; containerRepository.Add(dt_Container, true); pda_Location.L_Task = 2; pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString(); pdaloctionRepository.Update(pda_Location, true); } else if (agvTask.agv_remark.Contains("PDA产线叫料任务")) { //产线叫料等于出库 base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_toaddress); if (pda_Location == null) { return; } pda_Location.L_Task = 2; pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString(); pdaloctionRepository.Update(pda_Location, true); } else if (agvTask.agv_remark.Contains("PDA回流任务")) { base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_toaddress); if (pda_Location == null) { return; } dt_container dt_Container = new dt_container() { container_id = Guid.NewGuid(), container_sn = agvTask.agv_barcode, container_barcode = pda_Location.L_Code, container_materielid = "03", container_state = "emptybox",//空箱 container_creator = "WCS", container_createtime = DateTime.Now }; containerRepository.Add(dt_Container, true); pda_Location.L_Task = 2; pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString(); pdaloctionRepository.Update(pda_Location, d => new { d.L_state, d.L_Task }, true); } else if (agvTask.agv_remark.Contains("铝壳缓存架任务")) { dt_stationinfo dt_Stationinfo = stationinfoRepository.FindFirst(d => d.stationCode == agvTask.agv_toaddress); if (dt_Stationinfo == null) { return; } dt_Stationinfo.task = false; int a = stationinfoRepository.Update(dt_Stationinfo, x => new { x.task }, true); if (a == 0) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{dt_Stationinfo.stationCode},货位修改失败", $"货位修改失败"); } } #endregion plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } else { break; } } } //else //{ // WriteLog.GetLog().Write($"任务号:{taskId},AGV任务列表未找到此条任务 时间: {DateTime.Now}", "AGV任务反馈4"); // WriteLog.GetLog().Write("WCS写入AGV任务号,当前任务号不存在任务列表里," + taskId + "," + DateTime.Now + "任务终点完成状态确认1", "AGV更新任务状态"); // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // for (int i = 0; i < 5; i++) // { // Thread.Sleep(150); // var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); // if (agvnumber != 1) // { // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); // } // else // { // break; // } // } // WriteLog.GetLog().Write("WCS写入AGV任务号" + taskId + "," + DateTime.Now + "任务终点完成状态确认1", "AGV更新任务状态"); //} } else if (5 == taskState) //取消任务 { #region 编写对应项目的业务逻辑 //Task.Run(() => //{ //}); if (null == agvTask) { WriteLog.GetLog().Write($"任务号:{taskId},AGV任务列表未找到此条任务 时间: {DateTime.Now}", "AGV任务反馈5"); WriteLog.GetLog().Write("没有当前任务号的任务,ID:" + taskId, "AGV更新任务状态"); plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } else { break; } } WriteLog.GetLog().Write("WCS写入AGV任务号" + taskId + "," + DateTime.Now + "任务终点完成状态确认1", "AGV更新任务状态"); return; //throw new Exception("没有当前任务号的任务,ID:" + taskId); } WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈5"); if (agvTask.agv_toaddress.Contains("HCJ") && agvTask.agv_fromaddress.Contains("SB")) { if (agvTask.agv_remark.Contains("辊分下料任务")) { if (agvTask.agv_toaddress.Contains("ZJ-GFHCJ10-")) { string NUM = agvTask.agv_toaddress.Remove(11) + "4"; base_ware_location location = locationRepository.FindFirst(x => x.upper_code == NUM); if (location != null) { string lotionCode = agvTask.agv_toaddress.Remove(11); dt_agvtask Agvtask = agvtaskRepository.FindFirst(d => d.agv_tasknum != agvTask.agv_tasknum && d.agv_toaddress.Contains(lotionCode)); if (Agvtask == null) { location.logic_col = 0; location.logic_row = "0"; location.task = 2; locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task }, true); } } } else { string NUM = agvTask.agv_toaddress.Remove(10) + "4"; base_ware_location location = locationRepository.FindFirst(x => x.upper_code == NUM); if (location != null) { string lotionCode = agvTask.agv_toaddress.Remove(10); dt_agvtask Agvtask = agvtaskRepository.FindFirst(d => d.agv_tasknum != agvTask.agv_tasknum && d.agv_toaddress.Contains(lotionCode)); if (Agvtask == null) { location.logic_col = 0; location.logic_row = "0"; location.task = 2; locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task }, true); } } } } else { base_ware_location location = locationRepository.FindFirst(x => x.upper_code == agvTask.agv_toaddress); location.logic_col = 0; location.logic_row = "0"; location.task = 2; locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task }, true); } } else if (agvTask.agv_toaddress.Contains("SB") && agvTask.agv_fromaddress.Contains("HCJ")) { base_ware_location location = locationRepository.FindFirst(x => x.upper_code == agvTask.agv_fromaddress); location.logic_col = 0; location.logic_row = "0"; location.task = 2; locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task }, true); } else if (agvTask.agv_toaddress.Contains("HCJ") && agvTask.agv_fromaddress.Contains("HCJ")) { if (agvTask.agv_remark.Contains("铝壳缓存架任务")) { dt_stationinfo dt_Stationinfobegin = dt_stationinfoRepository.Instance.FindFirst(d => d.stationCode == agvTask.agv_fromaddress); dt_stationinfo dt_Stationinfoend = dt_stationinfoRepository.Instance.FindFirst(d => d.stationCode == agvTask.agv_toaddress); dt_Stationinfobegin.task = false; dt_Stationinfoend.task = false; int a = dt_stationinfoRepository.Instance.Update(dt_Stationinfobegin, x => new { x.task }, true); int b = dt_stationinfoRepository.Instance.Update(dt_Stationinfoend, x => new { x.task }, true); } else { base_ware_location location = locationRepository.FindFirst(x => x.upper_code == agvTask.agv_toaddress); location.logic_col = 0; location.logic_row = "0"; location.task = 2; base_ware_location location1 = locationRepository.FindFirst(x => x.upper_code == agvTask.agv_fromaddress); location1.logic_col = 0; location1.logic_row = "0"; location1.task = 2; if (!agvTask.agv_remark.Contains("切卷上料呼叫")) { location.geartype = "暂无"; locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task, x.geartype }, true); var entry = locationRepository.DbContext.ChangeTracker.Entries().FirstOrDefault(); if (entry != null) { entry.State = EntityState.Detached; } int a = locationRepository.Update(location1, x => new { x.logic_col, x.logic_row, x.task }, true); if (a != 1) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},修改失败:{a},时间: {DateTime.Now}", "AGV任务反馈5"); } } else if (!agvTask.agv_remark.Contains("切卷上料回空")) { location1.geartype = "暂无"; locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task, x.geartype }, true); var entry = locationRepository.DbContext.ChangeTracker.Entries().FirstOrDefault(); if (entry != null) { entry.State = EntityState.Detached; } int a = locationRepository.Update(location1, x => new { x.logic_col, x.logic_row, x.task, x.geartype }, true); if (a != 1) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},修改失败:{a},时间: {DateTime.Now}", "AGV任务反馈5"); } } else { locationRepository.Update(location, x => new { x.logic_col, x.logic_row, x.task }, true); var entry = locationRepository.DbContext.ChangeTracker.Entries().FirstOrDefault(); if (entry != null) { entry.State = EntityState.Detached; } int a = locationRepository.Update(location1, x => new { x.logic_col, x.logic_row, x.task }, true); if (a != 1) { WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},修改失败:{a},时间: {DateTime.Now}", "AGV任务反馈5"); } } } } else if (agvTask.agv_toaddress.Contains("HCG") && agvTask.agv_fromaddress.Contains("HCG")) { base_pda_location dt_Stationinfobegin = base_pda_locationRepository.Instance.FindFirst(d => d.L_Code == agvTask.agv_fromaddress); base_pda_location dt_Stationinfoend = base_pda_locationRepository.Instance.FindFirst(d => d.L_Code == agvTask.agv_toaddress); dt_Stationinfobegin.L_Task = 2; dt_Stationinfoend.L_Task = 2; int a = base_pda_locationRepository.Instance.Update(dt_Stationinfobegin, x => new { x.L_Task }, true); int b = base_pda_locationRepository.Instance.Update(dt_Stationinfoend, x => new { x.L_Task }, true); } string Operate = "AGV取消"; agvtask_HtyRepository.AddTaskHistory(agvTask, Operate); #endregion plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); } else { break; } } WriteLog.GetLog().Write("WCS写入AGV任务号" + taskId + DateTime.Now + "任务异常状态确认1", "AGV更新任务状态"); agvtaskRepository.Delete(agvTask, true); } } if (taskFbInteractive == 0 && taskFbInteractiveW == 1) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 0); for (int i = 0; i < 5; i++) { Thread.Sleep(150); var agvnumber = Convert.ToInt32(plcClient.ReadValue(TaskDBName.taskFbInteractiveW.ToString())); if (agvnumber != 0) { plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 0); } else { break; } } } //else if (taskFbInteractive == 1 && taskFbInteractiveW == 1) //{ // plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 0); //} } catch (Exception ex) { WriteLog.GetLog().Write("WCS接收AGV任务反馈异常" + ex.Message.ToString() + DateTime.Now, "AGV更新任务状态"); } //finally //{ // Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotext1, 0); //} } } }