main.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package main
  2. import (
  3. "context"
  4. "data_ent_wuye/ent_contact"
  5. "data_ent_wuye/ent_legal"
  6. "data_ent_wuye/ent_util"
  7. "flag"
  8. "strings"
  9. "log"
  10. _ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
  11. "github.com/google/uuid"
  12. "github.com/robfig/cron"
  13. )
  14. func init() {
  15. ent_util.InitGlobalVar()
  16. }
  17. func main() {
  18. mode := flag.Int("m", 1, "")
  19. flag.Parse()
  20. if *mode == 1 {
  21. //全量
  22. log.Println("全量任务")
  23. ent_legal.LegalFull()
  24. // projectT()
  25. } else {
  26. //增量
  27. a := cron.New()
  28. a.AddFunc("0 0 20 * * ?", func() {
  29. ent_legal.LegalAdd()
  30. })
  31. a.Start()
  32. select {}
  33. }
  34. }
  35. // 以下测试...
  36. func test() {
  37. //tidb全量
  38. ent_contact.InjectContactTidbInfo()
  39. //凭安全量
  40. info := ent_util.GetOneQyxyInfo("湖南德成大药房连锁有限公司鼎城淮阳店")
  41. name_id := uuid.New().String()
  42. name_id = strings.ReplaceAll(name_id, "-", "")
  43. ent_contact.InjectContactPingAnInfo(name_id, info)
  44. //马克全量
  45. ent_contact.InjectContactMaKeInfo(name_id, map[string]interface{}{"phone": "手机号"})
  46. }
  47. func test1() {
  48. query := `SELECT id,title FROM information.information WHERE id = '000fcf377e334bcc9380b921df93c268'`
  49. rows, err := ent_util.ClickHouseConn.Query(context.Background(), query)
  50. if err != nil {
  51. log.Println(err)
  52. }
  53. isok := 0
  54. type TTT struct {
  55. title string
  56. id string
  57. }
  58. for rows.Next() {
  59. var T TTT
  60. if err := rows.Scan(
  61. &T.id,
  62. &T.title,
  63. ); err != nil {
  64. log.Fatal(err)
  65. }
  66. log.Println(T)
  67. //err := ent_util.ClickHouseConn.Exec(context.Background(), "alter table information.information UPDATE endtime = 1738252800 where id = ?", id)
  68. //if err != nil {
  69. // log.Debug("update err:", err)
  70. //}
  71. isok++
  72. }
  73. log.Println("总计数量", isok)
  74. }
  75. func test2() {
  76. query := `ALTER TABLE information.information DELETE WHERE id='676470119ae64a18bab5d1fdb5f06bb3' `
  77. query = `-- TRUNCATE TABLE information.information_copy;`
  78. err := ent_util.ClickHouseConn.Exec(context.Background(), query)
  79. if err != nil {
  80. log.Println(err)
  81. }
  82. rows, err := ent_util.ClickHouseConn.Query(context.Background(), "select bitmapToArray(tag_bitmap) tag_bitmap from information.information limit 10")
  83. if err != nil {
  84. log.Println(err)
  85. }
  86. for rows.Next() {
  87. var (
  88. tag_bitmap []uint64
  89. )
  90. if err := rows.Scan(
  91. &tag_bitmap,
  92. ); err != nil {
  93. log.Println(err)
  94. }
  95. }
  96. }
  97. func projectT() {
  98. query := `SELECT project_id,project_name,business_type,property_form,subclass,area,city,district,buyer,create_time FROM information.transaction_info`
  99. rows, err := ent_util.ClickHouseConn.Query(context.Background(), query)
  100. if err != nil {
  101. log.Println(err)
  102. }
  103. count := 0
  104. var (
  105. project_id string
  106. project_name string
  107. business_type string
  108. property_form []string
  109. subclass []string
  110. area string
  111. city string
  112. district string
  113. create_time int64
  114. buyer string
  115. )
  116. for rows.Next() {
  117. if err := rows.Scan(
  118. &project_id,
  119. &project_name,
  120. &business_type,
  121. &property_form,
  122. &subclass,
  123. &area,
  124. &city,
  125. &district,
  126. &buyer,
  127. &create_time,
  128. ); err != nil {
  129. log.Println(err)
  130. } else {
  131. ent_util.EsClinet.UpdateNewDoc("transaction_info", "", map[string]interface{}{
  132. "_id": project_id,
  133. "project_name": project_name,
  134. "business_type": business_type,
  135. "property_form": property_form,
  136. "subclass": subclass,
  137. "area": area,
  138. "city": city,
  139. "district": district,
  140. "create_time": create_time,
  141. "buyer": buyer,
  142. "winner": buyer,
  143. "agency": buyer,
  144. })
  145. }
  146. count++
  147. log.Println("count ", count)
  148. }
  149. }