main.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. package main
  2. import (
  3. "data_tidb/config"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/spf13/cobra"
  7. "go.mongodb.org/mongo-driver/bson"
  8. "go.uber.org/zap"
  9. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  10. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  11. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  12. "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
  13. "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
  14. "net"
  15. "sync"
  16. "time"
  17. )
  18. var (
  19. UdpClient udp.UdpClient
  20. )
  21. func init() {
  22. config.Init("./common.toml")
  23. InitLog()
  24. InitMgo()
  25. InitMysql()
  26. InitField()
  27. //redis.InitRedis1("qyxy_id=127.0.0.1:8379", 1)
  28. //redis.InitRedis1("qyxy_id=192.168.3.166:4379", 1)
  29. log.Info("init success")
  30. //启动 nohup ./MTB bidding &
  31. }
  32. func main() {
  33. taskB()
  34. //go SaveFunc()
  35. //go SaveTagFunc()
  36. //go SaveExpandFunc()
  37. //go SaveAttrFunc()
  38. //go SaveImfFunc()
  39. //go SaveIntentFunc()
  40. //go SaveWinnerFunc()
  41. //go SavePackageFunc()
  42. //go SavePurFunc()
  43. //go saveErrMethod()
  44. //rootCmd := &cobra.Command{Use: "my cmd"}
  45. //rootCmd.AddCommand(bidding())
  46. //rootCmd.AddCommand(project())
  47. //rootCmd.AddCommand(projectAdd())
  48. //if err := rootCmd.Execute(); err != nil {
  49. // fmt.Println("rootCmd.Execute failed", err.Error())
  50. //}
  51. //go SaveRelationFunc()
  52. //taskMysql()
  53. //UdpClient = udp.UdpClient{Local: config.Conf.Udp.LocPort, BufSize: 1024}
  54. //UdpClient.Listen(processUdpMsg)
  55. //log.Info("Udp服务监听", zap.String("port:", config.Conf.Udp.LocPort))
  56. c := make(chan bool, 1)
  57. <-c
  58. }
  59. func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
  60. defer util.Catch()
  61. switch act {
  62. case udp.OP_TYPE_DATA: //上个节点的数据
  63. var mapInfo map[string]interface{}
  64. err := json.Unmarshal(data, &mapInfo)
  65. log.Info("processUdpMsg", zap.Any("mapInfo:", mapInfo))
  66. gtid, _ := mapInfo["gtid"].(string)
  67. lteid, _ := mapInfo["lteid"].(string)
  68. if err != nil {
  69. UdpClient.WriteUdp([]byte("tidb udp error"), udp.OP_NOOP, ra) //udp失败回写
  70. } else {
  71. //udp成功回写
  72. if k := util.ObjToString(mapInfo["key"]); k != "" {
  73. UdpClient.WriteUdp([]byte(k), udp.OP_NOOP, ra)
  74. } else {
  75. k = fmt.Sprintf("%s-%s-%s", gtid, lteid, util.ObjToString(mapInfo["stype"]))
  76. UdpClient.WriteUdp([]byte(k), udp.OP_NOOP, ra)
  77. }
  78. log.Info("start sync ...")
  79. //doBiddingTask(gtid, lteid, mapInfo)
  80. }
  81. }
  82. }
  83. func taskMysql() {
  84. pool := make(chan bool, 5) //控制线程数
  85. wg := &sync.WaitGroup{}
  86. finalId := 0
  87. lastInfo := MysqlTool.SelectBySql(fmt.Sprintf("SELECT * FROM %s ORDER BY id DESC LIMIT 1", "dws_f_bpmc_relation"))
  88. //lastInfo := MysqlTool.SelectBySql(fmt.Sprintf("SELECT id, projectid, infoid, name_id, identity_type+0 FROM %s ORDER BY id DESC LIMIT 1", "dws_f_bpmc_relation_new"))
  89. if len(*lastInfo) > 0 {
  90. finalId = util.IntAll((*lastInfo)[0]["id"])
  91. }
  92. log.Info("查询最后id---", zap.Int("finally id: ", finalId))
  93. lastid, count := 0, 0
  94. for {
  95. log.Info("重新查询,lastid---", zap.Int("lastid: ", lastid))
  96. q := fmt.Sprintf("SELECT * FROM %s WHERE id > %d ORDER BY id ASC limit 100000", "dws_f_bpmc_relation", lastid)
  97. //q := fmt.Sprintf("SELECT id, projectid, infoid, name_id, identity_type+0 FROM %s WHERE id=61771536 ORDER BY id ASC limit 1000000", "dws_f_bpmc_relation")
  98. //q := fmt.Sprintf("SELECT id, name, name_id FROM %s WHERE id>%d ORDER BY id ASC limit 1000000", "dws_f_ent_baseinfo", lastid)
  99. rows, err := MysqlTool.DB.Query(q)
  100. if err != nil {
  101. log.Error("mysql query err ", zap.Error(err))
  102. }
  103. columns, err := rows.Columns()
  104. if finalId == lastid {
  105. log.Info("----finish-----", zap.Int("count: ", count))
  106. break
  107. }
  108. for rows.Next() {
  109. scanArgs := make([]interface{}, len(columns))
  110. values := make([]interface{}, len(columns))
  111. ret := make(map[string]interface{})
  112. for k := range values {
  113. scanArgs[k] = &values[k]
  114. }
  115. err = rows.Scan(scanArgs...)
  116. if err != nil {
  117. log.Error("mysql scan err ", zap.Error(err))
  118. break
  119. }
  120. for i, col := range values {
  121. if col == nil {
  122. ret[columns[i]] = nil
  123. } else {
  124. switch val := (*scanArgs[i].(*interface{})).(type) {
  125. case byte:
  126. ret[columns[i]] = val
  127. break
  128. case []byte:
  129. v := string(val)
  130. switch v {
  131. case "\x00": // 处理数据类型为bit的情况
  132. ret[columns[i]] = 0
  133. case "\x01": // 处理数据类型为bit的情况
  134. ret[columns[i]] = 1
  135. default:
  136. ret[columns[i]] = v
  137. break
  138. }
  139. break
  140. case time.Time:
  141. if val.IsZero() {
  142. ret[columns[i]] = nil
  143. } else {
  144. ret[columns[i]] = val.Format("2006-01-02 15:04:05")
  145. }
  146. break
  147. default:
  148. ret[columns[i]] = val
  149. }
  150. }
  151. }
  152. lastid = util.IntAll(ret["id"])
  153. count++
  154. if count%20000 == 0 {
  155. log.Info("current----", zap.Int("count: ", count), zap.Int("lastid: ", lastid))
  156. }
  157. pool <- true
  158. wg.Add(1)
  159. go func(tmp map[string]interface{}) {
  160. defer func() {
  161. <-pool
  162. wg.Done()
  163. }()
  164. //cid := util.Int64All(tmp["id"])
  165. //iid := util.ObjToString(tmp["infoid"])
  166. //name_id := util.ObjToString(tmp["name_id"])
  167. //identity_type := util.Int64All(tmp["identity_type+0"])
  168. //if name_id != "" {
  169. // coll := "bidding"
  170. // if iid > "5a862e7040d2d9bbe88e3b1f" {
  171. // coll = "bidding"
  172. // } else {
  173. // coll = "bidding_back"
  174. // }
  175. // info, _ := MongoB.FindById(coll, iid, bson.M{"agencytel": 1, "agencyperson": 1, "buyertel": 1, "buyerperson": 1, "winnertel": 1, "winnerperson": 1})
  176. // if len(*info) > 0 {
  177. // if identity_type == 1 {
  178. // if util.ObjToString((*info)["buyertel"]) != "" {
  179. // q := make(map[string]interface{})
  180. // q["name_id"] = name_id
  181. // q["identity_type"] = identity_type
  182. // q["contact_tel"] = util.ObjToString((*info)["buyertel"])
  183. // if util.ObjToString((*info)["buyerperson"]) != "" {
  184. // q["contact_name"] = util.ObjToString((*info)["buyerperson"])
  185. // }
  186. // cinfo := MysqlTool.FindOne("dws_f_ent_contact", q, "", "")
  187. // if cinfo != nil && len(*cinfo) > 0 {
  188. // MysqlTool.Update("dws_f_bpmc_relation_new", bson.M{"id": cid}, bson.M{"contact_id": (*cinfo)["id"]})
  189. // }
  190. // }
  191. // } else if identity_type == 2 {
  192. // if util.ObjToString((*info)["winnertel"]) != "" {
  193. // q := make(map[string]interface{})
  194. // q["name_id"] = name_id
  195. // q["identity_type"] = identity_type
  196. // q["contact_tel"] = util.ObjToString((*info)["winnertel"])
  197. // if util.ObjToString((*info)["winnerperson"]) != "" {
  198. // q["contact_name"] = util.ObjToString((*info)["winnerperson"])
  199. // }
  200. // cinfo := MysqlTool.FindOne("dws_f_ent_contact", q, "", "")
  201. // if cinfo != nil && len(*cinfo) > 0 {
  202. // MysqlTool.Update("dws_f_bpmc_relation_new", bson.M{"id": cid}, bson.M{"contact_id": (*cinfo)["id"]})
  203. // }
  204. // }
  205. // } else if identity_type == 4 {
  206. // if util.ObjToString((*info)["agencytel"]) != "" {
  207. // q := make(map[string]interface{})
  208. // q["name_id"] = name_id
  209. // q["identity_type"] = identity_type
  210. // q["contact_tel"] = util.ObjToString((*info)["agencytel"])
  211. // if util.ObjToString((*info)["agencyperson"]) != "" {
  212. // q["contact_name"] = util.ObjToString((*info)["agencyperson"])
  213. // }
  214. // cinfo := MysqlTool.FindOne("dws_f_ent_contact", q, "", "")
  215. // if cinfo != nil && len(*cinfo) > 0 {
  216. // MysqlTool.Update("dws_f_bpmc_relation_new", bson.M{"id": cid}, bson.M{"contact_id": (*cinfo)["id"]})
  217. // }
  218. // }
  219. // }
  220. // }
  221. //}
  222. //redis.PutCKV("qyxy_id", util.ObjToString(tmp["name"]), util.ObjToString(tmp["name_id"]))
  223. saveM := make(map[string]interface{})
  224. if util.ObjToString(tmp["name_id"]) != "" {
  225. saveM["name_id"] = util.ObjToString(tmp["name_id"])
  226. } else {
  227. return
  228. }
  229. if util.ObjToString(tmp["contact_id"]) != "" {
  230. saveM["contact_id"] = util.IntAll(tmp["contact_id"])
  231. } else {
  232. return
  233. }
  234. saveM["projectid"] = util.ObjToString(tmp["projectid"])
  235. saveM["infoid"] = util.ObjToString(tmp["infoid"])
  236. saveM["identity_type"] = tmp["identity_type"]
  237. saveRelationPool <- saveM
  238. }(ret)
  239. ret = make(map[string]interface{})
  240. }
  241. _ = rows.Close()
  242. wg.Wait()
  243. }
  244. }
  245. func taskMgo() {
  246. sess := MongoP.GetMgoConn()
  247. defer MongoP.DestoryMongoConn(sess)
  248. ch := make(chan bool, 3)
  249. wg := &sync.WaitGroup{}
  250. q := bson.M{"_id": bson.M{"$lte": mongodb.StringTOBsonId("63411488911e1eb3459fb87e")}}
  251. field := map[string]interface{}{"ids": 1}
  252. query := sess.DB("qfw").C("projectset_20220721").Find(q).Select(field).Iter()
  253. count := 0
  254. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  255. if count%20000 == 0 {
  256. util.Debug("current ---", count, tmp["_id"])
  257. }
  258. ch <- true
  259. wg.Add(1)
  260. go func(tmp map[string]interface{}) {
  261. defer func() {
  262. <-ch
  263. wg.Done()
  264. }()
  265. id := mongodb.BsonIdToSId(tmp["_id"])
  266. for _, i := range util.ObjArrToStringArr(tmp["ids"].([]interface{})) {
  267. redis.PutCKV("s_id", i, id)
  268. }
  269. }(tmp)
  270. tmp = make(map[string]interface{})
  271. }
  272. wg.Wait()
  273. util.Debug("over ---", count)
  274. }
  275. // @Description 标讯数据
  276. // @Author J 2022/9/20 17:52
  277. func bidding() *cobra.Command {
  278. cmdClient := &cobra.Command{
  279. Use: "bidding",
  280. Short: "Start processing bidding data",
  281. Run: func(cmd *cobra.Command, args []string) {
  282. go SaveFunc()
  283. //go SaveTagFunc()
  284. //go SaveExpandFunc()
  285. //go SaveAttrFunc()
  286. //go SaveImfFunc()
  287. //go SaveIntentFunc()
  288. //go SaveWinnerFunc()
  289. //go SavePackageFunc()
  290. //go SavePurFunc()
  291. //go saveErrMethod()
  292. taskB()
  293. },
  294. }
  295. //cmdClient.Flags().StringVarP(&cfg, "conf", "c", "", "server config [toml]")
  296. return cmdClient
  297. }
  298. // @Description 项目数据
  299. // @Author J 2022/9/20 17:52
  300. func project() *cobra.Command {
  301. cmdClient := &cobra.Command{
  302. Use: "project",
  303. Short: "Start processing project data",
  304. Run: func(cmd *cobra.Command, args []string) {
  305. //go SaveProFunc()
  306. //go SaveProTagFunc()
  307. //go SaveProbFunc()
  308. go SaveRelationFunc()
  309. taskP()
  310. },
  311. }
  312. //cmdClient.Flags().StringVarP(&cfg, "conf", "c", "", "server config [toml]")
  313. return cmdClient
  314. }
  315. // @Description 项目数据
  316. // @Author J 2022/9/20 17:52
  317. func projectAdd() *cobra.Command {
  318. var pici int64
  319. cmdClient := &cobra.Command{
  320. Use: "project",
  321. Short: "Start processing project data",
  322. Run: func(cmd *cobra.Command, args []string) {
  323. //go SaveProFunc()
  324. //go SaveProTagFunc()
  325. //go SaveProbFunc()
  326. go SaveRelationFunc()
  327. taskPAdd(pici)
  328. },
  329. }
  330. cmdClient.Flags().Int64VarP(&pici, "pici", "p", 0, "")
  331. return cmdClient
  332. }
  333. func SaveFunc() {
  334. arru := make([]map[string]interface{}, saveSize)
  335. indexu := 0
  336. for {
  337. select {
  338. case v := <-saveBasePool:
  339. arru[indexu] = v
  340. indexu++
  341. if indexu == saveSize {
  342. saveBaseSp <- true
  343. go func(arru []map[string]interface{}) {
  344. defer func() {
  345. <-saveBaseSp
  346. }()
  347. MysqlTool.InsertBulk("dwd_f_bid_baseinfo", BaseField, arru...)
  348. }(arru)
  349. arru = make([]map[string]interface{}, saveSize)
  350. indexu = 0
  351. }
  352. case <-time.After(1000 * time.Millisecond):
  353. if indexu > 0 {
  354. saveBaseSp <- true
  355. go func(arru []map[string]interface{}) {
  356. defer func() {
  357. <-saveBaseSp
  358. }()
  359. MysqlTool.InsertBulk("dwd_f_bid_baseinfo", BaseField, arru...)
  360. }(arru[:indexu])
  361. arru = make([]map[string]interface{}, saveSize)
  362. indexu = 0
  363. }
  364. }
  365. }
  366. }
  367. func SaveExpandFunc() {
  368. arru := make([]map[string]interface{}, saveSize)
  369. indexu := 0
  370. for {
  371. select {
  372. case v := <-saveExpandPool:
  373. arru[indexu] = v
  374. indexu++
  375. if indexu == saveSize {
  376. saveExpandSp <- true
  377. go func(arru []map[string]interface{}) {
  378. defer func() {
  379. <-saveExpandSp
  380. }()
  381. MysqlTool.InsertBulk("dwd_f_bid_expand_baseinfo", ExpandField, arru...)
  382. }(arru)
  383. arru = make([]map[string]interface{}, saveSize)
  384. indexu = 0
  385. }
  386. case <-time.After(1000 * time.Millisecond):
  387. if indexu > 0 {
  388. saveExpandSp <- true
  389. go func(arru []map[string]interface{}) {
  390. defer func() {
  391. <-saveExpandSp
  392. }()
  393. MysqlTool.InsertBulk("dwd_f_bid_expand_baseinfo", ExpandField, arru...)
  394. }(arru[:indexu])
  395. arru = make([]map[string]interface{}, saveSize)
  396. indexu = 0
  397. }
  398. }
  399. }
  400. }
  401. func SaveDetailFunc() {
  402. arru := make([]map[string]interface{}, saveSize)
  403. indexu := 0
  404. for {
  405. select {
  406. case v := <-saveExpandPool:
  407. arru[indexu] = v
  408. indexu++
  409. if indexu == saveSize {
  410. saveExpandSp <- true
  411. go func(arru []map[string]interface{}) {
  412. defer func() {
  413. <-saveExpandSp
  414. }()
  415. MysqlTool.InsertBulk("dwd_f_bid_detail", ExpandField, arru...)
  416. }(arru)
  417. arru = make([]map[string]interface{}, saveSize)
  418. indexu = 0
  419. }
  420. case <-time.After(1000 * time.Millisecond):
  421. if indexu > 0 {
  422. saveExpandSp <- true
  423. go func(arru []map[string]interface{}) {
  424. defer func() {
  425. <-saveExpandSp
  426. }()
  427. MysqlTool.InsertBulk("dwd_f_bid_detail", ExpandField, arru...)
  428. }(arru[:indexu])
  429. arru = make([]map[string]interface{}, saveSize)
  430. indexu = 0
  431. }
  432. }
  433. }
  434. }
  435. func SaveTagFunc() {
  436. arru := make([]map[string]interface{}, saveSize)
  437. indexu := 0
  438. for {
  439. select {
  440. case v := <-saveTagPool:
  441. arru[indexu] = v
  442. indexu++
  443. if indexu == saveSize {
  444. saveTagSp <- true
  445. go func(arru []map[string]interface{}) {
  446. defer func() {
  447. <-saveTagSp
  448. }()
  449. MysqlTool.InsertBulk("dws_f_bid_tags", TagsField, arru...)
  450. }(arru)
  451. arru = make([]map[string]interface{}, saveSize)
  452. indexu = 0
  453. }
  454. case <-time.After(1000 * time.Millisecond):
  455. if indexu > 0 {
  456. saveTagSp <- true
  457. go func(arru []map[string]interface{}) {
  458. defer func() {
  459. <-saveTagSp
  460. }()
  461. MysqlTool.InsertBulk("dws_f_bid_tags", TagsField, arru...)
  462. }(arru[:indexu])
  463. arru = make([]map[string]interface{}, saveSize)
  464. indexu = 0
  465. }
  466. }
  467. }
  468. }
  469. func SaveAttrFunc() {
  470. arru := make([]map[string]interface{}, saveSize)
  471. indexu := 0
  472. for {
  473. select {
  474. case v := <-saveAttrPool:
  475. arru[indexu] = v
  476. indexu++
  477. if indexu == saveSize {
  478. saveAttrSp <- true
  479. go func(arru []map[string]interface{}) {
  480. defer func() {
  481. <-saveAttrSp
  482. }()
  483. MysqlTool.InsertBulk("dws_f_bid_filetext_baseinfo", AttrField, arru...)
  484. }(arru)
  485. arru = make([]map[string]interface{}, saveSize)
  486. indexu = 0
  487. }
  488. case <-time.After(1000 * time.Millisecond):
  489. if indexu > 0 {
  490. saveAttrSp <- true
  491. go func(arru []map[string]interface{}) {
  492. defer func() {
  493. <-saveAttrSp
  494. }()
  495. MysqlTool.InsertBulk("dws_f_bid_filetext_baseinfo", AttrField, arru...)
  496. }(arru[:indexu])
  497. arru = make([]map[string]interface{}, saveSize)
  498. indexu = 0
  499. }
  500. }
  501. }
  502. }
  503. func SaveImfFunc() {
  504. arru := make([]map[string]interface{}, saveSize)
  505. indexu := 0
  506. for {
  507. select {
  508. case v := <-saveIfmPool:
  509. arru[indexu] = v
  510. indexu++
  511. if indexu == saveSize {
  512. saveIfmSp <- true
  513. go func(arru []map[string]interface{}) {
  514. defer func() {
  515. <-saveIfmSp
  516. }()
  517. MysqlTool.InsertBulk("dws_f_bid_infoformat_baseinfo", IfmField, arru...)
  518. }(arru)
  519. arru = make([]map[string]interface{}, saveSize)
  520. indexu = 0
  521. }
  522. case <-time.After(1000 * time.Millisecond):
  523. if indexu > 0 {
  524. saveIfmSp <- true
  525. go func(arru []map[string]interface{}) {
  526. defer func() {
  527. <-saveIfmSp
  528. }()
  529. MysqlTool.InsertBulk("dws_f_bid_infoformat_baseinfo", IfmField, arru...)
  530. }(arru[:indexu])
  531. arru = make([]map[string]interface{}, saveSize)
  532. indexu = 0
  533. }
  534. }
  535. }
  536. }
  537. func SavePurFunc() {
  538. arru := make([]map[string]interface{}, saveSize)
  539. indexu := 0
  540. for {
  541. select {
  542. case v := <-savePurPool:
  543. arru[indexu] = v
  544. indexu++
  545. if indexu == saveSize {
  546. savePurSp <- true
  547. go func(arru []map[string]interface{}) {
  548. defer func() {
  549. <-savePurSp
  550. }()
  551. MysqlTool.InsertBulk("dws_f_bid_purchasing_baseinfo", PurField, arru...)
  552. }(arru)
  553. arru = make([]map[string]interface{}, saveSize)
  554. indexu = 0
  555. }
  556. case <-time.After(1000 * time.Millisecond):
  557. if indexu > 0 {
  558. savePurSp <- true
  559. go func(arru []map[string]interface{}) {
  560. defer func() {
  561. <-savePurSp
  562. }()
  563. MysqlTool.InsertBulk("dws_f_bid_purchasing_baseinfo", PurField, arru...)
  564. }(arru[:indexu])
  565. arru = make([]map[string]interface{}, saveSize)
  566. indexu = 0
  567. }
  568. }
  569. }
  570. }
  571. func SaveIntentFunc() {
  572. arru := make([]map[string]interface{}, saveSize)
  573. indexu := 0
  574. for {
  575. select {
  576. case v := <-saveIntentPool:
  577. arru[indexu] = v
  578. indexu++
  579. if indexu == saveSize {
  580. saveIntentSp <- true
  581. go func(arru []map[string]interface{}) {
  582. defer func() {
  583. <-saveIntentSp
  584. }()
  585. MysqlTool.InsertBulk("dws_f_bid_intention_baseinfo", IntentField, arru...)
  586. }(arru)
  587. arru = make([]map[string]interface{}, saveSize)
  588. indexu = 0
  589. }
  590. case <-time.After(1000 * time.Millisecond):
  591. if indexu > 0 {
  592. saveIntentSp <- true
  593. go func(arru []map[string]interface{}) {
  594. defer func() {
  595. <-saveIntentSp
  596. }()
  597. MysqlTool.InsertBulk("dws_f_bid_intention_baseinfo", IntentField, arru...)
  598. }(arru[:indexu])
  599. arru = make([]map[string]interface{}, saveSize)
  600. indexu = 0
  601. }
  602. }
  603. }
  604. }
  605. func SaveWinnerFunc() {
  606. arru := make([]map[string]interface{}, saveSize)
  607. indexu := 0
  608. for {
  609. select {
  610. case v := <-saveWinnerPool:
  611. arru[indexu] = v
  612. indexu++
  613. if indexu == saveSize {
  614. saveWinnerSp <- true
  615. go func(arru []map[string]interface{}) {
  616. defer func() {
  617. <-saveWinnerSp
  618. }()
  619. MysqlTool.InsertBulk("dws_f_bid_winner_baseinfo", WinnerField, arru...)
  620. }(arru)
  621. arru = make([]map[string]interface{}, saveSize)
  622. indexu = 0
  623. }
  624. case <-time.After(1000 * time.Millisecond):
  625. if indexu > 0 {
  626. saveWinnerSp <- true
  627. go func(arru []map[string]interface{}) {
  628. defer func() {
  629. <-saveWinnerSp
  630. }()
  631. MysqlTool.InsertBulk("dws_f_bid_winner_baseinfo", WinnerField, arru...)
  632. }(arru[:indexu])
  633. arru = make([]map[string]interface{}, saveSize)
  634. indexu = 0
  635. }
  636. }
  637. }
  638. }
  639. func SavePackageFunc() {
  640. arru := make([]map[string]interface{}, saveSize)
  641. indexu := 0
  642. for {
  643. select {
  644. case v := <-savePkgPool:
  645. arru[indexu] = v
  646. indexu++
  647. if indexu == saveSize {
  648. savePkgSp <- true
  649. go func(arru []map[string]interface{}) {
  650. defer func() {
  651. <-savePkgSp
  652. }()
  653. MysqlTool.InsertBulk("dws_f_bid_package_baseinfo", PackageField, arru...)
  654. }(arru)
  655. arru = make([]map[string]interface{}, saveSize)
  656. indexu = 0
  657. }
  658. case <-time.After(1000 * time.Millisecond):
  659. if indexu > 0 {
  660. savePkgSp <- true
  661. go func(arru []map[string]interface{}) {
  662. defer func() {
  663. <-savePkgSp
  664. }()
  665. MysqlTool.InsertBulk("dws_f_bid_package_baseinfo", PackageField, arru...)
  666. }(arru[:indexu])
  667. arru = make([]map[string]interface{}, saveSize)
  668. indexu = 0
  669. }
  670. }
  671. }
  672. }
  673. func SaveProFunc() {
  674. arru := make([]map[string]interface{}, saveSize)
  675. indexu := 0
  676. for {
  677. select {
  678. case v := <-saveProPool:
  679. arru[indexu] = v
  680. indexu++
  681. if indexu == saveSize {
  682. saveProSp <- true
  683. go func(arru []map[string]interface{}) {
  684. defer func() {
  685. <-saveProSp
  686. }()
  687. MysqlTool.InsertBulk("dws_f_project_baseinfo", ProField, arru...)
  688. }(arru)
  689. arru = make([]map[string]interface{}, saveSize)
  690. indexu = 0
  691. }
  692. case <-time.After(1000 * time.Millisecond):
  693. if indexu > 0 {
  694. saveProSp <- true
  695. go func(arru []map[string]interface{}) {
  696. defer func() {
  697. <-saveProSp
  698. }()
  699. MysqlTool.InsertBulk("dws_f_project_baseinfo", ProField, arru...)
  700. }(arru[:indexu])
  701. arru = make([]map[string]interface{}, saveSize)
  702. indexu = 0
  703. }
  704. }
  705. }
  706. }
  707. func SaveProbFunc() {
  708. arru := make([]map[string]interface{}, saveSize)
  709. indexu := 0
  710. for {
  711. select {
  712. case v := <-saveProbPool:
  713. arru[indexu] = v
  714. indexu++
  715. if indexu == saveSize {
  716. saveProbSp <- true
  717. go func(arru []map[string]interface{}) {
  718. defer func() {
  719. <-saveProbSp
  720. }()
  721. MysqlTool.InsertBulk("dws_f_project_business", ProBusField, arru...)
  722. }(arru)
  723. arru = make([]map[string]interface{}, saveSize)
  724. indexu = 0
  725. }
  726. case <-time.After(1000 * time.Millisecond):
  727. if indexu > 0 {
  728. saveProbSp <- true
  729. go func(arru []map[string]interface{}) {
  730. defer func() {
  731. <-saveProbSp
  732. }()
  733. MysqlTool.InsertBulk("dws_f_project_business", ProBusField, arru...)
  734. }(arru[:indexu])
  735. arru = make([]map[string]interface{}, saveSize)
  736. indexu = 0
  737. }
  738. }
  739. }
  740. }
  741. func SaveProTagFunc() {
  742. arru := make([]map[string]interface{}, saveSize)
  743. indexu := 0
  744. for {
  745. select {
  746. case v := <-saveProTagPool:
  747. arru[indexu] = v
  748. indexu++
  749. if indexu == saveSize {
  750. saveProTagSp <- true
  751. go func(arru []map[string]interface{}) {
  752. defer func() {
  753. <-saveProTagSp
  754. }()
  755. MysqlTool.InsertBulk("dws_f_project_tags", ProTagsField, arru...)
  756. }(arru)
  757. arru = make([]map[string]interface{}, saveSize)
  758. indexu = 0
  759. }
  760. case <-time.After(1000 * time.Millisecond):
  761. if indexu > 0 {
  762. saveProTagSp <- true
  763. go func(arru []map[string]interface{}) {
  764. defer func() {
  765. <-saveProTagSp
  766. }()
  767. MysqlTool.InsertBulk("dws_f_project_tags", ProTagsField, arru...)
  768. }(arru[:indexu])
  769. arru = make([]map[string]interface{}, saveSize)
  770. indexu = 0
  771. }
  772. }
  773. }
  774. }
  775. func SaveRelationFunc() {
  776. arru := make([]map[string]interface{}, saveSize)
  777. indexu := 0
  778. for {
  779. select {
  780. case v := <-saveRelationPool:
  781. arru[indexu] = v
  782. indexu++
  783. if indexu == saveSize {
  784. saveRelationSp <- true
  785. go func(arru []map[string]interface{}) {
  786. defer func() {
  787. <-saveRelationSp
  788. }()
  789. MysqlTool.InsertBulk("dws_f_bpmc_relation", RelationField, arru...)
  790. }(arru)
  791. arru = make([]map[string]interface{}, saveSize)
  792. indexu = 0
  793. }
  794. case <-time.After(1000 * time.Millisecond):
  795. if indexu > 0 {
  796. saveRelationSp <- true
  797. go func(arru []map[string]interface{}) {
  798. defer func() {
  799. <-saveRelationSp
  800. }()
  801. MysqlTool.InsertBulk("dws_f_bpmc_relation", RelationField, arru...)
  802. }(arru[:indexu])
  803. arru = make([]map[string]interface{}, saveSize)
  804. indexu = 0
  805. }
  806. }
  807. }
  808. }
  809. // 字段错误数据
  810. func saveErrMethod() {
  811. arru := make([]map[string]interface{}, 200)
  812. indexu := 0
  813. for {
  814. select {
  815. case v := <-saveErrPool:
  816. arru[indexu] = v
  817. indexu++
  818. if indexu == saveSize {
  819. saveErrSp <- true
  820. go func(arru []map[string]interface{}) {
  821. defer func() {
  822. <-saveErrSp
  823. }()
  824. MongoB.SaveBulk("bidding_mgo_to_tidb_f_err", arru...)
  825. }(arru)
  826. arru = make([]map[string]interface{}, saveSize)
  827. indexu = 0
  828. }
  829. case <-time.After(1000 * time.Millisecond):
  830. if indexu > 0 {
  831. saveErrSp <- true
  832. go func(arru []map[string]interface{}) {
  833. defer func() {
  834. <-saveErrSp
  835. }()
  836. MongoB.SaveBulk("bidding_mgo_to_tidb_f_err", arru...)
  837. }(arru[:indexu])
  838. arru = make([]map[string]interface{}, saveSize)
  839. indexu = 0
  840. }
  841. }
  842. }
  843. }