diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 4a07f1bbb9bb743ea0e33caf2362bc590ade31ea..3489bf904010d9bae39f63fb28bd640b24280695 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -113,22 +113,30 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara if familyId == 0 || (name == "" && nameplate == "" && declaration == "" && icon == "") { return nil } + // 修改铭牌 + 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;" + result := model.Db.Exec(sql, familyId, nameplate, nameplate, familyId) + if result.Error != nil { + return myerr.WrapErr(result.Error) + } + if result.RowsAffected <= 0 { + return myerr.WrapErr(bizerr.GroupPowerHaveChangeInfo) + } + return nil + } db := model.Db.Model(GroupPower{}) updateMap := make(map[string]interface{}) if name != "" { updateMap["name"] = name } - if nameplate != "" { - updateMap["nameplate"] = nameplate - db = db.Where("not exists (select id from group_power where nameplate = ?)", nameplate) - } if declaration != "" { updateMap["declaration"] = declaration } if icon != "" { updateMap["icon"] = icon } - result := db.Where("id = ?", familyId).Updates(updateMap).Limit(1) + result := db.Where("group_power.id = ?", familyId).Updates(updateMap).Limit(1) if result.Error != nil { return myerr.WrapErr(result.Error) } diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index cec52b414edaba08ed1e8c7d15db65473693d4a6..0f22f371e81336062eb888325fa8191441259702 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -768,6 +768,9 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { } if groupInfo != nil { info.Nameplate = groupInfo.Name + if len(info.Nameplate) > 6 { + info.Nameplate = info.Nameplate[:6] + } } } // 家族月排名 @@ -1420,7 +1423,7 @@ func GroupPowerSetInfo(c *gin.Context) (*mycontext.MyContext, error) { return myContext, bizerr.GroupPowerChangeNameplate } // 检查铭牌长度和唯一性 - if len(para.Nameplate) > 10 { + if len(para.Nameplate) > 6 { return myContext, bizerr.GroupPowerHaveTooLong } if groupPower_m.IsExistsNameplate(model, para.Nameplate) {