// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var appConfiguration = Configuration.Get <AppConfiguration>(); var httpClient = new HttpClient(); var zWayService = new ZWayService(httpClient, LoggerFactory.CreateLogger <ZWayService>()); var weatherService = new WeatherService(httpClient, LoggerFactory.CreateLogger <WeatherService>()); var sunService = new SunService(httpClient, LoggerFactory.CreateLogger <SunService>()); var virtualService = new DeviceGroupService(zWayService); var aggregatedService = new AggregatedDeviceService(zWayService, virtualService, weatherService, sunService); var statisticsService = new StatisticsService(LoggerFactory.CreateLogger <StatisticsService>(), aggregatedService, appConfiguration.Statistics); zWayService.InitAsync(appConfiguration.ZWay).Wait(); weatherService.InitAsync(appConfiguration.Weather).Wait(); sunService.InitAsync(appConfiguration.Sun).Wait(); virtualService.Init(appConfiguration.DeviceGroups); aggregatedService.Init(appConfiguration.ToggleAutomationRules); statisticsService.Init(); services.AddMvc(); services.AddSingleton <HttpClient>(new HttpClient()); services.AddSingleton <IDeviceService>(aggregatedService); services.AddSingleton <VersionService>(new VersionService()); services.AddSingleton <StatisticsService>(statisticsService); //services.AddSignalR(); }
public JsonResult DeviceGroupList(int groupId) { var myList = DeviceGroupService.GetByWhere(" where GroupId=" + groupId); var unioaList = DeviceGroupService.GetListAll(); foreach (var item in unioaList) { item.GroupId = groupId; var source = myList.Where(x => x.IO_SERVER_ID == item.IO_SERVER_ID && x.IO_COMM_ID == item.IO_COMM_ID && x.IO_DEVICE_ID == item.IO_DEVICE_ID); if (source.Count() > 0) { var sorItem = source.First(); item.LAY_CHECKED = true; item.ALIASNAME = sorItem.ALIASNAME; item.IOPARAS = sorItem.IOPARAS; item.IOPARATITLES = sorItem.IOPARATITLES; item.IOPARANAMES = sorItem.IOPARANAMES; item.SerieType = sorItem.SerieType; item.UpdateCycle = sorItem.UpdateCycle; } else { item.ALIASNAME = item.IODeviceName; item.LAY_CHECKED = false; item.IOPARAS = ""; item.IOPARATITLES = ""; item.IOPARANAMES = ""; item.SerieType = ""; } } var result = new { code = 0, count = unioaList.Count(), data = unioaList }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetDeviceColumns(int id) { DeviceGroupModel model = DeviceGroupService.GetById(id); List <GridColumn> columns = new List <GridColumn>(); if (model != null) { string[] fields = model.IOPARANAMES.Split(','); string[] titles = model.IOPARATITLES.Split(','); if (fields.Length == titles.Length) { for (int i = 0; i < fields.Length; i++) { GridColumn _option = new GridColumn { field = fields[i], title = titles[i], width = "120" }; columns.Add(_option); } } } columns.Insert(0, new GridColumn() { field = "DateStampTime", title = "采集时间", width = "120" }); return(Json(columns, JsonRequestBehavior.AllowGet)); }
public JsonResult GetGroupDevicePara(int id, string serverid, string communicateid, string deviceid) { DeviceGroupModel deviceModel = DeviceGroupService.GetById(id); List <SelectOption> _select = new List <SelectOption>(); if (deviceModel != null) { string[] titles = deviceModel.IOPARATITLES.Split(','); string[] ionames = deviceModel.IOPARANAMES.Split(','); string[] ioids = deviceModel.IOPARAS.Split(','); for (int i = 0; i < titles.Length; i++) { SelectOption _option = new SelectOption { id = ioids[i], name = titles[i], value = ioids[i], value1 = "/" + deviceModel.GroupId + "/" + deviceModel.IO_SERVER_ID + "/" + deviceModel.IO_COMM_ID + "/" + deviceModel.IO_DEVICE_ID + "/" + ioids[i] + "/" + deviceModel.UpdateCycle, }; _select.Add(_option); } } return(Json(_select, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveGroupSet(IEnumerable <DeviceGroupModel> list, int groupId) { var result = ErrorTip("失败"); result = DeviceGroupService.SaveDeviceGroup(list, groupId) > 0 ? SuccessTip("保存成功") : ErrorTip("保存失败"); return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult GeneralAlarm() { ScadaGreneralAlarmModel model = new ScadaGreneralAlarmModel(); model.AllDeviceList = DeviceGroupService.GetAll(); Session["AllDeviceList"] = model.AllDeviceList; return(View(model)); }
public JsonResult GetGroupDevice(int groupId) { string idlist = GroupService.GetGroupNodeChildren(groupId); IEnumerable <DeviceGroupModel> Items = DeviceGroupService.GetListByGroupId(idlist); List <SelectOption> _select = new List <SelectOption>(); if (Items != null && Items.Count() > 0) { foreach (var item in Items) { SelectOption _option = new SelectOption { id = item.Id.ToString(), name = item.ALIASNAME, value = item.Id.ToString(), value1 = item.IO_DEVICE_ID.ToString(), value2 = item.IO_COMM_ID, value3 = item.IO_SERVER_ID, value4 = item.IOPARANAMES, value5 = item.SerieType, }; _select.Add(_option); } } string deviceids = "'1'"; foreach (var item in Items) { deviceids += ",'" + item.IO_DEVICE_ID + "'"; } var deviceItems = IO_DeviceServer.GetByWhere(" where IO_DEVICE_ID in (" + deviceids + ")"); foreach (var item in _select) { var searchs = deviceItems.Where(x => x.IO_DEVICE_ID.Trim().ToLower() == item.value1.Trim().ToLower()); if (searchs.Count() > 0) { var sItem = searchs.First(); if (string.IsNullOrWhiteSpace(sItem.IO_DEVICE_UPDATECYCLE)) { item.value6 = "120"; } else { item.value6 = sItem.IO_DEVICE_UPDATECYCLE; } } } return(Json(_select, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(int id) { var result = ErrorTip("删除失败"); if (GroupService.DeleteById(id)) { DeviceGroupService.DeleteByWhere(" where GroupId=" + id); result = SuccessTip("删除成功"); } else { result = ErrorTip("删除失败"); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveGroupDevicePara(IEnumerable <IOParaModel> list, int groupId, string deviceid, string communicateid, string serverid) { var result = ErrorTip("失败"); if (list != null && list.Count() > 0 && !string.IsNullOrWhiteSpace(deviceid) && !string.IsNullOrWhiteSpace(communicateid) && !string.IsNullOrWhiteSpace(serverid)) { DeviceGroupModel model = DeviceGroupService.GetModel(groupId, serverid, communicateid, deviceid); if (model != null) { model.IO_COMM_ID = communicateid; model.IO_DEVICE_ID = deviceid; model.IO_SERVER_ID = serverid; model.GroupId = groupId; model.IOPARAS = ""; model.IOPARATITLES = ""; model.IOPARANAMES = ""; // DeviceGroupService.DeleteByWhere(" where GroupId=" + groupId + " and IO_SERVER_ID='" + serverid + "' and IO_COMM_ID='" + communicateid + "' and IO_DEVICE_ID='" + deviceid + "'"); foreach (var item in list) { if (!string.IsNullOrWhiteSpace(item.IO_ID)) { model.IOPARAS += item.IO_ID + ","; model.IOPARANAMES += item.IO_NAME + ","; if (item.IO_ALIASNAME != "") { model.IOPARATITLES += item.IO_ALIASNAME + ","; } else { model.IOPARATITLES += item.IO_LABEL + ","; } } } if (!string.IsNullOrWhiteSpace(model.IOPARAS)) { model.IOPARAS = model.IOPARAS.Remove(model.IOPARAS.Length - 1, 1); model.IOPARATITLES = model.IOPARATITLES.Remove(model.IOPARATITLES.Length - 1, 1); model.IOPARANAMES = model.IOPARANAMES.Remove(model.IOPARANAMES.Length - 1, 1); } result = DeviceGroupService.UpdateModelByIOPara(model) ? SuccessTip("保存成功") : ErrorTip("保存失败"); } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetDevicePara(string ServerID, string CommunicateID, string DeviceID, string GroupID) { var myList = DeviceGroupService.GetByWhere(" where GroupId=" + GroupID); var selectItems = myList.Where(x => x.IO_SERVER_ID == ServerID && x.IO_COMM_ID == CommunicateID && x.IO_DEVICE_ID == DeviceID); var myItem = selectItems.First(); if (myItem != null) { List <string> ids = myItem.IOPARAS.ToString().Split(',').ToList(); List <string> titles = myItem.IOPARATITLES.ToString().Split(',').ToList(); var paras = ParaService.GetByWhere(" where IO_SERVER_ID='" + ServerID + "' and IO_COMM_ID='" + CommunicateID + "' and IO_DEVICE_ID='" + DeviceID + "'"); foreach (var item in paras) { int index = ids.FindIndex(x => x == item.IO_ID); if (index >= 0) { if (index < titles.Count) { item.IO_ALIASNAME = titles[index]; } item.LAY_CHECKED = true; } else { item.IO_ALIASNAME = item.IO_LABEL; item.LAY_CHECKED = false; } } var result = new { code = 0, count = paras.Count(), data = paras }; return(Json(result, JsonRequestBehavior.AllowGet)); } else { return(Json(null, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetGroupDevice(int Id) { var myList = DeviceGroupService.GetByWhere(" where GroupId=" + Id); List <IOTreeSelect> treeSelectList = new List <IOTreeSelect>(); foreach (var item in myList) { IOTreeSelect tree = new IOTreeSelect { id = item.IO_DEVICE_ID.ToString(), name = item.ALIASNAME, CommunicateID = item.IO_COMM_ID, DeviceID = item.IO_DEVICE_ID, ServerID = item.IO_SERVER_ID, UpdateCycle = item.UpdateCycle, value = item.IO_DEVICE_ID, open = false }; treeSelectList.Add(tree); } return(Json(treeSelectList, JsonRequestBehavior.AllowGet)); }
public override ActionResult Index(int?id) { string para = Request.QueryString["id"].Split('?')[0]; string idstr = Request.QueryString["id"].Split('?')[1].Split('=')[1]; base.Index(int.Parse(idstr)); var rowModel = TableRowService.GetByWhere("where TableId=" + int.Parse(para)).First(); var tableUsers = TableUserRoleService.GetByWhere("where TableId=" + int.Parse(para)); var tableModel = TableService.GetById(int.Parse(para)); TableRealModel model = new TableRealModel(); model.TableId = int.Parse(para); model.Title = tableModel != null ? tableModel.Title : ""; model.RowNum = tableModel != null ? tableModel.RowNum : 100; var AllUsers = UserService.GetAll(); model.AllUserJson = JsonConvert.SerializeObject(AllUsers);//获取当前的所有用户 List <UserModel> privatemodels = new List <UserModel>(); foreach (var item in tableUsers) { var whereItems = AllUsers.Where(x => x.Id == item.UserId); if (whereItems.Count() > 0) { var extItem = whereItems.First(); privatemodels.Add(extItem); } } model.PrivateUserJson = JsonConvert.SerializeObject(privatemodels); //获取当前的所有用户 //获取表的列宽度 List <string> fontwidthmodels = new List <string>(); if (tableModel != null && !string.IsNullOrWhiteSpace(tableModel.ColimnWidths)) { fontwidthmodels = tableModel.ColimnWidths.Split(',').ToList(); } else { for (int i = 0; i < 26; i++) { fontwidthmodels.Add("120"); } } model.colwidthmodels = JsonConvert.SerializeObject(fontwidthmodels); //获取列标题 //获取表的列宽度 List <string> columntitlemodels = new List <string>(); if (tableModel != null && !string.IsNullOrWhiteSpace(tableModel.ColumnTitles)) { columntitlemodels = tableModel.ColumnTitles.Split(',').ToList(); } else { for (int i = 0; i < 26; i++) { columntitlemodels.Add(ExcelConvert.ToName(i)); } } model.coltitlesmodels = JsonConvert.SerializeObject(columntitlemodels); model.ScadaTable = tableModel; model.FieldBackColors = rowModel.FieldBackColors; model.FieldColors = rowModel.FieldColors; model.FieldFontSizes = rowModel.FieldFontSizes; model.FieldIOPaths = rowModel.FieldIOPaths; model.FieldWeights = rowModel.FieldWeights; ///获取设备列表 JavaScriptSerializer js = new JavaScriptSerializer(); //实例化一个能够序列化数据的类 List <ExcelModel> excelModels = js.Deserialize <List <ExcelModel> >(rowModel.FieldIOPaths); List <DeviceGroupModel> deviceAllModels = DeviceGroupService.GetAll().ToList(); List <DeviceGroupModel> deviceModels = new List <DeviceGroupModel>(); for (int i = 0; i < excelModels.Count; i++) { PropertyInfo[] properties = excelModels[i].GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); if (properties.Length <= 0) { continue; } foreach (PropertyInfo item in properties) { string name = item.Name; object value = item.GetValue(excelModels[i], null); if (value != null && value.ToString() != "") { if (value.ToString().Split('/').Length >= 8) { try { DeviceGroupModel groupDevice = new DeviceGroupModel(); groupDevice.GroupId = int.Parse(value.ToString().Split('/')[1]); groupDevice.IO_SERVER_ID = value.ToString().Split('/')[2]; groupDevice.IO_COMM_ID = value.ToString().Split('/')[3]; groupDevice.IO_DEVICE_ID = value.ToString().Split('/')[4]; groupDevice.UpdateCycle = int.Parse(value.ToString().Split('/')[6]); groupDevice.CurrentIO = value.ToString().Split('/')[5];//当前的iO DeviceGroupModel exitItem = deviceAllModels.Find(x => x.IO_SERVER_ID == groupDevice.IO_SERVER_ID && x.IO_COMM_ID == groupDevice.IO_COMM_ID && x.IO_DEVICE_ID == groupDevice.IO_DEVICE_ID && x.GroupId == groupDevice.GroupId); if (exitItem != null) { if (!deviceModels.Exists(x => x.IO_SERVER_ID == groupDevice.IO_SERVER_ID && x.IO_COMM_ID == groupDevice.IO_COMM_ID && x.IO_DEVICE_ID == groupDevice.IO_DEVICE_ID && x.GroupId == groupDevice.GroupId)) { exitItem.CurrentIO = groupDevice.CurrentIO; deviceModels.Add(exitItem); } } } catch { continue; } } } } } model.Devices = deviceModels; model.JsonDevices = js.Serialize(deviceModels); return(View(model)); }
private JsonResult QueryHistorySummaryData(string groupid, string serverid, string communicateid, string deviceid, string period, string method, string fields = "", string series = "", int charttype = 1, string sdate = "", string edate = "", string serieclassify = "", int pagesize = 1000) { ///传递的曲线指标信息 string serieindex = "'" + series.Trim().Replace(",", "','") + "'"; string[] myfields = fields.Split(','); //获取对应的曲线配置信息 IEnumerable <SerieConfigModel> allItems = SerieServer.GetByWhere(" where SerieName in(" + serieindex + ") and SerieClassify='" + serieclassify + "'"); List <SerieConfigModel> Items = new List <SerieConfigModel>(); foreach (var item in allItems) { if (myfields.Contains(item.SerieName)) { Items.Add(item); } } DeviceGroupModel pWell = DeviceGroupService.GetById(int.Parse(groupid)); ///初始化曲线对象 EChartOption chartOption = new EChartOption(); chartOption.xAxis = new Axis[1]; chartOption.xAxis[0] = new Axis(); chartOption.xAxis[0].gridIndex = 1; chartOption.xAxis[0].type = "time"; chartOption.xAxis[0].name = "时间"; List <Axis> yaxis = new List <Axis>(); int index = 0; string[] legend = new string[Items.Count()]; foreach (var item in Items) { yaxis.Add(new Axis() { gridIndex = index, name = item.SerieTitle, type = "value" }); legend[index] = item.SerieTitle; index++; } chartOption.legend.data = legend; chartOption.yAxis = yaxis.ToArray(); //初始化对象结束 if (sdate == null || sdate == "") { sdate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss"); } if (edate == null || edate == "") { edate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } chartOption.series = new Series[Items.Count()]; string returnFields = " time"; #region { foreach (var item in Items) { returnFields += "," + method + "(field_" + item.SerieName.Trim().ToLower().ToString() + "_value) as field_" + item.SerieName.Trim().ToLower().ToString() + "_value"; } } #endregion InfluxDBHistoryResult realResult = mWebInfluxDbManager.DbQuery_HistoryStatics(serverid, communicateid, deviceid, Convert.ToDateTime(sdate), Convert.ToDateTime(edate), pagesize, 1, " DESC ", period, returnFields); if (realResult != null) { var datas = realResult.Seres; if (datas != null && datas.Count() > 0) { var onedata = datas.First(); int sindex = 0; foreach (var item in Items) { chartOption.series[sindex] = new Series(); chartOption.series[sindex].name = item.SerieTitle; chartOption.series[sindex].lineStyle.color = item.SerieColor; chartOption.series[sindex].lineStyle.width = int.Parse(item.SerieWidth); chartOption.series[sindex].itemStyle = null; chartOption.series[sindex].data = new double[onedata.Values.Count]; chartOption.series[sindex].type = item.SerieType; chartOption.series[sindex].showSymbol = item.ShowSymbol == "1" ? true : false; chartOption.series[sindex].symbol = item.SymbolType; chartOption.series[sindex].symbolSize = int.Parse(item.SymbolSize); sindex++; } string[] axisData = new string[onedata.Values.Count]; //获取的数据按照时间先后 int dataindex = onedata.Values.Count() - 1; foreach (var value in onedata.Values) { //获取采集时间 object objx = onedata.Values[dataindex][onedata.Columns.IndexOf("time")]; axisData[dataindex] = objx != null?objx.ToString() : ""; ////////////////////////// sindex = 0; foreach (var item in Items) { try { string record = item.SerieName.ToString().ToLower(); int recordindex = onedata.Columns.IndexOf("field_" + record + "_value"); if (recordindex >= 0) { object objy = onedata.Values[dataindex][recordindex]; chartOption.series[sindex].data[dataindex] = Convert.ToDouble(objy); chartOption.series[sindex].id = item.SerieName; } } catch { } sindex++; } dataindex--; } chartOption.xAxis[0].data = axisData;//设置x轴数据,time格式的数据必须在Axis轴上进行设置 } } //读取以下的实时数据,从influxDB中读取 return(Json(chartOption, JsonRequestBehavior.AllowGet)); }
public JsonResult GetAllDevices() { IEnumerable <DeviceGroupModel> Items = DeviceGroupService.GetAll(); return(Json(Items.ToList(), JsonRequestBehavior.AllowGet)); }
/// <summary> /// 读取通用历史报警 /// </summary> /// <returns></returns> public JsonResult GeneralQueryHistoryAlarm(GeneralHistoryAlarmFormModel model, PageInfo pageInfo) { if (string.IsNullOrWhiteSpace(model.DeviceID)) { model.DeviceID = ""; } if (string.IsNullOrWhiteSpace(model.ServerID)) { model.ServerID = ""; } if (string.IsNullOrWhiteSpace(model.CommunicateID)) { model.ServerID = ""; } if (string.IsNullOrWhiteSpace(model.Fields)) { model.Fields = ""; } var deviceModel = DeviceGroupService.GetModel(model.GroupID, model.ServerID, model.CommunicateID, model.DeviceID); List <ScadaGreneralAlarmModel> alarms = new List <ScadaGreneralAlarmModel>(); InfluxDBHistoryResult realResult = null; realResult = mWebInfluxDbManager.DbQuery_Alarms(model.ServerID, model.CommunicateID, model.DeviceID, Convert.ToDateTime(model.StartDate), Convert.ToDateTime(model.EndDate), model.IO_ALARM_TYPE, model.IO_ALARM_LEVEL, pageInfo.limit, pageInfo.page); if (realResult != null && realResult.Seres.Count() > 0) { var s = realResult.Seres.First(); for (int i = 0; i < s.Values.Count; i++) { ScadaGreneralAlarmModel mymodel = new ScadaGreneralAlarmModel(); int index = s.Columns.IndexOf("time"); object time = s.Values[i][index]; mymodel.time = time != null?time.ToString() : ""; index = -1; index = s.Columns.IndexOf("field_io_alarm_date"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_DATE = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_disposalidea"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_DISPOSALIDEA = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_disposaluser"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_DISPOSALUSER = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_level"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_LEVEL = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_type"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_TYPE = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_value"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_VALUE = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_name"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_NAME = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_did"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_DEVICE_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_cid"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_COMMUNICATE_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_sid"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_SERVER_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_ioid"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_device_name"); if (index >= 0) { object v = s.Values[i][index]; mymodel.DEVICE_NAME = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_label"); if (index >= 0) { if (deviceModel != null) { string[] titles = deviceModel.IOPARATITLES.Split(','); List <string> ioids = deviceModel.IOPARAS.Split(',').ToList(); int nameindex = ioids.FindIndex(x => x == mymodel.IO_ID); if (nameindex >= 0) { mymodel.IO_LABEL = titles[nameindex]; } } } alarms.Add(mymodel); } } var result = Pager.Paging(alarms, realResult.RecordCount); //读取以下10行的实时数据,从influxDB中读取 return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 读取自定义表历史报警 /// </summary> /// <returns></returns> public JsonResult ScadaTableHistoryAlarm(ScadaTableAlarmSearchForm model, PageInfo pageInfo) { var result = Pager.Paging(null, 0); if (model.AlarmIOPath.Trim() == "") { return(Json(result, "application/text", JsonRequestBehavior.AllowGet)); } string[] paras = model.AlarmIOPath.Split('/'); if (paras.Length < 4) { return(Json(result, "application/text", JsonRequestBehavior.AllowGet)); } model.ServerID = paras[1]; model.CommunicateID = paras[2]; model.DeviceID = paras[3]; model.GroupId = int.Parse(paras[0]); IEnumerable <DeviceGroupModel> groupdevices = DeviceGroupService.GetByWhere(" where GroupId=" + model.GroupId + " and IO_SERVER_ID='" + model.ServerID + "' and IO_COMM_ID='" + model.CommunicateID + "' and IO_DEVICE_ID='" + model.DeviceID + "'"); DeviceGroupModel deviceModel = null; if (groupdevices.Count() > 0) { deviceModel = groupdevices.First(); } string[] columns = deviceModel.IOPARANAMES.Split(','); string[] titles = deviceModel.IOPARATITLES.Split(','); List <string> ioids = deviceModel.IOPARAS.Split(',').ToList(); List <ScadaGreneralAlarmModel> alarms = new List <ScadaGreneralAlarmModel>(); InfluxDBHistoryResult realResult = null; realResult = mWebInfluxDbManager.DbQuery_Alarms(model.ServerID, model.CommunicateID, model.DeviceID, Convert.ToDateTime(model.AlarmStartDate), Convert.ToDateTime(model.AlarmEndDate), "", "", pageInfo.limit, pageInfo.page); if (realResult != null && realResult.Seres.Count() > 0) { var s = realResult.Seres.First(); for (int i = 0; i < s.Values.Count; i++) { ScadaGreneralAlarmModel mymodel = new ScadaGreneralAlarmModel(); int index = s.Columns.IndexOf("time"); object time = s.Values[i][index]; mymodel.time = time != null?time.ToString() : ""; index = -1; index = s.Columns.IndexOf("field_io_alarm_date"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_DATE = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_disposalidea"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_DISPOSALIDEA = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_disposaluser"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_DISPOSALUSER = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_level"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_LEVEL = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_type"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_TYPE = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_alarm_value"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ALARM_VALUE = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_name"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_NAME = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_did"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_DEVICE_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_cid"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_COMMUNICATE_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_sid"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_SERVER_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_ioid"); if (index >= 0) { object v = s.Values[i][index]; mymodel.IO_ID = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("tag_device_name"); if (index >= 0) { object v = s.Values[i][index]; mymodel.DEVICE_NAME = v != null?v.ToString() : ""; } index = -1; index = s.Columns.IndexOf("field_io_label"); if (index >= 0) { if (deviceModel != null) { int nameindex = ioids.FindIndex(x => x == mymodel.IO_ID); if (nameindex >= 0) { mymodel.IO_LABEL = titles[nameindex]; } } } alarms.Add(mymodel); } } result = Pager.Paging(alarms, realResult.RecordCount); //读取以下10行的实时数据,从influxDB中读取 return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult ScadaTableHistory(ScadaTableSearchForm model, PageInfo pageInfo) { if (model.IOPath.Trim() == "") { var result = Pager.Paging2(null, 0); return(Json(result, "application/text", JsonRequestBehavior.AllowGet)); } string[] paras = model.IOPath.Split('/'); if (paras.Length < 4) { var result = Pager.Paging2(null, 0); return(Json(result, "application/text", JsonRequestBehavior.AllowGet)); } model.ServerID = paras[1]; model.CommunicateID = paras[2]; model.DeviceID = paras[3]; model.GroupId = int.Parse(paras[0]); IEnumerable <DeviceGroupModel> groupdevices = DeviceGroupService.GetByWhere(" where GroupId=" + model.GroupId + " and IO_SERVER_ID='" + model.ServerID + "' and IO_COMM_ID='" + model.CommunicateID + "' and IO_DEVICE_ID='" + model.DeviceID + "'"); DeviceGroupModel pItem = null; if (groupdevices.Count() > 0) { pItem = groupdevices.First(); } string items = "["; string[] columns = pItem.IOPARANAMES.Split(','); string[] titles = pItem.IOPARATITLES.Split(','); if (!string.IsNullOrWhiteSpace(model.DeviceID)) { string sdate = model.StartDate; string edate = model.EndDate; InfluxDBHistoryResult realResult = mWebInfluxDbManager.DbQuery_History(model.ServerID, model.CommunicateID, model.DeviceID, Convert.ToDateTime(sdate), Convert.ToDateTime(edate), pageInfo.limit, pageInfo.page, " DESC "); foreach (var s in realResult.Seres) { List <int> indexs = new List <int>(); for (int i = 0; i < s.Values.Count; i++) { string jsonrow = ""; int index = s.Columns.IndexOf("time"); object time = s.Values[i][index]; jsonrow += "{"; jsonrow += "\"DateStampTime\":\"" + (time != null ? time.ToString() : "") + "\""; foreach (string str in columns) { try { index = -1; index = s.Columns.IndexOf("field_" + str.Trim().ToLower().ToString() + "_value"); if (index >= 0) { object v = s.Values[i][index]; jsonrow += ",\"" + str + "\":\"" + (v != null ? v.ToString() : "") + "\""; } } catch { continue; } } jsonrow += "},"; items += jsonrow; } } items += "]"; var result = Pager.Paging2(items, realResult.RecordCount); //读取以下的实时数据,从influxDB中读取 return(Json(result, "application/text", JsonRequestBehavior.AllowGet)); } else { var result = Pager.Paging2("", 0); return(Json(result, "application/text", JsonRequestBehavior.AllowGet)); } }
public JsonResult QueryDefaultSeriesData(string groupid, string serverid, string communicateid, string deviceid, string paraid) { string sdate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss"); string edate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); IEnumerable <DeviceGroupModel> groupdevices = DeviceGroupService.GetByWhere(" where GroupId=" + groupid + " and IO_SERVER_ID='" + serverid + "' and IO_COMM_ID='" + communicateid + "' and IO_DEVICE_ID='" + deviceid + "'"); DeviceGroupModel pWell = null; if (groupdevices.Count() > 0) { pWell = groupdevices.First(); } if (pWell == null) { return(Json(null, JsonRequestBehavior.AllowGet)); } List <string> ioids = pWell.IOPARAS.Split(',').ToList(); List <string> names = pWell.IOPARANAMES.Split(',').ToList(); List <string> titles = pWell.IOPARATITLES.Split(',').ToList(); int index = ioids.FindIndex(X => X == paraid.Trim()); string seriename = ""; if (index >= 0) { seriename = names[index]; } IEnumerable <SerieConfigModel> allItems = SerieServer.GetByWhere(" where SerieName='" + seriename + "' and SerieClassify='" + pWell.SerieType + "'"); SerieConfigModel serieConfig = new SerieConfigModel(); if (allItems.Count() > 0) { serieConfig = allItems.First(); } else { serieConfig.SerieTitle = titles[index]; serieConfig.SerieName = seriename; serieConfig.SerieType = "line"; } ///初始化曲线对象 EChartOption chartOption = new EChartOption(); chartOption.xAxis = new Axis[1]; chartOption.xAxis[0] = new Axis(); chartOption.xAxis[0].gridIndex = 1; chartOption.xAxis[0].type = "time"; chartOption.xAxis[0].name = "时间"; chartOption.name = serieConfig.SerieTitle; List <Axis> yaxis = new List <Axis>(); string legend = serieConfig.SerieTitle; yaxis.Add(new Axis() { gridIndex = 0, name = serieConfig.SerieTitle, type = "value" }); chartOption.legend.data = new string[1] { legend }; chartOption.yAxis = yaxis.ToArray(); //初始化对象结束 if (sdate == null || sdate == "") { sdate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss"); } if (edate == null || edate == "") { edate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } chartOption.series = new Series[1]; InfluxDBHistoryResult realResult = mWebInfluxDbManager.DbQuery_History(serverid, communicateid, deviceid, Convert.ToDateTime(sdate), Convert.ToDateTime(edate), 10000, 1, " ASC "); if (realResult != null) { var datas = realResult.Seres; if (datas != null && datas.Count() > 0) { var onedata = datas.First(); if (onedata != null) { chartOption.series[0] = new Series(); chartOption.series[0].name = serieConfig.SerieTitle; chartOption.series[0].lineStyle.color = serieConfig.SerieColor; chartOption.series[0].lineStyle.width = int.Parse(serieConfig.SerieWidth); chartOption.series[0].itemStyle = null; chartOption.series[0].data = new double[onedata.Values.Count]; chartOption.series[0].type = serieConfig.SerieType; chartOption.series[0].showSymbol = serieConfig.ShowSymbol == "1" ? true : false; chartOption.series[0].symbol = serieConfig.SymbolType; chartOption.series[0].symbolSize = int.Parse(serieConfig.SymbolSize); string[] axisData = new string[onedata.Values.Count]; //获取的数据按照时间先后 int dataindex = onedata.Values.Count() - 1; foreach (var value in onedata.Values) { //获取采集时间 object objx = onedata.Values[dataindex][onedata.Columns.IndexOf("time")]; axisData[dataindex] = objx != null?objx.ToString() : ""; ////////////////////////// try { int recordindex = onedata.Columns.IndexOf("field_" + serieConfig.SerieName.Trim().ToLower() + "_value"); if (recordindex >= 0) { object objy = onedata.Values[dataindex][recordindex]; chartOption.series[0].data[dataindex] = Convert.ToDouble(objy); chartOption.series[0].id = serieConfig.SerieName; } } catch { } dataindex--; } chartOption.xAxis[0].data = axisData;//设置x轴数据,time格式的数据必须在Axis轴上进行设置 } } } //读取以下的实时数据,从influxDB中读取 return(Json(chartOption, JsonRequestBehavior.AllowGet)); }