try_api_task_update.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package base_api
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "time"
  7. "github.com/astaxie/beego/orm"
  8. )
  9. func ManagementUpdateTryApiTask(ctx context.Context, req *apis.ManagementUpdateTryApiTaskReq, reply *apis.ManagementUpdateTryApiTaskReply) (err error) {
  10. o := orm.NewOrm()
  11. if req.Status == 3 {
  12. // 当状态为进行中,修改状态为正在暂停
  13. sql := "update t_gd_try_api_task set status=?, updated_at=? where id=? and status = ?"
  14. _, err = o.Raw(sql, req.Status, time.Now().Format("2006-01-02 15:04:05"), req.TaskId, 0).Exec()
  15. if err != nil {
  16. return errors.DataBaseError
  17. }
  18. return nil
  19. }
  20. if req.DownloadFile == "" {
  21. sql := "update t_gd_try_api_task set status=?, err_msg=?, updated_at=? where id=?"
  22. _, err = o.Raw(sql, req.Status, req.ErrMsg, time.Now().Format("2006-01-02 15:04:05"), req.TaskId).Exec()
  23. if err != nil {
  24. return errors.DataBaseError
  25. }
  26. } else {
  27. sql := "update t_gd_try_api_task set status=?, err_msg=?, download_file=?, updated_at=? where id=?"
  28. _, err = o.Raw(sql, req.Status, req.ErrMsg, req.DownloadFile, time.Now().Format("2006-01-02 15:04:05"), req.TaskId).Exec()
  29. if err != nil {
  30. return errors.DataBaseError
  31. }
  32. }
  33. return nil
  34. }