123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- package main
- import (
- "fmt"
- "log"
- "sync"
- qu "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/mysql"
- "github.com/gogf/gf/v2/util/gconv"
- )
- var config map[string]interface{}
- var Mgo *mongodb.MongodbSim
- var TidbCall *mysql.Mysql
- var TidbBi *mysql.Mysql
- func InitMongo(mgs map[string]interface{}) {
- Mgo = &mongodb.MongodbSim{
- MongodbAddr: qu.ObjToString(mgs["address"]),
- Size: qu.IntAll(mgs["size"]),
- DbName: qu.ObjToString(mgs["dbName"]),
- ReplSet: qu.ObjToString(mgs["replSet"]),
- UserName: qu.ObjToString(mgs["userName"]),
- Password: qu.ObjToString(mgs["password"]),
- }
- Mgo.InitPool()
- log.Println("初始化 mongodb")
- }
- func InitMysql(mys map[string]interface{}) {
- TidbBi = &mysql.Mysql{
- Address: qu.ObjToString(mys["address"]),
- UserName: qu.ObjToString(mys["userName"]),
- PassWord: qu.ObjToString(mys["passWord"]),
- DBName: qu.ObjToString(mys["dbName"]),
- MaxOpenConns: qu.IntAll(mys["maxOpenConns"]),
- MaxIdleConns: qu.IntAll(mys["maxIdleConns"]),
- }
- TidbBi.Init()
- log.Println("初始化 mysql")
- }
- func InitTidb(mys map[string]interface{}) {
- TidbCall = &mysql.Mysql{
- Address: qu.ObjToString(mys["address"]),
- UserName: qu.ObjToString(mys["userName"]),
- PassWord: qu.ObjToString(mys["passWord"]),
- DBName: qu.ObjToString(mys["dbName"]),
- MaxOpenConns: qu.IntAll(mys["maxOpenConns"]),
- MaxIdleConns: qu.IntAll(mys["maxIdleConns"]),
- }
- TidbCall.Init()
- log.Println("初始化 Tidb")
- }
- func init() {
- qu.ReadConfig(&config)
- //
- mgs, _ := config["mongodb"].(map[string]interface{})
- InitMongo(mgs)
- mys, _ := config["tidb1"].(map[string]interface{})
- InitMysql(mys)
- tbs, _ := config["tidb2"].(map[string]interface{})
- InitTidb(tbs)
- }
- func main() {
- //
- log.Println("电销 开始")
- // do1()
- log.Println("电销 结束")
- //
- log.Println("合力易捷 开始")
- // do2()
- log.Println("合力易捷 结束")
- }
- //电销线索刷库
- func do1() {
- var (
- pool = make(chan bool, 5)
- wait = &sync.WaitGroup{}
- )
- i := 0
- for {
- count := TidbBi.CountBySql(`SELECT count(1) FROM dwd_f_crm_clue_info where company_nature is null`)
- if count == 0 {
- log.Println("find no data end")
- return
- }
- TidbBi.SelectByBath(10, func(l *[]map[string]interface{}) bool {
- for _, v := range *l {
- pool <- true
- wait.Add(1)
- i++
- go func(thisData map[string]interface{}) {
- defer func() {
- <-pool
- wait.Done()
- }()
- id := gconv.Int64(thisData["id"])
- query := map[string]interface{}{
- "id": id,
- }
- cluename := gconv.String(thisData["cluename"])
- update := getCompanyType(cluename)
- ok := TidbBi.Update("dwd_f_crm_clue_info", query, update)
- if !ok {
- log.Println("crm clue info update err", query, update)
- }
- }(v)
- }
- if i%5000 == 0 {
- log.Println(fmt.Sprintf("current --- %d ", i))
- }
- return true
- }, `SELECT * FROM dwd_f_crm_clue_info where company_nature is null limit 500`)
- }
- wait.Wait()
- }
- //电销线索刷库 无并发
- func do1_bak() {
- i := 0
- for {
- count := TidbBi.CountBySql(`SELECT count(1) FROM dwd_f_crm_clue_info where company_nature is null`)
- if count == 0 {
- log.Println("find no data end")
- return
- }
- TidbBi.SelectByBath(10, func(l *[]map[string]interface{}) bool {
- for _, v := range *l {
- i++
- id := gconv.Int64(v["id"])
- query := map[string]interface{}{
- "id": id,
- }
- cluename := gconv.String(v["cluename"])
- update := getCompanyType(cluename)
- ok := TidbBi.Update("dwd_f_crm_clue_info", query, update)
- if !ok {
- log.Println("crm clue info update err", query, update)
- }
- }
- if i%5000 == 0 {
- log.Println(fmt.Sprintf("current --- %d ", i))
- }
- return true
- }, `SELECT * FROM dwd_f_crm_clue_info where company_nature is null limit 500`)
- }
- }
- //合力易捷刷库
- func do2() {
- i := 0
- var (
- pool = make(chan bool, 5)
- wait = &sync.WaitGroup{}
- )
- for {
- count := TidbCall.CountBySql(`SELECT count(1) FROM customer where company_nature is null`)
- if count == 0 {
- log.Println("find no data end")
- return
- }
- TidbCall.SelectByBath(10, func(l *[]map[string]interface{}) bool {
- for _, v := range *l {
- pool <- true
- wait.Add(1)
- i++
- go func(thisData map[string]interface{}) {
- defer func() {
- <-pool
- wait.Done()
- }()
- id := gconv.String(thisData["unique_id"])
- query := map[string]interface{}{
- "unique_id": id,
- }
- company := gconv.String(thisData["company"])
- update := getCompanyType(company)
- ok := TidbCall.Update("customer", query, update)
- if !ok {
- log.Println("customer info update err", query, update)
- }
- }(v)
- }
- if i%5000 == 0 {
- log.Println(fmt.Sprintf("current --- %d ", i))
- }
- return true
- }, `SELECT * FROM customer where company_nature is null limit 1000`)
- }
- wait.Wait()
- }
- //合力易捷刷库 无并发
- func do2_bak() {
- i := 0
- for {
- count := TidbCall.CountBySql(`SELECT count(1) FROM customer where company_nature is null`)
- if count == 0 {
- log.Println("find no data end")
- return
- }
- TidbCall.SelectByBath(10, func(l *[]map[string]interface{}) bool {
- for _, v := range *l {
- i++
- id := gconv.String(v["unique_id"])
- query := map[string]interface{}{
- "unique_id": id,
- }
- company := gconv.String(v["company"])
- update := getCompanyType(company)
- ok := TidbCall.Update("customer", query, update)
- if !ok {
- log.Println("customer info update err", query, update)
- }
- }
- if i%5000 == 0 {
- log.Println(fmt.Sprintf("current --- %d ", i))
- }
- return true
- }, `SELECT * FROM customer where company_nature is null limit 1000`)
- }
- }
- //公司性质、公司核验
- func getCompanyType(name string) map[string]interface{} {
- data := map[string]interface{}{
- "company_nature": 0,
- "company_verification": 0,
- }
- if c := TidbBi.CountBySql(`select count(1) from group_company_name where company_name=?`, name); c > 0 {
- data["company_nature"] = 1
- }
- if c := Mgo.Count("qyxy_std", map[string]interface{}{"company_name": name}); c > 0 {
- data["company_verification"] = 1
- }
- return data
- }
|