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() }