1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package access_log
- import (
- "context"
- "gd_access_log/apis"
- "gd_access_log/errors"
- "gd_access_log/impl/dbmodel"
- "fmt"
- "time"
- "gd_access_log/common.in/utils"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- )
- func LogCallbackIn(ctx context.Context, req *apis.LogCallbackInReq, reply *apis.LogCallbackInReply) (err error) {
- // 参数检查
- if req.ServiceType == 0 || req.SourceName == "" {
- return errors.ArgsError
- }
- // 模型数据填充
- cr := dbmodel.CallbackIn{
- ServiceType: req.ServiceType,
- SourceName: req.SourceName,
- SourceObjectId: req.SourceObjectId,
- RequestCode: req.RequestCode,
- RequestParams: req.RequestParams,
- ResponseParams: req.ResponseParams,
- Elapsed: req.Elapsed,
- AddTime: time.Now().Unix(),
- }
- // 创建一条记录
- if _, err := cr.Create(orm.NewOrm()); err != nil {
- l.Error("mysql",
- zap.String("sql", fmt.Sprintf("INSERT INTO %s", cr.TableName())),
- zap.String("fields", utils.MarshalJsonString(cr)),
- zap.String("error", err.Error()))
- return err
- }
- return nil
- }
- func LogCallbackOut(ctx context.Context, req *apis.LogCallbackOutReq, reply *apis.LogCallbackOutReply) (err error) {
- // 参数检查
- if req.ServiceType == 0 || req.MerchantId == 0 {
- return errors.ArgsError
- }
- // 模型数据填充
- cs := dbmodel.CallbackOut{
- ServiceType: req.ServiceType,
- MerchantId: req.MerchantId,
- ObjectId: req.ObjectId,
- RequestCode: req.RequestCode,
- RequestParams: req.RequestParams,
- ResponseParams: req.ResponseParams,
- Elapsed: req.Elapsed,
- AddTime: time.Now().Unix(),
- IsReuse: req.IsReuse,
- Search: req.Search,
- }
- // 创建一条记录
- if _, err := cs.Create(orm.NewOrm()); err != nil {
- l.Error("mysql",
- zap.String("sql", fmt.Sprintf("INSERT INTO %s", cs.TableName())),
- zap.String("fields", utils.MarshalJsonString(cs)),
- zap.String("error", err.Error()))
- return err
- }
- return nil
- }
|