fix 代码合并,minio上传文件

This commit is contained in:
2024-01-26 18:22:57 +08:00
parent f83afdb4d0
commit 05c2073ea7
57 changed files with 637 additions and 203 deletions

View File

@@ -0,0 +1,35 @@
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Dlhis.User.Identity.Services;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Sys.Identity.Controllers;
/// <summary>
/// 角色
/// </summary>
[Authorize(Roles = "admin")]
[Route("api/[controller]")]
[ApiController]
public class RolesController : ControllerBase
{
private readonly IRoleService _roleService;
public RolesController(IRoleService roleService)
{
_roleService = roleService;
}
/// <summary>
/// 获取角色分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet]
public async Task<Pagination<RoleRespone>> GetPageAsync(RolePageRequest request)
{
return await _roleService.GetPageAsync(request);
}
}

View File

@@ -0,0 +1,64 @@
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Dlhis.Sys.Identity.Services;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Sys.Identity.Controllers;
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class TenantsController : ControllerBase
{
private readonly ITenantService _tenantService;
public TenantsController(ITenantService tenantService)
{
_tenantService = tenantService;
}
/// <summary>
/// 获取租户分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<Pagination<TenantResponse>> GetPageAsync([FromQuery] TenantPageRequest request)
{
return await _tenantService.GetPageAsync(request);
}
/// <summary>
/// 获取所有租户
/// </summary>
/// <returns></returns>
[HttpGet("list")]
public async Task<List<TenantResponse>> GetListAsync()
{
return await _tenantService.GetListAsync();
}
/// <summary>
/// 内部使用接口
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("list-internal")]
public async Task<List<TenantResponse>> GetListInternalAsync()
{
return await _tenantService.GetListAsync();
}
/// <summary>
/// 获取租户
/// </summary>
/// <returns></returns>
[HttpGet("single")]
public async Task<TenantResponse> GetTenantByCode(string code)
{
return await _tenantService.GetTenantByCode(code);
}
}

View File

@@ -0,0 +1,70 @@
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Dlhis.Sys.Identity.Services;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Sys.Identity.Controllers;
/// <summary>
/// 用户
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class UsersController : ControllerBase
{
private readonly IUserService _userService;
public UsersController(IUserService userService)
{
_userService = userService;
}
/// <summary>
/// 用户分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Authorize(Roles = "admin")]
[HttpGet("page")]
public async Task<Pagination<UserResponse>> GetPageAsync([FromQuery] UserPageRequest request)
{
return await _userService.GetPageAsync(request);
}
/// <summary>
/// 获取用户列表
/// </summary>
/// <returns></returns>
[Authorize(Roles = "admin")]
[HttpGet("list")]
public async Task<List<UserResponse>> GetUsersAsync()
{
return await _userService.GetUsersAsync();
}
/// <summary>
/// 根据id获取用户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[Authorize]
[HttpGet]
public async Task<UserResponse> GetUserByIdAsync(int id)
{
return await _userService.GetUserByIdAsync(id);
}
/// <summary>
/// 上传头像
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Authorize]
[HttpPost("avatar")]
public async Task UploadUserAvatarAsync([FromForm] UserAvatarUploadRequest request)
{
await _userService.UploadUserAvatarAsync(request);
}
}

View File

@@ -0,0 +1,10 @@
namespace Dlhis.Sys.Identity.Request;
public class ClientGrantRequest
{
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string Scope { get; set; } = "yikatong";
}

View File

@@ -0,0 +1,7 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Sys.Identity.Request;
public class RolePageRequest : PageDto
{
}

View File

@@ -0,0 +1,8 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Sys.Identity.Request
{
public class TenantPageRequest : PageDto
{
}
}

View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace Dlhis.Sys.Identity.Request;
public class UserAvatarUploadRequest
{
/// <summary>
/// 用户id
/// </summary>
[Range(1, int.MaxValue)]
public int UserNo { get; set; }
/// <summary>
/// 图片地址
/// </summary>
[Required(ErrorMessage = "图片地址不能为空")]
public string Picture { get; set; }
}

View File

@@ -0,0 +1,7 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Sys.Identity.Request;
public class UserPageRequest : PageDto
{
}

View File

