コード例 #1
0
        public IEnumerable <EqtCategory> FeatchAll(string ptpId)
        {
            using (var stdHandler = new StandardEquipmentHandle(Repository))
                using (var cateHandler = new EqtTypeHandle(Repository))
                {
                    var noDel = (short)DeleteStatus.No;
                    var query =
                        from std in stdHandler.All(t => t.IsDel == noDel && t.PtId == ptpId)
                        join cate in cateHandler.All(t => t.IsDel == noDel) on std.CateId equals cate.Id
                        select cate;

                    return
                        (query.ToArray());
                }
        }
コード例 #2
0
        public IEnumerable <PoliceTypeStandardEquipment> FeatchAll(string orgId)
        {
            using (var cateHandler = new EqtTypeHandle(Repository))
                using (var stdHandler = new StandardEquipmentHandle(Repository))
                    using (var orgHandler = new OrganizationHandle(Repository))
                    {
                        var noDel = (short)DeleteStatus.No;
                        var query =
                            from ptp in Handler.All(t => t.IsDel == noDel)
                            join org in orgHandler.All(t => t.IsDel == noDel) on ptp.OrgId equals org.Id
                            join stditem in stdHandler.All(t => t.IsDel == noDel) on ptp.Id equals stditem.PtId into stds
                            from std in stds.DefaultIfEmpty(new StandardEquipment {
                        })
                            join cateitem in cateHandler.All(t => t.IsDel == noDel) on std.CateId equals cateitem.Id into cates
                            from cate in cates.DefaultIfEmpty(new EqtCategory {
                        })
                            select new { ptp = ptp, org = org, std = std, cate = cate };

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

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

                        var items =
                            query.ToArray().GroupBy(t => new { ptpId = t.std.PtId, cateId = t.std.CateId, pk = t.std.IsPrimary, rq = t.std.IsRequire }).Select(
                                t =>
                        {
                            var item     = t.First();
                            item.std.Num = (short)(t.Sum(x => x.std.Num));
                            return(item);
                        }).Select(
                                t => new PoliceTypeStandardEquipment
                        {
                            category  = t.cate,
                            equipment = t.std,
                            org       = t.org,
                            type      = t.ptp
                        });
                        return(items.OrderBy(t => t.category.Id).OrderBy(t => t.equipment.Num));
                    }
        }
コード例 #3
0
        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);
                                }
        }