UserSessionController.cs
5.14 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
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
// ***********************************************************************
// <summary>
// 获取登录用户的全部信息
// 所有和当前登录用户相关的操作都在这里
// </summary>
// ***********************************************************************
using Hh.Mes.Common.Request;
using Hh.Mes.Common.Tree;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.Service.SystemAuth;
using Hh.Mes.Service.WebService.Base;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace WebMvc
{
[Area("base")]
public class UserSessionController : BaseController
{
private readonly AuthStrategyContext _authStrategyContext;
private readonly SysDeptService sysDeptService;
public UserSessionController(IAuth authUtil, SysDeptService sysDeptService) : base(authUtil)
{
_authStrategyContext = _authUtil.GetCurrentUser();
this.sysDeptService = sysDeptService;
this.sysDeptService.sysWebUser = _authStrategyContext.User;
}
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 Serialize(moduleTree);
}
/// <summary>
/// datatable结构的模块列表
/// </summary>
/// <param name="modules"></param>
/// <param name="pageRequest"></param>
/// <returns></returns>
public string GetModulesTable(QueryModules modules, PageReq pageRequest)
{
var query = _authStrategyContext.Modules;
if (modules.parentId == null && modules.pId != null)
{
//当前是一级模块,就加载子模块
query = query.Where(u => u.ParentId == modules.pId).ToList();
}
else if (modules.parentId != null && modules.pId != null)
{
//当前是小于二级的模块,就加载所有的子节点模块
query = query.Where(u => u.CascadeId.Contains(modules.cascadeId)).ToList();
}
else if (modules.parentId == null && modules.pId == null)
{
//当前是根模块,就加载父节点是“根节点”的模块
query = query.Where(u => u.ParentName== "根节点").OrderBy(x => x.SortNo).ToList();
return Serialize(new Response
{
Result = query.ToList(),
Count = query.Count,
});
}
var data = query.OrderBy(u => u.Id)
.Skip((pageRequest.page - 1) * pageRequest.limit)
.Take(pageRequest.limit);
return Serialize(new Response
{
Result = data.ToList(),
Count = query.Count(),
});
}
/// <summary>
/// 获取用户可访问的模块列表
/// </summary>
public string GetModules()
{
var moduleList = _authStrategyContext.Modules;
return Serialize(moduleList);
}
/// <summary>
/// 获取所有部门
/// <para>用于树状结构</para>
/// </summary>
public string GetOrgs()
{
return 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 Serialize(new Response
{
Message = "未找到指定的节点",
Code = 500,
});
}
cascadeId = org.CascadeId;
}
var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.StartsWith(cascadeId));
var data = query.OrderBy(u => u.Id)
.Skip((pageRequest.page - 1) * pageRequest.limit)
.Take(pageRequest.limit);
return Serialize(new Response
{
Result = data.ToList(),
Count = query.Count(),
});
}
}
/// <summary>
/// 查询模块模型
/// </summary>
public class QueryModules
{
//父级id
public int? parentId { get; set; }
public int? pId { get; set; }
public string cascadeId { get; set; }
}
}