BaseProjectService.cs
16.4 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
using Hh.Mes.Common.Infrastructure;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.EnumEntitys;
namespace Hh.Mes.Service.Base
{
public class BaseProjectService : RepositorySqlSugar<base_project>
{
public dynamic Load(PageReq pageReq, base_project entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var result = new Response();
var expression = LinqWhere(entity);
//先组合查询表达式(多表查询查看IOT 设备列表案例)
var query = Context.Queryable<base_project>().Where(expression);
//Exel false 分页
if (!entity.Exel)
{
int total = 0;
result.Result = query.ToOffsetPage(pageReq.page, pageReq.limit, ref total);
result.Count = total;
}
else
{
result.Result = query.ToList();
result.Count = result.Result.Count();
}
return result;
}, catchRetrunValue: "list");
}
public dynamic Ins(base_project entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
//entity.createBy = sysWebUser.Account;
entity.createTime = DateTime.Now;
entity.keys = Guid.NewGuid();
entity.state = 0;//默认 未开始状态
response.Status = Add(entity);
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
public dynamic Upd(base_project entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
//entity.updateBy = sysWebUser.Account;
//entity.updateTime = DateTime.Now;
response.Status = Update(entity);
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
public dynamic DelByIds(int[] ids)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
Context.Deleteable<base_project>(t => ids.Contains(t.id)).ExecuteCommand();
return response;
});
}
public Response ExportData(base_project entity)
{
return Load(null, entity);
}
public Expression<Func<base_project, bool>> LinqWhere(base_project model)
{
try
{
var exp = Expressionable.Create<base_project>();
//数据过滤条件
//if (!string.IsNullOrWhiteSpace(model.XXX)) exp.And(x => x.XXX.Contains(model.XXX));
if (!string.IsNullOrWhiteSpace(model.projectName))
{
exp.And(x => x.projectName.Contains(model.projectName));
}
if (!string.IsNullOrWhiteSpace(model.projectNo))
{
exp.And(x => x.projectNo.Contains(model.projectNo));
}
if (!string.IsNullOrWhiteSpace(model.temp1))
{
exp.And(x => x.temp1.Contains(model.temp1));
}
return exp.ToExpression();//拼接表达式
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}");
}
}
public dynamic BindProjectProcess(Guid keys, Guid processKeys, bool checkeds)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
base_project projectEntity = Context.Queryable<base_project>()
.Where(x => x.keys.Equals(keys)).First();
if (checkeds)
{
projectEntity.processKeys = processKeys;
}
else
{
projectEntity.processKeys = Guid.Empty;
}
response.Status = Context.Updateable<base_project>(projectEntity).ExecuteCommand() > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response.ResponseSuccess();
});
}
/// <summary>
/// 启动/终止项目 0未开始,10生产中,20生产结束,30生产终止
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public dynamic StartOrEndProject(base_project entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
var project = Context.Queryable<base_project>().Where(x => x.keys.Equals(entity.keys)).First();
if (entity.state == 0 || entity.state == 30)
{
//启动项目
response= ProjectTaskGenerate(entity.keys);
if (response.Code != (int)RetCode.SUCCESS) {
return response;
}
project.state = 10;
}
else if (entity.state == 10)
{
//终止项目
project.state = 30;
}
response.Status = Context.Updateable<base_project>(project).ExecuteCommand() > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response.ResponseSuccess();
});
}
#region 项目管理-质检任务生成-生产工单生成
/// <summary>
/// 项目管理-质检任务生成-生产工单生成
/// </summary>
/// <param name="keys">项目keys</param>
/// <returns></returns>
public dynamic ProjectTaskGenerate(Guid keys)
{
var response = new Response();
try
{
#region 数据验证
//项目
var project = Context.Queryable<base_project>().Where(x => x.keys == keys).First();
if (project == null)
{
return response.ResponseError($"未找到项目数据,请核对!");
}
if (project.state != (int)EnumProjectState.未开始)
{
return response.ResponseError($"项目已开始或终止不能进行操作,请核对!");
}
//项目工单
var projectOrder = Context.Queryable<base_project_production_order, base_productionOrder_EP3D>((a, b) => new JoinQueryInfos(
JoinType.Left, a.productionOrderKey == b.keys))
.Where((a, b) =>
b.state == (int)EnumEP3DState.已关联
&& a.projectKeys == keys
).Select((a, b) => new
{
b.keys,
b.pipelineNo,
b.weldingPointNo1,
b.weldingMaterial1,
b.weldingPointNo2,
b.weldingMaterial2,
b.pagination,
b.pipeSectionNo,
b.pipelineGrade,
b.pipeLength,
b.pipeMaterialCode,
b.pipeNumber,
b.batchNo
}).ToList();
if (projectOrder.Count <= 0)
{
return response.ResponseError($"项目为空或已经排版,请核对!");
}
//工艺路线
var processHead = Context.Queryable<base_process_route_head>()
.Where(x => x.keys == project.processKeys).First();
if (processHead == null)
{
return response.ResponseError($"项目未关联工艺路线,请核对!");
}
var processDetail = Context.Queryable<base_process_route_detail>()
.Where(x => x.headkeys == project.processKeys).OrderBy(x => x.oprSequence, OrderByType.Asc).ToList();
if (processDetail.Count <= 0)
{
return response.ResponseError($"工艺路线明细为空,请核对!");
}
#endregion
#region 按工艺路线生成数据
foreach (var item in processDetail)
{
var qualityDetail = new List<base_qualityStencil_detail>();
if (item.inspectionFlag == (int)EnumQualityisExecute.是)
{
qualityDetail = Context.Queryable<base_qualityStencil_detail>()
.Where(x => x.headKey == item.qualityKey && x.state == (int)EnumQuality.启用).ToList();
if (qualityDetail.Count <= 0)
{
return response.ResponseError($"工序【{item.oprSequenceCode}】有质检要求,但是关联的质检模板没有明细,请核对!");
}
}
//生成工单数据
foreach (var order in projectOrder)
{
int i = 1;
#region 生成工序任务头 bus_workOrder_head
var busWorkOrderHead = new bus_workOrder_head
{
keys = Guid.NewGuid(),
topKeys = project.keys,
plmeId = order.batchNo + "_" + i.ToString(),
workOrderCode = project.projectNo + "_" + i.ToString(),
workOrderName = project.projectName + "_" + i.ToString() + "_生产订单",
planCode = project.projectNo + "_" + i.ToString(),
processHeadKeys = processHead.keys,//工艺路线keys
processCode = processHead.processCode, //工艺路线编码
factoryCode = "lin4",
lineCode = "lin4",
orderType = "10",
edition = processHead.edition,
projectCode = project.projectNo, //项目编码
projectName = project.projectName,
lineNo = order.pipelineNo, //管线号/图纸号
planStartTime = project.scheduledStartTime,
planEndTime = project.scheduledEntTime,
otherOrderCode = project.projectNo,
state = (int)EnumOrderHeadStatus.初始化,
isDelete = 1,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
Context.Insertable(busWorkOrderHead).AddQueue();
#endregion
#region 生成工序任务明细 busWorkOrderDetailList
var busWorkOrderDetailList = new List<bus_workOrder_detail>();
var nowWorkDetail = new bus_workOrder_detail
{
headKeys = busWorkOrderHead.keys,
productHeaderCode = busWorkOrderHead.productHeaderCode,
workOrderCode = busWorkOrderHead.workOrderCode,
cutMaterCode = order.pipeMaterialCode,
cuttingLength = order.pipeLength,
lineCode = busWorkOrderHead.lineCode,
designNo = order.pagination,
designUrl = order.pipelineNo + ".pdf",
partCode = order.pipeSectionNo,
serialNumber = item.oprSequence,
oprSequenceCode = item.oprSequenceCode,
oprSequenceName = item.oprSequenceName,
workCenterCode = item.workCenterCode,
planStartTime = busWorkOrderHead.planStartTime,
planEndTime = busWorkOrderHead.planEndTime,
isEndProduct = 0,
isDelete = 1,
state = (int)EnumOrderBodyStatus.初始化,
workReportStatus = (int)EnumWorkReportStatus.未报工,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
nowWorkDetail.bodyKeys = Guid.NewGuid();
nowWorkDetail.serialNumberName = nowWorkDetail.serialNumber + "_1";
// 设置工序任务头的当前工序,为第一个工序任务明细的工序
if (busWorkOrderDetailList.Count > 0)
{
busWorkOrderHead.nowOprSequenceCode = busWorkOrderDetailList[0].oprSequenceCode;
}
//如果是组对或焊接需要补充焊口信息
if (item.workCenterCode == WorkCenterCode.组对 || item.workCenterCode == WorkCenterCode.焊接 || item.workCenterCode == WorkCenterCode.组焊)
{
nowWorkDetail.weldNo = order.weldingPointNo1;
nowWorkDetail.weldMaterCode = order.weldingMaterial1;
if (!string.IsNullOrEmpty(order.weldingPointNo1))
{
var nowWorkDetai2 = new bus_workOrder_detail();
nowWorkDetai2 = nowWorkDetail;
nowWorkDetai2.bodyKeys = Guid.NewGuid();
nowWorkDetai2.serialNumberName = nowWorkDetail.serialNumber + "_2";
nowWorkDetai2.weldNo = order.weldingPointNo2;
nowWorkDetai2.weldMaterCode = order.weldingMaterial2;
busWorkOrderDetailList.Add(nowWorkDetai2);
}
}
busWorkOrderDetailList.Add(nowWorkDetail);
Context.Insertable(busWorkOrderDetailList).AddQueue();
#endregion
#region 生成质检任务
foreach (var detail in qualityDetail)
{
var bqualityExecute = new base_qualityStencil_Execute
{
keys = Guid.NewGuid(),
workOrderDetailKey = nowWorkDetail.bodyKeys,
qualityDetailKey = detail.keys,
isExecute = (int)EnumQualityisExecute.否,
executeResult = (int)EnumQualityExecute.未执行,
state = (int)EnumQuality.启用,
createTime = DateTime.Now,
updateTime = DateTime.Now
};
Context.Insertable(bqualityExecute).AddQueue();
}
#endregion
}
}
var inCount = Context.SaveQueues();
if (inCount <= 0)
{
response.ResponseError($"数据保存数据库失败!");
}
#endregion
}
catch (Exception ex)
{
return response.ResponseError($"{ex.Message}!");
}
return response;
}
#endregion
}
}