123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- 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]
- /// <summary>
- /// 角色
- /// </summary>
- public class TsysRoleController : BaseController
- {
- private readonly ILogger<TsysRoleController> _logger;
- private readonly ITsysRoleService _tsysRoleService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="tsysRoleService"></param>
- /// <param name="logger"></param>
- public TsysRoleController(ITsysRoleService tsysRoleService, ILogger<TsysRoleController> logger)
- {
- _tsysRoleService = tsysRoleService;
- _logger = logger;
- }
- /// <summary>
- /// 通过角色ID获取角色信息
- /// </summary>
- /// <param name="RoleId"></param>
- /// <returns></returns>
- [HttpGet("GetRoleAsync/{RoleId}")]
- public async Task<ApiResult> GetRoleAsync(Guid RoleId)
- {
- if (Guid.Empty == RoleId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var Role = await _tsysRoleService.GetByIdAsync(RoleId);
- return new ApiResult<TsysRoleViewModel>(Role);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有角色
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetRolesAsync")]
- public async Task<ApiResult> GetRolesAsync()
- {
- try
- {
- var RoleList = await _tsysRoleService.GetAllAsync();
- return new ApiResult<IEnumerable<TsysRoleViewModel>>(RoleList.OrderBy(i=>i.C_LicenseCode));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 根据LicenseCode获取所有角色
- /// </summary>
- /// <param name="LicenseCode"></param>
- /// <returns></returns>
- [HttpGet("GetBylicenseCodeAsync/{LicenseCode}/{status=1}")]
- public async Task<ApiResult> 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<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 根据LicenseCode和名称获取所有角色
- /// </summary>
- /// <param name="LicenseCode"></param>
- /// <param name="Name"></param>
- /// <param name="status"></param>
- /// <returns></returns>
- [HttpGet("GetBylicenseCodeByNameAsync/{LicenseCode}/{Name}/{status=1}")]
- public async Task<ApiResult> 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<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList);
- else
- return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList.Where(x=>x.C_Name.Contains(Name)));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建角色
- /// </summary>
- /// <param name="Role"></param>
- /// <returns></returns>
- [Route("CreateRoleAsync")]
- [HttpPost]
- public async Task<ApiResult> 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);
- }
- /// <summary>
- /// 删除角色
- /// </summary>
- /// <param name="RoleId"></param>
- /// <returns></returns>
- [HttpDelete("DeleteRoleAsync/{RoleId}")]
- public async Task<ApiResult> 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);
- }
- /// <summary>
- /// 更新角色
- /// </summary>
- /// <param name="RoleId"></param>
- /// <param name="updateRole"></param>
- /// <returns></returns>
- [HttpPut("UpdateRoleAsync/{RoleId}")]
- public async Task<ApiResult> 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);
- }
-
- ///// <summary>
- ///// 条件查询角色
- ///// </summary>
- ///// <param name="searchViewModel"></param>
- ///// <returns></returns>
- //[Route("GetRolesByAsync")]
- //[HttpPost]
- //public async Task<ApiResult> GetByAsync(TsysRoleSearchModel searchViewModel)
- //{
- // try
- // {
- // var list = await _tsysRoleService.GetByAsync(searchViewModel);
- // return new ApiResult<PagesModel<TsysRoleViewModel>>(new PagesModel<TsysRoleViewModel>(list, searchViewModel));
- // }
- // catch (Exception ex)
- // {
- // return new ApiResult(ReturnCode.GeneralError, ex.Message);
- // }
- //}
- }
- }
|