// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package log import ( "context" "git.getensh.com/common/gopkgs/database" "property-log/model" "property-log/pb/v1" "time" "property-log/errors" ) func ManagementLog(ctx context.Context, req *v1.ManagementLogRequest) (reply *v1.ManagementLogReply, err error) { p := &model.TManagementLog{} if req.Page == 0 { req.Page = 1 } if req.PageSize == 0 { req.PageSize = 10 } reply = &v1.ManagementLogReply{} reply.Page = req.PageSize where := map[string]interface{}{} if req.Start > 0 { where["created_at >="] = time.Unix(req.Start, 0) } if req.End > 0 { where["created_at <"] = time.Unix(req.End, 0) } reply.Total, err = p.Count(database.DB(), where, nil) if err != nil { return nil, errors.DataBaseError } if reply.Total == 0 { return reply, nil } list, err := p.List(database.DB(), where, nil, int(req.Page), int(req.PageSize)) if err != nil { return nil, errors.DataBaseError } reply.List = make([]*v1.ManagementLogItem, len(list)) for i, v := range list { reply.List[i] = &v1.ManagementLogItem{ Uid:v.Uid, Username:v.Username, Origin:v.Origin, Target:v.Target, Action:v.Action, Module:v.Module, CreatedAt:v.CreatedAt.Format("2006-01-02 15:04:05"), } } return reply, nil }