コード例 #1
0
        // GET api/<controller>
        public IEnumerable <DeviceMapMode> Get(int areaId)
        {
            List <int> areaIds = areaRepository.GetChildAreas(areaId).ToList().Select(area => area.Id).ToList();
            IEnumerable <DeviceModel> devices = deviceRepository
                                                .FindAll(device => areaIds.Contains(device.AreaId)).Select(device =>
                                                                                                           new DeviceModel
            {
                Id          = device.Id,
                Name        = device.Name,
                Description = device.Description,
                IMEI        = device.IMEI,
                SimNumber   = device.SimNumber,
                AreaName    = areaRepository.Get(device.AreaId).Name
            });

            List <DeviceMapMode> devInfoList = new List <DeviceMapMode>();

            foreach (DeviceModel imei in devices)
            {
                var gps = gpsRepository.FindAll(p => p.IMEI == imei.IMEI).OrderByDescending(p => p.RecvTime).FirstOrDefault();

                if (gps != null)
                {
                    DeviceMapMode mode = new DeviceMapMode();
                    mode.Device = imei;
                    mode.DtuGPS = gps;
                    devInfoList.Add(mode);
                }
            }
            return(devInfoList);
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            Device existing = deviceRepository.Get(id);

            if (existing == null)
            {
                return(RedirectToAction("TableMode"));
            }

            var model = new DeviceModel
            {
                Id              = existing.Id,
                Name            = existing.Name,
                Description     = existing.Description,
                IMEI            = existing.IMEI,
                SimNumber       = existing.SimNumber,
                AreaId          = existing.AreaId,
                TransportPlanId = existing.TransportPlanId
            };

            var    sortingOptions = new SortingOptions <DtuGPS, DateTime>(x => x.RecvTime, true);
            DtuGPS gps            = dtuGpsRepository.FindAll(g => g.IMEI == existing.IMEI, sortingOptions).FirstOrDefault();

            if (gps != null)
            {
                model.longitude = gps.Longitude;
                model.latitude  = gps.Latitude;
            }

            ViewBag.Areas       = GetAreaSelectItems();
            ViewBag.Plans       = GetPlanSelectItems();
            ViewBag.DeviceTypes = GetDeviceTypeItems();
            return(View(model));
        }
コード例 #3
0
        public ActionResult ViewPlan(int id)
        {
            var plan = transportPlanRepository.Get(id);

            if (plan == null)
            {
                return(HttpNotFound());
            }
            //首先查询到计划关联的所有的设备
            var records = devicePlanRepository.FindAll(p => p.PlanId == id);
            //if(plan.stopTime != null)
            //{
            //    records = records.Where(p => { if (p.endTime == null) { return true; } else return p.endTime <= plan.stopTime; });
            //}

            var devIds = records.Select(p => p.DeviceId);

            var imeis = deviceRepository.FindAll(p => devIds.Contains(p.Id)).Select(d => d.IMEI);

            List <TransportTrack> tracks = new List <TransportTrack>();

            DateTime endTime = plan.stopTime == null ? DateTime.Now : plan.stopTime.Value;

            foreach (var ele in records)
            {
                DateTime devEndTime = ele.endTime == null ? DateTime.Now : ele.endTime.Value;

                DateTime realEndTime = devEndTime > endTime ? endTime : devEndTime;

                var query = dtuGpsRepository.FindAll(d => imeis.Contains(d.IMEI) && d.RecvTime >= ele.startTime && d.RecvTime < realEndTime, new SortingOptions <DtuGPS>("RecvTime"));

                Device device = deviceRepository.Get(ele.DeviceId.Value);
                var    eles   = query.Select(gps => new TransportTrack
                {
                    name      = device != null ? device.Name : "",
                    latitude  = gps.Latitude,
                    longitude = gps.Longitude
                });
                tracks.AddRange(eles);
            }
            ViewBag.PlanName = plan.Name;
            ViewBag.Data     = JsonConvert.SerializeObject(tracks);
            return(View());
        }