main.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. package main
  2. import (
  3. "go.mongodb.org/mongo-driver/bson"
  4. "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  5. es "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  7. "log"
  8. "strings"
  9. "time"
  10. )
  11. var (
  12. MgoB *mongodb.MongodbSim
  13. MgoQy *mongodb.MongodbSim
  14. MgoP *mongodb.MongodbSim
  15. Es *es.Elastic
  16. updatePool = make(chan []map[string]interface{}, 5000)
  17. updateEsPool = make(chan []map[string]interface{}, 5000)
  18. updateEsSp = make(chan bool, 5) //保存协程
  19. )
  20. func InitMgo() {
  21. //MgoB = &mongodb.MongodbSim{
  22. // MongodbAddr: "172.31.31.202:27081,172.20.45.128:27080",
  23. // //MongodbAddr: "127.0.0.1:27083",
  24. // Size: 10,
  25. // DbName: "qfw",
  26. // UserName: "SJZY_RWbid_ES",
  27. // Password: "SJZY@B4i4D5e6S",
  28. // //Direct: true,
  29. //}
  30. //MgoB.InitPool()
  31. MgoQy = &mongodb.MongodbSim{
  32. //MongodbAddr: "172.31.31.202:27081,172.20.45.128:27080",
  33. MongodbAddr: "127.0.0.1:27083",
  34. Size: 10,
  35. DbName: "mixdata",
  36. UserName: "SJZY_RWbid_ES",
  37. Password: "SJZY@B4i4D5e6S",
  38. Direct: true,
  39. }
  40. MgoQy.InitPool()
  41. MgoP = &mongodb.MongodbSim{
  42. //MongodbAddr: "127.0.0.1:27080",
  43. MongodbAddr: "172.17.4.85:27080",
  44. DbName: "qfw",
  45. Size: 10,
  46. //Direct: true,
  47. }
  48. MgoP.InitPool()
  49. // 本地数据库
  50. //MgoB = &mongodb.MongodbSim{
  51. // //MongodbAddr: "172.17.189.140:27080",
  52. // MongodbAddr: "127.0.0.1:27017",
  53. // Size: 10,
  54. // DbName: "wcc",
  55. // //UserName: "SJZY_RWbid_ES",
  56. // //Password: "SJZY@B4i4D5e6S",
  57. // //Direct: true,
  58. //}
  59. //MgoB.InitPool()
  60. // 测试环境
  61. //MgoB = &mongodb.MongodbSim{
  62. // MongodbAddr: "192.168.3.206:27002",
  63. // //MongodbAddr: "127.0.0.1:27017",
  64. // Size: 10,
  65. // DbName: "qfw_data",
  66. // UserName: "root",
  67. // Password: "root",
  68. // //Direct: true,
  69. //}
  70. //MgoB.InitPool()
  71. }
  72. func InitEs() {
  73. Es = &es.Elastic{
  74. S_esurl: "http://127.0.0.1:19908",
  75. //S_esurl: "http://172.17.4.184:19908",
  76. I_size: 5,
  77. Username: "jybid",
  78. Password: "Top2023_JEB01i@31",
  79. }
  80. Es.InitElasticSize()
  81. }
  82. func main() {
  83. InitMgo()
  84. InitEs()
  85. go updateEsMethod()
  86. fixQyxy()
  87. select {}
  88. //getBidding0311()
  89. //log.Println("数据删除完成")
  90. //------------------//
  91. //InitMgo()
  92. //getBidding2()
  93. //callAi()
  94. //getCount()
  95. //updateTop()
  96. //findData()
  97. //getCompanyName()
  98. //log.Println("over")
  99. //select {}
  100. //SpecialData()
  101. //StdData()
  102. // ==============================================
  103. ////1.调用分类大模型
  104. //title := "松江南站大型居住社区C18-26-01号地块动迁安置房(智能化工程)"
  105. //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>"
  106. //
  107. //data := map[string]interface{}{
  108. // "title": title,
  109. // "detail": detail,
  110. //}
  111. //reqData := map[string]interface{}{
  112. // "texts": []interface{}{data},
  113. //}
  114. //
  115. //url := "http://172.17.162.35:24401"
  116. //now := time.Now()
  117. //res := sendAi(reqData, url)
  118. ////log.Println("res", res)
  119. //log.Println("time seconds", time.Since(now).Seconds())
  120. //log.Println("lens", len(res))
  121. //if len(res) > 0 {
  122. // resa := res["result"]
  123. // log.Println("resa", resa)
  124. // if dataa, ok := resa.([]interface{}); ok {
  125. // log.Println(222)
  126. // da := dataa[0]
  127. // if len(util.ObjToString(da)) > 0 {
  128. // cs := strings.Split(util.ObjToString(da), "-")
  129. // log.Println("toptype", cs[0])
  130. // log.Println("subtype", cs[1])
  131. // }
  132. // }
  133. //}
  134. // ==============================================
  135. }
  136. func dealNavColumn() {
  137. columns := make([]map[string]interface{}, 0)
  138. column := []string{"招标公告", "招标预告", "招标结果", "招标信用", "采购意向", "项目分包", "企业直采",
  139. "政府采购", "拟在建项目", "审批项目", "推荐项目", "业主委托项目", "热门项目", "新兴项目",
  140. "国家级项目", "省级项目"}
  141. for k, v := range column {
  142. column := map[string]interface{}{
  143. "name": v,
  144. "sort": k + 1,
  145. }
  146. columns = append(columns, column)
  147. }
  148. now := time.Now()
  149. where := map[string]interface{}{
  150. "comeintime": map[string]interface{}{
  151. "$gte": now.AddDate(-1, 0, 0).Unix(),
  152. },
  153. }
  154. sess := MgoB.GetMgoConn()
  155. defer MgoB.DestoryMongoConn(sess)
  156. //
  157. query := sess.DB("qfw").C("bidding").Find(&where).Select(map[string]interface{}{
  158. "contenthtml": 0}).Iter()
  159. count := 0
  160. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  161. if count%1000 == 0 {
  162. log.Println("current", count)
  163. }
  164. //针对产权数据,暂时不入es 索引库
  165. if util.IntAll(tmp["infoformat"]) == 3 {
  166. continue
  167. }
  168. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  169. tmp = make(map[string]interface{})
  170. continue
  171. }
  172. if util.IntAll(tmp["extracttype"]) != 1 {
  173. continue
  174. }
  175. title := util.ObjToString(tmp["title"])
  176. if !strings.Contains(title, "省级财政资金") {
  177. continue
  178. } else {
  179. rea := TagBidding(tmp)
  180. reb := calculateFlag(rea, columns) //拿到十进制数字,标签栏目结果
  181. insert := map[string]interface{}{
  182. "bidding_id": mongodb.BsonIdToSId(tmp["_id"]),
  183. }
  184. MgoB.Save("wcc_bidding_id", insert)
  185. log.Println("bidding_id", mongodb.BsonIdToSId(tmp["_id"]))
  186. updatePool <- []map[string]interface{}{
  187. {"_id": tmp["_id"]},
  188. {"$set": bson.M{
  189. "nav_column": reb,
  190. }},
  191. }
  192. }
  193. }
  194. }
  195. // updateMethod 更新MongoDB
  196. func updateMethod() {
  197. updateSp := make(chan bool, 2)
  198. arru := make([][]map[string]interface{}, 200)
  199. indexu := 0
  200. for {
  201. select {
  202. case v := <-updatePool:
  203. arru[indexu] = v
  204. indexu++
  205. if indexu == 200 {
  206. updateSp <- true
  207. go func(arru [][]map[string]interface{}) {
  208. defer func() {
  209. <-updateSp
  210. }()
  211. MgoB.UpdateBulk("bidding", arru...)
  212. }(arru)
  213. arru = make([][]map[string]interface{}, 200)
  214. indexu = 0
  215. }
  216. case <-time.After(1000 * time.Millisecond):
  217. if indexu > 0 {
  218. updateSp <- true
  219. go func(arru [][]map[string]interface{}) {
  220. defer func() {
  221. <-updateSp
  222. }()
  223. MgoB.UpdateBulk("bidding", arru...)
  224. }(arru[:indexu])
  225. arru = make([][]map[string]interface{}, 200)
  226. indexu = 0
  227. }
  228. }
  229. }
  230. }
  231. func hots() {
  232. exists := make(map[string]bool)
  233. res, _ := MgoB.Find("bidding_hots", nil, map[string]interface{}{"createtime": -1}, nil, false, -1, -1)
  234. for _, v := range *res {
  235. biddingID := util.ObjToString(v["bidding_id"])
  236. if !exists[biddingID] {
  237. exists[biddingID] = true
  238. }
  239. }
  240. data := make([]map[string]interface{}, 0)
  241. for _, v := range *res {
  242. biddingID := util.ObjToString(v["bidding_id"])
  243. if exists[biddingID] {
  244. data = append(data, v)
  245. exists[biddingID] = false
  246. }
  247. }
  248. MgoB.SaveBulk("wcc_hots", data...)
  249. }
  250. // updateEsMethod 更新es
  251. func updateEsMethod() {
  252. arru := make([][]map[string]interface{}, 200)
  253. indexu := 0
  254. for {
  255. select {
  256. case v := <-updateEsPool:
  257. arru[indexu] = v
  258. indexu++
  259. if indexu == 200 {
  260. updateEsSp <- true
  261. go func(arru [][]map[string]interface{}) {
  262. defer func() {
  263. <-updateEsSp
  264. }()
  265. Es.UpdateBulk("projectset", arru...)
  266. }(arru)
  267. arru = make([][]map[string]interface{}, 200)
  268. indexu = 0
  269. }
  270. case <-time.After(1000 * time.Millisecond):
  271. if indexu > 0 {
  272. updateEsSp <- true
  273. go func(arru [][]map[string]interface{}) {
  274. defer func() {
  275. <-updateEsSp
  276. }()
  277. Es.UpdateBulk("projectset", arru...)
  278. }(arru[:indexu])
  279. arru = make([][]map[string]interface{}, 200)
  280. indexu = 0
  281. }
  282. }
  283. }
  284. }