// 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 SystemLog(ctx context.Context, req *v1.SystemLogRequest) (reply *v1.SystemLogReply, err error) { p := &model.TCompanyLog{} if req.Page == 0 { req.Page = 1 } if req.PageSize == 0 { req.PageSize = 10 } reply = &v1.SystemLogReply{} reply.Page = req.PageSize where := map[string]interface{}{} if req.Cid > 0 { where["cid"] = req.Cid } if req.GardenId > 0 { where["garden_id"] = req.GardenId } 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.SystemLogItem, len(list)) for i, v := range list { reply.List[i] = &v1.SystemLogItem{ Uid:v.Uid, Username:v.Username, Cid:v.Cid, 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 }