chengsc
2025-03-28 e00c9e03eeaffad919cf16c95b2d6048e8abfb9d
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.ModelDto.LogDto;
using SqlSugar;
using WMS.DAL;
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
 
namespace WMS.BLL.LogServer
{
    public class OperationASNServer:DbHelper<LogOperationASN>, IOperationASNServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public OperationASNServer():base(Db)
        { 
        }
        public List<OperationDto> GetLogOperationAsnList(string menuName, string type, string msg, string startTime, string endTime, int page, int limit, out int count)
        {
            try
            {
                var item = Expressionable.Create<LogOperationASN>()
                    .AndIF(!string.IsNullOrWhiteSpace(menuName), it => it.MenuName.Contains(menuName.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .AndIF(!string.IsNullOrWhiteSpace(msg), it => it.Msg.Contains(msg.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(startTime), it => it.CreateTime >= Convert.ToDateTime(startTime))
                    .AndIF(!string.IsNullOrWhiteSpace(endTime), it => it.CreateTime <= Convert.ToDateTime(endTime).AddDays(1))
                    .ToExpression();//注意 这一句 不能少
                var total = 0;
                var list = GetAllWhereAsync(item)
                    .LeftJoin<SysDictionary>((it, dic) => it.Type == dic.Id.ToString())
                    .LeftJoin<SysUserInfor>((it, dic, users) => it.CreateUser == users.Id)
                    .Select((it, dic, users) => new OperationDto()
                    {
                        Id = it.Id,
                        ParentNo = it.ParentNo,
                        MenuNo = it.MenuNo,
                        MenuName = it.MenuName,
                        FkNo = it.FkNo,
                        Type = dic.DictName,
                        Msg = it.Msg,
                        CreateTime = it.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        CreateUserName = users.RealName,
                    })
                    .OrderByDescending(it => it.CreateTime)
                    .ToOffsetPage(page, limit, ref total);
 
                count = total;
                return list.OrderByDescending(m=>m.CreateTime).ToList();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public bool AddLogOperationAsn(string parentNo, string menuName, string fkNo, string type, string msg, int userId)
        {
            try
            {
                var menu = Db.Queryable<SysFunctionMenu>().Where(m => m.IsDel == "0").ToList();
                var dic = Db.Queryable<SysDictionary>().Where(m => m.ParentNo == "LogType" && m.IsDel == "0").ToList();
                var typeId = dic.FirstOrDefault(m => m.DictName == type);
                var s = msg.Length;
                var n = Add(new LogOperationASN()
                {
                    ParentNo = menu.FirstOrDefault(m => m.MenuName == parentNo) == null ? "" : menu.First(m => m.MenuName == parentNo).MenuNo,
                    MenuNo = menu.FirstOrDefault(m => m.MenuName == menuName) == null ? "" : menu.First(m => m.MenuName == menuName).MenuNo,
                    MenuName = $"{parentNo}-{menuName}",
                    FkNo = fkNo,
                    Type = typeId == null ? "" : typeId.Id.ToString(),
                    Msg = msg,
 
                    CreateUser = userId
                });
                return n > 0;
 
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool AddLogOperationPdaAsn(string parentNo, string menuName, string fkNo, string type, string msg, int userId,string model,string kuai)
        {
            try
            {
                var menu = Db.Queryable<SysFunctionMenu>().Where(m => m.IsDel == "0").ToList();
                var dic = Db.Queryable<SysDictionary>().Where(m => m.ParentNo == "LogType" && m.IsDel == "0").ToList();
                var typeId = dic.FirstOrDefault(m => m.DictName == type);
                var s = msg.Length;
                var n = Add(new LogOperationASN()
                {
                    ParentNo = menu.FirstOrDefault(m => m.MenuName == parentNo) == null ? "" : menu.First(m => m.MenuName == parentNo).MenuNo,
                    MenuNo = menu.FirstOrDefault(m => m.MenuName == menuName) == null ? "" : menu.First(m => m.MenuName == menuName).MenuNo,
                    MenuName = $"{parentNo}-{menuName}",
                    FkNo = fkNo,
                    Type = typeId == null ? "" : typeId.Id.ToString(),
                    Msg = msg,
 
                    CreateUser = userId
                });
                return n > 0;
 
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        #region 数据归档
        /// <summary>
        /// 获取操作记录
        /// </summary>
        /// <returns></returns>
        public List<OperationDto> GetArchivingLogOperationList(string comeFrom, string menuName, string type, string msg, string startTime, string endTime, int page, int limit, out int count)
        {
            try
            {
                string sqlString = string.Empty;
                string sqlCount = string.Empty;
                string sqlPub = string.Empty;
                if (string.IsNullOrEmpty(comeFrom))
                {
                    comeFrom = "0";
                }
                string tableName = string.Empty;
                if (comeFrom == "0")
                {
                    tableName = "ArchivingOperationSys";
                }
                else if (comeFrom == "1")
                {
                    tableName = "ArchivingOperationASN";
                }
                else if (comeFrom == "2")
                {
                    tableName = "ArchivingOperationSo";
                }
                else if (comeFrom == "3")
                {
                    tableName = "ArchivingOperationCr";
                }
                sqlCount += $"SELECT COUNT(tb1.ID) FROM {tableName} AS tb1 ";
                sqlString += $"select tb1.Id,tb1.ParentNo,tb1.MenuNo,tb1.MenuName,tb1.FkNo,tb1.Msg,tb1.CreateTime ,tb2.DictName as Type,tb3.RealName as CreateUserName from {tableName} as tb1 ";
                sqlPub += "left join SysDictionary as tb2 on tb1.Type=tb2.Id ";
                sqlPub += "left join SysUserInfor as tb3 on tb1.CreateUser=tb3.Id ";
                sqlPub += $"where tb1.IsDel = '0'";
                if (!string.IsNullOrEmpty(menuName))
                {
                    sqlPub += $"AND tb1.MenuName like '%{menuName.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(type))
                {
                    sqlPub += $"AND tb1.Type = {int.Parse(type)} ";
                }
                if (!string.IsNullOrEmpty(msg))
                {
                    sqlPub += $"AND tb1.Msg like '%{msg.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(startTime))
                {
                    sqlPub += $"AND tb1.CreateTime >= '{Convert.ToDateTime(startTime)}' ";
                }
                if (!string.IsNullOrEmpty(endTime))
                {
                    sqlPub += $"AND tb1.CreateTime <= '{Convert.ToDateTime(endTime)}' ";
                }
                sqlCount += sqlPub;
                sqlPub += " order by tb1.CreateTime desc ";
                if (page == 0)
                {
                    page = 1;
                }
                sqlString += sqlPub + $" offset {((page - 1) * limit)} rows fetch next {limit} rows only;";
 
                var com = new Common();
                count = com.GetRowCount(sqlCount);
 
                var modelList = Db.Ado.SqlQuery<OperationDto>(sqlString);
 
                return modelList;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        #endregion
    }
}