|
1
2
3
|
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
|
|
4
|
using Hh.Mes.POJO.EnumEntitys;
|
|
5
6
7
8
9
10
|
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
|
|
11
|
using System.Diagnostics;
|
|
12
|
using System.Drawing;
|
|
13
14
15
16
17
|
using System.Linq;
using System.Text;
namespace Hh.Mes.Service.Material
{
|
|
18
|
public class ProductionOrderService : RepositorySqlSugar<bus_pro_plan_head>
|
|
19
20
|
{
/// <summary>
|
|
21
22
23
24
25
26
27
28
29
|
/// 初始化
/// </summary>
private int initState { get; set; }
/// <summary>
/// 已确认
/// </summary>
private int confirmState { get; set; }
|
|
30
31
|
public ProductionOrderService()
{
|
|
32
33
34
35
36
37
38
39
|
initState = (int)EnumProPlan.初始化;
confirmState = (int)EnumProPlan.已确认;
}
#region 列表
/// <summary>
|
|
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
|
/// 获取工单列表
/// </summary>
public Response GetProductionOrderList(PageReq pageReq, bus_pro_plan_head entity)
{
var result = new Response();
string orderBy = (pageReq == null || string.IsNullOrEmpty(pageReq.field)) ? " id desc" : $"{pageReq.field} {pageReq.order} ";
string sqlWhere = SqlProductionOrderWhere(entity);
var stringBuilder = new StringBuilder();
//页码,页数
//Exel ture 不分页
if (!entity.Exel && pageReq != null)
{
stringBuilder.Append("declare @pageIndex int,@pageSize int,@offset int");
stringBuilder.AppendLine($" select @pageIndex={pageReq.page}, @pageSize={pageReq.limit}, @offset=(@pageIndex - 1) * @pageSize");
}
stringBuilder.AppendLine($@" select * from bus_pro_plan_head where {sqlWhere} order by {orderBy} ");
//Exel ture 不分页
if (!entity.Exel)
{
stringBuilder.AppendLine(" offset @offset row fetch next @pageSize row only ");
stringBuilder.Append($@" select rowTotal= count(*) from bus_pro_plan_head where {sqlWhere}");
}
var parameters = new List<SugarParameter>(){
new SugarParameter("@planCode",entity.planCode),
new SugarParameter("@planName",entity.planName),
new SugarParameter("@productCode",entity.productCode),
new SugarParameter("@productName",entity.productName)
};
|
|
71
|
|
|
72
73
74
75
76
77
|
var ds = base.Context.Ado.GetDataSetAll(stringBuilder.ToString(), parameters);
result.Result = ds.Tables[0];
result.Count = entity.Exel ? (int)result.Result.Rows.Count : (int)ds.Tables[1].Rows[0]["rowTotal"];
return result;
}
|
|
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
|
/// <summary>
/// 获取工单列表明细
/// </summary>
public Response GetProductionOrderDetailList(PageReq pageReq, bus_pro_plan_head entity)
{
var result = new Response();
string orderBy = (pageReq == null || string.IsNullOrEmpty(pageReq.field)) ? " id asc" : $"{pageReq.field} {pageReq.order} ";
string sqlWhere = SqlProductionOrderDetailWhere(entity);
var stringBuilder = new StringBuilder();
//页码,页数
//Exel ture 不分页
if (!entity.Exel && pageReq != null)
{
stringBuilder.Append("declare @pageIndex int,@pageSize int,@offset int");
stringBuilder.AppendLine($" select @pageIndex={pageReq.page}, @pageSize={pageReq.limit}, @offset=(@pageIndex - 1) * @pageSize");
}
stringBuilder.AppendLine($@" select * from bus_pro_plan_detail where {sqlWhere} order by {orderBy} ");
//Exel ture 不分页
if (!entity.Exel)
{
stringBuilder.AppendLine(" offset @offset row fetch next @pageSize row only ");
stringBuilder.Append($@" select rowTotal= count(*) from bus_pro_plan_detail where {sqlWhere}");
}
var parameters = new List<SugarParameter>(){
new SugarParameter("@proPlanHeadKeys",entity.keys),
};
var ds = base.Context.Ado.GetDataSetAll(stringBuilder.ToString(), parameters);
result.Result = ds.Tables[0];
result.Count = entity.Exel ? (int)result.Result.Rows.Count : (int)ds.Tables[1].Rows[0]["rowTotal"];
return result;
}
/// <summary>
/// 获取工单列表明细Bom
/// </summary>
public Response GetProductionOrderDetailBomList(PageReq pageReq, bus_pro_plan_detail entity)
{
var result = new Response();
string orderBy = (pageReq == null || string.IsNullOrEmpty(pageReq.field)) ? " id asc" : $"{pageReq.field} {pageReq.order} ";
string sqlWhere = SqlProductionOrderDetailBomWhere();
var stringBuilder = new StringBuilder();
//页码,页数
//Exel ture 不分页
if (!entity.Exel && pageReq != null)
{
stringBuilder.Append("declare @pageIndex int,@pageSize int,@offset int");
stringBuilder.AppendLine($" select @pageIndex={pageReq.page}, @pageSize={pageReq.limit}, @offset=(@pageIndex - 1) * @pageSize");
}
stringBuilder.AppendLine($@" select * from bus_pro_plan_detail_bom where {sqlWhere} order by {orderBy} ");
//Exel ture 不分页
if (!entity.Exel)
{
stringBuilder.AppendLine(" offset @offset row fetch next @pageSize row only ");
stringBuilder.Append($@" select rowTotal= count(*) from bus_pro_plan_detail_bom where {sqlWhere}");
}
var parameters = new List<SugarParameter>(){
new SugarParameter("@proPlanDetailKeys",entity.bodyKeys),
};
var ds = base.Context.Ado.GetDataSetAll(stringBuilder.ToString(), parameters);
result.Result = ds.Tables[0];
result.Count = entity.Exel ? (int)result.Result.Rows.Count : (int)ds.Tables[1].Rows[0]["rowTotal"];
return result;
}
|
|
151
152
153
154
155
156
|
public string SqlProductionOrderWhere(bus_pro_plan_head model)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(" 1=1 ");
if (!string.IsNullOrEmpty(model.planCode))
{
|
|
157
|
stringBuilder.Append(" and planCode = @planCode ");
|
|
158
159
160
|
}
if (!string.IsNullOrEmpty(model.planName))
{
|
|
161
|
stringBuilder.Append(" and planName like '%'+@planName+'%' ");
|
|
162
163
164
|
}
if (!string.IsNullOrEmpty(model.productCode))
{
|
|
165
|
stringBuilder.Append(" and productCode = @productCode ");
|
|
166
167
168
|
}
if (!string.IsNullOrEmpty(model.productName))
{
|
|
169
|
stringBuilder.Append(" and productName like '%'+@productName+'%' ");
|
|
170
171
172
173
174
175
176
177
178
|
}
//下拉弹出搜索框
//if (!string.IsNullOrEmpty(model.codeOrName))
//{
// stringBuilder.Append($" and (t1.materialCode like '%'+@codeOrName+'%' or t1.materialName like '%'+@codeOrName+'%' ) ");
//}
return stringBuilder.ToString();
}
|
|
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
public string SqlProductionOrderDetailWhere(bus_pro_plan_head model)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(" 1=1 ");
stringBuilder.Append(" and proPlanHeadKeys = @proPlanHeadKeys ");
return stringBuilder.ToString();
}
public string SqlProductionOrderDetailBomWhere()
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(" 1=1 ");
stringBuilder.Append(" and proPlanDetailKeys = @proPlanDetailKeys ");
return stringBuilder.ToString();
|
|
193
|
}
|
|
194
|
#endregion
|
|
195
|
|
|
196
|
/// <summary>
|
|
197
|
/// 新增生产计划 工单
|
|
198
199
200
201
202
203
204
205
|
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public dynamic Ins(bus_pro_plan_head entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
|
|
206
207
|
var isExistCount = Context.Queryable<bus_pro_plan_head>().Where(x => x.planCode == entity.planCode).Count();
|
|
208
209
|
if (isExistCount > 0) return response.ResponseError("生产计划 已存在相同的计划号【" + entity.planCode + "】的记录!请勿重复!");
if (entity.productHeadKeys== Guid.Empty) return response.ResponseError("生产计划 选择的产品名称【" + entity.productName + "】没有关联工艺路线,请重新绑定!");
|
|
210
|
if (entity.planEndTime < entity.planStartTime) return response.ResponseError("计划结束时间不能小于计划开始时间!");
|
|
211
|
|
|
212
|
entity.keys = Guid.NewGuid();
|
|
213
|
entity.createBy = sysWebUser.Account;
|
|
214
|
entity.createTime = DateTime.Now;
|
|
215
|
entity.status = initState;
|
|
216
|
|
|
217
218
|
var materialCodeList = Context.Queryable<base_product_detail>().Where(x=>x.headKeys== entity.productHeadKeys).Select(x => x.materialCode).ToList();
if (materialCodeList.Count==0) return response.ResponseError("生产计划 选择的产品【" + entity.productName + "】没有产品明细信息!");
|
|
219
|
var materialList = Context.Queryable<base_material_rate>().Where(x => materialCodeList.Contains(x.materialCode)).ToList();
|
|
220
|
if(materialList.Count==0) return response.ResponseError("生产计划 选择的产品【" + entity.productName + "】明细物料信息【"+ string.Join(",", materialCodeList) + "】没有绑定物料比例,请在物料信息=>编辑物料BOM比例 绑定!");
|
|
221
|
|
|
222
223
|
Context.Insertable(entity).AddQueue();
for (int index = 0; index < entity.quantity; index++)
|
|
224
|
{
|
|
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
var detail = new bus_pro_plan_detail();
detail.bodyKeys = Guid.NewGuid();
detail.proPlanHeadKeys = entity.keys;
detail.workOrderCode = DateTime.Now.ToString("yyyyMMddHHmmss") + getNumber((index + 1).ToString());
detail.workOrderName = entity.planName + getNumber((index + 1).ToString());
detail.lineCode = entity.lineCode;
detail.productCode = entity.productCode;
detail.productName = entity.productName;
detail.createBy = sysWebUser?.Account;
detail.createTime = DateTime.Now;
int count = 0;
int i = 1;
foreach (var material in materialList)
|
|
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
|
count += material.quantityRate.Value;
var bom = new bus_pro_plan_detail_bom();
bom.bodyKeys = Guid.NewGuid();
bom.proPlanHeadKeys = entity.keys;
bom.proPlanDetailKeys = detail.bodyKeys;
bom.materialCode = material.materialCode;
bom.materialName = material.materialName;
bom.oprSequenceCode = material.oprSequenceCode;
bom.detailSN = DateTime.Now.ToString("yyyyMMddHHmmss") + getNumber((i++).ToString());
bom.spec = material.specifications;
bom.unit = material.unitCode;
bom.productCode = entity.productCode;
bom.quantity = material.quantityRate.Value;
bom.createBy = sysWebUser.Account;
bom.createTime = DateTime.Now;
Context.Insertable(bom).AddQueue();
var rel = new bus_pro_plan_detail_bom_rel();
rel.proPlanHeadKeys = entity.keys;
rel.proPlanDetailBodyKeys = detail.bodyKeys;
rel.proPlanDetailBomBodyKeys = bom.bodyKeys;
rel.createBy = sysWebUser.Account;
rel.createTime = DateTime.Now;
Context.Insertable(rel).AddQueue();
|
|
264
|
}
|
|
265
266
|
detail.quantity = count;
Context.Insertable(detail).AddQueue();
|
|
267
|
}
|
|
268
269
270
|
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
|
|
271
272
273
|
});
}
|
|
274
275
|
private string getNumber(string index)
{
|
|
276
|
while (index.Length < 5)
|
|
277
278
279
280
281
282
|
{
index = "0" + index;
}
return index;
}
|
|
283
|
/// <summary>
|
|
284
|
/// 更新 生产计划工单
|
|
285
|
/// </summary>
|
|
286
|
public dynamic Upd(bus_pro_plan_head entity)
|
|
287
288
289
290
|
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
|
|
291
292
293
294
295
296
297
298
299
300
301
302
303
|
var isExistCount = Context.Queryable<bus_pro_plan_head>().Where(x => x.planCode == entity.planCode && x.id != entity.id).Count();
if (isExistCount > 0)
{
response.ResponseErr("已存在工单为【" + entity.planCode + "】的记录!请勿重复!");
return response;
}
if (entity.planEndTime < entity.planStartTime)
{
response.ResponseErr("计划结束时间不能小于计划开始时间!");
return response;
}
|
|
304
|
entity.updateBy = sysWebUser.Account;
|
|
305
|
entity.updateTime = DateTime.Now;
|
|
306
|
entity.status = (int)EnumProPlan.初始化;
|
|
307
|
response.Status = Context.Updateable(entity).Where(u => u.id == entity.id).ExecuteCommand() > 0;
|
|
308
|
if (!response.Status) response.Message = "更新失败";
|
|
309
310
311
312
313
314
|
if (response.Status)
{
var countResult = Context.Queryable<bus_pro_plan_detail>().Where(x => x.proPlanHeadKeys == entity.keys).Count();
if (countResult != entity.quantity)
{
|
|
315
316
317
|
Context.Deleteable<bus_pro_plan_detail>().Where(x => x.proPlanHeadKeys == entity.keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail_bom>().Where(x => x.proPlanHeadKeys == entity.keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail_bom_rel>().Where(x => x.proPlanHeadKeys == entity.keys).AddQueue();
|
|
318
|
|
|
319
320
321
322
323
|
var productCodeList = Context.Queryable<base_product_header>().Where(x => x.productCode == entity.productCode).Select(x => x.keys).ToList();
var materialCodeList = Context.Queryable<base_product_detail>().Where(x => productCodeList.Contains(x.headKeys)).Select(x => x.materialCode).ToList();
var materialList = Context.Queryable<base_material_rate>().Where(x => materialCodeList.Contains(x.materialCode)).ToList();
if (materialList.Count > 0)
|
|
324
|
{
|
|
325
|
for (int index = 0; index < entity.quantity; index++)
|
|
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
|
var detail = new bus_pro_plan_detail();
detail.bodyKeys = Guid.NewGuid();
detail.proPlanHeadKeys = entity.keys;
detail.workOrderCode = DateTime.Now.ToString("yyyyMMddHHmmss") + getNumber((index + 1).ToString());
detail.workOrderName = entity.planName + getNumber((index + 1).ToString());
detail.lineCode = entity.lineCode;
detail.productCode = entity.productCode;
detail.productName = entity.productName;
detail.createBy = sysWebUser?.Account;
detail.createTime = DateTime.Now;
int count = 0;
int i = 1;
foreach (var material in materialList)
{
count += material.quantityRate.Value;
var bom = new bus_pro_plan_detail_bom();
bom.bodyKeys = Guid.NewGuid();
bom.proPlanHeadKeys = entity.keys;
bom.proPlanDetailKeys = detail.bodyKeys;
bom.materialCode = material.materialCode;
bom.materialName = material.materialName;
bom.oprSequenceCode = material.oprSequenceCode;
bom.detailSN = DateTime.Now.ToString("yyyyMMddHHmmss") + getNumber((i++).ToString());
bom.spec = material.specifications;
bom.unit = material.unitCode;
bom.productCode = entity.productCode;
bom.quantity = material.quantityRate.Value;
bom.createBy = sysWebUser?.Account;
bom.createTime = DateTime.Now;
Context.Insertable(bom).AddQueue();
var rel = new bus_pro_plan_detail_bom_rel();
rel.proPlanHeadKeys = entity.keys;
rel.proPlanDetailBodyKeys = detail.bodyKeys;
rel.proPlanDetailBomBodyKeys = bom.bodyKeys;
rel.createBy = sysWebUser?.Account;
rel.createTime = DateTime.Now;
Context.Insertable(rel).AddQueue();
}
detail.quantity = count;
Context.Insertable(detail).AddQueue();
|
|
369
|
}
|
|
370
371
372
373
374
375
376
|
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
}
else
{
return response.ResponseError("查不到产品物料列表,修改错误!");
|
|
377
378
379
380
|
}
}
}
|
|
381
382
383
384
385
|
return response;
});
}
/// <summary>
|
|
386
|
/// 更新 生产计划工单
|
|
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
/// </summary>
public dynamic UpdDetail(bus_pro_plan_detail entity)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
entity.updateBy = sysWebUser?.Account;
entity.updateTime = DateTime.Now;
response.Status = Context.Updateable(entity).Where(u => u.id == entity.id).ExecuteCommand() > 0;
if (!response.Status) response.Message = "更新失败";
return response;
});
}
/// <summary>
|
|
403
|
/// 更新 生产计划工单
|
|
404
405
406
407
408
409
|
/// </summary>
public dynamic UpdDetailBom(bus_pro_plan_detail_bom entity)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
|
|
410
|
entity.updateBy = sysWebUser.Account;
|
|
411
412
413
414
415
416
417
418
419
|
entity.updateTime = DateTime.Now;
response.Status = Context.Updateable(entity).Where(u => u.id == entity.id).ExecuteCommand() > 0;
if (!response.Status) response.Message = "更新失败";
return response;
});
}
/// <summary>
|
|
420
|
/// 删除生产计划
|
|
421
422
423
424
425
426
427
|
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public dynamic DelByIds(int[] ids)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
|
|
428
|
Response response = new Response();
|
|
429
430
|
var dataList = Context.Queryable<bus_pro_plan_head>().Where(x => ids.Contains(x.id)).ToList();
bool isSuccess = true;
|
|
431
|
int isDelete = 0;
|
|
432
433
|
for (int index = 0; index < dataList.Count; index++)
{
|
|
434
|
if (dataList[index].status == initState)
|
|
435
436
|
{
isDelete++;
|
|
437
438
439
440
441
|
Context.Deleteable<bus_pro_plan_head>().Where(x => x.keys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail>().Where(x => x.proPlanHeadKeys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail_bom>().Where(x => x.proPlanHeadKeys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail_bom_rel>().Where(x => x.proPlanHeadKeys == dataList[index].keys).AddQueue();
}
|
|
442
443
444
445
446
|
else
{
isSuccess = false;
}
}
|
|
447
|
var resultCount = Context.SaveQueues();
|
|
448
|
if (!isSuccess)
|
|
449
|
{
|
|
450
451
452
453
454
|
response.ResponseErr("已确认的无法删除!!!!");
}
else if (resultCount > 0)
{
response.ResponseSuccess("删除成功!已删除【" + isDelete + "】条");
|
|
455
456
457
458
459
|
}
return response;
});
}
|
|
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
public dynamic DelAllByIds(Guid[] ids)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
Response response = new Response();
var dataList = Context.Queryable<bus_pro_plan_head>().Where(x => ids.Contains(x.keys)).ToList();
bool isSuccess = true;
int isDelete = 0;
for (int index = 0; index < dataList.Count; index++)
{
isDelete++;
Context.Deleteable<bus_pro_plan_head>().Where(x => x.keys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail>().Where(x => x.proPlanHeadKeys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail_bom>().Where(x => x.proPlanHeadKeys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_pro_plan_detail_bom_rel>().Where(x => x.proPlanHeadKeys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_workOrder_head>().Where(x => x.keys == dataList[index].keys).AddQueue();
Context.Deleteable<bus_workOrder_detail>().Where(x => x.headKeys == dataList[index].keys).AddQueue();
}
var resultCount = Context.SaveQueues();
return response.ResponseSuccess("已删除【" + isDelete + "】条");
});
}
|
|
485
|
/// <summary>
|
|
486
|
/// 完成 生产计划工单
|
|
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public dynamic Complete(bus_pro_plan_head entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
var dataObj = Context.Queryable<bus_pro_plan_head>().Where(x => x.planCode == entity.planCode).First();
if (dataObj == null)
{
response.ResponseErr("查询不到计划工单!无法完成工单编制!");
return response;
}
|
|
502
|
dataObj.status = confirmState;
|
|
503
|
Context.Updateable(dataObj).AddQueue();
|
|
504
|
|
|
505
506
507
508
509
|
//找工序为1的
var oprSequenceCode = "";
var oprSequenceName = "";
var processDetailList = Context.Queryable<base_process_route_detail>().Where(x => x.headkeys == dataObj.processRouteKeys).OrderBy(t => t.oprSequence).ToList();
if (processDetailList.Count > 0)
|
|
510
|
{
|
|
511
512
513
514
515
516
517
518
|
oprSequenceCode = processDetailList[0].oprSequenceCode;
oprSequenceName = processDetailList[0].oprSequenceName;
}
//循环工单明细 保存工单
var planDetailList = Context.Queryable<bus_pro_plan_detail>().Where(x => x.proPlanHeadKeys == dataObj.keys).OrderBy(x => x.workOrderCode, OrderByType.Asc).ToList();
foreach (var planDetail in planDetailList)
{
var head = new bus_workOrder_head();
|
|
519
|
head.keys = entity.keys;//取生产计划主表的key
|
|
520
521
522
|
head.processHeadKeys = dataObj.processRouteKeys;
head.productHeaderCode = dataObj.productCode;
head.productName = dataObj.productName;
|
|
523
|
head.orderType = "3";//通过生产计划生成
|
|
524
525
526
|
head.lineCode = dataObj.lineCode;
head.nowOprSequenceCode = oprSequenceCode;
head.workOrderCode = dataObj.planCode;
|
|
527
|
head.planCode = planDetail.workOrderCode;
|
|
528
529
530
531
532
533
|
head.state = (int)EnumOrderHeadStatus.初始化;
head.planStartTime = dataObj.planStartTime;
head.planEndTime = dataObj.planEndTime;
head.isDelete = (int)EnumDeleteOrAdd.新增或更新;
head.projectCode = dataObj.projectCode;
head.projectName = dataObj.projectName;
|
|
534
|
head.lineNo = dataObj.lineNo;
|
|
535
536
537
538
539
540
541
542
|
head.edition = dataObj.edition;
head.factoryCode = dataObj.factoryCode;
head.createBy = sysWebUser?.Account;
head.createTime = DateTime.Now;
Context.Insertable(head).AddQueue();
//保存工单明细
foreach (var processDetail in processDetailList)
|
|
543
|
{
|
|
544
545
546
|
var list = Context.Queryable<base_work_center_station_rel>().Where(x => x.workCenterCode.Equals(processDetail.workCenterCode)).ToList();
var i = 0;
var bomList = Context.Queryable<bus_pro_plan_detail_bom>().Where(x => x.proPlanDetailKeys == planDetail.bodyKeys && x.oprSequenceCode == processDetail.oprSequenceCode).ToList();
|
|
547
548
549
550
551
|
if (bomList.Count == 0)
{
response.ResponseErr("工序【" + processDetail.oprSequenceCode + "】无法匹配,请确定是否配置正确!");
return response;
}
|
|
552
553
554
|
foreach (var bomObject in bomList)
{
for (int index = 0; index < bomObject.quantity; index++)
|
|
555
|
{
|
|
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
var detail = new bus_workOrder_detail();
detail.bodyKeys = Guid.NewGuid();
detail.headKeys = head.keys;
detail.serialNumber = processDetail.oprSequence;
detail.lineCode = head.lineCode;
detail.oprSequenceCode = processDetail.oprSequenceCode;
detail.oprSequenceName = processDetail.oprSequenceName;
detail.state = (int)EnumOrderBodyStatus.初始化;
detail.isRework = false;
detail.planStartTime = dataObj.planStartTime;
detail.planEndTime = dataObj.planEndTime;
detail.productHeaderCode = dataObj.productCode;
detail.isDelete = (int)EnumDeleteOrAdd.新增或更新;
detail.workOrderCode = head.workOrderCode;
detail.barCode = GetBarCode();
detail.designUrl = dataObj.designUrl;
detail.designNo = dataObj.designNo;
if (list.Count == 1)
|
|
574
|
{
|
|
575
|
detail.stationCode = list[0].workStationCode;
|
|
576
|
}
|
|
577
578
579
580
581
582
583
584
585
586
|
detail.workReportStatus = (int)EnumWorkReportStatus.未报工;
detail.workCenterCode = processDetail.workCenterCode;
detail.createBy = sysWebUser?.Account;
detail.createTime = DateTime.Now;
detail.cutMaterCode = bomObject.materialCode;
detail.weldMaterCode = bomObject.materialCode;
detail.serialNumberName = processDetail.oprSequence.ToString() + "-" + (++i);
Context.Insertable(detail).AddQueue();
|
|
587
588
589
590
591
|
}
}
}
}
|
|
592
593
|
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
|
|
594
595
|
});
}
|
|
596
597
598
599
|
public string GetBarCode()
{
var id = Context.Queryable<bus_identify_config>().Max(x => x.id);
|
|
600
601
602
603
604
605
606
|
if (id == 0)
{
//第一次加载 添加一行数据 默认从1001开始
Context.Insertable(new bus_identify_config { id = 1001 }).ExecuteCommand();
id = Context.Queryable<bus_identify_config>().Max(x => x.id);//取值
}
return id.ToString();
|
|
607
|
}
|
|
608
609
|
}
}
|