h5_api_del.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package h5
  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. "gd_management/impl/pubsub"
  9. "github.com/astaxie/beego/orm"
  10. "go.uber.org/zap"
  11. )
  12. func delH5Api(req *apis.ManagementDelH5ApiReq) error {
  13. task := func(o orm.Ormer) error {
  14. _, err := o.Raw("delete from t_gd_h5_api where id=?", req.H5ApiId).Exec()
  15. if err != nil {
  16. if err == orm.ErrNoRows {
  17. return errors.DataBaseNoRecord
  18. }
  19. return errors.DataBaseError
  20. }
  21. if err := pubsub.PublishNameNotify("h5_api_id", req.H5ApiId, 0); err != nil {
  22. return err
  23. }
  24. _, err = o.Raw("delete from t_gd_h5_base_api_relation where h5_api_id=?", req.H5ApiId).Exec()
  25. if err != nil {
  26. if err == orm.ErrNoRows {
  27. return errors.DataBaseNoRecord
  28. }
  29. return errors.DataBaseError
  30. }
  31. return nil
  32. }
  33. tasks := []storage.DbaTasker{}
  34. tasks = append(tasks, storage.GenerateDbaTask(task))
  35. storage.ExecTrans(tasks...)
  36. return nil
  37. }
  38. func ManagementDelH5Api(ctx context.Context, req *apis.ManagementDelH5ApiReq, reply *apis.ManagementDelH5ApiReply) (err error) {
  39. err = delH5Api(req)
  40. if err != nil {
  41. l.Error("func",
  42. zap.String("call", "ManagementDelH5Api"),
  43. zap.String("args", utils.MarshalJsonString(req)),
  44. zap.String("error", err.Error()))
  45. }
  46. l.Debug(utils.MarshalJsonString(req, reply))
  47. return
  48. }