Пример #1
0
        public long GetCountByTime(HTargetQuery mTargetQuery)
        {
            var builder = Builders <TargetInfo> .Filter;

            var filter = builder.Gt("PassTime", new BsonDateTime(Convert.ToDateTime(mTargetQuery.timeStart))) &
                         builder.Lt("PassTime", new BsonDateTime(Convert.ToDateTime(mTargetQuery.timeEnd)));

            if (!string.IsNullOrEmpty(mTargetQuery.queryCameraId))
            {
                string[] cameraIdArray = mTargetQuery.queryCameraId.Replace("'", "").Split(',');
                filter = filter & builder.In("CameraID", cameraIdArray);
            }
            if (!string.IsNullOrEmpty(mTargetQuery.queryMblx))
            {
                filter = filter & builder.Eq("TargetType", mTargetQuery.queryMblx);
                if ((HTargetQuery.HUMAN & Convert.ToInt64(mTargetQuery.queryMblx)) > 0)
                {
                    if (!string.IsNullOrEmpty(mTargetQuery.queryUpperColor))
                    {
                        string[] upper_color = mTargetQuery.queryUpperColor.Split(',');
                        filter = filter & (builder.In("HumanInfo.UpperBodyColor.MainColorCode", upper_color));
                    }
                    if (!string.IsNullOrEmpty(mTargetQuery.queryLowerColor))
                    {
                        string[] lower_color = mTargetQuery.queryLowerColor.Split(',');
                        filter = filter & (builder.In("HumanInfo.UpperBodyColor.MainColorCode", lower_color));
                    }
                }
                if ((HTargetQuery.VEHC & Convert.ToInt64(mTargetQuery.queryMblx)) > 0)
                {
                    if (!string.IsNullOrEmpty(mTargetQuery.queryCphm))
                    {
                        filter = filter & builder.Regex("VehicleInfo.PlateLicence", new BsonRegularExpression(mTargetQuery.queryCphm));
                    }
                    if (!string.IsNullOrEmpty(mTargetQuery.queryClys))
                    {
                        string[] vehicle_color = mTargetQuery.queryClys.Split(',');
                        filter = filter & builder.In("VehicleInfo.MainColorCode", vehicle_color);
                    }
                }
                if ((HTargetQuery.OTHER & Convert.ToInt64(mTargetQuery.queryMblx)) > 0)
                {
                    if (!string.IsNullOrEmpty(mTargetQuery.queryUpperColor))
                    {
                        string[] upper_color = mTargetQuery.queryUpperColor.Split(',');
                        filter = filter & (builder.In("OtherInfo.UpperBodyColor.MainColorCode", upper_color));
                    }
                    if (!string.IsNullOrEmpty(mTargetQuery.queryLowerColor))
                    {
                        string[] lower_color = mTargetQuery.queryLowerColor.Split(',');
                        filter = filter & (builder.In("OtherInfo.LowerBodyColor.MainColorCode", lower_color));
                    }
                }
            }
            else
            {
                if (mTargetQuery.bQueryVehicle)
                {
                    if (!string.IsNullOrEmpty(mTargetQuery.queryCphm))
                    {
                        filter = filter & builder.Regex("VehicleInfo.PlateLicence", new BsonRegularExpression(mTargetQuery.queryCphm));
                    }
                    if (!string.IsNullOrEmpty(mTargetQuery.queryClys))
                    {
                        string[] vehicle_color = mTargetQuery.queryClys.Split(',');
                        filter = filter & builder.In("VehicleInfo.MainColorCode", vehicle_color);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(mTargetQuery.queryUpperColor))
                    {
                        string[] upper_color = mTargetQuery.queryUpperColor.Split(',');
                        filter = filter & (builder.In("OtherInfo.UpperBodyColor.MainColorCode", upper_color) | builder.In("HumanInfo.UpperBodyColor.MainColorCode", upper_color));
                    }
                    if (!string.IsNullOrEmpty(mTargetQuery.queryLowerColor))
                    {
                        string[] lower_color = mTargetQuery.queryLowerColor.Split(',');
                        filter = filter & (builder.In("OtherInfo.LowerBodyColor.MainColorCode", lower_color) | builder.In("HumanInfo.UpperBodyColor.MainColorCode", lower_color));
                    }
                }
            }

            return(mTargetCollection.Count(filter));
        }
