服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-04-15 c00956f6649cc13b094ec83cc3121e7cb0027b3c
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
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;
using static Tiger.Business.Biz;
 
namespace Tiger.Business
{
    public partial class Biz
    {
        /// <summary>
        /// SN操作
        /// </summary>
        public partial class MqSNData : IMqSNData
        {
            /// <summary>
            /// 退回删除条码
            /// </summary>
            /// <param name="barcode"></param>
            /// <returns></returns>
            public async Task<ApiAction> ReturnSN(string barcode)
            {
                var result = new ApiAction();
                try
                {
                    SNData_His data_His = await Db.Queryable<SNData_His>().Where(x => x.OriginalSN == barcode).FirstAsync();
                    if (data_His == null)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"退回删除条码不存在";
                        return result;
                    }
                    List<SNData> sndatas = await Db.Queryable<SNData>().Where(x => x.SN == barcode || x.SN == data_His.SN).ToListAsync();
                    if (sndatas == null && sndatas.Count>0)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"退回删除条码不存在";
                        return result;
                    }
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        db.Deleteable(data_His).ExecuteCommand();
                        db.Deleteable(sndatas).ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false; 
                        result.Message = $"退回删除条码异常";
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "退回删除条码异常");
                }
                return result;
            }
 
            /// <summary>
            /// 分页
            /// </summary>
            /// <param name="pageList"></param>
            /// <returns></returns>
            public async Task<ApiAction<PageAble<SNData_His>>> GetSNDataHis(PageAble<SNData_His> pageList)
            {
                var res = new ApiAction<PageAble<SNData_His>>();
                try
                {
                    string[] strTime = pageList.sqlcmd?.Split(',');
                    RefAsync<int> total = 0;
                    pageList.data = await Db.Queryable<SNData_His>()
                        .WhereIF(!string.IsNullOrEmpty(strTime[0]), x => Convert.ToDateTime(x.ScanTime) > Convert.ToDateTime(strTime[0]))
                        .WhereIF(!string.IsNullOrEmpty(strTime[1]) && strTime.Length == 2, x => Convert.ToDateTime(x.ScanTime) < Convert.ToDateTime(strTime[1]))
                        .WhereIF(!string.IsNullOrEmpty(strTime[2]), x => x.ModelCode.Equals(strTime[2]))
                        .WhereIF(!string.IsNullOrEmpty(strTime[3]), x => x.CustomerCode.Equals(strTime[3]))
                        .ToPageListAsync(pageList.pageIndex, pageList.pageSize, total);
                    pageList.totals = total;
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "查询异常");
                }
                res.Data = pageList;
                return res;
            }
 
            /// <summary>
            /// 获取所有条码,原厂条码和客户条码在同一行,按条件
            /// </summary>
            /// <param name="where"></param>
            /// <returns></returns>
            public async Task<ApiAction<List<SNData_His>>> GetAllSNDataHis(SNDataWhere where)
            {
                var res = new ApiAction<List<SNData_His>>();
                List<SNData_His> list = new List<SNData_His>();
                try
                {
                    DateTime StartTime = DateTime.Now;
                    DateTime EndTime = DateTime.Now;
                    string[] strTime = where.strStartEnd?.Split(',');
                    if (!string.IsNullOrEmpty(where.strStartEnd)) { StartTime = Convert.ToDateTime(strTime[0].ToString()); EndTime = strTime.Length == 2 ? Convert.ToDateTime(strTime[1].ToString()) : DateTime.MinValue; }
                    RefAsync<int> total = 0;
                    list = await Db.Queryable<SNData_His>()
                        .WhereIF(!string.IsNullOrEmpty(where.strStartEnd), x => Convert.ToDateTime(x.ScanTime) > StartTime)
                        .WhereIF(!string.IsNullOrEmpty(where.strStartEnd) && strTime.Length == 2, x => Convert.ToDateTime(x.ScanTime) < EndTime)
                        .WhereIF(!string.IsNullOrEmpty(where.model), x => x.ModelCode == where.model)
                        .WhereIF(!string.IsNullOrEmpty(where.customerCode), x => x.CustomerCode.Equals(where.customerCode))
                        .ToListAsync();
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "查询异常");
                }
                res.Data = list;
                return res;
            }
 
            /// <summary>
            /// 获取所有条码,原厂条码和客户条码分开两行,按条件
            /// </summary>
            /// <param name="where"></param>
            /// <returns></returns>
            public async Task<ApiAction<List<SNData>>> GetAllSNData(SNDataWhere where)
            {
                var res = new ApiAction<List<SNData>>();
                List<SNData> list = new List<SNData>();
                try
                {
                    DateTime StartTime = DateTime.Now;
                    DateTime EndTime = DateTime.Now;
                    string[] strTime = where.strStartEnd?.Split(',');
                    if (!string.IsNullOrEmpty(where.strStartEnd)) { StartTime = Convert.ToDateTime(strTime[0].ToString()); EndTime = strTime.Length == 2 ? Convert.ToDateTime(strTime[1].ToString()) : DateTime.MinValue; }
                    RefAsync<int> total = 0;
                    list = await Db.Queryable<SNData>()
                        .WhereIF(!string.IsNullOrEmpty(where.strStartEnd), x => Convert.ToDateTime(x.CREATE_TIME) > StartTime)
                        .WhereIF(!string.IsNullOrEmpty(where.strStartEnd) && strTime.Length == 2, x => Convert.ToDateTime(x.CREATE_TIME) < EndTime)
                        .WhereIF(!string.IsNullOrEmpty(where.model), x => x.ItemCode == where.model)
                        .WhereIF(!string.IsNullOrEmpty(where.customerCode), x => x.CustomerCode.Equals(where.customerCode))
                        .ToListAsync();
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "查询异常");
                }
                res.Data = list;
                return res;
            }
        }
    }
}