/// <summary> /// 室外 /// </summary> /// <param name="deviceEntity">设备实体</param> /// <param name="state">要改变成什么状态</param> /// <returns></returns> public static bool OutStateChangeByType(string appUser, hsf_outdevice deviceEntity, bool state) { switch (deviceEntity.devtype) { case "Dahua_UnitDoor": //大华单元门口机 return(DaHuaDeviceService.UnitDoorSendMsg(deviceEntity.deviceid)); case "Dahua_EntranceGuard": //门禁 return(DaHuaDeviceService.EntranceGuardSendMsg(deviceEntity.deviceid)); case "Elevator": //电梯 if (appUser.Split('-').Length >= 3) { string floor = appUser.Split('-')[3]; if (!string.IsNullOrEmpty(floor)) { return(ElevatorSendMsg(deviceEntity.deviceid, floor)); } } return(false); default: return(false); } }
public ActionResult Delete(string id) { if (id == null) { throw new Exception("Not Found"); } hsf_outdevice hsf_outdevice = ihsf_outdeviceService.Find <hsf_outdevice>(id); if (hsf_outdevice == null) { throw new Exception("Not Found"); } else { ihsf_outdeviceService.Delete(hsf_outdevice); using (RedisHashService service = new RedisHashService()) { //室外,大华产品 string _residential = hsf_outdevice.residential; //小区 string _building = hsf_outdevice.building; //楼号 string _unit = hsf_outdevice.unit; //单元 string cachekey = _residential + "-" + _building + "-" + _unit; //默认房间 //清除当前设备类型的设备列表缓存 service.RemoveEntryFromHash("OutDevices", cachekey); logger.Debug($"清除当前单元的室外设备列表 {cachekey}"); } } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "residential, building, unit, deviceid, chinaname, devtype")] hsf_outdevice hsf_outdevice) { if (ModelState.IsValid) { hsf_outdevice hsf_outdeviceDB = ihsf_outdeviceService.Find <hsf_outdevice>(hsf_outdevice.Id); hsf_outdeviceDB.residential = hsf_outdevice.residential; hsf_outdeviceDB.building = hsf_outdevice.building; hsf_outdeviceDB.unit = hsf_outdevice.unit; hsf_outdeviceDB.deviceid = hsf_outdevice.deviceid; hsf_outdeviceDB.chinaname = hsf_outdevice.chinaname; hsf_outdeviceDB.devtype = hsf_outdevice.devtype; hsf_outdeviceDB.createtime = DateTime.Now; ihsf_outdeviceService.Update(hsf_outdeviceDB); using (RedisHashService service = new RedisHashService()) { //室外,大华产品 string _residential = hsf_outdevice.residential; //小区 string _building = hsf_outdevice.building; //楼号 string _unit = hsf_outdevice.unit; //单元 string cachekey = _residential + "-" + _building + "-" + _unit; //默认房间 //清除当前设备类型的设备列表缓存 service.RemoveEntryFromHash("OutDevices", cachekey); logger.Debug($"清除当前单元的室外设备列表 {cachekey}"); } return(RedirectToAction("Index")); } else { throw new Exception("ModelState未通过检测"); } }
public ActionResult Details(string id) { if (id == null) { throw new Exception("need hsf_outdevice id"); } hsf_outdevice hsf_outdevice = ihsf_outdeviceService.Find <hsf_outdevice>(id); if (hsf_outdevice == null) { throw new Exception("Not Found hsf_outdevice"); } return(View(hsf_outdevice)); }
public ActionResult Create([Bind(Include = "Id, residential, building, unit, deviceid, chinaname, devtype")] hsf_outdevice hsf_outdevice) { if (ModelState.IsValid) { hsf_outdevice.createtime = DateTime.Now; hsf_outdevice.deletemark = 0; hsf_outdevice newhsf_outdevice = ihsf_outdeviceService.Insert(hsf_outdevice); return(RedirectToAction("Index")); } else { throw new Exception("ModelState未通过检测"); } }
public ActionResult Edit(string id) { if (id == null) { throw new Exception("need hsf_outdevice id"); } hsf_outdevice hsf_outdevice = ihsf_outdeviceService.Find <hsf_outdevice>(id);// ?? -1 if (hsf_outdevice == null) { throw new Exception("Not Found"); } //ViewBag.categoryList = BuildCategoryList(); return(View(hsf_outdevice)); }
/// <summary> /// user:MMSJ-1#1-5-501 type:other msg:MMSJ-1-1-5-501;8;8133;08$/r$ /// connect user:MMSJ-1-1-30-3001_C40BCB80050A type:other msg:MMSJ-1-1-30-3001_C40BCB80050A;8;8133;08$/r$ /// </summary> /// <param name="msg"></param> public static bool OutDeviceStateChange(string appUser, string deviceId) { try { bool state = true;//室外设备全是打开 using (RedisHashService service = new RedisHashService()) { string deviceEntityStr = service.GetValueFromHash("OutDeviceEntity", deviceId);//8231有关联,改mac的情况下,其它改状态,改名称,不需要清理 hsf_outdevice deviceEntity = null; if (!string.IsNullOrEmpty(deviceEntityStr)) { deviceEntity = JsonConvert.DeserializeObject <hsf_outdevice>(deviceEntityStr);//设备实体缓存 } else { using (HsfDBContext hsfDBContext = new HsfDBContext()) { deviceEntity = hsfDBContext.hsf_outdevice.Where(t => t.deviceid == deviceId && t.deletemark == 0).FirstOrDefault();//注意device的唯一性 if (deviceEntity != null) { //缓存设备id与设备实体对应关系,避免查询数据库 service.SetEntryInHash("OutDeviceEntity", deviceId, JsonConvert.SerializeObject(deviceEntity)); } } } if (deviceEntity != null) { //拼装1002指令,发送给网关,执行改变状态操作 return(ChangeStateMain.OutStateChangeByType(appUser, deviceEntity, state)); } else { return(false);//error } } } catch (Exception) { throw; } }
public JsonResult AjaxDelete(string id) { if (id == null) { throw new Exception("Not Found"); } hsf_outdevice hsf_outdevice = ihsf_outdeviceService.Find <hsf_outdevice>(id); if (hsf_outdevice == null) { throw new Exception("Not Found"); } else { ihsf_outdeviceService.Delete <hsf_outdevice>(id); using (RedisHashService service = new RedisHashService()) { //室外,大华产品 string _residential = hsf_outdevice.residential; //小区 string _building = hsf_outdevice.building; //楼号 string _unit = hsf_outdevice.unit; //单元 string cachekey = _residential + "-" + _building + "-" + _unit; //默认房间 //清除当前设备类型的设备列表缓存 service.RemoveEntryFromHash("OutDevices", cachekey); logger.Debug($"清除当前单元的室外设备列表 {cachekey}"); } AjaxResult ajaxResult = new AjaxResult() { Result = DoResult.Success, PromptMsg = "删除成功" }; return(Json(ajaxResult)); } }
public hsf_outdevice Create(hsf_outdevice hsf_Outdevice) { hsf_Outdevice.createtime = DateTime.Now; hsf_Outdevice.deletemark = 0; return(hsf_Outdevice); }
public ActionResult AjaxCreate([Bind(Include = "Id, residential, building, unit, deviceid, chinaname, devtype")] hsf_outdevice hsf_outdevice) { if (!string.IsNullOrEmpty(hsf_outdevice.deviceid)) { hsf_outdevice.Id = Guid.NewGuid().ToString(); hsf_outdevice.createtime = DateTime.Now; hsf_outdevice.deletemark = 0; hsf_outdevice newhsf_outdevice = ihsf_outdeviceService.Insert(hsf_outdevice); using (RedisHashService service = new RedisHashService()) { //室外,大华产品 string _residential = hsf_outdevice.residential; //小区 string _building = hsf_outdevice.building; //楼号 string _unit = hsf_outdevice.unit; //单元 string cachekey = _residential + "-" + _building + "-" + _unit; //默认房间 //清除当前设备类型的设备列表缓存 if (string.IsNullOrEmpty(_building) && string.IsNullOrEmpty(_unit)) { //MMSJ--,整个所在小区添加公共设备,比如公共摄像头,所有业主的缓存全部删除 List <string> ods = service.GetHashKeys("OutDevices"); foreach (var item in ods) { if (item.Contains(_residential)) { service.RemoveEntryFromHash("OutDevices", item); } } } else if (string.IsNullOrEmpty(_unit)) { //MMSJ-1-所在楼号添加公共设备,比如楼号摄像头,楼号内业主的缓存全部删除 List <string> ods = service.GetHashKeys("OutDevices"); foreach (var item in ods) { if (item.Contains(_residential + "-" + _building)) { service.RemoveEntryFromHash("OutDevices", item); } } } else { //MMSJ-1-1所在单元设备变动,比如单元门,单元内业主的缓存全部删除 service.RemoveEntryFromHash("OutDevices", cachekey); } logger.Debug($"清除当前单元的室外设备列表 {cachekey}"); } AjaxResult ajaxResult = new AjaxResult() { Result = DoResult.Success, PromptMsg = "插入成功" }; return(Json(ajaxResult)); } else { logger.Debug($"error:id不能为空!"); AjaxResult ajaxResult = new AjaxResult() { Result = DoResult.Failed, PromptMsg = "id不能为空" }; return(Json(ajaxResult)); } }