fix 用户和菜单权限联合
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.7" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.User.Api\Dlhis.User.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -6,17 +6,17 @@ EXPOSE 80
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Src/Dlhis.Permission/Dlhis.Permission.csproj", "Src/Dlhis.Permission/"]
|
||||
COPY ["Src/Dlhis.Sys/Dlhis.Sys.csproj", "Src/Dlhis.Sys/"]
|
||||
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
|
||||
RUN dotnet restore "Src/Dlhis.Permission/Dlhis.Permission.csproj"
|
||||
RUN dotnet restore "Src/Dlhis.Sys/Dlhis.Sys.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Src/Dlhis.Permission"
|
||||
RUN dotnet build "Dlhis.Permission.csproj" -c Release -o /app/build
|
||||
WORKDIR "/src/Src/Dlhis.Sys"
|
||||
RUN dotnet build "Dlhis.Sys.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Dlhis.Permission.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
RUN dotnet publish "Dlhis.Sys.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Dlhis.Permission.dll"]
|
||||
ENTRYPOINT ["dotnet", "Dlhis.Sys.dll"]
|
||||
@@ -8,6 +8,9 @@ using Dlhis.Entity.Sys.Enums;
|
||||
|
||||
namespace Dlhis.Sys.Menu.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 菜单
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
@@ -23,14 +26,11 @@ public class MenusController : ControllerBase
|
||||
/// <summary>
|
||||
/// 菜单列表
|
||||
/// </summary>
|
||||
/// <param name="platform">菜单平台类型 PlatformEnumType</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public async Task<List<MenuResponse>> GetListAsync([EnumDataType(typeof(PlatformEnumType))] PlatformEnumType? platform)
|
||||
public async Task<List<MenuResponse>> GetListAsync([EnumDataType(typeof(PlatformEnumType))] PlatformEnumType? platform = PlatformEnumType.PCAdmin)
|
||||
{
|
||||
if (!platform.HasValue)
|
||||
{
|
||||
platform = PlatformEnumType.UserMobile;
|
||||
}
|
||||
return await _menuService.GetListAsync(platform.Value);
|
||||
}
|
||||
|
||||
@@ -59,17 +59,19 @@ public class MenusController : ControllerBase
|
||||
/// <summary>
|
||||
/// 当前类型的权限分配
|
||||
/// </summary>
|
||||
/// <param name="permissionType">权限类型</param>
|
||||
/// <param name="uniqueType">权限分配类型 MenuAssignmentTypeEnumType</param>
|
||||
/// <param name="uniqueValue">类型对应的唯一值</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("assignments")]
|
||||
public async Task<List<string>> GetAssignmentsAsync([EnumDataType(typeof(MenuPermissionTypeEnumType))] MenuPermissionTypeEnumType permissionType, [Required] string uniqueValue)
|
||||
public async Task<List<string>> GetAssignmentsAsync(
|
||||
[EnumDataType(typeof(MenuAssignmentTypeEnumType))] MenuAssignmentTypeEnumType uniqueType,
|
||||
[Required] string uniqueValue)
|
||||
{
|
||||
return await _menuService.GetAssignmentCodesAsync(permissionType, uniqueValue);
|
||||
return await _menuService.GetAssignmentCodesAsync(uniqueType, uniqueValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有权限分配
|
||||
/// 获取我的所有权限
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("assignments/all")]
|
||||
@@ -79,7 +81,7 @@ public class MenusController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 我的菜单
|
||||
/// 获取我的菜单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("my")]
|
||||
@@ -89,7 +91,7 @@ public class MenusController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置
|
||||
/// 重置所有路由
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace Dlhis.Sys.Menu.Request;
|
||||
public class MenuPermissionAssignmentRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限类型
|
||||
/// 权限类型 MenuAssignmentTypeEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(MenuPermissionTypeEnumType))]
|
||||
public MenuPermissionTypeEnumType UniqueType { get; set; }
|
||||
[EnumDataType(typeof(MenuAssignmentTypeEnumType))]
|
||||
public MenuAssignmentTypeEnumType UniqueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一值
|
||||
|
||||
@@ -60,13 +60,13 @@ public class SaveMenuRequest : IValidatableObject
|
||||
public int Sequence { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单类型
|
||||
/// 菜单类型 MenuEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(MenuEnumType))]
|
||||
public MenuEnumType MenuType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 平台
|
||||
/// 平台 PlatformEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(PlatformEnumType))]
|
||||
public PlatformEnumType Platform { get; set; }
|
||||
|
||||
@@ -68,12 +68,6 @@ public class MenuResponse
|
||||
/// </summary>
|
||||
public PlatformEnumType Platform { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 手机端才会有
|
||||
/// </summary>
|
||||
public List<string> HotelIds { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 子菜单
|
||||
/// </summary>
|
||||
|
||||
@@ -5,7 +5,7 @@ using Dlhis.Sys.Menu.Response;
|
||||
|
||||
namespace Dlhis.Sys.Menu.Services;
|
||||
|
||||
public interface IMenuService
|
||||
public interface IMenuService : IScopeDependency
|
||||
{
|
||||
Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform);
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface IMenuService
|
||||
|
||||
Task AssignmentAsync(MenuPermissionAssignmentRequest request);
|
||||
|
||||
Task<List<string>> GetAssignmentCodesAsync(MenuPermissionTypeEnumType permissionType, string uniqueData);
|
||||
Task<List<string>> GetAssignmentCodesAsync(MenuAssignmentTypeEnumType permissionType, string uniqueData);
|
||||
|
||||
Task<List<string>> GetAllAssignmentPermissionsAsync();
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Dlhis.Sys.Menu.Request;
|
||||
using Dlhis.Sys.Menu.Response;
|
||||
using Dlhis.User.Api;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Attributes;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
@@ -13,11 +15,13 @@ public class MenuService : IMenuService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IUserApi _userApi;
|
||||
|
||||
public MenuService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public MenuService(IDbContext dbContext, ICurrentUser currentUser, IUserApi userApi)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_userApi = userApi;
|
||||
}
|
||||
|
||||
public async Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform)
|
||||
@@ -37,6 +41,7 @@ public class MenuService : IMenuService
|
||||
return top;
|
||||
}
|
||||
|
||||
[Transactional]
|
||||
public async Task SaveMenuAsync(SaveMenuRequest request)
|
||||
{
|
||||
await CheckAsync(request);
|
||||
@@ -57,27 +62,9 @@ public class MenuService : IMenuService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task ChangeIfCodeEditAsync(string beforeCode, string pcode)
|
||||
{
|
||||
if (beforeCode != pcode)
|
||||
{
|
||||
//修改下级的PCode为当前的code
|
||||
var menus = await _dbContext.Queryable<MenuEntity>().Where(x => x.PCode == beforeCode).ToListAsync();
|
||||
menus.ForEach(x => { x.PCode = pcode; });
|
||||
|
||||
//修改权限code为当前的code,避免权限丢失
|
||||
var permissions = await _dbContext.Queryable<MenuPermissionEntity>().Where(x => x.Code == beforeCode).ToListAsync();
|
||||
permissions.ForEach(x => { x.Code = pcode; });
|
||||
|
||||
await _dbContext.UpdateAsync(menus);
|
||||
await _dbContext.UpdateAsync(permissions);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task AssignmentAsync(MenuPermissionAssignmentRequest request)
|
||||
{
|
||||
(request.UniqueType == MenuPermissionTypeEnumType.Role).ThrowIfTrue("暂不支持角色分配");
|
||||
(request.UniqueType == MenuAssignmentTypeEnumType.Role).ThrowIfTrue("暂不支持角色分配");
|
||||
|
||||
//清空覆盖
|
||||
var permissionsToDelete = await _dbContext.Queryable<MenuPermissionEntity>()
|
||||
@@ -98,15 +85,57 @@ public class MenuService : IMenuService
|
||||
await _dbContext.InsertAsync(permissions);
|
||||
}
|
||||
|
||||
public Task<List<string>> GetAssignmentCodesAsync(MenuPermissionTypeEnumType permissionType, string uniqueData)
|
||||
public async Task<List<string>> GetAssignmentCodesAsync(MenuAssignmentTypeEnumType uniqueType, string uniqueData)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var permissionCodes = await _dbContext.Queryable<MenuPermissionEntity>()
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.UniqueValue == uniqueData)
|
||||
.Select(x => x.Code)
|
||||
.ToListAsync();
|
||||
|
||||
var menus = await GetListAsync(PlatformEnumType.PCAdmin);
|
||||
|
||||
foreach (var menu in menus)
|
||||
{
|
||||
if (menu.Items.Any())
|
||||
{
|
||||
var codes = RecursionHandler(menu.Items, permissionCodes);
|
||||
permissionCodes.RemoveAll(x => codes.Contains(x));
|
||||
}
|
||||
}
|
||||
|
||||
return permissionCodes;
|
||||
|
||||
static List<string> RecursionHandler(List<MenuResponse> menus, List<string> innerPermissions)
|
||||
{
|
||||
var codes = new HashSet<string>();
|
||||
foreach (var menu in menus)
|
||||
{
|
||||
if (menu.Items.Any())
|
||||
{
|
||||
var innerPermissionCodes = RecursionHandler(menu.Items, innerPermissions);
|
||||
foreach (var item in innerPermissionCodes)
|
||||
{
|
||||
codes.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (!innerPermissions.Contains(menu.Code))
|
||||
{
|
||||
foreach (var item in menu.Items.Select(x => x.Code))
|
||||
{
|
||||
codes.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return codes.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetAllAssignmentPermissionsAsync()
|
||||
{
|
||||
var all = await GetAllAssignmentCodesAsync();
|
||||
|
||||
return await _dbContext.Queryable<MenuEntity>().Where(x => all.Contains(x.Code)).Select(x => x.Permission).ToListAsync();
|
||||
}
|
||||
|
||||
@@ -238,20 +267,34 @@ public class MenuService : IMenuService
|
||||
|
||||
private async Task<List<string>> GetAllAssignmentCodesAsync()
|
||||
{
|
||||
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == _currentUser.GetIntSubjectId()).FirstAsync();
|
||||
if (user == null)
|
||||
var userApiResult = await _userApi.GetUserByIdAsync(_currentUser.GetIntSubjectId());
|
||||
(userApiResult.Code == Kurisu.Core.Result.ApiStateCode.Success).ThrowIfFalse(userApiResult.Msg);
|
||||
var user = userApiResult.Data;
|
||||
|
||||
// var groupCodes = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.Group, manager.usergrp);
|
||||
|
||||
//user
|
||||
var userCodes = await GetAssignmentCodesAsync(MenuAssignmentTypeEnumType.User, user.Id.ToString());
|
||||
var all = userCodes;// gP.Concat(uP).Distinct().ToList();
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
private async Task ChangeIfCodeEditAsync(string beforeCode, string pcode)
|
||||
{
|
||||
if (beforeCode != pcode)
|
||||
{
|
||||
return new List<string>();
|
||||
//修改下级的PCode为当前的code
|
||||
var menus = await _dbContext.Queryable<MenuEntity>().Where(x => x.PCode == beforeCode).ToListAsync();
|
||||
menus.ForEach(x => { x.PCode = pcode; });
|
||||
|
||||
//修改权限code为当前的code,避免权限丢失
|
||||
var permissions = await _dbContext.Queryable<MenuPermissionEntity>().Where(x => x.Code == beforeCode).ToListAsync();
|
||||
permissions.ForEach(x => { x.Code = pcode; });
|
||||
|
||||
await _dbContext.UpdateAsync(menus);
|
||||
await _dbContext.UpdateAsync(permissions);
|
||||
}
|
||||
|
||||
// var gP = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.Group, manager.usergrp);
|
||||
//
|
||||
// //user
|
||||
// var uP = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.User, manager.account);
|
||||
// var all = gP.Concat(uP).Distinct().ToList();
|
||||
|
||||
//return all;
|
||||
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.Startup;
|
||||
|
||||
namespace Dlhis.Sys
|
||||
namespace Dlhis.Sys;
|
||||
|
||||
class Program
|
||||
{
|
||||
class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
KurisuHost.Run<Startup>(true, args);
|
||||
}
|
||||
KurisuHost.Run<Startup>(true, args);
|
||||
}
|
||||
}
|
||||
|
||||
public class Startup : DefaultStartup
|
||||
public class Startup : DefaultStartup
|
||||
{
|
||||
public Startup(IConfiguration configuration) : base(configuration)
|
||||
{
|
||||
public Startup(IConfiguration configuration) : base(configuration)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Dlhis.Permission": {
|
||||
"Dlhis.Sys": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5003"
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_URLS": "http://+:80"
|
||||
},
|
||||
"publishAllPorts": true
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Src/Dlhis.Sys/SqlSugarPack.cs
Normal file
14
Src/Dlhis.Sys/SqlSugarPack.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
|
||||
namespace Dlhis.Sys;
|
||||
|
||||
public class SqlSugarPack : BaseAppPack
|
||||
{
|
||||
public override bool IsBeforeUseRouting { get; }
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSqlSugar();
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,9 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"InternalRequest": {
|
||||
"CommonRequestUrl": "http://common",
|
||||
"UserRequestUrl": "http://localhost:5010"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,26 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"InternalRequest": {
|
||||
"CommonRequestUrl": "http://common",
|
||||
"UserRequestUrl": "http://user"
|
||||
},
|
||||
"SqlSugarOptions": {
|
||||
"DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;",
|
||||
"SlaveConnectionString": [],
|
||||
"Timeout": 30,
|
||||
"SlowSqlTime": 1,
|
||||
"EnableSqlLog": true
|
||||
},
|
||||
"SwaggerOptions": {
|
||||
"Enable": true,
|
||||
"Authority": "https://yikatong.isawesome.cn/oauth2",
|
||||
"ClientId": "4fb184324eac4180",
|
||||
"ClientSecret": "8ac8f235152f1524",
|
||||
"Scopes": {
|
||||
"openid": "openid"
|
||||
"openid": "openid",
|
||||
"profile": "profile",
|
||||
"yikatong": "yikatong"
|
||||
}
|
||||
},
|
||||
"IdentityServerOptions": {
|
||||
|
||||
13
Src/Dlhis.User.Api/Dlhis.User.Api.csproj
Normal file
13
Src/Dlhis.User.Api/Dlhis.User.Api.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.RemoteCall" Version="0.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
13
Src/Dlhis.User.Api/IUserApi.cs
Normal file
13
Src/Dlhis.User.Api/IUserApi.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Dlhis.User.Api.Response;
|
||||
using Kurisu.Core.Result;
|
||||
using Kurisu.RemoteCall.Attributes;
|
||||
|
||||
namespace Dlhis.User.Api;
|
||||
|
||||
[EnableRemoteClient(Name = "user-service", BaseUrl = "${InternalRequest:UserRequestUrl}")]
|
||||
public interface IUserApi
|
||||
{
|
||||
[Auth]
|
||||
[Get("/api/users")]
|
||||
Task<DefaultApiResult<UserResponse>> GetUserByIdAsync(int id);
|
||||
}
|
||||
28
Src/Dlhis.User.Api/Response/UserResponse.cs
Normal file
28
Src/Dlhis.User.Api/Response/UserResponse.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Dlhis.User.Api.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 string PhoneNumberConfirmed { get; set; }
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
|
||||
public bool LockoutEnd { get; set; }
|
||||
|
||||
public bool LockoutEnabled { get; set; }
|
||||
|
||||
public int AccessFailedCount { get; set; }
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>..\..</DockerfileContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.User.Identity.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 角色
|
||||
/// </summary>
|
||||
[Authorize(Roles = "admin")]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
@@ -19,6 +22,11 @@ public class RolesController : ControllerBase
|
||||
_roleService = roleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Pagination<RoleRespone>> GetPageAsync(RolePageRequest request)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.User.Identity.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
[Authorize(Roles = "admin")]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
@@ -29,4 +32,21 @@ public class UsersController : ControllerBase
|
||||
{
|
||||
return await _userService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public async Task<List<UserResponse>> GetUsersAsync()
|
||||
{
|
||||
return await _userService.GetUsersAsync();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public async Task<UserResponse> GetUserByIdAsync(int id)
|
||||
{
|
||||
return await _userService.GetUserByIdAsync(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,8 @@ public interface IUserService : IScopeDependency
|
||||
Task<Pagination<UserResponse>> GetPageAsync(UserPageRequest request);
|
||||
|
||||
Task ResetAccessFailedCountAsync(int id);
|
||||
|
||||
Task<List<UserResponse>> GetUsersAsync();
|
||||
|
||||
Task<UserResponse> GetUserByIdAsync(int id);
|
||||
}
|
||||
|
||||
@@ -38,4 +38,17 @@ public class UserService : IUserService
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
{
|
||||
"profiles": {
|
||||
"Dlhis.User": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5010",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5010"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json"
|
||||
}
|
||||
Reference in New Issue
Block a user