provider_modify_platform.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package provider
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "gd_management/impl/pubsub"
  7. "gd_management/rpc_apis"
  8. "gd_management/rpc_apis/gd_access_log"
  9. "time"
  10. "gd_management/common.in/storage"
  11. "github.com/astaxie/beego/orm"
  12. )
  13. func ManagementUpdateProviderPlatform(ctx context.Context, req *apis.ManagementUpdateProviderPlatformReq, reply *apis.ManagementUpdateProviderPlatformReply) error {
  14. task := func(o orm.Ormer) error {
  15. nameChanged := false
  16. if req.ProviderId == 0 {
  17. return errors.ArgsError
  18. }
  19. var providerPlatform apis.ProviderPlatform
  20. err := o.QueryTable("t_gd_provider").Filter("id", req.ProviderId).One(&providerPlatform)
  21. if err != nil {
  22. if err == orm.ErrNoRows {
  23. return errors.ProviderNotExist
  24. }
  25. return errors.DataBaseError
  26. }
  27. var timeLayout = "2006-01-02 15:04:05"
  28. timeNow := time.Now().Format(timeLayout)
  29. if req.PlatformName != "" {
  30. if providerPlatform.PlatformName != req.PlatformName {
  31. nameChanged = true
  32. }
  33. providerPlatform.PlatformName = req.PlatformName
  34. }
  35. if req.PlatformCode != "" {
  36. providerPlatform.PlatformCode = req.PlatformCode
  37. }
  38. if req.Contact != "" {
  39. providerPlatform.Contact = req.Contact
  40. }
  41. if req.Email != "" {
  42. providerPlatform.Email = req.Email
  43. }
  44. providerPlatform.UpdateTime = timeNow
  45. _, err = o.Update(&providerPlatform)
  46. if err != nil {
  47. return errors.DataBaseError
  48. }
  49. if nameChanged {
  50. if err := pubsub.PublishNameNotify("", 0, req.ProviderId); err != nil {
  51. return err
  52. }
  53. if err := pubsub.PublishProviderExportInfoNotify(); err != nil {
  54. return err
  55. }
  56. dreq := gd_access_log.LogUpdateApiNameReq{
  57. Type: 3,
  58. Name: req.PlatformName,
  59. Id: providerPlatform.Id,
  60. }
  61. go func() error {
  62. _, err := rpc_apis.AccessLog.LogUpdateApiName(context.Background(), &dreq)
  63. return err
  64. }()
  65. }
  66. return nil
  67. }
  68. tasks := []storage.DbaTasker{}
  69. tasks = append(tasks, storage.GenerateDbaTask(task))
  70. storage.ExecTrans(tasks...)
  71. return nil
  72. }