示例#1
0
        public IEnumerable <CabinetModel> Page(string orgId, string name, int page, int size, out int count)
        {
            using (var cabinetHandler = new CabinetHandle(Repository))
                using (var orgHandler = new OrganizationHandle(Repository))
                    using (var officerHandler = new OfficerHandle(Repository))
                        using (var siteHandler = new SiteHandle(Repository))
                        {
                            var noDel = (short)DeleteStatus.No;
                            var query =
                                from cab in cabinetHandler.All(t => t.IsDel == noDel)
                                join org in orgHandler.All(t => t.IsDel == noDel) on cab.OrgId equals org.Id
                                join officer in officerHandler.All(t => t.IsDel == noDel) on cab.OfficerId equals officer.Id into officers
                                from off in officers.DefaultIfEmpty(new Officer {
                            })
                                join site in siteHandler.All(t => t.IsDel == noDel) on cab.StationId equals site.Id into sites
                                from sta in sites.DefaultIfEmpty(new Station {
                            })
                                select new { cab = cab, org = org, officer = off, sta = sta };

                            if (!string.IsNullOrWhiteSpace(name))
                            {
                                query = query.Where(t => t.cab.Name.Contains(name));
                            }

                            if (!string.IsNullOrWhiteSpace(orgId))
                            {
                                query = query.Where(t => t.cab.OrgId == orgId);
                            }

                            if (string.IsNullOrWhiteSpace(orgId) && !User.IsSupperAdministrator)
                            {
                                var code = User.Organization.Code;
                                query = query.Where(t => t.org.Code.StartsWith(code));
                            }

                            count = query.Count();
                            var skipCount = (page - 1) * size;
                            var items     = query.OrderBy(t => t.sta.OrgId).Skip(skipCount).Take(size).ToArray()
                                            .Select(t => new CabinetModel
                            {
                                officer = t.officer,
                                org     = t.org,
                                cabinet = t.cab
                            });
                            return(items);
                        }
        }
        public IEnumerable <EquipmentModel> Page(string orgId, string storageId, string cabinetId,
                                                 string tagCode, string factorCode, short dataType, int page, int size, out int count)
        {
            using (var eqtHandler = new EquipmentHandle(Repository))
                using (var cateHandler = new EqtTypeHandle(Repository))
                    using (var stgHandler = new StorageHandle(Repository))
                        using (var cabHandler = new CabinetHandle(Repository))
                            using (var orgHandler = new OrganizationHandle(Repository))
                                using (var offHandler = new OfficerHandle(Repository))
                                {
                                    var noDel = (short)DeleteStatus.No;
                                    var query =
                                        from eqt in eqtHandler.All(t => t.IsDel == noDel)
                                        join org in orgHandler.All(t => t.IsDel == noDel) on eqt.OrgId equals org.Id
                                        join cate in cateHandler.All(t => t.IsDel == noDel) on eqt.CateId equals cate.Id
                                        join stg in stgHandler.All(t => t.IsDel == noDel) on eqt.LibId equals stg.Id
                                        join cabitem in cabHandler.All(t => t.IsDel == noDel) on eqt.CabId equals cabitem.Id into cabs
                                        from cab in cabs.DefaultIfEmpty(new Cabinet {
                                    })
                                        join offitem in offHandler.All(t => t.IsDel == noDel) on eqt.OfficerId equals offitem.Id into offs
                                        from off in offs.DefaultIfEmpty(new Officer {
                                    })
                                        select new { eqt = eqt, org = org, cate = cate, stg = stg, cab = cab, officer = off };

                                    if (!string.IsNullOrWhiteSpace(storageId))
                                    {
                                        query = query.Where(t => t.eqt.LibId == storageId);
                                    }

                                    if (!string.IsNullOrWhiteSpace(cabinetId))
                                    {
                                        query = query.Where(t => t.eqt.CabId == cabinetId);
                                    }

                                    if (!string.IsNullOrWhiteSpace(tagCode))
                                    {
                                        query = query.Where(t => t.eqt.TagId.Contains(tagCode));
                                    }

                                    if (!string.IsNullOrWhiteSpace(factorCode))
                                    {
                                        query = query.Where(t => t.eqt.FactorCode.Contains(factorCode));
                                    }

                                    if (!string.IsNullOrWhiteSpace(orgId))
                                    {
                                        query = query.Where(t => t.eqt.OrgId == orgId);
                                    }

                                    if (string.IsNullOrWhiteSpace(orgId) && !User.IsSupperAdministrator)
                                    {
                                        orgId = User.Organization.Id;
                                        query = query.Where(t => t.eqt.OrgId == orgId);
                                    }

                                    var dispatchStatus = 0;
                                    // 布控中
                                    if (dataType == (short)QueryEqtDataType.Dispatching)
                                    {
                                        dispatchStatus = (short)DispatchedStatus.Doing;
                                        query          = query.Where(t => t.eqt.Dispatched == dispatchStatus);
                                    }

                                    // 撤控
                                    if (dataType == (short)QueryEqtDataType.Dispatched)
                                    {
                                        dispatchStatus = (short)DispatchedStatus.Done;
                                        query          = query.Where(t => t.eqt.Dispatched == dispatchStatus);
                                    }

                                    var now = DateTime.Now.ToUnixTime();
                                    // 已过期
                                    if (dataType == (short)QueryEqtDataType.Expired)
                                    {
                                        query = query.Where(t => t.eqt.ExpiredTime <= now);
                                    }

                                    // 即将过期
                                    if (dataType == (short)QueryEqtDataType.PreExpired)
                                    {
                                        var preDate = DateTime.Now.AddDays(PreExpiredInterval).ToUnixTime();
                                        query = query.Where(t => t.eqt.ExpiredTime >= preDate && t.eqt.ExpiredTime < now);
                                    }

                                    // 尚未过期
                                    if (dataType == (short)QueryEqtDataType.NoExpired)
                                    {
                                        query = query.Where(t => t.eqt.ExpiredTime >= now);
                                    }

                                    // 绑定警员
                                    if (dataType == (short)QueryEqtDataType.Bound)
                                    {
                                        query = query.Where(t => t.eqt.OfficerId != null);
                                    }

                                    // 已损坏
                                    if (dataType == (short)QueryEqtDataType.Destoried)
                                    {
                                        var sta = (short)EquipmentStatus.Destory;
                                        query = query.Where(t => t.eqt.Status == sta);
                                    }

                                    // 低电量
                                    if (dataType == (short)QueryEqtDataType.LowPower)
                                    {
                                        query = query.Where(t => t.eqt.Power <= LowPowerFlag);
                                    }

                                    count = query.Count();
                                    var skipCount = (page - 1) * size;
                                    var items     =
                                        query.OrderByDescending(t => t.eqt.InputTime).Skip(skipCount).Take(size).ToArray()
                                        .Select(t => new EquipmentModel
                                    {
                                        cabinet   = t.cab,
                                        category  = t.cate,
                                        equipment = t.eqt,
                                        officer   = t.officer,
                                        org       = t.org,
                                        storage   = t.stg
                                    });
                                    return(items);
                                }
        }