package main import ( "git.hilo.cn/hilo-common/script/model" "git.hilo.cn/hilo-common/script/mysql" ) func main() { var powerOwners []model.GroupPowerUser if err := mysql.ProdReadOnlyDB.Model(model.GroupPowerUser{}).Where("role = 2").Find(&powerOwners).Error; err != nil { panic(err) } for _, owner := range powerOwners { var groupInfo model.GroupInfo if err := mysql.ProdReadOnlyDB.Model(model.GroupInfo{}).Where("owner = ?", owner.UserId).First(&groupInfo).Error; err != nil { continue } var cutNameplate []rune n := len([]rune(groupInfo.Name)) if n > 6 { n = 6 } cutNameplate = []rune(groupInfo.Name[0:n]) if len(cutNameplate) <= 0 { panic("empty nameplate") } if owner.GroupPowerId <= 0 { panic("0 powerId") } if err := mysql.ProdWriteDB.Model(model.GroupPower{}).Where("id = ?", owner.GroupPowerId).UpdateColumn("nameplate", string(cutNameplate)).Error; err != nil { panic(err) } //break } }