添加项目文件。
This commit is contained in:
@@ -0,0 +1,330 @@
|
||||
using System.Linq;
|
||||
using AdminService.System;
|
||||
using AdminService.System.Param;
|
||||
using AdminService.System.Response;
|
||||
using Common;
|
||||
using CommonInfrastructure ;
|
||||
using Domain.Admin.Admin;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace AdminApi.System
|
||||
{
|
||||
|
||||
[ApiController, Route("adminapi/[controller]")]
|
||||
[Authorize]
|
||||
public class SystemController : BaseController
|
||||
{
|
||||
private readonly ISystemService _systemService;
|
||||
|
||||
public SystemController(ISystemService systemService)
|
||||
{
|
||||
_systemService = systemService;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("user/add")]
|
||||
|
||||
public async Task<BaseResponse<string>> AddUser(AddUserParam param)
|
||||
{
|
||||
var result = await _systemService.AddUser(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpPost("user/update")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateUser(UpdateUserParam param)
|
||||
{
|
||||
var result = await _systemService.UpdateUser(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpGet("user/update/icon")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateUserIcon(string id, string icon)
|
||||
{
|
||||
var result = await _systemService.UpdateUserIcon(id,icon);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpGet("user/update/state")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateUserState(string id, int state)
|
||||
{
|
||||
var result = await _systemService.UpdateUserState(id, state);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpGet("user/delete")]
|
||||
|
||||
public async Task<BaseResponse<string>> DeleteUser(string id)
|
||||
{
|
||||
var result = await _systemService.DeleteUser(id);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpGet("user/login")]
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<AdminUserToken>> UserLogin(string userName, string password)
|
||||
{
|
||||
var result = await _systemService.UserLogin(userName, password);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.model);
|
||||
else
|
||||
return this.ToFailResult<AdminUserToken>(result.msg);
|
||||
}
|
||||
[HttpPost("user/list")]
|
||||
|
||||
public async Task<PageResponse<SystemUserDto>> GetUserList(GetUserListParam param)
|
||||
{
|
||||
var result = await _systemService.GetUserList(param);
|
||||
var dtos = result.list.Select(MapToSystemUserDto).ToList();
|
||||
return this.ToPageResult(dtos, (int)result.count);
|
||||
}
|
||||
|
||||
[HttpGet("user/getuser")]
|
||||
|
||||
public async Task<BaseResponse<SystemUserDto>> GetUser()
|
||||
{
|
||||
if (string.IsNullOrEmpty(loginUser.UserId))
|
||||
return this.ToFailResult<SystemUserDto>("用户未登录");
|
||||
var result = await _systemService.GetUser(loginUser.UserId);
|
||||
if (result == null)
|
||||
return this.ToFailResult<SystemUserDto>("用户不存在");
|
||||
return this.ToResult(MapToSystemUserDto(result));
|
||||
}
|
||||
|
||||
private static SystemUserDto MapToSystemUserDto(SystemUser entity)
|
||||
{
|
||||
if (entity == null) return new SystemUserDto();
|
||||
return new SystemUserDto
|
||||
{
|
||||
Id = entity.Id ?? "",
|
||||
UserName = entity.UserName ?? "",
|
||||
DisplayName = entity.DisplayName ?? "",
|
||||
Icon = entity.Icon ?? "",
|
||||
RegisterTime = entity.RegisterTime,
|
||||
State = entity.State,
|
||||
RoleId = entity.SystemRole?.Id ?? "",
|
||||
RoleName = entity.SystemRole?.Name ?? ""
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet("user/nav")]
|
||||
|
||||
public async Task<ListResponse<SystemNavigationResponse>> GetUserNav()
|
||||
{
|
||||
if (string.IsNullOrEmpty(loginUser.UserId))
|
||||
return this.ToListFailResult<SystemNavigationResponse>("用户未登录");
|
||||
var result = await _systemService.GetUserNav(this.loginUser);
|
||||
if (result == null)
|
||||
return this.ToListFailResult<SystemNavigationResponse>("获取菜单失败");
|
||||
return this.ToListResult(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost("role/add")]
|
||||
|
||||
public async Task<BaseResponse<string>> AddRole(AddRoleParam param)
|
||||
{
|
||||
var result = await _systemService.AddRole(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpPost("role/update")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateRole(UpdateRoleParam param)
|
||||
{
|
||||
var result = await _systemService.UpdateRole(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpPost("role/updatenav")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateRoleNav(UpdateRoleNavParam param)
|
||||
{
|
||||
var result = await _systemService.UpdateRoleNav(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpGet("role/delete")]
|
||||
|
||||
public async Task<BaseResponse<string>> DeleteRole(string id)
|
||||
{
|
||||
var result = await _systemService.DeleteRole(id);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpGet("role/list")]
|
||||
public async Task<ListResponse<SystemUserRoleDto>> GetRoleList(int page, int limit)
|
||||
{
|
||||
var result = await _systemService.GetRoleList();
|
||||
var dtos = result.Select(MapToSystemUserRoleDto).ToList();
|
||||
return this.ToListResult(dtos);
|
||||
}
|
||||
|
||||
private static SystemUserRoleDto MapToSystemUserRoleDto(SystemUserRole entity)
|
||||
{
|
||||
if (entity == null) return new SystemUserRoleDto();
|
||||
return new SystemUserRoleDto
|
||||
{
|
||||
Id = entity.Id ?? "",
|
||||
RoleName = entity.RoleName ?? "",
|
||||
Description = entity.Description ?? "",
|
||||
NavIds = entity.NavIds ?? new List<string>()
|
||||
};
|
||||
}
|
||||
[HttpGet("role/get")]
|
||||
|
||||
public async Task<BaseResponse<SystemUserRoleDto>> GetUserRole(string id)
|
||||
{
|
||||
var result = await _systemService.GetUserRole(id);
|
||||
return this.ToResult(MapToSystemUserRoleDto(result));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[HttpPost("nav/add")]
|
||||
|
||||
public async Task<BaseResponse<string>> AddNav(AddNavParam param)
|
||||
{
|
||||
var result = await _systemService.AddNav(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpPost("nav/update")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateNav(UpdateNavParam param)
|
||||
{
|
||||
var result = await _systemService.UpdateNav(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpGet("nav/delete")]
|
||||
|
||||
public async Task<BaseResponse<string>> DeleteNav(string id)
|
||||
{
|
||||
var result = await _systemService.DeleteNav(id);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("nav/list")]
|
||||
|
||||
public async Task<ListResponse<SystemNavigationResponse>> GetNavList(string? id="")
|
||||
{
|
||||
var result = await _systemService.GetNavList(id);
|
||||
return this.ToListResult(result);
|
||||
}
|
||||
|
||||
|
||||
public class SystemUserDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public DateTime RegisterTime { get; set; }
|
||||
public int State { get; set; }
|
||||
public string RoleId { get; set; }
|
||||
public string RoleName { get; set; }
|
||||
}
|
||||
|
||||
public class SystemUserRoleDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string RoleName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public List<string> NavIds { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost("dic/add")]
|
||||
|
||||
public async Task<BaseResponse<string>> AddDic(AddDicParam param)
|
||||
{
|
||||
var result = await _systemService.AddDic(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
[HttpPost("dic/update")]
|
||||
|
||||
public async Task<BaseResponse<string>> UpdateDic(UpdateDicParam param)
|
||||
{
|
||||
var result = await _systemService.UpdateDic(param);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpGet("dic/delete")]
|
||||
|
||||
public async Task<BaseResponse<string>> DeleteDic(string id)
|
||||
{
|
||||
var result = await _systemService.DeleteDic(id);
|
||||
if (result.isok)
|
||||
return this.ToResult(result.msg);
|
||||
else
|
||||
return this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("dic/list")]
|
||||
|
||||
public async Task<ListResponse<SystemDicResponse>> GetDicList(string id="")
|
||||
{
|
||||
var result = await _systemService.GetDicList(id);
|
||||
return this.ToListResult(result);
|
||||
}
|
||||
[HttpGet("dic/list/code")]
|
||||
|
||||
public async Task<ListResponse<SystemDicResponse>> GetDicListByCode(string code)
|
||||
{
|
||||
var result = await _systemService.GetDicListByCode(code);
|
||||
return this.ToListResult(result);
|
||||
}
|
||||
[HttpGet("dic/get/code")]
|
||||
|
||||
public async Task<BaseResponse<SystemDic>> GetDictByCode(string code)
|
||||
{
|
||||
var result = await _systemService.GetDictByCode(code);
|
||||
return this.ToResult(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user