UpstreamSendWorkOrderMethod.cs
15.2 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
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Request;
using Hh.Mes.POJO.Response;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
/// <summary>
/// 订单下发接受数据处理Head 校验
/// </summary>
public ResponseUpstream<string> HandleAcceptOrderHeadBefore()
{
if (MomEntity == null)
{
ResponseOrder.ResponseError("【上位系统】生产订单下发:工单数据为空,请检查!");
return ResponseOrder;
}
#region plmeid 判断逻辑
if (MomEntity.type == EnumAction.I.ToString())
{
if (Context.Queryable<bus_workOrder_head>().Any(t => t.plmeId == MomEntity.plmeid && t.isDelete == AddOrUpdateFlag))
{
ResponseOrder.ResponseError($"【上位系统】生产订单【plmeId、{MomEntity.plmeid}】【订单类型:{proOrderTypeName}】信息已存在,请勿重复添加!");
return ResponseOrder;
}
} //更新
else if (MomEntity.type == EnumAction.U.ToString())
{
busWkHead = Context.Queryable<bus_workOrder_head>().First(t => t.plmeId == MomEntity.plmeid && t.isDelete == AddOrUpdateFlag);
if (busWkHead == null)
{
ResponseOrder.ResponseError($"【上位系统】生产订单【plmeId、{MomEntity.plmeid}】【订单类型:{proOrderTypeName}】信息更新,订单不存在或已删除!");
return ResponseOrder;
}
else if (busWkHead.state != (int)EnumOrderHeadStatus.初始化)
{
ResponseOrder.ResponseError($"【上位系统】生产订单【plmeId、{MomEntity.plmeid}】【订单类型:{proOrderTypeName}】信息更新,只能更新“初始化”状态的订单!");
return ResponseOrder;
}
}
#endregion
#region 空值检查
if (string.IsNullOrWhiteSpace(MomEntity.pro_order_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:订单号【pro_order_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
if (string.IsNullOrWhiteSpace(MomEntity.plan_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:生产计划号【plan_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
if (string.IsNullOrWhiteSpace(MomEntity.product_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:产品编码【product_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
if (string.IsNullOrEmpty(MomEntity.factory_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:工厂编码【factory_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
if (string.IsNullOrEmpty(MomEntity.line_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:产线编码【line_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
#endregion
#region 生产订单的产品号要先存在工艺路线的产品表中
Sys_ProductHeader = base.Context.Queryable<base_product_header>().First(x => x.productCode == MomEntity.product_code && x.isDelete == AddOrUpdateFlag);
if (Sys_ProductHeader == null)
{
ResponseOrder.ResponseError($"【上位系统】工艺路线产品表【产品编码productCode、isDelete】[{MomEntity.product_code}、{AddOrUpdateFlag}] 【订单类型:{proOrderTypeName}】不存在,请【上位系统】先发送工艺线路基础数据!");
return ResponseOrder;
}
#endregion
#region 生产订单的产品号要先存在工艺路线的产品表中
var isExtWkOrder = base.Context.Queryable<bus_workOrder_head>().Any(x => x.planCode == MomEntity.plan_code);
if (isExtWkOrder)
{
ResponseOrder.ResponseError($"【上位系统】【订单类型:{proOrderTypeName}】工序任务表已相同的计划号【产品编码planCode】[{MomEntity.plan_code}],请【上位系统】检查核实!");
return ResponseOrder;
}
#endregion
#region 线体映射
var line = base.Context.Queryable<base_line>().First(x => x.otherCode == MomEntity.line_code);
if (line == null || string.IsNullOrEmpty(line.lineCode))
{
ResponseOrder.ResponseError($"订单下发:没有查询到线体【line_code】和华恒线体一致的数据,请通知管理员在【工厂模型->线体设置】维护外部编码!");
return ResponseOrder;
}
Sys_LineCode = line.lineCode;
#endregion
#region 生产订单查询工艺路线基础信息
var pp = base.Context.Queryable<base_process_product_rel>().First(x => x.productCode == MomEntity.product_code);
if (pp == null || string.IsNullOrEmpty(pp.lineCode))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:没有查询到工艺产品关系productCode【{MomEntity.product_code}】【订单类型:{proOrderTypeName}】对应的数据,请先发送工艺路线接口数据!");
return ResponseOrder;
}
Sys_ProcessHead = base.Context.Queryable<base_process_route_head>().First(x => x.keys == pp.processHeadKeys && x.edition == MomEntity.edition);
if (Sys_ProcessHead == null || string.IsNullOrEmpty(Sys_ProcessHead.lineCode))
{
ResponseOrder.ResponseError($"【上位系统】订单下发:没有查询到工艺路线lineCode【{Sys_LineCode}】【processCode】【{MomEntity.product_code}】版本【{MomEntity.edition}】对应的工艺路线,请先发送工艺路线接口数据!");
return ResponseOrder;
}
Sys_ProcessDetail = Context.Queryable<base_process_route_detail>().Where(x => x.headkeys == Sys_ProcessHead.keys && x.isDelete == AddOrUpdateFlag).OrderBy(t => t.oprSequence).ToList();
if (Sys_ProcessDetail.Count == 0)
{
ResponseOrder.ResponseError($"订单下发:没有查询到工艺路线明细【headkeys】【{Sys_ProcessHead.keys}】【订单类型:{proOrderTypeName}】,反复出现请联系管理员!!");
return ResponseOrder;
}
#endregion
return ResponseOrder;
}
/// <summary>
/// 订单下发接受数据处理Body 校验
/// </summary>
public ResponseUpstream<string> HandleAcceptOrderBodyBefore()
{
#region 切割、组队、焊接工序是否为空
Sys_process_cut = GetNowBaseprocessRouteDetail(Sys_ProcessHead.keys, EnumoprSequenceCode.切割坡口);
if (Sys_process_cut == null)
{
ResponseOrder.ResponseError($"【MOM】订单下发:工艺路线【{Sys_ProcessHead.keys}、{Sys_ProcessHead.processName}】【订单类型:{proOrderTypeName}】不存在切割工序【{EnumoprSequenceCode.切割坡口},请核实该产品【{MomEntity.product_code}】的工艺路线工序!");
return ResponseOrder;
}
Sys_process_fitUp = GetNowBaseprocessRouteDetail(Sys_ProcessHead.keys, EnumoprSequenceCode.组对);
if (Sys_process_fitUp == null)
{
ResponseOrder.ResponseError($"【MOM】订单下发:工艺路线【{Sys_ProcessHead.keys}、{Sys_ProcessHead.processName}】【订单类型:{proOrderTypeName}】不存在组队工序【{EnumoprSequenceCode.组对},请核实该产品【{MomEntity.product_code}】的工艺路线工序!");
return ResponseOrder;
}
Sys_process_weld = GetNowBaseprocessRouteDetail(Sys_ProcessHead.keys, EnumoprSequenceCode.焊接);
if (Sys_process_weld == null)
{
ResponseOrder.ResponseError($"【MOM】订单下发:工艺路线【{Sys_ProcessHead.keys}、{Sys_ProcessHead.processName}】【订单类型:{proOrderTypeName}】不存在焊接工序【{EnumoprSequenceCode.焊接},请核实该产品【{MomEntity.product_code}】的工艺路线工序!");
return ResponseOrder;
}
#endregion
#region 生产订单工序是否在工艺路线中、 切割工序物料不能为空、是否存在物料表信息
if (MomEntity.details.Count < Sys_ProcessDetail.Count)
{
ResponseOrder.ResponseError($"【MOM】订单下发:【订单类型:{proOrderTypeName}】 json数据details明细行数【{MomEntity.details.Count}】小于【工艺路线keys:{Sys_ProcessDetail[0].headkeys}】行数【{Sys_ProcessDetail.Count}】不一致,请核实订单计划数据明细数据!");
return ResponseOrder;
}
foreach (var item in MomEntity.details)
{
var isOk = Sys_ProcessDetail.Any(x => x.oprSequenceCode == item.proced_code);
if (!isOk)
{
ResponseOrder.ResponseError($"【MOM】订单下发:子表明细工序编码proced_code【{item.proced_code}】【订单类型:{proOrderTypeName}】不存在工艺路线工序集合中,请核实订单计划数据明细工序编码数据!");
return ResponseOrder;
}
if (item.proced_code == Sys_process_cut.oprSequenceCode)
{
foreach (var itemComponent in item.componentDetails)
{
if (string.IsNullOrEmpty(itemComponent.cut_mater_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发-切割工序:物料编码【cut_mater_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
else
{
var isExt = base.Context.Queryable<base_material>().Any(x => x.materialCode == itemComponent.cut_mater_code && x.isDelete == AddOrUpdateFlag);
if (isExt) continue;
ResponseOrder.ResponseError($"【上位系统】订单下发-切割工序:没有查询到物料主数据cut_mater_code【{itemComponent.cut_mater_code}】【订单类型:{proOrderTypeName}】对应的信息,请先发送物料主数据接口数据,或者在物料管理模块点击按钮【同步信科物料 】!");
return ResponseOrder;
}
}
}
else if (item.proced_code == Sys_process_weld.oprSequenceCode)
{
foreach (var itemComponent in item.componentDetails)
{
if (string.IsNullOrEmpty(itemComponent.weld_mater_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发-焊接工序:焊口物料编码【weld_mater_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
else if (string.IsNullOrEmpty(itemComponent.cut_mater_code))
{
ResponseOrder.ResponseError($"【上位系统】订单下发-焊接工序:管段物料编码【cut_mater_code】【订单类型:{proOrderTypeName}】不能为空值,请检查!");
return ResponseOrder;
}
else
{
var weldMaterCodeList = itemComponent.weld_mater_code.Split(',', StringSplitOptions.RemoveEmptyEntries);
for (int xp = 0; xp < weldMaterCodeList.Length; xp++)
{
var tempMaterCode = weldMaterCodeList[xp];
var isExt = base.Context.Queryable<base_material>().Any(x => x.materialCode == tempMaterCode && x.isDelete == AddOrUpdateFlag);
if (isExt) continue;
ResponseOrder.ResponseError($"【上位系统】订单下发-焊接工序:没有查询到物料主数据weld_mater_code【{tempMaterCode}】【订单类型:{proOrderTypeName}】对应的信息,请先发送物料主数据接口数据,或者在物料管理模块点击按钮【同步信科物料 】!");
return ResponseOrder;
}
}
}
}
}
#endregion
return ResponseOrder;
}
/// <summary>
/// 生成数据订单数据 除 正常订单之外
/// </summary>
private ValueTuple<bus_workOrder_head, List<bus_workOrder_detail>> HandleAcceptOhterOrderData()
{
#region 生成工序任务头 bus_workOrder_head
var busWorkOrderHead = new bus_workOrder_head
{
keys = Guid.NewGuid(),
plmeId = MomEntity.plmeid,
workOrderCode = MomEntity.pro_order_code,
workOrderName = MomEntity.pro_order_code + "_订单名称",
planCode = MomEntity.plan_code,
processHeadKeys = Sys_ProcessHead.keys,//工艺路线keys
processCode = Sys_ProductHeader.processCode, //工艺路线编码
productHeaderCode = MomEntity.product_code, //产品编码
productName = MomEntity.product_name,
factoryCode = MomEntity.factory_code,
lineCode = Sys_LineCode,
orderType = MomEntity.order_type,
edition = MomEntity.edition,
projectCode = MomEntity.project_code, //项目编码
projectName = MomEntity.project_name,
lineNo = MomEntity.line_no, //管线号/图纸号
planStartTime = MomEntity.oprplan_start_time,
planEndTime = MomEntity.oprplan_end_time,
extend1 = MomEntity.extend1,
extend2 = MomEntity.extend2,
extend3 = MomEntity.extend3,
extend4 = MomEntity.extend4,
otherOrderCode = MomEntity.plan_code,
state = (int)EnumOrderHeadStatus.初始化,
isDelete = AddOrUpdateFlag,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
#endregion
#region 生成工序任务明细 busWorkOrderDetailList
var busWorkOrderDetailList = new List<bus_workOrder_detail>();
foreach (var item in Sys_ProcessDetail)
{
var jsonMomItem = MomEntity.details.FirstOrDefault(x => x.proced_code == item.oprSequenceCode);
if (jsonMomItem == null)
{
ResponseOrder.ResponseError($"【上位系统】订单下发:【订单类型:{proOrderTypeName}】【工序{item.oprSequenceCode}】在【工艺路线:{Sys_ProcessDetail[0].headkeys}】没有找到行记录,请确认【产品:{MomEntity.product_code}】关联的工艺路线是否正确!!");
break;
}
for (int i = 0; i < jsonMomItem.componentDetails.Count; i++)
{
var nowWorkDetail = new bus_workOrder_detail
{
headKeys = busWorkOrderHead.keys,
productHeaderCode = busWorkOrderHead.productHeaderCode,
workOrderCode = busWorkOrderHead.workOrderCode,
cutMaterCode = jsonMomItem.componentDetails[i].cut_mater_code,
cuttingLength = (decimal)jsonMomItem.componentDetails[i].cutting_len,
lineCode = Sys_LineCode,
designNo = jsonMomItem.componentDetails[i].design_no,
designUrl = jsonMomItem.componentDetails[i].design_url,
partCode = jsonMomItem.componentDetails[i].part_code,
serialNumber = item.oprSequence,
oprSequenceCode = item.oprSequenceCode,
oprSequenceName = item.oprSequenceName,
workCenterCode = item.workCenterCode,
planStartTime = jsonMomItem.oprplan_start_time,
planEndTime = jsonMomItem.oprplan_end_time,
weldType= jsonMomItem.componentDetails[i].weld_type,
weldNo = jsonMomItem.componentDetails[i].weld_no,
weldMaterCode = jsonMomItem.componentDetails[i].weld_mater_code,
isEndProduct = jsonMomItem.isend_product,
isDelete = AddOrUpdateFlag,
state = (int)EnumOrderBodyStatus.初始化,
workReportStatus = (int)EnumWorkReportStatus.未报工,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
nowWorkDetail.bodyKeys = Guid.NewGuid();
nowWorkDetail.serialNumberName = nowWorkDetail.serialNumber + "_1";
busWorkOrderDetailList.Add(nowWorkDetail);
}
}
#endregion
// 设置工序任务头的当前工序,为第一个工序任务明细的工序
if (busWorkOrderDetailList.Count > 0)
{
busWorkOrderHead.nowOprSequenceCode = busWorkOrderDetailList[0].oprSequenceCode;
}
return (busWorkOrderHead, busWorkOrderDetailList);
}
}
}