Example #1
0
        public static Page <CabinetLogA> GetCabinets(CabinetLogSearchModel search, List <int> departList)
        {
            var sql = "select * from CabinetLog where DepartmentID in @DepartmentID ";

            if ((search.CabinetID ?? 0) > 0)
            {
                sql += " and CabinetID = " + search.CabinetID;
            }
            if (!string.IsNullOrEmpty(search.CabinetName))
            {
                List <Cabinet> cabinets = Cabinet.GetByLikeName(search.CabinetName);
                if (cabinets.Count == 0)
                {
                    sql += " and 1=2 ";
                }
                else
                {
                    sql += " and CabinetID in (" + string.Join(",", cabinets.Select(m => m.ID).ToList()) + ")";
                }
            }
            if (!string.IsNullOrEmpty(search.OperatorType))
            {
                sql += " and OperationType = " + search.OperatorType;
            }

            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 <CabinetLogA>(search.PageIndex, search.PageSize, sql, new { DepartmentID = departList }));
            }
        }
Example #2
0
 public IHttpActionResult QueryCabinetLog(CabinetLogSearchModel 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 = new List <Department>();
         if ((search.DepartmentID ?? 0) != 0)
         {
             departList = Department.GetAllChildren(search.DepartmentID.Value);
         }
         else
         {
             departList = Department.GetAllChildren(userCookie.DepartmentID);
         }
         var result = CabinetLog.GetCabinets(search, departList.Select(m => m.ID).ToList());
         if (result.Items.Count > 0)
         {
             var cabinet = Cabinet.GetCabinetByIds(result.Items.Select(m => m.CabinetID).ToList());
             var depart  = Department.GetAll(result.Items.Select(m => m.DepartmentID ?? 0).ToList());
             result.Items.ForEach(m =>
             {
                 m.OperationType  = m.OperationType;
                 m.CabinetName    = cabinet.Find(n => n.ID == m.CabinetID)?.Name;
                 m.DepartmentName = depart.Find(n => n.ID == m.DepartmentID)?.Name;
                 m.CabinetCode    = cabinet.Find(n => n.ID == m.CabinetID)?.Code;
                 if (!string.IsNullOrEmpty(m.EventContent) && m.EventContent.ToLower().Contains("photos"))
                 {
                     //有事件
                     CommandRequest req = JsonConvert.DeserializeObject <CommandRequest>(m.EventContent);
                     if (req != null && req.Photos != null && req.Photos.Count > 0)
                     {
                         for (int i = 0; i < req.Photos.Count; i++)
                         {
                             req.Photos[i] = ImgToBase64String(req.Photos[i]);
                         }
                         m.EventContent = JsonConvert.SerializeObject(req);
                     }
                 }
             });
         }
         return(Success(result));
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         return(Failure("查询失败"));
     }
 }