main.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package main
  2. import (
  3. "go.mongodb.org/mongo-driver/bson"
  4. "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  6. "log"
  7. "strings"
  8. "time"
  9. )
  10. var (
  11. MgoB *mongodb.MongodbSim
  12. updatePool = make(chan []map[string]interface{}, 5000)
  13. )
  14. func InitMgo() {
  15. MgoB = &mongodb.MongodbSim{
  16. MongodbAddr: "172.17.189.140:27080",
  17. //MongodbAddr: "127.0.0.1:27083",
  18. Size: 10,
  19. DbName: "qfw",
  20. UserName: "SJZY_RWbid_ES",
  21. Password: "SJZY@B4i4D5e6S",
  22. //Direct: true,
  23. }
  24. MgoB.InitPool()
  25. // 本地数据库
  26. //MgoB = &mongodb.MongodbSim{
  27. // //MongodbAddr: "172.17.189.140:27080",
  28. // MongodbAddr: "127.0.0.1:27017",
  29. // Size: 10,
  30. // DbName: "wcc",
  31. // //UserName: "SJZY_RWbid_ES",
  32. // //Password: "SJZY@B4i4D5e6S",
  33. // //Direct: true,
  34. //}
  35. //MgoB.InitPool()
  36. // 测试环境
  37. //MgoB = &mongodb.MongodbSim{
  38. // MongodbAddr: "192.168.3.206:27002",
  39. // //MongodbAddr: "127.0.0.1:27017",
  40. // Size: 10,
  41. // DbName: "qfw_data",
  42. // UserName: "root",
  43. // Password: "root",
  44. // //Direct: true,
  45. //}
  46. //MgoB.InitPool()
  47. }
  48. func main() {
  49. //deleteEs()
  50. log.Println("数据删除完成")
  51. //------------------//
  52. //InitMgo()
  53. //getBidding2()
  54. //callAi()
  55. //getCount()
  56. //updateTop()
  57. //findData()
  58. //getCompanyName()
  59. //log.Println("over")
  60. //select {}
  61. //SpecialData()
  62. //StdData()
  63. // ==============================================
  64. ////1.调用分类大模型
  65. //title := "松江南站大型居住社区C18-26-01号地块动迁安置房(智能化工程)"
  66. //detail := "<br><ul ><li>招标项目编号:</li><li >e3100000151006395007</li></ul><ul ><li>相关标段(包)编号:</li><li >e3100000151006395007001</li></ul><ul ><li>公示标题:</li><li >松江南站大型居住社区C18-26-01号地块动迁安置房(智能化工程)</li></ul><ul ><li>公示内容:</li><li >第一中标候选人:上海浩臣机电科技有限公司,投标价格:1228.1990,得分/投票:合格;第二中标候选人:上海格瑞特机电系统工程有限公司,投标价格:1230.1015,得分/投票:合格;</li></ul><ul ><li>公示发布时间:</li><li >2024-01-03</li></ul><ul ><li>公示发布媒介:</li><li >http://zjw.sh.gov.cn</li></ul><ul ><li>公示源URL:</li><li ><br>https://ciac.zjw.sh.gov.cn/XMJYPTInterWeb/Tender/PrinttoPdf?zbgcid=65693</li></ul><ul ><li>公示类型:</li><li >正常</li></ul><ul ><li>公示开始时间:</li><li >2024-01-03</li></ul><ul ><li>公示结束时间:</li><li >2024-01-05</li></ul>"
  67. //
  68. //data := map[string]interface{}{
  69. // "title": title,
  70. // "detail": detail,
  71. //}
  72. //reqData := map[string]interface{}{
  73. // "texts": []interface{}{data},
  74. //}
  75. //
  76. //url := "http://172.17.162.35:24401"
  77. //now := time.Now()
  78. //res := sendAi(reqData, url)
  79. ////log.Println("res", res)
  80. //log.Println("time seconds", time.Since(now).Seconds())
  81. //log.Println("lens", len(res))
  82. //if len(res) > 0 {
  83. // resa := res["result"]
  84. // log.Println("resa", resa)
  85. // if dataa, ok := resa.([]interface{}); ok {
  86. // log.Println(222)
  87. // da := dataa[0]
  88. // if len(util.ObjToString(da)) > 0 {
  89. // cs := strings.Split(util.ObjToString(da), "-")
  90. // log.Println("toptype", cs[0])
  91. // log.Println("subtype", cs[1])
  92. // }
  93. // }
  94. //}
  95. // ==============================================
  96. }
  97. func dealNavColumn() {
  98. columns := make([]map[string]interface{}, 0)
  99. column := []string{"招标公告", "招标预告", "招标结果", "招标信用", "采购意向", "项目分包", "企业直采",
  100. "政府采购", "拟在建项目", "审批项目", "推荐项目", "业主委托项目", "热门项目", "新兴项目",
  101. "国家级项目", "省级项目"}
  102. for k, v := range column {
  103. column := map[string]interface{}{
  104. "name": v,
  105. "sort": k + 1,
  106. }
  107. columns = append(columns, column)
  108. }
  109. now := time.Now()
  110. where := map[string]interface{}{
  111. "comeintime": map[string]interface{}{
  112. "$gte": now.AddDate(-1, 0, 0).Unix(),
  113. },
  114. }
  115. sess := MgoB.GetMgoConn()
  116. defer MgoB.DestoryMongoConn(sess)
  117. //
  118. query := sess.DB("qfw").C("bidding").Find(&where).Select(map[string]interface{}{
  119. "contenthtml": 0}).Iter()
  120. count := 0
  121. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  122. if count%1000 == 0 {
  123. log.Println("current", count)
  124. }
  125. //针对产权数据,暂时不入es 索引库
  126. if util.IntAll(tmp["infoformat"]) == 3 {
  127. continue
  128. }
  129. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  130. tmp = make(map[string]interface{})
  131. continue
  132. }
  133. if util.IntAll(tmp["extracttype"]) != 1 {
  134. continue
  135. }
  136. title := util.ObjToString(tmp["title"])
  137. if !strings.Contains(title, "省级财政资金") {
  138. continue
  139. } else {
  140. rea := TagBidding(tmp)
  141. reb := calculateFlag(rea, columns) //拿到十进制数字,标签栏目结果
  142. insert := map[string]interface{}{
  143. "bidding_id": mongodb.BsonIdToSId(tmp["_id"]),
  144. }
  145. MgoB.Save("wcc_bidding_id", insert)
  146. log.Println("bidding_id", mongodb.BsonIdToSId(tmp["_id"]))
  147. updatePool <- []map[string]interface{}{
  148. {"_id": tmp["_id"]},
  149. {"$set": bson.M{
  150. "nav_column": reb,
  151. }},
  152. }
  153. }
  154. }
  155. }
  156. // updateMethod 更新MongoDB
  157. func updateMethod() {
  158. updateSp := make(chan bool, 2)
  159. arru := make([][]map[string]interface{}, 200)
  160. indexu := 0
  161. for {
  162. select {
  163. case v := <-updatePool:
  164. arru[indexu] = v
  165. indexu++
  166. if indexu == 200 {
  167. updateSp <- true
  168. go func(arru [][]map[string]interface{}) {
  169. defer func() {
  170. <-updateSp
  171. }()
  172. MgoB.UpdateBulk("bidding", arru...)
  173. }(arru)
  174. arru = make([][]map[string]interface{}, 200)
  175. indexu = 0
  176. }
  177. case <-time.After(1000 * time.Millisecond):
  178. if indexu > 0 {
  179. updateSp <- true
  180. go func(arru [][]map[string]interface{}) {
  181. defer func() {
  182. <-updateSp
  183. }()
  184. MgoB.UpdateBulk("bidding", arru...)
  185. }(arru[:indexu])
  186. arru = make([][]map[string]interface{}, 200)
  187. indexu = 0
  188. }
  189. }
  190. }
  191. }
  192. func hots() {
  193. exists := make(map[string]bool)
  194. res, _ := MgoB.Find("bidding_hots", nil, map[string]interface{}{"createtime": -1}, nil, false, -1, -1)
  195. for _, v := range *res {
  196. biddingID := util.ObjToString(v["bidding_id"])
  197. if !exists[biddingID] {
  198. exists[biddingID] = true
  199. }
  200. }
  201. data := make([]map[string]interface{}, 0)
  202. for _, v := range *res {
  203. biddingID := util.ObjToString(v["bidding_id"])
  204. if exists[biddingID] {
  205. data = append(data, v)
  206. exists[biddingID] = false
  207. }
  208. }
  209. MgoB.SaveBulk("wcc_hots", data...)
  210. }