public IHttpActionResult QuerySystemLog(SystemLogSearchModel search) { try { if (search == null) { return(BadRequest()); } if (search.PageIndex == 0) { search.PageIndex = 1; } if (search.PageSize == 0) { search.PageSize = 20; } if (!UserController.LoginDictionary.ContainsKey(GetCookie("token"))) { return(Logout()); } UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")]; if (userCookie == null) { return(Logout()); } List <Department> departList = Department.GetAllChildren(userCookie.DepartmentID); var result = SystemLog.GetSystemLogs(search, departList.Select(m => m.ID).ToList()); if (result.Items.Count > 0) { var list = Department.GetAll(result.Items.ToList().Select(m => m.ID).ToList()); result.Items.ForEach(item => { item.DepartmentName = list.Find(m => m.ID == item.DepartmentID)?.Name; }); } return(Success(result)); } catch (Exception ex) { logger.Error(ex); return(Failure("查询失败")); } }
public static Page <SystemLogA> GetSystemLogs(SystemLogSearchModel search, List <int> departList) { var sql = "select * from SystemLog where DepartmentID in @DepartmentID"; if (!string.IsNullOrEmpty(search.UserName)) { sql += " and UserName like '%" + search.UserName + "%'"; } if (!string.IsNullOrEmpty(search.StartTime)) { sql += " and CreateTime >= '" + search.StartTime + "'"; } if (!string.IsNullOrEmpty(search.EndTime)) { sql += " and CreateTime <= '" + search.EndTime + "'"; } sql += " order by CreateTime desc"; using (var cn = Database.GetDbConnection()) { return(cn.PagedQuery <SystemLogA>(search.PageIndex, search.PageSize, sql, new { DepartmentID = departList })); } }