bklLiudl
2024-05-25 484e5129e4c9a671c5660a556a24bd306f1fdd9b
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
using Microsoft.VisualBasic;
using Model.ModelDto.LogDto;
using Model.ModelDto.SysDto;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IDAL.ILogInterface;
 
namespace WMS.DAL.LogInterface
{
    /// <summary>
    /// 系统操作日志仓储实践
    /// </summary>
    public class OperationSysRepository : BaseRepository<LogOperationSys>, IOperationSysRepository
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public OperationSysRepository() : base(Db)
        {
 
        }
 
        /// <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 List<OperationDto> GetSysOperationList(string menuName, string type, string msg, string menuNo, string parentNo)
        {
            string str = "select logsys.*,user1.RealName CreateUserName,dic.DictName TypeName from LogOperationSys logsys left join SysUserInfor user1 on logsys.CreateUser = user1.Id left join SysFunctionMenu menu on logsys.ParentNo = menu.MenuNo left join SysDictionary dic on logsys.type = dic.Id where logsys.IsDel = @isdel and logsys.ParentNo = (select MenuNo from SysFunctionMenu where IsDel = @isdel and MenuName = @menuname)";
            //判断菜单名称是否为空
            if (!string.IsNullOrEmpty(menuName))
            {
                str += " and logsys.MenuName like @mname";
            }
            //判断操作类型是否为空
            if (!string.IsNullOrEmpty(type))
            {
                str += " and logsys.Type = @type";
            }
            //判断操作内容是否为空
            if (!string.IsNullOrEmpty(msg))
            {
                str += " and logsys.Msg like @msg";
            }
            //判断菜单号是否为空
            if (!string.IsNullOrEmpty(menuNo))
            {
                str += " and logsys.MenuNo = @menuno";
            }
            str += " order by logsys.CreateTime desc";
            List<OperationDto> operationlist = Db.Ado.SqlQuery<OperationDto>(str, new
            {
                isdel = "0", //是否删除
                menuname = parentNo, //模块名称获取模块号
                mname = "%" + menuName + "%", //菜单名称
                type, //操作类型
                msg = "%" + msg + "%", //操作内容
                menuno = menuNo //菜单号
            });
            return operationlist;
        }
 
        /// <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="createUsercreateUser">创建人</param>
        /// <returns></returns>
        public async Task<int> InsertOperation(string parentNo, string menuNo, string menuName, string fkNo, string type, string msg, int createUser)
        {
            type = Db.Ado.SqlQuerySingle<SysDictionary>("select * from SysDictionary where IsDel = @isdel and DictName = @dictname", new
            {
                isdel = "0", //是否删除
                dictname = type == "修改" ? "编辑" : type //字典名称
            }).Id.ToString();
            string str = "insert into LogOperationSys values(@parentno, @menuno, @menuname, @fkno, @type, @msg, @isdel, @createtime, @createuser, null,null)";
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                parentno = parentNo, //模块号
                menuno = menuNo, //菜单号
                menuname = menuName, //菜单名称
                fkno = fkNo, //数据编号
                type, //操作类型
                msg, //操作内容
                isdel = "0", //是否删除
                createtime = Db.GetDate(), //创建时间
                createuser = createUser //创建人
            });
            return i;
        }
 
        /// <summary>
        /// 根据菜单名称获取菜单号
        /// </summary>
        /// <param name="ParentNo"></param>
        /// <param name="MenuNo"></param>
        public SysFunctionMenu GetMenuList(string menuName)
        {
            string str = "select MenuNo from SysFunctionMenu where MenuName = @menuname and IsDel = @isdel";
            SysFunctionMenu menu = Db.Ado.SqlQuerySingle<SysFunctionMenu>(str, new
            {
                menuname = menuName, //菜单名称
                isdel = "0" //是否删除
            });
            return menu;
 
        }
 
        /// <summary>
        /// 获取类型菜单
        /// </summary>
        /// <param name="dicName">字典名称</param>
        /// <returns></returns>
        public List<SysDictionary> GetDicTypeList(string dicName)
        {
            string str = "select * from SysDictionary where IsDel = @isdel and ParentNo = (select DictNo from SysDictionary where DictName = @dictname)";
            List<SysDictionary> diclist = Db.Ado.SqlQuery<SysDictionary>(str, new
            {
                isdel = "0", //是否删除
                dictname = dicName //字典名称
            });
            return diclist;
        }
    }
}