CutWeldService.cs
23.3 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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
using ApkInfo;
using Enyim.Caching.Configuration;
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Redis;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.Service.Repository;
using Hh.Mes.Service.SystemAuth;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Xml;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
namespace Hh.Mes.Service
{
public class CutWeldService : RepositorySqlSugar<dynamic>
{
/// <summary>
/// 管段工序完工调用
/// </summary>
/// <param name="BarCode">追踪码</param>
/// <param name="processesState">状态</param>
/// <returns></returns>
public async void SendIWPTechnologylineProcess(string BarCode, int processesState)
{
if (string.IsNullOrWhiteSpace(BarCode)) return;
//切割完成处理,ECS完成时会更新套料方案,工单工序,这里只需要组织数据反馈上游
var oprSequenceCode = "";
if (processesState == (int)EnumCutHeadState.已套料)
oprSequenceCode = EnumoprSequenceCode.套料;
if (processesState == (int)EnumCutHeadState.切坡完成)
oprSequenceCode = EnumoprSequenceCode.切割坡口;
if (processesState == (int)EnumCutHeadState.切割完成)
oprSequenceCode = EnumoprSequenceCode.切割;
if (processesState == (int)EnumCutHeadState.坡口完成)
oprSequenceCode = EnumoprSequenceCode.坡口;
if (processesState == (int)EnumCutHeadState.打磨完成)
oprSequenceCode = EnumoprSequenceCode.打磨;
if (processesState == (int)EnumCutHeadState.组对完成)
oprSequenceCode = EnumoprSequenceCode.组对;
if (processesState == (int)EnumCutHeadState.焊接完成)
oprSequenceCode = EnumoprSequenceCode.焊接;
if (processesState == (int)EnumCutHeadState.组焊完成)
oprSequenceCode = EnumoprSequenceCode.组焊;
if (processesState == (int)EnumCutHeadState.弯管完成)
oprSequenceCode = EnumoprSequenceCode.弯管;
if (oprSequenceCode == "") return;
var workOrderDetail = base.Context.Queryable<bus_workOrder_detail>().Where(x => x.oprSequenceCode == oprSequenceCode && x.barCode == BarCode).First();
if (workOrderDetail == null) return;
//更新工单明细
workOrderDetail.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
Context.Updateable(workOrderDetail).UpdateColumns(t => new { t.workReportStatus }).ExecuteCommand();
var data = new
{
Worker = workOrderDetail.createBy,
WorkerJobNo = workOrderDetail.createBy,
WorkStartDate = workOrderDetail.actualStartTime.ToString("yyyy-MM-dd HH:mm:ss"),
WorkEndDate = workOrderDetail.actualEndTime.ToString("yyyy-MM-dd HH:mm:ss"),
Operator = workOrderDetail.createBy,
OperatorJobNo = workOrderDetail.createBy,
OperateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
WorkstationTypeName = workOrderDetail.oprSequenceCode,
WorkPieceCode = workOrderDetail.barCode,
Status = 1
};
//var data = new
//{
// workOrderCode = workOrderDetail.workOrderCode,//工单
// partCode = workOrderDetail.partCode,//管段号
// barCode = workOrderDetail.barCode,//追踪码(管段码)
// oprSequenceCode = workOrderDetail.oprSequenceCode,//工序
// stationCode = workOrderDetail.stationCode,//工位
// equipmentCode = workOrderDetail.equipmentCode,//生产设备
// actualStartTime = workOrderDetail.actualStartTime,//开始时间
// actualEndTime = workOrderDetail.actualEndTime,// 完成时间
// cutMaterCode = workOrderDetail.cutMaterCode,//管段物料编码
// weldNo = workOrderDetail.weldNo,//组对(焊接)焊口号
// batchNo = workOrderDetail.batchNo,//组对(焊接)批次号
// createBy = workOrderDetail.createBy,//操作人
//};
//调用上游MES工序完工反馈
var url = GetDictionaryDictValue("UrlProcessFeedback", "GetUrl");
HttpManVoid(url, data, EnumLog.调用上游MES工序完工反馈.ToString(), method: "post");
}
/// <summary>
/// PDA,ECS调用,任务号设备完工报工
/// </summary>
/// <param name="taskCode">任务号</param>
/// <param name="equipmentCode">设备编码</param>
/// <returns></returns>
public void SendTaskEnd(string taskCode, string equipmentCode)
{
if (string.IsNullOrWhiteSpace(taskCode) || string.IsNullOrWhiteSpace(equipmentCode)) return;
//查询工序明细
var workOrderDetail = base.Context.Queryable<bus_workOrder_detail>()
.Where(x => x.barCode== taskCode&&x.oprSequenceCode == EnumoprSequenceCode.焊接&&x.state== (int)EnumOrderBodyStatus.生产中).ToList();
if (workOrderDetail.Count == 0) return;
//更新工单明细
workOrderDetail.ForEach(x => {
x.state = (int)EnumOrderBodyStatus.已完成;
x.equipmentCode = equipmentCode;
x.updateBy = sysUserApi?.Account;
x.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
x.actualEndTime = DateTime.Now;
});
Context.Updateable(workOrderDetail).ExecuteCommand();
foreach (var item in workOrderDetail)
{
var data = new
{
Worker = item.createBy,
WorkerJobNo = item.createBy,
WorkStartDate = item.actualStartTime.ToString("yyyy-MM-dd HH:mm:ss"),
WorkEndDate = item.actualEndTime.ToString("yyyy-MM-dd HH:mm:ss"),
Operator = item.createBy,
OperatorJobNo = item.createBy,
OperateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
WorkstationTypeName = item.oprSequenceCode,
WorkPieceCode = item.barCode,
Status = 1
};
//调用上游MES工序完工反馈
var url = GetDictionaryDictValue("UrlProcessFeedback", "GetUrl");
HttpManVoid(url, data, EnumLog.调用上游MES工序完工反馈.ToString(), method: "post");
}
}
/// <summary>
/// 余料反馈发送上游工单系统
/// </summary>
public void OddFeedBack(OddFeelBackModel model)
{
var url = GetDictionaryDictValue("OddFeedBack", "GetUrl");
HttpManVoid(url, model, EnumLog.余料接口.ToString(), method: "post");
}
public dynamic CreateXmlByWorkOrder(string workOrderCode)
{
var response = new POJO.Response.Response();
List<base_work_order_head> work_order = Context.Queryable<base_work_order_head>().Where(x => x.workOrderCode == workOrderCode).ToList();
foreach (var item in work_order)
{
CreateXmlByOrder(item.workPieceNo);
}
return response;
}
public dynamic CreateXmlByOrder(string barCode)
{
var response = new POJO.Response.Response();
base_work_order_head work_order = Context.Queryable<base_work_order_head>().First(x => x.workPieceNo == barCode);
if (work_order == null)
{
return response.ResponseError("未获取到对应的工单数据");
}
base_work_order_flameCut cuts = Context.Queryable<base_work_order_flameCut>().First(x => x.headKeys.Equals(work_order.keys));
if (cuts == null)
{
return response.ResponseError("未获取到对应的切割数据");
}
# region 管段信息
List<Tube> tubes = new List<Tube>();
Tube tube = new Tube();
tube.diameter = work_order.diameter;
tube.amount = "1";// 固定是1
tube.material = work_order.materielCode;
//判断 平口还是马鞍口
List<Saddle> saddles = new List<Saddle>();
List<POJO.ApiEntity.PlaneInfo> planes = new List<PlaneInfo>();
if (cuts.end1_D == "0" || string.IsNullOrEmpty(cuts.end1_D) )
{
tube.saddle1 = "2";
PlaneInfo plane = new PlaneInfo();
plane.angle = "90";
plane.bevelAngle = "0.0";
plane.bevelType = "0.0";
plane.pos = "END1";
plane.twist = "0.0";
planes.Add(plane);
}
else
{
tube.saddle1 = "1";
Saddle sa1 = new Saddle();
sa1.angle = string.IsNullOrEmpty(cuts.end1_angle) ? "0" : cuts.end1_angle;
sa1.bevelAngle = string.IsNullOrEmpty(cuts.end1_beveAngle) ? "0.0" : cuts.end1_beveAngle;
sa1.bevelType = string.IsNullOrEmpty(cuts.end1_Type) ? "0.0" : cuts.end1_Type;
sa1.centerOffest = string.IsNullOrEmpty(cuts.end1_centeroffest) ? "0.0" : cuts.end1_centeroffest;
sa1.diameter = work_order.diameter;
sa1.pos = "END1";
sa1.twist = string.IsNullOrEmpty(cuts.end1_twist) ? "0" : cuts.end1_twist;
saddles.Add(sa1);
}
if (cuts.end2_D == "0" || string.IsNullOrEmpty(cuts.end2_D))
{
tube.saddle2 = "2";
PlaneInfo plane = new PlaneInfo();
plane.angle = "90";
plane.bevelAngle = "0.0";
plane.bevelType = "0.0";
plane.pos = "END2";
plane.twist = "0.0";
planes.Add(plane);
}
else
{
tube.saddle2 = "1";
Saddle sa2 = new Saddle();
sa2.angle = string.IsNullOrEmpty(cuts.end2_angle) ? "0" : cuts.end2_angle;
sa2.bevelAngle = string.IsNullOrEmpty(cuts.end2_beveAngle) ? "0.0" : cuts.end2_beveAngle;
sa2.bevelType = string.IsNullOrEmpty(cuts.end2_Type) ? "0.0" : cuts.end2_Type;
sa2.centerOffest = string.IsNullOrEmpty(cuts.end2_centeroffest) ? "0.0" : cuts.end2_centeroffest;
sa2.diameter = work_order.diameter;
sa2.pos = "END2";
sa2.twist = string.IsNullOrEmpty(cuts.end2_twist) ? "0" : cuts.end2_twist;
saddles.Add(sa2);
}
string saddle1Test = tube.saddle1 == "1" || tube.saddle2 == "1" ? "saddle" : "plane";
string saddle2Test = tube.saddle1 == "2" || tube.saddle2 == "2" ? "plane" : "saddle";
tube.comment = $"Tube with END1({saddle1Test}) END2({saddle2Test})";
tube.saddles = saddles;
tube.planes = planes;
tube.length = cuts.lenth;
tube.id = work_order.iD.ToString();
tube.name = $"{work_order.pipePartsNo}-{work_order.workPieceNo}" ; // work_order.workPieceNo;
tube.thickness = work_order.thickness;
List<base_work_order_flameCut_d> cut_Ds = Context.Queryable<base_work_order_flameCut_d>().Where(x => x.headKeys == cuts.Keys).ToList();
List<Hole> holes = new List<Hole>();
foreach (var cut_d in cut_Ds)
{
//<hole angle="75.0" bevelAngle="0.0" bevelType="0.0" centerOffest="0.0" diameter="80.0" pos="hole" thickness="5.0" twist="0.0" xoffset="-200.0" />
Hole hole = new Hole();
hole.angle = cut_d.hole_angle;
hole.bevelAngle =string.IsNullOrEmpty( cut_d.hole_bevelAngle) ? "0" : cut_d.hole_bevelAngle;
hole.bevelType = string.IsNullOrEmpty(cut_d.hole_bevelType) ? "0" : cut_d.hole_bevelType;
hole.centerOffest = string.IsNullOrEmpty(cut_d.hole_centerOffest) ? "0" : cut_d.hole_centerOffest;
hole.diameter = work_order.diameter;
hole.pos = "hole";
hole.thickness = string.IsNullOrEmpty(cut_d.thickness) ? "0" : cut_d.thickness;
hole.twist = string.IsNullOrEmpty(cut_d.hole_twist) ? "0" : cut_d.hole_twist;
hole.xoffset = string.IsNullOrEmpty(cut_d.hole_offset) ? "0" : cut_d.hole_offset;
holes.Add(hole);
}
tube.holes = holes;
tubes.Add(tube);
#endregion
CutInfoXml xml1 = new CutInfoXml();
xml1.assemblyID ="1";
xml1.assemblyName = "aName";
xml1.id = "1";
xml1.name = $"{work_order.pipePartsNo}-{work_order.workPieceNo}";// work_order.workPieceNo;
xml1.tubes = tubes;
CreateXmlByCut(xml1,work_order);
return response;
}
public bool CreateXmlByCut(CutInfoXml xmlInfo, base_work_order_head work_order)
{
// 创建XmlDocument对象
XmlDocument xmlDoc = new XmlDocument();
// 创建XML声明节点
XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
xmlDoc.AppendChild(node);
XmlElement projectNode = xmlDoc.CreateElement("project");
projectNode.SetAttribute("id", xmlInfo.id);
projectNode.SetAttribute("name", xmlInfo.name);
XmlElement source = xmlDoc.CreateElement("source");
source.SetAttribute("date", DateTime.Now.ToLocalTime().ToString());
source.SetAttribute("name", "EXCEL");
source.SetAttribute("version", "1.0");
projectNode.AppendChild(source);
XmlElement assembly = xmlDoc.CreateElement("assembly");
assembly.SetAttribute("id", xmlInfo.assemblyID);
assembly.SetAttribute("name",work_order.workPieceNo);
List<Tube> tubeInfos = xmlInfo.tubes;
if (tubeInfos != null && tubeInfos.Count > 0)
{
foreach (var tubeInfo in tubeInfos)
{
XmlElement tube = xmlDoc.CreateElement("tube");
tube.SetAttribute("amount", tubeInfo.amount);
tube.SetAttribute("comment", tubeInfo.comment);
tube.SetAttribute("diameter", tubeInfo.diameter);
tube.SetAttribute("id", tubeInfo.id);
tube.SetAttribute("length", tubeInfo.length);
tube.SetAttribute("material", tubeInfo.material);
tube.SetAttribute("name", tubeInfo.name);
tube.SetAttribute("thickness", tubeInfo.thickness);
int endIndex = 1;
foreach (var saddleInfo in tubeInfo.saddles)
{
XmlElement saddle = xmlDoc.CreateElement("saddle");
saddle.SetAttribute("angle", saddleInfo.angle);
saddle.SetAttribute("bevelAngle", saddleInfo.bevelAngle);
saddle.SetAttribute("bevelType", saddleInfo.bevelType);
saddle.SetAttribute("centerOffest", saddleInfo.centerOffest);
saddle.SetAttribute("diameter", saddleInfo.diameter);
saddle.SetAttribute("pos", $"END{endIndex}");
saddle.SetAttribute("twist", saddleInfo.twist);
tube.AppendChild(saddle);
endIndex++;
}
foreach (var pl in tubeInfo.planes)
{
XmlElement plane = xmlDoc.CreateElement("plane");
// POJO.ApiEntity.PlaneInfo pl = tubeInfo.planes[1];
plane.SetAttribute("angle", pl.angle);
plane.SetAttribute("bevelAngle", pl.bevelAngle);
plane.SetAttribute("bevelType", pl.bevelType);
plane.SetAttribute("pos", $"END{endIndex}");
plane.SetAttribute("twist", pl.twist);
tube.AppendChild(plane);
endIndex++;
}
#region 要把saddle 放前面
/*
if (tubeInfo.saddle1 == "1" && tubeInfo.saddles.Count > 0)
{
XmlElement saddle = xmlDoc.CreateElement("saddle");
Saddle saddleInfo = tubeInfo.saddles[0];
saddle.SetAttribute("angle", saddleInfo.angle);
saddle.SetAttribute("bevelAngle", saddleInfo.bevelAngle);
saddle.SetAttribute("bevelType", saddleInfo.bevelType);
saddle.SetAttribute("centerOffest", saddleInfo.centerOffest);
saddle.SetAttribute("diameter", saddleInfo.diameter);
saddle.SetAttribute("pos", saddleInfo.pos);
saddle.SetAttribute("twist", saddleInfo.twist);
tube.AppendChild(saddle);
}
else
{
XmlElement saddle = xmlDoc.CreateElement("plane");
POJO.ApiEntity.PlaneInfo plane = tubeInfo.planes[0];
saddle.SetAttribute("angle", plane.angle);
saddle.SetAttribute("bevelAngle", plane.bevelAngle);
saddle.SetAttribute("bevelType", plane.bevelType);
saddle.SetAttribute("pos", plane.pos);
saddle.SetAttribute("twist", plane.twist);
tube.AppendChild(saddle);
}
if (tubeInfo.saddle2 == "1" && tubeInfo.saddles.Count > 0)
{
XmlElement saddle = xmlDoc.CreateElement("saddle");
if (tubeInfo.saddle1 =="1")
{
Saddle saddleInfo = tubeInfo.saddles[1];
saddle.SetAttribute("angle", saddleInfo.angle);
saddle.SetAttribute("bevelAngle", saddleInfo.bevelAngle);
saddle.SetAttribute("bevelType", saddleInfo.bevelType);
saddle.SetAttribute("centerOffest", saddleInfo.centerOffest);
saddle.SetAttribute("diameter", saddleInfo.diameter);
saddle.SetAttribute("pos", saddleInfo.pos);
saddle.SetAttribute("twist", saddleInfo.twist);
tube.AppendChild(saddle);
}
else
{
Saddle saddleInfo = tubeInfo.saddles[0];
saddle.SetAttribute("angle", saddleInfo.angle);
saddle.SetAttribute("bevelAngle", saddleInfo.bevelAngle);
saddle.SetAttribute("bevelType", saddleInfo.bevelType);
saddle.SetAttribute("centerOffest", saddleInfo.centerOffest);
saddle.SetAttribute("diameter", saddleInfo.diameter);
saddle.SetAttribute("pos", saddleInfo.pos);
saddle.SetAttribute("twist", saddleInfo.twist);
tube.AppendChild(saddle);
}
}
else
{
if (tubeInfo.saddle1 != "2")
{
XmlElement plane = xmlDoc.CreateElement("plane");
POJO.ApiEntity.PlaneInfo pl = tubeInfo.planes[0];
plane.SetAttribute("angle", pl.angle);
plane.SetAttribute("bevelAngle", pl.bevelAngle);
plane.SetAttribute("bevelType", pl.bevelType);
plane.SetAttribute("pos", pl.pos);
plane.SetAttribute("twist", pl.twist);
tube.AppendChild(plane);
}
else
{
XmlElement plane = xmlDoc.CreateElement("plane");
POJO.ApiEntity.PlaneInfo pl = tubeInfo.planes[1];
plane.SetAttribute("angle", pl.angle);
plane.SetAttribute("bevelAngle", pl.bevelAngle);
plane.SetAttribute("bevelType", pl.bevelType);
plane.SetAttribute("pos", pl.pos);
plane.SetAttribute("twist", pl.twist);
tube.AppendChild(plane);
}
}
*/
#endregion
if (tubeInfo.holes != null && tubeInfo.holes.Count > 0)
{
foreach (var item in tubeInfo.holes)
{
XmlElement hole = xmlDoc.CreateElement("hole");
hole.SetAttribute("angle", item.angle);
hole.SetAttribute("bevelAngle", item.bevelAngle);
hole.SetAttribute("bevelType", item.bevelType);
hole.SetAttribute("centerOffest", item.centerOffest);
hole.SetAttribute("diameter", item.diameter);
hole.SetAttribute("pos", item.pos);
hole.SetAttribute("thickness",item.thickness);
hole.SetAttribute("twist", item.twist);
hole.SetAttribute("xoffset",$"-{item.xoffset}" );//要求转为负数
tube.AppendChild(hole);
}
}
assembly.AppendChild(tube);
}
}
projectNode.AppendChild(assembly);
xmlDoc.AppendChild(projectNode);
// string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
string filePathDic = GetDictionaryDictValue("CutXmlUrl", "CutConfig");
// 定义文件路径
// string filePath = Path.Combine(currentDirectory,$"xmlDoc//{DateTime.Now.ToString("yyyyMMdd")}" );
// 检查文件是否已存在,如果不存在则创建
if (!File.Exists(filePathDic))
{
try
{
Directory.CreateDirectory(filePathDic);
}
catch (Exception)
{
}
}
xmlDoc.Save($"{filePathDic}//{xmlInfo.name}.xml") ;
return true;
}
}
}