main.go 21 KB

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