using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using WIDESEA_Common; using WIDESEA_Common.Tools; using WIDESEA_Core.EFDbContext; using WIDESEA_Core.Utilities; using WIDESEA_Entity.DomainModels; using WIDESEA_Services; using WIDESEA_Services.IRepositories; using WIDESEA_Services.Repositories; using WIDESEA_Services.Services; using WIDESEA_WCS.WCSClient; namespace WIDESEA_WCS.Jobs { public partial class EquipmentExecutor : SchedulerExecuteBase { private static int _readSignalso = 0; /// /// 涂布机下料工作逻辑 /// /// public static void Z_TBSB_DownTask() { if (Interlocked.Exchange(ref _readSignalso, 1) == 0) { WebResponseContent responseContent = new WebResponseContent(); try { VOLContext Context = new VOLContext(); Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context); dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep); Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context); Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context); Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context); Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context); Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context); List TBSB = new List { "正极1号涂布机", "正极2号涂布机", "正极3号涂布机" }; IequipmentRepository equipmentRepository = new equipmentRepository(Context); PLCClient zagvplc = WCSService.Clients.Find(v => v.PLCName == "正极1号AGV"); foreach (var item in TBSB) { WriteLog.Info($"{item}上料").Write($"{item}开始,时间:" + DateTime.Now + " ----------", $"{item}上料"); PLCClient plc = WCSService.Clients.Find(v => v.PLCName == item); if (plc == null) continue; var task = agvRepository.FindFirst(f => f.agv_fromaddress == plc.PLCDownLoc); if (task == null) { //获取下料请求 string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_TBSB_DOWNrequest.ToString(), plc.PLCDescroption).ToString(); //获取工单号 string batchNo = plc.ReadValue(ConveyorLineInfoDBName.R_TBSB_DOWNbatchNo.ToString(), plc.PLCDescroption).ToString(); GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "", ""); WriteLog.Info($"{item}下料").Write($"isWork:{isWork},batchNo:{batchNo},时间:" + DateTime.Now + " ----------", $"{item}下料"); if (bool.Parse(isWork)) { //调用MES接口获取下料信息 MESback material = MESAPIInvoke.EquipUnloading(plc.PLCDownLoc, batchNo); WriteLog.Info($"{item}下料").Write($"MES返回数据:{JsonConvert.SerializeObject(material)},时间:" + DateTime.Now + "", $"{item}下料"); if (material.Code == 0) { //查询路由信息 var routes = routingRepository.Find(v => v.route_began == plc.PLCDownLoc).ToList(); foreach (var route in routes) { string ismaterial = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), route.route_end).ToString(); GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "", route.route_end+"的货位状态是"+ismaterial); if (ismaterial == "2") continue; var location = locRepository.FindFirst(v => v.upper_code == route.route_end); if (location.location_state != LocationStateEnum.LocationState_Empty.ToString()) continue; //条件全部通过,生成AGV任务 dt_agvtask agvtask = new dt_agvtask { agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码 agv_barcode = "", agv_code = "正极1号AGV", agv_createtime = DateTime.Now, agv_fromaddress = route.route_began, agv_grade = 1, agv_materielid = material.MaterialType, agv_qty = 1, agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep), agv_taskstate = "Create", agv_tasktype = "TaskType_Outbound", agv_toaddress = route.route_end, agv_userid = "WCS", agv_worktype = 1 }; location.location_state = LocationStateEnum.LocationState_Lock.ToString(); locRepository.Update(location, true); agvRepository.Add(agvtask, true); WriteLog.Info("Z_TBSB_DownTask").Write("Z_TBSB_DownTask" + agvtask.agv_tasknum + DateTime.Now, "Z_TBSB_DownTask"); break; } } else { WriteLog.Info("F_TBSB_DownTask").Write("调用MES接口EquipUnloading失败" + material.Message, "F_TBSB_DownTask"); } } } WriteLog.Info($"{item}下料").Write($"{item}结束,时间:" + DateTime.Now + $" ----------{Environment.NewLine}", $"{item}下料"); } } catch (Exception ex) { WriteLog.Info("Z_TBSB_DownTask").Write("Z_TBSB_DownTask" + ex.Message + DateTime.Now, "Z_TBSB_DownTask"); StackTrace stackTrace = new StackTrace(); StackFrame[] stackFrames = stackTrace.GetFrames(); string str = ""; foreach (var item in stackFrames) { str += "方法名:" + item.GetMethod().Name + ",行号:" + item.GetFileLineNumber() + ",文件名:" + item.GetFileName() + Environment.NewLine; } WIDESEA_Common.Tools.WriteLog.GetLog("正极涂布下料").Write($"错误信息:{ex.Message},{str}", "正极涂布下料"); } finally { Interlocked.Exchange(ref _readSignalso, 0); } } } } }