Commit 40dfe214 authored by hujiebin's avatar hujiebin

1

parent 2e543c09
......@@ -10,4 +10,6 @@ charge_max:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o charge_max charge_max.go
group_power_data:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o group_power_data group_power_data.go
cp_pairs_stat:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o cp_pairs_stat cp_pairs_stat.go
package main
import (
"fmt"
"git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/script/mysql"
"github.com/tealeg/xlsx"
)
type CpPairData struct {
Level string
Cnt int
KsaCnt int
NotKsaCnt int
}
func ats26(a interface{}) string {
return fmt.Sprintf("%v", a)
}
func getAreaByCode2(code string) string {
sql := "SELECT area FROM res_country c,user u WHERE u.country = c.name AND u.code = ?"
var area int
if err := mysql.ProdReadOnlyDB.Raw(sql, code).Scan(&area).Error; err != nil {
panic(err)
}
if area == 1 {
return "阿语区"
}
return "非阿语区"
}
type CpInfo struct {
Id uint64
UserId1 uint64
UserId2 uint64
Code1 string
Code2 string
UserId1Area string
UserId2Area string
Level uint64
}
type CpLevel struct {
CpId uint64
Level uint64
}
func main() {
var cpInfos []CpInfo
if err := mysql.ProdReadOnlyDB.Table("cp_relation").Select("id,user_id1,user_id2").Find(&cpInfos).Error; err != nil {
panic(err)
}
var cpIds []uint64
for _, v := range cpInfos {
cpIds = append(cpIds, v.Id)
}
var cpLevels []CpLevel
if err := mysql.ProdReadOnlyDB.Table("cp_level").Select("cp_id,level").Where("cp_id in ?", cpIds).Find(&cpLevels).Error; err != nil {
panic(err)
}
var userIds []uint64
var users []model.User
for i, v := range cpInfos {
userIds = append(userIds, v.UserId1)
userIds = append(userIds, v.UserId2)
for _, v2 := range cpLevels {
if v.Id == v2.CpId {
cpInfos[i].Level = v2.Level
break
}
}
}
if err := mysql.ProdReadOnlyDB.Table("user").Where("id in ?", userIds).Find(&users).Error; err != nil {
panic(err)
}
uM := make(map[uint64]model.User)
for i, v := range users {
uM[v.Id] = users[i]
}
for i, v := range cpInfos {
cpInfos[i].Code1 = uM[v.UserId1].Code
cpInfos[i].Code2 = uM[v.UserId2].Code
cpInfos[i].UserId1Area = getAreaByCode2(uM[v.UserId1].Code)
cpInfos[i].UserId2Area = getAreaByCode2(uM[v.UserId2].Code)
}
excelFileName := fmt.Sprintf("./cp数据.xlsx")
xlFile := xlsx.NewFile()
sheet, err := xlFile.AddSheet("cp")
if err != nil {
panic(err)
}
row := sheet.AddRow()
c1, c2, c3, c4, c5, c6 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = "cp ID", "userId1", "userId2", "user1区域", "user2区域", "等级"
for _, d := range cpInfos {
row := sheet.AddRow()
c1, c2, c3, c4, c5, c6 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value =
ats26(d.Id), ats26(d.UserId1), ats26(d.UserId2), ats26(d.UserId1Area), ats26(d.UserId2Area), ats26(d.Level)
}
_ = xlFile.Save(excelFileName)
//var data []CpPairData
}
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