PDAService.cs
18.1 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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}的物料基础信息,请检查!");
//查询套料信息得到管材长度
var cutplandetail= Context.Queryable<bus_cutplan_detail>().First(x => x.barCode == barCode);
if (cutplandetail == null) return response.ResponseError($"{barCode}追踪码无效,请检查!");
materialInfo.barCode = barCode;
materialInfo.cuttingLength = cutplandetail.cuttingLength;
//查询套料头得到物料使用的批次
var buscutplanhead = Context.Queryable<bus_cutplan_head>().First(x => x.keys == cutplandetail.headKeys);
if (cutplandetail == null) return response.ResponseError($"{barCode}追踪码无效,请检查!");
materialInfo.lotNo = buscutplanhead.lotNo;
materialInfo.extend1 = bwdInfo.batchNo;//批次号
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;
});
}
/// <summary>
/// 焊接工艺下发保存
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <param name="barCode">管段码</param>
/// <returns></returns>
public dynamic SaveWeldTechnology(string equipmentCode, string barCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode) || string.IsNullOrWhiteSpace(barCode))
{
return response.ResponseError($"设备编码或管段码为空,请重新扫描!");
}
//设备信息
var equipment = base.Context.Queryable<base_equipment>().Where(x => x.code == equipmentCode).First();
if (equipment == null)
{
return response.ResponseError($"设备编码{equipmentCode}在设备表中没有找到!");
}
//工序任务明细
var resultItem = base.Context.Queryable<bus_workOrder_detail>().Where(x => x.barCode == barCode).First();
if (equipment == null)
{
return response.ResponseError($"barCode:【{barCode}】不存在工序任务明细表中,请核对!");
}
//物料信息
var material = base.Context.Queryable<base_material>().Where(x => x.materialCode == resultItem.cutMaterCode).First();
if (equipment == null)
{
return response.ResponseError($"barCode:【{barCode}】对应物料没有信息,请核对!");
}
//焊接工艺参数
var Equipment = new base_weld_technology_equipment()
{
technologyHeadId = 0,
equipmentCode = equipmentCode,
createBy = sysWebUser?.Account,
createTime = DateTime.Now.ToString(),
sendStatus = 0,
minDiameter = material.diameter,
minThickness = material.thickness,
minWeldingSeam = "0",
material = material.types
};
switch (Equipment.material)
{
case "碳钢": Equipment.material = "1"; break;
case "不锈钢": Equipment.material = "2"; break;
case "合金钢": Equipment.material = "3"; break;
case "多重钢": Equipment.material = "4"; break;
default: Equipment.material = "0"; break;
}
response.Status = Add(Equipment);
return response;
});
}
/// <summary>
/// 批次码获取物料信息
/// </summary>
/// <param name="lotNo">批次码</param>
/// <returns></returns>
public dynamic GetMaterialBylotNo(string lotNo)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(lotNo))
{
return response.ResponseError($"批次码为空,请重新扫描!");
}
//调用上游接口查询批次码对应的物料码
//物料信息
var material = base.Context.Queryable<base_material>().Where(x => x.materialCode == lotNo).First();
if (material == null)
{
return response.ResponseError($"批次码{lotNo}在系统表中没有找到对应的物料信息!");
}
response.Result = material;
return response;
});
}
#endregion
}
}