fix 框架tenant问题;档案组和设备组特殊处理返回

This commit is contained in:
2024-03-05 16:45:15 +08:00
parent 40a0234bbf
commit 888460ea99
13 changed files with 139 additions and 105 deletions

View File

@@ -24,17 +24,6 @@ public class DeviceGroupsController : ControllerBase
_deviceGroupService = deviceGroupService;
}
/// <summary>
/// 设备组分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("page")]
public async Task<Pagination<DeviceGroupPageResponse>> GetPageAsync([FromQuery] DeviceGroupPageRequest request)
{
return await _deviceGroupService.GetPageAsync(request);
}
/// <summary>
/// 获取设备组树
/// </summary>
@@ -42,6 +31,7 @@ public class DeviceGroupsController : ControllerBase
/// <param name="type">分组类型</param>
/// <returns></returns>
[HttpGet("tree")]
[IgnoreTenant]
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type)
{
return await _deviceGroupService.GetTreeAsync(showDevices, type);

View File

@@ -1,12 +0,0 @@
using Dlhis.Entity.Device.Enums;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Device.Request;
public class DeviceGroupPageRequest : PageDto
{
/// <summary>
/// 分组类型
/// </summary>
public DeviceTypeEnumType? Type { get; set; }
}

View File

@@ -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; }
/// <summary>
/// 下级
/// </summary>

View File

@@ -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<Pagination<DeviceGroupPageResponse>> GetPageAsync(DeviceGroupPageRequest request);
Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type);
Task SaveAsync(DeviceGroupSaveRequest request);

View File

@@ -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<Pagination<DeviceGroupPageResponse>> GetPageAsync(DeviceGroupPageRequest request)
{
return await _dbContext.Queryable<DeviceGroupEntity>()
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search))
.WhereIF(request.Type.HasValue, x => x.Type == request.Type)
.Select<DeviceGroupPageResponse>()
.ToPageListAsync(request);
}
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type)
{
@@ -206,15 +199,32 @@ public class DeviceGroupService : IDeviceGroupService
/// 递归获取树
/// </summary>
/// <param name="current"></param>
/// <param name="departments"></param>
/// <param name="deviceGroups"></param>
/// <param name="showDevices"></param>
private void RecursionGetNext(DeviceGroupTreeResponse current, List<DeviceGroupTreeResponse> departments, bool showDevices)
private void RecursionGetNext(DeviceGroupTreeResponse current, List<DeviceGroupTreeResponse> 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);
}
//最后层级附加设备信息

View File

@@ -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
}
/// <summary>
/// 获取档案组分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<Pagination<GainfoGroupResponse>> GetPageAsync([FromQuery] GainfoGroupPageRequest request)
{
return await _gainfoGroupService.GetPageAsync(request);
}
/// <summary>
/// 获取所有档案组
/// 获取档案分组树
/// </summary>
/// <returns></returns>
[HttpGet("list")]
public async Task<List<GainfoGroupResponse>> GetListAsync()
[HttpGet("tree")]
[IgnoreTenant]
public async Task<List<GainfoGroupTreeResponse>> GetTreeAsync()
{
return await _gainfoGroupService.GetListAsync();
return await _gainfoGroupService.GetTreeAsync();
}
/// <summary>

View File

@@ -1,7 +0,0 @@
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Organization.Request;
public class GainfoGroupPageRequest: PageDto
{
}

View File

@@ -4,6 +4,11 @@ public class GainfoGroupSaveRequest
{
public long? Id { get; set; }
/// <summary>
/// 上级
/// </summary>
public Guid? PCode { get; set; }
/// <summary>
/// 名称
/// </summary>

View File

@@ -1,21 +0,0 @@
namespace Dlhis.Basic.Organization.Response;
public class GainfoGroupResponse
{
public long Id { get; set; }
/// <summary>
/// 分组code
/// </summary>
public Guid Code { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
}

View File

@@ -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; }
/// <summary>
/// 分组code
/// </summary>
public Guid Code { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
[JsonIgnore]
public string TenantId { get; set; }
/// <summary>
/// 下级数据
/// </summary>
public List<GainfoGroupTreeResponse> Next { get; set; }
}

View File

@@ -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<Pagination<GainfoGroupResponse>> GetPageAsync(GainfoGroupPageRequest request);
Task<List<GainfoGroupResponse>> GetListAsync();
Task<List<GainfoGroupTreeResponse>> GetTreeAsync();
Task SaveAsync(GainfoGroupSaveRequest request);

View File

@@ -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<Pagination<GainfoGroupResponse>> GetPageAsync(GainfoGroupPageRequest request)
public async Task<List<GainfoGroupTreeResponse>> GetTreeAsync()
{
return await _dbContext.Queryable<GainfoGroupEntity>()
.Select<GainfoGroupResponse>()
.ToPageListAsync(request);
}
var deviceGroups = await _dbContext.Queryable<GainfoGroupEntity>()
.Select<GainfoGroupTreeResponse>()
.ToListAsync();
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
tops.ForEach(x =>
{
RecursionGetNext(x, deviceGroups);
});
public async Task<List<GainfoGroupResponse>> GetListAsync()
{
return await _dbContext.Queryable<GainfoGroupEntity>()
.Select<GainfoGroupResponse>()
.ToListAsync();
return tops;
}
public async Task SaveAsync(GainfoGroupSaveRequest request)
{
await CheckDuplicateNameAsync(request);
try
{
//todo
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
var defaultGroup = await _dbContext.Queryable<GainfoGroupEntity>().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<GainfoGroupEntity>();
entity.Code = Guid.NewGuid();
entity.Editable = true;
await _dbContext.InsertAsync(entity);
}
else
{
var entity = await _dbContext.Queryable<GainfoGroupEntity>().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<GainfoGroupTreeResponse> 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);
}
}
}

View File

@@ -36,13 +36,13 @@ public class GainfoGroupEntity : SugarBaseEntity, ITenantId
/// <summary>
/// 是否默认分组
/// </summary>
[SugarColumn(ColumnDescription = "是否默认分组")]
[SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit")]
public bool IsDefault { get; set; }
/// <summary>
/// 是否可编辑
/// </summary>
[SugarColumn(ColumnDescription = "是否可编辑")]
[SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit")]
public bool Editable { get; set; }