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 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 })); }