1
yanjinhui
7 天以前 a3b1d7bfe497ca5ece2a51eb15a5534a98b33dcb
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
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using WIDESEAWCS_DTO.System;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseController;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using Microsoft.AspNetCore.Authorization;
 
namespace WIDESEAWCS_WCSServer.Controllers.System
{
    [Route("api/Sys_Role")]
    [ApiController]
    public class Sys_RoleController : ApiBaseController<ISys_RoleService, Sys_Role>
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        public Sys_RoleController(ISys_RoleService service, IHttpContextAccessor httpContextAccessor) : base(service)
        {
            _httpContextAccessor = httpContextAccessor;
        }
 
        [HttpPost, Route("getUserChildRoles")]
        public IActionResult GetUserChildRoles()
        {
            int roleId = App.User.RoleId;
            var data = Service.GetAllChildren(roleId);
 
            if (App.User.IsSuperAdmin)
            {
                return Json(WebResponseContent.Instance.OK(null, data));
            }
            //不是超级管理,将自己的角色查出来,在树形菜单上作为根节点
            var self = data.Where(x => x.Id == roleId)
                 .Select(s => new RoleNodes()
                 {
                     Id = s.Id,
                     ParentId = 0,//将自己的角色作为root节点
                     RoleName = s.RoleName
                 }).ToList();
            data.AddRange(self);
            return Json(WebResponseContent.Instance.OK(null, data));
        }
 
        [HttpPost, Route("getCurrentTreePermission")]
        public IActionResult GetCurrentTreePermission()
        {
            return Json(Service.GetCurrentTreePermission());
        }
 
        [HttpPost, Route("getUserTreePermission")]
        public IActionResult GetUserTreePermission(int roleId)
        {
            return Json(Service.GetUserTreePermission(roleId));
        }
 
        [HttpPost, Route("GetUserTreeUserRole"), AllowAnonymous]
        public IActionResult GetUserTreeUserRole(string url)
        {
 
            return Json(Service.GetUserTreeUserRole(url));
        }
 
        [HttpPost, Route("savePermission")]
        public IActionResult SavePermission([FromBody] List<UserPermissionDTO> userPermissions, int roleId)
        {
            return Json(Service.SavePermission(userPermissions, roleId));
        }
    }
}