UpstreamSendProcessRoute.cs
13.6 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
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using System;
using System.Collections.Generic;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.POJO.WebEntity.bus;
using Hh.Mes.POJO.Response;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
public dynamic SendProcessRoute(MomProcessRouteHeadEntity entity)
{
int resultCount = 0;
var response = new ResponseUpstream<string>(entity.plmeid);
var validation = ExecuteQueuesbefore(entity, response);
if (!validation.Status)
{
return validation;
}
return ExceptionsHelp.Instance.ExecuteT(() =>
{
#region 工艺路线 赋值
var line = Context.Queryable<base_line>().First(x => x.otherCode == entity.line_code);
if (line == null || string.IsNullOrEmpty(line.lineCode))
{
response.ResponseError($"工艺路线下发:没有查询到线体【line_code】【{entity.line_code}】和华恒线体一致的数据,请通知管理员在【工厂模型->线体设置】维护外部编码!");
return response;
}
var busEqList = new List<bus_equipment_process_template>();
var details = new List<base_process_route_detail>();
var head = new base_process_route_head
{
keys = Guid.NewGuid(),
plmeid = entity.plmeid,
processCode = Guid.NewGuid().ToString(),
productHeaderCode = entity.product_code,
processName = entity.product_code + "工艺名称",
otherCode = entity.product_code,
lineCode = line.lineCode,
edition = entity.edition,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
createTime = DateTime.Now
};
var workCenterList = new List<base_work_center>();
foreach (var item in entity.details)
{
if (!int.TryParse(item.proced_num, out int sequence))
{
response.plmeid = item.plmeid;
return response.ResponseError($"【MOM】工艺路线的工序顺序【proced_num】【{item.proced_num}】不能转换为数字,请核对数据!");
}
var processRouteDetail = new base_process_route_detail
{
headkeys = head.keys,
bodyKeys = Guid.NewGuid(),
oprSequenceCode = item.proced_code,
oprSequenceName = item.proced_name,
oprSequence = sequence,
plmeid = item.plmeid,
isDelete = false,
workCenterCode = item.station_code,
workCenterName = item.station_name,
LineCode = item.line_code,
createBy = item.CREATEUNAME,
createTime = DateTime.Now
};
details.Add(processRouteDetail);
#region 工作中心 赋值 默认外部编码就是工作中心编码
var temp = new base_work_center
{
key = Guid.NewGuid(),
workCenterCode = item.station_code,
workCenterName = item.station_name,
otherCode = item.station_code,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
createTime = DateTime.Now
};
var isExt = workCenterList.Exists(x => x.workCenterCode == temp.workCenterCode);
if (!isExt) workCenterList.Add(temp);
#endregion
#region 设备工艺参数 赋值 工作中心默认设备工艺参数模板
var tempEq = new bus_equipment_process_template
{
keys = Guid.NewGuid(),
device_information = item.station_code,
device_code = item.station_code,
processing_steps = "",
processing_parameters = "",
processing_results = "",
remarks = $"编码【{item.station_code}】{item.station_name},工作中心默认设备工艺参数模板",
createBy = SystemVariable.DefaultCreated,
createTime = DateTime.Now
};
var isExtEq = busEqList.Exists(x => x.device_code == item.station_code);
if (!isExtEq) busEqList.Add(tempEq);
#endregion
}
#endregion
#region base_product_header 赋值
var productHead = new base_product_header
{
keys = Guid.NewGuid(),
productCode = entity.product_code,
productName = entity.product_name,
productCodeOrProductName = entity.product_code,
processCode = head.processCode,
processHeadKeys = head.keys,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
createTime = DateTime.Now
};
#endregion
var existHead = Context.Queryable<base_process_route_head>().Any(t => t.plmeid == head.plmeid && t.isDelete == AddOrUpdateFlag);
if (entity.type == EnumAction.I.ToString())
{
if (existHead) return response.ResponseError($"【MOM】【plmeid】[{head.plmeid}]工艺路线信息已经存在,请勿重复发送!");
//如果没有产品信息就增加,如果有了就更新
if (Context.Queryable<base_product_header>().Any(t => t.productCode == productHead.productCode))
{
productHead.updateBy = SystemVariable.DefaultCreated;
productHead.updateTime = DateTime.Now;
Context.Updateable(productHead)
.IgnoreColumns(x => new { x.createBy, x.createTime })
.Where(x => x.productCode == productHead.productCode).AddQueue();
}
else
{
Context.Insertable(productHead).AddQueue();
}
#region 如果没有工作中心信息就增加,如果有了就更新
foreach (var item in workCenterList)
{
if (Context.Queryable<base_work_center>().Any(t => t.otherCode == item.workCenterCode))
{
item.updateBy = SystemVariable.DefaultCreated;
item.updateTime = DateTime.Now;
Context.Updateable(item)
.IgnoreColumns(x => new { x.createBy, x.createTime, x.otherCode })
.Where(x => x.otherCode == item.workCenterCode).AddQueue();
}
else
{
Context.Insertable(item).AddQueue();
}
}
#endregion
#region 设备工艺参数模板
foreach (var item in busEqList)
{
if (!Context.Queryable<bus_equipment_process_template>().Any(t => t.device_code == item.device_code))
{
Context.Insertable(item).AddQueue();
}
}
#endregion
Context.Insertable(head).AddQueue();
Context.Insertable(details).AddQueue();
}
else if (entity.type == EnumAction.U.ToString())
{
if (!existHead) return response.ResponseError($"【MOM】【plmeid】[{head.plmeid}]工艺路线信息不存在,修改失败!");
#region 更新工艺路线
head.updateTime = DateTime.Now;
head.updateBy = SystemVariable.DefaultCreated;
Context.Updateable(head)
.IgnoreColumns(it => new { it.createBy, it.createTime, it.keys })
.Where(x => x.plmeid == head.plmeid && x.isDelete == AddOrUpdateFlag).AddQueue();
for (var i = 0; i < details.Count; i++)
{
details[i].isDelete = false;
details[i].updateBy = SystemVariable.DefaultCreated;
details[i].updateTime = DateTime.Now;
var index = i;
Context.Updateable(details[index])
.IgnoreColumns(it => new { it.createBy, it.createTime, it.headkeys, it.bodyKeys })
.Where(x => x.plmeid == details[index].plmeid).AddQueue();
}
#endregion
#region 更新产品
productHead.updateBy = SystemVariable.DefaultCreated;
productHead.updateTime = DateTime.Now;
Context.Updateable(productHead)
.UpdateColumns(x => new { x.isDelete, x.productName, x.updateBy, x.updateTime })
.Where(x => x.productCode == productHead.productCode && x.isDelete == AddOrUpdateFlag).AddQueue();
#endregion
#region 工作中心
foreach (var item in workCenterList)
{
item.updateBy = SystemVariable.DefaultCreated;
item.updateTime = DateTime.Now;
Context.Updateable(item)
.UpdateColumns(x => new { x.isDelete, x.workCenterName, x.updateBy, x.updateTime })
.Where(x => x.otherCode == item.otherCode && x.isDelete == AddOrUpdateFlag).AddQueue();
}
#endregion
}
else if (entity.type == EnumAction.D.ToString())
{
if (!existHead) return response.ResponseError($"【MOM】【plmeid】[{head.plmeid}]工艺路线信息不存在,修改失败!");
#region 删除工艺路线(逻辑删除)
head.isDelete = DeleteFlag;
Context.Updateable(head)
.UpdateColumns(x => new { x.isDelete })
.Where(x => x.plmeid == head.plmeid && x.isDelete == AddOrUpdateFlag).AddQueue();
for (var i = 0; i < details.Count; i++)
{
details[i].isDelete = false;
details[i].updateBy = SystemVariable.DefaultCreated;
details[i].updateTime = DateTime.Now;
var index = i;
Context.Updateable(details[index])
.UpdateColumns(x => new { x.isDelete })
.Where(x => x.plmeid == details[index].plmeid && x.isDelete.Value).AddQueue();
}
#endregion
#region 删除产品(逻辑删除)
productHead.updateBy = SystemVariable.DefaultCreated;
productHead.updateTime = DateTime.Now;
productHead.isDelete = DeleteFlag;
Context.Updateable(productHead)
.UpdateColumns(x => new { x.isDelete, x.updateBy, x.updateTime })
.Where(x => x.productCode == productHead.productCode && x.isDelete == AddOrUpdateFlag).AddQueue();
#endregion
#region 删除工作中心(逻辑删除)
foreach (var item in workCenterList)
{
item.updateBy = SystemVariable.DefaultCreated;
item.updateTime = DateTime.Now;
item.isDelete = DeleteFlag;
Context.Updateable(item)
.UpdateColumns(x => new { x.isDelete, x.updateBy, x.updateTime })
.Where(x => x.otherCode == item.otherCode && x.isDelete == AddOrUpdateFlag).AddQueue();
}
#endregion
}
resultCount = ExecuteQueues(Context);
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
public ResponseUpstream<string> ExecuteQueuesbefore(MomProcessRouteHeadEntity entity, ResponseUpstream<string> response)
{
if (string.IsNullOrWhiteSpace(entity.product_code))
{
response.Status = false;
response.Message = $"【MOM】工艺路线的工序顺序【product_code】不能为空,请核对数据!";
}
return response;
}
}
}