// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package log import ( "context" "cp-organization-management/errors" dbmodel "cp-organization-management/model" pb_v1 "cp-organization-management/pb/v1" "cp-organization-management/utils" "encoding/json" "fmt" "time" "github.com/jaryhe/gopkgs/database" "github.com/jaryhe/gopkgs/logger" "go.uber.org/zap" "google.golang.org/grpc/status" ) // func ManagementLogAdd(ctx context.Context, req *pb_v1.ManagementLogAddRequest) (reply *pb_v1.ManagementLogAddReply, err error) { reply = &pb_v1.ManagementLogAddReply{} // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err = fmt.Errorf("%+v", r) e := &status.Status{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { logger.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() if req.OrganizationCode == "" { return nil, errors.ParamsError } dbname := utils.GetDbName(req.OrganizationCode) p := dbmodel.NewTLog(dbname) p.Uid = req.Uid p.Username = req.Username p.Action = req.Action p.Module = req.Module p.Origin = req.Origin p.Target = req.Target p.CreatedAt = time.Unix(req.CreatedAt, 0) err = p.Insert(database.DB()) if err != nil { return nil, errors.DataBaseError } return &pb_v1.ManagementLogAddReply{}, nil }