From 888460ea99460f9311bef8d768a43a3faedd1b49 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 16:45:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20=E6=A1=86=E6=9E=B6tenant=E9=97=AE?= =?UTF-8?q?=E9=A2=98;=E6=A1=A3=E6=A1=88=E7=BB=84=E5=92=8C=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=BB=84=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DeviceGroupsController.cs | 12 +-- .../Device/Request/DeviceGroupPageRequest.cs | 12 --- .../Response/DeviceGroupTreeResponse.cs | 4 + .../Device/Services/IDeviceGroupService.cs | 3 - .../Services/Implements/DeviceGroupService.cs | 40 ++++++---- .../Controllers/GainfoGroupsController.cs | 22 ++---- .../Request/GainfoGroupPageRequest.cs | 7 -- .../Request/GainfoGroupSaveRequest.cs | 5 ++ .../Response/GainfoGroupResponse.cs | 21 ------ .../Response/GainfoGroupTreeResponse.cs | 34 +++++++++ .../Services/IGainfoGroupService.cs | 5 +- .../Services/Implements/GainfoGroupService.cs | 75 +++++++++++++++---- .../Basic/Entity/GainfoGroupEntity.cs | 4 +- 13 files changed, 139 insertions(+), 105 deletions(-) delete mode 100644 Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs delete mode 100644 Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs delete mode 100644 Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs create mode 100644 Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index 5f6ac7f8..66a5089f 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -24,17 +24,6 @@ public class DeviceGroupsController : ControllerBase _deviceGroupService = deviceGroupService; } - /// - /// 设备组分页 - /// - /// - /// - [HttpPost("page")] - public async Task> GetPageAsync([FromQuery] DeviceGroupPageRequest request) - { - return await _deviceGroupService.GetPageAsync(request); - } - /// /// 获取设备组树 /// @@ -42,6 +31,7 @@ public class DeviceGroupsController : ControllerBase /// 分组类型 /// [HttpGet("tree")] + [IgnoreTenant] public async Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type) { return await _deviceGroupService.GetTreeAsync(showDevices, type); diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs deleted file mode 100644 index aee1a3d9..00000000 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Dlhis.Entity.Device.Enums; -using Kurisu.Core.DataAccess.Dto; - -namespace Dlhis.Basic.Device.Request; - -public class DeviceGroupPageRequest : PageDto -{ - /// - /// 分组类型 - /// - public DeviceTypeEnumType? Type { get; set; } -} diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index 9a1e26de..31b5f3f3 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -1,5 +1,6 @@ using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; +using Newtonsoft.Json; namespace Dlhis.Basic.Device.Response; @@ -44,6 +45,9 @@ public class DeviceGroupTreeResponse } } + [JsonIgnore] + public string TenantId { get; set; } + /// /// 下级 /// diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs index 13368b4f..4335fce8 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs @@ -1,14 +1,11 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Entity.Device.Enums; -using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Device.Services; public interface IDeviceGroupService : IScopeDependency { - Task> GetPageAsync(DeviceGroupPageRequest request); - Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type); Task SaveAsync(DeviceGroupSaveRequest request); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 7ffdc0d4..361d6289 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -5,8 +5,7 @@ using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Extensions; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; using Mapster; @@ -16,21 +15,15 @@ public class DeviceGroupService : IDeviceGroupService { private readonly IDbContext _dbContext; private readonly IDevicePermissionService _devicePermissionService; + private readonly ICurrentUser _currentUser; - public DeviceGroupService(IDbContext dbContext, IDevicePermissionService devicePermissionService) + public DeviceGroupService(IDbContext dbContext, IDevicePermissionService devicePermissionService, ICurrentUser currentUser) { _dbContext = dbContext; _devicePermissionService = devicePermissionService; + _currentUser = currentUser; } - public async Task> GetPageAsync(DeviceGroupPageRequest request) - { - return await _dbContext.Queryable() - .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search)) - .WhereIF(request.Type.HasValue, x => x.Type == request.Type) - .Select() - .ToPageListAsync(request); - } public async Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type) { @@ -206,15 +199,32 @@ public class DeviceGroupService : IDeviceGroupService /// 递归获取树 /// /// - /// + /// /// - private void RecursionGetNext(DeviceGroupTreeResponse current, List departments, bool showDevices) + private void RecursionGetNext(DeviceGroupTreeResponse current, List deviceGroups, bool showDevices) { - var next = departments.Where(x => x.PCode == current.Code).ToList(); + var currentTenantId = _currentUser.GetStringTenantId(); + var next = deviceGroups.Where(x => + { + if (x.PCode == current.Code) + { + if (x.TenantId.IsEmpty()) + { + return true; + } + else + { + return x.TenantId == currentTenantId; + } + } + + return false; + + }).ToList(); current.Next = next; foreach (var item in next) { - RecursionGetNext(item, departments, showDevices); + RecursionGetNext(item, deviceGroups, showDevices); } //最后层级附加设备信息 diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs index 42e765ba..ca2225a9 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs @@ -1,8 +1,8 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.AspNetCore.MVC; -using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -25,24 +25,14 @@ public class GainfoGroupsController : ControllerBase } /// - /// 获取档案组分页 - /// - /// - /// - [HttpGet("page")] - public async Task> GetPageAsync([FromQuery] GainfoGroupPageRequest request) - { - return await _gainfoGroupService.GetPageAsync(request); - } - - /// - /// 获取所有档案组 + /// 获取档案分组树 /// /// - [HttpGet("list")] - public async Task> GetListAsync() + [HttpGet("tree")] + [IgnoreTenant] + public async Task> GetTreeAsync() { - return await _gainfoGroupService.GetListAsync(); + return await _gainfoGroupService.GetTreeAsync(); } /// diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs deleted file mode 100644 index b38a161d..00000000 --- a/Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -using Kurisu.Core.DataAccess.Dto; - -namespace Dlhis.Basic.Organization.Request; - -public class GainfoGroupPageRequest: PageDto -{ -} diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs index bb5173e4..eb4bfe9a 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs @@ -4,6 +4,11 @@ public class GainfoGroupSaveRequest { public long? Id { get; set; } + /// + /// 上级 + /// + public Guid? PCode { get; set; } + /// /// 名称 /// diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs deleted file mode 100644 index f7f397b4..00000000 --- a/Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Dlhis.Basic.Organization.Response; - -public class GainfoGroupResponse -{ - public long Id { get; set; } - - /// - /// 分组code - /// - public Guid Code { get; set; } - - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 备注 - /// - public string Remark { get; set; } -} diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs new file mode 100644 index 00000000..3fb4ca63 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Dlhis.Basic.Organization.Response; + +public class GainfoGroupTreeResponse +{ + public long Id { get; set; } + + public Guid? PCode { get; set; } + + /// + /// 分组code + /// + public Guid Code { get; set; } + + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + + [JsonIgnore] + public string TenantId { get; set; } + + /// + /// 下级数据 + /// + public List Next { get; set; } +} diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs index 344f4dd1..d9b2801e 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs @@ -1,14 +1,11 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; -using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Organization.Services; public interface IGainfoGroupService : IScopeDependency { - Task> GetPageAsync(GainfoGroupPageRequest request); - - Task> GetListAsync(); + Task> GetTreeAsync(); Task SaveAsync(GainfoGroupSaveRequest request); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index ae598cf1..2a4390ef 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -2,8 +2,8 @@ using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Extensions; +using Kurisu.Core.DataAccess.Entity; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; using Mapster; @@ -12,42 +12,61 @@ namespace Dlhis.Basic.Organization.Services.Implements; public class GainfoGroupService : IGainfoGroupService { private readonly IDbContext _dbContext; + private readonly ICurrentUser _currentUser; - public GainfoGroupService(IDbContext dbContext) + public GainfoGroupService(IDbContext dbContext, ICurrentUser currentUser) { _dbContext = dbContext; + _currentUser = currentUser; } - public async Task> GetPageAsync(GainfoGroupPageRequest request) + public async Task> GetTreeAsync() { - return await _dbContext.Queryable() - .Select() - .ToPageListAsync(request); - } + var deviceGroups = await _dbContext.Queryable() + .Select() + .ToListAsync(); + var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); + tops.ForEach(x => + { + RecursionGetNext(x, deviceGroups); + }); - public async Task> GetListAsync() - { - return await _dbContext.Queryable() - .Select() - .ToListAsync(); + return tops; } public async Task SaveAsync(GainfoGroupSaveRequest request) { await CheckDuplicateNameAsync(request); + try + { + //todo + _dbContext.Client.QueryFilter.ClearAndBackup(); + var defaultGroup = await _dbContext.Queryable().Where(x => x.IsDefault).FirstAsync(); + + if (!request.PCode.HasValue) + { + request.PCode = defaultGroup.Code; + } + } + finally + { + _dbContext.Client.QueryFilter.Restore(); + } + if (!request.Id.HasValue) { var entity = request.Adapt(); entity.Code = Guid.NewGuid(); + entity.Editable = true; await _dbContext.InsertAsync(entity); } else { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); request.Adapt(entity); - + entity.Editable = true; await _dbContext.UpdateAsync(entity); } } @@ -99,4 +118,32 @@ public class GainfoGroupService : IGainfoGroupService exists.ThrowIfTrue($"重复组名{request.Name}"); } + + + private void RecursionGetNext(GainfoGroupTreeResponse current, List gainfoGroups) + { + var currentTenantId = _currentUser.GetStringTenantId(); + var next = gainfoGroups.Where(x => + { + if (x.PCode == current.Code) + { + if (x.TenantId.IsEmpty()) + { + return true; + } + else + { + return x.TenantId == currentTenantId; + } + } + + return false; + + }).ToList(); + current.Next = next; + foreach (var item in next) + { + RecursionGetNext(item, gainfoGroups); + } + } } diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs index b7e533c0..84c1bbf1 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs @@ -36,13 +36,13 @@ public class GainfoGroupEntity : SugarBaseEntity, ITenantId /// /// 是否默认分组 /// - [SugarColumn(ColumnDescription = "是否默认分组")] + [SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit")] public bool IsDefault { get; set; } /// /// 是否可编辑 /// - [SugarColumn(ColumnDescription = "是否可编辑")] + [SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit")] public bool Editable { get; set; } From 49dcf96bfcf31b515297909a3bc3c8511cbcd042 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 16:45:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?add=20=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Dlhis.Basic.csproj | 2 +- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 2 +- Src/Dlhis.Common/Dlhis.Common.csproj | 2 +- Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj | 2 +- Src/Dlhis.Sys/Dlhis.Sys.csproj | 2 +- Src/Dlhis.User/Dlhis.User.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 7094a50f..43b23333 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index f30be7d1..30b34732 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -36,7 +36,7 @@ - + diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index d3228328..02b72955 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -21,7 +21,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index e412c478..96b47437 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,7 +20,7 @@ - + diff --git a/Src/Dlhis.Sys/Dlhis.Sys.csproj b/Src/Dlhis.Sys/Dlhis.Sys.csproj index 830d7da2..b14b421d 100644 --- a/Src/Dlhis.Sys/Dlhis.Sys.csproj +++ b/Src/Dlhis.Sys/Dlhis.Sys.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index a803e35b..7934a4d0 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -17,6 +17,6 @@ - +