fix 优化查询判断

This commit is contained in:
2024-03-06 21:40:34 +08:00
parent d3e0581963
commit 14c63ead73
5 changed files with 13 additions and 13 deletions

View File

@@ -66,6 +66,7 @@ public class DeviceGroupsController : ControllerBase
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("assign")]
[IgnoreTenant]
[Transactional]
public async Task AssignDevicesAsync(DeviceAssignRequest request)
{

View File

@@ -90,7 +90,7 @@ public class DeviceGroupService : IDeviceGroupService
public async Task AssignDevicesAsync(DeviceAssignRequest request)
{
var group = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.GroupCode).FirstAsync();
group.ThrowIfNull("设备组不存在,无法进行分配");
group.ThrowIfNull("设备分组不存在,无法进行分配");
await CheckNoNextGroupAsync(group.Code);
await CheckGroupTypeMatchAsync(request, group);
@@ -99,7 +99,7 @@ public class DeviceGroupService : IDeviceGroupService
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
{
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
await _dbContext.DeleteAsync(relationships);
await _dbContext.DeleteReallyAsync(relationships);
var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity
{

View File

@@ -63,6 +63,8 @@ public class GainfoGroupsController : ControllerBase
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("assign")]
[IgnoreTenant]
[Transactional]
public async Task AssignGainfosAsync(GainfoAssignRequest request)
{
await _gainfoGroupService.AssignGainfosAsync(request);

View File

@@ -89,14 +89,14 @@ public class GainfoGroupService : IGainfoGroupService
public async Task AssignGainfosAsync(GainfoAssignRequest request)
{
var pGrp = await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.Code == request.GroupCode).FirstAsync();
pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组");
var existsNextGroup = await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.PCode == request.GroupCode).AnyAsync();
existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员");
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
{
var pGrp = await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.Code == request.GroupCode).FirstAsync();
pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组");
var existsNextGroup = await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.PCode == request.GroupCode).AnyAsync();
existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员");
{
var relations = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
await _dbContext.DeleteReallyAsync(relations);

View File

@@ -8,7 +8,7 @@ namespace Dlhis.Entity.Device.Entities;
/// 设备组/设备关系
/// </summary>
[SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")]
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDeleted
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId
{
/// <summary>
/// 设备组code
@@ -22,8 +22,5 @@ public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDe
[SugarColumn(ColumnDescription = "设备code")]
public Guid DeviceCode { get; set; }
public string TenantId { get; set; }
public bool IsDeleted { get; set; }
}