TsysRoleHandController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Autofac.Core;
  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.Service.SYS.Interface;
  7. using System.Collections.Generic;
  8. using System.Threading.Tasks;
  9. using System;
  10. using Ropin.Inspection.Model.ViewModel.SYS;
  11. namespace Ropin.Inspection.Api.Controllers.SYS
  12. {
  13. public class TsysRoleHandController : BaseController
  14. {
  15. private readonly ILogger<TsysRoleController> _logger;
  16. private readonly ITsysRoleHandServices _service;
  17. /// <summary>
  18. /// 构造函数
  19. /// </summary>
  20. /// <param name="service"></param>
  21. /// <param name="logger"></param>
  22. public TsysRoleHandController(ITsysRoleHandServices service, ILogger<TsysRoleController> logger)
  23. {
  24. _service = service;
  25. _logger = logger;
  26. }
  27. /// <summary>
  28. /// 创建角色手持设备关联
  29. /// </summary>
  30. /// <returns></returns>
  31. [HttpPost("CreateAsync")]
  32. public async Task<ApiResult> CreateAsync(AddRoleHandModel viewModel)
  33. {
  34. if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || null == viewModel.HandList||viewModel.HandList.Count==0)
  35. {
  36. return new ApiResult(ReturnCode.GeneralError);
  37. }
  38. try
  39. {
  40. await _service.CreateAsync(viewModel);
  41. return new ApiResult(ReturnCode.Success, "添加成功!");
  42. }
  43. catch (Exception ex)
  44. {
  45. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  46. }
  47. }
  48. /// <summary>
  49. /// 创建角色手持设备关联
  50. /// </summary>
  51. /// <returns></returns>
  52. [HttpPost("CreateOneAsync")]
  53. public async Task<ApiResult> CreateOneAsync(TSYSRoleHandViewModel viewModel)
  54. {
  55. if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || Guid.Empty == viewModel.C_HandCode)
  56. {
  57. return new ApiResult(ReturnCode.GeneralError);
  58. }
  59. try
  60. {
  61. await _service.CreateOneAsync(viewModel);
  62. return new ApiResult(ReturnCode.Success, "添加成功!");
  63. }
  64. catch (Exception ex)
  65. {
  66. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  67. }
  68. }
  69. /// <summary>
  70. /// 删除角色手持设备关联,根据角色ID和手持设备ID
  71. /// </summary>
  72. /// <returns></returns>
  73. [HttpPost("DeleteRoleHandAsync")]
  74. public async Task<ApiResult> DeleteRoleHandAsync(TSYSRoleHandViewModel viewModel)
  75. {
  76. if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || Guid.Empty == viewModel.C_HandCode)
  77. {
  78. return new ApiResult(ReturnCode.GeneralError);
  79. }
  80. try
  81. {
  82. await _service.DeleteRoleHandAsync(viewModel.C_HandCode,viewModel.C_RoleCode);
  83. return new ApiResult(ReturnCode.Success, "删除成功!");
  84. }
  85. catch (Exception ex)
  86. {
  87. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  88. }
  89. }
  90. /// <summary>
  91. /// 通过角色ID获取角色手持设备关联
  92. /// </summary>
  93. /// <param name="roleId"></param>
  94. /// <returns></returns>
  95. [HttpGet("GetRoleHandListByRoleIdAsync/{roleId}")]
  96. public async Task<ApiResult> GetRoleHandListByRoleIdAsync(Guid roleId)
  97. {
  98. if (roleId==Guid.Empty)
  99. {
  100. return new ApiResult(ReturnCode.GeneralError);
  101. }
  102. try
  103. {
  104. var rolePrivs = await _service.GetRoleHandListAsync(roleId);
  105. return new ApiResult<IEnumerable<TSYSRoleHandModel>>(rolePrivs);
  106. }
  107. catch (Exception ex)
  108. {
  109. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  110. }
  111. }
  112. }
  113. }