lua_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  6. "log"
  7. "strings"
  8. "testing"
  9. )
  10. func TestUpdateLuaConfig(t *testing.T) {
  11. //87 竞品
  12. MgoLua := &mongodb.MongodbSim{
  13. //MongodbAddr: "172.17.189.140:27080",
  14. MongodbAddr: "127.0.0.1:27081",
  15. Size: 10,
  16. DbName: "editor",
  17. UserName: "",
  18. Password: "",
  19. Direct: true,
  20. }
  21. MgoLua.InitPool()
  22. sess := MgoLua.GetMgoConn()
  23. defer MgoLua.DestoryMongoConn(sess)
  24. f, err := excelize.OpenFile("./luaconfig.xlsx")
  25. if err != nil {
  26. fmt.Println(err)
  27. return
  28. }
  29. defer func() {
  30. if err := f.Close(); err != nil {
  31. fmt.Println(err)
  32. }
  33. }()
  34. rows, err := f.GetRows("Sheet1")
  35. if err != nil {
  36. fmt.Println(err)
  37. return
  38. }
  39. /**
  40. 1、刷至 golua平台 爬虫,state=0,platform=golua平台
  41. 2、刷至通用平台爬虫,state=0,platform=通用平台,claimtype=1
  42. 3、刷至jschrome平台爬虫,state=0,platform=jschrome
  43. 4、以上所有爬虫均修改createuser、modifyuser、modifyuserid、createuserid、createuseremail、next字段。createuser、modifyuser 为user表s_name;modifyuserid、createuserid为user表_id;createuseremail、next为user表s_email
  44. 5、爬虫表87/editor/luaconfig 用户表87/editor/user
  45. */
  46. for i := 1; i < len(rows); i++ {
  47. row := rows[i]
  48. code := strings.TrimSpace(row[0])
  49. modifyuser := strings.TrimSpace(row[1])
  50. platform := strings.TrimSpace(row[2])
  51. //更新MongoDB
  52. updateWhere := map[string]interface{}{
  53. "code": code,
  54. }
  55. exists, _ := MgoLua.FindOne("luaconfig", updateWhere)
  56. if len(*exists) == 0 {
  57. log.Println("code 没有找到数据", code)
  58. continue
  59. }
  60. log.Println(code, modifyuser, platform)
  61. update := make(map[string]interface{})
  62. if platform == "golua平台" {
  63. update["state"] = 0
  64. update["platform"] = "golua平台"
  65. } else if platform == "通用平台" {
  66. update["state"] = 0
  67. update["platform"] = "通用平台"
  68. update["claimtype"] = 1
  69. } else if platform == "jschrome" {
  70. update["state"] = 0
  71. update["platform"] = "jschrome"
  72. }
  73. update["createuser"] = modifyuser
  74. update["modifyuser"] = modifyuser
  75. where := map[string]interface{}{
  76. "s_name": modifyuser,
  77. }
  78. user, _ := MgoLua.FindOne("user", where)
  79. if user == nil {
  80. log.Println("user 查询失败", where)
  81. return
  82. }
  83. update["modifyuserid"] = mongodb.BsonIdToSId((*user)["_id"])
  84. update["createuserid"] = mongodb.BsonIdToSId((*user)["_id"])
  85. update["createuseremail"] = (*user)["s_email"]
  86. update["next"] = (*user)["s_email"]
  87. MgoLua.Update("luaconfig", updateWhere, map[string]interface{}{"$set": update}, true, false)
  88. }
  89. }