tool.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package tool
  2. import (
  3. "data_ai/extract"
  4. "data_ai/ul"
  5. log "github.com/donnie4w/go-logger/logger"
  6. "github.com/google/uuid"
  7. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  8. "strings"
  9. "sync"
  10. )
  11. // 工具修正程序
  12. func StartToolInfo() {
  13. log.Debug("工具开始大模型修正数据······")
  14. q := map[string]interface{}{}
  15. pool_mgo := make(chan bool, ul.Reading)
  16. wg_mgo := &sync.WaitGroup{}
  17. sess := ul.SourceMgo.GetMgoConn()
  18. defer ul.SourceMgo.DestoryMongoConn(sess)
  19. total, isok := 0, 0
  20. it := sess.DB(ul.SourceMgo.DbName).C(ul.Ext_Name).Find(&q).Sort("_id").Iter()
  21. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  22. if total%100 == 0 {
  23. log.Debug("cur index ", total)
  24. }
  25. isok++
  26. pool_mgo <- true
  27. wg_mgo.Add(1)
  28. go func(tmp map[string]interface{}) {
  29. defer func() {
  30. <-pool_mgo
  31. wg_mgo.Done()
  32. }()
  33. u_id := ul.BsonTOStringId(tmp["_id"])
  34. data := extract.ResolveInfo(tmp)
  35. if len(data) > 0 || u_id == "" {
  36. tmp["ai_zhipu"] = data
  37. update_info := make(map[string]interface{}, 0)
  38. is_unset := ul.ChooseCheckDataAI(tmp, &update_info)
  39. if update_info["com_package"] == nil { //构建单包信息···
  40. com_package := CreatSingleFieldInfo(tmp, update_info)
  41. update_info["com_package"] = com_package
  42. }
  43. update_info["ai_zhipu"] = data
  44. //清洗与记录
  45. if len(update_info) > 0 {
  46. //$set
  47. ul.SourceMgo.UpdateById(ul.Ext_Name, u_id, map[string]interface{}{
  48. "$set": update_info,
  49. })
  50. }
  51. if is_unset {
  52. //"$unset"
  53. ul.SourceMgo.UpdateById(ul.Ext_Name, u_id, map[string]interface{}{
  54. "$unset": ul.Unset_Check,
  55. })
  56. }
  57. }
  58. }(tmp)
  59. tmp = make(map[string]interface{})
  60. }
  61. wg_mgo.Wait()
  62. log.Debug("ai is over ...")
  63. }
  64. // 工具更新程序
  65. func StartToolUpdateInfo() {
  66. log.Debug("工具开始大模型修正数据······")
  67. q := map[string]interface{}{}
  68. pool_mgo := make(chan bool, ul.Reading)
  69. wg_mgo := &sync.WaitGroup{}
  70. sess := ul.SourceMgo.GetMgoConn()
  71. defer ul.SourceMgo.DestoryMongoConn(sess)
  72. total, isok := 0, 0
  73. it := sess.DB(ul.SourceMgo.DbName).C(ul.Ext_Name).Find(&q).Sort("_id").Iter()
  74. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  75. if total%100 == 0 {
  76. log.Debug("cur index ", total)
  77. }
  78. isok++
  79. pool_mgo <- true
  80. wg_mgo.Add(1)
  81. go func(tmp map[string]interface{}) {
  82. defer func() {
  83. <-pool_mgo
  84. wg_mgo.Done()
  85. }()
  86. u_id := ul.BsonTOStringId(tmp["_id"])
  87. b_id := qu.ObjToString(tmp["id"])
  88. data := ul.BidMgo.FindById("bidding", b_id)
  89. if len(data) > 0 && u_id != "" && b_id != "" && data["ai_zhipu"] != nil {
  90. ai_zhipu := qu.ObjToMap(data["ai_zhipu"])
  91. tmp["ai_zhipu"] = ai_zhipu
  92. update_info := make(map[string]interface{}, 0)
  93. is_unset := ul.ChooseCheckDataAI(tmp, &update_info)
  94. update_info["ai_zhipu"] = ai_zhipu
  95. //清洗与记录
  96. if len(update_info) > 0 { //$set
  97. ul.SourceMgo.UpdateById(ul.Ext_Name, u_id, map[string]interface{}{
  98. "$set": update_info,
  99. })
  100. }
  101. if is_unset { //"$unset"
  102. ul.SourceMgo.UpdateById(ul.Ext_Name, u_id, map[string]interface{}{
  103. "$unset": ul.Unset_Check,
  104. })
  105. }
  106. }
  107. }(tmp)
  108. tmp = make(map[string]interface{})
  109. }
  110. wg_mgo.Wait()
  111. log.Debug("ai update is over ...")
  112. }
  113. func CreatSingleFieldInfo(tmp map[string]interface{}, update_info map[string]interface{}) []map[string]interface{} {
  114. pkgArr := []map[string]interface{}{}
  115. com_package := map[string]interface{}{}
  116. package_id := uuid.New().String()
  117. package_id = strings.ReplaceAll(package_id, "-", "")
  118. com_package["package_id"] = package_id
  119. com_package["name"] = qu.ObjToString(tmp["projectname"])
  120. if update_info["budget"] != nil {
  121. com_package["budget"] = update_info["budget"]
  122. } else {
  123. if tmp["budget"] != nil {
  124. com_package["budget"] = tmp["budget"]
  125. }
  126. }
  127. subtype := qu.ObjToString(update_info["subtype"])
  128. if subtype == "" {
  129. subtype = qu.ObjToString(tmp["subtype"])
  130. }
  131. if subtype == "单一" || subtype == "中标" || subtype == "成交" || subtype == "合同" {
  132. if update_info["bidamount"] != nil {
  133. com_package["bidamount"] = update_info["bidamount"]
  134. } else {
  135. if tmp["bidamount"] != nil {
  136. com_package["bidamount"] = tmp["bidamount"]
  137. }
  138. }
  139. if update_info["winner"] != nil {
  140. com_package["winner"] = update_info["winner"]
  141. } else {
  142. if tmp["winner"] != nil {
  143. com_package["winner"] = tmp["winner"]
  144. }
  145. }
  146. }
  147. pkgArr = append(pkgArr, com_package)
  148. return pkgArr
  149. }