12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package base_api
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "strings"
- "github.com/astaxie/beego/orm"
- )
- func ManagementGetTryApiTaskList(ctx context.Context, req *apis.ManagementGetTryApiTaskListReq, reply *apis.ManagementGetTryApiTaskListReply) (err error) {
- total := 0
- sql := "select count(1) from t_gd_try_api_task where type = ?"
- o := orm.NewOrm()
- if req.MerchantId > 0 {
- sql += " AND merchant_id = ?"
- err = o.Raw(sql, req.Type, req.MerchantId).QueryRow(&total)
- } else {
- err = o.Raw(sql, req.Type).QueryRow(&total)
- }
- if err != nil {
- return errors.DataBaseError
- }
- if req.PageSize == 0 {
- req.PageSize = PAGESIZE
- }
- reply.Total = total
- var list = []apis.TryApi{}
- defer func() {
- for _, v := range list {
- item := apis.TryApiItem{}
- item.ApiName = v.ApiName
- item.CreatedAt = v.CreatedAt
- item.FileName = v.FileName
- item.DownloadFile = v.DownloadFile
- item.ApiRouter = v.ApiRouter
- item.TaskName = v.TaskName
- item.Merchant = v.Merchant
- item.Id = v.Id
- item.StatusCode = v.StatusCode
- reply.Tasks = append(reply.Tasks, item)
- }
- }()
- if req.IsAll {
- if req.MerchantId > 0 {
- sql := `select * from t_gd_try_api_task where api_name like "%??%" and type = ? AND merchant_id = ? order by updated_at desc`
- sql = strings.ReplaceAll(sql, "??", req.ApiName)
- _, err = o.Raw(sql, req.Type, req.MerchantId).QueryRows(&list)
- } else {
- sql := `select * from t_gd_try_api_task where api_name like "%??%" and type = ? order by updated_at desc`
- sql = strings.ReplaceAll(sql, "??", req.ApiName)
- _, err = o.Raw(sql, req.Type).QueryRows(&list)
- }
- if err != nil && err != orm.ErrNoRows {
- return errors.DataBaseError
- }
- return nil
- }
- if req.PageNumber > 0 {
- req.PageNumber--
- }
- reply.PageNumber = req.PageNumber + 1
- reply.PageSize = req.PageSize
- if req.MerchantId > 0 {
- sql = `select * from t_gd_try_api_task where api_name like "%??%" and type = ? AND merchant_id = ? order by updated_at desc limit ? offset ?`
- sql = strings.ReplaceAll(sql, "??", req.ApiName)
- _, err = o.Raw(sql, req.Type, req.MerchantId, req.PageSize, req.PageNumber*req.PageSize).QueryRows(&list)
- } else {
- sql = `select * from t_gd_try_api_task where api_name like "%??%" and type = ? order by updated_at desc limit ? offset ?`
- sql = strings.ReplaceAll(sql, "??", req.ApiName)
- _, err = o.Raw(sql, req.Type, req.PageSize, req.PageNumber*req.PageSize).QueryRows(&list)
- }
- if err != nil && err != orm.ErrNoRows {
- return errors.DataBaseError
- }
- return nil
- }
|