刘磊
2025-04-19 823752496e2a4cdb6a1fb36227cd15b8b7135336
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
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using WIDESEA_Core;
using WIDESEA_Core.BaseController;
using WIDESEA_Core.BaseRepository;
using WIDESEA_DTO.System;
using WIDESEA_IServices;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.System;
namespace WIDESEA_WMSServer.Controllers{
 
[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("savePermission")]
    public IActionResult SavePermission([FromBody] List<UserPermissionDTO> userPermissions, int roleId)
    {
        return Json(Service.SavePermission(userPermissions, roleId));
    }
}
}