12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package h5
- import (
- "context"
- "gd_management/apis"
- "gd_management/common.in/utils"
- "go.uber.org/zap"
- "github.com/astaxie/beego/orm"
- "gd_management/errors"
- "time"
- "gd_management/common.in/storage"
- )
- func addH5Api(req *apis.ManagementAddH5ApiReq) (int64, error) {
- var ret int64
- if req.Name == "" || req.Host == "" || req.Router == ""{
- return 0, errors.ArgsError
- }
- task := func(o orm.Ormer) error {
- if o.QueryTable("t_gd_h5_api").Filter("host", req.Host).Filter("router", req.Router).Exist() {
- return errors.DataApiExist
- }
- tab := apis.TGdH5Api{}
- tab.Name = req.Name
- tab.Host = req.Host
- tab.Router = req.Router
- tab.CreateTime = time.Now().Format("2006-01-02 15:04:05")
- tab.UpdateTime = tab.CreateTime
- tab.IsEnable = true
- id, err := o.Insert(&tab)
- ret = id
- if err != nil {
- return errors.DataBaseError
- }
- return nil
- }
- tasks := []storage.DbaTasker{}
- tasks = append(tasks, storage.GenerateDbaTask(task))
- storage.ExecTrans(tasks...)
- return ret, nil
- }
- func ManagementAddH5Api(ctx context.Context, req *apis.ManagementAddH5ApiReq, reply *apis.ManagementAddH5ApiReply) (err error) {
- reply.H5ApiId, err = addH5Api(req)
- if err != nil {
- l.Error("func",
- zap.String("call", "ManagementAddH5Api"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- }
- l.Debug(utils.MarshalJsonString(req, reply))
- return
- }
|