本次更新实现了基于用户类型的论述题访问权限控制,并为论述题添加了专门的AI评分功能。 后端更新: - 添加论述题权限验证:根据用户类型(ordinary-person/management-person)控制不同论述题的访问权限 - 新增 GradeEssay 方法:为论述题提供专门的AI评分,不依赖标准答案,基于保密法规进行专业评分 - 优化AI评分提示词:增加法规依据要求,返回参考答案、评分依据等更详细的评分信息 - 添加用户类型管理:新增 UpdateUserType API,支持用户更新个人类型 - 路由调整:将练习题相关API移至需要认证的路由组 前端更新: - 论述题答题界面优化:不显示标准答案,展示AI评分的参考答案和评分依据 - 用户类型选择:登录/注册时支持选择用户类型 - 权限控制适配:根据用户类型显示对应的论述题列表 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
2.5 KiB
Go
54 lines
2.5 KiB
Go
package models
|
|
|
|
import "gorm.io/gorm"
|
|
|
|
// PracticeQuestion 练习题目模型
|
|
type PracticeQuestion struct {
|
|
gorm.Model
|
|
QuestionID string `gorm:"size:50;not null" json:"question_id"` // 题目ID (原JSON中的id字段)
|
|
Type string `gorm:"index;size:30;not null" json:"type"` // 题目类型
|
|
TypeName string `gorm:"size:50" json:"type_name"` // 题型名称(中文)
|
|
Question string `gorm:"type:text;not null" json:"question"` // 题目内容
|
|
AnswerData string `gorm:"type:text;not null" json:"-"` // 答案数据(JSON格式存储)
|
|
OptionsData string `gorm:"type:text" json:"-"` // 选项数据(JSON格式存储,用于选择题)
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (PracticeQuestion) TableName() string {
|
|
return "practice_questions"
|
|
}
|
|
|
|
// PracticeQuestionDTO 用于前端返回的数据传输对象
|
|
type PracticeQuestionDTO struct {
|
|
ID uint `json:"id"` // 数据库自增ID
|
|
QuestionID string `json:"question_id"` // 题目编号(原JSON中的id)
|
|
Type string `json:"type"` // 前端使用的简化类型: single, multiple, judge, fill
|
|
Content string `json:"content"` // 题目内容
|
|
Options []Option `json:"options"` // 选择题选项数组
|
|
Category string `json:"category"` // 题目分类
|
|
Answer interface{} `json:"answer"` // 正确答案(用于题目管理编辑)
|
|
}
|
|
|
|
// PracticeAnswerSubmit 练习题答案提交
|
|
type PracticeAnswerSubmit struct {
|
|
QuestionID uint `json:"question_id" binding:"required"` // 数据库ID
|
|
Answer interface{} `json:"answer" binding:"required"` // 用户答案
|
|
}
|
|
|
|
// PracticeAnswerResult 练习题答案结果
|
|
type PracticeAnswerResult struct {
|
|
Correct bool `json:"correct"` // 是否正确
|
|
UserAnswer interface{} `json:"user_answer"` // 用户答案
|
|
CorrectAnswer interface{} `json:"correct_answer,omitempty"` // 正确答案(仅在错误时返回)
|
|
AIGrading *AIGrading `json:"ai_grading,omitempty"` // AI评分结果(仅简答题)
|
|
}
|
|
|
|
// AIGrading AI评分结果
|
|
type AIGrading struct {
|
|
Score float64 `json:"score"` // 得分 (0-100)
|
|
Feedback string `json:"feedback"` // 评语
|
|
Suggestion string `json:"suggestion"` // 改进建议
|
|
ReferenceAnswer string `json:"reference_answer,omitempty"` // 参考答案(论述题)
|
|
ScoringRationale string `json:"scoring_rationale,omitempty"` // 评分依据
|
|
}
|