// Copyright 2017 utimes.cc. All rights reserved. // Use of this source code is governed by utimes.cc. package action import ( "gd_admin/apis" "gd_admin/errors" "gd_admin/impl/dbmodel" "encoding/json" "fmt" "gd_admin/common.in/jsonrpc2" "gd_admin/common.in/utils" "github.com/astaxie/beego/orm" "go.uber.org/zap" "golang.org/x/net/context" ) func Add(ctx context.Context, req *apis.AddActionLogReq, reply *apis.AddActionLogReply) (err error) { // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err := fmt.Errorf("%+v", r) e := &jsonrpc2.Error{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { l.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() if req.Uid <= 0 || req.Modules == "" || req.Func == "" || req.ModifyTime == "" { return errors.ArgsError } p := dbmodel.Action{ Uid: req.Uid, Name: req.Name, Modules: req.Modules, Func: req.Func, Before: req.Before, After: req.Content, CreatedAt: req.ModifyTime, } if _, err := p.Create(orm.NewOrm()); err != nil { l.Error("mysql", zap.String("sql", fmt.Sprintf("INSET %s", p.TableName())), zap.String("fields", utils.MarshalJsonString(p)), zap.String("error", err.Error())) return errors.DataBaseError } return nil }