ningshuxia
2024-05-27 f51ccee7e76f598c1f718190d216f96b5ea1ca46
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
namespace Yw.Application
{
    /// <summary>
    /// RoleUserMapping
    /// </summary>
    [Route("Auth/Role/User/Mapping")]
    [ApiDescriptionSettings("Auth", Name = "角色与用户映射", Order = 5800)]
    public class RoleUser_Controller : IDynamicApiController
    {
        private readonly Service.UserRoleMapping _service = new();
 
        /// <summary>
        ///  获取下发用户列表
        /// </summary>
        [Route("GetAuthorizeUserList@V1.0")]
        [HttpGet]
        public List<RoleUserHaveDto> GetAuthorizeUserList([FromQuery][Required] RoleIDInput input)
        {
            var role = new Service.Role().GetByID(input.RoleID);
            if (role == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"RoleID:{input.RoleID} 数据不存在");
            }
            var dict = _service.GetAuthorizeUserList(input.RoleID);
            if (dict.Count < 1)
            {
                return default;
            }
            var vmList = new List<RoleUserHaveDto>();
            foreach (var item in dict)
            {
                var vm = new RoleUserHaveDto(item.Key, item.Value);
                vmList.Add(vm);
            }
            return vmList;
        }
 
        /// <summary>
        /// 设置
        /// </summary>
        [Route("Set@V1.0")]
        [HttpPost]
        public bool Set([Required] SetRoleUserInput input)
        {
            var role = new Service.Role().GetByID(input.RoleID);
            if (role == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"RoleID:{input.RoleID} 数据不存在");
            }
            if (input.UserIds != null && input.UserIds.Count > 0)
            {
                var userList = new Service.User().GetByIds(input.UserIds);
                if (userList == null || userList.Count < 1)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"用户id列表与数据库不匹配");
                }
                var corpIds = userList.Select(x => x.CorpID).Distinct().ToList();
                if (corpIds.Count != 1 || corpIds[0] != role.CorpID)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"用户id列表与数据库不匹配");
                }
            }
 
            var bol = _service.SetByRole(input.RoleID, input.UserIds);
            return bol;
        }
 
 
 
    }
}