UserSessionController.cs
4.03 KB
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
// ***********************************************************************
// <summary>
// 获取登录用户的全部信息
// 所有和当前登录用户相关的操作都在这里
// </summary>
// ***********************************************************************
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using WebApp;
using WebRepository;
namespace WebMvc
{
[Area("base")]
public class UserSessionController : BaseController
{
private readonly AuthStrategyContext _authStrategyContext;
public UserSessionController(IAuth authUtil) : base(authUtil)
{
_authStrategyContext = _authUtil.GetCurrentUser();
}
public List<string> GetCurrentUser()
{
return new List<string> { _authStrategyContext.User.Account, _authStrategyContext.User.Name };
}
/// <summary>
/// 获取登录用户可访问的所有模块,及模块的操作菜单
/// </summary>
public string GetModulesTree()
{
//OpenAuth原左边栏菜单
var moduleTree = _authStrategyContext.Modules.GenerateTree(u => u.Id, u => u.ParentId);
return JsonHelper.Instance.Serialize(moduleTree);
}
/// <summary>
/// datatable结构的模块列表
/// </summary>
/// <param name="pId"></param>
/// <param name="pageRequest"></param>
/// <returns></returns>
public string GetModulesTable(int pId, PageReq pageRequest)
{
string cascadeId = ".0.";
if (pId != 0)
{
var obj = _authStrategyContext.Modules.SingleOrDefault(u => u.Id == pId);
if (obj != null)
{
cascadeId = obj.CascadeId;
}
}
var query = _authStrategyContext.Modules
.Where(u => u.CascadeId.Contains(cascadeId));
var data = query.OrderBy(u => u.Id)
.Skip((pageRequest.page - 1) * pageRequest.limit)
.Take(pageRequest.limit);
return JsonHelper.Instance.Serialize(new TableData
{
data = data.ToList(),
count = query.Count(),
});
}
/// <summary>
/// 获取用户可访问的模块列表
/// </summary>
public string GetModules()
{
return JsonHelper.Instance.Serialize(_authStrategyContext.Modules);
}
/// <summary>
/// 获取登录用户可访问的所有部门
/// <para>用于树状结构</para>
/// </summary>
public string GetOrgs()
{
return JsonHelper.Instance.Serialize(_authStrategyContext.Orgs);
}
/// <summary>
/// 加载机构的全部下级机构
/// </summary>
/// <param name="orgId">机构ID</param>
/// <param name="pageRequest">机构ID</param>
/// <returns></returns>
public string GetSubOrgs(int orgId, PageReq pageRequest)
{
string cascadeId = ".0.";
if (orgId != 0)
{
var org = _authStrategyContext.Orgs.SingleOrDefault(u => u.Id == orgId);
if (org == null)
{
return JsonHelper.Instance.Serialize(new TableData
{
msg = "未找到指定的节点",
code = 500,
});
}
cascadeId = org.CascadeId;
}
var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.Contains(cascadeId));
var data = query.OrderBy(u => u.Id)
.Skip((pageRequest.page - 1) * pageRequest.limit)
.Take(pageRequest.limit);
return JsonHelper.Instance.Serialize(new TableData
{
data = data.ToList(),
count = query.Count(),
});
}
}
}