feat(cultivate-flower): 新增等待时长字段并更新阶段规则校验逻辑

This commit is contained in:
Austin
2026-10-08 12:47:17 +08:00
parent 5a7d8407bc
commit 55ae8b2acd
5 changed files with 34 additions and 14 deletions
@@ -51,6 +51,7 @@ type cultivateStageRuleDTO struct {
RequiredPoints uint `json:"requiredPoints"`
WaterPoints uint `json:"waterPoints"`
FertilizePoints uint `json:"fertilizePoints"`
WaitHours uint `json:"waitHours"`
AllowedActions []string `json:"allowedActions"`
ImageFileID string `json:"imageFileId"`
AnimationFileID string `json:"animationFileId"`
@@ -182,7 +183,7 @@ func flowerPayload(in *sysin.CultivateFlowerEditInp) map[string]any {
rules = append(rules, map[string]any{
"id": strconv.FormatUint(rule.Id, 10), "stage": rule.Stage, "next_stage": rule.NextStage,
"required_points": rule.RequiredPoints, "water_points": rule.WaterPoints, "fertilize_points": rule.FertilizePoints,
"allowed_actions": rule.AllowedActions, "image_file_id": rule.ImageFileId, "animation_file_id": rule.AnimationFileId,
"wait_hours": rule.WaitHours, "allowed_actions": rule.AllowedActions, "image_file_id": rule.ImageFileId, "animation_file_id": rule.AnimationFileId,
"progress_text_template": rule.ProgressTextTemplate, "completion_text": rule.CompletionText, "sort_no": rule.SortNo,
})
}
@@ -227,7 +228,7 @@ func flowerViewModel(item *cultivateFlowerDTO) (*sysin.CultivateFlowerViewModel,
}
result.StageRules = append(result.StageRules, &sysin.CultivateStageRuleEditInp{
Id: id, Stage: rule.Stage, NextStage: rule.NextStage, RequiredPoints: rule.RequiredPoints,
WaterPoints: rule.WaterPoints, FertilizePoints: rule.FertilizePoints, AllowedActions: rule.AllowedActions,
WaterPoints: rule.WaterPoints, FertilizePoints: rule.FertilizePoints, WaitHours: rule.WaitHours, AllowedActions: rule.AllowedActions,
ImageFileId: rule.ImageFileID, AnimationFileId: rule.AnimationFileID,
ProgressTextTemplate: rule.ProgressTextTemplate, CompletionText: rule.CompletionText, SortNo: rule.SortNo,
})
@@ -18,6 +18,7 @@ type CultivateStageRuleEditInp struct {
RequiredPoints uint `json:"requiredPoints"`
WaterPoints uint `json:"waterPoints"`
FertilizePoints uint `json:"fertilizePoints"`
WaitHours uint `json:"waitHours"`
AllowedActions []string `json:"allowedActions"`
ImageFileId string `json:"imageFileId"`
AnimationFileId string `json:"animationFileId"`
@@ -64,8 +65,8 @@ func (in *CultivateFlowerEditInp) Filter(ctx context.Context) error {
return gerror.New("成长阶段不能重复")
}
seen[rule.Stage] = true
if rule.Stage != "bloom" && rule.RequiredPoints == 0 {
return gerror.New("非开花阶段升级阈值必须大于0")
if rule.Stage != "bloom" && rule.RequiredPoints == 0 && rule.WaitHours == 0 {
return gerror.New("非开花阶段必须配置升级阈值或等待时长")
}
if rule.NextStage != "" && !validStage[rule.NextStage] {
return gerror.New("下一阶段不正确")