public JsonResult GetReservations(int start, int limit, DateTime startDate, DateTime endDate, int type, string keyWord) { var data = new AjaxDataModel <List <ReservationModel> > { success = true, message = "无数据", total = 0, data = new List <ReservationModel>() }; try { startDate = startDate.Date; endDate = endDate.Date.AddSeconds(86399); var reservations = _reservationService.GetReservationsInSpan(startDate, endDate); var projects = _projectService.GetProjects(); var result = (from res in reservations join pro in projects on res.ProjectId equals pro.Id select new { Reservation = res, Project = pro }).ToList(); if (!string.IsNullOrWhiteSpace(keyWord)) { var keyWords = Common.SplitCondition(keyWord.Trim()); if (type == (int)EnmSSH.Area) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Area); var areas = _workContext.Areas().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join area in areas on node.NodeId equals area.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else if (type == (int)EnmSSH.Device) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Device); var devices = _workContext.Devices().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join device in devices on node.NodeId equals device.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else if (type == (int)EnmSSH.Room) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Room); var rooms = _workContext.Rooms().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join room in rooms on node.NodeId equals room.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else if (type == (int)EnmSSH.Station) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Station); var stations = _workContext.Stations().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join station in stations on node.NodeId equals station.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else { result = result.FindAll(a => CommonHelper.ConditionContain(a.Project.Name, keyWords)); } } if (result.Count > 0) { data.message = "200 Ok"; data.total = result.Count; var end = start + limit; if (end > result.Count) { end = result.Count; } var users = _userService.GetPagedUsers().ToDictionary(k => k.Id, v => v.Uid); for (int i = start; i < end; i++) { data.data.Add(new ReservationModel { index = i + 1, id = result[i].Reservation.Id, name = result[i].Reservation.Name, expStartDate = CommonHelper.DateTimeConverter(result[i].Reservation.ExpStartTime), startDate = CommonHelper.DateTimeConverter(result[i].Reservation.StartTime), endDate = CommonHelper.DateTimeConverter(result[i].Reservation.EndTime), projectId = result[i].Project.Id, projectName = result[i].Project.Name, creator = result[i].Reservation.Creator, user = users[result[i].Reservation.UserId], createdTime = CommonHelper.DateTimeConverter(result[i].Reservation.CreatedTime), comment = result[i].Reservation.Comment, enabled = result[i].Reservation.Enabled, statusId = ((int)result[i].Reservation.Status), status = Common.GetResStatusDisplay(result[i].Reservation.Status) }); } } } catch (Exception exc) { _webLogger.Error(EnmEventType.Other, exc.Message, _workContext.User().Id, exc); data.success = false; data.message = exc.Message; } return(Json(data, JsonRequestBehavior.AllowGet)); }
public JsonResult GetMarkers(double minlng, double minlat, double maxlng, double maxlat) { var data = new AjaxDataModel <List <MarkerModel> > { success = true, message = "No data", total = 0, data = new List <MarkerModel>() }; try { var stations = _workContext.Stations().FindAll(s => { if (string.IsNullOrWhiteSpace(s.Current.Longitude)) { return(false); } if (string.IsNullOrWhiteSpace(s.Current.Latitude)) { return(false); } double lng, lat; if (!double.TryParse(s.Current.Longitude, out lng)) { return(false); } if (!double.TryParse(s.Current.Latitude, out lat)) { return(false); } return(lng >= minlng && lng <= maxlng && lat >= minlat && lat <= maxlat); }); if (stations.Count > 0) { if (stations.Count > 100) { stations = stations.Take(100).ToList(); } data.message = "200 Ok"; data.total = stations.Count; var almsInSta = from alarm in _workContext.ActAlarms() group alarm by alarm.Current.StationId into g select new { Id = g.Key, Alarms = g.Select(a => a.Current) }; foreach (var station in stations) { var model = new MarkerModel() { id = station.Current.Id, name = station.Current.Name, type = station.Current.Type.Name, lng = double.Parse(station.Current.Longitude), lat = double.Parse(station.Current.Latitude) }; var eachSta = almsInSta.FirstOrDefault(s => s.Id == station.Current.Id); if (eachSta != null) { model.alm1 = eachSta.Alarms.Count(a => a.AlarmLevel == EnmAlarm.Level1); model.alm2 = eachSta.Alarms.Count(a => a.AlarmLevel == EnmAlarm.Level2); model.alm3 = eachSta.Alarms.Count(a => a.AlarmLevel == EnmAlarm.Level3); model.alm4 = eachSta.Alarms.Count(a => a.AlarmLevel == EnmAlarm.Level4); if (model.alm1 > 0) { model.level = (int)EnmAlarm.Level1; } else if (model.alm2 > 0) { model.level = (int)EnmAlarm.Level2; } else if (model.alm3 > 0) { model.level = (int)EnmAlarm.Level3; } else if (model.alm4 > 0) { model.level = (int)EnmAlarm.Level4; } else { model.level = (int)EnmAlarm.Level0; } } else { model.level = (int)EnmAlarm.Level0; model.alm1 = 0; model.alm2 = 0; model.alm3 = 0; model.alm4 = 0; } data.data.Add(model); } } } catch (Exception exc) { data.success = false; data.message = exc.Message; } return(Json(data, JsonRequestBehavior.AllowGet)); }