服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-05-30 7e25ed322740ed337296a990bac67e95bc250ac0
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
using Tiger.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Rhea.Common;
using System.Net;
using System.Linq;
using Newtonsoft.Json;
using Tiger.IBusiness;
using Microsoft.AspNetCore.Http;
 
namespace Tiger.Business
{
    public partial class Biz
    {
        /// <summary>
        /// 工艺路线
        /// </summary>
        public partial class Route : IRoute
        {
            /// <summary>
            /// 获取工艺路线
            /// </summary>
            /// <param name="routerCode"></param>
            /// <returns></returns>
            public async Task<ApiAction<List<MES_ROUTE>>> GetRoute(string routerCode)
            {
                var res = new ApiAction<List<MES_ROUTE>>();
                List<MES_ROUTE> list = new List<MES_ROUTE>();
                try
                {
                    list = await Db.Queryable<MES_ROUTE>()
                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
                        .OrderBy(x => x.CREATE_TIME).ToListAsync();
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "查询异常");
                }
                res.Data = list;
                return res;
            }
 
            /// <summary>
            /// 获取工艺路线图形数据
            /// </summary>
            /// <param name="routerId"></param>
            /// <returns></returns>
            public async Task<ApiAction<RouteData>> GetRouteData(string routerId)
            {
                var res = new ApiAction<RouteData>();
                RouteData rotData = new RouteData();
                try
                {
                    if (string.IsNullOrEmpty(routerId))
                    {
                        res.IsSuccessed = false;
                        res.LocaleMsg = new($"传入的工艺路线ID为空,不能查找工艺路线!");
                        return res;
                    }
                    //工艺路线
                    var route = await Db.Queryable<MES_ROUTE>()
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ID.Equals(routerId))
                        .OrderBy(x => x.CREATE_TIME).FirstAsync();
                    rotData.route = route;
                    //节点
                    var nodes = await Db.Queryable<MES_ROUTE_NODE>()
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ROT_ID.Equals(routerId))
                        .ToListAsync();
                    foreach (var node in nodes)
                    {
                        node.node = new()
                        {
                            id = node.ID,
                            type = node.GPH_TYPE,
                            x = node.GPH_X,
                            y = node.GPH_Y,
                            properties = node.GPH_PROP,
                            text = new()
                            {
                                x = node.GPH_X,
                                y = node.GPH_Y,
                                value = node.GPH_TEXT
                            }
                        };
                    }
                    rotData.nodes = nodes;
 
                    var acts = await Db.Queryable<MES_ROUTE_NODE_ACT>()
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ROT_ID.Equals(routerId))
                        .ToListAsync();
                    foreach (var act in acts)
                    {
                        act.node = new()
                        {
                            id = act.ID,
                            type = act.GPH_TYPE,
                            x = act.GPH_X,
                            y = act.GPH_Y,
                            properties = act.GPH_PROP,
                            text = new()
                            {
                                x = act.GPH_X,
                                y = act.GPH_Y,
                                value = act.GPH_TEXT
                            }
                        };
                    }
                    rotData.acts = acts;
 
