diff --git a/server/MiAssessment/src/MiAssessment.Admin.Business/Models/Assessment/QuestionDto.cs b/server/MiAssessment/src/MiAssessment.Admin.Business/Models/Assessment/QuestionDto.cs
index c71996c..b7aa6b2 100644
--- a/server/MiAssessment/src/MiAssessment.Admin.Business/Models/Assessment/QuestionDto.cs
+++ b/server/MiAssessment/src/MiAssessment.Admin.Business/Models/Assessment/QuestionDto.cs
@@ -45,6 +45,11 @@ public class QuestionDto
///
public string StatusName { get; set; } = string.Empty;
+ ///
+ /// 关联的分类数量
+ ///
+ public int CategoryCount { get; set; }
+
///
/// 创建时间
///
diff --git a/server/MiAssessment/src/MiAssessment.Admin.Business/Services/AssessmentService.cs b/server/MiAssessment/src/MiAssessment.Admin.Business/Services/AssessmentService.cs
index 4bcc94f..034580a 100644
--- a/server/MiAssessment/src/MiAssessment.Admin.Business/Services/AssessmentService.cs
+++ b/server/MiAssessment/src/MiAssessment.Admin.Business/Services/AssessmentService.cs
@@ -344,7 +344,7 @@ public class AssessmentService : IAssessmentService
var total = await query.CountAsync();
// 分页查询,按 QuestionNo 升序排列
- var items = await query
+ var questions = await query
.OrderBy(q => q.QuestionNo)
.ThenByDescending(q => q.CreateTime)
.Skip(request.Skip)
@@ -363,7 +363,23 @@ public class AssessmentService : IAssessmentService
})
.ToListAsync();
- return PagedResult.Create(items, total, request.Page, request.PageSize);
+ // 获取这些题目的分类数量
+ if (questions.Count > 0)
+ {
+ var questionIds = questions.Select(q => q.Id).ToList();
+ var categoryCounts = await _dbContext.QuestionCategoryMappings
+ .Where(m => questionIds.Contains(m.QuestionId))
+ .GroupBy(m => m.QuestionId)
+ .Select(g => new { QuestionId = g.Key, Count = g.Count() })
+ .ToDictionaryAsync(x => x.QuestionId, x => x.Count);
+
+ foreach (var question in questions)
+ {
+ question.CategoryCount = categoryCounts.TryGetValue(question.Id, out var count) ? count : 0;
+ }
+ }
+
+ return PagedResult.Create(questions, total, request.Page, request.PageSize);
}
///
diff --git a/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/api/business/assessment.ts b/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/api/business/assessment.ts
index 61cc5a4..9955fb0 100644
--- a/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/api/business/assessment.ts
+++ b/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/api/business/assessment.ts
@@ -97,8 +97,8 @@ export interface QuestionItem {
sort: number
/** 状态 (0: 禁用, 1: 启用) */
status: number
- /** 关联的分类ID列表 */
- categoryIds: number[]
+ /** 关联的分类数量 */
+ categoryCount: number
}
/**
@@ -219,6 +219,24 @@ export interface MappingItem {
categoryId: number
}
+/**
+ * 映射关系中的分类信息
+ */
+export interface MappingCategoryDto {
+ /** 分类ID */
+ id: number
+ /** 分类名称 */
+ name: string
+ /** 分类编码 */
+ code: string
+ /** 分类类型:1-8 */
+ categoryType: number
+ /** 分类类型名称 */
+ categoryTypeName: string
+ /** 映射创建时间 */
+ mappingCreateTime: string
+}
+
/**
* 批量更新映射请求
*/
@@ -482,10 +500,10 @@ export function deleteCategory(id: number): Promise> {
/**
* 获取题目的分类映射
* @param questionId 题目ID
- * @returns 分类ID列表
+ * @returns 分类信息列表
*/
-export function getMappingsByQuestion(questionId: number): Promise> {
- return request({
+export function getMappingsByQuestion(questionId: number): Promise> {
+ return request({
url: '/admin/assessment/mapping/getByQuestion',
method: 'get',
params: { questionId }
diff --git a/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/views/business/assessment/question/index.vue b/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/views/business/assessment/question/index.vue
index fe74fdd..0dfb27f 100644
--- a/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/views/business/assessment/question/index.vue
+++ b/server/MiAssessment/src/MiAssessment.Admin/admin-web/src/views/business/assessment/question/index.vue
@@ -95,7 +95,7 @@
- {{ row.categoryIds?.length || 0 }}
+ {{ row.categoryCount || 0 }}
个分类
@@ -583,7 +583,8 @@ async function loadQuestionMappings(questionId: number) {
try {
const res = await getMappingsByQuestion(questionId)
if (res.code === 0) {
- state.selectedCategoryIds = res.data || []
+ // 从返回的分类对象数组中提取分类ID
+ state.selectedCategoryIds = (res.data || []).map(item => item.id)
}
} catch (error) {
console.error('Failed to load question mappings:', error)