SendBendsInfoService.cs
8.79 KB
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
using Autofac.Core;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.Service.Repository;
using MySqlX.XDevAPI.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace Hh.Mes.Service.QuartzJobService
{
public class SendBendsInfoService : RepositorySqlSugar<bus_pipebends_job>
{
public void Execute()
{
List<bus_pipebends_job> bends = Context.Queryable<bus_pipebends_job>().Where(x => x.state == "0").Take(30).ToList(); //初始的和未发送成功的均需要一起发送
if (bends != null && bends.Count > 0)
{
Log4NetHelper.Instance.Info("开始发送弯管数据,数量:"+ bends.Count);
PDAService service = new PDAService(null);
//获取工位
List<base_work_station> stations = Context.Queryable<base_work_station>().Where(x => x.workStationCode.Contains("BentPipe") && !string.IsNullOrEmpty(x.monitorIP)).ToList();
foreach (bus_pipebends_job pipe in bends)
{
try
{
pipe.state = "1";
pipe.updateTime = DateTime.Now;
pipe.msg = "";
List<base_work_station> stations2 = stations.Where(x => x.lineCode.ToUpper() == pipe.lineCode.ToUpper()).ToList();
if (stations2.Count == 0)
{
pipe.state = "3";
pipe.msg += $" 处理失败,暂未配置弯管下发ip端口";
}
foreach (base_work_station station in stations2)
{
POJO.Response.Response result = service.InBentPipeTask(pipe.workPieceNo, station.workStationCode);
if (result.Code == 200)
{
pipe.msg += $"{station.workStationCode} 处理成功";
}
else
{
pipe.state = "2";
pipe.msg += $"{station.workStationCode} 处理失败,错误信息{result.Message}";
}
}
if (pipe.msg.Length> 254)
{
pipe.msg = pipe.msg.Substring(0, 254);
}
Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
}
catch (Exception x)
{
pipe.msg += x.Message;
if (pipe.msg.Length > 254)
{
pipe.msg = pipe.msg.Substring(0, 254);
}
pipe.state = "2";
Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
}
}
}
List<bus_pipebends_job> bends1 = Context.Queryable<bus_pipebends_job>().Where(x => x.state == "2").Take(30).ToList(); //初始的和未发送成功的均需要一起发送
if (bends1 != null && bends1.Count > 0)
{
Log4NetHelper.Instance.Info("开始再次发送弯管数据,数量:" + bends1.Count);
PDAService service = new PDAService(null);
//获取工位
List<base_work_station> stations = Context.Queryable<base_work_station>().Where(x => x.workStationCode.Contains("BentPipe") && !string.IsNullOrEmpty(x.monitorIP)).ToList();
foreach (bus_pipebends_job pipe in bends1)
{
try
{
pipe.state = "1";
pipe.updateTime = DateTime.Now;
pipe.msg = "";
List<base_work_station> stations2 = stations.Where(x => x.lineCode.ToUpper() == pipe.lineCode.ToUpper()).ToList();
if (stations2.Count == 0) {
pipe.state = "3";
pipe.msg += $" 处理失败,暂未配置弯管下发ip端口";
}
foreach (base_work_station station in stations2)
{
POJO.Response.Response result = service.InBentPipeTask(pipe.workPieceNo, station.workStationCode);
if (result.Code == 200)
{
pipe.msg += $"{station.workStationCode} 处理成功";
}
else
{
pipe.state = "2";
pipe.msg += $"{station.workStationCode} 处理失败,错误信息{result.Message}";
}
}
if (pipe.msg.Length > 254)
{
pipe.msg = pipe.msg.Substring(0, 254);
}
Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
}
catch (Exception x)
{
pipe.msg += x.Message;
if (pipe.msg.Length > 254)
{
pipe.msg = pipe.msg.Substring(0, 254);
}
pipe.state = "2";
Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
}
}
}
List<bus_pipebends_job> bends2 = Context.Queryable<bus_pipebends_job>().Where(x => x.state == "3").Take(30).ToList(); //初始的和未发送成功的均需要一起发送
if (bends2 != null && bends2.Count > 0)
{
Log4NetHelper.Instance.Info("开始检验配置发送弯管数据,数量:" + bends2.Count);
PDAService service = new PDAService(null);
//获取工位
List<base_work_station> stations = Context.Queryable<base_work_station>().Where(x => x.workStationCode.Contains("BentPipe") && !string.IsNullOrEmpty(x.monitorIP)).ToList();
foreach (bus_pipebends_job pipe in bends2)
{
try
{
pipe.state = "1";
pipe.updateTime = DateTime.Now;
pipe.msg = "";
List<base_work_station> stations2 = stations.Where(x => x.lineCode.ToUpper() == pipe.lineCode.ToUpper()).ToList();
if (stations2.Count == 0)
{
pipe.state = "3";
pipe.msg += $" 处理失败,暂未配置弯管下发ip端口";
}
foreach (base_work_station station in stations2)
{
POJO.Response.Response result = service.InBentPipeTask(pipe.workPieceNo, station.workStationCode);
if (result.Code == 200)
{
pipe.msg += $"{station.workStationCode} 处理成功";
}
else
{
pipe.state = "2";
pipe.msg += $"{station.workStationCode} 处理失败,错误信息{result.Message}";
}
}
if (pipe.msg.Length > 254)
{
pipe.msg = pipe.msg.Substring(0, 254);
}
Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
}
catch (Exception x)
{
pipe.msg += x.Message;
if (pipe.msg.Length > 254)
{
pipe.msg = pipe.msg.Substring(0, 254);
}
pipe.state = "2";
Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
}
}
}
}
}
}