TsysRoleController.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Ropin.Inspection.Api.Common;
  5. using Ropin.Inspection.Model;
  6. using Ropin.Inspection.Model.ViewModel;
  7. using Ropin.Inspection.Service.SYS.Interface;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Api.Controllers
  13. {
  14. [AllowAnonymous]
  15. /// <summary>
  16. /// 角色
  17. /// </summary>
  18. public class TsysRoleController : BaseController
  19. {
  20. private readonly ILogger<TsysRoleController> _logger;
  21. private readonly ITsysRoleService _tsysRoleService;
  22. /// <summary>
  23. /// 构造函数
  24. /// </summary>
  25. /// <param name="tsysRoleService"></param>
  26. /// <param name="logger"></param>
  27. public TsysRoleController(ITsysRoleService tsysRoleService, ILogger<TsysRoleController> logger)
  28. {
  29. _tsysRoleService = tsysRoleService;
  30. _logger = logger;
  31. }
  32. /// <summary>
  33. /// 通过角色ID获取角色信息
  34. /// </summary>
  35. /// <param name="RoleId"></param>
  36. /// <returns></returns>
  37. [HttpGet("GetRoleAsync/{RoleId}")]
  38. public async Task<ApiResult> GetRoleAsync(Guid RoleId)
  39. {
  40. if (Guid.Empty == RoleId)
  41. {
  42. return new ApiResult(ReturnCode.GeneralError);
  43. }
  44. try
  45. {
  46. var Role = await _tsysRoleService.GetByIdAsync(RoleId);
  47. return new ApiResult<TsysRoleViewModel>(Role);
  48. }
  49. catch (Exception ex)
  50. {
  51. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  52. }
  53. }
  54. /// <summary>
  55. /// 获取所有角色
  56. /// </summary>
  57. /// <returns></returns>
  58. [HttpGet("GetRolesAsync")]
  59. public async Task<ApiResult> GetRolesAsync()
  60. {
  61. try
  62. {
  63. var RoleList = await _tsysRoleService.GetAllAsync();
  64. return new ApiResult<IEnumerable<TsysRoleViewModel>>(RoleList.OrderBy(i=>i.C_LicenseCode));
  65. }
  66. catch (Exception ex)
  67. {
  68. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  69. }
  70. }
  71. /// <summary>
  72. /// 根据LicenseCode获取所有角色
  73. /// </summary>
  74. /// <param name="LicenseCode"></param>
  75. /// <returns></returns>
  76. [HttpGet("GetBylicenseCodeAsync/{LicenseCode}/{status=1}")]
  77. public async Task<ApiResult> GetBylicenseCodeAsync(string LicenseCode, string status)
  78. {
  79. if (string.IsNullOrEmpty(LicenseCode))
  80. {
  81. return new ApiResult(ReturnCode.GeneralError);
  82. }
  83. try
  84. {
  85. var RoleList = await _tsysRoleService.GetBylicenseCodeAsync(LicenseCode, status);
  86. return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList);
  87. }
  88. catch (Exception ex)
  89. {
  90. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  91. }
  92. }
  93. /// <summary>
  94. /// 根据LicenseCode和名称获取所有角色
  95. /// </summary>
  96. /// <param name="LicenseCode"></param>
  97. /// <param name="Name"></param>
  98. /// <param name="status"></param>
  99. /// <returns></returns>
  100. [HttpGet("GetBylicenseCodeByNameAsync/{LicenseCode}/{Name}/{status=1}")]
  101. public async Task<ApiResult> GetBylicenseCodeByNameAsync(string LicenseCode, string Name, string status)
  102. {
  103. if (string.IsNullOrEmpty(LicenseCode))
  104. {
  105. return new ApiResult(ReturnCode.GeneralError);
  106. }
  107. try
  108. {
  109. var RoleList = await _tsysRoleService.GetBylicenseCodeAsync(LicenseCode, status);
  110. if(string.IsNullOrWhiteSpace(Name))
  111. return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList);
  112. else
  113. return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList.Where(x=>x.C_Name.Contains(Name)));
  114. }
  115. catch (Exception ex)
  116. {
  117. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  118. }
  119. }
  120. /// <summary>
  121. /// 创建角色
  122. /// </summary>
  123. /// <param name="Role"></param>
  124. /// <returns></returns>
  125. [Route("CreateRoleAsync")]
  126. [HttpPost]
  127. public async Task<ApiResult> CreateRoleAsync([FromBody] TsysRoleCreateViewModel Role)
  128. {
  129. if (Role == null)
  130. {
  131. return new ApiResult(ReturnCode.ArgsError);
  132. }
  133. try
  134. {
  135. await _tsysRoleService.CreateAsync(Role);
  136. }
  137. catch (Exception ex)
  138. {
  139. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  140. }
  141. return new ApiResult(ReturnCode.Success);
  142. }
  143. /// <summary>
  144. /// 删除角色
  145. /// </summary>
  146. /// <param name="RoleId"></param>
  147. /// <returns></returns>
  148. [HttpDelete("DeleteRoleAsync/{RoleId}")]
  149. public async Task<ApiResult> DeleteRoleAsync(Guid RoleId)
  150. {
  151. if (Guid.Empty == RoleId)
  152. {
  153. return new ApiResult(ReturnCode.GeneralError);
  154. }
  155. try
  156. {
  157. await _tsysRoleService.DeleteAsync(RoleId);
  158. }
  159. catch (Exception ex)
  160. {
  161. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  162. }
  163. return new ApiResult(ReturnCode.Success);
  164. }
  165. /// <summary>
  166. /// 更新角色
  167. /// </summary>
  168. /// <param name="RoleId"></param>
  169. /// <param name="updateRole"></param>
  170. /// <returns></returns>
  171. [HttpPut("UpdateRoleAsync/{RoleId}")]
  172. public async Task<ApiResult> UpdateRoleAsync(Guid RoleId, TsysRoleUpdateViewModel updateRole)
  173. {
  174. if (Guid.Empty == RoleId)
  175. {
  176. return new ApiResult(ReturnCode.GeneralError);
  177. }
  178. try
  179. {
  180. await _tsysRoleService.UpdateAsync(RoleId, updateRole);
  181. }
  182. catch (Exception ex)
  183. {
  184. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  185. }
  186. return new ApiResult(ReturnCode.Success);
  187. }
  188. ///// <summary>
  189. ///// 条件查询角色
  190. ///// </summary>
  191. ///// <param name="searchViewModel"></param>
  192. ///// <returns></returns>
  193. //[Route("GetRolesByAsync")]
  194. //[HttpPost]
  195. //public async Task<ApiResult> GetByAsync(TsysRoleSearchModel searchViewModel)
  196. //{
  197. // try
  198. // {
  199. // var list = await _tsysRoleService.GetByAsync(searchViewModel);
  200. // return new ApiResult<PagesModel<TsysRoleViewModel>>(new PagesModel<TsysRoleViewModel>(list, searchViewModel));
  201. // }
  202. // catch (Exception ex)
  203. // {
  204. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  205. // }
  206. //}
  207. }
  208. }