main.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package main
  2. import (
  3. "mongodb"
  4. "qfw/util"
  5. "reflect"
  6. "sync"
  7. )
  8. func main() {
  9. //taskQyxy()
  10. taskBidding()
  11. }
  12. func taskQyxy() {
  13. sess := Mgo.GetMgoConn()
  14. defer Mgo.DestoryMongoConn(sess)
  15. pool := make(chan bool, 3)
  16. wg := &sync.WaitGroup{}
  17. q := map[string]interface{}{"_id": mongodb.StringTOBsonId("61d552398e4217aff3dd7462")}
  18. it := sess.DB("wjh").C("oprd_qyxy").Find(q).Select(nil).Iter()
  19. count := 0
  20. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  21. if count%2000 == 0 {
  22. util.Debug("current:", count)
  23. }
  24. pool <- true
  25. wg.Add(1)
  26. go func(tmp map[string]interface{}) {
  27. defer func() {
  28. <-pool
  29. wg.Done()
  30. }()
  31. save := make(map[string]interface{})
  32. for s, s2 := range QyxyFieldsMap {
  33. if s == "company_id" {
  34. save[s] = mongodb.BsonIdToSId(tmp["_id"])
  35. } else if s == "partners" {
  36. if partners, ok := tmp["partners"].([]interface{}); ok {
  37. for _, p := range partners {
  38. p1 := p.(map[string]interface{})
  39. ptSave := make(map[string]interface{})
  40. for s3, s4 := range QyxyPartner {
  41. if s3 == "company_id" {
  42. ptSave["company_id"] = mongodb.BsonIdToSId(tmp["_id"])
  43. } else {
  44. if p1[s3] != nil && reflect.TypeOf(p1[s3]).String() == s4 {
  45. ptSave[s3] = p1[s3]
  46. }
  47. }
  48. }
  49. if len(ptSave) > 0 {
  50. MysqlTool.Insert("qyxy_partner", ptSave)
  51. }
  52. }
  53. }
  54. } else {
  55. if tmp[s] != nil && reflect.TypeOf(tmp[s]).String() == s2 {
  56. save[s] = tmp[s]
  57. }
  58. }
  59. }
  60. if len(save) > 0 {
  61. MysqlTool.Insert("qyxy", save)
  62. }
  63. }(tmp)
  64. }
  65. wg.Wait()
  66. }
  67. func taskBidding() {
  68. sess := Mgo.GetMgoConn()
  69. defer Mgo.DestoryMongoConn(sess)
  70. pool := make(chan bool, 3)
  71. wg := &sync.WaitGroup{}
  72. q := map[string]interface{}{"_id": mongodb.StringTOBsonId("5d4a77cda5cb26b9b7e6986a")}
  73. it := sess.DB("wjh").C("oprd_bidding").Find(q).Select(nil).Iter()
  74. count := 0
  75. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  76. if count%2000 == 0 {
  77. util.Debug("current:", count)
  78. }
  79. pool <- true
  80. wg.Add(1)
  81. go func(tmp map[string]interface{}) {
  82. defer func() {
  83. <-pool
  84. wg.Done()
  85. }()
  86. save := make(map[string]interface{})
  87. for s, s2 := range BiddingMap {
  88. if s == "_id" {
  89. save[s] = mongodb.BsonIdToSId(tmp["_id"])
  90. } else if s == "contract_guarantee" || s == "bid_guarantee" {
  91. if tmp[s] != nil {
  92. if tmp[s] == true {
  93. save[s] = 1
  94. } else {
  95. save[s] = 0
  96. }
  97. }
  98. } else {
  99. if s == "budget" {
  100. util.Debug(reflect.TypeOf(tmp[s]).String())
  101. }
  102. if tmp[s] != nil && reflect.TypeOf(tmp[s]).String() == s2 {
  103. save[s] = tmp[s]
  104. }
  105. }
  106. }
  107. if len(save) > 0 {
  108. MysqlTool.Insert("bidding", save)
  109. }
  110. }(tmp)
  111. }
  112. wg.Wait()
  113. }
  114. func taskProject() {
  115. sess := Mgo.GetMgoConn()
  116. defer Mgo.DestoryMongoConn(sess)
  117. pool := make(chan bool, 3)
  118. wg := &sync.WaitGroup{}
  119. q := map[string]interface{}{"_id": mongodb.StringTOBsonId("5d4a77cda5cb26b9b7e6986a")}
  120. it := sess.DB("wjh").C("oprd_project").Find(q).Select(nil).Iter()
  121. count := 0
  122. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  123. if count%2000 == 0 {
  124. util.Debug("current:", count)
  125. }
  126. pool <- true
  127. wg.Add(1)
  128. go func(tmp map[string]interface{}) {
  129. defer func() {
  130. <-pool
  131. wg.Done()
  132. }()
  133. save := make(map[string]interface{})
  134. for s, s2 := range BiddingMap {
  135. if s == "_id" {
  136. save[s] = mongodb.BsonIdToSId(tmp["_id"])
  137. } else if s == "contract_guarantee" || s == "bid_guarantee" {
  138. if tmp[s] != nil {
  139. if tmp[s] == true {
  140. save[s] = 1
  141. } else {
  142. save[s] = 0
  143. }
  144. }
  145. } else {
  146. if tmp[s] != nil && reflect.TypeOf(tmp[s]).String() == s2 {
  147. save[s] = tmp[s]
  148. }
  149. }
  150. }
  151. if len(save) > 0 {
  152. MysqlTool.Insert("bidding", save)
  153. }
  154. }(tmp)
  155. }
  156. wg.Wait()
  157. }