12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package base_api
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "gd_management/impl/pubsub"
- "fmt"
- "gd_management/common.in/storage"
- "gd_management/common.in/utils"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- )
- func ManagementDelBaseApi(ctx context.Context, req *apis.ManagementDelBaseApiReq, reply *apis.ManagementDelBaseApiReply) (err error) {
- if req.ApiId == 0 {
- return errors.ArgsError
- }
- task := func(o orm.Ormer) error {
- exist := o.QueryTable("t_gd_child_data_api").Filter("api_id", req.ApiId).Exist()
- if exist {
- return errors.ApiInDataApi
- }
- tab := apis.TGdApi{}
- o.QueryTable("t_gd_api").Filter("id", req.ApiId).One(&tab)
- if err != nil {
- if err == orm.ErrNoRows {
- return errors.DataBaseNoRecord
- }
- return errors.DataBaseError
- }
- if err := pubsub.PublishApiNotify(0, tab.Router, tab.Method); err != nil {
- return err
- }
- if err := pubsub.PublishNameNotify("api_id", req.ApiId, 0); err != nil {
- return err
- }
- sql := "delete from t_gd_api where id=?"
- _, err = o.Raw(sql, req.ApiId).Exec()
- if err != nil {
- l.Error("mysql",
- zap.String("sql", sql),
- zap.String("args", fmt.Sprintf("%d\n", req.ApiId)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- _, err = o.Raw("delete from t_gd_api_provider_relation where api_id=?", req.ApiId).Exec()
- if err != nil {
- return errors.DataBaseError
- }
- key := fmt.Sprintf("t_gd_api-%s-%s", tab.Method, tab.Router)
- if err == nil {
- utils.RedisDelKey(key)
- }
- return nil
- }
- tasks := []storage.DbaTasker{}
- tasks = append(tasks, storage.GenerateDbaTask(task))
- storage.ExecTrans(tasks...)
- l.Debug(utils.MarshalJsonString(req, reply))
- return
- }
|