@@ -0,0 +1,10 @@
namespace Dlhis.Sys.Identity.Response;
public class RoleRespone
{
public int Id { get; set; }
public string Name { get; set; }
public string NormalizedName { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace Dlhis.Sys.Identity.Response;
public class TenantResponse
{
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}

View File

@@ -0,0 +1,28 @@
namespace Dlhis.Sys.Identity.Response;
public class UserResponse
{
public int Id { get; set; }
public string UserName { get; set; }
public string NormalizedUserName { get; set; }
public string Email { get; set; }
public string NormalizedEmail { get; set; }
public bool EmailConfirmed { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
public bool TwoFactorEnabled { get; set; }
public DateTime? LockoutEnd { get; set; }
public bool LockoutEnabled { get; set; }
public int AccessFailedCount { get; set; }
}

View File

@@ -0,0 +1,10 @@
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Services;
public interface IRoleService : IScopeDependency
{
Task<Pagination<RoleRespone>> GetPageAsync(RolePageRequest request);
}

View File

@@ -0,0 +1,14 @@
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Sys.Identity.Services;
public interface ITenantService : IScopeDependency
{
Task<Pagination<TenantResponse>> GetPageAsync(TenantPageRequest request);
Task<List<TenantResponse>> GetListAsync();
Task<TenantResponse> GetTenantByCode(string code);
}

View File

@@ -0,0 +1,18 @@
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Sys.Identity.Services;
public interface IUserService : IScopeDependency
{
Task<Pagination<UserResponse>> GetPageAsync(UserPageRequest request);
Task ResetAccessFailedCountAsync(int id);
Task<List<UserResponse>> GetUsersAsync();
Task<UserResponse> GetUserByIdAsync(int id);
Task UploadUserAvatarAsync(UserAvatarUploadRequest request);
}

View File

@@ -0,0 +1,28 @@
using Dlhis.Entity.Sys.Entities;
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Dlhis.User.Identity.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
namespace Dlhis.Sys.Identity.Services.Implements;
public class RoleService : IRoleService
{
private readonly IDbContext _dbContext;
public RoleService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<Pagination<RoleRespone>> GetPageAsync(RolePageRequest request)
{
return await _dbContext.Queryable<RoleEntity>()
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search))
.Select<RoleRespone>()
.ToPageListAsync(request);
}
}

View File

@@ -0,0 +1,42 @@
using Dlhis.Entity.Sys.Entities;
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
namespace Dlhis.Sys.Identity.Services.Implements;
public class TenantService : ITenantService
{
private readonly IDbContext _dbContext;
public TenantService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<Pagination<TenantResponse>> GetPageAsync(TenantPageRequest request)
{
return await _dbContext.Queryable<TenantEntity>()
.WhereIF(request.Search.IsPresent(), (tenant) => tenant.Name.Contains(request.Search))
.Select<TenantResponse>()
.ToPageListAsync(request);
}
public async Task<List<TenantResponse>> GetListAsync()
{
return await _dbContext.Queryable<TenantEntity>()
.Select<TenantResponse>()
.ToListAsync();
}
public async Task<TenantResponse> GetTenantByCode(string code)
{
return await _dbContext.Queryable<TenantEntity>()
.Where(x => x.Code == code)
.Select<TenantResponse>()
.FirstAsync();
}
}

View File

@@ -0,0 +1,59 @@
using Dlhis.Entity.Sys.Entities;
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
namespace Dlhis.Sys.Identity.Services.Implements;
public class UserService : IUserService
{
private readonly IDbContext _dbContext;
public UserService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<Pagination<UserResponse>> GetPageAsync(UserPageRequest request)
{
return await _dbContext.Queryable<UserEntity>()
.WhereIF(request.Search.IsPresent(), x => x.UserName.Contains(request.Search)
|| x.NormalizedUserName.Contains(request.Search)
|| x.Email.Contains(request.Search)
|| x.NormalizedEmail.Contains(request.Search)
|| x.PhoneNumber.Contains(request.Search)
)
.Select<UserResponse>()
.ToPageListAsync(request);
}
public async Task ResetAccessFailedCountAsync(int id)
{
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == id).FirstAsync();
user.ThrowIfNull("用户不存在,无法重置");
user.AccessFailedCount = 0;
await _dbContext.UpdateAsync(user);
}
public async Task<List<UserResponse>> GetUsersAsync()
{
//todo tenant
var users = await _dbContext.Queryable<UserEntity>().Select<UserResponse>().ToListAsync();
return users;
}
public async Task<UserResponse> GetUserByIdAsync(int id)
{
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == id).Select<UserResponse>().FirstAsync();
return user;
}
public async Task UploadUserAvatarAsync(UserAvatarUploadRequest request)
{
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserNo).Select<UserResponse>().FirstAsync();
}
}