ProcessRouteService.cs
10 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
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.Pojo.System;
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 System.Text;
namespace Hh.Mes.Service.Configure
{
public class ProcessRouteService : RepositorySqlSugar<base_process_route_head>
{
#region 头表
/// <summary>
///
/// </summary>
public Response Load(PageReq pageReq, base_process_route_head model)
{
var totalCount = 0;
var result = new Response();
var query = Context.Queryable<base_process_route_head, base_line>((x, li) => new JoinQueryInfos(
JoinType.Left, x.lineCode == li.lineCode)).
Where(Wheres(model)).
Select((x, li) => new
{
x.id,
x.keys,
x.processCode,
x.processName,
x.lineCode,
li.lineName,
x.edition,
x.otherCode,
x.isDelete,
x.plmeid,
x.createBy,
x.createTime,
x.updateBy,
x.updateTime
});
dynamic data;
if (pageReq != null)
{
data = query.OrderBy(x => x.createTime, OrderByType.Desc).ToOffsetPage(pageReq.page, pageReq.limit, ref totalCount);
}
else
{
data = query.ToList();
totalCount = data.Count;
}
result.Result = data;
result.Count = totalCount;
return result;
}
/// <summary>
/// 查询条件
/// </summary>
/// <returns></returns>
public Expression<Func<base_process_route_head, bool>> Wheres(base_process_route_head model)
{
var exp = Expressionable.Create<base_process_route_head>();
if (!string.IsNullOrWhiteSpace(model.lineCode)) exp.And(x => x.lineCode.Contains(model.lineCode));
if (!string.IsNullOrWhiteSpace(model.processCode)) exp.And(x => x.processCode.Contains(model.processCode));
if (model.keys!= Guid.Empty) exp.And(x => x.keys== model.keys);
if (!string.IsNullOrWhiteSpace(model.plmeid)) exp.And(x => x.plmeid == model.plmeid);
var wheres = exp.ToExpression();//拼接表达式
return wheres;
}
/// <summary>
/// 添加
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
public dynamic Ins(base_process_route_head model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.createBy = sysWebUser?.Account;
model.createTime = DateTime.Now;
model.keys = Guid.NewGuid();
response.Status = Add(model);
if (!response.Status)
{
response.Message = SystemVariable.dataActionError;
}
return response;
});
}
/// <summary>
/// 编辑方法
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
public dynamic Upd(base_process_route_head model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.updateBy = sysWebUser?.Account;
model.updateTime = DateTime.Now;
response.Status = base.Context.Updateable(model).IgnoreColumns(it => new { it.createBy, it.createTime }).ExecuteCommand() > 0;
if (!response.Status)
{
response.Message = SystemVariable.dataActionError;
}
return response;
});
}
/// <summary>
/// 删除方法
/// </summary>
/// <param name="ids">需要删除的id</param>
/// <returns></returns>
public dynamic DelByIds(Guid[] ids)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
base.Context.Deleteable<base_process_route_head>().In(x => x.keys, ids).AddQueue();
base.Context.Deleteable<base_process_route_detail>().In(x => x.headkeys, ids).AddQueue();
//删除工序工位
Guid[] processRouteDetailId = Context.Queryable<base_process_route_detail>().In(x => x.headkeys, ids).Select(x => x.bodyKeys).ToArray();
//base.Context.Deleteable<base_process_route_station>().In(x => x.bodyKeys, processRouteDetailId).AddQueue();
//删除工艺路线和 产品关系
base.Context.Deleteable<base_process_product_rel>().In(x => x.processHeadKeys, ids).AddQueue();
response.Status = Context.SaveQueues() > 0;
if (!response.Status)
{
response.Message = SystemVariable.dataActionError;
}
return response;
});
}
/// <summary>
/// 导出方法
/// </summary>
/// <returns></returns>
public dynamic Export(base_process_route_head Table_Entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
Response result = Load(null, Table_Entity);
if (result.Count == 0)
{
result.Result = null;
result.Message = SystemVariable.queryNotData;
result.Code = -1;
return result;
}
var guids = new List<Guid>();
foreach (var item in result.Result)
{
guids.Add((Guid)item.keys);
}
var data = LoadDesc(null, new base_process_route_detail{ headkeysList= guids });
result.Result = new
{
head = result.Result,
body = data.Result
};
return result;
}, catchRetrunValue: "list");
}
#endregion
#region 明细
/// <summary>
/// 查询方法明细 支持导出查询
/// </summary>
public Response LoadDesc(PageReq pageReq, base_process_route_detail model)
{
var totalCount = 0;
var result = new Response();
var query = base.Context.Queryable<base_process_route_detail>();
var data = model.headkeysList!=null ? query.In(x => x.headkeys, model.headkeysList).ToList() :
query.Where(x => x.headkeys == model.headkeys).OrderBy(x=>x.oprSequence).ToOffsetPage(pageReq.page, pageReq.limit, ref totalCount);
//页码,页数
result.Result = data;
result.Count = totalCount;
return result;
}
/// <summary>
/// 添加
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
public dynamic InsDesc(base_process_route_detail model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.bodyKeys = Guid.NewGuid();
model.createBy = sysWebUser?.Account;
model.createTime = DateTime.Now;
response.Status = Add(model);
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
/// <summary>
/// 编辑方法
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
public dynamic UpdDesc(base_process_route_detail model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
response.Status = base.Context.Updateable(model).Where(x=>x.bodyKeys==model.bodyKeys).IgnoreColumns(it => new { it.createBy, it.createTime }).ExecuteCommand() > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
/// <summary>
/// 删除方法
/// </summary>
/// <param name="ids">需要删除的id</param>
/// <returns></returns>
public dynamic DelByIdsDesc(Guid[] ids)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
Context.Deleteable<base_process_route_detail>().In(x => x.bodyKeys, ids).AddQueue();
//删除工序工位
//Context.Deleteable<base_process_route_station>().In(x => x.bodyKeys, ids).AddQueue();
response.Status = Context.SaveQueues() > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
#endregion
/// <summary>
/// //获取列表
/// </summary>
public Response GetProcessDetail()
{
var result = new Response();
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine($@" select distinct oprSequenceCode ,oprSequenceName
from [dbo].[base_process_route_detail] ");
var ds = base.Context.Ado.GetDataSetAll(stringBuilder.ToString());
result.Result = ds.Tables[0];
result.Count = result.Result.Rows.Count;
return result;
}
}
}