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("project_ids=127.0.0.1:8379", 0)
  29. //redis.InitRedis1("qyxy_id=192.168.3.166:4379", 1)
  30. log.Info("init success")
  31. }
  32. func main() {
  33. //
  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(relation())
  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 relation() *cobra.Command {
  301. cmdClient := &cobra.Command{
  302. Use: "relation",
  303. Short: "Start processing relation data",
  304. Run: func(cmd *cobra.Command, args []string) {
  305. InitEs()
  306. go SaveRelationFunc()
  307. taskR()
  308. },
  309. }
  310. return cmdClient
  311. }
  312. // @Description 项目数据(目前仅关系表数据)
  313. // @Author J 2022/9/20 17:52
  314. func projectAdd() *cobra.Command {
  315. var pici int64
  316. cmdClient := &cobra.Command{
  317. Use: "project",
  318. Short: "Start processing project data",
  319. Run: func(cmd *cobra.Command, args []string) {
  320. //go SaveProFunc()
  321. //go SaveProTagFunc()
  322. //go SaveProbFunc()
  323. go SaveRelationFunc()
  324. taskPAdd(pici)
  325. },
  326. }
  327. cmdClient.Flags().Int64VarP(&pici, "pici", "p", 0, "")
  328. return cmdClient
  329. }
  330. func SaveFunc() {
  331. arru := make([]map[string]interface{}, saveSize)
  332. indexu := 0
  333. for {
  334. select {
  335. case v := <-saveBasePool:
  336. arru[indexu] = v
  337. indexu++
  338. if indexu == saveSize {
  339. saveBaseSp <- true
  340. go func(arru []map[string]interface{}) {
  341. defer func() {
  342. <-saveBaseSp
  343. }()
  344. MysqlTool.InsertBulk("dws_f_bid_baseinfo", BaseField, arru...)
  345. }(arru)
  346. arru = make([]map[string]interface{}, saveSize)
  347. indexu = 0
  348. }
  349. case <-time.After(1000 * time.Millisecond):
  350. if indexu > 0 {
  351. saveBaseSp <- true
  352. go func(arru []map[string]interface{}) {
  353. defer func() {
  354. <-saveBaseSp
  355. }()
  356. MysqlTool.InsertBulk("dws_f_bid_baseinfo", BaseField, arru...)
  357. }(arru[:indexu])
  358. arru = make([]map[string]interface{}, saveSize)
  359. indexu = 0
  360. }
  361. }
  362. }
  363. }
  364. func SaveExpandFunc() {
  365. arru := make([]map[string]interface{}, saveSize)
  366. indexu := 0
  367. for {
  368. select {
  369. case v := <-saveExpandPool:
  370. arru[indexu] = v
  371. indexu++
  372. if indexu == saveSize {
  373. saveExpandSp <- true
  374. go func(arru []map[string]interface{}) {
  375. defer func() {
  376. <-saveExpandSp
  377. }()
  378. MysqlTool.InsertBulk("dws_f_bid_expand_baseinfo", ExpandField, arru...)
  379. }(arru)
  380. arru = make([]map[string]interface{}, saveSize)
  381. indexu = 0
  382. }
  383. case <-time.After(1000 * time.Millisecond):
  384. if indexu > 0 {
  385. saveExpandSp <- true
  386. go func(arru []map[string]interface{}) {
  387. defer func() {
  388. <-saveExpandSp
  389. }()
  390. MysqlTool.InsertBulk("dws_f_bid_expand_baseinfo", ExpandField, arru...)
  391. }(arru[:indexu])
  392. arru = make([]map[string]interface{}, saveSize)
  393. indexu = 0
  394. }
  395. }
  396. }
  397. }
  398. func SaveTagFunc() {
  399. arru := make([]map[string]interface{}, saveSize)
  400. indexu := 0
  401. for {
  402. select {
  403. case v := <-saveTagPool:
  404. arru[indexu] = v
  405. indexu++
  406. if indexu == saveSize {
  407. saveTagSp <- true
  408. go func(arru []map[string]interface{}) {
  409. defer func() {
  410. <-saveTagSp
  411. }()
  412. MysqlTool.InsertBulk("dws_f_bid_tags", TagsField, arru...)
  413. }(arru)
  414. arru = make([]map[string]interface{}, saveSize)
  415. indexu = 0
  416. }
  417. case <-time.After(1000 * time.Millisecond):
  418. if indexu > 0 {
  419. saveTagSp <- true
  420. go func(arru []map[string]interface{}) {
  421. defer func() {
  422. <-saveTagSp
  423. }()
  424. MysqlTool.InsertBulk("dws_f_bid_tags", TagsField, arru...)
  425. }(arru[:indexu])
  426. arru = make([]map[string]interface{}, saveSize)
  427. indexu = 0
  428. }
  429. }
  430. }
  431. }
  432. func SaveAttrFunc() {
  433. arru := make([]map[string]interface{}, saveSize)
  434. indexu := 0
  435. for {
  436. select {
  437. case v := <-saveAttrPool:
  438. arru[indexu] = v
  439. indexu++
  440. if indexu == saveSize {
  441. saveAttrSp <- true
  442. go func(arru []map[string]interface{}) {
  443. defer func() {
  444. <-saveAttrSp
  445. }()
  446. MysqlTool.InsertBulk("dws_f_bid_filetext_baseinfo", AttrField, arru...)
  447. }(arru)
  448. arru = make([]map[string]interface{}, saveSize)
  449. indexu = 0
  450. }
  451. case <-time.After(1000 * time.Millisecond):
  452. if indexu > 0 {
  453. saveAttrSp <- true
  454. go func(arru []map[string]interface{}) {
  455. defer func() {
  456. <-saveAttrSp
  457. }()
  458. MysqlTool.InsertBulk("dws_f_bid_filetext_baseinfo", AttrField, arru...)
  459. }(arru[:indexu])
  460. arru = make([]map[string]interface{}, saveSize)
  461. indexu = 0
  462. }
  463. }
  464. }
  465. }
  466. func SaveImfFunc() {
  467. arru := make([]map[string]interface{}, saveSize)
  468. indexu := 0
  469. for {
  470. select {
  471. case v := <-saveIfmPool:
  472. arru[indexu] = v
  473. indexu++
  474. if indexu == saveSize {
  475. saveIfmSp <- true
  476. go func(arru []map[string]interface{}) {
  477. defer func() {
  478. <-saveIfmSp
  479. }()
  480. MysqlTool.InsertBulk("dws_f_bid_infoformat_baseinfo", IfmField, arru...)
  481. }(arru)
  482. arru = make([]map[string]interface{}, saveSize)
  483. indexu = 0
  484. }
  485. case <-time.After(1000 * time.Millisecond):
  486. if indexu > 0 {
  487. saveIfmSp <- true
  488. go func(arru []map[string]interface{}) {
  489. defer func() {
  490. <-saveIfmSp
  491. }()
  492. MysqlTool.InsertBulk("dws_f_bid_infoformat_baseinfo", IfmField, arru...)
  493. }(arru[:indexu])
  494. arru = make([]map[string]interface{}, saveSize)
  495. indexu = 0
  496. }
  497. }
  498. }
  499. }
  500. func SavePurFunc() {
  501. arru := make([]map[string]interface{}, saveSize)
  502. indexu := 0
  503. for {
  504. select {
  505. case v := <-savePurPool:
  506. arru[indexu] = v
  507. indexu++
  508. if indexu == saveSize {
  509. savePurSp <- true
  510. go func(arru []map[string]interface{}) {
  511. defer func() {
  512. <-savePurSp
  513. }()
  514. MysqlTool.InsertBulk("dws_f_bid_purchasing_baseinfo", PurField, arru...)
  515. }(arru)
  516. arru = make([]map[string]interface{}, saveSize)
  517. indexu = 0
  518. }
  519. case <-time.After(1000 * time.Millisecond):
  520. if indexu > 0 {
  521. savePurSp <- true
  522. go func(arru []map[string]interface{}) {
  523. defer func() {
  524. <-savePurSp
  525. }()
  526. MysqlTool.InsertBulk("dws_f_bid_purchasing_baseinfo", PurField, arru...)
  527. }(arru[:indexu])
  528. arru = make([]map[string]interface{}, saveSize)
  529. indexu = 0
  530. }
  531. }
  532. }
  533. }
  534. func SaveIntentFunc() {
  535. arru := make([]map[string]interface{}, saveSize)
  536. indexu := 0
  537. for {
  538. select {
  539. case v := <-saveIntentPool:
  540. arru[indexu] = v
  541. indexu++
  542. if indexu == saveSize {
  543. saveIntentSp <- true
  544. go func(arru []map[string]interface{}) {
  545. defer func() {
  546. <-saveIntentSp
  547. }()
  548. MysqlTool.InsertBulk("dws_f_bid_intention_baseinfo", IntentField, arru...)
  549. }(arru)
  550. arru = make([]map[string]interface{}, saveSize)
  551. indexu = 0
  552. }
  553. case <-time.After(1000 * time.Millisecond):
  554. if indexu > 0 {
  555. saveIntentSp <- true
  556. go func(arru []map[string]interface{}) {
  557. defer func() {
  558. <-saveIntentSp
  559. }()
  560. MysqlTool.InsertBulk("dws_f_bid_intention_baseinfo", IntentField, arru...)
  561. }(arru[:indexu])
  562. arru = make([]map[string]interface{}, saveSize)
  563. indexu = 0
  564. }
  565. }
  566. }
  567. }
  568. func SaveWinnerFunc() {
  569. arru := make([]map[string]interface{}, saveSize)
  570. indexu := 0
  571. for {
  572. select {
  573. case v := <-saveWinnerPool:
  574. arru[indexu] = v
  575. indexu++
  576. if indexu == saveSize {
  577. saveWinnerSp <- true
  578. go func(arru []map[string]interface{}) {
  579. defer func() {
  580. <-saveWinnerSp
  581. }()
  582. MysqlTool.InsertBulk("dws_f_bid_winner_baseinfo", WinnerField, arru...)
  583. }(arru)
  584. arru = make([]map[string]interface{}, saveSize)
  585. indexu = 0
  586. }
  587. case <-time.After(1000 * time.Millisecond):
  588. if indexu > 0 {
  589. saveWinnerSp <- true
  590. go func(arru []map[string]interface{}) {
  591. defer func() {
  592. <-saveWinnerSp
  593. }()
  594. MysqlTool.InsertBulk("dws_f_bid_winner_baseinfo", WinnerField, arru...)
  595. }(arru[:indexu])
  596. arru = make([]map[string]interface{}, saveSize)
  597. indexu = 0
  598. }
  599. }
  600. }
  601. }
  602. func SavePackageFunc() {
  603. arru := make([]map[string]interface{}, saveSize)
  604. indexu := 0
  605. for {
  606. select {
  607. case v := <-savePkgPool:
  608. arru[indexu] = v
  609. indexu++
  610. if indexu == saveSize {
  611. savePkgSp <- true
  612. go func(arru []map[string]interface{}) {
  613. defer func() {
  614. <-savePkgSp
  615. }()
  616. MysqlTool.InsertBulk("dws_f_bid_package_baseinfo", PackageField, arru...)
  617. }(arru)
  618. arru = make([]map[string]interface{}, saveSize)
  619. indexu = 0
  620. }
  621. case <-time.After(1000 * time.Millisecond):
  622. if indexu > 0 {
  623. savePkgSp <- true
  624. go func(arru []map[string]interface{}) {
  625. defer func() {
  626. <-savePkgSp
  627. }()
  628. MysqlTool.InsertBulk("dws_f_bid_package_baseinfo", PackageField, arru...)
  629. }(arru[:indexu])
  630. arru = make([]map[string]interface{}, saveSize)
  631. indexu = 0
  632. }
  633. }
  634. }
  635. }
  636. func SaveProFunc() {
  637. arru := make([]map[string]interface{}, saveSize)
  638. indexu := 0
  639. for {
  640. select {
  641. case v := <-saveProPool:
  642. arru[indexu] = v
  643. indexu++
  644. if indexu == saveSize {
  645. saveProSp <- true
  646. go func(arru []map[string]interface{}) {
  647. defer func() {
  648. <-saveProSp
  649. }()
  650. MysqlTool.InsertBulk("dws_f_project_baseinfo", ProField, arru...)
  651. }(arru)
  652. arru = make([]map[string]interface{}, saveSize)
  653. indexu = 0
  654. }
  655. case <-time.After(1000 * time.Millisecond):
  656. if indexu > 0 {
  657. saveProSp <- true
  658. go func(arru []map[string]interface{}) {
  659. defer func() {
  660. <-saveProSp
  661. }()
  662. MysqlTool.InsertBulk("dws_f_project_baseinfo", ProField, arru...)
  663. }(arru[:indexu])
  664. arru = make([]map[string]interface{}, saveSize)
  665. indexu = 0
  666. }
  667. }
  668. }
  669. }
  670. func SaveProbFunc() {
  671. arru := make([]map[string]interface{}, saveSize)
  672. indexu := 0
  673. for {
  674. select {
  675. case v := <-saveProbPool:
  676. arru[indexu] = v
  677. indexu++
  678. if indexu == saveSize {
  679. saveProbSp <- true
  680. go func(arru []map[string]interface{}) {
  681. defer func() {
  682. <-saveProbSp
  683. }()
  684. MysqlTool.InsertBulk("dws_f_project_business", ProBusField, arru...)
  685. }(arru)
  686. arru = make([]map[string]interface{}, saveSize)
  687. indexu = 0
  688. }
  689. case <-time.After(1000 * time.Millisecond):
  690. if indexu > 0 {
  691. saveProbSp <- true
  692. go func(arru []map[string]interface{}) {
  693. defer func() {
  694. <-saveProbSp
  695. }()
  696. MysqlTool.InsertBulk("dws_f_project_business", ProBusField, arru...)
  697. }(arru[:indexu])
  698. arru = make([]map[string]interface{}, saveSize)
  699. indexu = 0
  700. }
  701. }
  702. }
  703. }
  704. func SaveProTagFunc() {
  705. arru := make([]map[string]interface{}, saveSize)
  706. indexu := 0
  707. for {
  708. select {
  709. case v := <-saveProTagPool:
  710. arru[indexu] = v
  711. indexu++
  712. if indexu == saveSize {
  713. saveProTagSp <- true
  714. go func(arru []map[string]interface{}) {
  715. defer func() {
  716. <-saveProTagSp
  717. }()
  718. MysqlTool.InsertBulk("dws_f_project_tags", ProTagsField, arru...)
  719. }(arru)
  720. arru = make([]map[string]interface{}, saveSize)
  721. indexu = 0
  722. }
  723. case <-time.After(1000 * time.Millisecond):
  724. if indexu > 0 {
  725. saveProTagSp <- true
  726. go func(arru []map[string]interface{}) {
  727. defer func() {
  728. <-saveProTagSp
  729. }()
  730. MysqlTool.InsertBulk("dws_f_project_tags", ProTagsField, arru...)
  731. }(arru[:indexu])
  732. arru = make([]map[string]interface{}, saveSize)
  733. indexu = 0
  734. }
  735. }
  736. }
  737. }
  738. func SaveRelationFunc() {
  739. arru := make([]map[string]interface{}, saveSize)
  740. indexu := 0
  741. for {
  742. select {
  743. case v := <-saveRelationPool:
  744. arru[indexu] = v
  745. indexu++
  746. if indexu == saveSize {
  747. saveRelationSp <- true
  748. go func(arru []map[string]interface{}) {
  749. defer func() {
  750. <-saveRelationSp
  751. }()
  752. MysqlTool.InsertBulk("dws_f_bpmc_relation_new", RelationField, arru...)
  753. }(arru)
  754. arru = make([]map[string]interface{}, saveSize)
  755. indexu = 0
  756. }
  757. case <-time.After(1000 * time.Millisecond):
  758. if indexu > 0 {
  759. saveRelationSp <- true
  760. go func(arru []map[string]interface{}) {
  761. defer func() {
  762. <-saveRelationSp
  763. }()
  764. MysqlTool.InsertBulk("dws_f_bpmc_relation_new", RelationField, arru...)
  765. }(arru[:indexu])
  766. arru = make([]map[string]interface{}, saveSize)
  767. indexu = 0
  768. }
  769. }
  770. }
  771. }
  772. // 字段错误数据
  773. func saveErrMethod() {
  774. arru := make([]map[string]interface{}, 200)
  775. indexu := 0
  776. for {
  777. select {
  778. case v := <-saveErrPool:
  779. arru[indexu] = v
  780. indexu++
  781. if indexu == saveSize {
  782. saveErrSp <- true
  783. go func(arru []map[string]interface{}) {
  784. defer func() {
  785. <-saveErrSp
  786. }()
  787. MongoB.SaveBulk("bidding_tidb_f_err", arru...)
  788. }(arru)
  789. arru = make([]map[string]interface{}, saveSize)
  790. indexu = 0
  791. }
  792. case <-time.After(1000 * time.Millisecond):
  793. if indexu > 0 {
  794. saveErrSp <- true
  795. go func(arru []map[string]interface{}) {
  796. defer func() {
  797. <-saveErrSp
  798. }()
  799. MongoB.SaveBulk("bidding_tidb_f_err", arru...)
  800. }(arru[:indexu])
  801. arru = make([]map[string]interface{}, saveSize)
  802. indexu = 0
  803. }
  804. }
  805. }
  806. }