123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package main
- import (
- "log"
- "mgo_tidb_update/config"
- "app.yhyue.com/moapp/jybase/mongodb"
- "github.com/gogf/gf/v2/util/gconv"
- )
- func do() {
- tag_subinformation := ""
- tag_subinformation_arr := []string{"物业1", "物业2"}
- for k, v := range tag_subinformation_arr {
- tag_subinformation += v
- if k != len(tag_subinformation_arr)-1 {
- tag_subinformation += ","
- }
- }
- log.Println(tag_subinformation)
- }
- func do2() {
- // ok := config.Tidb.Update("dws_f_bid_baseinfo", map[string]interface{}{
- // "infoid": "5ad8c18fa5cb26b9b72ce09d",
- // }, map[string]interface{}{
- // "tag_topinformation": "物业",
- // })
- // log.Println(ok)
- // return
- values := []string{"infoid", "tag_topinformation"}
- args := [][]interface{}{
- []interface{}{"5ad8c18fa5cb26b9b72ce09d", "物业1"},
- []interface{}{"5ad8c1e9a5cb26b9b72d01c0", "物业2"},
- []interface{}{"5ad8c1e9a5cb26b9b72d01cb", "物业1,物业2"},
- []interface{}{"123", "物业11"},
- }
- config.Tidb.UpdateBath("dws_f_bid_baseinfo", values, args)
- log.Println(config.Tidb.SelectBySql(`select infoid,tag_topinformation from dws_f_bid_baseinfo limit 1`))
- }
- func initBidding() {
- query := map[string]interface{}{
- "tag_topinformation": map[string]interface{}{
- "$exists": true,
- },
- }
- config.Mgo_Bidding.Count("bidding", query)
- return
- m := map[string]int{}
- session := config.Mgo_Bidding.GetMgoConn()
- defer config.Mgo_Bidding.DestoryMongoConn(session)
- iter := session.DB("qfw_data").C("bidding").Find(query).Sort("_id").Iter()
- ct := 0
- for thisData := map[string]interface{}{}; iter.Next(&thisData); {
- ct++
- if ct%50000 == 0 {
- log.Println("已加载", ct)
- }
- _id := mongodb.BsonIdToSId(thisData["_id"])
- m[_id]++
- thisData = map[string]interface{}{}
- }
- log.Println(len(m))
- }
- func main2() {
- values := []string{"infoid", "tag_topinformation"}
- config.Mgo_Bidding.GetMgoConn()
- defer config.Mgo_Bidding.DestoryMongoConn(session)
- args := [][]interface{}{}
- // do2()
- // return
- values := []string{"infoid", "tag_topinformation"}
- session := config.Mgo_Bidding.GetMgoConn()
- defer config.Mgo_Bidding.DestoryMongoConn(session)
- args := [][]interface{}{}
- iter := session.DB("qfw_data").C("bidding").Find(nil).Sort("_id").Iter()
- ct := 0
- for thisData := map[string]interface{}{}; iter.Next(&thisData); {
- ct++
- if ct%50000 == 0 {
- log.Println("已加载", ct)
- }
- _id := mongodb.BsonIdToSId(thisData["_id"])
- if thisData["tag_topinformation"] != nil {
- tag_topinformation := ""
- tag_topinformation_arr := gconv.Strings(thisData["tag_topinformation"])
- for k, v := range tag_topinformation_arr {
- tag_topinformation += v
- if k != len(tag_topinformation_arr)-1 {
- tag_topinformation += ","
- }
- }
- log.Println(_id)
- args = append(args, []interface{}{_id, tag_topinformation})
- }
- if ct%100 == 0 {
- if len(args) > 0 {
- config.Tidb.UpdateBath("dws_f_bid_baseinfo", values, args)
- args = [][]interface{}{}
- }
- }
- thisData = map[string]interface{}{}
- }
- if len(args) > 0 {
- config.Tidb.UpdateBath("dws_f_bid_baseinfo", values, args)
- args = [][]interface{}{}
- }
- log.Println("结束")
- }
- func main() {
- do()
- return
- limit := 200
- c := 0
- values := []string{"infoid", "tag_topinformation"}
- args := [][]interface{}{}
- bl := false
- lastid := int64(0)
- // lastid = int64(16547665)
- // lastid = int64(16547574)
- for {
- config.Tidb.SelectByBath(limit, func(l *[]map[string]interface{}) bool {
- for _, v := range *l {
- lastid = gconv.Int64(v["id"])
- c++
- if c%10000 == 0 {
- log.Println("已加载", c, lastid)
- }
- infoid := gconv.String(v["infoid"])
- d, ok := config.Mgo_Bidding.FindById("bidding", infoid, `["tag_topinformation":1}`)
- if ok && d != nil && len(*d) > 0 {
- if (*d)["tag_topinformation"] != nil {
- tag_topinformation := ""
- tag_topinformation_arr := gconv.Strings((*d)["tag_topinformation"])
- for k, v := range tag_topinformation_arr {
- tag_topinformation += v
- if k != len(tag_topinformation_arr)-1 {
- tag_topinformation += ","
- }
- }
- args = append(args, []interface{}{infoid, tag_topinformation})
- }
- }
- if len(args) == 50 {
- config.Tidb.UpdateBath("dws_f_bid_baseinfo", values, args)
- args = [][]interface{}{}
- }
- }
- if len(*l) < limit {
- bl = true
- }
- return true
- }, `SELECT infoid,id FROM dws_f_bid_baseinfo where id > ? order by id LIMIT ? `, lastid, limit)
- if bl {
- break
- }
- }
- if len(args) > 0 {
- config.Tidb.UpdateBath("dws_f_bid_baseinfo", values, args)
- args = [][]interface{}{}
- }
- log.Println("结束", lastid)
- }
|