using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model; using Ropin.Inspection.Service; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Controllers { public class TsysUserRoleController : BaseController { private readonly ILogger _logger; private readonly ITsysUserRoleService _service; /// /// 构造函数 /// /// /// public TsysUserRoleController(ITsysUserRoleService service, ILogger logger) { _service = service; _logger = logger; } /// /// 通过用户ID获取用户角色信息 /// /// /// [HttpGet("GetUserRolesByUserIdAsync/{userId}")] public async Task GetUserRolesByUserIdAsync(Guid userId) { if (Guid.Empty == userId) { return new ApiResult(ReturnCode.GeneralError); } try { var userRole = await _service.GetUserRolesByUserIdAsync(userId); return new ApiResult>(userRole); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建用户角色 /// /// [HttpPost("CreateRolesAsync")] public async Task CreateRolesAsync(TsysUserRoleCreateModel viewModel) { if (viewModel == null || Guid.Empty == viewModel.C_UserCode || null == viewModel.RoleCodeList) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.CreateRolesAsync(viewModel); return new ApiResult(ReturnCode.Success, "添加成功!"); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建角色权限 /// /// [HttpPost("CreateRolePrivsAsync")] public async Task CreateRolePrivsAsync(TsysRolePrivCreateModel viewModel) { if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || null == viewModel.PrivCodeList) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.CreateRolePrivsAsync(viewModel); return new ApiResult(ReturnCode.Success, "添加成功!"); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过角色ID获取权限信息 /// /// /// [HttpGet("GetRolePrivsByRoleIdAsync/{roleId}")] public async Task GetRolePrivsByRoleIdAsync(string roleId) { if (string.IsNullOrEmpty(roleId)) { return new ApiResult(ReturnCode.GeneralError); } try { var rolePrivs = await _service.GetRolePrivsByRoleIdAsync(roleId); return new ApiResult>(rolePrivs); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } } }