|
1
2
3
4
5
6
7
8
9
10
11
|
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;
|
赖素文
authored
|
12
|
using System.Linq;
|
|
13
14
15
16
|
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
|
赖素文
authored
|
17
18
19
20
21
22
23
24
25
|
{
#region 属性
/// <summary>
/// 华恒线体code
/// </summary>
base_line line = null;
#endregion
|
|
26
27
|
public dynamic SendProcessRoute(MomProcessRouteHeadEntity entity)
{
|
|
28
|
return ExceptionsHelp.Instance.ExecuteT(() =>
|
|
29
|
{
|
赖素文
authored
|
30
31
32
33
34
35
36
|
var response = new ResponseUpstream<string>(entity.plmeid);
if (!typeValidation(entity.type, response).Status) return response;
int resultCount = 0;
var validation = ExecuteQueuesBefore(entity, response);
if (!validation.Status) return validation;
|
|
37
|
#region 工艺路线 赋值
|
赖素文
authored
|
38
|
|
|
39
40
41
42
|
var head = new base_process_route_head
{
keys = Guid.NewGuid(),
plmeid = entity.plmeid,
|
|
43
|
processCode = entity.product_code + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"),//Guid.NewGuid().ToString(),
|
|
44
45
46
47
48
49
50
51
52
|
processName = entity.product_code + "工艺名称",
otherCode = entity.product_code,
lineCode = line.lineCode,
edition = entity.edition,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
createTime = DateTime.Now
};
|
赖素文
authored
|
53
|
var details = new List<base_process_route_detail>();
|
|
54
55
56
57
58
59
60
61
|
foreach (var item in entity.details)
{
var processRouteDetail = new base_process_route_detail
{
headkeys = head.keys,
bodyKeys = Guid.NewGuid(),
oprSequenceCode = item.proced_code,
oprSequenceName = item.proced_name,
|
赖素文
authored
|
62
|
oprSequence = item.proced_num,
|
|
63
|
oprsequenceTime=item.oprsequenceTime,//工序耗时
|
赖素文
authored
|
64
65
66
67
68
69
70
71
72
|
workCenterCode = item.workcenter_code,
workCenterName = item.workcenter_name,
LineCode = line.lineCode,
plmeid=head.plmeid,
remarks = item.remark,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
|
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
createTime = DateTime.Now
};
details.Add(processRouteDetail);
}
#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
|
赖素文
authored
|
96
|
#region 工艺路线和产品关系
|
赖素文
authored
|
97
|
var bpprel = new base_process_product_rel
|
赖素文
authored
|
98
99
100
101
102
103
104
105
106
107
108
109
110
|
{
keys = Guid.NewGuid(),
processHeadKeys = head.keys,
processCode = head.processCode,
processName = head.processName,
productCode = head.productHeaderCode,
lineCode = line.lineCode,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
#endregion
|
|
111
112
113
|
var existHead = Context.Queryable<base_process_route_head>().Any(t => t.plmeid == head.plmeid && t.isDelete == AddOrUpdateFlag);
if (entity.type == EnumAction.I.ToString())
{
|
|
114
|
if (existHead) return response.ResponseError($"【上位系统】【plmeid】[{head.plmeid}]工艺路线信息已经存在,请勿重复发送!");
|
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
//如果没有产品信息就增加,如果有了就更新
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();
}
Context.Insertable(head).AddQueue();
Context.Insertable(details).AddQueue();
|
赖素文
authored
|
131
|
Context.Insertable(bpprel).AddQueue();
|
|
132
133
134
|
}
else if (entity.type == EnumAction.U.ToString())
{
|
|
135
|
if (!existHead) return response.ResponseError($"【上位系统】【plmeid】[{head.plmeid}]工艺路线信息不存在,修改失败!");
|
赖素文
authored
|
136
|
|
|
137
138
139
140
141
142
|
#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();
|
赖素文
authored
|
143
|
|
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
for (var i = 0; i < details.Count; i++)
{
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)
|
赖素文
authored
|
160
|
.UpdateColumns(x => new { x.productName, x.updateBy, x.updateTime })
|
|
161
162
163
164
165
166
|
.Where(x => x.productCode == productHead.productCode && x.isDelete == AddOrUpdateFlag).AddQueue();
#endregion
}
|
赖素文
authored
|
167
|
|
|
168
169
170
171
172
|
resultCount = ExecuteQueues(Context);
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
|
赖素文
authored
|
173
|
public ResponseUpstream<string> ExecuteQueuesBefore(MomProcessRouteHeadEntity entity, ResponseUpstream<string> response)
|
|
174
175
176
177
|
{
if (string.IsNullOrWhiteSpace(entity.product_code))
{
response.Status = false;
|
|
178
|
response.Message = $"【上位系统】工艺路线的工序顺序【product_code】不能为空,请核对数据!";
|
赖素文
authored
|
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
return response;
}
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;
}
foreach (var item in entity.details)
{
if (string.IsNullOrEmpty(item.workcenter_code))
{
response.ResponseError($"【上位系统】工艺路线的 工作中心【workcenter_code】【{item.workcenter_code}】不能为空,请核对数据!");
return response;
}
var isAngWkCen = Context.Queryable<base_work_center>().Any(x => x.workCenterCode == item.workcenter_code);
if (!isAngWkCen)
{
|
赖素文
authored
|
198
|
response.ResponseError($"【上位系统】工艺路线的 工作中心【workcenter_code】【{item.workcenter_code}】和华恒工作中心数据不一致的数据,请核对数据!");
|
赖素文
authored
|
199
200
201
202
203
204
205
206
207
208
|
return response;
}
}
var repeatProcedcode = entity.details.GroupBy(x => new { x.proced_code }).Any(c => c.Count() > 1);
if (repeatProcedcode)
{
response.ResponseError($"【上位系统】工艺路线的工序【proced_code】存在相同工序编码,请核对数据!");
return response;
|
|
209
210
211
212
213
|
}
return response;
}
}
}
|