data_api_modify_base_api.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package data_api
  4. import (
  5. "context"
  6. "gd_management/apis"
  7. "gd_management/errors"
  8. "encoding/json"
  9. "time"
  10. "gd_management/common.in/storage"
  11. "github.com/astaxie/beego/orm"
  12. )
  13. // DataApiModifyBaseApi 修改数据api下的基础api
  14. func DataApiModifyBaseApi(ctx context.Context, req *apis.ManagementDataApiModifyBaseApiReq, reply *apis.ManagementDataApiModifyBaseApiReply) error {
  15. // 参数检查
  16. if req.DataApiBaseApiId == 0 {
  17. return errors.ArgsError
  18. }
  19. task := func(o orm.Ormer) error {
  20. var dataApiBaseApi apis.ManagementDataApiBaseApi
  21. // 获取老数据
  22. err := o.QueryTable("t_gd_child_data_api").Filter("id", req.DataApiBaseApiId).One(&dataApiBaseApi)
  23. if err != nil {
  24. if err != orm.ErrNoRows {
  25. return errors.DataBaseError
  26. } else {
  27. return errors.DataApiBaseApiNotExist
  28. }
  29. }
  30. if req.SaleName != "" {
  31. dataApiBaseApi.SaleName = req.SaleName
  32. }
  33. if req.CountCode != "" {
  34. dataApiBaseApi.CountCode = req.CountCode
  35. }
  36. if req.CountType != dataApiBaseApi.CountType {
  37. dataApiBaseApi.CountType = req.CountType
  38. }
  39. if req.ForceUpdate != dataApiBaseApi.ForceUpdate {
  40. dataApiBaseApi.ForceUpdate = req.ForceUpdate
  41. }
  42. if req.IsCrypto != dataApiBaseApi.IsCrypto {
  43. dataApiBaseApi.IsCrypto = req.IsCrypto
  44. }
  45. if req.ReuseTime != dataApiBaseApi.ReuseTime {
  46. dataApiBaseApi.ReuseTime = req.ReuseTime
  47. }
  48. if len(req.RequestParam) != 0 {
  49. requestParam, err := json.Marshal(req.RequestParam)
  50. if err != nil {
  51. return err
  52. }
  53. dataApiBaseApi.RequestParam = string(requestParam)
  54. }
  55. if len(req.ResponseParam) != 0 {
  56. responseParam, err := json.Marshal(req.ResponseParam)
  57. if err != nil {
  58. return err
  59. }
  60. dataApiBaseApi.ResponseParam = string(responseParam)
  61. }
  62. if len(req.Filters) != 0 {
  63. filter, err := json.Marshal(req.Filters)
  64. if err != nil {
  65. return err
  66. }
  67. dataApiBaseApi.Filter = string(filter)
  68. } else {
  69. dataApiBaseApi.Filter = ""
  70. }
  71. var timeLayout = "2006-01-02 15:04:05"
  72. timeNow := time.Now().Format(timeLayout)
  73. dataApiBaseApi.UpdateTime = timeNow
  74. _, err = o.Update(&dataApiBaseApi)
  75. if err != nil {
  76. return errors.DataBaseError
  77. }
  78. for _, group := range req.ProviderGroupList {
  79. for _, provider := range group.ProviderApiList {
  80. _, err := o.Raw("update t_gd_data_api_provider_api_relation set enable = ? where child_data_api_id=? and group_no=? and provider_api_id=?",
  81. provider.Enable, req.DataApiBaseApiId, group.GroupNo, provider.ProviderApiId).Exec()
  82. if err != nil {
  83. return errors.DataBaseError
  84. }
  85. }
  86. }
  87. return nil
  88. }
  89. tasks := []storage.DbaTasker{}
  90. tasks = append(tasks, storage.GenerateDbaTask(task))
  91. storage.ExecTrans(tasks...)
  92. return nil
  93. }