UpstreamSendProcessRoute.cs
9.42 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
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;
using System.Linq;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
#region 属性
/// <summary>
/// 华恒线体code
/// </summary>
base_line line = null;
#endregion
public dynamic SendProcessRoute(MomProcessRouteHeadEntity entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
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;
#region 工艺路线 赋值
var head = new base_process_route_head
{
keys = Guid.NewGuid(),
plmeid = entity.plmeid,
processCode = entity.product_code + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"),//Guid.NewGuid().ToString(),
processName = entity.product_code + "工艺名称",
otherCode = entity.product_code,
lineCode = line.lineCode,
edition = entity.edition,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
createTime = DateTime.Now
};
var details = new List<base_process_route_detail>();
foreach (var item in entity.details)
{
var processRouteDetail = new base_process_route_detail
{
headkeys = head.keys,
bodyKeys = Guid.NewGuid(),
oprSequenceCode = item.workcenter_code,
oprSequenceName = item.proced_name,
oprSequence = item.proced_num,
oprsequenceTime=item.oprsequenceTime,//工序耗时
workCenterCode = item.workcenter_code,
workCenterName = item.workcenter_name,
LineCode = line.lineCode,
plmeid=head.plmeid,
remarks = item.remark,
isDelete = AddOrUpdateFlag,
createBy = SystemVariable.DefaultCreated,
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
#region 工艺路线和产品关系
var bpprel = new base_process_product_rel
{
keys = Guid.NewGuid(),
processHeadKeys = head.keys,
processCode = head.processCode,
processName = head.processName,
productCode = entity.product_code,
lineCode = line.lineCode,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
#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($"【上位系统】【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();
}
Context.Insertable(head).AddQueue();
Context.Insertable(details).AddQueue();
Context.Insertable(bpprel).AddQueue();
}
else if (entity.type == EnumAction.U.ToString())
{
if (!existHead) return response.ResponseError($"【上位系统】【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].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.productName, x.updateBy, x.updateTime })
.Where(x => x.productCode == productHead.productCode && 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 = $"【上位系统】工艺路线的工序顺序【product_code】不能为空,请核对数据!";
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)
{
response.ResponseError($"【上位系统】工艺路线的 工作中心【workcenter_code】【{item.workcenter_code}】和华恒工作中心数据不一致的数据,请核对数据!");
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;
}
return response;
}
}
}