feat:获取成绩接口

This commit is contained in:
zhouwentao 2025-12-19 15:39:23 +08:00
parent 8a8c0f0933
commit 94486dd149
11 changed files with 211 additions and 194 deletions

View File

@ -1,10 +1,12 @@
{ {
"kiroAgent.configureMCP": "Disabled", "kiroAgent.configureMCP": "Disabled",
"cSpell.words": [ "cSpell.words": [
"apikey",
"Cognitio", "Cognitio",
"Fzby", "Fzby",
"gonic", "gonic",
"gorm", "gorm",
"swaggo",
"Xjysby", "Xjysby",
"Xjysdy", "Xjysdy",
"Yybyqy", "Yybyqy",

View File

@ -30,7 +30,7 @@ func InitDB() {
} }
// 连接池配置 // 连接池配置
sqlDB.SetMaxIdleConns(10) // 最大空闲连接数 sqlDB.SetMaxIdleConns(20) // 最大空闲连接数
sqlDB.SetMaxOpenConns(100) // 最大打开连接数 sqlDB.SetMaxOpenConns(100) // 最大打开连接数
sqlDB.SetConnMaxLifetime(time.Hour) // 连接最大存活时间 sqlDB.SetConnMaxLifetime(time.Hour) // 连接最大存活时间

View File

@ -15,71 +15,6 @@ const docTemplate = `{
"host": "{{.Host}}", "host": "{{.Host}}",
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "paths": {
"/auth/info": {
"get": {
"tags": [
"认证"
],
"summary": "获取当前登录用户信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/auth/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"认证"
],
"summary": "用户登录",
"parameters": [
{
"description": "登录信息",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/server_modules_user_controller.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/auth/logout": {
"post": {
"tags": [
"认证"
],
"summary": "用户登出",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/sys-users": { "/sys-users": {
"get": { "get": {
"tags": [ "tags": [
@ -347,6 +282,71 @@ const docTemplate = `{
} }
} }
}, },
"/user/auth/info": {
"get": {
"tags": [
"认证"
],
"summary": "获取当前登录用户信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/user/auth/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"认证"
],
"summary": "用户登录",
"parameters": [
{
"description": "登录信息",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/server_modules_user_controller.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/user/auth/logout": {
"post": {
"tags": [
"认证"
],
"summary": "用户登出",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/user/score/save-score": { "/user/score/save-score": {
"post": { "post": {
"tags": [ "tags": [

View File

@ -9,71 +9,6 @@
"host": "localhost:8080", "host": "localhost:8080",
"basePath": "/api", "basePath": "/api",
"paths": { "paths": {
"/auth/info": {
"get": {
"tags": [
"认证"
],
"summary": "获取当前登录用户信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/auth/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"认证"
],
"summary": "用户登录",
"parameters": [
{
"description": "登录信息",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/server_modules_user_controller.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/auth/logout": {
"post": {
"tags": [
"认证"
],
"summary": "用户登出",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/sys-users": { "/sys-users": {
"get": { "get": {
"tags": [ "tags": [
@ -341,6 +276,71 @@
} }
} }
}, },
"/user/auth/info": {
"get": {
"tags": [
"认证"
],
"summary": "获取当前登录用户信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/user/auth/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"认证"
],
"summary": "用户登录",
"parameters": [
{
"description": "登录信息",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/server_modules_user_controller.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/user/auth/logout": {
"post": {
"tags": [
"认证"
],
"summary": "用户登出",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
}
}
}
},
"/user/score/save-score": { "/user/score/save-score": {
"post": { "post": {
"tags": [ "tags": [

View File

@ -538,47 +538,6 @@ info:
title: 艺考招生管理系统 API title: 艺考招生管理系统 API
version: "2.0" version: "2.0"
paths: paths:
/auth/info:
get:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/common.Response'
summary: 获取当前登录用户信息
tags:
- 认证
/auth/login:
post:
consumes:
- application/json
parameters:
- description: 登录信息
in: body
name: request
required: true
schema:
$ref: '#/definitions/server_modules_user_controller.LoginRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/common.Response'
summary: 用户登录
tags:
- 认证
/auth/logout:
post:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/common.Response'
summary: 用户登出
tags:
- 认证
/sys-users: /sys-users:
get: get:
parameters: parameters:
@ -751,6 +710,47 @@ paths:
summary: Sys用户登出 summary: Sys用户登出
tags: tags:
- 认证 - 认证
/user/auth/info:
get:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/common.Response'
summary: 获取当前登录用户信息
tags:
- 认证
/user/auth/login:
post:
consumes:
- application/json
parameters:
- description: 登录信息
in: body
name: request
required: true
schema:
$ref: '#/definitions/server_modules_user_controller.LoginRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/common.Response'
summary: 用户登录
tags:
- 认证
/user/auth/logout:
post:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/common.Response'
summary: 用户登出
tags:
- 认证
/user/score/{id}: /user/score/{id}:
get: get:
responses: responses:

View File

@ -15,6 +15,7 @@ import (
_ "server/docs" _ "server/docs"
"server/middleware" "server/middleware"
sysController "server/modules/system/controller" sysController "server/modules/system/controller"
userController "server/modules/user/controller"
yxController "server/modules/yx/controller" yxController "server/modules/yx/controller"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -81,6 +82,10 @@ func main() {
yxController.NewYxVolunteerController().RegisterRoutes(api) yxController.NewYxVolunteerController().RegisterRoutes(api)
yxController.NewYxVolunteerRecordController().RegisterRoutes(api) yxController.NewYxVolunteerRecordController().RegisterRoutes(api)
// 注册 User 模块路由
userController.NewUserScoreController().RegisterRoutes(api)
userController.NewAuthController().RegisterRoutes(api)
// 创建 HTTP 服务器 // 创建 HTTP 服务器
srv := &http.Server{ srv := &http.Server{
Addr: ":8080", Addr: ":8080",

View File

@ -21,8 +21,10 @@ const (
// 白名单路径 (不需要登录即可访问) // 白名单路径 (不需要登录即可访问)
var whiteList = []string{ var whiteList = []string{
"/api/auth/login", "/api/sys/auth/login",
"/api/auth/register", "/api/sys/auth/register",
"/api/user/auth/login",
"/api/user/auth/register",
"/swagger/", "/swagger/",
"/swagger/index.html", "/swagger/index.html",
} }

View File

@ -24,9 +24,9 @@ func NewAuthController() *AuthController {
} }
func (ctrl *AuthController) RegisterRoutes(r *gin.RouterGroup) { func (ctrl *AuthController) RegisterRoutes(r *gin.RouterGroup) {
r.POST("/auth/login", ctrl.Login) r.POST("/user/auth/login", ctrl.Login)
r.POST("/auth/logout", ctrl.Logout) r.POST("/user/auth/logout", ctrl.Logout)
r.GET("/auth/info", ctrl.GetUserInfo) r.GET("/user/auth/info", ctrl.GetUserInfo)
} }
// Login 用户登录 // Login 用户登录
@ -36,7 +36,7 @@ func (ctrl *AuthController) RegisterRoutes(r *gin.RouterGroup) {
// @Produce json // @Produce json
// @Param request body LoginRequest true "登录信息" // @Param request body LoginRequest true "登录信息"
// @Success 200 {object} common.Response // @Success 200 {object} common.Response
// @Router /auth/login [post] // @Router /user/auth/login [post]
func (ctrl *AuthController) Login(c *gin.Context) { func (ctrl *AuthController) Login(c *gin.Context) {
var req LoginRequest var req LoginRequest
if err := c.ShouldBindJSON(&req); err != nil { if err := c.ShouldBindJSON(&req); err != nil {
@ -60,7 +60,7 @@ func (ctrl *AuthController) Login(c *gin.Context) {
// @Summary 用户登出 // @Summary 用户登出
// @Tags 认证 // @Tags 认证
// @Success 200 {object} common.Response // @Success 200 {object} common.Response
// @Router /auth/logout [post] // @Router /user/auth/logout [post]
func (ctrl *AuthController) Logout(c *gin.Context) { func (ctrl *AuthController) Logout(c *gin.Context) {
token := c.GetHeader("Authorization") token := c.GetHeader("Authorization")
if len(token) > 7 { if len(token) > 7 {
@ -75,7 +75,7 @@ func (ctrl *AuthController) Logout(c *gin.Context) {
// @Summary 获取当前登录用户信息 // @Summary 获取当前登录用户信息
// @Tags 认证 // @Tags 认证
// @Success 200 {object} common.Response // @Success 200 {object} common.Response
// @Router /auth/info [get] // @Router /user/auth/info [get]
func (ctrl *AuthController) GetUserInfo(c *gin.Context) { func (ctrl *AuthController) GetUserInfo(c *gin.Context) {
user := common.GetLoginUser(c) user := common.GetLoginUser(c)
if user == nil { if user == nil {

View File

@ -25,7 +25,8 @@ func NewUserScoreController() *UserScoreController {
func (ctrl *UserScoreController) RegisterRoutes(rg *gin.RouterGroup) { func (ctrl *UserScoreController) RegisterRoutes(rg *gin.RouterGroup) {
group := rg.Group("/user/score") group := rg.Group("/user/score")
{ {
group.GET("/:id", ctrl.Get) // group.GET("/:id", ctrl.Get)
group.GET("/", ctrl.Get)
group.POST("/save-score", ctrl.SaveUserScore) // 新增接口 group.POST("/save-score", ctrl.SaveUserScore) // 新增接口
} }
} }
@ -60,9 +61,10 @@ func (ctrl *UserScoreController) SaveUserScore(c *gin.Context) {
// @Summary 获取当前用户的当前分数 // @Summary 获取当前用户的当前分数
// @Tags 用户分数 // @Tags 用户分数
// @Success 200 {object} common.Response // @Success 200 {object} common.Response
// @Router /user/score/{id} [get] // @Router /user/score [get]
func (ctrl *UserScoreController) Get(c *gin.Context) { func (ctrl *UserScoreController) Get(c *gin.Context) {
item, err := ctrl.userScoreService.GetActiveByID(common.GetLoginUser(c).ID) loginUserId := common.GetLoginUser(c).ID
item, err := ctrl.userScoreService.GetActiveByID(loginUserId)
if err != nil { if err != nil {
common.Error(c, 404, "未找到记录") common.Error(c, 404, "未找到记录")
return return

View File

@ -133,7 +133,7 @@ func (s *UserScoreService) convertEntityToVo(item *entity.YxUserScore) *vo.UserS
CognitioPolyclinic: item.CognitioPolyclinic, CognitioPolyclinic: item.CognitioPolyclinic,
SubjectList: strings.Split(item.Subjects, ","), SubjectList: strings.Split(item.Subjects, ","),
ProfessionalCategory: item.ProfessionalCategory, ProfessionalCategory: item.ProfessionalCategory,
ProfessionalCategoryChildren: strings.Split(item.ProfessionalCategoryChildren, ","), ProfessionalCategoryChildren: []string{},
ProfessionalCategoryChildrenScore: make(map[string]float64), ProfessionalCategoryChildrenScore: make(map[string]float64),
ProfessionalScore: item.ProfessionalScore, ProfessionalScore: item.ProfessionalScore,
CulturalScore: item.CulturalScore, CulturalScore: item.CulturalScore,
@ -143,6 +143,12 @@ func (s *UserScoreService) convertEntityToVo(item *entity.YxUserScore) *vo.UserS
State: item.State, State: item.State,
} }
if item.ProfessionalCategoryChildren == "" {
voItem.ProfessionalCategoryChildren = []string{}
} else {
voItem.ProfessionalCategoryChildren = strings.Split(item.ProfessionalCategoryChildren, ",")
}
// 映射具体字段到子专业成绩 Map // 映射具体字段到子专业成绩 Map
if item.Yybysy > 0 { if item.Yybysy > 0 {
voItem.ProfessionalCategoryChildrenScore["音乐表演声乐"] = item.Yybysy voItem.ProfessionalCategoryChildrenScore["音乐表演声乐"] = item.Yybysy

View File

@ -5,15 +5,15 @@ type UserScoreVO struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type"` // 填报类型(1-普通类 2-艺术类) Type string `json:"type"` // 填报类型(1-普通类 2-艺术类)
EducationalLevel string `json:"educationalLevel"` // 学历层次(1-本科,2-专科) EducationalLevel string `json:"educationalLevel"` // 学历层次(1-本科,2-专科)
CognitioPolyclinic string `json:"CognitioPolyclinic"` // 文理分班(文科/理科) CognitioPolyclinic string `json:"cognitioPolyclinic"` // 文理分班(文科/理科)
SubjectList []string `json:"SubjectList"` // 选课列表 SubjectList []string `json:"subjectList"` // 选课列表
ProfessionalCategory string `json:"ProfessionalCategory"` // 专业类别 ProfessionalCategory string `json:"professionalCategory"` // 专业类别
ProfessionalCategoryChildren []string `json:"ProfessionalCategoryChildren"` // 子级专业类别 ProfessionalCategoryChildren []string `json:"professionalCategoryChildren"` // 子级专业类别
ProfessionalCategoryChildrenScore map[string]float64 `json:"ProfessionalCategoryChildrenScore"` // 子级专业成绩 ProfessionalCategoryChildrenScore map[string]float64 `json:"professionalCategoryChildrenScore"` // 子级专业成绩
ProfessionalScore float64 `json:"ProfessionalScore"` // 专业总分 ProfessionalScore float64 `json:"professionalScore"` // 专业总分
CulturalScore float64 `json:"CulturalScore"` // 文化成绩分 CulturalScore float64 `json:"culturalScore"` // 文化成绩分
EnglishScore float64 `json:"EnglishScore"` // 英语成绩 EnglishScore float64 `json:"englishScore"` // 英语成绩
ChineseScore float64 `json:"ChineseScore"` // 语文成绩 ChineseScore float64 `json:"chineseScore"` // 语文成绩
Province string `json:"Province"` // 高考省份 Province string `json:"province"` // 高考省份
State string `json:"state"` // 状态 State string `json:"state"` // 状态
} }