diff --git a/.vscode/settings.json b/.vscode/settings.json index 393a84f..f0904cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,12 @@ { "kiroAgent.configureMCP": "Disabled", "cSpell.words": [ + "apikey", "Cognitio", "Fzby", "gonic", "gorm", + "swaggo", "Xjysby", "Xjysdy", "Yybyqy", diff --git a/server/config/database.go b/server/config/database.go index b337179..f7adcc1 100644 --- a/server/config/database.go +++ b/server/config/database.go @@ -30,7 +30,7 @@ func InitDB() { } // 连接池配置 - sqlDB.SetMaxIdleConns(10) // 最大空闲连接数 + sqlDB.SetMaxIdleConns(20) // 最大空闲连接数 sqlDB.SetMaxOpenConns(100) // 最大打开连接数 sqlDB.SetConnMaxLifetime(time.Hour) // 连接最大存活时间 diff --git a/server/docs/docs.go b/server/docs/docs.go index fd6ae88..4da8f36 100644 --- a/server/docs/docs.go +++ b/server/docs/docs.go @@ -15,71 +15,6 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "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": { "get": { "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": { "post": { "tags": [ diff --git a/server/docs/swagger.json b/server/docs/swagger.json index aa7d9f7..70b8714 100644 --- a/server/docs/swagger.json +++ b/server/docs/swagger.json @@ -9,71 +9,6 @@ "host": "localhost:8080", "basePath": "/api", "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": { "get": { "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": { "post": { "tags": [ diff --git a/server/docs/swagger.yaml b/server/docs/swagger.yaml index 3939aaf..400af6d 100644 --- a/server/docs/swagger.yaml +++ b/server/docs/swagger.yaml @@ -538,47 +538,6 @@ info: title: 艺考招生管理系统 API version: "2.0" 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: get: parameters: @@ -751,6 +710,47 @@ paths: summary: Sys用户登出 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}: get: responses: diff --git a/server/main.go b/server/main.go index 71674df..5d49029 100644 --- a/server/main.go +++ b/server/main.go @@ -15,6 +15,7 @@ import ( _ "server/docs" "server/middleware" sysController "server/modules/system/controller" + userController "server/modules/user/controller" yxController "server/modules/yx/controller" "github.com/gin-gonic/gin" @@ -81,6 +82,10 @@ func main() { yxController.NewYxVolunteerController().RegisterRoutes(api) yxController.NewYxVolunteerRecordController().RegisterRoutes(api) + // 注册 User 模块路由 + userController.NewUserScoreController().RegisterRoutes(api) + userController.NewAuthController().RegisterRoutes(api) + // 创建 HTTP 服务器 srv := &http.Server{ Addr: ":8080", diff --git a/server/middleware/auth.go b/server/middleware/auth.go index 2ed4163..7a0ee34 100644 --- a/server/middleware/auth.go +++ b/server/middleware/auth.go @@ -21,8 +21,10 @@ const ( // 白名单路径 (不需要登录即可访问) var whiteList = []string{ - "/api/auth/login", - "/api/auth/register", + "/api/sys/auth/login", + "/api/sys/auth/register", + "/api/user/auth/login", + "/api/user/auth/register", "/swagger/", "/swagger/index.html", } diff --git a/server/modules/user/controller/auth_controller.go b/server/modules/user/controller/user_auth_controller.go similarity index 88% rename from server/modules/user/controller/auth_controller.go rename to server/modules/user/controller/user_auth_controller.go index aa3b911..5765f78 100644 --- a/server/modules/user/controller/auth_controller.go +++ b/server/modules/user/controller/user_auth_controller.go @@ -24,9 +24,9 @@ func NewAuthController() *AuthController { } func (ctrl *AuthController) RegisterRoutes(r *gin.RouterGroup) { - r.POST("/auth/login", ctrl.Login) - r.POST("/auth/logout", ctrl.Logout) - r.GET("/auth/info", ctrl.GetUserInfo) + r.POST("/user/auth/login", ctrl.Login) + r.POST("/user/auth/logout", ctrl.Logout) + r.GET("/user/auth/info", ctrl.GetUserInfo) } // Login 用户登录 @@ -36,7 +36,7 @@ func (ctrl *AuthController) RegisterRoutes(r *gin.RouterGroup) { // @Produce json // @Param request body LoginRequest true "登录信息" // @Success 200 {object} common.Response -// @Router /auth/login [post] +// @Router /user/auth/login [post] func (ctrl *AuthController) Login(c *gin.Context) { var req LoginRequest if err := c.ShouldBindJSON(&req); err != nil { @@ -60,7 +60,7 @@ func (ctrl *AuthController) Login(c *gin.Context) { // @Summary 用户登出 // @Tags 认证 // @Success 200 {object} common.Response -// @Router /auth/logout [post] +// @Router /user/auth/logout [post] func (ctrl *AuthController) Logout(c *gin.Context) { token := c.GetHeader("Authorization") if len(token) > 7 { @@ -75,7 +75,7 @@ func (ctrl *AuthController) Logout(c *gin.Context) { // @Summary 获取当前登录用户信息 // @Tags 认证 // @Success 200 {object} common.Response -// @Router /auth/info [get] +// @Router /user/auth/info [get] func (ctrl *AuthController) GetUserInfo(c *gin.Context) { user := common.GetLoginUser(c) if user == nil { diff --git a/server/modules/user/controller/score_controller.go b/server/modules/user/controller/user_score_controller.go similarity index 90% rename from server/modules/user/controller/score_controller.go rename to server/modules/user/controller/user_score_controller.go index 5252c2e..14979d1 100644 --- a/server/modules/user/controller/score_controller.go +++ b/server/modules/user/controller/user_score_controller.go @@ -25,7 +25,8 @@ func NewUserScoreController() *UserScoreController { func (ctrl *UserScoreController) RegisterRoutes(rg *gin.RouterGroup) { 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) // 新增接口 } } @@ -60,9 +61,10 @@ func (ctrl *UserScoreController) SaveUserScore(c *gin.Context) { // @Summary 获取当前用户的当前分数 // @Tags 用户分数 // @Success 200 {object} common.Response -// @Router /user/score/{id} [get] +// @Router /user/score [get] 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 { common.Error(c, 404, "未找到记录") return diff --git a/server/modules/user/service/user_score_service.go b/server/modules/user/service/user_score_service.go index cfe4953..a32e431 100644 --- a/server/modules/user/service/user_score_service.go +++ b/server/modules/user/service/user_score_service.go @@ -133,7 +133,7 @@ func (s *UserScoreService) convertEntityToVo(item *entity.YxUserScore) *vo.UserS CognitioPolyclinic: item.CognitioPolyclinic, SubjectList: strings.Split(item.Subjects, ","), ProfessionalCategory: item.ProfessionalCategory, - ProfessionalCategoryChildren: strings.Split(item.ProfessionalCategoryChildren, ","), + ProfessionalCategoryChildren: []string{}, ProfessionalCategoryChildrenScore: make(map[string]float64), ProfessionalScore: item.ProfessionalScore, CulturalScore: item.CulturalScore, @@ -143,6 +143,12 @@ func (s *UserScoreService) convertEntityToVo(item *entity.YxUserScore) *vo.UserS State: item.State, } + if item.ProfessionalCategoryChildren == "" { + voItem.ProfessionalCategoryChildren = []string{} + } else { + voItem.ProfessionalCategoryChildren = strings.Split(item.ProfessionalCategoryChildren, ",") + } + // 映射具体字段到子专业成绩 Map if item.Yybysy > 0 { voItem.ProfessionalCategoryChildrenScore["音乐表演声乐"] = item.Yybysy diff --git a/server/modules/user/vo/user_score_vo.go b/server/modules/user/vo/user_score_vo.go index 50b935c..93780fb 100644 --- a/server/modules/user/vo/user_score_vo.go +++ b/server/modules/user/vo/user_score_vo.go @@ -5,15 +5,15 @@ type UserScoreVO struct { ID string `json:"id"` Type string `json:"type"` // 填报类型(1-普通类 2-艺术类) EducationalLevel string `json:"educationalLevel"` // 学历层次(1-本科,2-专科) - CognitioPolyclinic string `json:"CognitioPolyclinic"` // 文理分班(文科/理科) - SubjectList []string `json:"SubjectList"` // 选课列表 - ProfessionalCategory string `json:"ProfessionalCategory"` // 专业类别 - ProfessionalCategoryChildren []string `json:"ProfessionalCategoryChildren"` // 子级专业类别 - ProfessionalCategoryChildrenScore map[string]float64 `json:"ProfessionalCategoryChildrenScore"` // 子级专业成绩 - ProfessionalScore float64 `json:"ProfessionalScore"` // 专业总分 - CulturalScore float64 `json:"CulturalScore"` // 文化成绩分 - EnglishScore float64 `json:"EnglishScore"` // 英语成绩 - ChineseScore float64 `json:"ChineseScore"` // 语文成绩 - Province string `json:"Province"` // 高考省份 + CognitioPolyclinic string `json:"cognitioPolyclinic"` // 文理分班(文科/理科) + SubjectList []string `json:"subjectList"` // 选课列表 + ProfessionalCategory string `json:"professionalCategory"` // 专业类别 + ProfessionalCategoryChildren []string `json:"professionalCategoryChildren"` // 子级专业类别 + ProfessionalCategoryChildrenScore map[string]float64 `json:"professionalCategoryChildrenScore"` // 子级专业成绩 + ProfessionalScore float64 `json:"professionalScore"` // 专业总分 + CulturalScore float64 `json:"culturalScore"` // 文化成绩分 + EnglishScore float64 `json:"englishScore"` // 英语成绩 + ChineseScore float64 `json:"chineseScore"` // 语文成绩 + Province string `json:"province"` // 高考省份 State string `json:"state"` // 状态 }