分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-20 d2cef0150abe6d14cbfa60c8845795b91a1f5f97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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<StackerReadDBItem> StackerReadDBItems = new List<StackerReadDBItem>();
            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);
                //}
            }
            
        }
    }
}