优化条件筛选
This commit is contained in:
1 parent
eb20211f0e
commit
130bffbd01
6 files changed
+152
-1
No files matched your search
@@ -237,6 +237,10 @@ public sealed class BaseDataController(AppDbContext db, IAppCache cache) : Contr
|
|||||||
int? page,
|
int? page,
|
||||||
int? pageSize,
|
int? pageSize,
|
||||||
string? keyword,
|
string? keyword,
|
||||||
|
Guid? collegeId,
|
||||||
|
Guid? majorId,
|
||||||
|
int? grade,
|
||||||
|
bool? isEnabled,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (page.HasValue || pageSize.HasValue)
|
if (page.HasValue || pageSize.HasValue)
|
||||||
@@ -245,6 +249,11 @@ public sealed class BaseDataController(AppDbContext db, IAppCache cache) : Contr
|
|||||||
return ValidationProblem("页码必须大于 0,且每页条数应在 1 至 100 之间。");
|
return ValidationProblem("页码必须大于 0,且每页条数应在 1 至 100 之间。");
|
||||||
|
|
||||||
var source = db.AdministrativeClasses.AsNoTracking();
|
var source = db.AdministrativeClasses.AsNoTracking();
|
||||||
|
if (collegeId.HasValue)
|
||||||
|
source = source.Where(x => x.Major!.CollegeId == collegeId.Value);
|
||||||
|
if (majorId.HasValue) source = source.Where(x => x.MajorId == majorId.Value);
|
||||||
|
if (grade.HasValue) source = source.Where(x => x.Grade == grade.Value);
|
||||||
|
if (isEnabled.HasValue) source = source.Where(x => x.IsEnabled == isEnabled.Value);
|
||||||
if (!string.IsNullOrWhiteSpace(keyword))
|
if (!string.IsNullOrWhiteSpace(keyword))
|
||||||
{
|
{
|
||||||
keyword = keyword.Trim();
|
keyword = keyword.Trim();
|
||||||
@@ -511,6 +520,11 @@ public sealed class BaseDataController(AppDbContext db, IAppCache cache) : Contr
|
|||||||
int? page,
|
int? page,
|
||||||
int? pageSize,
|
int? pageSize,
|
||||||
string? keyword,
|
string? keyword,
|
||||||
|
Guid? campusId,
|
||||||
|
Guid? buildingId,
|
||||||
|
int? minimumCapacity,
|
||||||
|
TeachingVenueNature? teachingVenueNature,
|
||||||
|
bool? isEnabled,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (page.HasValue || pageSize.HasValue)
|
if (page.HasValue || pageSize.HasValue)
|
||||||
@@ -519,6 +533,14 @@ public sealed class BaseDataController(AppDbContext db, IAppCache cache) : Contr
|
|||||||
return ValidationProblem("页码必须大于 0,且每页条数应在 1 至 100 之间。");
|
return ValidationProblem("页码必须大于 0,且每页条数应在 1 至 100 之间。");
|
||||||
|
|
||||||
var source = db.Classrooms.AsNoTracking();
|
var source = db.Classrooms.AsNoTracking();
|
||||||
|
if (campusId.HasValue)
|
||||||
|
source = source.Where(x => x.Building!.CampusId == campusId.Value);
|
||||||
|
if (buildingId.HasValue) source = source.Where(x => x.BuildingId == buildingId.Value);
|
||||||
|
if (minimumCapacity.HasValue)
|
||||||
|
source = source.Where(x => x.Capacity >= minimumCapacity.Value);
|
||||||
|
if (teachingVenueNature.HasValue)
|
||||||
|
source = source.Where(x => (x.TeachingVenueNature & teachingVenueNature.Value) != 0);
|
||||||
|
if (isEnabled.HasValue) source = source.Where(x => x.IsEnabled == isEnabled.Value);
|
||||||
if (!string.IsNullOrWhiteSpace(keyword))
|
if (!string.IsNullOrWhiteSpace(keyword))
|
||||||
{
|
{
|
||||||
keyword = keyword.Trim();
|
keyword = keyword.Trim();
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ public sealed class GradeAnalyticsController(
|
|||||||
public async Task<ActionResult> GetTeachingClasses(
|
public async Task<ActionResult> GetTeachingClasses(
|
||||||
Guid? academicTermId,
|
Guid? academicTermId,
|
||||||
string? keyword,
|
string? keyword,
|
||||||
|
Guid? collegeId = null,
|
||||||
|
string? teacherKeyword = null,
|
||||||
|
bool? riskOnly = null,
|
||||||
int page = 1,
|
int page = 1,
|
||||||
int pageSize = 20,
|
int pageSize = 20,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
@@ -105,12 +108,23 @@ public sealed class GradeAnalyticsController(
|
|||||||
.Where(x => VisibleTeachingTasks().Any(task => task.Id == x.TeachingTaskId));
|
.Where(x => VisibleTeachingTasks().Any(task => task.Id == x.TeachingTaskId));
|
||||||
if (academicTermId.HasValue)
|
if (academicTermId.HasValue)
|
||||||
source = source.Where(x => x.AcademicTermId == academicTermId);
|
source = source.Where(x => x.AcademicTermId == academicTermId);
|
||||||
|
if (collegeId.HasValue)
|
||||||
|
source = source.Where(x => x.TeachingTask!.Course!.CollegeId == collegeId.Value);
|
||||||
if (keyword is not null)
|
if (keyword is not null)
|
||||||
source = source.Where(x =>
|
source = source.Where(x =>
|
||||||
x.TeachingTask!.TaskNumber.Contains(keyword) ||
|
x.TeachingTask!.TaskNumber.Contains(keyword) ||
|
||||||
x.TeachingTask.Name.Contains(keyword) ||
|
x.TeachingTask.Name.Contains(keyword) ||
|
||||||
x.TeachingTask.Course!.Code.Contains(keyword) ||
|
x.TeachingTask.Course!.Code.Contains(keyword) ||
|
||||||
x.TeachingTask.Course.Name.Contains(keyword));
|
x.TeachingTask.Course.Name.Contains(keyword));
|
||||||
|
if (!string.IsNullOrWhiteSpace(teacherKeyword))
|
||||||
|
{
|
||||||
|
teacherKeyword = teacherKeyword.Trim();
|
||||||
|
source = source.Where(x => x.TeachingTask!.Teachers.Any(item =>
|
||||||
|
item.Teacher!.Name.Contains(teacherKeyword) ||
|
||||||
|
item.Teacher.TeacherNumber.Contains(teacherKeyword)));
|
||||||
|
}
|
||||||
|
if (riskOnly == true)
|
||||||
|
source = source.Where(x => x.PassRate < 60 || x.AverageScore < 60);
|
||||||
|
|
||||||
var total = await source.CountAsync(cancellationToken);
|
var total = await source.CountAsync(cancellationToken);
|
||||||
var items = await source
|
var items = await source
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ public sealed class UsersController(
|
|||||||
int page = 1,
|
int page = 1,
|
||||||
int pageSize = 20,
|
int pageSize = 20,
|
||||||
string? keyword = null,
|
string? keyword = null,
|
||||||
|
string? roleName = null,
|
||||||
|
Guid? collegeId = null,
|
||||||
|
bool? isEnabled = null,
|
||||||
|
bool? hasLoggedIn = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (page < 1 || pageSize is < 1 or > 100)
|
if (page < 1 || pageSize is < 1 or > 100)
|
||||||
@@ -42,6 +46,21 @@ public sealed class UsersController(
|
|||||||
where userRole.UserId == user.Id && role.Name!.Contains(keyword)
|
where userRole.UserId == user.Id && role.Name!.Contains(keyword)
|
||||||
select role.Id).Any());
|
select role.Id).Any());
|
||||||
}
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(roleName))
|
||||||
|
{
|
||||||
|
roleName = roleName.Trim();
|
||||||
|
query = query.Where(user =>
|
||||||
|
(from userRole in db.UserRoles
|
||||||
|
join candidateRole in db.Roles on userRole.RoleId equals candidateRole.Id
|
||||||
|
where userRole.UserId == user.Id && candidateRole.Name == roleName
|
||||||
|
select userRole.RoleId).Any());
|
||||||
|
}
|
||||||
|
if (collegeId.HasValue) query = query.Where(user => user.CollegeId == collegeId.Value);
|
||||||
|
if (isEnabled.HasValue) query = query.Where(user => user.IsEnabled == isEnabled.Value);
|
||||||
|
if (hasLoggedIn.HasValue)
|
||||||
|
query = hasLoggedIn.Value
|
||||||
|
? query.Where(user => user.LastLoginAt != null)
|
||||||
|
: query.Where(user => user.LastLoginAt == null);
|
||||||
|
|
||||||
var total = await query.CountAsync(cancellationToken);
|
var total = await query.CountAsync(cancellationToken);
|
||||||
var users = await query
|
var users = await query
|
||||||
|
|||||||
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user