bklLiudl
3 天以前 3c280a6e7343a6d4da1d3a5e75d55f5f2adf3196
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Model.ModelDto.LogDto;
using Model.ModelVm.LogVm;
using SqlSugar;
using Utility;
using WMS.DAL;
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
using WMS.IDAL.ILogInterface;
 
namespace WMS.BLL.LogServer
{
    public class OperationSysServer : DbHelper<LogOperationSys>, IOperationSysServer
    {
        private readonly IOperationSysRepository _operation;
        private readonly IMapper _mapper;
        private static readonly SqlSugarScope Db = DataContext.Db;
        private readonly UserManager _userManager;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="operation">日志</param>
        /// <param name="mapper">automapper</param>
        public OperationSysServer(IOperationSysRepository operation, IMapper mapper, UserManager userManager) : base(Db)
        {
            _operation = operation; //日志
            _mapper = mapper; //automapper
            _userManager = userManager;
        }
 
        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="parentNo">模块号</param>
        /// <param name="menuNo">菜单号</param>
        /// <param name="menuName">菜单名称</param>
        /// <param name="fkNo">数据编号</param>
        /// <param name="type">类型 添加 修改 删除 停用 启用</param>
        /// <param name="msg">操作</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<bool> AddOperationSys(string parentNo, string menuNo, string menuName, string fkNo, string type, string msg, int userId)
        {
            try
            {
                var num = await AddAsync(new LogOperationSys()
                {
                    ParentNo = parentNo,
                    MenuNo = menuNo,
                    MenuName = menuName,
                    FkNo = fkNo,
                    Type = type,
                    Msg = msg,
                    CreateUser = userId
                });
                if (num > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
 
        /// <summary>
        /// 获取系统操作日志数据列表
        /// </summary>
        /// <param name="menuName">菜单名称</param>
        /// <param name="type">操作类型</param>
        /// <param name="msg">操作内容</param>
        /// <param name="menuNo">菜单号</param>
        /// <param name="parentNo">模块号</param>
        /// <returns></returns>
        public async Task<SqlSugarPagedList> GetSysOperationList(GetOperationVm model)
        {
            return await Db.Queryable<LogOperationSys>()
                           .LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id)
                           .LeftJoin<SysFunctionMenu>((a, b, c) => a.ParentNo == c.MenuNo)
                           .LeftJoin<SysDictionary>((a, b, c, d) => SqlFunc.ToInt32(a.Type) == d.Id)
                           .Where(a => a.IsDel == "0")
                           .WhereIF(!string.IsNullOrEmpty(model.MenuName), a => a.MenuName.Contains(model.MenuName))
                           .WhereIF(!string.IsNullOrEmpty(model.Type), a => a.Type == model.Type)
                           .WhereIF(!string.IsNullOrEmpty(model.Msg), a => a.Msg.Contains(model.Msg))
                           .WhereIF(!string.IsNullOrEmpty(model.MenuNo), a => a.MenuNo == model.MenuNo)
                           .Where((a, b, c, d) => a.ParentNo == SqlFunc.Subqueryable<SysFunctionMenu>().Where(e => e.IsDel == "0" && e.MenuName == model.ParentNo).Select(e => e.MenuNo))
                           .Select<OperationDto>((a, b, c, d) => new OperationDto()
                           {
                               Id = a.Id,
                               CreateUserName = b.RealName,
                               TypeName = d.DictName,
                           }, true)
                           .ToPagedListAsync(model.Page, model.Limit);
        }
 
        /// <summary>
        /// 新增系统操作日志
        /// </summary>
        /// <param name="parentName">模块号</param>
        /// <param name="menuName">菜单号</param>
        /// <param name="fkNo">数据编号</param>
        /// <param name="type">操作类型</param>
        /// <param name="msg">操作内容</param>
        /// <param name="createuser">创建人</param>
        /// <returns></returns>
        public async Task<int> InsertOperation(string parentName, string menuName, string fkNo, string type, string msg, int createuser)
        {
            //捕获异常
            try
            {
                var parentNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == parentName && s.IsDel == "0"))?.MenuNo;
                var menuNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == menuName && s.IsDel == "0"))?.MenuNo;
                int i = await _operation.InsertOperation(parentNo, menuNo, parentName + "-" + menuName, fkNo, type, msg, createuser);
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("新增操作日志异常", ex);
            }
        }
        /// <summary>
        /// 新增系统操作日志
        /// </summary>
        /// <param name="parentName">模块号</param>
        /// <param name="menuName">菜单号</param>
        /// <param name="fkNo">数据编号</param>
        /// <param name="type">操作类型</param>
        /// <param name="msg">操作内容</param>
        /// <param name="createuser">创建人</param>
        /// <returns></returns>
        public async Task<int> InsertOperation(OperationInputVm input)
        {
            input.ParentNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == input.ParentName && s.IsDel == "0"))?.MenuNo;
            input.MenuNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == input.MenuName && s.IsDel == "0"))?.MenuNo;
            input.Type = (await Db.Queryable<SysDictionary>().FirstAsync(s => s.DictName == input.TypeName && s.IsDel == "0"))?.Id.ToString();
            input.CreateUser = _userManager.UserId;
            input.CreateTime = DateTime.Now;
            return await Db.Insertable<LogOperationSys>(input).ExecuteCommandAsync();
        }
        /// <summary>
        /// 获取类型菜单
        /// </summary>
        /// <param name="dicName">字典名称</param>
        /// <returns></returns>
        public async Task<List<SysDictionary>> GetDicTypeList(string dicName)
        {
            return await Db.Queryable<SysDictionary>()
                           .Where(s => s.IsDel == "0")
                           .Where(s => s.ParentNo == SqlFunc.Subqueryable<SysDictionary>().Where(c => c.DictName == dicName).Select(c => c.DictNo))
                           .ToListAsync();
        }
    }
}