解决统计数据不对的问题
This commit is contained in:
parent
61e32ef970
commit
0f544c169d
@ -66,7 +66,6 @@ yarn dev
|
||||
- `GET /api/practice/questions` - 获取练习题目列表 (支持分页和类型过滤)
|
||||
- `GET /api/practice/questions/:id` - 获取指定练习题目
|
||||
- `POST /api/practice/submit` - 提交练习答案 (简答题自动AI评分)
|
||||
- `GET /api/practice/types` - 获取题型列表
|
||||
|
||||
#### 其他
|
||||
- `GET /api/health` - 健康检查端点
|
||||
|
||||
@ -172,52 +172,6 @@ func GetPracticeQuestionByID(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// GetRandomPracticeQuestion 获取随机练习题目
|
||||
func GetRandomPracticeQuestion(c *gin.Context) {
|
||||
typeParam := c.Query("type")
|
||||
|
||||
log.Printf("[GetRandomPracticeQuestion] 收到请求 (type: '%s')", typeParam)
|
||||
|
||||
db := database.GetDB()
|
||||
var question models.PracticeQuestion
|
||||
|
||||
query := db.Model(&models.PracticeQuestion{})
|
||||
if typeParam != "" {
|
||||
// 如果请求论述题,检查权限
|
||||
if strings.HasSuffix(typeParam, "-essay") && !checkEssayPermission(c, typeParam) {
|
||||
// 权限不足,返回暂无题目
|
||||
log.Printf("[GetRandomPracticeQuestion] 权限检查失败,返回暂无题目 (type: '%s')", typeParam)
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"success": false,
|
||||
"message": "暂无题目",
|
||||
})
|
||||
return
|
||||
}
|
||||
query = query.Where("type = ?", typeParam)
|
||||
log.Printf("[GetRandomPracticeQuestion] 添加题型过滤 (type: '%s')", typeParam)
|
||||
}
|
||||
|
||||
// 使用PostgreSQL的随机排序
|
||||
if err := query.Order("RANDOM()").First(&question).Error; err != nil {
|
||||
log.Printf("[GetRandomPracticeQuestion] 未找到题目 (type: '%s', error: %v)", typeParam, err)
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"success": false,
|
||||
"message": "暂无题目",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[GetRandomPracticeQuestion] 找到题目 (id: %d, type: '%s')", question.ID, question.Type)
|
||||
|
||||
// 转换为DTO
|
||||
dto := convertToDTO(question)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": dto,
|
||||
})
|
||||
}
|
||||
|
||||
// SubmitPracticeAnswer 提交练习答案
|
||||
func SubmitPracticeAnswer(c *gin.Context) {
|
||||
var submit models.PracticeAnswerSubmit
|
||||
@ -452,45 +406,6 @@ func SubmitPracticeAnswer(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// GetPracticeQuestionTypes 获取题型列表
|
||||
func GetPracticeQuestionTypes(c *gin.Context) {
|
||||
types := []gin.H{
|
||||
{
|
||||
"type": "fill-in-blank",
|
||||
"type_name": "填空题",
|
||||
},
|
||||
{
|
||||
"type": "true-false",
|
||||
"type_name": "判断题",
|
||||
},
|
||||
{
|
||||
"type": "multiple-choice",
|
||||
"type_name": "选择题",
|
||||
},
|
||||
{
|
||||
"type": "multiple-selection",
|
||||
"type_name": "多选题",
|
||||
},
|
||||
{
|
||||
"type": "short-answer",
|
||||
"type_name": "简答题",
|
||||
},
|
||||
{
|
||||
"type": "ordinary-essay",
|
||||
"type_name": "普通涉密人员论述题",
|
||||
},
|
||||
{
|
||||
"type": "management-essay",
|
||||
"type_name": "保密管理人员论述题",
|
||||
},
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": types,
|
||||
})
|
||||
}
|
||||
|
||||
type CheckAnswer interface {
|
||||
check(userAnswer, correctAnswer interface{}) bool
|
||||
}
|
||||
@ -705,7 +620,7 @@ func GetStatistics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
uid, ok := userID.(uint)
|
||||
uid, ok := userID.(int64)
|
||||
if !ok {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"success": false,
|
||||
|
||||
@ -130,7 +130,7 @@ func GetWrongQuestionStats(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
stats, err := services.GetWrongQuestionStats(userID.(uint))
|
||||
stats, err := services.GetWrongQuestionStats(userID.(int64))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取统计失败"})
|
||||
return
|
||||
@ -159,14 +159,14 @@ func GetRecommendedWrongQuestions(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 获取要排除的题目ID(前端传递当前题目ID,避免重复推荐)
|
||||
excludeQuestionID := uint(0)
|
||||
excludeQuestionID := int64(0)
|
||||
if e := c.Query("exclude"); e != "" {
|
||||
if parsed, err := strconv.ParseUint(e, 10, 32); err == nil {
|
||||
excludeQuestionID = uint(parsed)
|
||||
if parsed, err := strconv.ParseUint(e, 10, 64); err == nil {
|
||||
excludeQuestionID = int64(parsed)
|
||||
}
|
||||
}
|
||||
|
||||
questions, err := services.GetRecommendedWrongQuestions(userID.(uint), limit, excludeQuestionID)
|
||||
questions, err := services.GetRecommendedWrongQuestions(userID.(int64), limit, excludeQuestionID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取推荐错题失败"})
|
||||
return
|
||||
|
||||
@ -111,7 +111,7 @@ func RecordCorrectAnswer(userID, questionID int64, userAnswer, correctAnswer int
|
||||
}
|
||||
|
||||
// GetWrongQuestionStats 获取错题统计
|
||||
func GetWrongQuestionStats(userID uint) (*models.WrongQuestionStats, error) {
|
||||
func GetWrongQuestionStats(userID int64) (*models.WrongQuestionStats, error) {
|
||||
db := database.GetDB()
|
||||
|
||||
stats := &models.WrongQuestionStats{
|
||||
@ -193,7 +193,7 @@ func GetWrongQuestionStats(userID uint) (*models.WrongQuestionStats, error) {
|
||||
}
|
||||
|
||||
// calculateTrendData 计算错题趋势数据
|
||||
func calculateTrendData(db *gorm.DB, userID uint, days int) []models.TrendPoint {
|
||||
func calculateTrendData(db *gorm.DB, userID int64, days int) []models.TrendPoint {
|
||||
trendData := make([]models.TrendPoint, days)
|
||||
now := time.Now()
|
||||
|
||||
@ -223,7 +223,7 @@ func calculateTrendData(db *gorm.DB, userID uint, days int) []models.TrendPoint
|
||||
// 1. 最优先推荐掌握度为0的题目(从未答对过)
|
||||
// 2. 其次推荐掌握度低的题目(mastery_level 从低到高)
|
||||
// 3. 最后推荐最近答错的题目
|
||||
func GetRecommendedWrongQuestions(userID uint, limit int, excludeQuestionID uint) ([]models.WrongQuestion, error) {
|
||||
func GetRecommendedWrongQuestions(userID int64, limit int, excludeQuestionID int64) ([]models.WrongQuestion, error) {
|
||||
db := database.GetDB()
|
||||
|
||||
var questions []models.WrongQuestion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user