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; }