From 64b86d2a68d0e54687ca1edb043a70901ebef1e7 Mon Sep 17 00:00:00 2001 From: biss Date: Sun, 25 Oct 2026 21:29:06 +0800 Subject: [PATCH] fix: remove remaining list truncation gaps --- .../CourseDiscussionsController.cs | 25 ++++++++-- .../Controllers/ExperimentsController.cs | 48 ++++++++++++------- .../Controllers/GradeAnalyticsController.cs | 25 ++++++++-- .../Controllers/UsersExcelController.cs | 26 +++++++++- web/src/components/CourseDiscussionPanel.vue | 16 +++++-- web/src/views/ExperimentsView.vue | 30 +++++++++--- web/src/views/GradeAnalyticsView.vue | 15 +++++- web/src/views/UsersView.vue | 8 +++- 8 files changed, 153 insertions(+), 40 deletions(-) diff --git a/src/Jiaowu.Api/Controllers/CourseDiscussionsController.cs b/src/Jiaowu.Api/Controllers/CourseDiscussionsController.cs index 01b3360..de2324a 100644 --- a/src/Jiaowu.Api/Controllers/CourseDiscussionsController.cs +++ b/src/Jiaowu.Api/Controllers/CourseDiscussionsController.cs @@ -86,20 +86,35 @@ public sealed class CourseDiscussionsController( } [HttpGet("comments/{commentId:guid}/replies")] - public async Task GetReplies(Guid sheetId, Guid commentId, CancellationToken cancellationToken) + public async Task GetReplies( + Guid sheetId, Guid commentId, DateTime? afterCreatedAt, Guid? afterId, + int pageSize = 30, CancellationToken cancellationToken = default) { var courseId = await GetAccessibleCourseIdAsync(sheetId, cancellationToken); if (!courseId.HasValue) return NotFound(); + if (afterCreatedAt.HasValue != afterId.HasValue) return BadRequest("回复游标不完整。"); + pageSize = Math.Clamp(pageSize, 1, 50); var userId = currentUserDataScope.Current.UserId; - var items = await db.GradeAnalyticsComments.AsNoTracking() - .Where(x => x.CourseId == courseId && x.ParentCommentId == commentId) - .OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(100) + var source = db.GradeAnalyticsComments.AsNoTracking() + .Where(x => x.CourseId == courseId && x.ParentCommentId == commentId); + if (afterCreatedAt.HasValue) + { + var cursorAt = afterCreatedAt.Value; + var cursorId = afterId!.Value; + source = source.Where(x => x.CreatedAt > cursorAt || + x.CreatedAt == cursorAt && x.Id.CompareTo(cursorId) > 0); + } + var rows = await source.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(pageSize + 1) .Join(db.Users.AsNoTracking(), comment => comment.AuthorUserId, user => user.Id, (comment, user) => new { comment.Id, comment.Content, comment.IsAnonymous, comment.CreatedAt, AuthorName = comment.IsAnonymous ? "匿名用户" : user.DisplayName, CanDelete = comment.AuthorUserId == userId || CanModerate() }) .ToListAsync(cancellationToken); - return Ok(new { Items = items }); + var hasMore = rows.Count > pageSize; + var items = rows.Take(pageSize).ToArray(); + var last = items.LastOrDefault(); + return Ok(new { Items = items, HasMore = hasMore, + NextCursor = hasMore && last is not null ? new { last.CreatedAt, last.Id } : null }); } [HttpPost("comments/{commentId:guid}/replies")] diff --git a/src/Jiaowu.Api/Controllers/ExperimentsController.cs b/src/Jiaowu.Api/Controllers/ExperimentsController.cs index e3067b3..51ef955 100644 --- a/src/Jiaowu.Api/Controllers/ExperimentsController.cs +++ b/src/Jiaowu.Api/Controllers/ExperimentsController.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.Data; using System.Text.Json; +using Jiaowu.Api.Contracts; using Jiaowu.Api.Domain.Academic; using Jiaowu.Api.Domain.Identity; using Jiaowu.Api.Domain.System; @@ -49,6 +50,19 @@ public sealed class ExperimentsController( x.Course!.Code.Contains(normalizedCourseKeyword) || x.Course.Name.Contains(normalizedCourseKeyword)); + var scheduleEntries = db.ScheduleEntries.AsNoTracking() + .Where(x => x.SchedulePlan!.Status == SchedulePlanStatus.Published && + x.Kind == ScheduleEntryKind.Experiment && + x.ClassroomId.HasValue && + AccessibleTeachingTasks().Select(task => task.Id).Contains(x.TeachingTaskId)) + .Where(x => !academicTermId.HasValue || x.SchedulePlan!.AcademicTermId == academicTermId.Value) + .Where(x => !offeringCollegeId.HasValue || x.TeachingTask!.Course!.CollegeId == offeringCollegeId.Value) + .Where(x => normalizedCourseKeyword == null || + x.TeachingTask!.Course!.Code.Contains(normalizedCourseKeyword) || + x.TeachingTask.Course.Name.Contains(normalizedCourseKeyword)); + var taskTotal = await tasks.CountAsync(cancellationToken); + var scheduleEntryTotal = await scheduleEntries.CountAsync(cancellationToken); + var periods = db.ScheduleTimeSlots.AsNoTracking() .Where(x => x.IsEnabled); if (academicTermId.HasValue) @@ -76,6 +90,8 @@ public sealed class ExperimentsController( return Ok(new { + TaskTotal = taskTotal, + TasksTruncated = taskTotal > 200, Tasks = await tasks .OrderByDescending(x => x.AcademicTerm!.StartDate) .ThenBy(x => x.Course!.Code) @@ -110,19 +126,9 @@ public sealed class ExperimentsController( .Distinct() .OrderBy(x => x.CollegeName) .ToListAsync(cancellationToken), - ScheduleEntries = await db.ScheduleEntries.AsNoTracking() - .Where(x => x.SchedulePlan!.Status == SchedulePlanStatus.Published && - x.Kind == ScheduleEntryKind.Experiment && - x.ClassroomId.HasValue && - AccessibleTeachingTasks().Select(task => task.Id) - .Contains(x.TeachingTaskId)) - .Where(x => !academicTermId.HasValue || - x.SchedulePlan!.AcademicTermId == academicTermId.Value) - .Where(x => !offeringCollegeId.HasValue || - x.TeachingTask!.Course!.CollegeId == offeringCollegeId.Value) - .Where(x => normalizedCourseKeyword == null || - x.TeachingTask!.Course!.Code.Contains(normalizedCourseKeyword) || - x.TeachingTask.Course.Name.Contains(normalizedCourseKeyword)) + ScheduleEntryTotal = scheduleEntryTotal, + ScheduleEntriesTruncated = scheduleEntryTotal > 500, + ScheduleEntries = await scheduleEntries .OrderBy(x => x.TeachingTask!.Course!.Code) .ThenBy(x => x.TeachingTask!.TaskNumber) .ThenBy(x => x.DayOfWeek) @@ -1244,7 +1250,9 @@ public sealed class ExperimentsController( public async Task GetProxyBookingStudents( Guid id, string? keyword, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + int page = 1, + int pageSize = 20) { var session = await LoadManagedSessionAsync(id, cancellationToken); if (session is null) return NotFound(); @@ -1260,15 +1268,21 @@ public sealed class ExperimentsController( var normalizedKeyword = string.IsNullOrWhiteSpace(keyword) ? null : keyword.Trim(); var roster = await TeachingTaskRosterQuery.LoadForTasksAsync( db, [session.ExperimentProject.TeachingTaskId], cancellationToken); - return Ok(roster + var filtered = roster .Where(x => !bookedStudentIds.Contains(x.StudentId)) .Where(x => normalizedKeyword is null || x.StudentNumber.Contains(normalizedKeyword) || x.Name.Contains(normalizedKeyword) || x.ClassName.Contains(normalizedKeyword)) .OrderBy(x => x.StudentNumber) - .Take(100) - .Select(x => new { x.StudentId, x.StudentNumber, x.Name, x.ClassName })); + .ThenBy(x => x.StudentId) + .ToArray(); + page = Math.Max(1, page); + pageSize = Math.Clamp(pageSize, 1, 100); + var items = filtered.Skip((page - 1) * pageSize).Take(pageSize) + .Select(x => new { x.StudentId, x.StudentNumber, x.Name, x.ClassName }) + .Cast().ToArray(); + return Ok(new PagedResult(items, filtered.Length, page, pageSize)); } [HttpPost("sessions/{id:guid}/proxy-bookings")] diff --git a/src/Jiaowu.Api/Controllers/GradeAnalyticsController.cs b/src/Jiaowu.Api/Controllers/GradeAnalyticsController.cs index b9d3536..c9a5281 100644 --- a/src/Jiaowu.Api/Controllers/GradeAnalyticsController.cs +++ b/src/Jiaowu.Api/Controllers/GradeAnalyticsController.cs @@ -137,20 +137,35 @@ public sealed class GradeAnalyticsController( } [HttpGet("courses/{courseId:guid}/comments/{commentId:guid}/replies")] - public async Task GetReplies(Guid courseId, Guid commentId, CancellationToken cancellationToken) + public async Task GetReplies( + Guid courseId, Guid commentId, DateTime? afterCreatedAt, Guid? afterId, + int pageSize = 30, CancellationToken cancellationToken = default) { if (!await CanAccessCommentCourseAsync(courseId, cancellationToken)) return NotFound(); + if (afterCreatedAt.HasValue != afterId.HasValue) return BadRequest("回复游标不完整。"); + pageSize = Math.Clamp(pageSize, 1, 50); var currentUserId = currentUserDataScope.Current.UserId; var canModerate = CanModerateComments(); - var items = await db.GradeAnalyticsComments.AsNoTracking() - .Where(x => x.CourseId == courseId && x.ParentCommentId == commentId) - .OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(100) + var source = db.GradeAnalyticsComments.AsNoTracking() + .Where(x => x.CourseId == courseId && x.ParentCommentId == commentId); + if (afterCreatedAt.HasValue) + { + var cursorAt = afterCreatedAt.Value; + var cursorId = afterId!.Value; + source = source.Where(x => x.CreatedAt > cursorAt || + x.CreatedAt == cursorAt && x.Id.CompareTo(cursorId) > 0); + } + var rows = await source.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(pageSize + 1) .Join(db.Users.AsNoTracking(), comment => comment.AuthorUserId, user => user.Id, (comment, user) => new { comment.Id, comment.Content, comment.IsAnonymous, comment.CreatedAt, AuthorName = comment.IsAnonymous ? "匿名用户" : user.DisplayName, CanDelete = comment.AuthorUserId == currentUserId || canModerate }) .ToListAsync(cancellationToken); - return Ok(new { Items = items }); + var hasMore = rows.Count > pageSize; + var items = rows.Take(pageSize).ToArray(); + var last = items.LastOrDefault(); + return Ok(new { Items = items, HasMore = hasMore, + NextCursor = hasMore && last is not null ? new { last.CreatedAt, last.Id } : null }); } [HttpPost("courses/{courseId:guid}/comments/{commentId:guid}/replies")] diff --git a/src/Jiaowu.Api/Controllers/UsersExcelController.cs b/src/Jiaowu.Api/Controllers/UsersExcelController.cs index a3c1297..6cbbfe2 100644 --- a/src/Jiaowu.Api/Controllers/UsersExcelController.cs +++ b/src/Jiaowu.Api/Controllers/UsersExcelController.cs @@ -42,12 +42,27 @@ public sealed class UsersExcelController( } [HttpGet("export")] - public async Task Export(CancellationToken cancellationToken) + public async Task Export( + string? keyword = null, + string? roleName = null, + Guid? collegeId = null, + bool? isEnabled = null, + bool? hasLoggedIn = null, + CancellationToken cancellationToken = default) { var colleges = await db.Colleges.AsNoTracking() .ToDictionaryAsync(x => x.Id, x => x.Code, cancellationToken); - var users = await userManager.Users.AsNoTracking() + var source = userManager.Users.AsNoTracking(); + if (collegeId.HasValue) source = source.Where(user => user.CollegeId == collegeId.Value); + if (isEnabled.HasValue) source = source.Where(user => user.IsEnabled == isEnabled.Value); + if (hasLoggedIn.HasValue) + source = hasLoggedIn.Value + ? source.Where(user => user.LastLoginAt != null) + : source.Where(user => user.LastLoginAt == null); + var users = await source .OrderBy(x => x.UserName).ToListAsync(cancellationToken); + var normalizedKeyword = keyword?.Trim(); + var normalizedRoleName = roleName?.Trim(); var rows = new List>(); foreach (var user in users) { @@ -55,6 +70,13 @@ public sealed class UsersExcelController( var roles = identityUser is null ? [] : await userManager.GetRolesAsync(identityUser); + if (!string.IsNullOrWhiteSpace(normalizedRoleName) && + !roles.Contains(normalizedRoleName, StringComparer.OrdinalIgnoreCase)) continue; + if (!string.IsNullOrWhiteSpace(normalizedKeyword) && + !(user.UserName?.Contains(normalizedKeyword, StringComparison.OrdinalIgnoreCase) == true || + user.DisplayName.Contains(normalizedKeyword, StringComparison.OrdinalIgnoreCase) || + user.StaffNumber?.Contains(normalizedKeyword, StringComparison.OrdinalIgnoreCase) == true || + roles.Any(role => role.Contains(normalizedKeyword, StringComparison.OrdinalIgnoreCase)))) continue; rows.Add(Row( user.UserName, user.DisplayName, string.Empty, user.StaffNumber, user.CollegeId.HasValue diff --git a/web/src/components/CourseDiscussionPanel.vue b/web/src/components/CourseDiscussionPanel.vue index 114c747..939537b 100644 --- a/web/src/components/CourseDiscussionPanel.vue +++ b/web/src/components/CourseDiscussionPanel.vue @@ -4,9 +4,10 @@ import { Delete, Refresh } from '@element-plus/icons-vue' import http, { apiErrorMessage } from '../api/http' type Reply = { id: string; content: string; isAnonymous: boolean; authorName: string; createdAt: string; canDelete: boolean } +type ReplyCursor = { createdAt: string; id: string } type ReactionName = 'Like' | 'Insightful' | 'Agree' | 'Hooray' | 'Heart' | 'Rocket' | 'Eyes' | 'Laugh' type ReactionOption = { type: ReactionName; emoji: string; label: string; countKey: string; activeKey: string } -type Comment = Reply & { replyCount: number; replies?: Reply[]; [key: string]: string | number | boolean | Reply[] | undefined } +type Comment = Reply & { replyCount: number; replies?: Reply[]; repliesHasMore?: boolean; repliesNextCursor?: ReplyCursor; [key: string]: string | number | boolean | Reply[] | ReplyCursor | undefined } const reactionOptions: ReactionOption[] = [ { type: 'Like', emoji: '👍', label: '赞', countKey: 'likeCount', activeKey: 'hasLiked' }, { type: 'Insightful', emoji: '💡', label: '有启发', countKey: 'insightfulCount', activeKey: 'hasInsightful' }, @@ -44,8 +45,17 @@ function reacted(comment: Comment, option: ReactionOption) { return comment[opti async function react(comment: Comment, type: ReactionName) { try { await http.post(`${base()}/comments/${comment.id}/reactions/${type}`); await load(true) } catch (error) { ElMessage.error(apiErrorMessage(error)) } } async function toggleReplies(comment: Comment) { replyOpen[comment.id] = !replyOpen[comment.id]; if (!replyOpen[comment.id] || comment.replies) return + await loadReplies(comment, true) +} +async function loadReplies(comment: Comment, reset = false) { replyLoading[comment.id] = true - try { comment.replies = (await http.get(`${base()}/comments/${comment.id}/replies`)).data.items } catch (error) { ElMessage.error(apiErrorMessage(error)) } finally { replyLoading[comment.id] = false } + try { + const cursor = reset ? undefined : comment.repliesNextCursor + const data = (await http.get(`${base()}/comments/${comment.id}/replies`, { params: cursor ? { afterCreatedAt: cursor.createdAt, afterId: cursor.id } : undefined })).data + comment.replies = reset ? data.items : [...(comment.replies ?? []), ...data.items] + comment.repliesHasMore = data.hasMore + comment.repliesNextCursor = data.nextCursor ?? undefined + } catch (error) { ElMessage.error(apiErrorMessage(error)) } finally { replyLoading[comment.id] = false } } async function reply(comment: Comment) { const text = drafts[comment.id]?.trim(); if (!text) return @@ -64,7 +74,7 @@ watch(() => props.sheetId, () => load(true), { immediate: true })
匿名发布发布评论
-
  1. {{ comment.authorName || '未命名用户' }}匿名

    {{ comment.content }}

    回复{{ comment.replyCount ? ` (${comment.replyCount})` : '' }}删除
    1. {{ item.authorName }}匿名

      {{ item.content }}

      删除
    匿名回复回复
+
  1. {{ comment.authorName || '未命名用户' }}匿名

    {{ comment.content }}

    回复{{ comment.replyCount ? ` (${comment.replyCount})` : '' }}删除
    1. {{ item.authorName }}匿名

      {{ item.content }}

      删除
    加载更多回复
    匿名回复回复
加载更多评论
diff --git a/web/src/views/ExperimentsView.vue b/web/src/views/ExperimentsView.vue index b46bdd1..e466967 100644 --- a/web/src/views/ExperimentsView.vue +++ b/web/src/views/ExperimentsView.vue @@ -27,6 +27,10 @@ const options = reactive({ classrooms: [] as any[], teachers: [] as any[], periods: [] as any[], + taskTotal: 0, + tasksTruncated: false, + scheduleEntryTotal: 0, + scheduleEntriesTruncated: false, }) const modeFilter = ref('') const statusFilter = ref('') @@ -83,6 +87,9 @@ const proxyBookingStudents = ref([]) const proxyBookingLoading = ref(false) const proxyBookingKeyword = ref('') const proxyBookingStudentIds = ref([]) +const proxyBookingPage = ref(1) +const proxyBookingPageSize = 20 +const proxyBookingTotal = ref(0) const selectedTask = computed(() => options.tasks.find((task) => task.id === projectForm.teachingTaskIds[0]), @@ -618,14 +625,18 @@ async function showParticipants(project: any, session: any) { } } -async function loadProxyBookingStudents() { +async function loadProxyBookingStudents(page = proxyBookingPage.value) { if (!participantSession.value) return + proxyBookingPage.value = page + proxyBookingStudentIds.value = [] proxyBookingLoading.value = true try { - proxyBookingStudents.value = (await http.get( + const { data } = await http.get( `/experiments/sessions/${participantSession.value.id}/eligible-students`, - { params: { keyword: proxyBookingKeyword.value || undefined } }, - )).data + { params: { keyword: proxyBookingKeyword.value || undefined, page, pageSize: proxyBookingPageSize } }, + ) + proxyBookingStudents.value = data.items + proxyBookingTotal.value = data.total } catch (error) { proxyBookingStudents.value = [] ElMessage.error(apiErrorMessage(error)) @@ -637,6 +648,7 @@ async function loadProxyBookingStudents() { async function openProxyBooking() { proxyBookingStudentIds.value = [] proxyBookingKeyword.value = '' + proxyBookingPage.value = 1 proxyBookingDialog.value = true await loadProxyBookingStudents() } @@ -719,8 +731,12 @@ async function loadOptions() { }, }) options.tasks = data.tasks + options.taskTotal = data.taskTotal + options.tasksTruncated = data.tasksTruncated options.colleges = data.colleges options.scheduleEntries = data.scheduleEntries + options.scheduleEntryTotal = data.scheduleEntryTotal + options.scheduleEntriesTruncated = data.scheduleEntriesTruncated options.classrooms = data.classrooms options.teachers = data.teachers options.periods = data.periods @@ -1117,6 +1133,7 @@ onMounted(async () => { />
PROJECT规定实验项目
+ { show-icon /> { +