sync_group_power_nameplate.go 953 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
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
	}
}