123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package main
- import (
- "mongodb"
- "qfw/util"
- "reflect"
- "sync"
- )
- func main() {
- //taskQyxy()
- taskBidding()
- }
- func taskQyxy() {
- sess := Mgo.GetMgoConn()
- defer Mgo.DestoryMongoConn(sess)
- pool := make(chan bool, 3)
- wg := &sync.WaitGroup{}
- q := map[string]interface{}{"_id": mongodb.StringTOBsonId("61d552398e4217aff3dd7462")}
- it := sess.DB("wjh").C("oprd_qyxy").Find(q).Select(nil).Iter()
- count := 0
- for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
- if count%2000 == 0 {
- util.Debug("current:", count)
- }
- pool <- true
- wg.Add(1)
- go func(tmp map[string]interface{}) {
- defer func() {
- <-pool
- wg.Done()
- }()
- save := make(map[string]interface{})
- for s, s2 := range QyxyFieldsMap {
- if s == "company_id" {
- save[s] = mongodb.BsonIdToSId(tmp["_id"])
- } else if s == "partners" {
- if partners, ok := tmp["partners"].([]interface{}); ok {
- for _, p := range partners {
- p1 := p.(map[string]interface{})
- ptSave := make(map[string]interface{})
- for s3, s4 := range QyxyPartner {
- if s3 == "company_id" {
- ptSave["company_id"] = mongodb.BsonIdToSId(tmp["_id"])
- } else {
- if p1[s3] != nil && reflect.TypeOf(p1[s3]).String() == s4 {
- ptSave[s3] = p1[s3]
- }
- }
- }
- if len(ptSave) > 0 {
- MysqlTool.Insert("qyxy_partner", ptSave)
- }
- }
- }
- } else {
- if tmp[s] != nil && reflect.TypeOf(tmp[s]).String() == s2 {
- save[s] = tmp[s]
- }
- }
- }
- if len(save) > 0 {
- MysqlTool.Insert("qyxy", save)
- }
- }(tmp)
- }
- wg.Wait()
- }
- func taskBidding() {
- sess := Mgo.GetMgoConn()
- defer Mgo.DestoryMongoConn(sess)
- pool := make(chan bool, 3)
- wg := &sync.WaitGroup{}
- q := map[string]interface{}{"_id": mongodb.StringTOBsonId("5d4a77cda5cb26b9b7e6986a")}
- it := sess.DB("wjh").C("oprd_bidding").Find(q).Select(nil).Iter()
- count := 0
- for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
- if count%2000 == 0 {
- util.Debug("current:", count)
- }
- pool <- true
- wg.Add(1)
- go func(tmp map[string]interface{}) {
- defer func() {
- <-pool
- wg.Done()
- }()
- save := make(map[string]interface{})
- for s, s2 := range BiddingMap {
- if s == "_id" {
- save[s] = mongodb.BsonIdToSId(tmp["_id"])
- } else if s == "contract_guarantee" || s == "bid_guarantee" {
- if tmp[s] != nil {
- if tmp[s] == true {
- save[s] = 1
- } else {
- save[s] = 0
- }
- }
- } else {
- if s == "budget" {
- util.Debug(reflect.TypeOf(tmp[s]).String())
- }
- if tmp[s] != nil && reflect.TypeOf(tmp[s]).String() == s2 {
- save[s] = tmp[s]
- }
- }
- }
- if len(save) > 0 {
- MysqlTool.Insert("bidding", save)
- }
- }(tmp)
- }
- wg.Wait()
- }
- func taskProject() {
- sess := Mgo.GetMgoConn()
- defer Mgo.DestoryMongoConn(sess)
- pool := make(chan bool, 3)
- wg := &sync.WaitGroup{}
- q := map[string]interface{}{"_id": mongodb.StringTOBsonId("5d4a77cda5cb26b9b7e6986a")}
- it := sess.DB("wjh").C("oprd_project").Find(q).Select(nil).Iter()
- count := 0
- for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
- if count%2000 == 0 {
- util.Debug("current:", count)
- }
- pool <- true
- wg.Add(1)
- go func(tmp map[string]interface{}) {
- defer func() {
- <-pool
- wg.Done()
- }()
- save := make(map[string]interface{})
- for s, s2 := range BiddingMap {
- if s == "_id" {
- save[s] = mongodb.BsonIdToSId(tmp["_id"])
- } else if s == "contract_guarantee" || s == "bid_guarantee" {
- if tmp[s] != nil {
- if tmp[s] == true {
- save[s] = 1
- } else {
- save[s] = 0
- }
- }
- } else {
- if tmp[s] != nil && reflect.TypeOf(tmp[s]).String() == s2 {
- save[s] = tmp[s]
- }
- }
- }
- if len(save) > 0 {
- MysqlTool.Insert("bidding", save)
- }
- }(tmp)
- }
- wg.Wait()
- }
|