using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Quartz; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using WIDESEA_Comm.PLCDBItem; using WIDESEA_Core.Extensions; using WIDESEA_WCS.Jobs; using WIDESEA_WCS.WCSClient; using static Dapper.SqlMapper; namespace WIDESEA_WCS { [DisallowConcurrentExecution] public class VK4Job : JobBase, IJob { public Task Execute(IJobExecutionContext context) { try { ExecuteJob(context, DoAction); } catch (Exception ex) { } return Task.CompletedTask; } public static StackerReadDBItem StackerDBItem; private void DoAction(IJobExecutionContext context) { var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient; //自动重连 if (!client.IsConnected) { client.Connect(); return; } PropertyInfo[] propertyInfos = typeof(StackerReadDBItem).GetProperties(); if (StackerDBItem == null) { StackerDBItem = new(); //StackerDBItem.OnReadStackerSignal += HandleReadStackerSignal; } List StackerReadDBItems = new List(); var groups = client.itemGroups.OrderBy(x => x.Methods).ThenBy(x=>x.name).GroupBy(x => x.Methods); foreach (var key in groups) { //foreach (var item in key) //{ for (int i = 0; i < propertyInfos.Length; i++) { if (i == 0) { StackerDBItem.StackerNo = key.First(x=>true).Methods; } else { DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfos[i].Name); if (group != null) { object readData = DBExtension.Read(group, client); object obj = propertyInfos[i].GetValue(StackerDBItem); if (obj != readData) propertyInfos[i].SetValue(StackerDBItem, readData); } } } StackerReadDBItems.Add(StackerDBItem); //} } } } }