                    //边
                    var edges = await Db.Queryable<MES_ROUTE_EDGE>()
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ROT_ID.Equals(routerId))
                        .ToListAsync();
                    foreach (var edge in edges)
                    {
                        edge.edge = new()
                        {
                            id = edge.ID,
                            type = edge.GPH_TYPE,
                            sourceNodeId = edge.SRC_NODE,
                            targetNodeId = edge.TGT_NODE,
                            properties = edge.GPH_PROP,
                            startPoint = new()
                            {
                                x = edge.GPH_SRC_X,
                                y = edge.GPH_SRC_Y,
                            },
                            endPoint = new()
                            {
                                x = edge.GPH_TGT_X,
                                y = edge.GPH_TGT_Y,
                            },
                            pointsList = new()
                            {
                                new(){
                                    x = edge.GPH_SRC_X,
                                    y = edge.GPH_SRC_Y,
                                },
                                new(){
                                    x = edge.GPH_TGT_X,
                                    y = edge.GPH_TGT_Y,
                                }
                            }
                        };
                    }
                    rotData.edges = edges;
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "查询异常");
                }
                res.Data = rotData;
                return res;
            }
 
            /// <summary>
            /// 保存边数据
            /// </summary>
            /// <param name="routeEdge"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveEdges(List<MES_ROUTE_EDGE> routeEdge)
            {
                var result = new ApiAction();
                try
                {
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(routeEdge)
                           .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"保存边数据异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存边数据异常");
                }
                return await Task.FromResult(result);
            }
 
            /// <summary>
            /// 保存节点数据
            /// </summary>
            /// <param name="routeNode"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveNodes(List<MES_ROUTE_NODE> routeNode)
            {
                var result = new ApiAction();
                try
                {
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(routeNode)
                           .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"保存节点数据异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存节点数据异常");
                }
                return await Task.FromResult(result);
            }
 
            /// <summary>
            /// 保存行为
            /// </summary>
            /// <param name="routeAct"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveActs(List<MES_ROUTE_NODE_ACT> routeAct)
            {
                var result = new ApiAction();
                try
                {
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(routeAct)
                           .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"保存行为数据异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存行为数据异常");
                }
                return await Task.FromResult(result);
            }
 
            /// <summary>
            /// 保存
            /// </summary>
            /// <param name="route"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveRoute(MES_ROUTE route)
            {
                var result = new ApiAction();
                try
                {
                    var _route = Db.Queryable<MES_ROUTE>().Where(x=>x.ROT_CODE == route.ROT_CODE).First();
                    if (_route!=null && Db.Queryable<MES_ROUTE_NODE>().Where(x=>x.ROT_ID == _route.ID).Any())
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"工艺路线已经有设计记录,不能保存!"); 
                        return result;
                    }
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(route)
                           .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"保存工艺路线异常";
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存工艺路线异常");
                }
                return await Task.FromResult(result);
            }
 
            /// <summary>
            /// 保存工艺路线图形数据
            /// </summary>
            /// <param name="routeData"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveRouteData(RouteData routeData)
            {
                var result = new ApiAction();
                try
                {
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        if (routeData.route != null)
                        {
                            var y = db.Storageable(routeData.route)
                               .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
                               .ToStorage();
                            y.AsInsertable.ExecuteCommand();
                            y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                        }
                        db.Deleteable<MES_ROUTE_NODE>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand();
                        db.Deleteable<MES_ROUTE_EDGE>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand();
                        db.Deleteable<MES_ROUTE_NODE_ACT>(false).Where(x=>x.ROT_ID == routeData.route.ID).ExecuteCommand();
                        if (routeData.nodes != null)
                        {
                            db.Insertable(routeData.nodes).ExecuteCommand();
                        }
                        if (routeData.edges != null)
                        {
                            db.Insertable(routeData.edges).ExecuteCommand();
                        }
                        if (routeData.acts != null)
                        {
                            db.Insertable(routeData.acts).ExecuteCommand();
                        }
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"保存工艺路线图形数据异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存工艺路线图形数据异常");
                }
                return await Task.FromResult(result);
            }
 
            /// <summary>
            /// 删除工艺路线
            /// </summary>
            /// <param name="routeId"></param>
            /// <returns></returns>
            public async Task<ApiAction> DeleteRoute(string routeId) {
                var result = new ApiAction();
                try
                {
                    //查询是否已经有工单在用或者有绑定产品
 
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        db.Deleteable<MES_ROUTE_NODE>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand();
                        db.Deleteable<MES_ROUTE_EDGE>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand();
                        db.Deleteable<MES_ROUTE_NODE_ACT>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand();
                        db.Deleteable<MES_ROUTE>().Where(x => x.ID == routeId).ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"删除工艺路线异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "删除工艺路线异常");
                }
                return await Task.FromResult(result);
            }
        }
    }
}