Example #1
0
 /// <summary>
 /// 对象删除 的日志
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="user"></param>
 /// <param name="tag"></param>
 /// <param name="t"></param>
 /// <param name="ip"></param>
 public async Task RemoveLogAsync <T>(CurrentUser curUser, string tag, T t) where T : class, new()
 {
     OperateLog log = new OperateLog
     {
         Tag        = tag,
         Content    = ObjectToStr(t),
         Operator   = curUser.RealName,
         OperatorId = curUser.Id,
         IP         = curUser.LoginIPAddress
     };
     await OperateLogRep.AddAsync(log);
 }
Example #2
0
        /// <summary>
        /// 对象添加 的日志
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="user"></param>
        /// <param name="tag"></param>
        /// <param name="t"></param>
        /// <param name="ip"></param>
        public async Task InsertLogAsync <T>(CurrentUser curUser, string tag, T t) where T : class, new()
        {
            OperateLog log = new OperateLog
            {
                Tag        = tag,
                Content    = ObjectToStr(t, "UpdatePerson,UpdateDate"),
                Operator   = curUser.RealName,
                OperatorId = curUser.Id,
                IP         = curUser.LoginIPAddress
            };

            log.Id = log.CreateId();
            await OperateLogRep.AddAsync(log);
        }
Example #3
0
        /// <summary>
        /// 对象编辑 的日志
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="user"></param>
        /// <param name="tag"></param>
        /// <param name="ip"></param>
        /// <param name="before"></param>
        /// <param name="after"></param>
        public async Task EditLogAsync <T>(CurrentUser curUser, string tag, T before, T after) where T : class, new()
        {
            OperateLog log = new OperateLog
            {
                Tag        = tag,
                Content    = ObjectEquals(before, after, "CreatePerson,CreateDate,UpdatePerson,UpdateDate"),
                Operator   = curUser.RealName,
                OperatorId = curUser.Id,
                IP         = curUser.LoginIPAddress
            };

            if (!string.IsNullOrEmpty(log.Content))
            {
                await OperateLogRep.AddAsync(log);
            }
        }
        /// <summary>
        /// 自定义 日志内容
        /// </summary>
        /// <param name="uinfo"></param>
        /// <param name="tag"></param>
        /// <param name="content"></param>
        public async Task CustomLogAsync(CurrentUser curUser, string tag, string content)
        {
            OperateLog log = new OperateLog
            {
                Tag        = tag,
                Content    = content,
                Operator   = curUser.RealName,
                OperatorId = curUser.Id,
                IP         = curUser.LoginIPAddress
            };

            if (!string.IsNullOrWhiteSpace(content))
            {
                await OperateLogRep.AddAsync(log);
            }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="rowsPrePage"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public async Task <PageResult <OperateLogDto> > GetPageAsync(int pageNumber, int rowsPrePage, OperateLogOption option)
        {
            List <OperateLogDto>       data = new List <OperateLogDto>();
            PageResult <OperateLogDto> list = new PageResult <OperateLogDto>();
            string orderby   = " id desc";
            var    predicate = PredicateBuilder.True <OperateLog>();

            if (option.StartDateTime != null)
            {
                predicate = predicate.And(o => o.CreateTime >= option.StartDateTime.Value);
            }
            if (option.EndDateTime != null)
            {
                predicate = predicate.And(o => o.CreateTime <= option.EndDateTime.Value);
            }
            if (!string.IsNullOrWhiteSpace(option.Tag))
            {
                predicate = predicate.And(o => o.Tag == option.Tag);
            }
            var tlist = await OperateLogRep.Find(pageNumber, rowsPrePage, orderby, predicate).ToListAsync();

            data = tlist.ToList().MapToList <OperateLogDto>();
            if (data != null && data.Count > 0)
            {
                var operatorIds = data.Select(o => o.OperatorId).ToList();
                var userlist    = await UserRep.Find(o => operatorIds.Contains(o.Id)).ToListAsync();

                int i = 0;
                foreach (var item in data)
                {
                    long oid   = item.OperatorId;
                    var  uname = userlist.FirstOrDefault(o => o.Id == oid);
                    data[i].OperatorName = uname?.RealName ?? "";
                    i++;
                }
            }
            list.Data = data.ToList();
            int total = await OperateLogRep.GetCountAsync(predicate);

            list.ItemCount = total;
            return(list);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        public async Task <Page <OperateLogDto> > PagerAsync(OperateLogOption option)
        {
            var predicate = PredicateBuilder.True <OperateLog>();

            if (option.StartDateTime != null && option.StartDateTime.HasValue)
            {
                predicate = predicate.And(o => o.CreateTime >= option.StartDateTime.Value);
            }
            if (option.EndDateTime != null && option.EndDateTime.HasValue)
            {
                predicate = predicate.And(o => o.CreateTime <= option.EndDateTime.Value);
            }
            if (!string.IsNullOrWhiteSpace(option.Tag))
            {
                predicate = predicate.And(o => o.Tag == option.Tag);
            }
            List <OperateLogDto> data = new List <OperateLogDto>();
            int total = await OperateLogRep.GetCountAsync(predicate);

            if (total > 0)
            {
                IEnumerable <OperateLog> result = (await OperateLogRep.Find(option.PageIndex, option.Limit, option.OrderBy, predicate).ToListAsync());
                data = AutoMapperExt.MapToList <OperateLog, OperateLogDto>(result.ToList());
                if (data != null && data.Count > 0)
                {
                    var list     = data.Select(o => o.OperatorId).ToList();
                    var userlist = await UserRep.Find(o => list.Contains(o.Id)).ToListAsync();

                    int i = 0;
                    foreach (var item in data)
                    {
                        long oid   = item.OperatorId;
                        var  uname = userlist.Where(o => o.Id == oid).FirstOrDefault();
                        data[i].OperatorName = uname?.RealName ?? "";
                        i++;
                    }
                }
            }
            return(new Page <OperateLogDto>(total, data));
        }