kyy
3 天以前 bd18a149bfd83807d7cbcf80a2384ef502184a96
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using Gs.Toolbox;
using Gs.Toolbox.ApiCore.Abstract.Mvc;
using Gs.Toolbox.ApiCore.Common.Mvc;
using Gs.Toolbox.ApiCore.Group;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Gs.Toolbox.UtilityHelper;
 
namespace Gs.Sys.Services
{
 
    [ApiGroup(ApiGroupNames.FM)]
    public class FmController : IRomteService
    {
        private readonly IHttpContextAccessor _http;
        private readonly string _userCode, _userGuid, _orgFids;
 
        public FmController(IHttpContextAccessor httpContextAccessor)
        {
            _http = httpContextAccessor;
            (_userCode, _userGuid, _orgFids) =
                GetUserGuidAndOrgGuid(_http);
        }
 
        #region 版面
        /// <summary>
        ///     增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> EditModel([FromBody] dynamic model)
        {
            string applyUserGuid = "";
            string formPath = model.formPath;
            int intType = model.intType;
            dynamic m = new ExpandoObject();
            m.outMsg = "";
            Hashtable SQLStringList = new Hashtable();
            string _groupGuid = Guid.NewGuid().ToString();
            //只有超级管理员权限
            if (intType == 1 || intType == 3)
            {
                int? isAdmin = 0;
                try
                {
                    isAdmin = chkAdmin();
                    if (isAdmin <= 0)
                    {
                        m.outMsg = "你不是管理员,操作失败!";
                        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "操作成功!");
                    }
                }
                catch (Exception ex)
                {
                    Gs.Toolbox.LogHelper.Debug(this.ToString(), "EditModel isAdmin error:" + ex.Message);
                }
            }
            //保存标准版
            if (intType == 1)
            {
                applyUserGuid = null;
                Gs.Toolbox.DbHelperSQL.ExecuteSql("delete from [FM_LAYOUT] where groupGuid<>'" + _groupGuid + "' and [formPath]=@formPath and applyUserGuid is null", new SqlParameter[] { new SqlParameter("@formPath", formPath) });
                // SQLStringList.Add("delete from [FM_LAYOUT] where groupGuid<>'" + _groupGuid + "' and [formPath]=@formPath and applyUserGuid is null", new SqlParameter[] { new SqlParameter("@formPath", formPath) });
            }
            //保存个人版本
            if (intType == 2)
            {
                applyUserGuid = _userGuid;
                Gs.Toolbox.DbHelperSQL.ExecuteSql("delete from [FM_LAYOUT] where  groupGuid<>'" + _groupGuid + "' and [formPath]=@formPath and applyUserGuid =@applyUserGuid", new SqlParameter[] { new SqlParameter("@formPath", formPath), new SqlParameter("@applyUserGuid", applyUserGuid) });
                //SQLStringList.Add("delete from [FM_LAYOUT] where  groupGuid<>'" + _groupGuid + "' and [formPath]=@formPath and applyUserGuid =@applyUserGuid", new SqlParameter[] { new SqlParameter("@formPath", formPath), new SqlParameter("@applyUserGuid", applyUserGuid) });
            }
            //清空标准版本
            if (intType == 3)
            {
                applyUserGuid = null;
                SQLStringList.Add("delete from [FM_LAYOUT] where [formPath]=@formPath and applyUserGuid is null", new SqlParameter[] { new SqlParameter("@formPath", formPath) });
                Gs.Toolbox.DbHelperSQL.ExecuteSqlTranRtn(SQLStringList);
                m.outMsg = "清空标准版配置成功!";
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "操作成功!");
            }
            //清空个人版本
            if (intType == 4)
            {
                applyUserGuid = _userGuid;
                SQLStringList.Add("delete from [FM_LAYOUT] where [formPath]=@formPath and applyUserGuid =@applyUserGuid", new SqlParameter[] { new SqlParameter("@formPath", formPath), new SqlParameter("@applyUserGuid", applyUserGuid) });
                Gs.Toolbox.DbHelperSQL.ExecuteSqlTranRtn(SQLStringList);
                m.outMsg = "清空个人版配置成功!";
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "操作成功!");
            }
            //这是所有的gridview,lay xml
            JArray jArray = model.xmlList;
            try
            {
                foreach (var jsonitem in jArray)
                {
                    JObject job = (JObject)jsonitem;
                    if (job["idName"] != null)
                    {
                        string idName = job["idName"].ToString();
                        string idXml = job["idXml"].ToString();
                        string idType = job["idType"].ToString();
                        string _splitterPosition = job["splitterPosition"].ToString();
                        string splitterPosition = string.IsNullOrEmpty(_splitterPosition) ? "0" : _splitterPosition;
                        System.Text.StringBuilder _sql = new System.Text.StringBuilder();
                        _sql.Append(" INSERT INTO [dbo].[FM_LAYOUT] ([guid] ,[applyUserGuid] ,[formPath] ,[controlId],[controlHeight],[lastUpdateBy],[lastUpdateDate],controlXml,controlType,groupGuid,splitterPosition)");
                        _sql.Append("values(newid(),@applyUserGuid,@formPath,@controlId,@controlHeight,@lastUpdateBy,getdate(),@controlXml,'" + idType + "','" + _groupGuid + "'," + splitterPosition + ")");
                        SQLStringList.Add(_sql, new SqlParameter[] {
                            new SqlParameter("@formPath", formPath)
                            , new SqlParameter("@controlId", idName)
                             , new SqlParameter("@controlHeight", "0")
                             , new SqlParameter("@lastUpdateBy", _userCode)
                             , new SqlParameter("@applyUserGuid", applyUserGuid)
                             , new SqlParameter("@controlXml", idXml)
                        });
                    }
                }
                Gs.Toolbox.DbHelperSQL.ExecuteSqlTranRtn(SQLStringList);
                m.outMsg = "保存" + (intType == 1 ? "标准版" : "个人版") + "配置成功!";
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "操作成功!");
            }
            catch (Exception ex)
            {
                m.outMsg = "操作失败:" + ex.Message;
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "EditModel error:" + ex.Message);
            }
            //这是所有的
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "操作成功!");
        }
 
 
        /// <summary>
        ///     读取
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> GetModel([FromBody] dynamic model)
        {
            string formPath = model.formPath.ToString();
            dynamic m = new ExpandoObject();
            m.list = new List<dynamic>();
            m.list2 = new List<dynamic>();
            SqlParameter[] parameters =
            {
                new("@formPath", formPath),
                new("@userGuid", _userGuid),
            };
            var dset = new DataSet();
            try
            {
                dset = DbHelperSQL.RunProcedure("[fm_get_layout]", parameters, "0");
                if (dset != null && dset.Tables.Count > 0
                 )
                {
                    var _tb = dset.Tables[0].TableToDynamicList();
                    m.list = _tb;
                    var _tb2 = dset.Tables[1].TableToDynamicList();
                    m.list2 = _tb2;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message);
            }
            if (m != null)
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success,
                    "读取成功!");
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default,
                "读取失败!");
        }
 
 
        /// <summary>
        ///     读取
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<string> GetModelByVersion([FromBody] dynamic model)
        {
            string formPath = model.formPath.ToString();
            string strMsg = "";
            SqlParameter[] parameters =
            {
                new("@formPath", formPath),
                new("@userGuid", _userGuid),
            };
            var dset = new DataSet();
            try
            {
                dset = DbHelperSQL.RunProcedure("[fm_get_layout_ver]", parameters, "0");
                if (dset != null && dset.Tables.Count > 0
                 )
                {
                    strMsg = dset.Tables[0].Rows[0][0].ToString();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message + ",formPath:" + formPath + ",_userGuid:" + _userGuid);
 
            }
            return ReturnDto<string>.QuickReturn(strMsg, ReturnCode.Success, "读取成功!");
        }
 
 
        #endregion
 
        private int? chkAdmin()
        {
            int? isAdmin = 0;
            System.Text.StringBuilder _sb = new System.Text.StringBuilder();
            _sb.Append("select count(1) from [dbo].[SYS_USER] where GUID='" + _userGuid + "' and  IS_SYS=1");
            object _obj = Gs.Toolbox.DbHelperSQL.GetSingle(_sb.ToString());
            if (_obj == null)
            {
                isAdmin = 0;
            }
            else
                isAdmin = Gs.Toolbox.UtilityHelper.ToInt(_obj.ToString());
            return isAdmin;
        }
 
        /*       #region 发送erp新版本
 
               /// <summary>
               /// 
               /// </summary>
               /// <param name="model">keyType:1审核,0反审核</param>
               /// <returns></returns>
               [RequestMethod(RequestMethods.POST)]
               public string SendErp([FromBody] dynamic model)
               {
                   //string keyGuid = model.keyGuid; 原生主键
                   //string keyUserGuid = model.keyUserGuid;操作用户
                   //string keyProduce = model.keyProduce;存储过程名
                   //string keyTaskName = model.keyTaskName;任务名
                   //string keyChild = model.keyChild;任务子节点名
                   //string keyMeth = model.keyMeth;方法名
                   //string keyNo = model.keyNo;单据编号
                   int _rtnInt = 0;
                   string _rtnStr = "";
                   try
                   {
                       string _erpJson = GetErpParam(model);
                       if (_erpJson.Length <= 0)
                           return "-1读取erp参数失败!";
                       string keyUserGuid = model.keyUserGuid;
                       string keyGuid = model.keyGuid;
                       string keyNo = model.keyNo;
                       string idtype = model.idtype;//2仅仅是更新工单状态的时候有
 
                       if (keyGuid.Length != 36)
                           keyGuid = "00000000-0000-0000-0000-000000000000";
                       if (string.IsNullOrEmpty(idtype))
                           (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo);
                       else
                           (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 2);
                   }
                   catch (Exception ex)
                   {
                       Gs.Toolbox.LogHelper.Debug(this.ToString(), "Fm SendErp:" + ex.Message);
                       return "发送erp失败:" + ex.Message;
                   }
                   if (_rtnInt <= 0)
                   {
                       return "发送erp失败:" + _rtnStr;
                   }
                   return _rtnStr;
               }
 
               /// <summary>
               /// 构建erp参数
               /// </summary>
               /// <param name="model"></param>
               /// <returns></returns>
               private string GetErpParam(dynamic model)
               {
                   string keyGuid = model.keyGuid;
                   string keyUserGuid = model.keyUserGuid;
                   string keyProduce = model.keyProduce;
                   string keyTaskName = model.keyTaskName;
                   string keyChild = model.keyChild;
                   string keyMeth = model.keyMeth;
                   string keyNo = model.keyNo;
                   string idtype = model.idtype;//这个仅仅是更新工单状态的时候有
 
                   if (keyMeth.ToUpper() == "delete".ToUpper())
                       return "";
                   try
                   {
                       System.Data.DataSet dset = new System.Data.DataSet();
                       SqlParameter[] parameters =
                             {
                              new("@inOrderGuid", keyGuid),
                              new("@inEdtUserGuid", keyUserGuid),
                              new("@keyMeth", keyMeth.ToLower()),
                          };
                       dset = DbHelperSQL.RunProcedure(keyProduce, parameters, "0");
                       if (dset == null)
                           return "";
                       if (dset.Tables.Count <= 0)
                           return "";
                       if (dset.Tables[0].Rows.Count <= 0)
                           return "";
                       //这是普通的接口
                       if (string.IsNullOrEmpty(idtype))
                       {
                           string _mesGuid = dset.Tables[0].Rows[0][0].ToString();
                           dynamic _datajson = new ExpandoObject();
                           if (dset.Tables.Count > 1)
                           {
                               //这是这是普通的接口里的结案,结构和其它不一样
                               if (keyMeth.ToLower() == "toclose".ToLower() || keyMeth.ToLower() == "closure".ToLower() || keyMeth.ToLower() == "unfinish")
                               {
                                   _datajson = dset.Tables[1].Rows[0].RowToDynamic();
                               }
                               else
                               {
                                   _datajson = dset.Tables[0].Rows[0].RowToDynamic();
                                   List<dynamic> _lst = dset.Tables[1].TableToDynamicList();
                                   ((IDictionary<string, object>)_datajson)[keyChild] = _lst;
                               }
                           }
                           var _obj = new
                           {
                               mesid = _mesGuid,
                               taskname = keyTaskName,
                               optype = keyMeth,
                               datajson = JsonConvert.SerializeObject(_datajson),
                           };
                           return JsonConvert.SerializeObject(_obj);
                       }
                       //这是订单回传标识
                       List<dynamic> _datajson22 = new List<dynamic>();
                       dynamic _ob = new ExpandoObject();
                       _ob.ENTRY = dset.Tables[0].TableToDynamicList();
                       _datajson22.Add(_ob);
                       var _obj22 = new
                       {
                           taskname = keyTaskName,
                           idtype = idtype,
                           datajson = JsonConvert.SerializeObject(_datajson22),
                       };
                       return JsonConvert.SerializeObject(_obj22);
                   }
                   catch (Exception ex)
                   {
                       Gs.Toolbox.LogHelper.Debug(this.ToString(), ex.Message);
                       throw ex;
                   }
               }
               #endregion
       */
 
        #region 发送erp新版本
 
        /// <summary>
        /// 发送数据到ERP系统
        /// </summary>
        /// <param name="model">包含以下字段的动态对象:
        /// - keyGuid: 原生主键
        /// - keyUserGuid: 操作用户GUID
        /// - keyProduce: 存储过程名
        /// - keyTaskName: 任务名
        /// - keyChild: 任务子节点名
        /// - keyMeth: 方法名(如add、update、delete、toclose等)
        /// - keyNo: 单据编号
        /// - keyUrl: 接口地址
        /// - idtype: 特殊操作类型标识(如工单状态更新)
        /// - keyType: 操作类型(1=审核,0=反审核)
        /// </param>
        /// <returns>成功返回ERP响应消息,失败返回错误描述</returns>
        /// <remarks>
        /// 将MES数据打包成ERP载荷并根据请求的操作类型推送
        /// 通过存储过程转换业务数据,调用InterfaceUtil推送到ERP
        /// </remarks>
        [RequestMethod(RequestMethods.POST)]
        public string SendErp([FromBody] dynamic model)
        {
            int _rtnInt = 0;
            string _rtnStr = "";
            try
            {
                // 构建ERP请求参数
                string _erpJson = GetErpParam(model);
                if (_erpJson.Length <= 0)
                    return "-1读取erp参数失败!";
                string keyUserGuid = model.keyUserGuid;
                string keyGuid = model.keyGuid;
                string keyNo = model.keyNo;
                string idtype = model.idtype; // 仅在更新工单状态时使用
                string keyUrl = model.keyUrl;
                if (string.IsNullOrEmpty(idtype))
                {
                    // 常规接口:按操作类型推送单条业务数据
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson,
                        keyUserGuid, keyGuid, keyNo, 0, keyUrl);
                }
                else
                {
                    // 带idtype的请求用于特殊流程(如关闭、反关闭),ERP需要额外的状态标记
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson,
                        keyUserGuid, keyGuid, keyNo, 2, keyUrl);
                }
            }
            catch (Exception ex)
            {
                // 记录ERP数据转换异常,便于定位存储过程或序列化问题
                Gs.Toolbox.LogHelper.Debug(this.ToString(),
                    "Fm SendErp:" + ex.Message);
                return "发送erp失败:" + ex.Message;
            }
 
            if (_rtnInt <= 0)
            {
                return "发送erp失败:" + _rtnStr;
            }
 
            return _rtnStr;
        }
 
        /// <summary>
        /// 构建ERP参数(内部方法)
        /// </summary>
        /// <param name="model">包含业务参数的动态对象</param>
        /// <returns>JSON格式的ERP参数字符串</returns>
        /// <remarks>
        /// 调用业务定义的存储过程将MES数据打包给ERP
        /// 根据keyMeth(操作方法)和idtype决定返回数据结构
        /// </remarks>
        private string GetErpParam(dynamic model)
        {
            string keyGuid = model.keyGuid;
            string keyUserGuid = model.keyUserGuid;
            string keyProduce = model.keyProduce;
            string keyTaskName = model.keyTaskName;
            string keyChild = model.keyChild;
            string keyMeth = model.keyMeth;
            string keyNo = model.keyNo;
            string idtype = model.idtype; // 仅在更新工单状态时使用
            if (keyMeth.ToUpper() == "delete".ToUpper())
                // 删除操作无需向ERP推送数据,只需返回空串
                return "";
            try
            {
                System.Data.DataSet dset = new System.Data.DataSet();
                SqlParameter[] parameters =
                {
                    new("@inOrderGuid", keyGuid),
                    new("@inEdtUserGuid", keyUserGuid),
                    new("@keyMeth", keyMeth.ToLower()),
                };
                // 调用业务定义的存储过程,将MES数据打包给ERP
                dset = DbHelperSQL.RunProcedure(keyProduce, parameters, "0");
                if (dset == null)
                    return "";
                if (dset.Tables.Count <= 0)
                    return "";
                if (dset.Tables[0].Rows.Count <= 0)
                    return "";
                // 常规接口处理逻辑
                if (string.IsNullOrEmpty(idtype))
                {
                    // 常规出参:第一张表是主数据,第二张表(若存在)是子表集合
                    string _mesGuid = dset.Tables[0].Rows[0][0].ToString();
                    dynamic _datajson = new ExpandoObject();
                    if (dset.Tables.Count > 1)
                    {
                        // 多表返回时,需要把子表集合挂到datajson中
                        // 结案操作的结构与其他不一样,特殊处理
                        if (keyMeth.ToLower() == "toclose".ToLower() ||
                            keyMeth.ToLower() == "closure".ToLower() ||
                            keyMeth.ToLower() == "unfinish")
                        {
                            _datajson = dset.Tables[1].Rows[0].RowToDynamic();
                        }
                        else
                        {
                            _datajson = dset.Tables[0].Rows[0].RowToDynamic();
                            List<dynamic> _lst =
                                dset.Tables[1].TableToDynamicList();
                            ((IDictionary<string, object>)_datajson)[keyChild] =
                                _lst;
                        }
                    }
                    else if (dset.Tables.Count == 1)
                    {
                        _datajson = dset.Tables[0].Rows[0].RowToDynamic();
                    }
 
                    // var _obj = new
                    // {
                    //     mesid = _mesGuid,
                    //     taskname = keyTaskName,
                    //     optype = keyMeth,
                    //     datajson = JsonConvert.SerializeObject(_datajson),
                    // };
                    // return JsonConvert.SerializeObject(_obj);
                    return JsonConvert.SerializeObject(_datajson);
                }
 
                // 订单回传标识处理逻辑(带idtype)
                List<dynamic> _datajson22 = new List<dynamic>();
                dynamic _ob = new ExpandoObject();
                _ob.ENTRY = dset.Tables[0].TableToDynamicList();
                _datajson22.Add(_ob);
                // var _obj22 = new
                // {
                //     taskname = keyTaskName,
                //     idtype = idtype,
                //     datajson = JsonConvert.SerializeObject(_datajson22),
                // };
                // return JsonConvert.SerializeObject(_obj22);
                return JsonConvert.SerializeObject(_datajson22);
            }
            catch (Exception ex)
            {
                // 记录ERP数据转换异常,便于定位存储过程或序列化问题
                Gs.Toolbox.LogHelper.Debug(this.ToString(), ex.Message);
                throw ex;
            }
        }
 
        #endregion
 
 
        #region 查询
 
        /// <summary>
        /// 读取
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> GetQuery([FromBody] dynamic model)
        {
            dynamic m = new ExpandoObject();
            m.list = new List<dynamic>();
            m.list2 = new List<dynamic>();
            m.list3 = new List<dynamic>();
            m.list4 = new List<dynamic>();
            var _split = "|";
            string formPath = model.formPath.ToString();
            System.Text.StringBuilder _sb = new System.Text.StringBuilder();
            foreach (var _obj in model.list)
            {
                var _line =
                     _obj.colName + _split
                    + _obj.colCap + _split
                   ;
                if (_sb.Length > 0)
                    _sb.Append("~");
                _sb.Append(_line);
            }
            ;
            var lst = new List<dynamic>();
            SqlParameter[] parameters =
            {
                new("@formPath", formPath),
                new("@colArray", _sb.ToString()),
            };
            var dset = new DataSet();
            try
            {
                dset = DbHelperSQL.RunProcedure("[fm_set_query]", parameters, "0");
                if (dset != null && dset.Tables.Count > 0)
                {
                    m.list = dset.Tables[0].TableToDynamicList();
                    m.list2 = dset.Tables[1].TableToDynamicList();
                    m.list3 = dset.Tables[2].TableToDynamicList();
                    m.list4 = dset.Tables[3].TableToDynamicList();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message);
            }
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
        }
 
        /// <summary>
        /// 编辑表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> EditQuery([FromBody] dynamic model)
        {
            dynamic m = new ExpandoObject();
            m.outMsg = "";
            string formPath = model.formPath;
            ArrayList arrayList = new ArrayList();
            string _groupGuid = Guid.NewGuid().ToString();
            int? isAdmin = 0;
            try
            {
                isAdmin = chkAdmin();
                if (isAdmin <= 0)
                {
                    m.outMsg = "你不是管理员,操作失败!";
                    return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "操作成功!");
                }
            }
            catch (Exception ex)
            {
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "EditModel isAdmin error:" + ex.Message);
            }
            try
            {
                Gs.Toolbox.DbHelperSQL.ExecuteSql("delete from [FM_QUERY_TABLE] where formPath=@formPath ", new SqlParameter[] { new SqlParameter("@formPath", formPath) });
                foreach (var _obj in model.list)
                {
                    System.Text.StringBuilder _sb = new System.Text.StringBuilder();
                    _sb.Append("INSERT INTO [dbo].[FM_QUERY_TABLE]([guid],[formPath] ,[tableName] ,[lastUpdateBy] ,[lastUpdateDate],[tableOtherName])");
                    _sb.Append(" values(newid(),'" + formPath + "','" + _obj.tableName + "','',getdate(),'" + _obj.tableOtherName + "')");
                    arrayList.Add(_sb.ToString());
                }
                Gs.Toolbox.DbHelperSQL.ExecuteSqlTran(arrayList);
            }
            catch (Exception ex)
            {
                m.outMsg = ex.Message;
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, ex.Message);
            }
            m.outMsg = "操作成功!";
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "操作成功!");
        }
 
        /// <summary>
        ///   删除表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> DeleteQuery([FromBody] dynamic model)
        {
            int? rtnInt = (int)ReturnCode.Default;
            int? isAdmin = 0;
            try
            {
                isAdmin = chkAdmin();
                if (isAdmin <= 0)
                {
                    return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Default, "你不是管理员,操作失败!");
                }
            }
            catch (Exception ex)
            {
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "EditModel isAdmin error:" + ex.Message);
            }
            Guid? guid = model.guid;
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            stringBuilder.Append("delete from FM_QUERY_TABLE where guid='" + guid + "'");
            rtnInt = Gs.Toolbox.DbHelperSQL.ExecuteSql(stringBuilder.ToString());
            if (rtnInt <= 0)
                return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "操作失败!");
            return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "操作成功!");
        }
 
        /// <summary>
        ///   编辑列
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> EditCol([FromBody] dynamic model)
        {
            int? rtnInt = (int)ReturnCode.Default;
            int? isAdmin = 0;
            try
            {
                isAdmin = chkAdmin();
                if (isAdmin <= 0)
                {
                    return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Default, "你不是管理员,操作失败!");
                }
            }
            catch (Exception ex)
            {
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "EditModel isAdmin error:" + ex.Message);
            }
            Guid? guid = model.guid;
            string sqlField = model.sqlField;
            string sqlFieldType = model.sqlFieldType;
            string fType = model.fType;
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            if (fType == "1")
                stringBuilder.Append("update  FM_QUERY set sqlFieldType='" + sqlFieldType + "', lastUpdateDate=getdate() where guid='" + guid + "'");
            else
                stringBuilder.Append("update  FM_QUERY set sqlField='" + sqlField + "', lastUpdateDate=getdate() where guid='" + guid + "'");
            rtnInt = Gs.Toolbox.DbHelperSQL.ExecuteSql(stringBuilder.ToString());
            if (rtnInt <= 0)
                return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "操作成功!");
            return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "操作失败!");
        }
        #endregion
    }
}