diff --git a/server/MiAssessment/src/MiAssessment.Core/Services/AssessmentService.cs b/server/MiAssessment/src/MiAssessment.Core/Services/AssessmentService.cs
index 8e6353b..4490a33 100644
--- a/server/MiAssessment/src/MiAssessment.Core/Services/AssessmentService.cs
+++ b/server/MiAssessment/src/MiAssessment.Core/Services/AssessmentService.cs
@@ -132,29 +132,39 @@ public class AssessmentService : IAssessmentService
// 获取总数
var total = await query.CountAsync();
- // 分页查询
+ // 分页查询(使用左连接避免缺少关联数据时丢失记录)
var records = await query
.OrderByDescending(r => r.CreateTime)
.Skip((page - 1) * pageSize)
.Take(pageSize)
- .Join(
+ .GroupJoin(
_dbContext.Orders.AsNoTracking(),
r => r.OrderId,
o => o.Id,
- (r, o) => new { Record = r, Order = o }
+ (r, orders) => new { Record = r, Orders = orders }
)
- .Join(
+ .SelectMany(
+ ro => ro.Orders.DefaultIfEmpty(),
+ (ro, o) => new { ro.Record, Order = o }
+ )
+ .GroupJoin(
_dbContext.AssessmentTypes.AsNoTracking(),
ro => ro.Record.AssessmentTypeId,
at => at.Id,
- (ro, at) => new AssessmentHistoryDto
+ (ro, types) => new { ro.Record, ro.Order, Types = types }
+ )
+ .SelectMany(
+ rot => rot.Types.DefaultIfEmpty(),
+ (rot, at) => new AssessmentHistoryDto
{
- Id = ro.Record.Id,
- OrderNo = ro.Order.OrderNo,
- AssessmentName = at.Name,
- Status = ro.Record.Status,
- StatusText = GetStatusText(ro.Record.Status),
- TestDate = ro.Record.CreateTime.ToString("yyyy-MM-dd")
+ Id = rot.Record.Id,
+ OrderNo = rot.Order != null ? rot.Order.OrderNo : "",
+ AssessmentName = at != null ? at.Name : "多元智能测评",
+ Name = rot.Record.Name,
+ AssessmentTypeId = rot.Record.AssessmentTypeId,
+ Status = rot.Record.Status,
+ StatusText = GetStatusText(rot.Record.Status),
+ TestDate = rot.Record.CreateTime.ToString("yyyy-MM-dd")
}
)
.ToListAsync();
diff --git a/server/MiAssessment/src/MiAssessment.Model/Models/Assessment/AssessmentHistoryDto.cs b/server/MiAssessment/src/MiAssessment.Model/Models/Assessment/AssessmentHistoryDto.cs
index db12325..b301a68 100644
--- a/server/MiAssessment/src/MiAssessment.Model/Models/Assessment/AssessmentHistoryDto.cs
+++ b/server/MiAssessment/src/MiAssessment.Model/Models/Assessment/AssessmentHistoryDto.cs
@@ -20,6 +20,16 @@ public class AssessmentHistoryDto
///
public string AssessmentName { get; set; } = null!;
+ ///
+ /// 测评人姓名
+ ///
+ public string Name { get; set; } = null!;
+
+ ///
+ /// 测评类型ID
+ ///
+ public long AssessmentTypeId { get; set; }
+
///
/// 状态:1待测评 2测评中 3生成中 4已完成
///
diff --git a/uniapp/pages/assessment/history/index.vue b/uniapp/pages/assessment/history/index.vue
index 6e81076..fdd8fdf 100644
--- a/uniapp/pages/assessment/history/index.vue
+++ b/uniapp/pages/assessment/history/index.vue
@@ -14,11 +14,12 @@ import Loading from '@/components/Loading/index.vue'
const userStore = useUserStore()
const { checkLogin } = useAuth()
-// 测评状态常量
+// 测评状态常量(与后端一致)
const ASSESSMENT_STATUS = {
- GENERATING: 1, // 生成中
- COMPLETED: 2, // 已完成
- FAILED: 3 // 生成失败
+ PENDING: 1, // 待测评
+ TESTING: 2, // 测评中
+ GENERATING: 3, // 生成中
+ COMPLETED: 4 // 已完成
}
// 状态
@@ -32,44 +33,20 @@ const noMore = ref(false)
// 计算属性
const isEmpty = computed(() => !loading.value && historyList.value.length === 0)
-const hasMore = computed(() => historyList.value.length < total.value)
-
-/**
- * 获取测评状态文本
- */
-function getStatusText(status) {
- const statusMap = {
- [ASSESSMENT_STATUS.GENERATING]: '生成中',
- [ASSESSMENT_STATUS.COMPLETED]: '已完成',
- [ASSESSMENT_STATUS.FAILED]: '生成失败'
- }
- return statusMap[status] || '未知状态'
-}
/**
* 获取测评状态样式类
*/
function getStatusClass(status) {
const classMap = {
+ [ASSESSMENT_STATUS.PENDING]: 'status-pending',
+ [ASSESSMENT_STATUS.TESTING]: 'status-testing',
[ASSESSMENT_STATUS.GENERATING]: 'status-generating',
- [ASSESSMENT_STATUS.COMPLETED]: 'status-completed',
- [ASSESSMENT_STATUS.FAILED]: 'status-failed'
+ [ASSESSMENT_STATUS.COMPLETED]: 'status-completed'
}
return classMap[status] || ''
}
-/**
- * 格式化日期
- */
-function formatDate(dateStr) {
- if (!dateStr) return ''
- const date = new Date(dateStr)
- const year = date.getFullYear()
- const month = String(date.getMonth() + 1).padStart(2, '0')
- const day = String(date.getDate()).padStart(2, '0')
- return `${year}-${month}-${day}`
-}
-
/**
* 加载测评历史列表
*/
@@ -142,6 +119,15 @@ onReachBottom(() => {
* 查看测评结果
*/
function viewResult(record) {
+ // 已完成 - 查看报告
+ if (record.status === ASSESSMENT_STATUS.COMPLETED) {
+ uni.navigateTo({
+ url: `/pages/assessment/result/index?recordId=${record.id}`
+ })
+ return
+ }
+
+ // 生成中 - 提示等待
if (record.status === ASSESSMENT_STATUS.GENERATING) {
uni.showToast({
title: '报告生成中,请稍后查看',
@@ -150,24 +136,13 @@ function viewResult(record) {
return
}
- if (record.status === ASSESSMENT_STATUS.FAILED) {
- uni.showToast({
- title: '报告生成失败,请联系客服',
- icon: 'none'
+ // 待测评/测评中 - 跳转到答题页继续
+ if (record.status === ASSESSMENT_STATUS.PENDING || record.status === ASSESSMENT_STATUS.TESTING) {
+ uni.navigateTo({
+ url: `/pages/assessment/info/index?typeId=${record.assessmentTypeId || 1}`
})
return
}
-
- uni.navigateTo({
- url: `/pages/assessment/result/index?recordId=${record.id}`
- })
-}
-
-/**
- * 判断是否显示查看结果按钮
- */
-function showViewResultBtn(status) {
- return status === ASSESSMENT_STATUS.COMPLETED
}
/**
@@ -201,28 +176,28 @@ onMounted(() => {
:key="record.id"
@click="viewResult(record)"
>
-
+
-
+
测评人
- {{ record.userName || '--' }}
+ {{ record.name || '--' }}
测评日期
- {{ formatDate(record.createTime) }}
+ {{ record.testDate || '--' }}
-
-