protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { try { ApiLog log = new ApiLog(); if (request.Headers.Contains("openid")) { log.openId = request.Headers.GetValues("openid").FirstOrDefault(); } if (request.Headers.Contains("nickname")) { log.nickName = request.Headers.GetValues("nickname").FirstOrDefault(); } log.endpoint = request.RequestUri.ToString(); log.ip = GetClientIpAddress(request); log.client = request.Headers.UserAgent.ToString(); var dao = new ApiLogDao(ConfigurationManager.AppSettings["mysqlConnStr"]); dao.Add(log); } catch (Exception ex) { logger.Error(ex.Message); } return(base.SendAsync(request, cancellationToken)); }
public UserList GetAdminUserList(int pageIndex = 1, int pageSize = 10, string order = "") { var dao = new UserDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var userOpenIds = dao.GetUserOpenIdListByApiLog(pageIndex, pageSize, "and (usertype='普通用户' or usertype is null) "); var count = dao.GetListCount("and (usertype='普通用户' or usertype is null) "); var usersExt = new List <UserExt>(); var apiLogDao = new ApiLogDao(ConfigurationManager.AppSettings["mysqlConnStr"]); userOpenIds.ForEach(openId => { if (!string.IsNullOrEmpty(openId)) { var user = dao.GetUser(openId); var log = apiLogDao.GetByOpenId(user.openId); UserExt userExt = new UserExt(); userExt.id = user.id; userExt.openId = user.openId; userExt.nickName = user.nickName; userExt.province = user.province; userExt.city = user.city; userExt.phone = user.phone; userExt.sex = user.sex; userExt.headpic = user.headpic; userExt.usertype = user.usertype; userExt.note = user.note; userExt.expertise = user.expertise; userExt.verified = user.verified; userExt.displayinapp = user.displayinapp; userExt.detailimage = user.detailimage; userExt.createdAt = user.createdAt; userExt.lastVisitedAt = apiLogDao.GetLastVisitedTime(user.openId); //log.lastVisitedAt; userExt.visitCountLastWeek = apiLogDao.GetLastWeekCount(user.openId); //log.visitCountLastWeek; usersExt.Add(userExt); } }); if (order == "descend") { usersExt = usersExt.OrderByDescending(user => user.lastVisitedAt).ToList(); } else if (order == "ascend") { usersExt = usersExt.OrderBy(user => user.lastVisitedAt).ToList(); } return(new UserList() { list = usersExt, count = count }); }
public VisitLogList GetApiLogList(int pageIndex = 1, int pageSize = 10) { List <VisitLog> logs = new List <VisitLog>(); var dao = new ApiLogDao(ConfigurationManager.AppSettings["mysqlConnStr"]); logs = dao.GetList(pageIndex, pageSize); logs.ForEach(log => { log.visitCountLastWeek = dao.GetLastWeekCount(log.openId); //log.lastVisitedAt = dao.GetLastVisitedTime(log.openId); }); long count = dao.GetListCount(); return(new VisitLogList() { count = count, list = logs }); }