package com.mydreamjob.assessment; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; /** * 答卷主记录(V34/V35)。 * *
状态流转:DRAFT → IN_PROGRESS → COMPLETED。{@code samplingSeed} 用于抽题随机种子, * 持久化但不下发前端。{@code idempotencyKey} 与 {@code studentUserId} 联合唯一实现创建幂等。
*/ @Data @Builder @NoArgsConstructor @AllArgsConstructor @Entity @Table(name = "assessment_attempts") @EntityListeners(AuditingEntityListener.class) public class AssessmentAttempt { public static final String STATUS_DRAFT = "DRAFT"; public static final String STATUS_IN_PROGRESS = "IN_PROGRESS"; public static final String STATUS_COMPLETED = "COMPLETED"; public static final String STATUS_EXPIRED = "EXPIRED"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "student_user_id", nullable = false) private Long studentUserId; @Column(name = "definition_id", nullable = false) private Long definitionId; @Column(nullable = false, length = 20) @Builder.Default private String status = STATUS_DRAFT; @Column(name = "sampling_seed") private Long samplingSeed; @Column(name = "question_set_version", nullable = false, length = 40) private String questionSetVersion; @Column(name = "selected_question_count", nullable = false) private Integer selectedQuestionCount; @Column(name = "answered_count", nullable = false) @Builder.Default private Integer answeredCount = 0; @Column(name = "idempotency_key", length = 64) private String idempotencyKey; /** 活跃答卷唯一键:DRAFT/IN_PROGRESS 非空,终态后置 NULL(数据库唯一约束保证同学生同类型仅一份活跃) */ @Column(name = "active_key", length = 255) private String activeKey; @Version @Column(nullable = false) @Builder.Default private Long version = 0L; @Column(name = "started_at") private LocalDateTime startedAt; @Column(name = "submitted_at") private LocalDateTime submittedAt; @Column(name = "completed_at") private LocalDateTime completedAt; @CreatedDate @Column(name = "created_at", nullable = false, updatable = false) private LocalDateTime createdAt; @LastModifiedDate @Column(name = "updated_at", nullable = false) private LocalDateTime updatedAt; }