public ActionResult Detail(string code) { //WebsocketService.SendMessage(); var model = new SmokeDetailModel(); model.DetectorInfo = SmokeDetectorServices.LoadSmokeDetail(code); if (model.DetectorInfo == null || (CurrUser.CompanySysNo > 0 && CurrUser.CompanySysNo != model.DetectorInfo.CompanySysNo)) { model.HasError = true; model.ErrorMessage = "设备信息不存在"; } else { ClientFilter cFilter = new ClientFilter { SmokeDetectorCode = code, PageIndex = 0, PageSize = int.MaxValue }; if (CurrUser != null && CurrUser.CompanySysNo > 0) { cFilter.CompanySysNo = CurrUser.CompanySysNo; } model.ClientList = ClientService.QueryClientList(cFilter).data; //model.LogList = SmokeDetectorServices.QueryDeviceNoticeList(code); } return(View(model)); }
public ActionResult SendEmergencyMessage(string SerID) { if (string.IsNullOrEmpty(SerID)) { throw new BusinessException("请传入设备Code"); } var smoke = SmokeDetectorServices.LoadSmokeDetail(SerID); if (smoke == null || string.IsNullOrEmpty(smoke.AddressCode)) { throw new BusinessException("当前设备还未安装入网"); } DevicesWarningTemplateTemplate devicesWarningTemplate = new DevicesWarningTemplateTemplate { SerID = SerID, DeviceName = "烟感器报警", Type = "感应报警", WarningTime = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"), Memo = $"此设备地址为{smoke.AddressName}", // Url = "http://tfs-code2.chinacloudapp.cn/Smoke/Notice", MasterID = SerID, DateStr = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),//短信通知时间 Address = smoke.AddressName, }; if (smoke.InstallerSysNo.HasValue && smoke.InstallerSysNo < 0) { devicesWarningTemplate.Address = smoke.Position; devicesWarningTemplate.Memo = smoke.Position; } SendMessageService.SendMessage(devicesWarningTemplate, SerID); return(Json(new AjaxResult { Success = true })); }
public ActionResult DeleteDetector(string code, bool isdelete) { SmokeDetector detector = SmokeDetectorServices.LoadSmokeDetail(code); if (detector == null) { throw new BusinessException(string.Format("编号为【{0}】的设备不存在", code)); } if (isdelete) { DeleteDeviceRequest send = new DeleteDeviceRequest() { DeviceID = detector.DeviceId }; DeleteDviceResponse sendRes = ONENETService.DeleteDevice(send); SmokeDetectorServices.DeleteSmokeDetector(detector, CurrUser); SmokeDetectorServices.DeleteClientSmokeDetectorBycode(code); return(Json(new AjaxResult() { Success = true }, JsonRequestBehavior.AllowGet)); } else { DeleteDeviceRequest send = new DeleteDeviceRequest() { DeviceID = detector.DeviceId }; DeleteDviceResponse sendRes = ONENETService.DeleteDevice(send); if (sendRes.IsSuccess) { //更新本地设备状态 SmokeDetectorServices.DeleteSmokeDetector(detector, CurrUser); SmokeDetectorServices.DeleteClientSmokeDetectorBycode(code); return(Json(new AjaxResult() { Success = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new AjaxResult() { Success = false, Message = "删除失败,ONENET平台返回消息:" + sendRes.msg }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult DeviceDetails(string code) { DateTime now = DateTime.Now; QF_SmokeDetectorStatusLog filter = new QF_SmokeDetectorStatusLog() { DeviceCode = code, PageIndex = 0, PageSize = 9999 }; QueryResult <SmokeDetectorStatusLog> list = SmokeDetectorServices.QueryDeviceNoticeList(filter); SmokeDetector info = SmokeDetectorServices.LoadSmokeDetail(code); info.MessageList = list.data; ViewBag.UserType = curentUser.UserType; return(View(info)); }
public JsonResult DeleteDetector(string code) { //if (curentUser.UserType != UserType.Installer) //{ // throw new BusinessException("您不是安装人员,不能删除当前设备"); //} SmokeDetector detector = SmokeDetectorServices.LoadSmokeDetail(code); if (detector == null) { throw new BusinessException(string.Format("编号为【{0}】的设备不存在", code)); } if (curentUser.UserType == UserType.Installer) { if (detector.InstallerSysNo != curentUser.ManagerSysNo) { throw new BusinessException("您没有安装过当前设备,无权删除"); } } else { if (detector.InstallerSysNo != -curentUser.UserSysNo) { throw new BusinessException("您没有安装过当前设备,无权删除"); } } DeleteDeviceRequest send = new DeleteDeviceRequest() { DeviceID = detector.DeviceId }; DeleteDviceResponse sendRes = ONENETService.DeleteDevice(send); CurrentUser current = new CurrentUser { UserSysNo = curentUser.UserSysNo, UserDisplayName = curentUser.UserDisplayName }; SmokeDetectorServices.DeleteSmokeDetector(detector, current); SmokeDetectorServices.DeleteClientSmokeDetectorBycode(code); return(Json(new AjaxResult() { Success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult ScanDevicesQR(string serID) { if (string.IsNullOrEmpty(serID)) { throw new BusinessException("读取设备id失败,请重新扫描"); } var ClientSmokeDetectorList = ClientSmokeDetectorProcessor.LoadAllBindClientUser(serID); var temp = ClientSmokeDetectorList.Find(e => string.Equals(e.ClientSysNo, curentUser.UserSysNo)); if (temp != null) { throw new BusinessException("你已绑定过当前设备"); } if (ClientSmokeDetectorList.Count > 0) { throw new BusinessException($"设备已经绑定到“{ClientSmokeDetectorList.FirstOrDefault().Name}”,不能再次绑定"); } var smoke = SmokeDetectorServices.LoadSmokeDetail(serID); if (smoke == null || smoke.Status == SmokeDetectorStatus.Delete) { return(Json(new AjaxResult { Success = true, Code = 1, Message = "设备还未安装入网,请添加设备,如果您是公司用户,请绑定管理员!" })); //throw new BusinessException("设备还未安装入网"); } string addr = smoke.AddressName + smoke.Position; if (smoke.InstallerSysNo.HasValue && smoke.InstallerSysNo < 0) { addr = smoke.Position; } return(Json(new AjaxResult { Success = true, Data = addr })); }
public ActionResult _Modify(string code) { SmokeDetector detector = SmokeDetectorServices.LoadSmokeDetail(code) ?? new SmokeDetector(); return(PartialView("_Modify", detector)); }
public ActionResult CancelWarning(string code) { SmokeDetector detector = SmokeDetectorServices.LoadSmokeDetail(code); if (detector == null) { throw new BusinessException(string.Format("编号为【{0}】的设备不存在", code)); } if (detector.Status != SmokeDetectorStatus.Warning && detector.Status != SmokeDetectorStatus.TestWarning) { throw new BusinessException(string.Format("编号为【{0}】的设备不是报警状态", code)); } if (detector.Status == SmokeDetectorStatus.TestWarning) { //更新本地设备状态 SmokeDetectorStatusLog lastLog = SmokeDetectorServices.LoadSmokeDetectorStatusLogByDeviceCode(detector.Code); SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog() { PreStatus = detector.Status.Value, Status = SmokeDetectorStatus.CancelWarning, BeginTime = DateTimeHelper.GetTimeZoneNow(), ReceivedJsonData = "", SmokeDetectorCode = detector.Code }; detector.Status = SmokeDetectorStatus.CancelWarning; if (lastLog != null && statusLog.BeginTime.HasValue && lastLog.BeginTime.HasValue) { statusLog.DurationSeconds = (int)(statusLog.BeginTime.Value - lastLog.BeginTime.Value).TotalSeconds; } //更新本地设备状态 SmokeDetectorServices.UpdateSmokeDetector(detector); //更新首页数据 (new MapDataService(detector.CompanySysNo)).DataChangeAsync(); //写设备状态更改日志 SmokeDetectorServices.InsertSmokeDetectorStatusLog(statusLog); return(Json(new AjaxResult() { Success = true }, JsonRequestBehavior.AllowGet)); } else { SendCmdRequest send = new SendCmdRequest() { Imei = detector.Code }; SendCmdResponse sendRes = ONENETService.SendCmd(send); if (sendRes.IsSuccess) { //更新本地设备状态 SmokeDetectorStatusLog lastLog = SmokeDetectorServices.LoadSmokeDetectorStatusLogByDeviceCode(detector.Code); SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog() { PreStatus = detector.Status.Value, Status = SmokeDetectorStatus.CancelWarning, BeginTime = DateTimeHelper.GetTimeZoneNow(), ReceivedJsonData = "", SmokeDetectorCode = detector.Code }; detector.Status = SmokeDetectorStatus.CancelWarning; if (lastLog != null && statusLog.BeginTime.HasValue && lastLog.BeginTime.HasValue) { statusLog.DurationSeconds = (int)(statusLog.BeginTime.Value - lastLog.BeginTime.Value).TotalSeconds; } //更新本地设备状态 SmokeDetectorServices.UpdateSmokeDetector(detector); //更新首页数据 (new MapDataService(detector.CompanySysNo)).DataChangeAsync(); //写设备状态更改日志 SmokeDetectorServices.InsertSmokeDetectorStatusLog(statusLog); return(Json(new AjaxResult() { Success = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new AjaxResult() { Success = false, Message = "取消失败!" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult BindingDevicesApi(string serID) { if (string.IsNullOrEmpty(serID)) { throw new BusinessException("读取设备id失败,请重新扫描"); } var user = ClientService.LoadClient(curentUser.UserSysNo); if (user == null) { UserMgr.Logout(); throw new BusinessException("登录信息已过期,请退出重新进入公众号"); } var ClientSmokeDetectorList = ClientSmokeDetectorProcessor.LoadAllBindClientUser(serID); var temp = ClientSmokeDetectorList.Find(e => string.Equals(e.ClientSysNo, curentUser.UserSysNo)); if (temp != null) { throw new BusinessException("你已绑定过当前设备"); } if (ClientSmokeDetectorList.Count > 0) { throw new BusinessException($"设备已经绑定到“{ClientSmokeDetectorList.FirstOrDefault().Name}”,不能再次绑定"); } var smoke = SmokeDetectorServices.LoadSmokeDetail(serID); if (smoke == null || string.IsNullOrEmpty(smoke.AddressCode) || smoke.Status == SmokeDetectorStatus.Delete) { return(Json(new AjaxResult { Success = true, Code = 1, Message = "设备还未安装入网,请添加设备,如果您是公司用户,请绑定管理员!" })); // throw new BusinessException("设备还未安装入网"); } if (user != null) { ClientSmokeDetector clientSmokeDetector = new ClientSmokeDetector { ClientSysNo = user.SysNo, SmokeDetectorCode = serID, IsDefaultCellPhone = true, CellPhone = user.CellPhone, CellPhone2 = user.CellPhone2, CellPhone3 = user.CellPhone3 }; ClientSmokeDetectorProcessor.InsertClientSmokeDetector(clientSmokeDetector); List <MessageCenter.Entity.ReceiverInfo> receivers = new List <MessageCenter.Entity.ReceiverInfo> { new MessageCenter.Entity.ReceiverInfo { ReceiverNo = user.AppCustomerID, MsgType = MessageCenter.Entity.MsgType.WeiXin } }; var cellphone = clientSmokeDetector.CellPhone ?? clientSmokeDetector.CellPhone2 ?? clientSmokeDetector.CellPhone3 ?? null; if (!string.IsNullOrEmpty(cellphone)) { receivers.Add(new MessageCenter.Entity.ReceiverInfo { ReceiverNo = cellphone, MsgType = MessageCenter.Entity.MsgType.SMS }); } Task.Factory.StartNew(() => { WechatUserBindDevicesTemplate wechatUserBind = new WechatUserBindDevicesTemplate { Title = $"尊敬的{HttpUtility.UrlDecode(curentUser.UserID)}用户", SerID = serID, BindResult = "绑定成功", BindTimeStr = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"), Memo = $"此设备地址为{smoke.AddressName}", // Url = $"http://tfs-code2.chinacloudapp.cn//Smoke/Notice?code= {serID}", MasterID = serID, DateStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),//短信通知时间 Address = smoke.AddressName, }; if (smoke.InstallerSysNo.HasValue && smoke.InstallerSysNo < 0) { wechatUserBind.Address = smoke.Position; wechatUserBind.Memo = smoke.Position; } SendMessageService.SendMessageOnce(wechatUserBind, receivers); }); } return(Json(new AjaxResult { Success = true })); }