task.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/v2/util/gconv"
  6. "go.mongodb.org/mongo-driver/bson"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  8. "strings"
  9. "sync"
  10. "time"
  11. )
  12. type Transaction struct {
  13. Project_Id string `bson:"project_id"`
  14. Project_Name string `bson:"project_name"`
  15. Project_Budget float64 `bson:"project_budget"`
  16. Project_Bidamount float64 `bson:"project_bidamount"`
  17. Project_Money float64 `bson:"project_money"`
  18. Business_Type string `bson:"business_type"`
  19. Project_Bidstatus int `bson:"project_bidstatus"`
  20. Info_Id string `bson:"info_id"`
  21. Information_Id string `bson:"information_id"`
  22. Buyer string `bson:"buyer"`
  23. Buyer_Id string `bson:"buyer_id"`
  24. Winner []string `bson:"winner"`
  25. Winner_Id []string `bson:"winner_id"`
  26. Agency string `bson:"agency"`
  27. Agency_Id string `bson:"agency_id"`
  28. Property_Form []string `bson:"property_form"`
  29. SubClass []string `bson:"subclass"`
  30. MultiPackage int `bson:"multipackage"`
  31. Area string `bson:"area"`
  32. City string `bson:"city"`
  33. District string `bson:"district"`
  34. ZbTime int64 `bson:"zbtime"`
  35. JgTime int64 `bson:"jgtime"`
  36. StartTime int64 `bson:"starttime"`
  37. EndTime int64 `bson:"endtime"`
  38. Create_Time int64 `bson:"create_time"`
  39. Update_Time int64 `bson:"update_time"`
  40. //
  41. From string `bson:"from"`
  42. }
  43. func IncTransactionDataFromBidAndPro() {
  44. IncTransactionDataFromBid() //bidding
  45. IncTransactionDataFromPro() //project
  46. return
  47. IncTransactionDataMgoToCkhAndEs() //mongodb迁移至clickhouse
  48. }
  49. // IncTransactionDataFromBid 增量bidding
  50. func IncTransactionDataFromBid() {
  51. endTime := GetTime(-1) //前一天凌晨
  52. fmt.Println("开始执行增量采购意向、拟建信息", BidStartTime, endTime)
  53. if BidStartTime >= endTime {
  54. fmt.Println("增量bidding采购意向、拟建查询异常:", BidStartTime, endTime)
  55. return
  56. }
  57. query := map[string]interface{}{
  58. "comeintime": map[string]interface{}{
  59. "$gte": BidStartTime,
  60. "$lt": endTime,
  61. },
  62. }
  63. fmt.Println("增量bidding采购意向query:", query)
  64. sess := MgoB.GetMgoConn()
  65. defer MgoB.DestoryMongoConn(sess)
  66. ch := make(chan bool, 5)
  67. wg := &sync.WaitGroup{}
  68. lock := &sync.Mutex{}
  69. fields := map[string]interface{}{
  70. "projectname": 1,
  71. "budget": 1,
  72. "bidamount": 1,
  73. "buyer": 1,
  74. "s_winner": 1,
  75. "agency": 1,
  76. "property_form": 1,
  77. "multipackage": 1,
  78. "area": 1,
  79. "city": 1,
  80. "district": 1,
  81. //
  82. "s_topscopeclass": 1,
  83. "publishtime": 1,
  84. "toptype": 1,
  85. "extracttype": 1,
  86. "tag_subinformation": 1,
  87. "tag_subinformation_ai": 1,
  88. "tag_topinformation": 1,
  89. "tag_topinformation_ai": 1,
  90. }
  91. arr := []map[string]interface{}{}
  92. it := sess.DB(MgoB.DbName).C("bidding").Find(&query).Select(&fields).Iter()
  93. n := 0
  94. count := 0
  95. for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
  96. ch <- true
  97. wg.Add(1)
  98. go func(tmp map[string]interface{}) {
  99. defer func() {
  100. <-ch
  101. wg.Done()
  102. }()
  103. if gconv.Int(tmp["extracttype"]) == -1 { //重复数据过滤
  104. return
  105. }
  106. toptype := gconv.String(tmp["toptype"])
  107. tag_topinformation := gconv.String(tmp["tag_topinformation"])
  108. tag_topinformation_ai := gconv.String(tmp["tag_topinformation_ai"])
  109. var business_type string
  110. var project_bidstatus int
  111. if toptype == "采购意向" { //采购意向数据
  112. if !strings.Contains(tag_topinformation, "物业") && !strings.Contains(tag_topinformation_ai, "物业") {
  113. return
  114. }
  115. business_type = "采购意向"
  116. project_bidstatus = 3
  117. } else if toptype == "拟建" {
  118. if strings.Contains(tag_topinformation, "物业") || strings.Contains(tag_topinformation_ai, "物业") {
  119. return
  120. }
  121. business_type = "新增项目"
  122. project_bidstatus = 4
  123. } else {
  124. return
  125. }
  126. result := DealTransactionForBid(tmp, business_type, project_bidstatus)
  127. lock.Lock()
  128. if len(result) > 0 {
  129. arr = append(arr, result)
  130. count++
  131. }
  132. if len(arr) > 50 {
  133. MgoPro.SaveBulk("projectset_wy", arr...)
  134. arr = []map[string]interface{}{}
  135. }
  136. lock.Unlock()
  137. }(tmp)
  138. if n%1000 == 0 {
  139. fmt.Println("current:", n)
  140. }
  141. tmp = map[string]interface{}{}
  142. }
  143. wg.Wait()
  144. if len(arr) > 0 {
  145. MgoPro.SaveBulk("projectset_wy", arr...)
  146. arr = []map[string]interface{}{}
  147. }
  148. fmt.Println("执行增量采购意向、拟建信息完毕", BidStartTime, endTime, count)
  149. BidStartTime = endTime //替换
  150. }
  151. // DealTransactionForBid bidding采购意向数据处理
  152. func DealTransactionForBid(tmp map[string]interface{}, business_type string, project_bidstatus int) map[string]interface{} {
  153. //基本信息封装
  154. id := mongodb.BsonIdToSId(tmp["_id"])
  155. buyer := gconv.String(tmp["buyer"])
  156. winner := gconv.String(tmp["s_winner"])
  157. agency := gconv.String(tmp["agency"])
  158. property_form := []string{}
  159. if tmp["property_form"] != nil {
  160. property_form = gconv.Strings(tmp["property_form"])
  161. }
  162. bidamount := gconv.Float64(tmp["bidamount"])
  163. budget := gconv.Float64(tmp["budget"])
  164. money := bidamount
  165. if money <= 0 {
  166. money = budget
  167. }
  168. //物业分类
  169. subclass := []string{}
  170. if tag_subinformation := tmp["tag_subinformation"]; tag_subinformation != nil {
  171. subclass = gconv.Strings(tag_subinformation)
  172. } else if tag_subinformation_ai := tmp["tag_subinformation_ai"]; tag_subinformation_ai != nil {
  173. subclass = gconv.Strings(tag_subinformation_ai)
  174. }
  175. //TODO 情报库信息(待补充)
  176. information_id := ""
  177. starttime, endtime := int64(0), int64(0)
  178. //if project_bidstatus == 4 {//补充情报信息
  179. // //bidId = "65fbf3f566cf0db42a2a99d2"
  180. // info := FindInfomationData(id) //情报信息查询
  181. // information_id = info.Id
  182. // starttime = info.Starttime
  183. // endtime = info.Endtime
  184. //}
  185. //TODO 查询法人库信息(待补充)
  186. winners := []string{}
  187. if winner != "" {
  188. winners = strings.Split(winner, ",")
  189. }
  190. buyer_id, agency_id := "", ""
  191. winner_ids := []string{}
  192. //buyer_id, agency_id, winner_ids := FindEntInfoData(id, buyer, agency, winners)
  193. //物业信息
  194. t := &Transaction{
  195. Project_Id: id,
  196. Project_Name: gconv.String(tmp["projectname"]),
  197. Project_Budget: budget,
  198. Project_Bidamount: bidamount,
  199. Project_Money: money,
  200. Business_Type: business_type,
  201. Project_Bidstatus: project_bidstatus,
  202. Info_Id: id,
  203. Information_Id: information_id,
  204. Buyer: buyer,
  205. Winner: winners,
  206. Agency: agency,
  207. Buyer_Id: buyer_id,
  208. Winner_Id: winner_ids,
  209. Agency_Id: agency_id,
  210. Property_Form: property_form,
  211. SubClass: subclass,
  212. MultiPackage: gconv.Int(tmp["multipackage"]),
  213. Area: gconv.String(tmp["area"]),
  214. City: gconv.String(tmp["city"]),
  215. District: gconv.String(tmp["district"]),
  216. ZbTime: gconv.Int64(tmp["publishtime"]),
  217. JgTime: int64(0),
  218. StartTime: starttime,
  219. EndTime: endtime,
  220. Create_Time: time.Now().Unix(),
  221. Update_Time: time.Now().Unix(),
  222. //
  223. From: "bidding",
  224. }
  225. result := map[string]interface{}{}
  226. infomation, _ := bson.Marshal(t)
  227. bson.Unmarshal(infomation, &result)
  228. return result
  229. }
  230. // IncTransactionDataFromProject 增量project
  231. func IncTransactionDataFromPro() {
  232. endTime := GetTime(-1) //前一天凌晨
  233. fmt.Println("开始执行增量项目信息", ProStartTime, endTime)
  234. if ProStartTime >= endTime {
  235. fmt.Println("增量项目信息查询异常:", ProStartTime, endTime)
  236. return
  237. }
  238. query := map[string]interface{}{
  239. "pici": map[string]interface{}{
  240. "$gte": ProStartTime,
  241. "$lt": endTime,
  242. },
  243. }
  244. fmt.Println("增量项目查询query:", query)
  245. sess := MgoPro.GetMgoConn()
  246. defer MgoPro.DestoryMongoConn(sess)
  247. ch := make(chan bool, 5)
  248. wg := &sync.WaitGroup{}
  249. lock := &sync.Mutex{}
  250. fields := map[string]interface{}{
  251. "projectname": 1,
  252. "budget": 1,
  253. "bidamount": 1,
  254. "buyer": 1,
  255. "s_winner": 1,
  256. "agency": 1,
  257. "property_form": 1,
  258. "multipackage": 1,
  259. "area": 1,
  260. "city": 1,
  261. "district": 1,
  262. "zbtime": 1,
  263. "jgtime": 1,
  264. "bidstatus": 1,
  265. //
  266. "firsttime": 1,
  267. "pici": 1,
  268. "ids": 1,
  269. "sourceinfoid": 1,
  270. "tag_subinformation": 1,
  271. "tag_subinformation_ai": 1,
  272. "tag_topinformation": 1,
  273. "tag_topinformation_ai": 1,
  274. }
  275. arr := [][]map[string]interface{}{}
  276. it := sess.DB(MgoPro.DbName).C("projectset_20230904").Find(&query).Select(&fields).Iter()
  277. n := 0
  278. count := 0
  279. for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
  280. ch <- true
  281. wg.Add(1)
  282. go func(tmp map[string]interface{}) {
  283. defer func() {
  284. <-ch
  285. wg.Done()
  286. }()
  287. if tmp["tag_topinformation"] == nil && tmp["tag_topinformation_ai"] == nil { //无效数据过滤
  288. return
  289. }
  290. result := DealTransactionForPro(tmp)
  291. lock.Lock()
  292. if len(result) > 0 {
  293. count++
  294. update := []map[string]interface{}{
  295. {"project_id": tmp["_id"]},
  296. {"$set": result},
  297. }
  298. arr = append(arr, update)
  299. }
  300. if len(arr) > 50 {
  301. MgoPro.UpSertBulk("projectset_wy_back", arr...)
  302. arr = [][]map[string]interface{}{}
  303. }
  304. lock.Unlock()
  305. }(tmp)
  306. if n%1000 == 0 {
  307. fmt.Println("current:", n)
  308. }
  309. tmp = map[string]interface{}{}
  310. }
  311. wg.Wait()
  312. if len(arr) > 0 {
  313. MgoPro.UpSertBulk("projectset_wy_back", arr...)
  314. arr = [][]map[string]interface{}{}
  315. }
  316. fmt.Println("执行增量项目信息完毕", ProStartTime, endTime, count)
  317. ProStartTime = endTime //替换
  318. }
  319. // DealTransactionForPro project数据处理
  320. func DealTransactionForPro(data map[string]interface{}) map[string]interface{} {
  321. //基本信息封装
  322. id := mongodb.BsonIdToSId(data["_id"])
  323. buyer := gconv.String(data["buyer"])
  324. winner := gconv.String(data["s_winner"])
  325. agency := gconv.String(data["agency"])
  326. zbtime := gconv.Int64(data["zbtime"])
  327. if zbtime == 0 {
  328. zbtime = gconv.Int64(data["firsttime"])
  329. }
  330. property_form := []string{}
  331. if data["property_form"] != nil {
  332. property_form = gconv.Strings(data["property_form"])
  333. }
  334. bidamount := gconv.Float64(data["bidamount"])
  335. budget := gconv.Float64(data["budget"])
  336. money := bidamount
  337. if money <= 0 {
  338. money = budget
  339. }
  340. //物业分类
  341. subclass := []string{}
  342. if tag_subinformation := data["tag_subinformation"]; tag_subinformation != nil {
  343. subclass = gconv.Strings(tag_subinformation)
  344. } else if tag_subinformation_ai := data["tag_subinformation_ai"]; tag_subinformation_ai != nil {
  345. subclass = gconv.Strings(tag_subinformation_ai)
  346. }
  347. //项目状态、商机类型
  348. business_type := ""
  349. project_bidstatus := 2
  350. bidstatus := gconv.String(data["bidstatus"])
  351. if bidstatus == "中标" || bidstatus == "成交" || bidstatus == "合同" {
  352. project_bidstatus = 1
  353. business_type = "存量项目"
  354. } else if bidstatus == "废标" || bidstatus == "流标" {
  355. project_bidstatus = 0
  356. } else if bidstatus == "招标" {
  357. business_type = "招标项目"
  358. }
  359. //查询情报信息
  360. //bidId = "65fbf3f566cf0db42a2a99d2"
  361. ids := gconv.Strings(data["ids"])
  362. info := FindInfomationData(ids...) //情报信息查询
  363. //TODO 查询法人库信息(待补充)
  364. winners := []string{}
  365. if winner != "" {
  366. winners = strings.Split(winner, ",")
  367. }
  368. buyer_id, agency_id := "", ""
  369. winner_ids := []string{}
  370. //buyer_id, agency_id, winner_ids = FindEntInfoData(id, buyer, agency, winners)
  371. //物业信息
  372. t := &Transaction{
  373. Project_Id: id,
  374. Project_Name: gconv.String(data["projectname"]),
  375. Project_Budget: budget,
  376. Project_Bidamount: bidamount,
  377. Project_Money: money,
  378. Business_Type: business_type,
  379. Project_Bidstatus: project_bidstatus,
  380. Info_Id: gconv.String(data["sourceinfoid"]),
  381. Information_Id: info.Id,
  382. Buyer: buyer,
  383. Winner: winners,
  384. Agency: agency,
  385. Buyer_Id: buyer_id,
  386. Winner_Id: winner_ids,
  387. Agency_Id: agency_id,
  388. Property_Form: property_form,
  389. SubClass: subclass,
  390. MultiPackage: gconv.Int(data["multipackage"]),
  391. Area: gconv.String(data["area"]),
  392. City: gconv.String(data["city"]),
  393. District: gconv.String(data["district"]),
  394. ZbTime: zbtime,
  395. JgTime: gconv.Int64(data["jgtime"]),
  396. StartTime: info.Starttime,
  397. EndTime: info.Endtime,
  398. Create_Time: time.Now().Unix(),
  399. Update_Time: time.Now().Unix(),
  400. //
  401. From: "project",
  402. }
  403. result := map[string]interface{}{}
  404. infomation, _ := bson.Marshal(t)
  405. bson.Unmarshal(infomation, &result)
  406. return result
  407. }
  408. // IncTransactionDataMgoToCkhAndEs 数据迁移
  409. func IncTransactionDataMgoToCkhAndEs() {
  410. /*
  411. 数据根据update_time查询
  412. 1、采购意向数据(from=bidding)只插入
  413. 2、项目信息先查,有则更新,无则插入
  414. */
  415. fmt.Println("开始执行迁移...")
  416. sess := MgoPro.GetMgoConn()
  417. defer MgoPro.DestoryMongoConn(sess)
  418. ch := make(chan bool, 2)
  419. wg := &sync.WaitGroup{}
  420. query := map[string]interface{}{
  421. "update_time": map[string]interface{}{
  422. "$gte": GetTime(0),
  423. },
  424. }
  425. it := sess.DB(MgoPro.DbName).C("projectset_wy").Find(&query).Iter()
  426. n := 0
  427. for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
  428. ch <- true
  429. wg.Add(1)
  430. go func(tmp map[string]interface{}) {
  431. defer func() {
  432. <-ch
  433. wg.Done()
  434. }()
  435. from := gconv.String(tmp["from"])
  436. delete(tmp, "from") //无用字段删除
  437. delete(tmp, "_id") //无用字段删除
  438. if !SaveDataToEs(tmp) { //保存、更新es
  439. fmt.Println("数据保存es失败,项目project_id", tmp["project_id"])
  440. }
  441. if from == "bidding" { //采购意向、拟建,插入
  442. SaveDataToClickHouse(tmp)
  443. } else { //项目信息,更新,插入
  444. UpdateOrSaveDataToClickHouse(tmp)
  445. }
  446. }(tmp)
  447. if n%100 == 0 {
  448. fmt.Println("current:", n)
  449. }
  450. tmp = map[string]interface{}{}
  451. }
  452. wg.Wait()
  453. fmt.Println("迁移结束...")
  454. }
  455. type Infomation struct {
  456. Id string
  457. Starttime int64
  458. Endtime int64
  459. }
  460. // FindInfomationData 情报信息查询
  461. func FindInfomationData(ids ...string) (info Infomation) {
  462. for _, id := range ids {
  463. query := fmt.Sprintf(`SELECT id,starttime,endtime FROM %s WHERE datajson_id = ?`, Config.ClickHouse.DataBase+".information")
  464. rows, err := CkhTool.Query(context.Background(), query, id)
  465. if err != nil {
  466. continue
  467. }
  468. for rows.Next() {
  469. info = Infomation{}
  470. if err := rows.Scan(&info.Id, &info.Starttime, &info.Endtime); err != nil {
  471. fmt.Println("查询情报信息异常:", id, err)
  472. }
  473. if info.Id != "" {
  474. return
  475. }
  476. //break //目前只有一条结果
  477. }
  478. }
  479. return
  480. }
  481. // FindEntInfoData 法人信息查询
  482. func FindEntInfoData(bid, buyer, agency string, winners []string) (buyer_id, agency_id string, winner_ids []string) {
  483. winner_ids = []string{}
  484. winnerMap := map[string]bool{} //记录所有中标单位
  485. values := []interface{}{}
  486. placeholders := []string{}
  487. if buyer != "" {
  488. placeholders = append(placeholders, "?")
  489. values = append(values, buyer)
  490. }
  491. if len(winners) > 0 {
  492. for _, w := range winners {
  493. winnerMap[w] = true
  494. placeholders = append(placeholders, "?")
  495. values = append(values, w)
  496. }
  497. }
  498. if agency != "" {
  499. placeholders = append(placeholders, "?")
  500. values = append(values, agency)
  501. }
  502. if len(values) == 0 {
  503. return
  504. }
  505. query := fmt.Sprintf(`SELECT id,company_name FROM %s WHERE company_name IN (%s)`, Config.ClickHouse.DataBase+".ent_info", strings.Join(placeholders, ","))
  506. rows, err := CkhTool.Query(context.Background(), query, values...)
  507. if err != nil {
  508. return
  509. }
  510. for rows.Next() {
  511. var id, company_name string
  512. if err := rows.Scan(&id, &company_name); err == nil {
  513. if company_name == buyer {
  514. buyer_id = id
  515. } else if company_name == agency {
  516. agency_id = id
  517. } else if winnerMap[company_name] {
  518. winner_ids = append(winner_ids, id)
  519. }
  520. } else {
  521. fmt.Println("查询情报信息异常:", err, bid)
  522. }
  523. }
  524. return
  525. }
  526. // UpdateOrSaveDataToClickHouse 判断clickhouse更新or保存
  527. func UpdateOrSaveDataToClickHouse(data map[string]interface{}) (err error) {
  528. project_id := gconv.String(data["project_id"])
  529. count := FindClickHouseByProjectId(project_id) //查询
  530. if count > 0 { //更新
  531. delete(data, "create_time") //不更新创建时间
  532. delete(data, "project_id") //不更新项目id(主键)
  533. err = UpdateDataToClickHouse(data, map[string]interface{}{"project_id": project_id})
  534. if err != nil {
  535. fmt.Println("clickhouse更新失败", project_id, data)
  536. }
  537. } else { //插入
  538. err = SaveDataToClickHouse(data)
  539. if err != nil {
  540. fmt.Println("clickhouse保存失败", project_id, data)
  541. }
  542. }
  543. return
  544. }
  545. // SaveDataToClickHouse 数据保存clickhouse
  546. func SaveDataToClickHouse(data map[string]interface{}) error {
  547. fields, placeholders := []string{}, []string{}
  548. values := []interface{}{}
  549. for k, v := range data {
  550. fields = append(fields, k)
  551. values = append(values, v)
  552. placeholders = append(placeholders, "?")
  553. }
  554. query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", Config.ClickHouse.DataBase+".transaction_info", strings.Join(fields, ","), strings.Join(placeholders, ","))
  555. return CkhTool.Exec(context.Background(), query, values...)
  556. }
  557. // FindClickHouseByProjectId 根据条件count clickhouse
  558. func FindClickHouseByProjectId(project_id string) int {
  559. query := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE project_id = ?`, Config.ClickHouse.DataBase+".transaction_info")
  560. row := CkhTool.QueryRow(context.Background(), query, project_id)
  561. var count uint64
  562. row.Scan(&count)
  563. return gconv.Int(count)
  564. }
  565. // UpdateDataToClickHouse 数据更新clickhouse
  566. func UpdateDataToClickHouse(data, querys map[string]interface{}) error {
  567. sets := []string{}
  568. values := []interface{}{}
  569. for k, v := range data {
  570. sets = append(sets, fmt.Sprintf("%s=?", k))
  571. values = append(values, v)
  572. }
  573. qs := []string{}
  574. for k, v := range querys {
  575. qs = append(qs, fmt.Sprintf("%s=?", k))
  576. values = append(values, v)
  577. }
  578. query := fmt.Sprintf("ALTER TABLE %s UPDATE %s WHERE %s", Config.ClickHouse.DataBase+".transaction_info", strings.Join(sets, ","), strings.Join(qs, ","))
  579. //query := `ALTER TABLE information.transaction_info UPDATE update_time = ? WHERE project_id = '5c9ee78ca5cb26b9b7fd0b57'`
  580. return CkhTool.Exec(context.Background(), query, values...)
  581. }
  582. // SaveDataToEs es存储
  583. func SaveDataToEs(data map[string]interface{}) bool {
  584. tmp := map[string]interface{}{}
  585. for k, v := range data {
  586. if k == "project_id" {
  587. k = "_id"
  588. }
  589. tmp[k] = v
  590. }
  591. err, result := Es.GetById(Config.Es.Index, gconv.String(tmp["_id"]))
  592. if err == nil && len(result) > 0 { //存在,更新
  593. tmp["create_time"] = result["create_time"] //不更新create_time
  594. }
  595. return Es.Save(Config.Es.Index, tmp)
  596. }
  597. func FindEntInfoData2(bid, buyer, agency string, winners []string) (buyer_id, agency_id string, winner_ids []string) {
  598. query := fmt.Sprintf(`SELECT id FROM %s WHERE company_name = ?`, Config.ClickHouse.DataBase+".ent_info")
  599. if buyer != "" {
  600. buyer_id = GetClickHouseData(bid, query, buyer)
  601. }
  602. if agency != "" {
  603. agency_id = GetClickHouseData(bid, query, agency)
  604. }
  605. if len(winners) > 0 {
  606. for _, w := range winners {
  607. winner_id := GetClickHouseData(bid, query, w)
  608. if winner_id != "" {
  609. winner_ids = append(winner_ids, winner_id)
  610. }
  611. }
  612. }
  613. return
  614. }
  615. func GetClickHouseData(bid, query, value string) string {
  616. rows, err := CkhTool.Query(context.Background(), query, value)
  617. if err != nil {
  618. return ""
  619. }
  620. for rows.Next() {
  621. var id string
  622. if err := rows.Scan(&id); err == nil {
  623. return id
  624. } else {
  625. fmt.Println("查询情报信息异常:", err, bid)
  626. }
  627. }
  628. return ""
  629. }
  630. /*// SaveTransactionData 保存增量物业信息
  631. func SaveTransactionData() {
  632. fmt.Println("save projectset_wy...")
  633. savearr := make([]map[string]interface{}, 100)
  634. indexdb := 0
  635. for {
  636. select {
  637. case v := <-TransactionSaveCache:
  638. savearr[indexdb] = v
  639. indexdb++
  640. if indexdb == 100 {
  641. Transaction_Ch <- true
  642. go func(tmp []map[string]interface{}) {
  643. defer func() {
  644. <-Transaction_Ch
  645. }()
  646. MgoPro.SaveBulk("projectset_wy", tmp...)
  647. }(savearr)
  648. savearr = make([]map[string]interface{}, 100)
  649. indexdb = 0
  650. }
  651. case <-time.After(30 * time.Second):
  652. if indexdb > 0 {
  653. Transaction_Ch <- true
  654. go func(tmp []map[string]interface{}) {
  655. defer func() {
  656. <-Transaction_Ch
  657. }()
  658. MgoPro.SaveBulk("projectset_wy", tmp...)
  659. }(savearr[:indexdb])
  660. savearr = make([]map[string]interface{}, 100)
  661. indexdb = 0
  662. }
  663. }
  664. }
  665. }*/