/// <summary> /// 视频下载(往视频下载记录表中插入一条需要下载的记录 /// </summary> /// <param name="deviceCode"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns></returns> public JsonResult VideoDownload(string deviceCode, string startTime, string endTime) { try { ServVideoInfoModel model = new ServVideoInfoModel(); //根据设备code获取设备 ServDeviceInfoModel servDeviceInfo = deviceInfoBLL.GetDeviceInfoByDeviceCode(deviceCode); if (servDeviceInfo == null) { return(Json(new { state = 1, message = "该设备不存在" })); } model.video_name = servDeviceInfo.device_name + DateTime.Now.ToString(); model.video_path = ""; model.video_type = (int)VideoDownLoadType.自定义下载; model.video_start_time = Convert.ToDateTime(startTime); model.video_end_time = Convert.ToDateTime(endTime); model.device_name = servDeviceInfo.device_name; model.device_code = servDeviceInfo.device_code; model.platform_id = 1; model.create_time = DateTime.Now; model.download_status = (int)VideoDownLoadStatus.未开始下载; bool result = servVideoDownloadBLL.VideoDownloadWrite(model); return(Json(result)); } catch (Exception ex) { return(Json(new { state = 1, message = ex.Message })); } }
/// <summary> /// 修改设备信息 /// </summary> /// <param name="deviceID"></param> /// <param name="device_name"></param> /// <param name="device_code"></param> /// <param name="device_type"></param> /// <param name="subsystem_id"></param> /// <param name="device_status"></param> /// <param name="cover_range"></param> /// <param name="camera_towards"></param> /// <param name="visual_range"></param> /// <param name="isParts"></param> /// <param name="jishihuifang"></param> /// <param name="duolubofang"></param> /// <param name="shangdaqiang"></param> /// <param name="lishihuifang"></param> /// <returns></returns> public JsonResult UpdateDeviceInfo(int deviceID, string device_name, string device_code, int device_type, int subsystem_id, int device_status, string cover_range, string camera_towards, string visual_range, int isParts, string jishihuifang, string duolubofang, string shangdaqiang, string lishihuifang) { try { ServDeviceInfoModel model = new ServDeviceInfoModel(); model.id = deviceID; model.device_name = device_name; model.device_code = device_code; model.device_type = device_type; model.subsystem_id = subsystem_id; model.device_status = device_status; if ((int)SubSystem.视频子系统 == subsystem_id) { model.cover_range = Convert.ToInt32(cover_range); model.camera_towards = Convert.ToInt32(camera_towards); model.visual_range = Convert.ToInt32(visual_range); } model.is_parts = isParts; model.ext1 = jishihuifang; model.ext2 = duolubofang; model.ext3 = shangdaqiang; model.ext4 = lishihuifang; model.update_status_time = DateTime.Now; bool result = deviceInfoBLL.UpdateDeviceInfo(model); return(Json(new { status = 0, msg = result })); } catch (Exception ex) { return(Json(new { status = 1, msg = ex.Message })); } }
///// <summary> ///// 新增设备告警(含有位置信息,区域信息) ///// </summary> ///// <param name="eventType"></param> ///// <param name="device_code"></param> ///// <param name="alarm_location"></param> ///// <param name="area_id"></param> ///// <param name="alarm_level"></param> ///// <param name="report_time"></param> ///// <param name="content"></param> ///// <returns></returns> //public bool AddInformAlarm(int eventType, string device_code, string alarm_location, int area_id, int alarm_level, string content) //{ // try // { // ServInformAlarmModel model = new ServInformAlarmModel(); // model.alarm_level = alarm_level; // model.alarm_location = alarm_location; // model.area_id = area_id; // model.content = content; // model.device_code = device_code; // model.event_type = eventType; // model.report_time = DateTime.Now; // model.status = (int)EnumClass.InformAlarmStatus.未处理; // int res = servInformAlarmDal.AddEntity(model); // if (res > 0) // { // return true; // } // else // { // return false; // } // } // catch (Exception ex) // { // throw ex; // } //} /// <summary> /// 页面发送模拟报警至转发层 /// </summary> /// <param name="alarmLevel"></param> /// <param name="deviceCode"></param> /// <param name="content"></param> /// <param name="eventCode"></param> /// <returns></returns> public bool AddDeviceAlarm(string alarmName, int alarmLevel, string deviceCode, string content, string eventCode) { try { sendAlarmPageDele = new SendAlarmPageDele(CSM.Utils.HttpHelper.PostJsonData); string url = System.Configuration.ConfigurationManager.AppSettings["InterfaceUrl"] + "/api/Interface/Forward"; ServDeviceInfoDAL deviceDal = new ServDeviceInfoDAL(); AlarmInfoModel alarmModel = new AlarmInfoModel(); InterfaceData data = new InterfaceData(); ServDeviceInfoModel deviceModel = deviceDal.GetDeviceByDeviceCode(deviceCode); alarmModel.alarm_cache_status = 0; alarmModel.alarm_event = eventCode; alarmModel.alarm_level = alarmLevel; alarmModel.alarm_location = ""; alarmModel.alarm_name = alarmName; alarmModel.alarm_subsystem = deviceModel.subsystem_id; alarmModel.alarm_text = content; alarmModel.alarm_time = DateTime.Now; alarmModel.alarm_type = (int)EnumClass.AlarmType.设备报警; alarmModel.code = deviceCode; data.data = alarmModel; data.dataType = 1; data.subSysType = deviceModel.subsystem_id; data.mark = "pageMoniter"; string param = CSM.Utils.JsonHelper.ObjectToString(data); sendAlarmPageDele.BeginInvoke(url, param, Encoding.UTF8, null, null); return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// 修改设备信息(设备列表页面,不可修改坐标等信息) /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateDeviceInfo(ServDeviceInfoModel model) { try { return(mapContext.Update("UpdateDeviceInfoListPage", model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据设备code查询设备 /// </summary> /// <param name="code"></param> /// <returns></returns> public JsonResult GetDeviceInfoByDeviceCode(string code) { try { ServDeviceInfoModel device = deviceInfoBLL.GetDeviceInfoByDeviceCode(code); return(Json(new { status = 0, msg = device })); } catch (Exception ex) { return(Json(new { status = 1, msg = ex.Message })); } }
/// <summary> /// 根据id获取设备数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonResult GetDeviceInfoById(int id) { try { ServDeviceInfoModel device = deviceInfoBLL.GetDeviceInfoById(id); return(Json(new { status = 0, msg = device })); } catch (Exception ex) { return(Json(new { status = 1, msg = ex.Message })); } }
/// <summary> /// 添加设备 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int AddEntity(ServDeviceInfoModel entity) { try { int id = (int)mapContext.Insert("InsertDeviceInfo", entity); return(id); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据设备code查询设备 /// </summary> /// <param name="code"></param> public ServDeviceInfoModel GetDeviceInfoByDeviceCode(string code) { try { ServDeviceInfoModel deviceModel = servDeviceInfoDAL.GetEntity(code); return(deviceModel); } catch (Exception ex) { throw ex; } }
/// <summary> /// 注册25D设备 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool registerDevice25D(ServDeviceInfoModel model) { try { bool result = servDeviceInfoDAL.RegisterDevice25D(model); return(result); } catch (Exception) { throw; } }
/// <summary> /// 修改设备 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateDeviceInfoById(ServDeviceInfoModel model) { try { int result = mapContext.Update("UpdateDeviceInfo", model); return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 修改设备信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateDeviceInfo(ServDeviceInfoModel model) { try { bool result = false; int num = servDeviceInfoDAL.UpdateDeviceInfo(model); result = true; return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 2D设备注册 /// </summary> /// <returns></returns> public ServDeviceInfoModel AddDevice2D(ServDeviceInfoQuery deviceInfo, int deviceTempID) { try { if (deviceInfo.device_code == "")//其他设备(非摄像头) { //提取中文首字母 ConvertChinese chinese = new ConvertChinese(); string codes = chinese.GetHeadOfChs(Enum.GetName(typeof(BaseDeviceType), deviceInfo.device_type)); //根据基础设备类型取出设备表中该类型所有的设备计算设备code List <ServDeviceInfoModel> servDeviceList = servDeviceInfoDAL.GetDeviceInfoLikeCode(codes); string lastDeviceCode = ""; if (servDeviceList.Count > 0) { for (int i = servDeviceList.Count - 1; i >= 0; i--)//取出最后一条设备数据 { if (servDeviceList[i].device_code.Substring(0, codes.Length) == codes) { lastDeviceCode = servDeviceList[i].device_code; break; } } if (lastDeviceCode.IndexOf(codes) >= 0) { int codeID = Convert.ToInt32(lastDeviceCode.Substring(codes.Length, lastDeviceCode.Length - codes.Length)); deviceInfo.device_code = codes + (codeID + 1); } } else { deviceInfo.device_code = codes + 1; } } int id = servDeviceInfoDAL.AddEntity(deviceInfo); if (id != 0) { //删除设备临时表数据 int num = servTempDeviceDAL.DeleteTempDeviceById(deviceTempID); } ServDeviceInfoModel model = new ServDeviceInfoModel(); model.id = id; model.device_code = deviceInfo.device_code; return(model); } catch (Exception) { throw; } }
/// <summary> /// 注册2.5D的设备 /// </summary> /// <param name="id">id</param> /// <param name="local_longitude">25D坐标</param> /// <param name="local_latitude">25D坐标</param> /// <returns></returns> public JsonResult registerDevice25D(int id, string local_longitude, string local_latitude) { try { ServDeviceInfoModel model = new ServDeviceInfoModel(); model.id = id; model.local_longitude = local_longitude; model.local_latitude = local_latitude; bool result = mapRegisterBLL.registerDevice25D(model); return(Json(result)); } catch (Exception ex) { return(Json(new { state = 1, message = ex.Message })); } }
/// <summary> /// 页面发送模拟报警至转发层 /// </summary> /// <param name="alarmLevel"></param> /// <param name="deviceCode"></param> /// <param name="content"></param> /// <param name="eventCode"></param> /// <returns></returns> public RetMsgModel AddMapDeviceAlarm(string alarmName, int alarmLevel, string deviceCode, string content, string eventCode) { try { RetMsgModel retModel = new RetMsgModel(); sendAlarmPageDele = new SendAlarmPageDele(CSM.Utils.HttpHelper.PostJsonData); string url = System.Configuration.ConfigurationManager.AppSettings["InterfaceUrl"] + "/api/Interface/Forward"; ServDeviceInfoDAL deviceDal = new ServDeviceInfoDAL(); AlarmInfoModel alarmModel = new AlarmInfoModel(); InterfaceData data = new InterfaceData(); ServDeviceInfoModel deviceModel = deviceDal.GetDeviceByDeviceCode(deviceCode); alarmModel.alarm_cache_status = 0; alarmModel.alarm_event = eventCode; alarmModel.alarm_level = alarmLevel; alarmModel.alarm_location = ""; alarmModel.alarm_name = alarmName; alarmModel.alarm_subsystem = deviceModel.subsystem_id; alarmModel.alarm_text = content; alarmModel.alarm_time = DateTime.Now; alarmModel.alarm_type = (int)EnumClass.AlarmType.设备报警; alarmModel.code = deviceCode; data.data = alarmModel; data.dataType = 1; data.subSysType = deviceModel.subsystem_id; data.mark = "pageMoniter"; string param = CSM.Utils.JsonHelper.ObjectToString(data); //sendAlarmPageDele.BeginInvoke(url, param, Encoding.UTF8, null, null); string ret = Utils.HttpHelper.PostWebRequestBandError(url, param, "application/json;charset=utf-8", Encoding.UTF8); if (string.IsNullOrEmpty(ret)) { retModel.status = 1; retModel.message = "调用转发层返回值为空!"; } else { retModel = Utils.JsonHelper.StringToObject <RetMsgModel>(ret); } return(retModel); } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新设备的2.5D的坐标 /// </summary> /// <param name="id"></param> /// <param name="local_longitude"></param> /// <param name="local_latitude"></param> /// <returns></returns> public bool RegisterDevice25D(ServDeviceInfoModel model) { try { int result = mapContext.Update("RegisterDeviceInfo25D", model); if (result > 0) { return(true); } else { return(false); } } catch (Exception) { throw; } }
/// <summary> /// 宇视更新未注册设备列表 /// </summary> /// <param name="xml"></param> public void UpdateUnRegisterDevice(string xml, string servIp, int regionId, out int total) { try { XmlDocument videoXml = new XmlDocument(); videoXml.LoadXml(xml); XmlNode resNode = videoXml.SelectSingleNode("ResList"); //资源总数 total = Convert.ToInt32(((XmlElement)resNode).GetAttribute("count")); XmlNodeList itemList = resNode.ChildNodes; foreach (XmlNode item in itemList) { ServTempDeviceModel model = new ServTempDeviceModel(); XmlElement resCode = (XmlElement)item.SelectSingleNode("ResCode"); model.device_code = resCode.InnerText; XmlElement resName = (XmlElement)item.SelectSingleNode("ResName"); model.device_name = resName.InnerText; XmlElement ResType = (XmlElement)item.SelectSingleNode("ResType"); string resType = ResType.InnerText; if (resType == "1001") { XmlElement resSubType = (XmlElement)item.SelectSingleNode("ResSubType"); model.device_type = Convert.ToInt32(resSubType.InnerText); } else if (resType == "14") { model.device_type = 5; } model.subsystem_id = (int)SubSystem.视频子系统; model.create_time = DateTime.Now; ConvertChinese convertchinese = new ConvertChinese(); model.search_code = convertchinese.GetHeadOfChs(model.device_name); model.ext1 = servIp; //判断该条数据是否在未注册设备表 int num = servTempDeviceDAL.GetTempDeviceByCode(model.device_code); int deviceNum = 0; //判断该条数据是否在已注册设备表中已存在 ServDeviceInfoModel deviceModel = servDeviceInfoDAL.GetEntity(model.device_code); if (deviceModel != null) { deviceNum = 1; } //在设备临时表和已注册的设备列表中都不存在则往临时表中写入数据 if (model.device_type == 5)//监视器 { if (deviceNum == 0 && num == 0) { //直接添加到已注册设备列表中 ServDeviceInfoModel deviceInfo = new ServDeviceInfoModel(); deviceInfo.device_name = model.device_name; deviceInfo.device_code = model.device_code; deviceInfo.device_type = 5; deviceInfo.device_status = Convert.ToInt32(((XmlElement)item.SelectSingleNode("ResStatus")).InnerText); deviceInfo.subsystem_id = model.subsystem_id; deviceInfo.is_parts = -2; deviceInfo.register_time = DateTime.Now; deviceInfo.create_time = DateTime.Now; deviceInfo.search_code = convertchinese.GetHeadOfChs(deviceInfo.device_name); deviceInfo.region_id = regionId; deviceInfo.local_longitude = ""; deviceInfo.local_latitude = ""; deviceInfo.cover_range = 0; deviceInfo.update_status_time = DateTime.Now; deviceInfo.camera_towards = 0; deviceInfo.visual_range = 0; deviceInfo.asset_code = ""; deviceInfo.org_id = 0; deviceInfo.guarantee_time = DateTime.Now; deviceInfo.asset_status = 1; deviceInfo.manager_id = 0; deviceInfo.is_inbuilding = 0; deviceInfo.room_id = 0; deviceInfo.area_id = 0; int deId = servDeviceInfoDAL.AddEntity(deviceInfo); } } else { if (deviceNum == 0 && num == 0) { servTempDeviceDAL.AddEntity(model); } } } } catch (Exception ex) { throw ex; } }
/// <summary> /// 处理报警数据 /// </summary> /// <param name="alarmRecord"></param> public void HandlePlan(ServAlarmRecordModel alarmRecord) { try { ServExecutionTimeDAL executeTimeDal = new ServExecutionTimeDAL(); ServDeviceInfoModel deviceInfo = GetDeviceInfo(alarmRecord.alarm_code); BaseRegionConfigDAL baseRegionConfigDal = new BaseRegionConfigDAL(); if (deviceInfo != null) { BaseRegionConfigModel regionModel = baseRegionConfigDal.GetEntity(deviceInfo.region_id); //获取设备所在园区 int parentEventId = GetParentEvent(alarmRecord.alarm_event); //获取父级事件ID //查找设备预案 string alarmTime = alarmRecord.alarm_time.ToLocalTime().ToString("HH:mm:ss"); var devicePlans = CheckDevicePlanIsExist(deviceInfo.id, (int)EnumClass.PlanStatus.启用, alarmTime); DevicePlanAndTimeConfig devicePlan = devicePlans == null ? null : devicePlans.FirstOrDefault(); //目前取第一条设备预案 if (devicePlan != null) { #region 检验时间表达式 //if (TimeExpression.TimePointIsExistSpan(alarmRecord.alarm_time.ToLocalTime(), devicePlan.update_time, timeModel.execution_cycle)) //{ //} //else //{ // Log4NetHelp.Info("报警时间未在设置周期内,报警时间:" + alarmRecord.alarm_time.ToLocalTime().ToString() + " 开始时间:" + devicePlan.update_time + " 时间表达式:" + timeModel.execution_cycle); //} #endregion List <ServPlanHandleItemModel> planHandleItemList = GetPlanHandleItem(devicePlan.id, (int)EnumClass.PlanType.设备预案, (int)EnumClass.PlanHandleTime.确警前); if (planHandleItemList != null && planHandleItemList.Count != 0) { //执行设备预案,写入预案执行记录 PlanBLL planBll = new PlanBLL(); int planRecordId = planBll.AddPlanRecord(alarmRecord.id, devicePlan.id, (int)EnumClass.PlanType.设备预案); if (planRecordId > 0) { List <ServDeviceInfoModel> camerasList = null; string ledMessage = ""; HandleDevicePlanItem(planRecordId, parentEventId, regionModel, planHandleItemList, deviceInfo, alarmRecord, out camerasList, out ledMessage); // Hashtable hash = HandleDevicePlanItem(planRecordId, planHandleItemList, deviceInfo, alarmRecord,out camerasList,out ledMessage); if (hash != null && hash.Count != 0) { WebSocketMsgModel webMsg = new WebSocketMsgModel(); DevicePlanMsgModel devicePlanMsg = new DevicePlanMsgModel(); devicePlanMsg.hash = hash; devicePlanMsg.alarm = alarmRecord; devicePlanMsg.deviceInfo = deviceInfo; // devicePlanMsg.videoTime = GetAlarmVideoTime(alarmRecord.alarm_event); devicePlanMsg.videoTime = GetAlarmVideoTime(parentEventId); devicePlanMsg.camerasList = camerasList; devicePlanMsg.ledMessage = ledMessage; //用于页面显示滚动条信息 // string devicePlanMsgStr = JsonHelper.ObjectToString(devicePlanMsg); webMsg.info = devicePlanMsg; webMsg.type = (int)EnumClass.WebSocketMsgType.设备预案; string param = JsonHelper.ObjectToString(webMsg); HttpHelper.PostJsonData(SubSystemRouteBLL.GetToWebsocketRoute(), param, Encoding.UTF8); } } } else { //log:未找到相应设备预案处置项 Log4NetHelp.Info("未找到对应设备预案处置项:" + alarmRecord.alarm_code); } } else { //log 未找到设备预案或者设备预案未启用 //TODO 查找事件预案 Log4NetHelp.Info("未找到当前时间段内配置的设备预案或者设备预案未启用,继续查找事件预案"); //int parentEventId = GetParentEvent(alarmRecord.alarm_event); //获取父级事件ID if (parentEventId != -1) { var eventPlans = CheckEventPlanIsExist(alarmTime, parentEventId, (int)EnumClass.PlanStatus.启用, regionModel.id); EventPlanAndTimeConfig eventPlan = eventPlans == null ? null : eventPlans.FirstOrDefault();//目前取第一条设备预案 if (eventPlan != null) { List <ServPlanHandleItemModel> planHandleItemList = GetPlanHandleItem(eventPlan.id, (int)EnumClass.PlanType.事件预案, (int)EnumClass.PlanHandleTime.确警前);//获取事件预案处置项 if (planHandleItemList != null && planHandleItemList.Count != 0) { //执行事件预案,写入预案执行记录 PlanBLL planBll = new PlanBLL(); int planRecordId = planBll.AddPlanRecord(alarmRecord.id, eventPlan.id, (int)EnumClass.PlanType.事件预案); if (planRecordId > 0) { List <ServDeviceInfoModel> camerasList = null; string ledMessage = ""; HandleEventPlanItem(planRecordId, parentEventId, regionModel, planHandleItemList, deviceInfo, alarmRecord, out camerasList, out ledMessage); // Hashtable hash = HandleDevicePlanItem(planRecordId, planHandleItemList, deviceInfo, alarmRecord,out camerasList,out ledMessage); if (hash != null && hash.Count != 0) { WebSocketMsgModel webMsg = new WebSocketMsgModel(); DevicePlanMsgModel devicePlanMsg = new DevicePlanMsgModel(); devicePlanMsg.hash = hash; devicePlanMsg.alarm = alarmRecord; devicePlanMsg.deviceInfo = deviceInfo; // devicePlanMsg.videoTime = GetAlarmVideoTime(alarmRecord.alarm_event); devicePlanMsg.videoTime = GetAlarmVideoTime(parentEventId); devicePlanMsg.camerasList = camerasList; devicePlanMsg.ledMessage = ledMessage; //用于页面显示滚动条信息 // string devicePlanMsgStr = JsonHelper.ObjectToString(devicePlanMsg); webMsg.info = devicePlanMsg; webMsg.type = (int)EnumClass.WebSocketMsgType.事件预案; string param = JsonHelper.ObjectToString(webMsg); HttpHelper.PostJsonData(SubSystemRouteBLL.GetToWebsocketRoute(), param, Encoding.UTF8); } } } else { Log4NetHelp.Info("未找到对应事件预案处置项,事件ID:" + alarmRecord.alarm_event + " 园区ID:" + regionModel.id + " 报警时间:" + alarmTime); } } else { Log4NetHelp.Info("未找到对应事件预案,事件ID:" + alarmRecord.alarm_event + " 园区ID:" + regionModel.id + " 报警时间:" + alarmTime); } } else { Log4NetHelp.Info("未找到对应事件,事件ID:" + alarmRecord.alarm_event); } } } else { //log:未找到设备alarmRecord.alarm_code Log4NetHelp.Info("未找到设备:" + alarmRecord.alarm_code); } } catch (Exception ex) { // Log4NetHelp.Error("业务层处理报警数据失败!" + ex.Message); Log4NetHelp.Error("业务层处理报警数据失败!" + ex.Message); } }
/// <summary> /// 执行设备预案处置项 /// </summary> /// <param name="itemList"></param> /// <returns></returns> public void HandleDevicePlanItem(int planRecordId, int eventId, BaseRegionConfigModel regionModel, List <ServPlanHandleItemModel> itemList, ServDeviceInfoModel deviceInfo, ServAlarmRecordModel alarmRecord, out List <ServDeviceInfoModel> camerasList, out string ledMessage) { try { PlanItemBLL planItemBll = new PlanItemBLL(); ServPlanHandleItemModel handleItemModel = itemList.FirstOrDefault(n => n.item_type == (int)EnumClass.DevicePlanDefaultOptions.关联摄像头); if (handleItemModel != null) { HandleCamerasBLL camerasbll = new HandleCamerasBLL(); camerasList = camerasbll.GetCameras(handleItemModel.id); } else { camerasList = null; } LEDHandle ledHandle = new LEDHandle(deviceInfo, alarmRecord); ledMessage = ledHandle.GetAlarmText(); foreach (ServPlanHandleItemModel item in itemList) { switch (item.item_type) { case (int)EnumClass.DevicePlanDefaultOptions.中控室LED信息显示: // string content = ""; // LEDHandle ledHandle = new LEDHandle(deviceInfo, alarmRecord); bool ledResult = ledHandle.HandleLedItem(ledMessage, regionModel.region_code); //处理LED planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.成功, item.item_type, planRecordId, ledMessage); //if (!ht.ContainsKey(item.item_type)) //{ // ht.Add(item.item_type, new { status = 1, info = "" });//已执行 //} //else //{ // Log4NetHelp.Info("处置项重复:" + Enum.Parse(typeof(EnumClass.DevicePlanDefaultOptions), item.item_type.ToString()).ToString()); //} AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.DevicePlanDefaultOptions.关联摄像头: // ht.Add(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId });//未执行 AddHashTable(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId }); break; case (int)EnumClass.DevicePlanDefaultOptions.告警视频下载: int handleDownloadRecordId = planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.成功, item.item_type, planRecordId, ""); if (handleDownloadRecordId > 0) //插入处置项记录成功,开始执行处置项 { VideoDownloadBLL videoDownloadBll = new VideoDownloadBLL(); bool bl = videoDownloadBll.VideoDownload(handleDownloadRecordId, eventId, alarmRecord.alarm_time.ToLocalTime(), camerasList); } // ht.Add(item.item_type, new { status = 1, info = "" });//已执行 AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.DevicePlanDefaultOptions.打开告警设备附近视频: // ht.Add(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId, info = "" });//未执行 AddHashTable(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId, info = "" }); break; case (int)EnumClass.DevicePlanDefaultOptions.控制中心声光蜂鸣器开启: HandleRelayBLL handleRelayBll = new HandleRelayBLL(); handleRelayBll.HandleRelay(item.ext1, regionModel.region_code); planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.成功, item.item_type, planRecordId, ""); // ht.Add(item.item_type, new { status = 1, info = "" });//已执行 AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.DevicePlanDefaultOptions.相关摄像头上大屏: // ht.Add(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId, info = "" });//未执行 AddHashTable(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId, info = "" }); break; case (int)EnumClass.DevicePlanDefaultOptions.通知其他负责人: PlanPersonBLL planPersonBll = new PlanPersonBLL(); int handlePersonRecordId = planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.失败, item.item_type, planRecordId, "暂未设置短信平台"); if (handlePersonRecordId > 0) //插入处置项记录成功,开始执行处置项 { bool bl = planPersonBll.HandlePlanPerson(item.id, alarmRecord, handlePersonRecordId); } // ht.Add(item.item_type, new { status = 1, info = "" }); AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.DevicePlanDefaultOptions.通知设备网格第一负责人: //查找第一负责人,发送短信,记录短信记录与执行结果 // planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, item.item_type, planRecordId, ""); // ht.Add(item.item_type, new { status = 1, info = "" }); int dutyPersonRecordId = planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.失败, item.item_type, planRecordId, "暂未设置短信平台"); AddHashTable(item.item_type, new { status = 1, info = "" }); break; default: break; } } } catch (Exception ex) { camerasList = null; ledMessage = ""; Log4NetHelp.Info("处理设备预案失败!报警记录ID:" + planRecordId + " " + ex.Message); } // return ht; }
public LEDHandle(ServDeviceInfoModel deviceInfo, ServAlarmRecordModel alarmRecord) { _deviceInfo = deviceInfo; _alarmRecord = alarmRecord; }
public bool UpdateEntity(int id, ServDeviceInfoModel newentity) { throw new NotImplementedException(); }
/// <summary> /// 获取设备分组树,设备列表页面 /// </summary> /// <param name="query">查询条件</param> /// <param name="pageType">页面标识(设备列表:0;视频监控页面:1)</param> /// <returns></returns> public List <DeviceGroupTreeCustom> GetDeviceGroupTree(ServDeviceGroupInfoQuery query, int industryId, int pageType) { try { //分组树结构集合 List <DeviceGroupTreeCustom> deviceGroupTreeList = new List <DeviceGroupTreeCustom>(); //获取所有的分组 List <ServDeviceGroupInfoModel> deviceGroupList = servDeviceGroupInfoDAL.GetDeviceGroupInfo(query); //获取行业下该园区的所有的设备 ServDeviceInfoQuery deviceQuery = new ServDeviceInfoQuery(); deviceQuery.area_id = industryId; //行业id deviceQuery.region_id = query.region_id; //园区id List <ServDeviceInfoModel> deviceInfoList = servDeviceInfoDAL.GetAllDeviceInfoByIndustry(deviceQuery); if (pageType == 1) //视频监控页面只取摄像头 { deviceInfoList = deviceInfoList.Where(n => n.device_type < 5).ToList(); } DeviceGroupTreeCustom deviceGroupTree; for (int i = 0; i < deviceGroupList.Count; i++) { deviceGroupTree = new DeviceGroupTreeCustom(); deviceGroupTree.id = deviceGroupList[i].id; deviceGroupTree.name = deviceGroupList[i].group_name; deviceGroupTree.sid = deviceGroupList[i].id; deviceGroupTree.pid = deviceGroupList[i].pid; deviceGroupTree.device_code = ""; deviceGroupTree.iconOpen = "../images/groupIcon/文件夹开.png"; deviceGroupTree.iconClose = "../images/groupIcon/文件夹闭.png"; //根据设备分组id获取分组和设备的绑定 List <ServDeviceRelateModel> relateList = servDeviceRelateDAL.GetDeviceRelateByGroupId(deviceGroupList[i].id); if (pageType == 1) //视频监控页面 { List <ServDeviceInfoModel> deviceList = new List <ServDeviceInfoModel>(); //如果分组下没有设备则不添加分组 for (int j = 0; j < relateList.Count; j++) { ServDeviceInfoModel deviceModel = deviceInfoList.Where(n => n.id == relateList[j].device_id).FirstOrDefault(); if (deviceModel != null) { deviceList.Add(deviceModel); } } if (deviceList.Count != 0) { deviceGroupTreeList.Add(deviceGroupTree); } } else//设备列表页面 { deviceGroupTreeList.Add(deviceGroupTree); } for (int j = 0; j < relateList.Count; j++) { ServDeviceInfoModel deviceModel = deviceInfoList.Where(n => n.id == relateList[j].device_id).FirstOrDefault(); if (deviceModel != null) { deviceGroupTree = new DeviceGroupTreeCustom(); deviceGroupTree.id = deviceModel.id; deviceGroupTree.name = deviceModel.device_name; deviceGroupTree.sid = 0; deviceGroupTree.pid = deviceGroupList[i].id; deviceGroupTree.device_code = deviceModel.device_code; deviceGroupTree.rank = relateList[j].rank; switch (deviceModel.device_type) { case 1: case 2: case 3: case 4: deviceGroupTree.icon = "../images/groupIcon/摄像头.png"; break; case 5: case 6: deviceGroupTree.icon = "../images/groupIcon/门禁.png"; break; case 7: case 9: case 14: deviceGroupTree.icon = "../images/groupIcon/手报.png"; break; case 8: case 12: deviceGroupTree.icon = "../images/groupIcon/卡口.png"; break; case 10: case 11: deviceGroupTree.icon = "../images/groupIcon/消防栓.png"; break; case 13: deviceGroupTree.icon = "../images/groupIcon/水表.png"; break; case 15: case 19: deviceGroupTree.icon = "../images/groupIcon/巡更点.png"; break; case 16: deviceGroupTree.icon = "../images/groupIcon/烟感.png"; break; case 17: deviceGroupTree.icon = "../images/groupIcon/广播.png"; break; case 18: deviceGroupTree.icon = "../images/groupIcon/红外对射探测器.png"; break; } deviceGroupTreeList.Add(deviceGroupTree); deviceInfoList.Remove(deviceModel); } } } //将剩余未分组的设备加入树结构 for (int i = 0; i < deviceInfoList.Count; i++) { deviceGroupTree = new DeviceGroupTreeCustom(); deviceGroupTree.id = deviceInfoList[i].id; deviceGroupTree.name = deviceInfoList[i].device_name; deviceGroupTree.device_code = deviceInfoList[i].device_code; deviceGroupTree.sid = -2; deviceGroupTree.pid = 0; switch (deviceInfoList[i].device_type) { case 1: case 2: case 3: case 4: deviceGroupTree.icon = "../images/groupIcon/摄像头.png"; break; case 5: case 6: deviceGroupTree.icon = "../images/groupIcon/门禁.png"; break; case 7: case 9: case 14: deviceGroupTree.icon = "../images/groupIcon/手报.png"; break; case 8: case 12: deviceGroupTree.icon = "../images/groupIcon/卡口.png"; break; case 10: case 11: deviceGroupTree.icon = "../images/groupIcon/消防栓.png"; break; case 13: deviceGroupTree.icon = "../images/groupIcon/水表.png"; break; case 15: case 19: deviceGroupTree.icon = "../images/groupIcon/巡更点.png"; break; case 16: deviceGroupTree.icon = "../images/groupIcon/烟感.png"; break; case 17: deviceGroupTree.icon = "../images/groupIcon/广播.png"; break; case 18: deviceGroupTree.icon = "../images/groupIcon/红外对射探测器.png"; break; } deviceGroupTreeList.Add(deviceGroupTree); } //加入一个未分组的树结构 deviceGroupTree = new DeviceGroupTreeCustom(); deviceGroupTree.id = 0; deviceGroupTree.name = "未分组设备"; deviceGroupTree.device_code = ""; deviceGroupTree.sid = 0; deviceGroupTree.pid = -1; deviceGroupTree.iconOpen = "../images/groupIcon/文件夹开.png"; deviceGroupTree.iconClose = "../images/groupIcon/文件夹闭.png"; deviceGroupTreeList.Add(deviceGroupTree); return(deviceGroupTreeList); } catch (Exception ex) { throw ex; } }
/// <summary> /// 设备注册2D /// </summary> /// <param name="device_name">设备名称</param> /// <param name="device_code">设备编码</param> /// <param name="device_type">设备类型</param> /// <param name="subsystem_id">子系统</param> /// <param name="device_status">设备状态</param> /// <param name="cover_range">覆盖角度</param> /// <param name="camera_towards">设备朝向</param> /// <param name="visual_range">覆盖角度</param> /// <param name="is_inbuilding">是否楼内</param> /// <param name="lonLat">坐标</param> /// <param name="isParts">是否复合设备</param> /// <param name="regionID">园区id</param> /// <param name="jishihuifang">及时回放</param> /// <param name="duolubofang">多路播放</param> /// <param name="shangdaqiang">上大墙</param> /// <param name="lishihuifang">历史回放</param> /// <param name="deviceTempID">设备临时表id</param> /// <param name="industryId">行业id</param> /// <returns></returns> public JsonResult AddDevice2D(string device_name, string device_code, int device_type, int subsystem_id, int device_status, int cover_range, int camera_towards, int visual_range, int is_inbuilding, string lonLat, int isParts, int regionID, string jishihuifang, string duolubofang, string shangdaqiang, string lishihuifang, int deviceTempID, int industryId) { try { ServDeviceInfoQuery deviceInfo = new ServDeviceInfoQuery(); if (device_code != "") { //验证设备code是否已经存在 ServDeviceInfoModel deviceInfoModel = mapRegisterBLL.GetDeviceInfoByDeviceCode(device_code); if (deviceInfoModel != null) { return(Json(new { state = 2, message = "该设备code已存在" })); } deviceInfo.device_code = device_code; } else { deviceInfo.device_code = device_code; } deviceInfo.is_parts = isParts; deviceInfo.device_name = device_name; deviceInfo.device_type = device_type; deviceInfo.subsystem_id = subsystem_id; deviceInfo.longitude = lonLat.Split(',')[1]; deviceInfo.latitude = lonLat.Split(',')[0]; deviceInfo.register_time = DateTime.Now.ToString(); deviceInfo.search_code = ""; deviceInfo.local_longitude = null; deviceInfo.local_latitude = null; deviceInfo.device_status = device_status; deviceInfo.update_status_time = ""; deviceInfo.cover_range = cover_range; deviceInfo.camera_towards = camera_towards; deviceInfo.visual_range = visual_range; deviceInfo.asset_code = ""; deviceInfo.org_id = 0; deviceInfo.manufactor = ""; deviceInfo.asset_model = ""; deviceInfo.create_time = ""; deviceInfo.guarantee_time = ""; deviceInfo.asset_status = 0; deviceInfo.asset_ip = ""; deviceInfo.port = ""; deviceInfo.mac_code = ""; deviceInfo.serial_number = ""; deviceInfo.manager_id = 0; deviceInfo.is_inbuilding = is_inbuilding; deviceInfo.room_id = 0; deviceInfo.region_id = regionID; deviceInfo.area_id = 0; deviceInfo.ext1 = jishihuifang; deviceInfo.ext2 = duolubofang; deviceInfo.ext3 = shangdaqiang; deviceInfo.ext4 = lishihuifang; //根据设备类型查询设备图标地址 ServDefinedDeviceModel definedDevice = mapRegisterBLL.GetDeviceIcon(industryId, device_type); string path = definedDevice == null ? "" : definedDevice.normal_image; ServDeviceInfoModel model = mapRegisterBLL.AddDevice2D(deviceInfo, deviceTempID); return(Json(new { id = model.id, device_code = model.device_code, iconPath = path })); } catch (Exception ex) { return(Json(new { state = 1, message = ex.Message })); } }
/// <summary> /// 查找事件预案并处理 /// </summary> public void HandleEventPlanItem(int planRecordId, int eventId, BaseRegionConfigModel regionModel, List <ServPlanHandleItemModel> planHandleItemList, ServDeviceInfoModel deviceInfo, ServAlarmRecordModel alarmRecord, out List <ServDeviceInfoModel> camerasList, out string ledMessage) { try { PlanItemBLL planItemBll = new PlanItemBLL(); //ServPlanHandleItemModel handleItemModel = planHandleItemList.FirstOrDefault(n => n.item_type == (int)EnumClass.EventPlanDefaultOptions.打开周围摄像头); //if (handleItemModel != null) //{ // HandleCamerasBLL camerasbll = new HandleCamerasBLL(); // camerasList = camerasbll.GetEventPlanCameras(deviceInfo.id, int.Parse(handleItemModel.ext2), int.Parse(handleItemModel.ext3), int.Parse(handleItemModel.ext4)); //} //else //{ // camerasList = null; //} camerasList = null; LEDHandle ledHandle = new LEDHandle(deviceInfo, alarmRecord); ledMessage = ledHandle.GetAlarmText(); //单独处理打开周围摄像头 var cameraEventList = planHandleItemList.Where(n => n.item_type == (int)EnumClass.EventPlanDefaultOptions.打开周围摄像头); if (cameraEventList != null && cameraEventList.Count() > 0) { AddEventHashTable((int)EnumClass.EventPlanDefaultOptions.打开周围摄像头, new { status = 0, planRecordId = planRecordId, model = cameraEventList.ToList() }); } foreach (ServPlanHandleItemModel item in planHandleItemList) { switch (item.item_type) { case (int)EnumClass.EventPlanDefaultOptions.中控室LED信息显示: bool ledResult = ledHandle.HandleLedItem(ledMessage, regionModel.region_code); //处理LED planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.成功, item.item_type, planRecordId, ledMessage); AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.EventPlanDefaultOptions.告警视频下载: //int handleDownloadRecordId = planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, item.item_type, planRecordId, ""); //if (handleDownloadRecordId > 0) //插入处置项记录成功,开始执行处置项 //{ // VideoDownloadBLL videoDownloadBll = new VideoDownloadBLL(); // bool bl = videoDownloadBll.VideoDownload(handleDownloadRecordId, eventId, alarmRecord.alarm_time.ToLocalTime(), camerasList); //} //AddHashTable(item.item_type, new { status = 1, info = "" }); AddHashTable(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId }); break; //case (int)EnumClass.EventPlanDefaultOptions.打开周围摄像头: // AddEventHashTable(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId, model = item }); // break; case (int)EnumClass.EventPlanDefaultOptions.控制中心声光蜂鸣器开启: HandleRelayBLL handleRelayBll = new HandleRelayBLL(); handleRelayBll.HandleRelay(item.ext1, regionModel.region_code); planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.成功, item.item_type, planRecordId, ""); // ht.Add(item.item_type, new { status = 1, info = "" });//已执行 AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.EventPlanDefaultOptions.相关摄像头上大屏: AddHashTable(item.item_type, new { status = 0, itemid = item.id, itemType = item.item_type, planRecordId = planRecordId, info = "" }); break; case (int)EnumClass.EventPlanDefaultOptions.通知其他负责人: PlanPersonBLL planPersonBll = new PlanPersonBLL(); int handlePersonRecordId = planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.失败, item.item_type, planRecordId, "暂未设置短信平台"); if (handlePersonRecordId > 0) //插入处置项记录成功,开始执行处置项 { bool bl = planPersonBll.HandlePlanPerson(item.id, alarmRecord, handlePersonRecordId); } // ht.Add(item.item_type, new { status = 1, info = "" }); AddHashTable(item.item_type, new { status = 1, info = "" }); break; case (int)EnumClass.EventPlanDefaultOptions.通知设备网格第一负责人: int firstDutyRecordId = planItemBll.AddItemRecord((int)EnumClass.PlanHandleTime.确警前, item.id, (int)EnumClass.PlanItemResult.失败, item.item_type, planRecordId, "暂未设置短信平台"); AddHashTable(item.item_type, new { status = 1, info = "" }); break; default: break; } } } catch (Exception ex) { camerasList = null; ledMessage = ""; Log4NetHelp.Info("处理事件预案失败!预案执行记录ID:" + planRecordId + " " + ex.Message); } }
/// <summary> /// 通过设备的id得到设备周围的摄像头 /// </summary> /// <param name="id">目标设备的id</param> /// <param name="distance">距离,单位为m</param> /// <returns></returns> public List <ServDeviceInfoModel> GetDeviceNearCameraByDeviceId(int id, int distance) { try { //返回的结果 List <ServDeviceInfoModel> resultCamera = new List <ServDeviceInfoModel>(); //根据id查询到的设备 ServDeviceInfoModel targetDevice = new ServDeviceInfoModel(); targetDevice = GetDeviceNameById(id); if (targetDevice != null) { //查询到设备的经纬度 double tlat = double.Parse(targetDevice.latitude); double tlng = double.Parse(targetDevice.longitude); List <ServDeviceInfoModel> cameraModelList = new List <ServDeviceInfoModel>(); cameraModelList = servDeviceInfoDAL.GetDeviceNearCameraByDeviceId(id); for (int i = 0; i < cameraModelList.Count; i++) { ServDeviceInfoModel cameraDevice = cameraModelList[i]; if (targetDevice.is_inbuilding == -1 && cameraDevice.is_inbuilding == -1)//如果目标设备在楼外,则要求摄像头也要是楼外的 { if (!String.IsNullOrEmpty(cameraModelList[i].latitude) && !String.IsNullOrEmpty(cameraModelList[i].longitude)) { double clat = double.Parse(cameraModelList[i].latitude); double clng = double.Parse(cameraModelList[i].longitude); double d = GetDistance(tlat, tlng, clat, clng); if (d <= distance) { resultCamera.Add(cameraDevice); } } } //如果目标设备在楼内,则摄像头不做限定 else if (targetDevice.is_inbuilding != -1) { //如果是楼内的摄像头,将楼内的全部返回 if (cameraDevice.is_inbuilding == targetDevice.is_inbuilding) { resultCamera.Add(cameraDevice); } //如果不是楼内的则做距离的判断 else if (cameraDevice.is_inbuilding != targetDevice.is_inbuilding) { if (!String.IsNullOrEmpty(cameraModelList[i].latitude) && !String.IsNullOrEmpty(cameraModelList[i].longitude)) { double clat = double.Parse(cameraModelList[i].latitude); double clng = double.Parse(cameraModelList[i].longitude); double d = GetDistance(tlat, tlng, clat, clng); if (d <= distance) { resultCamera.Add(cameraDevice); } } } } } } return(resultCamera); } catch (Exception) { throw; } }
/// <summary> /// 处理丛文设备数据 /// </summary> /// <returns></returns> private bool HandleCowinDeviceData(object message, string mark) { try { List <DeviceModel> deviceList = JsonHelper.StringToObject <List <DeviceModel> >(message.ToString()); ServTempDeviceDAL tempDeviceDal = new ServTempDeviceDAL(); ServDeviceInfoDAL deviceInfoDal = new ServDeviceInfoDAL(); ConvertChinese convert = new ConvertChinese(); List <BaseDeviceTypeModel> typeList = null; try { typeList = baseMapConfigBLL.GetAllBaseDeviceTypeModel(); } catch (Exception ex) { Log4NetHelp.Error("获取基本设备类型失败!" + ex.Message); } for (int i = 0; i < deviceList.Count; i++) { //int tempNum = tempDeviceDal.GetTempDeviceByCode(deviceList[i].deviceCode); ServTempDeviceModel tempDevice = tempDeviceDal.GetTempDeviceByDeviceCode(deviceList[i].deviceCode); ServDeviceInfoModel deviceInfo = deviceInfoDal.GetDeviceByDeviceCode(deviceList[i].deviceCode); if (tempDevice == null && deviceInfo == null) { ServTempDeviceModel model = new ServTempDeviceModel(); var type = typeList.Where(n => n.type_name == deviceList[i].typeName).FirstOrDefault(); model.device_type = type == null ? 0 : type.id; model.create_time = DateTime.Now; model.device_code = deviceList[i].deviceCode; model.device_name = deviceList[i].deviceName; model.search_code = convert.GetHeadOfChs(deviceList[i].deviceName); model.subsystem_id = deviceList[i].subsystemId; model.ext1 = deviceList[i].serverIp; try { int res = tempDeviceDal.AddEntity(model); if (res == 0) { Log4NetHelp.Error("设备code:" + deviceList[i].deviceCode + " 设备名称:" + deviceList[i].deviceName + " 插入临时表失败!"); } else { Log4NetHelp.Info("设备code:" + deviceList[i].deviceCode + " 设备名称:" + deviceList[i].deviceName + " 插入临时表成功!"); } } catch (Exception ex) { Log4NetHelp.Error("设备code:" + deviceList[i].deviceCode + " 设备名称:" + deviceList[i].deviceName + " 插入临时表失败!" + ex.Message); } } else if (tempDevice != null) { Log4NetHelp.Error("设备code:" + deviceList[i].deviceCode + " 设备名称:" + deviceList[i].deviceName + " 在临时设备表已存在!"); } else if (deviceInfo != null) { Log4NetHelp.Error("设备code:" + deviceList[i].deviceCode + " 设备名称:" + deviceList[i].deviceName + " 在设备表已存在!"); } } return(true); } catch (Exception ex) { Log4NetHelp.Error("标识为:" + mark + "驱动同步丛文设备数据失败!" + ex.Message); return(false); } }