wzp
2021-07-19 e65183d31755a0e5fae4bf428435d2e0fd6afdc5
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using FineAdmin.Common;
using FineAdmin.IRepository;
using FineAdmin.Model;
 
namespace FineAdmin.Repository
{
    public class ButtonRepository : BaseRepository<ButtonModel>, IButtonRepository
    {
        /// <summary>
        /// 根据角色菜单按钮位置获得按钮列表
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="moduleId"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public IEnumerable<ButtonModel> GetButtonListByRoleIdModuleId(int roleId, int moduleId, PositionEnum position)
        {
            using (var conn = OracleHelper.OracleConnection())
            {
                string sql = @"SELECT b.* FROM dbsys_roleauthorize a
                            INNER JOIN dbsys_button b ON a.ButtonId=b.Id
                            WHERE a.RoleId=:RoleId
                            and a.ModuleId=:ModuleId
                            and b.Location=:Location
                            ORDER BY b.SortCode";
                return conn.Query<ButtonModel>(sql, new { RoleId = roleId, ModuleId = moduleId, Location = (int)position });
            }
        }
 
        /// <summary>
        /// 根据角色菜单获得按钮列表
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="moduleId"></param>
        /// <param name="selectList"></param>
        /// <returns></returns>
        public IEnumerable<ButtonModel> GetButtonListByRoleIdModuleId(int roleId, int moduleId, out IEnumerable<ButtonModel> selectList)
        {
            using (var conn = OracleHelper.OracleConnection())
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(@"SELECT Id,FullName FROM dbsys_button a
                            INNER JOIN dbsys_roleauthorize b ON a.Id = b.ButtonId
                            WHERE b.RoleId = :RoleId and b.ModuleId = :ModuleId");
                
                using (var reader = conn.QueryMultiple(sb.ToString(), new { RoleId = roleId, ModuleId = moduleId }))
                {
                    selectList = reader.Read<ButtonModel>();
                }
 
                StringBuilder sb2 = new StringBuilder();
                sb2.Append(@"SELECT Id, FullName FROM dbsys_button");
 
                using (var reader = conn.QueryMultiple(sb2.ToString()))
                {
                    return reader.Read<ButtonModel>();
                }
                
            }
        }
    }
}