服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-04-12 964a430c977cfc2f539d6b7fab6161827fdd71db
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
using Rhea.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using Tiger.Model;
 
namespace Tiger.Business
{
    public partial class Biz
    {
        /// <summary>
        /// 客户
        /// </summary>
        public partial class MqModelInfo : IModelInfo
        {
            /// <summary>
            /// 获取分页
            /// </summary>
            /// <param name="pageList"></param>
            /// <returns></returns>
            public async Task<ApiAction<PageAble<ModelInfo>>> GetModelInfo(PageAble<ModelInfo> pageList)
            {
                var res = new ApiAction<PageAble<ModelInfo>>();
                try
                {
                    RefAsync<int> total = 0;
                    pageList.data = await Db.Queryable<ModelInfo>().WhereIF(!string.IsNullOrEmpty(pageList.sqlcmd), x => x.Model.Contains(pageList.sqlcmd)).OrderBy(x=>x.Model).ToPageListAsync(pageList.pageIndex, pageList.pageSize, total);
                    pageList.totals = total;
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "获取产品信息异常");
                }
                res.Data = pageList;
                return res;
            }
 
            /// <summary>
            /// 导入
            /// </summary>
            /// <param name="list"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveImportModelInfo(List<ModelInfo> list)
            {
                var res = new ApiAction();
                //更新机型记录
                var db = Db;
                var dbTran = await db.UseTranAsync(async () =>
                {
                    await db.Saveable(list).ExecuteCommandAsync();
                });
                if (!dbTran.IsSuccess)
                {
                    res.IsSuccessed = false;
                    res.Message = $"导入异常";
                }
                return res;
            }
 
            /// <summary>
            /// 保存机型
            /// </summary>
            /// <param name="user"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveModel(ModelInfo modelInfo)
            {
                var result = new ApiAction();
                try
                {
 
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(modelInfo)
                           .WhereColumns(t => new { t.Model })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"导入异常";
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存机型异常");
                }
                return result;
            }
        }
    }
}