From d6c63af142d90d331e377c34b7ce09128b44b6b0 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 24 Mar 2023 16:53:25 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=9B=B4=E6=96=B0=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E5=90=8C=E6=AD=A5=E9=93=AD=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/family.go | 15 ++++++++++++++- domain/model/groupPower_m/groupPower.go | 21 +++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index fa7c13c..2c881c3 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -2,6 +2,7 @@ package groupPower_m import ( "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" "hilo-group/_const/enum/groupPower_e" "hilo-group/common" @@ -116,9 +117,13 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara if familyId == 0 || (name == "" && nameplate == "" && declaration == "" && icon == "") { return nil } + var groupPower GroupPower + if err := model.DB().Model(GroupPower{}).Where("id = ?", familyId).First(&groupPower).Error; err != nil { + return err + } // 修改铭牌 if nameplate != "" { - sql := "UPDATE `group_power` a left join (SELECT ? `id` FROM group_power WHERE nameplate = ?) b on a.id = b.id SET a.`nameplate`=? where a.id=? and b.id is null;" + sql := "UPDATE `group_power` a left join (SELECT ? `id` FROM group_power WHERE nameplate = ?) b on a.id = b.id SET a.`nameplate`=?,modify_nameplate = 1 where a.id=? and b.id is null;" result := model.Db.Exec(sql, familyId, nameplate, nameplate, familyId) if result.Error != nil { return myerr.WrapErr(result.Error) @@ -132,6 +137,14 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara updateMap := make(map[string]interface{}) if name != "" { updateMap["name"] = name + if groupPower.ModifyNameplate != mysql.YES { + // 同步修改铭牌 + n := len([]rune(name)) + if n > 6 { + n = 6 + } + updateMap["nameplate"] = string([]rune(name[0:n])) + } } if declaration != "" { updateMap["declaration"] = declaration diff --git a/domain/model/groupPower_m/groupPower.go b/domain/model/groupPower_m/groupPower.go index 37c4fbf..52c382c 100644 --- a/domain/model/groupPower_m/groupPower.go +++ b/domain/model/groupPower_m/groupPower.go @@ -22,16 +22,17 @@ import ( type GroupPower struct { mysql.Entity - *domain.Model `gorm:"-"` - GroupUid mysql.Str - Name mysql.Str - Status groupPower_e.GroupPowerStatus - Nameplate mysql.Str // 铭牌 - Declaration mysql.Str // 宣言 - Icon mysql.Str // 头像 - GradeName mysql.Str // 等级称号 - GradeMedal mysql.Str // 等级勋章图片 - Grade groupPower_e.GroupPowerGrade `gorm:"-"` + *domain.Model `gorm:"-"` + GroupUid mysql.Str + Name mysql.Str + Status groupPower_e.GroupPowerStatus + Nameplate mysql.Str // 铭牌 + Declaration mysql.Str // 宣言 + Icon mysql.Str // 头像 + GradeName mysql.Str // 等级称号 + GradeMedal mysql.Str // 等级勋章图片 + Grade groupPower_e.GroupPowerGrade `gorm:"-"` + ModifyNameplate mysql.YesNo } type GroupPowerUser struct { -- 2.22.0