From cd31e3fc58af1796d306324d17df6211984a73cb Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 10 Jan 2024 11:44:59 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BA=BA=E4=BA=8B=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Dlhis.Basic.csproj | 1 + .../Controllers/WerksController.cs | 5 ++- .../Organization/Response/WerkResponse.cs | 23 ---------- .../Organization/Services/IWerkService.cs | 6 +-- .../Services/Implements/WerkService.cs | 34 ++++++++------- Src/Dlhis.Basic/SqlSugarPack.cs | 5 ++- Src/Dlhis.Basic/appsettings.Development.json | 3 +- Src/Dlhis.Basic/appsettings.json | 3 +- .../Properties/launchSettings.json | 8 ---- Src/Dlhis.Sys/appsettings.Development.json | 4 +- Src/Dlhis.User.Api/ITenantApi.cs | 14 +++++++ Src/Dlhis.User.Api/Response/TenantResponse.cs | 10 +++++ Src/Dlhis.User/Dlhis.User.csproj | 1 + .../Identity/Controllers/TenantsController.cs | 42 +++++++++++++++++++ .../Identity/Request/TenantPageRequest.cs | 8 ++++ .../Identity/Response/TenantResponse.cs | 10 +++++ .../Identity/Services/ITenantService.cs | 12 ++++++ .../Services/Implements/RoleService.cs | 27 ++++++++++++ .../Services/Implements/TenantService.cs | 34 +++++++++++++++ Src/Dlhis.User/Properties/launchSettings.json | 2 +- Src/Dlhis.User/appsettings.Development.json | 1 - Src/Dlhis.User/appsettings.json | 1 - 22 files changed, 195 insertions(+), 59 deletions(-) delete mode 100644 Src/Dlhis.Basic/Organization/Response/WerkResponse.cs create mode 100644 Src/Dlhis.User.Api/ITenantApi.cs create mode 100644 Src/Dlhis.User.Api/Response/TenantResponse.cs create mode 100644 Src/Dlhis.User/Identity/Controllers/TenantsController.cs create mode 100644 Src/Dlhis.User/Identity/Request/TenantPageRequest.cs create mode 100644 Src/Dlhis.User/Identity/Response/TenantResponse.cs create mode 100644 Src/Dlhis.User/Identity/Services/ITenantService.cs create mode 100644 Src/Dlhis.User/Identity/Services/Implements/RoleService.cs create mode 100644 Src/Dlhis.User/Identity/Services/Implements/TenantService.cs diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index d70ce740..d1819b46 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -23,6 +23,7 @@ + diff --git a/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs b/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs index bf6b57ca..5f7522dd 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs @@ -1,5 +1,6 @@ using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; +using Dlhis.User.Api.Response; using Kurisu.AspNetCore.MVC; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -27,7 +28,7 @@ public class WerksController : ControllerBase /// /// [HttpGet("list")] - public async Task> GetListAsync() + public async Task> GetListAsync() { return await _werkService.GetListAsync(); } @@ -37,7 +38,7 @@ public class WerksController : ControllerBase /// /// [HttpGet("current")] - public async Task GetCurrentAsync() + public async Task GetCurrentAsync() { return await _werkService.GetCurrentAsync(); } diff --git a/Src/Dlhis.Basic/Organization/Response/WerkResponse.cs b/Src/Dlhis.Basic/Organization/Response/WerkResponse.cs deleted file mode 100644 index 9ab6f83e..00000000 --- a/Src/Dlhis.Basic/Organization/Response/WerkResponse.cs +++ /dev/null @@ -1,23 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Basic.Organization.Response; - -public class WerkResponse -{ - public long Id { get; set; } - - /// - /// 代号 - /// - public string Code { get; set; } - - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 是否可见 - /// - public bool Visible { get; set; } -} diff --git a/Src/Dlhis.Basic/Organization/Services/IWerkService.cs b/Src/Dlhis.Basic/Organization/Services/IWerkService.cs index 0114d2e7..8f8ecc4b 100644 --- a/Src/Dlhis.Basic/Organization/Services/IWerkService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IWerkService.cs @@ -1,10 +1,10 @@ -using Dlhis.Basic.Organization.Response; +using Dlhis.User.Api.Response; namespace Dlhis.Basic.Organization.Services; public interface IWerkService : IScopeDependency { - Task> GetListAsync(); + Task> GetListAsync(); - Task GetCurrentAsync(); + Task GetCurrentAsync(); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs index e9982a88..7af7ff74 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs @@ -1,34 +1,38 @@ -using Dlhis.Basic.Organization.Response; -using Dlhis.Entity.Basic.Entity; +using Dlhis.User.Api; +using Dlhis.User.Api.Response; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.Result; using Kurisu.Core.User.Abstractions; -using Kurisu.SqlSugar.Services; namespace Dlhis.Basic.Organization.Services.Implements; public class WerkService : IWerkService { - private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; + private readonly ITenantApi _tenantApi; - public WerkService(IDbContext dbContext, ICurrentUser currentUser) + public WerkService(ICurrentUser currentUser, ITenantApi tenantApi) { - _dbContext = dbContext; _currentUser = currentUser; + _tenantApi = tenantApi; } - public async Task> GetListAsync() + public async Task> GetListAsync() { - return await _dbContext.Queryable() - .Select() - .ToListAsync(); + var tenantResult = await _tenantApi.GetTenantsAsync(); + (tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg); + + var tenants = tenantResult.Data; + return tenants; } - public async Task GetCurrentAsync() + public async Task GetCurrentAsync() { var tenant = _currentUser.GetStringTenantId(); - return await _dbContext.Queryable() - .Where(x => x.Code == tenant) - .Select() - .FirstAsync(); + var tenantResult = await _tenantApi.GetTenantsAsync(); + (tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg); + + var tenants = tenantResult.Data; + return tenants.FirstOrDefault(x => x.Code == tenant); } } diff --git a/Src/Dlhis.Basic/SqlSugarPack.cs b/Src/Dlhis.Basic/SqlSugarPack.cs index 3145a868..5adc1505 100644 --- a/Src/Dlhis.Basic/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/SqlSugarPack.cs @@ -19,7 +19,10 @@ public class SqlSugarPack : BaseAppPack #if DEBUG using var scope = app.ApplicationServices.CreateScope(); var db = scope.ServiceProvider.GetService(); - var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray(); + var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)) + .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false)) + .ToArray(); + db.DbMaintenance.CreateDatabase(); db.CodeFirst.InitTables(tables); #endif diff --git a/Src/Dlhis.Basic/appsettings.Development.json b/Src/Dlhis.Basic/appsettings.Development.json index 20ab3f6d..e5eed0cf 100644 --- a/Src/Dlhis.Basic/appsettings.Development.json +++ b/Src/Dlhis.Basic/appsettings.Development.json @@ -6,7 +6,8 @@ } }, "InternalRequest": { - "CommonRequestUrl": "http://localhost:5001" + "CommonRequestUrl": "http://localhost:5001", + "UserRequestUrl": "http://localhost:5004" }, "SwaggerOptions": { "Enable": true, diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index c244b003..1b5c78f0 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -7,7 +7,8 @@ }, "AllowedHosts": "*", "InternalRequest": { - "CommonRequestUrl": "http://common" + "CommonRequestUrl": "http://common", + "UserRequestUrl": "http://user" }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", diff --git a/Src/Dlhis.ScheduledTask/Properties/launchSettings.json b/Src/Dlhis.ScheduledTask/Properties/launchSettings.json index 4f4a7b14..fd368e29 100644 --- a/Src/Dlhis.ScheduledTask/Properties/launchSettings.json +++ b/Src/Dlhis.ScheduledTask/Properties/launchSettings.json @@ -6,14 +6,6 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "http://localhost:5010" - }, - "Docker": { - "commandName": "Docker", - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", - "environmentVariables": { - "ASPNETCORE_URLS": "http://+:80" - }, - "publishAllPorts": true } } } \ No newline at end of file diff --git a/Src/Dlhis.Sys/appsettings.Development.json b/Src/Dlhis.Sys/appsettings.Development.json index 18251b98..e5eed0cf 100644 --- a/Src/Dlhis.Sys/appsettings.Development.json +++ b/Src/Dlhis.Sys/appsettings.Development.json @@ -6,8 +6,8 @@ } }, "InternalRequest": { - "CommonRequestUrl": "http://common", - "UserRequestUrl": "http://localhost:5010" + "CommonRequestUrl": "http://localhost:5001", + "UserRequestUrl": "http://localhost:5004" }, "SwaggerOptions": { "Enable": true, diff --git a/Src/Dlhis.User.Api/ITenantApi.cs b/Src/Dlhis.User.Api/ITenantApi.cs new file mode 100644 index 00000000..2a27136e --- /dev/null +++ b/Src/Dlhis.User.Api/ITenantApi.cs @@ -0,0 +1,14 @@ +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 ITenantApi +{ + [Auth] + [Get("/api/tenants/list")] + Task>> GetTenantsAsync(); +} diff --git a/Src/Dlhis.User.Api/Response/TenantResponse.cs b/Src/Dlhis.User.Api/Response/TenantResponse.cs new file mode 100644 index 00000000..1201754e --- /dev/null +++ b/Src/Dlhis.User.Api/Response/TenantResponse.cs @@ -0,0 +1,10 @@ +namespace Dlhis.User.Api.Response; + +public class TenantResponse +{ + public int Id { get; set; } + + public string Code { get; set; } + + public string Name { get; set; } +} diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index 0ff70623..e3bb86f7 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -6,6 +6,7 @@ enable Linux ..\.. + True diff --git a/Src/Dlhis.User/Identity/Controllers/TenantsController.cs b/Src/Dlhis.User/Identity/Controllers/TenantsController.cs new file mode 100644 index 00000000..52b02d55 --- /dev/null +++ b/Src/Dlhis.User/Identity/Controllers/TenantsController.cs @@ -0,0 +1,42 @@ +using Dlhis.User.Identity.Request; +using Dlhis.User.Identity.Response; +using Dlhis.User.Identity.Services; +using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.User.Identity.Controllers; + +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class TenantsController : ControllerBase +{ + private readonly ITenantService _tenantService; + + public TenantsController(ITenantService tenantService) + { + _tenantService = tenantService; + } + + /// + /// 获取租户分页 + /// + /// + /// + [HttpGet("page")] + public async Task> GetPageAsync([FromQuery] TenantPageRequest request) + { + return await _tenantService.GetPageAsync(request); + } + + /// + /// 获取所有租户 + /// + /// + [HttpGet("list")] + public async Task> GetListAsync() + { + return await _tenantService.GetListAsync(); + } +} diff --git a/Src/Dlhis.User/Identity/Request/TenantPageRequest.cs b/Src/Dlhis.User/Identity/Request/TenantPageRequest.cs new file mode 100644 index 00000000..6dbe5a50 --- /dev/null +++ b/Src/Dlhis.User/Identity/Request/TenantPageRequest.cs @@ -0,0 +1,8 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.User.Identity.Request +{ + public class TenantPageRequest : PageDto + { + } +} diff --git a/Src/Dlhis.User/Identity/Response/TenantResponse.cs b/Src/Dlhis.User/Identity/Response/TenantResponse.cs new file mode 100644 index 00000000..46b131c5 --- /dev/null +++ b/Src/Dlhis.User/Identity/Response/TenantResponse.cs @@ -0,0 +1,10 @@ +namespace Dlhis.User.Identity.Response; + +public class TenantResponse +{ + public int Id { get; set; } + + public string Code { get; set; } + + public string Name { get; set; } +} diff --git a/Src/Dlhis.User/Identity/Services/ITenantService.cs b/Src/Dlhis.User/Identity/Services/ITenantService.cs new file mode 100644 index 00000000..72c4bd87 --- /dev/null +++ b/Src/Dlhis.User/Identity/Services/ITenantService.cs @@ -0,0 +1,12 @@ +using Dlhis.User.Identity.Request; +using Dlhis.User.Identity.Response; +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.User.Identity.Services; + +public interface ITenantService : IScopeDependency +{ + Task> GetPageAsync(TenantPageRequest request); + + Task> GetListAsync(); +} diff --git a/Src/Dlhis.User/Identity/Services/Implements/RoleService.cs b/Src/Dlhis.User/Identity/Services/Implements/RoleService.cs new file mode 100644 index 00000000..d501d200 --- /dev/null +++ b/Src/Dlhis.User/Identity/Services/Implements/RoleService.cs @@ -0,0 +1,27 @@ +using Dlhis.Entity.Sys.Entities; +using Dlhis.User.Identity.Request; +using Dlhis.User.Identity.Response; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.User.Identity.Services.Implements; + +public class RoleService : IRoleService +{ + private readonly IDbContext _dbContext; + + public RoleService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task> GetPageAsync(RolePageRequest request) + { + return await _dbContext.Queryable() + .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search)) + .Select() + .ToPageListAsync(request); + } +} diff --git a/Src/Dlhis.User/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.User/Identity/Services/Implements/TenantService.cs new file mode 100644 index 00000000..a6ec9b54 --- /dev/null +++ b/Src/Dlhis.User/Identity/Services/Implements/TenantService.cs @@ -0,0 +1,34 @@ +using Dlhis.Entity.Sys.Entities; +using Dlhis.User.Identity.Request; +using Dlhis.User.Identity.Response; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.User.Identity.Services.Implements; + +public class TenantService : ITenantService +{ + private readonly IDbContext _dbContext; + + public TenantService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task> GetPageAsync(TenantPageRequest request) + { + return await _dbContext.Queryable() + .WhereIF(request.Search.IsPresent(), (tenant) => tenant.Name.Contains(request.Search)) + .Select() + .ToPageListAsync(request); + } + + public async Task> GetListAsync() + { + return await _dbContext.Queryable() + .Select() + .ToListAsync(); + } +} diff --git a/Src/Dlhis.User/Properties/launchSettings.json b/Src/Dlhis.User/Properties/launchSettings.json index 67846e57..5ea15179 100644 --- a/Src/Dlhis.User/Properties/launchSettings.json +++ b/Src/Dlhis.User/Properties/launchSettings.json @@ -6,7 +6,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "http://localhost:5010" + "applicationUrl": "http://localhost:5004" } }, "$schema": "https://json.schemastore.org/launchsettings.json" diff --git a/Src/Dlhis.User/appsettings.Development.json b/Src/Dlhis.User/appsettings.Development.json index d4cafc4f..20ab3f6d 100644 --- a/Src/Dlhis.User/appsettings.Development.json +++ b/Src/Dlhis.User/appsettings.Development.json @@ -16,7 +16,6 @@ "Scopes": { "openid": "openid", "profile": "profile", - "role": "role", "yikatong": "yikatong" } }, diff --git a/Src/Dlhis.User/appsettings.json b/Src/Dlhis.User/appsettings.json index adb68f64..393b8739 100644 --- a/Src/Dlhis.User/appsettings.json +++ b/Src/Dlhis.User/appsettings.json @@ -22,7 +22,6 @@ "Scopes": { "openid": "openid", "profile": "profile", - "role": "role", "yikatong": "yikatong" } },