h5_api_add.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package h5
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/common.in/utils"
  6. "go.uber.org/zap"
  7. "github.com/astaxie/beego/orm"
  8. "gd_management/errors"
  9. "time"
  10. "gd_management/common.in/storage"
  11. )
  12. func addH5Api(req *apis.ManagementAddH5ApiReq) (int64, error) {
  13. var ret int64
  14. if req.Name == "" || req.Host == "" || req.Router == ""{
  15. return 0, errors.ArgsError
  16. }
  17. task := func(o orm.Ormer) error {
  18. if o.QueryTable("t_gd_h5_api").Filter("host", req.Host).Filter("router", req.Router).Exist() {
  19. return errors.DataApiExist
  20. }
  21. tab := apis.TGdH5Api{}
  22. tab.Name = req.Name
  23. tab.Host = req.Host
  24. tab.Router = req.Router
  25. tab.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  26. tab.UpdateTime = tab.CreateTime
  27. tab.IsEnable = true
  28. id, err := o.Insert(&tab)
  29. ret = id
  30. if err != nil {
  31. return errors.DataBaseError
  32. }
  33. return nil
  34. }
  35. tasks := []storage.DbaTasker{}
  36. tasks = append(tasks, storage.GenerateDbaTask(task))
  37. storage.ExecTrans(tasks...)
  38. return ret, nil
  39. }
  40. func ManagementAddH5Api(ctx context.Context, req *apis.ManagementAddH5ApiReq, reply *apis.ManagementAddH5ApiReply) (err error) {
  41. reply.H5ApiId, err = addH5Api(req)
  42. if err != nil {
  43. l.Error("func",
  44. zap.String("call", "ManagementAddH5Api"),
  45. zap.String("args", utils.MarshalJsonString(req)),
  46. zap.String("error", err.Error()))
  47. }
  48. l.Debug(utils.MarshalJsonString(req, reply))
  49. return
  50. }