using FreeSql; using OfficeOpenXml.Drawing.Chart; using Quartz; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using WIDESEA_Comm; using WIDESEA_Comm.ItemDB; using WIDESEA_Comm.LogInfo; using WIDESEA_Core.EFDbContext; using WIDESEA_Core.Extensions; using WIDESEA_Entity.DomainModels; using WIDESEA_WCS.IRepositories; using WIDESEA_WCS.IServices; using WIDESEA_WCS.Jobs; using WIDESEA_WCS.Repositories; using WIDESEA_WCS.Services; using WIDESEA_WCS.WCSClient; using static System.Collections.Specialized.BitVector32; namespace WIDESEA_WCS { /// /// 一二单元调度 /// [DisallowConcurrentExecution] public class One_two_unitJob : JobBase, IJob { public Task Execute(IJobExecutionContext context) { try { AddDB(); //ExecuteJob(context, DoAction); } catch (Exception ex) { } return Task.CompletedTask; } private void DoAction(IJobExecutionContext context) { var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient; //自动重连 if (!client.IsConnected) { client.Connect(); return; } StackerReadDBItem.StackerReadDBItems = new List(); PropertyInfo[] propertyInfos = typeof(StackerReadDBItem).GetProperties(); var groups = client.itemGroups.OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList(); foreach (var key in groups) { StackerReadDBItem StackerDBItem = new StackerReadDBItem(); foreach (var propertyInfo in propertyInfos) { if (propertyInfo.Name == "StackerNo") { StackerDBItem.StackerNo = key.Key; } else { DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfo.Name); if (group != null) { var readData = DBExtension.Read(group, client); switch (propertyInfo.Name) { case "R_wheel_SN": StackerDBItem.R_wheel_SN = readData.ToString(); break; case "R_wheel_type": StackerDBItem.R_wheel_type = Convert.ToInt16(readData); break; case "R_part_status": StackerDBItem.R_part_status = Convert.ToByte(readData); break; case "R_part_process": StackerDBItem.R_part_process = Convert.ToByte(readData); break; case "R_machine_nr": StackerDBItem.R_machine_nr = Convert.ToBoolean(readData); break; case "R_direction": StackerDBItem.R_direction = Convert.ToByte(readData); break; } } } } StackerReadDBItem.StackerReadDBItems.Add(StackerDBItem); } } /// /// 添加DB地址信息 /// public void AddDB() { VOLContext context = new VOLContext(); Idt_plcinfodetailRepository repository = new dt_plcinfodetailRepository(context); List plcinfodetail = new List(); string name = "VK5"; for (int i = 1; i <= 2; i++) { dt_plcinfodetail dt_Plcinfodetail1 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (0 + (i - 1) * 144).ToString(), plcdetail_valtype = "byte", plcdetail_name = "oi_on", plcdetail_opratortype = "labeller", plcdetail_remark = "申请", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail1); dt_plcinfodetail dt_Plcinfodetail2 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (2 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "o_wp_id", plcdetail_opratortype = "labeller", plcdetail_remark = "车轮SN号", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail2); dt_plcinfodetail dt_Plcinfodetail3 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (24 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "i_job_id", plcdetail_opratortype = "labeller", plcdetail_remark = "工单编号", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail3); dt_plcinfodetail dt_Plcinfodetail4 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (22 + (i - 1) * 144).ToString(), plcdetail_valtype = "byte", plcdetail_name = "i_status", plcdetail_opratortype = "labeller", plcdetail_remark = "状态", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail4); dt_plcinfodetail dt_Plcinfodetail5 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (44 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "i_heat_id", plcdetail_opratortype = "labeller", plcdetail_remark = "炉代号", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail5); dt_plcinfodetail dt_Plcinfodetail6 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (64 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "i_billet_id", plcdetail_opratortype = "labeller", plcdetail_remark = "钢坯号", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail6); dt_plcinfodetail dt_Plcinfodetail7 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (84 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "i_batch_id", plcdetail_opratortype = "labeller", plcdetail_remark = "热处理批次", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail7); dt_plcinfodetail dt_Plcinfodetail8 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (104 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "i_drawing_id", plcdetail_opratortype = "labeller", plcdetail_remark = "图号", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail8); dt_plcinfodetail dt_Plcinfodetail9 = new dt_plcinfodetail() { plcdetail_id = Guid.NewGuid(), plcdetail_iotype = name, plcdetail_db = "DB603", plcdetail_value = (124 + (i - 1) * 144).ToString(), plcdetail_len = 20, plcdetail_valtype = "string", plcdetail_name = "i_wheel_type", plcdetail_opratortype = "labeller", plcdetail_remark = "i_wheel_type", plcdetail_number = i + "单元", }; plcinfodetail.Add(dt_Plcinfodetail9); } repository.AddRange(plcinfodetail, true); } } }