分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-28 1e38f44af86775a341e4d0e4411d24ad35e417d3
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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
{
    /// <summary>
    /// 一二单元调度
    /// </summary>
    [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<StackerReadDBItem>();
            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);
            }
        }
        /// <summary>
        /// 添加DB地址信息
        /// </summary>
        public void AddDB()
        {
            VOLContext context = new VOLContext();
            Idt_plcinfodetailRepository repository = new dt_plcinfodetailRepository(context);
            List<dt_plcinfodetail> plcinfodetail = new List<dt_plcinfodetail>();
            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);
        }
    }
}