Пример #2
0
        public List <TargetInfo> GetTargetByTime(HTargetQuery mTargetQuery)
        {
            try
            {
                Stopwatch sw1     = new Stopwatch();
                var       builder = Builders <TargetInfo> .Filter;

                var filter = builder.Gt("PassTime", new BsonDateTime(Convert.ToDateTime(mTargetQuery.timeStart))) &
                             builder.Lt("PassTime", new BsonDateTime(Convert.ToDateTime(mTargetQuery.timeEnd)));
                if (!string.IsNullOrEmpty(mTargetQuery.queryCameraId))
                {
                    string[] cameraIdArray = mTargetQuery.queryCameraId.Replace("'", "").Split(',');
                    filter = filter & builder.In("CameraID", cameraIdArray);
                }

                if (!string.IsNullOrEmpty(mTargetQuery.queryMblx))
                {
                    filter = filter & builder.Eq("TargetType", mTargetQuery.queryMblx);
                    if ((HTargetQuery.HUMAN & Convert.ToInt64(mTargetQuery.queryMblx)) > 0)
                    {
                        if (!string.IsNullOrEmpty(mTargetQuery.queryUpperColor))
                        {
                            string[] upper_color = mTargetQuery.queryUpperColor.Split(',');
                            filter = filter & (builder.In("HumanInfo.UpperBodyColor.MainColorCode", upper_color));
                        }
                        if (!string.IsNullOrEmpty(mTargetQuery.queryLowerColor))
                        {
                            string[] lower_color = mTargetQuery.queryLowerColor.Split(',');
                            filter = filter & (builder.In("HumanInfo.LowerBodyColor.MainColorCode", lower_color));
                        }
                    }
                    if ((HTargetQuery.VEHC & Convert.ToInt64(mTargetQuery.queryMblx)) > 0)
                    {
                        if (!string.IsNullOrEmpty(mTargetQuery.queryCphm))
                        {
                            filter = filter & builder.Regex("VehicleInfo.PlateLicence", new BsonRegularExpression(mTargetQuery.queryCphm));
                        }
                        if (!string.IsNullOrEmpty(mTargetQuery.queryClys))
                        {
                            string[] vehicle_color = mTargetQuery.queryClys.Split(',');
                            filter = filter & builder.In("VehicleInfo.MainColorCode", vehicle_color);
                        }
                    }
                    if ((HTargetQuery.OTHER & Convert.ToInt64(mTargetQuery.queryMblx)) > 0)
                    {
                        if (!string.IsNullOrEmpty(mTargetQuery.queryUpperColor))
                        {
                            string[] upper_color = mTargetQuery.queryUpperColor.Split(',');
                            filter = filter & (builder.In("OtherInfo.UpperBodyColor.MainColorCode", upper_color));
                        }
                        if (!string.IsNullOrEmpty(mTargetQuery.queryLowerColor))
                        {
                            string[] lower_color = mTargetQuery.queryLowerColor.Split(',');
                            filter = filter & (builder.In("OtherInfo.LowerBodyColor.MainColorCode", lower_color));
                        }
                    }
                }
                else
                {
                    if (mTargetQuery.bQueryVehicle)
                    {
                        if (!string.IsNullOrEmpty(mTargetQuery.queryCphm))
                        {
                            filter = filter & builder.Regex("VehicleInfo.PlateLicence", new BsonRegularExpression(mTargetQuery.queryCphm));
                        }
                        if (!string.IsNullOrEmpty(mTargetQuery.queryClys))
                        {
                            string[] vehicle_color = mTargetQuery.queryClys.Split(',');
                            filter = filter & builder.In("VehicleInfo.MainColorCode", vehicle_color);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(mTargetQuery.queryUpperColor))
                        {
                            string[] upper_color = mTargetQuery.queryUpperColor.Split(',');
                            filter = filter & (builder.In("OtherInfo.UpperBodyColor.MainColorCode", upper_color) | builder.In("HumanInfo.UpperBodyColor.MainColorCode", upper_color));
                        }
                        if (!string.IsNullOrEmpty(mTargetQuery.queryLowerColor))
                        {
                            string[] lower_color = mTargetQuery.queryLowerColor.Split(',');
                            filter = filter & (builder.In("OtherInfo.LowerBodyColor.MainColorCode", lower_color) | builder.In("HumanInfo.LowerBodyColor.MainColorCode", lower_color));
                        }
                    }
                }

                var sort = Builders <TargetInfo> .Sort.Descending("PassTime");

                sw1.Start();

                var cursor = mTargetCollection.Find(filter).Sort(sort).Skip((mTargetQuery.PageNumber - 1) * mTargetQuery.PageSize).Limit(mTargetQuery.PageSize).ToList();
                sw1.Stop();
                Console.WriteLine("方式分页耗时:{0},{1}", sw1.ElapsedMilliseconds, cursor.Count);
                return(cursor);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(null);
        }