main.go 22 KB

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