예제 #1
0
        public IEnumerable <OfficerModel> Page(string orgId, string ptId, string name, string code, int page, int size, out int count)
        {
            using (var officerHandler = new OfficerHandle(Repository))
                using (var userHandler = new UserHandle(Repository))
                    using (var orgHandler = new OrganizationHandle(Repository))
                        using (var ptpHandler = new PoliceTypeHandle(Repository))
                        {
                            var noDel = (short)DeleteStatus.No;
                            var query =
                                from officer in officerHandler.All(t => t.IsDel == noDel)
                                join useritem in userHandler.All(t => t.IsDel == noDel) on officer.UserId equals useritem.Id into usrs
                                from usr in usrs.DefaultIfEmpty(new User {
                            })
                                join org in orgHandler.All(t => t.IsDel == noDel) on officer.OrgId equals org.Id
                                join ptp in ptpHandler.All(t => t.IsDel == noDel) on officer.PtId equals ptp.Id
                                select new { officer = officer, usr = usr, org = org, ptp = ptp };

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

                            if (!string.IsNullOrWhiteSpace(code))
                            {
                                query = query.Where(t => t.officer.IdentyCode.Contains(code));
                            }

                            if (!string.IsNullOrWhiteSpace(ptId))
                            {
                                query = query.Where(t => t.officer.PtId == ptId);
                            }

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

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

                            count = query.Count();
                            var skipCount = (page - 1) * size;
                            var items     =
                                query.OrderByDescending(t => t.officer.SignupDate).Skip(skipCount).Take(size).ToArray()
                                .Select(t => new OfficerModel
                            {
                                officer = t.officer,
                                org     = t.org,
                                ptp     = t.ptp,
                                user    = t.usr
                            });
                            return(items);
                        }
        }
예제 #2
0
        public IEnumerable <OfficerAttendanceQueryModel> AttendanceSelect(string pattern, DateTime stime, DateTime etime)
        {
            var ocrHandler = new OfficerHandle(Repository);
            var orgHandler = new OrganizationHandle(Repository);
            var ptHandler  = new PoliceTypeHandle(Repository);
            var atdHandler = new OfficerAttendanceHandle(Repository);

            var noDel = (short)DeleteStatus.No;
            var query =
                from atd in atdHandler.All(null)
                join ocr in ocrHandler.All(t => t.IsDel == noDel) on atd.OfficerId equals ocr.Id
                join org in orgHandler.All(t => t.IsDel == noDel) on ocr.OrgId equals org.Id
                join ptp in ptHandler.All(t => t.IsDel == noDel) on ocr.PtId equals ptp.Id
                select new { atd = atd, ocr = ocr, org = org, ptp = ptp };

            if (!string.IsNullOrWhiteSpace(pattern))
            {
                query = query.Where(t => t.ocr.Name.Contains(pattern) || t.ocr.IdentyCode.Contains(pattern));
            }

            if (!User.IsSupperAdministrator)
            {
                var orgId = User.Organization.Id;
                query = query.Where(t => t.org.Id == orgId);
            }

            var items = query.OrderBy(t => t.ocr.Id).OrderByDescending(t => t.atd.STime).ToArray();

            if (0 == items.Count())
            {
                return(new OfficerAttendanceQueryModel[0]);
            }


            var sttime = items.Select(t => t.atd.STime).Min();
            var ettime = DateTime.Now.ToUnixTime();

            if (!items.Any(t => t.atd.ETime == 0L))
            {
                ettime = items.Select(t => t.atd.ETime).Max();
            }
            var ids    = items.Select(t => t.atd.OfficerId).Distinct().ToArray();
            var tracks = OfficerTracks(sttime, ettime, ids);
            var data   = items.Select(t => {
                var m = new OfficerAttendanceQueryModel
                {
                    atd     = t.atd,
                    officer = t.ocr,
                    org     = t.org,
                    ptp     = t.ptp
                };

                var sdtime = t.atd.STime;
                var edtime = ettime;
                if (t.atd.ETime != 0L)
                {
                    edtime = t.atd.ETime;
                }
                m.tracks = tracks.Where(x => x.track.OfficerId == t.atd.OfficerId && x.track.UpTime >= sdtime && x.track.UpTime <= edtime);

                return(m);
            });

            return(data);
        }
예제 #3
0
        // 矩形选择
        public IEnumerable <OfficerDispatchQueryModel> RectangleSelect(double x1, double y1, double x2, double y2)
        {
            var lcHandler  = new OfficerLocationHandle(Repository);
            var ocHandler  = new OfficerHandle(Repository);
            var orgHandler = new OrganizationHandle(Repository);
            var ptHandler  = new PoliceTypeHandle(Repository);
            var stHandler  = new StationHandle(Repository);

            var noDel = (short)DeleteStatus.No;
            var query =
                from lc in lcHandler.All(null)
                join oc in ocHandler.All(t => t.IsDel == noDel) on lc.OfficerId equals oc.Id
                join org in orgHandler.All(t => t.IsDel == noDel) on oc.OrgId equals org.Id
                join ptp in ptHandler.All(t => t.IsDel == noDel) on oc.PtId equals ptp.Id
                join sts in stHandler.All(t => t.IsDel == noDel) on lc.SiteId equals sts.SiteId into stas
                from st in stas.DefaultIfEmpty(new Station {
            })
                select new { location = lc, officer = oc, org = org, ptp = ptp, station = st };

            // 此处进一步查询
            if (!User.IsSupperAdministrator)
            {
                var orgId = User.Organization.Id;
                query = query.Where(t => t.org.Id == orgId);
            }

            var xmin = x1;
            var xmax = x2;

            if (x1 > x2)
            {
                xmax = x1;
                xmin = x2;
            }

            var ymin = y1;
            var ymax = y2;

            if (y1 > y2)
            {
                ymin = y2;
                ymax = y1;
            }
            var items = query.OrderByDescending(t => t.location.UpTime).ToArray()
                        .Select(t => {
                OfficerDispatchQueryModel m = null;
                if (string.IsNullOrWhiteSpace(t.station.SiteId) ||
                    (t.station.Lon >= xmin && t.station.Lon <= xmax && t.station.Lat >= ymin && t.station.Lat <= ymax)
                    )
                {
                    m = new OfficerDispatchQueryModel
                    {
                        location = t.location,
                        officer  = t.officer,
                        org      = t.org,
                        ptp      = t.ptp,
                        station  = t.station
                    };
                }
                return(m);
            }).Where(t => t != null).ToArray();

            return(items);
        }
예제 #4
0
 public PoliceTypeModule(UserInfo user) : base(user)
 {
     Handler = new PoliceTypeHandle(Repository);
 }