fix 子查询补充过滤

This commit is contained in:
2025-12-17 11:04:56 +08:00
parent b409f6f375
commit 4bca8859ef
4 changed files with 55 additions and 44 deletions

View File

@@ -446,52 +446,53 @@ public class DevicePermissionService : IDevicePermissionService
);
break;
case AssignTypeEnumType.Group:
{
var codes = assignValues.Select(Guid.Parse);
ids.AddRange(await _dbContext.Queryable<GainfoGroupEntity>()
.LeftJoin<GainfoGroupRelationshipEntity>((a, b) => a.Code == b.GroupCode)
.LeftJoin<GainfoEntity>((a, b, c) => b.UserNo == c.No)
.Where(a => codes.Contains(a.Code))
.Select((a, b, c) => c.Id)
.ToListAsync()
);
}
{
var codes = assignValues.Select(Guid.Parse);
ids.AddRange(await _dbContext.Queryable<GainfoGroupEntity>()
.LeftJoin<GainfoGroupRelationshipEntity>((a, b) => a.Code == b.GroupCode)
.LeftJoin<GainfoEntity>((a, b, c) => b.UserNo == c.No)
.Where(a => codes.Contains(a.Code))
.Select((a, b, c) => c.Id)
.ToListAsync()
);
}
break;
case AssignTypeEnumType.Department:
{
//递归向上获取 assignValue = tenant:department
var tenantDepartments = assignValues.Select(x =>
{
var arr = x.Split(":");
var currentDepartmentNo = arr.Last();
var departmentNos = RecursionHelper.HandlerDepartmentNextCodes(currentDepartmentNo, departments);
return new
//递归向上获取 assignValue = tenant:department
var tenantDepartments = assignValues.Select(x =>
{
tenantId = arr.First(), departmentNos
};
});
var arr = x.Split(":");
var currentDepartmentNo = arr.Last();
var departmentNos = RecursionHelper.HandlerDepartmentNextCodes(currentDepartmentNo, departments);
return new
{
tenantId = arr.First(),
departmentNos
};
});
var where = LinqExpressionExtensions.False<GainfoEntity>();
foreach (var tenantDepartment in tenantDepartments)
{
where = where.Or(x => x.Factory == tenantDepartment.tenantId && tenantDepartment.departmentNos.Contains(x.DepartmentNo));
var where = LinqExpressionExtensions.False<GainfoEntity>();
foreach (var tenantDepartment in tenantDepartments)
{
where = where.Or(x => x.Factory == tenantDepartment.tenantId && tenantDepartment.departmentNos.Contains(x.DepartmentNo));
}
ids.AddRange(await _dbContext.Queryable<GainfoEntity>()
.Where(where)
.Select(x => x.Id)
.ToListAsync()
);
}
ids.AddRange(await _dbContext.Queryable<GainfoEntity>()
.Where(where)
.Select(x => x.Id)
.ToListAsync()
);
}
break;
case AssignTypeEnumType.Tenant:
{
ids.AddRange(await _dbContext.Queryable<GainfoEntity>()
.Where(x => assignValues.Contains(x.Factory))
.Select(x => x.Id)
.ToListAsync()
);
}
{
ids.AddRange(await _dbContext.Queryable<GainfoEntity>()
.Where(x => assignValues.Contains(x.Factory))
.Select(x => x.Id)
.ToListAsync()
);
}
break;
default:
throw new ArgumentOutOfRangeException($"不支持的权限类型:{assignType}");
@@ -603,8 +604,10 @@ public class DevicePermissionService : IDevicePermissionService
var devicePermissionManuallyUserNos = await _dbContext.Queryable<GainfoEntity>()
.Where(x => SqlFunc.Subqueryable<DevicePermissionManuallyEntity>()
.Where(p => p.DeviceCode == device.Code)
.Where(p => p.UserNo == x.No).Any())
.EnableTableFilter()
.Where(p => p.DeviceCode == device.Code)
.Where(p => p.UserNo == x.No)
.Any())
.Select(x => x.No)
.ToListAsync();
@@ -626,6 +629,7 @@ public class DevicePermissionService : IDevicePermissionService
// 获取与指定设备关联的分组编码
var groupCodes = await _dbContext.Queryable<DeviceGroupEntity>()
.Where(x => SqlFunc.Subqueryable<DeviceGroupRelationshipEntity>()
.EnableTableFilter()
.Where(p => p.GroupCode == x.Code)
.Where(p => p.DeviceCode == deviceCode)
.Any())
@@ -663,8 +667,10 @@ public class DevicePermissionService : IDevicePermissionService
{
return await _dbContext.Queryable<GainfoEntity>()
.Where(x => SqlFunc.Subqueryable<DevicePermissionManuallyEntity>()
.EnableTableFilter()
.Where(p => p.DeviceCode == deviceCode)
.Where(p => p.UserNo == x.No).Any())
.Where(p => p.UserNo == x.No)
.Any())
.Select(x => x.No)
.ToListAsync();
}

View File

@@ -131,7 +131,11 @@ public class GainfoOutsourceService : IGainfoOutsourceService
{
var outsources = await _dbContext.Queryable<GainfoEntity>()
.Where(x => x.Type == GainfoUserTypeEnumType.Outsource)
.Where(x => SqlFunc.Subqueryable<OutsourceWhiteListEntity>().Where(p => p.UserCode == x.Code).NotAny())//不存在白名单中
.Where(x => SqlFunc.Subqueryable<OutsourceWhiteListEntity>()
.Where(p => p.UserCode == x.Code)
.Where(p => p.IsDeleted == false)
.NotAny()
)//不存在白名单中
.Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime })
.ToListAsync();

View File

@@ -50,7 +50,7 @@ public class EFenceService : IEFenceService
Name = x.Name,
Description = x.Description,
DirectionType = x.DirectionType,
DeviceCount = SqlFunc.Subqueryable<EFenceDeviceRelationEntity>().Where(p => p.EFenceCode == x.Code).Count(),
DeviceCount = SqlFunc.Subqueryable<EFenceDeviceRelationEntity>().Where(p => p.EFenceCode == x.Code).Where(p => p.IsDeleted == false).Count(),
})
.ToPageListAsync(request);
@@ -84,6 +84,7 @@ public class EFenceService : IEFenceService
.Where(d => deviceCodes.Contains(d.Code))
.Where(d => SqlFunc.Subqueryable<EFenceDeviceRelationEntity>()
.Where(p => p.DeviceCode == d.Code)
.Where(p => p.IsDeleted == false)
.NotAny() //不可重复分配
)
.ToListAsync();

View File

@@ -23,7 +23,7 @@
"Timeout": 30,
"SlowSqlTime": 1,
"EnableSqlLog": true,
"Generate": true
"Generate": false
},
"SwaggerOptions": {
"Enable": true,