diff --git a/server/modules/user/service/user_score_service.go b/server/modules/user/service/user_score_service.go index d8c0bf6..61d3379 100644 --- a/server/modules/user/service/user_score_service.go +++ b/server/modules/user/service/user_score_service.go @@ -21,6 +21,7 @@ import ( type UserScoreService struct { yxUserScoreService *service.YxUserScoreService + yxVolunteerService *service.YxVolunteerService yxCalculationMajorService *service.YxCalculationMajorService mapper *mapper.YxUserScoreMapper } @@ -193,6 +194,8 @@ func (s *UserScoreService) SaveUserScore(req *dto.SaveScoreRequest) (vo.UserScor return vo.UserScoreVO{}, fmt.Errorf("缓存成绩记录失败: %w", err) } + // 创建志愿表 + s.yxVolunteerService.CreateByScoreId(entityItem.ID, req.CreateBy) return userScoreVO, nil } diff --git a/server/modules/yx/entity/yx_volunteer.go b/server/modules/yx/entity/yx_volunteer.go index 950b93d..feb4d35 100644 --- a/server/modules/yx/entity/yx_volunteer.go +++ b/server/modules/yx/entity/yx_volunteer.go @@ -6,7 +6,7 @@ import "time" type YxVolunteer struct { ID string `gorm:"column:id;primaryKey" json:"id"` VolunteerName string `gorm:"column:volunteer_name" json:"volunteerName"` // 志愿单名称 - ScoreID string `gorm:"column:score_id" json:"scoreId"` // 使用成绩id + ScoreId string `gorm:"column:score_id" json:"scoreId"` // 使用成绩id CreateType string `gorm:"column:create_type;default:1" json:"createType"` // 生成类型(1.手动生成,2.智能生成) State string `gorm:"column:state;default:0" json:"state"` // 志愿单状态(0-否,1.正在使用,2-历史) CreateBy string `gorm:"column:create_by" json:"createBy"` // 创建人 diff --git a/server/modules/yx/mapper/yx_volunteer_mapper.go b/server/modules/yx/mapper/yx_volunteer_mapper.go index 6297836..bf23489 100644 --- a/server/modules/yx/mapper/yx_volunteer_mapper.go +++ b/server/modules/yx/mapper/yx_volunteer_mapper.go @@ -10,6 +10,10 @@ import ( type YxVolunteerMapper struct{} +func (m *YxVolunteerMapper) CloseOtherVolunteer(userId string) { + config.DB.Model(&entity.YxVolunteer{}).Where("create_by = ? ", userId).Updates(map[string]interface{}{"state": "0"}) +} + func NewYxVolunteerMapper() *YxVolunteerMapper { return &YxVolunteerMapper{} } diff --git a/server/modules/yx/service/yx_volunteer_service.go b/server/modules/yx/service/yx_volunteer_service.go index 0fad5bc..dd92138 100644 --- a/server/modules/yx/service/yx_volunteer_service.go +++ b/server/modules/yx/service/yx_volunteer_service.go @@ -4,6 +4,7 @@ package service import ( "server/modules/yx/entity" "server/modules/yx/mapper" + "time" "github.com/google/uuid" ) @@ -64,3 +65,24 @@ func (s *YxVolunteerService) BatchUpsert(items []entity.YxVolunteer, updateColum func (s *YxVolunteerService) BatchDelete(ids []string) error { return s.mapper.BatchDelete(ids) } + +// 根据ScoreId创建新志愿表 +func (s *YxVolunteerService) CreateByScoreId(scoreId string, userId string) error { + volunteer := entity.YxVolunteer{} + volunteer.ID = uuid.New().String() + + // 志愿表名称格式 时间戳 20260101134501志愿表 + volunteer.VolunteerName = time.Now().Format("20060102150405") + "志愿表" + + volunteer.ScoreId = scoreId + volunteer.CreateType = "1" + volunteer.State = "1" + volunteer.CreateBy = userId + volunteer.CreateTime = time.Now() + volunteer.UpdateTime = time.Now() + + // 先关闭当前用户其他志愿单 + s.mapper.CloseOtherVolunteer(userId) + // 创建志愿表 + return s.mapper.Create(&volunteer) +}