base_api_provider_del.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package base_api
  2. /*import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/common.in/storage"
  6. "gd_management/common.in/utils"
  7. "gd_management/errors"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego/orm"
  11. "go.uber.org/zap"
  12. "strings"
  13. )
  14. func ManagementDelBaseApiProvider(ctx context.Context, req *apis.ManagementDelBaseApiProviderReq, reply *apis.ManagementDelBaseApiProviderReply) (err error) {
  15. task := func(o orm.Ormer) error {
  16. pids := ""
  17. err = o.Raw("select provider_api_ids from db_gd_management.t_gd_api where id=?", req.ApiId).QueryRow(&pids)
  18. if err != nil {
  19. l.Error("mysql",
  20. zap.String("sql", "select provider_api_ids from db_gd_management.t_gd_api"),
  21. zap.String("args", utils.MarshalJsonString(req)),
  22. zap.String("error", err.Error()))
  23. if err == orm.ErrNoRows {
  24. return errors.DataBaseNoRecord
  25. }
  26. return errors.DataBaseError
  27. }
  28. groups := map[int]string{}
  29. json.Unmarshal([]byte(pids), &groups)
  30. if _, ok := groups[req.GroupNumber]; ok == false {
  31. return errors.ProviderGroupNotExist
  32. }
  33. array := strings.Split(groups[req.GroupNumber], ",")
  34. delpid := fmt.Sprintf("%d", req.ProviderApiId)
  35. newpids := ""
  36. for _, v := range array {
  37. if v == delpid {
  38. continue
  39. }
  40. if newpids == "" {
  41. newpids = v
  42. } else {
  43. newpids = fmt.Sprintf("%s,%s", newpids, v)
  44. }
  45. }
  46. if newpids == "" {
  47. delete(groups, req.GroupNumber)
  48. } else {
  49. groups[req.GroupNumber] = newpids
  50. }
  51. bytes, _ := json.Marshal(groups)
  52. _, err = o.Raw("update db_gd_management.t_gd_api set provider_api_ids=? where id = ?", string(bytes), req.ApiId).Exec()
  53. if err != nil {
  54. l.Error("mysql",
  55. zap.String("sql", "update db_gd_management.t_gd_api set provider_api_ids"),
  56. zap.String("args", utils.MarshalJsonString(req)),
  57. zap.String("error", err.Error()))
  58. return errors.DataBaseError
  59. }
  60. return nil
  61. }
  62. tasks := []storage.DbaTasker{}
  63. tasks = append(tasks, storage.GenerateDbaTask(task))
  64. storage.ExecTrans(tasks...)
  65. l.Debug(utils.MarshalJsonString(req, reply))
  66. return
  67. }
  68. */