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
72
73
74
75
namespace Yw.Application
{
    /// <summary>
    /// ProjectRoleMapping
    /// </summary>
    [Route("Auth/Project/Role/Mapping")]
    [ApiDescriptionSettings("Auth", Name = "项目与角色映射", Order = 7900)]
    public class ProjectRole_Controller : IDynamicApiController
    {
        private readonly Service.ProjectRoleMapping _service = new();
 
        /// <summary>
        ///  获取下发角色列表
        /// </summary>
        [Route("GetAuthorizeRoleList@V1.0")]
        [HttpGet]
        public List<ProjectRoleHaveDto> GetAuthorizeRoleList([FromQuery][Required] ProjectIDInput input)
        {
            var project = new Service.Project().GetByID(input.ProjectID);
            if (project == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ProjectID:{input.ProjectID} 数据不存在");
            }
            var dict = _service.GetAuthorizeRoleList(project.ID);
            if (dict.Count < 1)
            {
                return default;
            }
            var vmList = new List<ProjectRoleHaveDto>();
            foreach (var item in dict)
            {
                var vm = new ProjectRoleHaveDto(item.Key, item.Value);
                vmList.Add(vm);
            }
            return vmList;
        }
 
        /// <summary>
        /// 设置
        /// </summary>
        [Route("Set@V1.0")]
        [HttpPost]
        public bool Set([Required] SetProjectRoleInput input)
        {
            var project = new Service.Project().GetByID(input.ProjectID);
            if (project == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ProjectID:{input.ProjectID} 数据不存在");
            }
            if (input.RoleIds != null && input.RoleIds.Count > 0)
            {
                var roleList = new Service.Role().GetByIds(input.RoleIds);
                if (roleList == null || roleList.Count < 1)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"RoleIds:{LongListHelper.ToString(input.RoleIds)} 角色检索失败");
                }
                var corpIds = roleList.Select(x => x.CorpID).Distinct().ToList();
                if (corpIds.Count != 1 || corpIds[0] != project.CorpID)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"RoleIds:{LongListHelper.ToString(input.RoleIds)} 角色验证失败");
                }
            }
 
            var bol = _service.Set(input.ProjectID, input.RoleIds, out string Msg);
            if (!bol)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg);
            }
            return bol;
        }
 
 
 
    }
}