Exemplo n.º 1
0
        public static Page <CabinetA> GetCabinets(CabinetSearchModel search, List <int> departList)
        {
            var sql = "select * from Cabinet where DepartmentID in @DepartmentID ";

            if (!string.IsNullOrEmpty(search.CabinetName))
            {
                sql += " and Name like '%" + search.CabinetName + "%'";
            }

            if (search.CabinetCode != null)
            {
                sql += " and Code like '%" + search.CabinetCode + "%'";
            }
            using (var cn = Database.GetDbConnection())
            {
                return(cn.PagedQuery <CabinetA>(search.PageIndex, search.PageSize, sql, new { DepartmentID = departList }));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult QueryCabinet(CabinetSearchModel search)
        {
            try
            {
                if (search == null)
                {
                    return(BadRequest());
                }
                if (search.PageIndex == 0)
                {
                    search.PageIndex = 1;
                }
                if (search.PageSize == 0)
                {
                    search.PageSize = 20;
                }
                _logger.Info(JsonConvert.SerializeObject(UserController.LoginDictionary));
                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }

                //更新保险柜状态
                //var cabinetList = Cabinet.GetAll().FindAll(m => (m.Status == 1 || m.Status == 4));
                //foreach (var m in cabinetList)
                //{
                //    var log = CabinetLog.GetOpenLog(m.ID);
                //    if (log == null || log.CreateTime.AddSeconds(60) < DateTime.Now)
                //    {
                //        m.Status = 3;
                //        Cabinet.Update(m);
                //        _logger.Info("自动重置关闭");
                //    }
                //}

                List <Department> departList = Department.GetAllChildren(userCookie.DepartmentID);
                if (!string.IsNullOrEmpty(search.DepartmentName))
                {
                    departList = departList.FindAll(m => m.Name.Contains(search.DepartmentName));
                }
                var result = Cabinet.GetCabinets(search, departList.Select(m => m.ID).ToList());
                if (result.Items.Count > 0)
                {
                    var depart = Department.GetAll(result.Items.Select(m => m.DepartmentID).ToList());
                    result.Items.ForEach(m =>
                    {
                        m.DepartmentName        = depart.Find(n => n.ID == m.DepartmentID)?.Name;
                        m.FirstContactPassword  = string.IsNullOrEmpty(m.FirstContactPassword) ? "" : AESAlgorithm.Decrypto(m.FirstContactPassword);
                        m.SecondContactPassword = string.IsNullOrEmpty(m.SecondContactPassword) ? "" : AESAlgorithm.Decrypto(m.SecondContactPassword);
                    });
                }
                return(Success(result));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(Failure("查询失败"));
            }
        }