updates
This commit is contained in:
parent
1f9d5a1431
commit
180b8f09f3
|
|
@ -26,6 +26,9 @@ rate_limit:
|
||||||
/api/user/score/save-score:
|
/api/user/score/save-score:
|
||||||
interval: 1
|
interval: 1
|
||||||
max_requests: 1
|
max_requests: 1
|
||||||
|
/user/major/list:
|
||||||
|
interval: 1
|
||||||
|
max_requests: 5
|
||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
user: admin
|
user: admin
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ func (s *UserScoreService) SaveUserScore(req *dto.SaveScoreRequest) (vo.UserScor
|
||||||
|
|
||||||
// 2. DTO 转 Entity
|
// 2. DTO 转 Entity
|
||||||
entityItem := s.convertDtoToEntity(req)
|
entityItem := s.convertDtoToEntity(req)
|
||||||
entityItem.CalculationTableName = "yx_calculation_major_2026"
|
entityItem.CalculationTableName = "yx_calculation_major_2025_2"
|
||||||
entityItem.ID = common.GenerateStringID() // 使用新封装的 ID 生成工具
|
entityItem.ID = common.GenerateStringID() // 使用新封装的 ID 生成工具
|
||||||
entityItem.CreateTime = time.Now()
|
entityItem.CreateTime = time.Now()
|
||||||
entityItem.UpdateTime = time.Now()
|
entityItem.UpdateTime = time.Now()
|
||||||
|
|
@ -183,6 +183,16 @@ func (s *UserScoreService) SaveUserScore(req *dto.SaveScoreRequest) (vo.UserScor
|
||||||
return vo.UserScoreVO{}, fmt.Errorf("提交事务失败: %w", err)
|
return vo.UserScoreVO{}, fmt.Errorf("提交事务失败: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清除之前的Redis成绩缓存
|
||||||
|
config.RDB.Del(context.Background(), common.RedisUserScorePrefix+req.CreateBy)
|
||||||
|
|
||||||
|
// 更新Redis 数据
|
||||||
|
scoreRedisSetData, err := json.Marshal(entityItem)
|
||||||
|
err = config.RDB.Set(context.Background(), common.RedisUserScorePrefix+req.CreateBy, scoreRedisSetData, common.RedisUserScoreExpire).Err()
|
||||||
|
if err != nil {
|
||||||
|
return vo.UserScoreVO{}, fmt.Errorf("缓存成绩记录失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return userScoreVO, nil
|
return userScoreVO, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ package dto
|
||||||
|
|
||||||
// 定义概率数量统计结果结构体,用于接收四种录取概率对应的各自数量
|
// 定义概率数量统计结果结构体,用于接收四种录取概率对应的各自数量
|
||||||
type ProbabilityCountDTO struct {
|
type ProbabilityCountDTO struct {
|
||||||
HardAdmit int64 `gorm:"column:hard_admit"` // 难录取(<60)
|
Hard int64 `json:"hard" gorm:"column:hard"` // 难录取(<60)
|
||||||
Impact int64 `gorm:"column:impact"` // 可冲击(60<=x<73)
|
Risky int64 `json:"risky" gorm:"column:risky"` // 可冲击(60<=x<73)
|
||||||
Stable int64 `gorm:"column:stable"` // 较稳妥(73<=x<93)
|
Stable int64 `json:"stable" gorm:"column:stable"` // 较稳妥(73<=x<93)
|
||||||
Secure int64 `gorm:"column:secure"` // 可保底(>=93)
|
Safe int64 `json:"safe" gorm:"column:safe"` // 可保底(>=93)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,10 @@ func (m *YxCalculationMajorMapper) FindRecommendList(query dto.SchoolMajorQuery)
|
||||||
// 4. 四种概率批量统计SQL(使用CASE WHEN一次查询,性能最优)
|
// 4. 四种概率批量统计SQL(使用CASE WHEN一次查询,性能最优)
|
||||||
probCountSQL := fmt.Sprintf(`
|
probCountSQL := fmt.Sprintf(`
|
||||||
SELECT
|
SELECT
|
||||||
SUM(CASE WHEN cm.enroll_probability < 60 THEN 1 ELSE 0 END) AS hard_admit,
|
SUM(CASE WHEN cm.enroll_probability < 60 THEN 1 ELSE 0 END) AS hard,
|
||||||
SUM(CASE WHEN cm.enroll_probability >= 60 AND cm.enroll_probability < 73 THEN 1 ELSE 0 END) AS impact,
|
SUM(CASE WHEN cm.enroll_probability >= 60 AND cm.enroll_probability < 73 THEN 1 ELSE 0 END) AS risky,
|
||||||
SUM(CASE WHEN cm.enroll_probability >= 73 AND cm.enroll_probability < 93 THEN 1 ELSE 0 END) AS stable,
|
SUM(CASE WHEN cm.enroll_probability >= 73 AND cm.enroll_probability < 93 THEN 1 ELSE 0 END) AS stable,
|
||||||
SUM(CASE WHEN cm.enroll_probability >= 93 THEN 1 ELSE 0 END) AS secure
|
SUM(CASE WHEN cm.enroll_probability >= 93 THEN 1 ELSE 0 END) AS safe
|
||||||
FROM %s cm
|
FROM %s cm
|
||||||
%s
|
%s
|
||||||
`, tableName, baseSQL)
|
`, tableName, baseSQL)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue