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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using Dm;
using Model.ModelDto.SysDto;
using Model.ModelVm.SysVm;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IDAL.ISysInterface;
 
namespace WMS.DAL.SysInfrastructure
{
    /// <summary>
    /// 角色仓储实践
    /// </summary>
    public class RolesRepository : BaseRepository<SysRoles>, IRolesRepository
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public RolesRepository() : base(Db)
        {
        }
 
        /// <summary>
        /// 查询角色数据信息列表
        /// </summary>
        /// <param name="RoleNo">角色号</param>
        /// <param name="RoleName">角色名称</param>
        /// <returns></returns>
        public List<RoleDto> GetRoleList(string RoleNo, string RoleName,string UserId)
        {
            string whereSql = " role.IsDel = '0' ";
            if (!string.IsNullOrEmpty(UserId))
            {
                SysUserInfor userEntry = Db.Ado.SqlQuerySingle<SysUserInfor>($"select * from SysUserInfor where Id={UserId}");
                if (userEntry != null && userEntry.UserName.ToUpper() !="ADMIN")
                {
                    //除系统超级管理员admin外其他账号角色权限列表只能看到自己创建的角色
                    whereSql += $" and role.CreateUser = {UserId}";
                }
            }
            if (!string.IsNullOrEmpty(RoleNo))
            {
                whereSql += $" and role.RoleNo like '%{RoleNo}%' ";
            }
            if (!string.IsNullOrEmpty(RoleName))
            {
                whereSql += $" and role.RoleName like '%{RoleName}%' ";
            }
            string str = $@"select 
                                role.*,
                                user1.RealName CreateUserName,
                                user2.RealName UpdateUserName 
                            from SysRoles role 
                            left join SysUserInfor user1 on role.CreateUser = user1.Id 
                            left join SysUserInfor user2 on role.UpdateUser = user2.Id 
                            where {whereSql} order by role.Id";
 
            List<RoleDto> roles = Db.Ado.SqlQuery<RoleDto>(str);
            return roles;
        }
 
        /// <summary>
        /// 根据编号获取用户信息列表
        /// </summary>
        /// <param name="RoleNo">角色号</param>
        /// <returns></returns>
        public List<SysRoles> GetRoleByNo(string RoleNo)
        {
            string str = "select * from SysRoles where RoleNo = @roleno";
            List<SysRoles> userlist = Db.Ado.SqlQuery<SysRoles>(str, new
            {
                roleno = RoleNo //角色号
            });
            return userlist;
        }
 
        /// <summary>
        /// 新增角色数据信息
        /// </summary>
        /// <param name="roles">角色实体模型</param>
        /// <returns></returns>
        public async Task<int> InsertRoleInfo(SysRoles roles)
        {
            string str = "insert into SysRoles values(@roleno, @rolename, @demo, @isdel, @createtime, @createuser, null, null)";
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                roleno = roles.RoleNo, //角色号
                rolename = roles.RoleName, //角色名称
                demo = roles.Demo, //备注
                isdel = "0", //是否删除
                createtime = Db.GetDate(), //创建时间
                createuser = roles.CreateUser, //创建人
            });
            return i;
        }
 
        /// <summary>
        /// 删除\批量删除角色信息
        /// </summary>
        /// <param name="roles">角色实体模型</param>
        /// <returns></returns>
        public async Task<int> DeleteRoleInfo(SysRoles roles)
        {
            string str = "update SysRoles set IsDel = @isdel, UpdateTime = @updatetime, UpdateUser = @updateuser where Id in (@id)";
            //删除\批量删除
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                isdel = "1", //是否删除
                updatetime = Db.GetDate(), //更改时间
                updateuser = roles.UpdateUser, //更改人
                id = roles.Id //角色id
            });
            return i;
        }
 
 
        /// <summary>
        /// 编辑角色信息
        /// </summary>
        /// <param name="role">角色实体模型</param>
        /// <returns></returns>
        public async Task<int> UpdateRoleInfo(SysRoles role)
        {
            string str = "update SysRoles set RoleName = @rolename, Demo = @demo, UpdateTime = @updatetime, UpdateUser = @updateuser where Id = @id";
            //修改
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                roleno = role.RoleNo, //角色号
                rolename = role.RoleName, //角色名称
                demo = role.Demo, //备注
                updatetime = Db.GetDate(), //更改时间
                updateuser = role.UpdateUser, //更改人
                id = role.Id //角色id
            });
            return i;
 
        }
 
        /// <summary>
        /// 根据id获取角色信息
        /// </summary>
        /// <param name="roleid">角色id</param>
        /// <returns></returns>
        public SysRoles GetRoleInfoById(int roleid)
        {
            string str = "select * from SysRoles where Id = @id and IsDel = @isdel";
            SysRoles role= Db.Ado.SqlQuerySingle<SysRoles>(str, new
            {
                id = roleid, //角色id
                isdel = "0" //是否删除
            });
            return role;
 
        }
 
    }
}