PDAService.cs
13.5 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
using ApkInfo;
using Hh.Mes.Common;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Redis;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.Service.Repository;
using Hh.Mes.Service.SystemAuth;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hh.Mes.Service
{
public class PDAService : RepositorySqlSugar<sys_user>
{
AuthContextFactory authContextFactory;
public PDAService(AuthContextFactory authContextFactory)
{
this.authContextFactory = authContextFactory;
}
/// <summary>
/// PDA物料追溯查询
/// (扫码查询物料追溯码,查看物料的批次,物料名称,壁厚等物料信息)
/// </summary>
/// <param name="barCode"></param>
/// <returns></returns>
public dynamic GetMaterialInfoByBarCode(dynamic requestData)
{
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
var reqData = DynamicJson.Parse(requestData.ToString());
var response = new Response();
if (reqData == null||!reqData.IsDefined("barCode"))
{
return response.ResponseError($"barCode:参数字段不正确,请核对!");
}
string barCode = reqData.barCode;
if (string.IsNullOrEmpty(barCode)) return response.ResponseError($"barCode:值不能为空,请核对!");
//1:扫码 BarCode 查询bus_workOrder_detail 表确认BarCode是否存在。
var bwdInfo = Context.Queryable<bus_workOrder_detail>().First(x => x.barCode == barCode);
if (bwdInfo == null || string.IsNullOrEmpty(bwdInfo.barCode))
{
return response.ResponseError($"barCode:【{barCode}】不存在工序任务明细表中,请核对!");
}
if (string.IsNullOrEmpty(bwdInfo.cutMaterCode))
{
return response.ResponseError($"根据barCode:【{barCode}】未查询到工序任务明细表中的物料编码信息,请核对!");
}
//2:根据BarCode 查询到当前行的 materialCode,在去物料表查询 返回物料表的基础信息。
var materialInfo = Context.Queryable<base_material>().First(x => x.materialCode == bwdInfo.cutMaterCode);
if (materialInfo == null) return response.ResponseError($"未查询到{bwdInfo.cutMaterCode}的物料基础信息,请检查!");
response.Result = materialInfo;
return response;
});
}
#region 组对、焊接
/// <summary>
/// 获取匹配的组对信息
/// </summary>
/// <param name="pipe">管段码</param>
/// <param name="batch">批次码</param>
/// <returns></returns>
public dynamic GetMatchTeamList(string pipe, string batch)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
if (string.IsNullOrWhiteSpace(pipe))
{
response.ResponseErr($"管段码【{pipe}】是空,请重新扫描管段码!");
return response;
}
if (string.IsNullOrWhiteSpace(batch))
{
response.ResponseErr($"批次码【{batch}】是空,请重新扫描批次码!");
return response;
}
var materialCode = batch;//todo:批次需要调用接口获取物料码
var resultDetail = Context.Queryable<bus_workOrder_detail>().Where(x =>
x.barCode.Equals(pipe) &&
x.state == (int)EnumOrderBodyStatus.初始化 &&
x.weldMaterCode.Equals(materialCode) &&
x.workCenterCode == "Polish").ToList();
bus_workOrder_head result = null;
if (resultDetail.Count > 0)
{
result = Context.Queryable<bus_workOrder_head>().Where(x => x.keys == resultDetail[0].headKeys).First();
result.teamList = resultDetail;
}
response.Result = result;
return response;
});
}
/// <summary>
/// 获取组对开始列表
/// </summary>
/// <returns></returns>
public dynamic GetTeamStartList()
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
var resultDetail = Context.Queryable<bus_workOrder_detail>().Where(x =>
(x.state > (int)EnumOrderBodyStatus.初始化 && x.state < (int)EnumOrderBodyStatus.已完成) &&
x.workCenterCode == "Polish").ToList();
var headKeyList = Context.Queryable<bus_workOrder_detail>().Where(x =>
(x.state > (int)EnumOrderBodyStatus.初始化 && x.state < (int)EnumOrderBodyStatus.已完成) &&
x.workCenterCode == "Polish").GroupBy(x => x.headKeys).Select(x => x.headKeys).ToList();
List<bus_workOrder_head> result = new List<bus_workOrder_head>();
foreach (var key in headKeyList)
{
var item = Context.Queryable<bus_workOrder_head>().Where(x => x.keys == key).First();
item.teamList = new List<bus_workOrder_detail>();
foreach (var detail in resultDetail)
{
if(detail.headKeys == key)
{
item.teamList.Add(detail);
}
}
result.Add(item);
}
response.Result = result;
return response;
});
}
/// <summary>
/// 保存组对开始列表
/// </summary>
/// <returns></returns>
public dynamic SaveTeamStartList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach(var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.stationCode = item.stationCode;
resultItem.batchNo = item.batchNo;
resultItem.state = (int)EnumOrderBodyStatus.生产中;
resultItem.updateBy = sysWebUser?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).ExecuteCommand();
}
}
return response;
});
}
/// <summary>
/// 保存组对结束列表
/// </summary>
/// <returns></returns>
public dynamic SaveTeamEndList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.state = (int)EnumOrderBodyStatus.已完成;
resultItem.updateBy = sysWebUser?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).ExecuteCommand();
var result = Context.Queryable<bus_workOrder_detail>().Where(x =>
x.barCode == resultItem.barCode &&
x.weldNo == resultItem.weldNo &&
x.workCenterCode == "Weld").First();
if (result != null)
{
result.batchNo = resultItem.batchNo;
result.updateBy = sysWebUser?.Account;
result.updateTime = DateTime.Now;
Context.Updateable(result).ExecuteCommand();
}
}
}
return response;
});
}
/// <summary>
/// 获取匹配的焊接信息
/// </summary>
/// <param name="pipe">管段码</param>
/// <param name="batch">批次码</param>
/// <returns></returns>
public dynamic GetMatchWeldList(string pipe)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
if (string.IsNullOrWhiteSpace(pipe))
{
response.ResponseErr($"管段码【{pipe}】是空,请重新扫描管段码!");
return response;
}
var resultDetail = Context.Queryable<bus_workOrder_detail>().Where(x =>
x.barCode.Equals(pipe) &&
x.state == (int)EnumOrderBodyStatus.初始化 &&
x.workCenterCode == "Weld" &&
!string.IsNullOrEmpty(x.batchNo)).ToList();
bus_workOrder_head result = null;
if (resultDetail.Count > 0)
{
result = Context.Queryable<bus_workOrder_head>().Where(x => x.keys == resultDetail[0].headKeys).First();
result.teamList = resultDetail;
}
response.Result = result;
return response;
});
}
/// <summary>
/// 获取焊接开始列表
/// </summary>
/// <returns></returns>
public dynamic GetWeldStartList()
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
var resultDetail = Context.Queryable<bus_workOrder_detail>().Where(x =>
(x.state > (int)EnumOrderBodyStatus.初始化 && x.state < (int)EnumOrderBodyStatus.已完成) &&
x.workCenterCode == "Weld").ToList();
var headKeyList = Context.Queryable<bus_workOrder_detail>().Where(x =>
(x.state > (int)EnumOrderBodyStatus.初始化 && x.state < (int)EnumOrderBodyStatus.已完成) &&
x.workCenterCode == "Weld").GroupBy(x => x.headKeys).Select(x => x.headKeys).ToList();
List<bus_workOrder_head> result = new List<bus_workOrder_head>();
foreach (var key in headKeyList)
{
var item = Context.Queryable<bus_workOrder_head>().Where(x => x.keys == key).First();
item.teamList = new List<bus_workOrder_detail>();
foreach (var detail in resultDetail)
{
if (detail.headKeys == key)
{
item.teamList.Add(detail);
}
}
result.Add(item);
}
response.Result = result;
return response;
});
}
/// <summary>
/// 保存焊接开始列表
/// </summary>
/// <returns></returns>
public dynamic SaveWeldStartList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.stationCode = item.stationCode;
resultItem.state = (int)EnumOrderBodyStatus.生产中;
resultItem.updateBy = sysWebUser?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).ExecuteCommand();
}
}
return response;
});
}
/// <summary>
/// 保存焊接结束列表
/// </summary>
/// <returns></returns>
public dynamic SaveWeldEndList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.state = (int)EnumOrderBodyStatus.已完成;
resultItem.updateBy = sysWebUser?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).ExecuteCommand();
}
}
return response;
});
}
#endregion
}
}