分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-01-31 50fd5cc9cfad08714c4daa6d481c5293ff2ae6b1
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.DBItem;
using WIDESEA_Comm.ItemDB;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Jobs;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    /// <summary>
    /// 桁架
    /// </summary>
    [DisallowConcurrentExecution]
    public class GantryJob : JobBase, IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                ExecuteJob(context, DoAction);
            }
            catch { }
            return Task.CompletedTask;
        }
 
        private void DoAction(IJobExecutionContext context)
        {
            var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
            //自动重连
            if (!client.IsConnected)
            {
                client.Connect();
                return;
            }
            Gantry gantry = new Gantry();
            gantry.QueryWheeldata(client);
            gantry.QueryOrder(client);
            gantry.Layofflevel(client);
            gantry.Stupidproofmeasure(client);
        }
 
        #region
        static List<MachineDB> MachineDBs = new List<MachineDB>();
        static List<WheelDataDB> wheelDataDBs = new List<WheelDataDB>();
        private void DoAction(PLCClient client)
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
 
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                var numbers = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep).GroupBy(x => x.plcdetail_number).ToList();
                foreach (var number in numbers)
                {
                    if (number.Key.Contains("辊道下料"))
                    {
                        PropertyInfo[] propertyInfos = typeof(WheelDataDB).GetProperties();//获取所有属性
                        WheelDataDB dBItem = wheelDataDBs.Where(x => x.R_Name == number.Key).FirstOrDefault();
                        if (dBItem == null)
                        {
                            dBItem = new();
                            dBItem.OnReadSignal += HandleReadSignal;
                            wheelDataDBs.Add(dBItem);
                        }
                        List<dt_plcinfodetail> details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == number.Key).ToList();
                        for (int i = 0; i < propertyInfos.Length; i++)
                        {
                            if (i == 0)
                            {
                                dBItem.R_Name = number.Key;
                            }
                            else
                            {
                                object readData = DBExtension.Read(details.Where(x => x.plcdetail_name == propertyInfos[i].Name).FirstOrDefault(), client);
                                if (readData != null) { }
                                object obj = propertyInfos[i].GetValue(dBItem);
                                if (obj != readData)
                                    propertyInfos[i].SetValue(dBItem, readData);
                            }
                        }
                    }
                    else
                    {
 
                        PropertyInfo[] propertyInfos = typeof(MachineDB).GetProperties();//获取所有属性
                        MachineDB dBItem = MachineDBs.Where(x => x.R_Name == number.Key).FirstOrDefault();
                        if (dBItem == null)
                        {
                            dBItem = new();
                            dBItem.OnReadSignal += HandleReadSignal;
                            MachineDBs.Add(dBItem);
                        }
                        List<dt_plcinfodetail> details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == number.Key).ToList();
                        for (int i = 0; i < propertyInfos.Length; i++)
                        {
                            if (i == 0)
                            {
                                dBItem.R_Name = number.Key;
                            }
                            else
                            {
                                object readData = DBExtension.Read(details.Where(x => x.plcdetail_name == propertyInfos[i].Name).FirstOrDefault(), client);
                                if (readData != null) { }
                                object obj = propertyInfos[i].GetValue(dBItem);
                                if (obj != readData)
                                    propertyInfos[i].SetValue(dBItem, readData);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
 
                throw;
            }
        }
        #endregion
        public void HandleReadSignal(string type, MachineDB DBItem)
        {
            switch (type)
            {
                case OperationType.OperationType_Record:
 
                    break;
                case OperationType.OperationType_Processor:
 
                    break;
                case OperationType.OperationType_WheelData:
 
                    break;
            }
        }
        public void HandleReadSignal(string type, WheelDataDB DBItem)
        {
            switch (type)
            {
                case OperationType.OperationType_Record:
 
                    break;
                case OperationType.OperationType_Processor:
 
                    break;
                case OperationType.OperationType_WheelData:
 
                    break;
            }
        }
    }
}