1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package base_api
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "fmt"
- "strings"
- "time"
- "github.com/astaxie/beego/orm"
- )
- func ManagementCreateTryApiTask(ctx context.Context, req *apis.ManagementCreateTryApiTaskReq, reply *apis.ManagementCreateTryApiTaskReply) (err error) {
- if req.Router == "" || req.FileName == "" || req.Method == "" {
- return errors.ArgsError
- }
- now := time.Now().Format("2006-01-02 15:04:05")
- o := orm.NewOrm()
- count := 0
- sql := "select count(1) from t_gd_try_api_task where file_name=? and type=?"
- err = o.Raw(sql, req.FileName, 1).QueryRow(&count)
- if count > 0 {
- return errors.TaskExist
- } else if err != nil && err != orm.ErrNoRows {
- return errors.DataBaseError
- }
- merchantName := ""
- o.Raw("select merchant_name from t_gd_merchants where app_key=?", req.AppKey).QueryRow(&merchantName)
- task := apis.TryApi{}
- task.Type = 1
- task.ApiName = req.ApiName
- task.StatusCode = 0
- task.ApiRouter = req.Router
- task.FileName = req.FileName
- task.DownloadFile = req.DownloadFile
- task.OriginFile = req.OriginFile
- task.RequestInfo = req.RequestInfo
- task.UpdatedAt = now
- task.CreatedAt = now
- task.TaskName = req.TaskName
- task.MerchantId = req.MerchantId
- task.Merchant = fmt.Sprintf("%s(使用内部账号)", merchantName)
- if req.IsMerchant {
- task.Merchant = fmt.Sprintf("%s(使用商户账号)", merchantName)
- }
- if task.TaskName == "" {
- task.TaskName = strings.TrimRight(req.FileName, ".xlsx")
- }
- id, err := o.Insert(&task)
- if err != nil {
- return errors.DataBaseError
- }
- reply.Id = id
- return nil
- }
|