using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Service.SYS.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Controllers { [AllowAnonymous] /// /// 角色 /// public class TsysRoleController : BaseController { private readonly ILogger _logger; private readonly ITsysRoleService _tsysRoleService; /// /// 构造函数 /// /// /// public TsysRoleController(ITsysRoleService tsysRoleService, ILogger logger) { _tsysRoleService = tsysRoleService; _logger = logger; } /// /// 通过角色ID获取角色信息 /// /// /// [HttpGet("GetRoleAsync/{RoleId}")] public async Task GetRoleAsync(Guid RoleId) { if (Guid.Empty == RoleId) { return new ApiResult(ReturnCode.GeneralError); } try { var Role = await _tsysRoleService.GetByIdAsync(RoleId); return new ApiResult(Role); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有角色 /// /// [HttpGet("GetRolesAsync")] public async Task GetRolesAsync() { try { var RoleList = await _tsysRoleService.GetAllAsync(); return new ApiResult>(RoleList.OrderBy(i=>i.C_LicenseCode)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 根据LicenseCode获取所有角色 /// /// /// [HttpGet("GetBylicenseCodeAsync/{LicenseCode}/{status=1}")] public async Task GetBylicenseCodeAsync(string LicenseCode, string status) { if (string.IsNullOrEmpty(LicenseCode)) { return new ApiResult(ReturnCode.GeneralError); } try { var RoleList = await _tsysRoleService.GetBylicenseCodeAsync(LicenseCode, status); return new ApiResult>(RoleList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 根据LicenseCode和名称获取所有角色 /// /// /// /// /// [HttpGet("GetBylicenseCodeByNameAsync/{LicenseCode}/{Name}/{status=1}")] public async Task GetBylicenseCodeByNameAsync(string LicenseCode, string Name, string status) { if (string.IsNullOrEmpty(LicenseCode)) { return new ApiResult(ReturnCode.GeneralError); } try { var RoleList = await _tsysRoleService.GetBylicenseCodeAsync(LicenseCode, status); if(string.IsNullOrWhiteSpace(Name)) return new ApiResult>(RoleList); else return new ApiResult>(RoleList.Where(x=>x.C_Name.Contains(Name))); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建角色 /// /// /// [Route("CreateRoleAsync")] [HttpPost] public async Task CreateRoleAsync([FromBody] TsysRoleCreateViewModel Role) { if (Role == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _tsysRoleService.CreateAsync(Role); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除角色 /// /// /// [HttpDelete("DeleteRoleAsync/{RoleId}")] public async Task DeleteRoleAsync(Guid RoleId) { if (Guid.Empty == RoleId) { return new ApiResult(ReturnCode.GeneralError); } try { await _tsysRoleService.DeleteAsync(RoleId); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新角色 /// /// /// /// [HttpPut("UpdateRoleAsync/{RoleId}")] public async Task UpdateRoleAsync(Guid RoleId, TsysRoleUpdateViewModel updateRole) { if (Guid.Empty == RoleId) { return new ApiResult(ReturnCode.GeneralError); } try { await _tsysRoleService.UpdateAsync(RoleId, updateRole); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } ///// ///// 条件查询角色 ///// ///// ///// //[Route("GetRolesByAsync")] //[HttpPost] //public async Task GetByAsync(TsysRoleSearchModel searchViewModel) //{ // try // { // var list = await _tsysRoleService.GetByAsync(searchViewModel); // return new ApiResult>(new PagesModel(list, searchViewModel)); // } // catch (Exception ex) // { // return new ApiResult(ReturnCode.GeneralError, ex.Message); // } //} } }