name_update.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package access_log
  4. import (
  5. "context"
  6. "gd_access_log/apis"
  7. "gd_access_log/common.in/storage"
  8. "gd_access_log/errors"
  9. "fmt"
  10. "github.com/astaxie/beego/orm"
  11. )
  12. func updateApiName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error {
  13. task := func(o orm.Ormer) error {
  14. _, err := o.Raw("update t_gd_access_log_day set api_name=? where api_id=?", req.Name, req.Id).Exec()
  15. if err != nil {
  16. return errors.DataBaseError
  17. }
  18. _, err = o.Raw("update t_gd_thirdpart_log_day set api_name=? where api_id=?", req.Name, req.Id).Exec()
  19. if err != nil {
  20. return errors.DataBaseError
  21. }
  22. for i := 1; i <= 12; i++ {
  23. sql := fmt.Sprintf("update t_gd_access_log_month%d set api_name=? where api_id=?", i)
  24. if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil {
  25. return errors.DataBaseError
  26. }
  27. }
  28. return nil
  29. }
  30. tasks := []storage.DbaTasker{}
  31. tasks = append(tasks, storage.GenerateDbaTask(task))
  32. storage.ExecTrans(tasks...)
  33. return nil
  34. }
  35. func updateProviderApiName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error {
  36. task := func(o orm.Ormer) error {
  37. _, err := o.Raw("update t_gd_thirdpart_log_day set provider_api_name=? where provider_api_id=?", req.Name, req.Id).Exec()
  38. if err != nil {
  39. return errors.DataBaseError
  40. }
  41. for i := 1; i <= 12; i++ {
  42. sql := fmt.Sprintf("update t_gd_thirdpart_log_month%d set provider_api_name=? where provider_api_id=?", i)
  43. if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil {
  44. return errors.DataBaseError
  45. }
  46. }
  47. return nil
  48. }
  49. tasks := []storage.DbaTasker{}
  50. tasks = append(tasks, storage.GenerateDbaTask(task))
  51. storage.ExecTrans(tasks...)
  52. return nil
  53. }
  54. func updateMerchantName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error {
  55. task := func(o orm.Ormer) error {
  56. _, err := o.Raw("update t_gd_access_log_day set merchant_name=? where merchant_id=?", req.Name, req.Id).Exec()
  57. if err != nil {
  58. return errors.DataBaseError
  59. }
  60. _, err = o.Raw("update t_gd_thirdpart_log_day set merchant_name=? where merchant_id=?", req.Name, req.Id).Exec()
  61. if err != nil {
  62. return errors.DataBaseError
  63. }
  64. for i := 1; i <= 12; i++ {
  65. sql := fmt.Sprintf("update t_gd_access_log_month%d set merchant_name=? where merchant_id=?", i)
  66. if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil {
  67. return errors.DataBaseError
  68. }
  69. }
  70. return nil
  71. }
  72. tasks := []storage.DbaTasker{}
  73. tasks = append(tasks, storage.GenerateDbaTask(task))
  74. storage.ExecTrans(tasks...)
  75. return nil
  76. }
  77. func updateProviderName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error {
  78. task := func(o orm.Ormer) error {
  79. _, err := o.Raw("update t_gd_thirdpart_access_log set provider_name=? where provider_id=?", req.Name, req.Id).Exec()
  80. if err != nil {
  81. return errors.DataBaseError
  82. }
  83. _, err = o.Raw("update t_gd_thirdpart_access_log_history set provider_name=? where provider_id=?", req.Name, req.Id).Exec()
  84. if err != nil {
  85. return errors.DataBaseError
  86. }
  87. _, err = o.Raw("update t_gd_thirdpart_log_day set provider_name=? where provider_id=?", req.Name, req.Id).Exec()
  88. if err != nil {
  89. return errors.DataBaseError
  90. }
  91. for i := 1; i <= 12; i++ {
  92. sql := fmt.Sprintf("update t_gd_thirdpart_log_month%d set provider_name=? where provider_id=?", i)
  93. if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil {
  94. return errors.DataBaseError
  95. }
  96. }
  97. return nil
  98. }
  99. tasks := []storage.DbaTasker{}
  100. tasks = append(tasks, storage.GenerateDbaTask(task))
  101. storage.ExecTrans(tasks...)
  102. return nil
  103. }
  104. func LogUpdateApiName(ctx context.Context, req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) (err error) {
  105. if req.Name == "" || req.Id == 0 {
  106. return errors.ArgsError
  107. }
  108. switch req.Type {
  109. case 0:
  110. return updateApiName(req, reply)
  111. case 1:
  112. return updateProviderApiName(req, reply)
  113. case 2:
  114. return updateMerchantName(req, reply)
  115. case 3:
  116. return updateProviderName(req, reply)
  117. }
  118. return nil
  119. }