feat:获取成绩接口
This commit is contained in:
parent
2440e201bb
commit
8a8c0f0933
|
|
@ -4,6 +4,7 @@
|
|||
"Cognitio",
|
||||
"Fzby",
|
||||
"gonic",
|
||||
"gorm",
|
||||
"Xjysby",
|
||||
"Xjysdy",
|
||||
"Yybyqy",
|
||||
|
|
|
|||
|
|
@ -23,3 +23,9 @@
|
|||
- `YxUserScoreController`: 用户分数控制器。
|
||||
- `YxVolunteerController`: 志愿控制器。
|
||||
- `YxVolunteerRecordController`: 志愿明细控制器。
|
||||
|
||||
## server/modules/user
|
||||
- `UserScoreService`: 用户成绩服务。
|
||||
- `GetActiveByID(userID string)`: 获取用户当前激活的成绩,返回 `UserScoreVO`。
|
||||
- `SaveUserScore(req *dto.SaveScoreRequest)`: 保存用户成绩,处理旧记录状态更新及 DTO 转换。
|
||||
- `UserScoreVO`: 用户成绩视图对象,包含基础信息、选课列表及子专业成绩映射。
|
||||
|
|
|
|||
|
|
@ -47,3 +47,12 @@
|
|||
- 创建了 `server/modules/yx/dto/` 目录。
|
||||
- 将 `SaveScoreRequest` 及其校验逻辑移动到 `yx_user_score_dto.go`。
|
||||
- Controller 改为引用 `dto` 包。
|
||||
|
||||
### [任务执行] 处理 UserScoreVO 信息转换
|
||||
- **操作目标**: 在 `UserScoreService` 中实现 Entity 到 VO 的转换,并完善 `UserScoreVO` 定义。
|
||||
- **影响范围**: `server/modules/user/vo/user_score_vo.go`, `server/modules/user/service/user_score_service.go`
|
||||
- **修改前记录**: `UserScoreVO` 为空,`GetActiveByID` 返回原始 Entity。
|
||||
- **修改结果**:
|
||||
- 定义了 `UserScoreVO` 结构体,其字段设计参考了 `SaveScoreRequest`。
|
||||
- 在 `UserScoreService` 中实现了 `convertEntityToVo` 私有方法,处理了逗号分隔字符串到切片的转换,以及具体分数字段到 Map 的映射。
|
||||
- 更新 `GetActiveByID` 返回 `UserScoreVO` 对象。
|
||||
|
|
|
|||
|
|
@ -24,4 +24,7 @@
|
|||
- `mapper/`: 数据访问层实现。
|
||||
- `service/`: 业务逻辑层实现。
|
||||
- `controller/`: 控制层实现。
|
||||
- `user/`: 用户相关业务扩展。
|
||||
- `vo/`: 视图对象,用于数据展示。
|
||||
- `service/`: 业务逻辑层。
|
||||
- `docs/`: Swagger API文档。
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"server/config"
|
||||
"server/modules/user/vo"
|
||||
"server/modules/yx/dto"
|
||||
"server/modules/yx/entity"
|
||||
"server/modules/yx/mapper"
|
||||
"server/modules/yx/service"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserScoreService struct {
|
||||
|
|
@ -16,8 +20,25 @@ type UserScoreService struct {
|
|||
mapper *mapper.YxUserScoreMapper
|
||||
}
|
||||
|
||||
func (s *UserScoreService) GetActiveByID(d string) (any, any) {
|
||||
panic("unimplemented")
|
||||
// GetActiveByID 获取当前激活的成绩
|
||||
func (s *UserScoreService) GetActiveByID(userID string) (*vo.UserScoreVO, error) {
|
||||
var score entity.YxUserScore
|
||||
// 明确指定字段,提高可读性
|
||||
err := config.DB.Model(&entity.YxUserScore{}).
|
||||
Where("create_by = ? AND state = ?", userID, "1"). // 注意:yx_user_score 表中关联用户的是 create_by
|
||||
First(&score).Error
|
||||
// 错误处理
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fmt.Errorf("未找到用户的激活成绩记录")
|
||||
}
|
||||
return nil, fmt.Errorf("查询成绩记录失败: %w", err)
|
||||
}
|
||||
|
||||
// 转换为 VO
|
||||
scoreVO := s.convertEntityToVo(&score)
|
||||
|
||||
return scoreVO, nil
|
||||
}
|
||||
|
||||
func NewUserScoreService() *UserScoreService {
|
||||
|
|
@ -77,32 +98,70 @@ func (s *UserScoreService) convertDtoToEntity(req *dto.SaveScoreRequest) *entity
|
|||
ChineseScore: *req.ChineseScore,
|
||||
Province: req.Province,
|
||||
State: "1", // 默认状态
|
||||
Type: "2", // 艺术类
|
||||
CreateBy: req.CreateBy,
|
||||
}
|
||||
|
||||
// 映射子专业成绩到具体字段
|
||||
if v, ok := req.ProfessionalCategoryChildrenScore["音乐表演声乐"]; ok {
|
||||
entityItem.Yybysy = v
|
||||
}
|
||||
if v, ok := req.ProfessionalCategoryChildrenScore["音乐表演器乐"]; ok {
|
||||
entityItem.Yybyqy = v
|
||||
}
|
||||
if v, ok := req.ProfessionalCategoryChildrenScore["音乐教育"]; ok {
|
||||
entityItem.Yyjy = v
|
||||
}
|
||||
if v, ok := req.ProfessionalCategoryChildrenScore["戏剧影视导演"]; ok {
|
||||
entityItem.Xjysdy = v
|
||||
}
|
||||
if v, ok := req.ProfessionalCategoryChildrenScore["戏剧影视表演"]; ok {
|
||||
entityItem.Xjysby = v
|
||||
}
|
||||
if v, ok := req.ProfessionalCategoryChildrenScore["服装表演"]; ok {
|
||||
entityItem.Fzby = v
|
||||
}
|
||||
|
||||
// 映射子专业成绩
|
||||
s.mapProfessionalScores(entityItem, req.ProfessionalCategoryChildrenScore)
|
||||
return entityItem
|
||||
}
|
||||
|
||||
// 私有方法:映射专业成绩
|
||||
func (s *UserScoreService) mapProfessionalScores(entity *entity.YxUserScore, scoreMap map[string]float64) {
|
||||
if v, ok := scoreMap["音乐表演声乐"]; ok {
|
||||
entity.Yybysy = v
|
||||
// 私有方法:Entity 转 VO
|
||||
func (s *UserScoreService) convertEntityToVo(item *entity.YxUserScore) *vo.UserScoreVO {
|
||||
voItem := &vo.UserScoreVO{
|
||||
ID: item.ID,
|
||||
Type: item.Type,
|
||||
EducationalLevel: item.EducationalLevel,
|
||||
CognitioPolyclinic: item.CognitioPolyclinic,
|
||||
SubjectList: strings.Split(item.Subjects, ","),
|
||||
ProfessionalCategory: item.ProfessionalCategory,
|
||||
ProfessionalCategoryChildren: strings.Split(item.ProfessionalCategoryChildren, ","),
|
||||
ProfessionalCategoryChildrenScore: make(map[string]float64),
|
||||
ProfessionalScore: item.ProfessionalScore,
|
||||
CulturalScore: item.CulturalScore,
|
||||
EnglishScore: item.EnglishScore,
|
||||
ChineseScore: item.ChineseScore,
|
||||
Province: item.Province,
|
||||
State: item.State,
|
||||
}
|
||||
if v, ok := scoreMap["音乐表演器乐"]; ok {
|
||||
entity.Yybyqy = v
|
||||
|
||||
// 映射具体字段到子专业成绩 Map
|
||||
if item.Yybysy > 0 {
|
||||
voItem.ProfessionalCategoryChildrenScore["音乐表演声乐"] = item.Yybysy
|
||||
}
|
||||
if v, ok := scoreMap["音乐教育"]; ok {
|
||||
entity.Yyjy = v
|
||||
if item.Yybyqy > 0 {
|
||||
voItem.ProfessionalCategoryChildrenScore["音乐表演器乐"] = item.Yybyqy
|
||||
}
|
||||
if v, ok := scoreMap["戏剧影视导演"]; ok {
|
||||
entity.Xjysdy = v
|
||||
if item.Yyjy > 0 {
|
||||
voItem.ProfessionalCategoryChildrenScore["音乐教育"] = item.Yyjy
|
||||
}
|
||||
if v, ok := scoreMap["戏剧影视表演"]; ok {
|
||||
entity.Xjysby = v
|
||||
if item.Xjysdy > 0 {
|
||||
voItem.ProfessionalCategoryChildrenScore["戏剧影视导演"] = item.Xjysdy
|
||||
}
|
||||
if v, ok := scoreMap["服装表演"]; ok {
|
||||
entity.Fzby = v
|
||||
if item.Xjysby > 0 {
|
||||
voItem.ProfessionalCategoryChildrenScore["戏剧影视表演"] = item.Xjysby
|
||||
}
|
||||
if item.Fzby > 0 {
|
||||
voItem.ProfessionalCategoryChildrenScore["服装表演"] = item.Fzby
|
||||
}
|
||||
|
||||
return voItem
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package vo
|
||||
|
||||
// UserScoreVO 用户成绩展示对象
|
||||
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"` // 高考省份
|
||||
State string `json:"state"` // 状态
|
||||
}
|
||||
|
|
@ -7,3 +7,11 @@
|
|||
2. 创建了 `server/modules/yx/dto/yx_user_score_dto.go`,将 `SaveScoreRequest` 结构体及 `Validate` 方法移动至此。
|
||||
3. 修改 `server/modules/yx/controller/yx_user_score_controller.go`,引入 `dto` 包并使用 `dto.SaveScoreRequest`。
|
||||
- **执行结果**: 代码结构更清晰,符合 DTO 分层规范。
|
||||
|
||||
## 会话 ID: 20251219-01
|
||||
- **执行原因**: 用户要求在 `UserScoreService` 中处理 `scoreVO` 信息,参考 `yx_user_score_dto` 的结构。
|
||||
- **执行过程**:
|
||||
1. 定义 `server/modules/user/vo/user_score_vo.go` 中的 `UserScoreVO` 结构。
|
||||
2. 在 `server/modules/user/service/user_score_service.go` 中实现 `convertEntityToVo` 逻辑。
|
||||
3. 修改 `GetActiveByID` 方法,使其返回 `vo.UserScoreVO`。
|
||||
- **执行结果**: 实现了 Entity 到 VO 的完整转换逻辑,支持子专业分数的 Map 映射。
|
||||
|
|
|
|||
Loading…
Reference in New Issue