From 28871aa4505c4dcf2ef1a04a36aef4ad9472ee37 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 1 Feb 2024 17:46:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=8A=9F=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BusinessPlaceShiftService.cs | 7 +++-- .../Device/Controllers/DevicesController.cs | 6 ++--- .../Device/Request/DeviceGroupSaveRequest.cs | 8 +++--- .../Device/Request/DevicePageRequest.cs | 15 ++++++----- .../Device/Request/DeviceSaveRequest.cs | 8 +++--- .../Device/Response/DevicePageResponse.cs | 4 +-- .../Services/Implements/DeviceGroupService.cs | 24 +++++++++++++++-- .../Services/Implements/DeviceService.cs | 14 ++++++++++ .../Services/Implements/WerkService.cs | 2 +- .../Properties/launchSettings.json | 10 +------ Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 6 ++--- .../Device/Entities/DeviceGroupEntity.cs | 4 +-- ...ctionEnumType.cs => DeviceTypeEnumType.cs} | 17 +++++------- .../Sys/Entities/UserTenantEntity.cs | 16 +++++++++++ .../Request/DeviceUploadLogUploadRequest.cs | 4 +-- .../Implements/DeviceUploadLogService.cs | 18 ++++++++++++- .../Services/Implements/JinkoSapService.cs | 2 +- Src/Dlhis.Sys.Api/ITenantApi.cs | 10 ++++++- Src/Dlhis.Sys.Api/IUserApi.cs | 2 +- .../Identity/Controllers/TenantsController.cs | 9 +++++++ .../Identity/Services/ITenantService.cs | 2 ++ .../Services/Implements/TenantService.cs | 27 ++++++++++++++++++- Src/Dlhis.User/Properties/launchSettings.json | 8 ++++++ 23 files changed, 164 insertions(+), 59 deletions(-) rename Src/Dlhis.Entity/Device/Enums/{DeviceGroupFunctionEnumType.cs => DeviceTypeEnumType.cs} (59%) create mode 100644 Src/Dlhis.Entity/Sys/Entities/UserTenantEntity.cs diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index d856a3bd..aa263e38 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -2,12 +2,11 @@ using Dlhis.Basic.BusinessShift.Request; using Dlhis.Basic.BusinessShift.Response; using Dlhis.Entity.Basic.Entity; -using Dlhis.User.Api; +using Dlhis.Sys.Api; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.CustomClass; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.Result; -using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; @@ -30,8 +29,8 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService { var page = await _dbContext.Queryable() .LeftJoin((shift, place) => shift.BusinessPlaceCode == place.Code) - .LeftJoin((shift, place,type)=>shift.Code.ToString() == type.Code) - .WhereIF(request.Search.IsPresent(), (shift, place) => shift.CustomCode.Contains(request.Search) ) + .LeftJoin((shift, place, type) => shift.Code.ToString() == type.Code) + .WhereIF(request.Search.IsPresent(), (shift, place) => shift.CustomCode.Contains(request.Search)) .WhereIF(request.BusinessPlaceCode.HasValue, (shift, place) => shift.BusinessPlaceCode == request.BusinessPlaceCode) .Select((shift, place, type) => new BusinessPlaceShiftResponse { diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 0fc36ce8..dc903205 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -20,9 +20,9 @@ public class DevicesController : ControllerBase private readonly IDeviceConnectService _deviceConnectService; private readonly IConfiguration _configuration; - public DevicesController(IDeviceService deviceService, - IDeviceTemplateService deviceTemplateService, - IDeviceConnectService deviceConnectService, + public DevicesController(IDeviceService deviceService, + IDeviceTemplateService deviceTemplateService, + IDeviceConnectService deviceConnectService, IConfiguration configuration) { _deviceService = deviceService; diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs index 2dc8e5b2..35240dac 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs @@ -19,9 +19,9 @@ public class DeviceGroupSaveRequest public string Name { get; set; } /// - /// 设备组功能类型 + /// 分类类型 DeviceTypeEnumType /// - [Required(ErrorMessage = "设备组功能类型不能为空")] - [EnumDataType(typeof(DeviceGroupFunctionEnumType))] - public DeviceGroupFunctionEnumType Type { get; set; } + [Required(ErrorMessage = "分类不能为空")] + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType Type { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Request/DevicePageRequest.cs b/Src/Dlhis.Basic/Device/Request/DevicePageRequest.cs index f3b9da48..e8acbe7f 100644 --- a/Src/Dlhis.Basic/Device/Request/DevicePageRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DevicePageRequest.cs @@ -1,16 +1,19 @@ -using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Device.Enums; +using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Device.Request; public class DevicePageRequest : PageDto { /// - /// 平台 + /// 品牌 /// public string Brand { get; set; } - /// - /// 设备唯一号 - /// - public string UniqueNo { get; set; } + /// + /// 设备分类 DeviceTypeEnumType + /// + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType? Type { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs index 02f923c1..10b3a65b 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs @@ -33,11 +33,11 @@ public class DeviceSaveRequest public List Funcs { get; set; } /// - /// 设备机功能类型 + /// 设备类型 DeviceTypeEnumType /// - [Required(ErrorMessage = "设备机功能类型不能为空")] - [EnumDataType(typeof(DeviceGroupFunctionEnumType))] - public DeviceGroupFunctionEnumType Type { get; set; } + [Required(ErrorMessage = "设备类型不能为空")] + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType Type { get; set; } /// /// 心跳间隔 diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index b2869e94..448e34e9 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -1,7 +1,5 @@ using Dlhis.Entity.Device.Enums; -using Google.Protobuf.WellKnownTypes; using Kurisu.AspNetCore.Utils.Extensions; -using System.ComponentModel.DataAnnotations; namespace Dlhis.Basic.Device.Response; @@ -52,7 +50,7 @@ public class DevicePageResponse /// /// 设备机功能类型 /// - public DeviceGroupFunctionEnumType Type { get; set; } + public DeviceTypeEnumType Type { get; set; } public string TypeDescription => Type.GetDescription(); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index f183213f..3047dc21 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -80,6 +80,7 @@ public class DeviceGroupService : IDeviceGroupService group.ThrowIfNull("设备组不存在"); await CheckNoNextGroupAsync(group.Code); + await CheckGroupTypeMatchAsync(request, group); //下发任务 await _devicePermissionService.GenerateDeviceTasksAsync(async () => @@ -87,7 +88,7 @@ public class DeviceGroupService : IDeviceGroupService var relationships = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); await _dbContext.DeleteAsync(relationships); - request.DeviceCodes = await _dbContext.Queryable().Where(x => request.DeviceCodes.Contains(x.Code)).Select(x => x.Code).ToListAsync(); + var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity { GroupCode = request.GroupCode, @@ -115,7 +116,7 @@ public class DeviceGroupService : IDeviceGroupService /****************************************************** help methods *********************************************************/ /// - /// 检查 + /// 检查父级分组存在设备 /// /// /// @@ -139,6 +140,25 @@ public class DeviceGroupService : IDeviceGroupService exists.ThrowIfTrue("存在下级设备分组"); } + /// + /// 检查分组分类匹配 + /// + /// + /// + /// + private async Task CheckGroupTypeMatchAsync(DeviceAssignRequest request, DeviceGroupEntity group) + { + var devices = await _dbContext.Queryable().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync(); + //检查分组的分类控制 + if (group.Type.HasValue) + { + devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组"); + } + + //重新赋值到请求参数中 + request.DeviceCodes = devices.Select(x => x.Code).ToList(); + } + /// /// 递归获取树 diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index c3fafd5f..d398e296 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -28,11 +28,13 @@ public class DeviceService : IDeviceService { var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .WhereIF(request.Type.HasValue, (d, dt) => d.Type == request.Type) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), Brand = dt.Brand, Type = d.Type, + }, true) .ToPageListAsync(request); @@ -72,6 +74,18 @@ public class DeviceService : IDeviceService var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); entity.ThrowIfNull("设备不存在,无法更新"); + //分类发生变化,检查是否存在分组 + if (request.Type != entity.Type) + { + var existsG = await _dbContext.Queryable() + .LeftJoin((dgr, dg) => dgr.GroupCode == dg.Code) + .Where((dgr, dg) => dgr.DeviceCode == entity.Code) + .Where((dgr, dg) => dg.Type != null) + .AnyAsync(); + + existsG.ThrowIfTrue("存在设备分组,不可修改设备分类"); + } + var uniqueNo = entity.UniqueNo; request.Adapt(entity).UniqueNo = uniqueNo; diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs index 7af7ff74..718bd6c1 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs @@ -1,4 +1,4 @@ -using Dlhis.User.Api; +using Dlhis.Sys.Api; using Dlhis.User.Api.Response; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.Result; diff --git a/Src/Dlhis.Basic/Properties/launchSettings.json b/Src/Dlhis.Basic/Properties/launchSettings.json index 3a2eaf2f..2321b0e1 100644 --- a/Src/Dlhis.Basic/Properties/launchSettings.json +++ b/Src/Dlhis.Basic/Properties/launchSettings.json @@ -7,15 +7,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "http://*:5002" - }, - "Docker": { - "commandName": "Docker", - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger/index.html", - "environmentVariables": { - "ASPNETCORE_URLS": "http://+:80" - }, - "publishAllPorts": true + "applicationUrl": "http://localhost:5002" } }, "$schema": "https://json.schemastore.org/launchsettings.json" diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index c6bd3218..6c24630f 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -43,10 +43,10 @@ public class DeviceEntity : SugarBaseEntity, ITenantId public List Funcs { get; set; } /// - /// 设备机功能类型 + /// 设备类型 /// - [SugarColumn(ColumnDescription = "设备机功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] - public DeviceGroupFunctionEnumType Type { get; set; } + [SugarColumn(ColumnDescription = "设备类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public DeviceTypeEnumType Type { get; set; } /// /// 部署点 diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index 8fdce64f..3c06d72e 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -16,8 +16,8 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted /// /// 设备组功能类型 /// - [SugarColumn(ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] - public DeviceGroupFunctionEnumType Type { get; set; } + [SugarColumn(IsNullable = true, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public DeviceTypeEnumType? Type { get; set; } /// /// 上级设备组code diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceGroupFunctionEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs similarity index 59% rename from Src/Dlhis.Entity/Device/Enums/DeviceGroupFunctionEnumType.cs rename to Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs index 02d27cf4..230e6e17 100644 --- a/Src/Dlhis.Entity/Device/Enums/DeviceGroupFunctionEnumType.cs +++ b/Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs @@ -1,17 +1,12 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; namespace Dlhis.Entity.Device.Enums; /// -/// 设备/设备组功能类型 +///设备分类类型 /// -[Description("设备/设备组功能类型")] -public enum DeviceGroupFunctionEnumType +[Description("设备分类类型")] +public enum DeviceTypeEnumType { /// /// 门禁 @@ -29,11 +24,11 @@ public enum DeviceGroupFunctionEnumType /// 考勤 /// [Description("考勤")] - Attendance = 3 , + Attendance = 3, /// /// 门禁并作为考勤 /// [Description("门禁并作为考勤")] - Access = 4, + DoorAndAttendance = 4, } diff --git a/Src/Dlhis.Entity/Sys/Entities/UserTenantEntity.cs b/Src/Dlhis.Entity/Sys/Entities/UserTenantEntity.cs new file mode 100644 index 00000000..4f50204f --- /dev/null +++ b/Src/Dlhis.Entity/Sys/Entities/UserTenantEntity.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.DependencyInjection; +using SqlSugar; + +namespace Dlhis.Entity.Sys.Entities; + + +[SkipScan] +[SugarTable(TableName = "UserTenants")] +public class UserTenantEntity +{ + public int Id { get; set; } + + public int UserId { get; set; } + + public string TenantCode { get; set; } +} diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs index 3407da8f..f11ff379 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs @@ -28,8 +28,8 @@ public class DeviceUploadLogUploadRequest /// - /// 日志类型 + /// 记录类型 /// [EnumDataType(typeof(DeviceUploadLogTypeEnumType))] - public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Door; + public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Attendance; } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 5e266701..e479e4df 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -1,4 +1,5 @@ -using Dlhis.Entity.Basic.Entity; +using System.Linq.Expressions; +using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; @@ -7,6 +8,7 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using SqlSugar; namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements; @@ -59,6 +61,20 @@ public class DeviceUploadLogService : IDeviceUploadLogService [IgnoreTenant] public async Task UploadLogsAsync(List requests) { + //判断存在的记录 + Expression> where = LinqExpressionExtension.False(); + requests.ForEach(p => + { + where = where.Or(x => x.DeviceUniqueNo == p.DeviceUniqueNo && x.SerialNo == p.SerialNo && x.RaiseDateTime == p.RaiseDateTime); + }); + + //处理冗余的请求数据 + var exists = await _dbContext.Queryable().Where(where).ToListAsync(); + foreach (var item in exists) + { + requests.RemoveAll(x => x.DeviceUniqueNo == item.DeviceUniqueNo && x.SerialNo == item.SerialNo && x.RaiseDateTime == item.RaiseDateTime); + } + var nos = requests.Select(x => x.DeviceUniqueNo).ToList(); var devices = await _dbContext.Queryable().Where(x => nos.Contains(x.UniqueNo)).ToListAsync(); diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs index b8aea8d6..7e2eac25 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs @@ -1,7 +1,7 @@ using System.Text; using Dlhis.ScheduledTask.SyncSapInfo.Dto; using Dlhis.ScheduledTask.SyncSapInfo.Response; -using Dlhis.User.Api; +using Dlhis.Sys.Api; using Newtonsoft.Json; namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements; diff --git a/Src/Dlhis.Sys.Api/ITenantApi.cs b/Src/Dlhis.Sys.Api/ITenantApi.cs index f6b1dfb1..efa3634f 100644 --- a/Src/Dlhis.Sys.Api/ITenantApi.cs +++ b/Src/Dlhis.Sys.Api/ITenantApi.cs @@ -2,7 +2,7 @@ using Kurisu.Core.Result; using Kurisu.RemoteCall.Attributes; -namespace Dlhis.User.Api; +namespace Dlhis.Sys.Api; /// /// 租户Api @@ -34,4 +34,12 @@ public interface ITenantApi [Auth] [Get("/api/tenants/single")] Task> GetTenantByCodeAsync(string code); + + /// + /// 获取我的管理的基地/租户 + /// + /// + [Auth] + [Get("/api/tenants/my")] + Task>> GetMyTenantsAsync(); } diff --git a/Src/Dlhis.Sys.Api/IUserApi.cs b/Src/Dlhis.Sys.Api/IUserApi.cs index 2437c11d..643fce04 100644 --- a/Src/Dlhis.Sys.Api/IUserApi.cs +++ b/Src/Dlhis.Sys.Api/IUserApi.cs @@ -2,7 +2,7 @@ using Kurisu.Core.Result; using Kurisu.RemoteCall.Attributes; -namespace Dlhis.User.Api; +namespace Dlhis.Sys.Api; [EnableRemoteClient(Name = "sys-service", BaseUrl = "${InternalRequest:SysRequestUrl}")] public interface IUserApi diff --git a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs index 578347eb..1a0a605d 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs @@ -61,4 +61,13 @@ public class TenantsController : ControllerBase return await _tenantService.GetTenantByCode(code); } + /// + /// 获取我的管理租户 + /// + /// + [HttpGet("my")] + public async Task> GetMyTenants() + { + return await _tenantService.GetMyTenantsAsync(); + } } diff --git a/Src/Dlhis.Sys/Identity/Services/ITenantService.cs b/Src/Dlhis.Sys/Identity/Services/ITenantService.cs index 6fadc229..c8a144fb 100644 --- a/Src/Dlhis.Sys/Identity/Services/ITenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/ITenantService.cs @@ -11,4 +11,6 @@ public interface ITenantService : IScopeDependency Task> GetListAsync(); Task GetTenantByCode(string code); + + Task> GetMyTenantsAsync(); } diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs index d1369278..441bd744 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs @@ -3,6 +3,7 @@ using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; @@ -11,12 +12,14 @@ namespace Dlhis.Sys.Identity.Services.Implements; public class TenantService : ITenantService { private readonly IDbContext _dbContext; + private readonly ICurrentUser _currentUser; - public TenantService(IDbContext dbContext, IConfiguration configuration) + public TenantService(IDbContext dbContext, IConfiguration configuration, ICurrentUser currentUser) { var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; _dbContext = dbContext; + _currentUser = currentUser; } public async Task> GetPageAsync(TenantPageRequest request) @@ -41,4 +44,26 @@ public class TenantService : ITenantService .Select() .FirstAsync(); } + + public async Task> GetMyTenantsAsync() + { + var userId = _currentUser.GetIntSubjectId(); + var myTenants = await _dbContext.Queryable() + .LeftJoin((ut, t) => ut.TenantCode == t.Code) + .Where(ut => ut.UserId == userId) + .Select((ut, t) => new TenantResponse + { + Id = t.Id, + Code = t.Code, + Name = t.Name, + }) + .ToListAsync(); + + if (myTenants.IsEmpty()) + { + myTenants = await GetListAsync(); + } + + return myTenants; + } } diff --git a/Src/Dlhis.User/Properties/launchSettings.json b/Src/Dlhis.User/Properties/launchSettings.json index 5ea15179..8bf84199 100644 --- a/Src/Dlhis.User/Properties/launchSettings.json +++ b/Src/Dlhis.User/Properties/launchSettings.json @@ -7,6 +7,14 @@ }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:5004" + }, + "Docker": { + "commandName": "Docker", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_URLS": "http://+:80" + }, + "publishAllPorts": true } }, "$schema": "https://json.schemastore.org/launchsettings.json"