分支自 SuZhouGuanHong/TaiYuanTaiZhong

huanghongfeng
2024-07-04 08dd2afd7a9614dad029e94918516b068d413cac
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
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 = "Pipeline";
            for (int i = 1; i <= 3; i++)
            {
                dt_plcinfodetail dt_Plcinfodetail1 = new dt_plcinfodetail()
                {
                    plcdetail_id = Guid.NewGuid(),
                    plcdetail_iotype = name,
                    plcdetail_db = "DB29",
                    plcdetail_value = (21 + (i - 1) * 80).ToString(),
                    plcdetail_valtype = "string",
                    plcdetail_len = 20,
                    plcdetail_name = "R_Wheel_SN",
                    plcdetail_opratortype = "oiler",
                    plcdetail_remark = "Wheel_SN",
                    plcdetail_number = i + "单元",
                };
                plcinfodetail.Add(dt_Plcinfodetail1);
                dt_plcinfodetail dt_Plcinfodetail2 = new dt_plcinfodetail()
                {
                    plcdetail_id = Guid.NewGuid(),
                    plcdetail_iotype = name,
                    plcdetail_db = "DB29",
                    plcdetail_value = (22 + (i - 1) * 80).ToString(),
                    plcdetail_valtype = "int16",
                    plcdetail_name = "R_Wheel_Type",
                    plcdetail_opratortype = "oiler",
                    plcdetail_remark = "Wheel_Type",
                    plcdetail_number = i + "单元",
                };
                plcinfodetail.Add(dt_Plcinfodetail2);
                dt_plcinfodetail dt_Plcinfodetail3 = new dt_plcinfodetail()
                {
                    plcdetail_id = Guid.NewGuid(),
                    plcdetail_iotype = name,
                    plcdetail_db = "DB29",
                    plcdetail_value = (24 + (i - 1) * 80).ToString(),
                    plcdetail_valtype = "byte",
                    plcdetail_name = "R_Part_Status",
                    plcdetail_opratortype = "oiler",
                    plcdetail_remark = "Part_Status",
                    plcdetail_number = i + "单元",
                };
                plcinfodetail.Add(dt_Plcinfodetail3);
                dt_plcinfodetail dt_Plcinfodetail4 = new dt_plcinfodetail()
                {
                    plcdetail_id = Guid.NewGuid(),
                    plcdetail_iotype = name,
                    plcdetail_db = "DB29",
                    plcdetail_value = (25 + (i - 1) * 80).ToString(),
                    plcdetail_valtype = "byte",
                    plcdetail_name = "R_Part_Process",
                    plcdetail_opratortype = "oiler",
                    plcdetail_remark = "Part_Process",
                    plcdetail_number = i + "单元",
                };
                plcinfodetail.Add(dt_Plcinfodetail4);
            }
            repository.AddRange(plcinfodetail, true);
        }
    }
}