RoleController.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Bowin.Common.ServiceToken.Permission;
  6. using Bowin.Common.WebModels;
  7. using YLShipBuildLandMap.Entity;
  8. using YLShipBuildLandMap.Entity.ViewModel;
  9. using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
  10. using YLShipBuildLandMap.Services.SystemSetting;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.AspNetCore.Mvc;
  14. using Newtonsoft.Json.Linq;
  15. namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
  16. {
  17. [Route("api/systemsetting/[controller]/[action]")]
  18. [ApiController]
  19. [Authorize]
  20. public class RoleController : ControllerBase
  21. {
  22. private IRoleService RoleService { get; set; }
  23. private IMenuService MenuService { get; set; }
  24. private IFunctionCodeService FunctionCodeService { get; set; }
  25. public RoleController(IRoleService roleService, IFunctionCodeService functionCodeService)
  26. {
  27. RoleService = roleService;
  28. FunctionCodeService = functionCodeService;
  29. }
  30. [HttpPost]
  31. public ResultMessage GetRolesForSelect([FromBody] dynamic inputObj)
  32. {
  33. try
  34. {
  35. string roleName = inputObj.roleName;
  36. int? pageIndex = inputObj.pageIndex;
  37. int? pageSize = inputObj.pageSize;
  38. return ResultMessage.Success(RoleService.GetRoleViewsForSelect(roleName, pageIndex, pageSize));
  39. }
  40. catch (Exception ex)
  41. {
  42. return ResultMessage.GetError(ex.Message);
  43. }
  44. }
  45. [HttpPost]
  46. [FunctionCode("9902")]
  47. public ResultMessage GetRoleList([FromBody] dynamic inputObj)
  48. {
  49. try
  50. {
  51. string roleName = inputObj.roleName;
  52. int? pageIndex = inputObj.pageIndex;
  53. int? pageSize = inputObj.pageSize;
  54. var roleList = RoleService.GetRoleViewList(roleName, pageIndex, pageSize);
  55. return ResultMessage.Success(roleList);
  56. }
  57. catch (Exception ex)
  58. {
  59. return ResultMessage.GetError(ex.Message);
  60. }
  61. }
  62. [HttpPost]
  63. [FunctionCode("9902")]
  64. public ResultMessage GetRole([FromBody] dynamic inputObj)
  65. {
  66. try
  67. {
  68. Guid roleID = inputObj.roleID;
  69. var role = RoleService.GetRoleView(roleID);
  70. return ResultMessage.Success(role);
  71. }
  72. catch (Exception ex)
  73. {
  74. return ResultMessage.GetError(ex.Message);
  75. }
  76. }
  77. [HttpPost]
  78. [FunctionCode("990201")]
  79. public async Task<ResultMessage> Add([FromBody] JObject inputObj)
  80. {
  81. try
  82. {
  83. RoleView role = inputObj["role"].ToObject<RoleView>();
  84. List<string> functionCodes = inputObj["functionCodes"].ToObject<List<string>>();
  85. RoleView result = RoleService.GetRoleViewByName(role.RoleName);
  86. if (result != null)
  87. {
  88. return ResultMessage.GetError("角色已存在");
  89. }
  90. role.RoleID = null;
  91. await RoleService.Save(role, functionCodes, LoginUser.Current.UserID);
  92. return ResultMessage.Success();
  93. }
  94. catch (Exception ex)
  95. {
  96. return ResultMessage.GetError(ex.Message);
  97. }
  98. }
  99. [HttpPost]
  100. [FunctionCode("990202")]
  101. public async Task<ResultMessage> Edit([FromBody] dynamic inputObj)
  102. {
  103. try
  104. {
  105. RoleView role = inputObj["role"].ToObject<RoleView>();
  106. List<string> functionCodes = inputObj["functionCodes"].ToObject<List<string>>();
  107. if (!role.RoleID.HasValue)
  108. {
  109. throw new Exception("实体ID不能为空。");
  110. }
  111. await RoleService.Save(role, functionCodes, LoginUser.Current.UserID);
  112. return ResultMessage.Success();
  113. }
  114. catch (Exception ex)
  115. {
  116. return ResultMessage.GetError(ex.Message);
  117. }
  118. }
  119. [HttpPost]
  120. [FunctionCode("990203")]
  121. public async Task<ResultMessage> Delete([FromBody] dynamic inputObj)
  122. {
  123. try
  124. {
  125. List<Guid> roleIDList = inputObj.roleIDs.ToObject<List<Guid>>();
  126. await RoleService.Delete(roleIDList);
  127. return ResultMessage.Success();
  128. }
  129. catch (Exception ex)
  130. {
  131. return ResultMessage.GetError(ex.Message);
  132. }
  133. }
  134. [HttpPost]
  135. [FunctionCode("990202")]
  136. public ResultMessage GetFunctionCodeList()
  137. {
  138. try
  139. {
  140. var functionCodeList = FunctionCodeService.GetFunctionCodeList();
  141. return ResultMessage.Success(functionCodeList);
  142. }
  143. catch (Exception ex)
  144. {
  145. return ResultMessage.GetError(ex.Message);
  146. }
  147. }
  148. [HttpPost]
  149. [FunctionCode("990202")]
  150. public ResultMessage GetRoleFunctionCode([FromBody] dynamic inputObj)
  151. {
  152. try
  153. {
  154. Guid roleID = inputObj.roleID;
  155. List<String> roleFunctionCodeList = FunctionCodeService.GetRoleFunctionCode(roleID);
  156. return ResultMessage.Success(roleFunctionCodeList);
  157. }
  158. catch (Exception ex)
  159. {
  160. return ResultMessage.GetError(ex.Message);
  161. }
  162. }
  163. }
  164. }