修复
This commit is contained in:
parent
f06daf07d9
commit
1edbe04a71
|
|
@ -45,6 +45,11 @@ public class QuestionDto
|
|||
/// </summary>
|
||||
public string StatusName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 关联的分类数量
|
||||
/// </summary>
|
||||
public int CategoryCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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<QuestionDto>.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<QuestionDto>.Create(questions, total, request.Page, request.PageSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -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<ApiResponse<boolean>> {
|
|||
/**
|
||||
* 获取题目的分类映射
|
||||
* @param questionId 题目ID
|
||||
* @returns 分类ID列表
|
||||
* @returns 分类信息列表
|
||||
*/
|
||||
export function getMappingsByQuestion(questionId: number): Promise<ApiResponse<number[]>> {
|
||||
return request<number[]>({
|
||||
export function getMappingsByQuestion(questionId: number): Promise<ApiResponse<MappingCategoryDto[]>> {
|
||||
return request<MappingCategoryDto[]>({
|
||||
url: '/admin/assessment/mapping/getByQuestion',
|
||||
method: 'get',
|
||||
params: { questionId }
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@
|
|||
<el-table-column label="分类映射" width="120" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link size="small" @click="handleCategoryMapping(row)">
|
||||
<span class="category-count">{{ row.categoryIds?.length || 0 }}</span>
|
||||
<span class="category-count">{{ row.categoryCount || 0 }}</span>
|
||||
<span>个分类</span>
|
||||
</el-button>
|
||||
</template>
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user