Commit e3be2346 authored by hujiebin's avatar hujiebin

feat:庆幸有冗余数据

parent f44d7fed
...@@ -81,13 +81,14 @@ type CpInfo struct { ...@@ -81,13 +81,14 @@ type CpInfo struct {
} }
type CpLevel struct { type CpLevel struct {
CpId uint64 CpId uint64
Level uint64 Level uint64
CreatedTime time.Time
} }
func main() { func main() {
var cpInfos []*CpInfo var cpInfos []*CpInfo
if err := mysql.ProdReadOnlyDB.Table("cp_relation").Select("id,user_id1,user_id2,created_time").Find(&cpInfos).Error; err != nil { if err := mysql.ProdReadOnlyDB.Table("cp_relation").Select("id,user_id1,user_id2").Find(&cpInfos).Error; err != nil {
panic(err) panic(err)
} }
var cpIds []uint64 var cpIds []uint64
...@@ -95,7 +96,7 @@ func main() { ...@@ -95,7 +96,7 @@ func main() {
cpIds = append(cpIds, v.Id) cpIds = append(cpIds, v.Id)
} }
var cpLevels []CpLevel var cpLevels []CpLevel
if err := mysql.ProdReadOnlyDB.Table("cp_level").Select("cp_id,level").Where("cp_id in ?", cpIds).Find(&cpLevels).Error; err != nil { if err := mysql.ProdReadOnlyDB.Table("cp_level").Select("cp_id,level,created_time").Where("cp_id in ?", cpIds).Find(&cpLevels).Error; err != nil {
panic(err) panic(err)
} }
var userIds []uint64 var userIds []uint64
...@@ -106,6 +107,7 @@ func main() { ...@@ -106,6 +107,7 @@ func main() {
for _, v2 := range cpLevels { for _, v2 := range cpLevels {
if v.Id == v2.CpId { if v.Id == v2.CpId {
cpInfos[i].Level = v2.Level cpInfos[i].Level = v2.Level
cpInfos[i].CreatedTime = v2.CreatedTime
break break
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment