tool.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package tool
  2. import (
  3. "data_ai/extract"
  4. "data_ai/ul"
  5. log "github.com/donnie4w/go-logger/logger"
  6. "sync"
  7. )
  8. // 工具修正程序
  9. func StartToolInfo() {
  10. log.Debug("工具开始大模型修正数据······")
  11. q := map[string]interface{}{}
  12. pool_mgo := make(chan bool, ul.Reading)
  13. wg_mgo := &sync.WaitGroup{}
  14. sess := ul.SourceMgo.GetMgoConn()
  15. defer ul.SourceMgo.DestoryMongoConn(sess)
  16. total, isok := 0, 0
  17. it := sess.DB(ul.SourceMgo.DbName).C(ul.Ext_Name).Find(&q).Sort("_id").Iter()
  18. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  19. if total%100 == 0 {
  20. log.Debug("cur index ", total)
  21. }
  22. isok++
  23. pool_mgo <- true
  24. wg_mgo.Add(1)
  25. go func(tmp map[string]interface{}) {
  26. defer func() {
  27. <-pool_mgo
  28. wg_mgo.Done()
  29. }()
  30. u_id := ul.BsonTOStringId(tmp["_id"])
  31. data := extract.ResolveInfo(tmp)
  32. if len(data) > 0 || u_id == "" {
  33. tmp["ai_zhipu"] = data
  34. update_info := make(map[string]interface{}, 0)
  35. is_unset := ul.ChooseCheckDataAI(tmp, &update_info)
  36. update_info["ai_zhipu"] = data
  37. //清洗与记录
  38. if len(update_info) > 0 {
  39. //$set
  40. ul.SourceMgo.UpdateById(ul.Ext_Name, u_id, map[string]interface{}{
  41. "$set": update_info,
  42. })
  43. }
  44. if is_unset {
  45. //"$unset"
  46. ul.SourceMgo.UpdateById(ul.Ext_Name, u_id, map[string]interface{}{
  47. "$unset": ul.Unset_Check,
  48. })
  49. }
  50. }
  51. }(tmp)
  52. tmp = make(map[string]interface{})
  53. }
  54. wg_mgo.Wait()
  55. log.Debug("ai is over ...")
  56. }