package base_api /*import ( "context" "gd_management/apis" "gd_management/common.in/storage" "gd_management/common.in/utils" "gd_management/errors" "encoding/json" "fmt" "github.com/astaxie/beego/orm" "go.uber.org/zap" "strings" ) func ManagementDelBaseApiProvider(ctx context.Context, req *apis.ManagementDelBaseApiProviderReq, reply *apis.ManagementDelBaseApiProviderReply) (err error) { task := func(o orm.Ormer) error { pids := "" err = o.Raw("select provider_api_ids from db_gd_management.t_gd_api where id=?", req.ApiId).QueryRow(&pids) if err != nil { l.Error("mysql", zap.String("sql", "select provider_api_ids from db_gd_management.t_gd_api"), zap.String("args", utils.MarshalJsonString(req)), zap.String("error", err.Error())) if err == orm.ErrNoRows { return errors.DataBaseNoRecord } return errors.DataBaseError } groups := map[int]string{} json.Unmarshal([]byte(pids), &groups) if _, ok := groups[req.GroupNumber]; ok == false { return errors.ProviderGroupNotExist } array := strings.Split(groups[req.GroupNumber], ",") delpid := fmt.Sprintf("%d", req.ProviderApiId) newpids := "" for _, v := range array { if v == delpid { continue } if newpids == "" { newpids = v } else { newpids = fmt.Sprintf("%s,%s", newpids, v) } } if newpids == "" { delete(groups, req.GroupNumber) } else { groups[req.GroupNumber] = newpids } bytes, _ := json.Marshal(groups) _, err = o.Raw("update db_gd_management.t_gd_api set provider_api_ids=? where id = ?", string(bytes), req.ApiId).Exec() if err != nil { l.Error("mysql", zap.String("sql", "update db_gd_management.t_gd_api set provider_api_ids"), zap.String("args", utils.MarshalJsonString(req)), zap.String("error", err.Error())) return errors.DataBaseError } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) l.Debug(utils.MarshalJsonString(req, reply)) return } */