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 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 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 AddSmokeDetector(SmokeDetector entity) { long deviceCode = 0; long.TryParse(entity.Code, out deviceCode); if (deviceCode <= 0) { return(Json(new AjaxResult() { Success = false, Message = "请扫描正确的设备二维码。" })); } //if (curentUser.UserType != UserType.Installer) //{ // return Json(new AjaxResult() { Success = false, Message = "您不是管理员,请绑定管理员账号。" }); //} //if ((entity.AddressSysNo == null || entity.AddressSysNo <= 0) && (entity.Memo == "" || entity.Memo == null)) //{ // return Json(new AjaxResult() { Success = false, Message = "请选择详细地址或者填写备注。" }); //} if ((!entity.AddressSysNo.HasValue || entity.AddressSysNo <= 0) && string.IsNullOrWhiteSpace(entity.Position)) { return(Json(new AjaxResult() { Success = false, Message = "请选择地址或填写设备具体位置。" })); } Address address = AddressDA.LoadAddress(entity.AddressSysNo.GetValueOrDefault()); if (address == null) { return(Json(new AjaxResult() { Success = false, Message = "位置信息错误,请重新选择后再试。" })); } entity.AddressCode = address.Code; entity.AddressName = address.PathName; if ((address.ParentSysNo == 0 || address.ParentSysNo == null) && (address.PathName == "" || address.PathName == null)) { entity.AddressName = address.Name; } entity.Status = SmokeDetectorStatus.Offline; if (curentUser.UserType == UserType.Installer) { entity.InstallerSysNo = curentUser.ManagerSysNo; } else { entity.InstallerSysNo = -curentUser.UserSysNo; } entity.InstallerName = HttpUtility.UrlDecode(curentUser.UserID); entity.InUserSysNo = curentUser.UserSysNo; entity.InUserName = HttpUtility.UrlDecode(curentUser.UserID); SmokeDetector smoke = SmokeDetectorServices.IsUniquenessCode(entity.Code); SystemUserService service = new SystemUserService(); SystemUser systemuser = service.LoadSystemUser(curentUser.ManagerSysNo.GetValueOrDefault(), ConstValue.ApplicationID); if (systemuser == null) { UserMgr.Logout(); return(Json(new AjaxResult() { Success = false, Message = "登录超时,请退出公众号重新进入。" })); } //if (smoke != null && smoke.CompanySysNo != systemuser.MasterSysNo) //{ // return Json(new AjaxResult() { Success = false, Message = "设备已安装,不能再安装。" }); //} //else if (smoke != null) { if (smoke.Status == SmokeDetectorStatus.Delete) { entity.Status = SmokeDetectorStatus.Offline; } else { entity.Status = smoke.Status; if (smoke.InstallerSysNo <= 0) { if (smoke.InstallerSysNo != -curentUser.UserSysNo) { return(Json(new AjaxResult() { Success = false, Message = "设备已安装,不能再安装。" })); } } else { if (!(smoke.CompanySysNo == systemuser.MasterSysNo && curentUser.UserType == UserType.Installer)) { return(Json(new AjaxResult() { Success = false, Message = "设备已安装,不能再安装。" })); } } }; CreateDeviceRequest reques = new CreateDeviceRequest() { IMei = entity.Code, IMsi = entity.Code, Desc = "测试设备", IsOnLine = 1, Observe = 1, Protocol = "LWM2M", Title = entity.Code, Tags = entity.Code + "," + entity.Code }; CreateDeviceResponse result = ONENETService.CreateDevice(reques); if (result.IsSuccess) { entity.DeviceId = result.DeviceId; } else { entity.DeviceId = smoke.DeviceId; } entity.SysNo = smoke.SysNo; SmokeDetectorServices.UpdateSmokeDetector(entity); if (curentUser.UserType != UserType.Installer) { Logger.WriteLog("Code:" + entity.Code); BindingDevicesApi(entity.Code); } return(Json(new AjaxResult() { Success = true, Message = "修改成功!" })); //} //else //{ // return Json(new AjaxResult() { Success = false, Message = "系统异常!" }); //} } else { CreateDeviceRequest reques = new CreateDeviceRequest() { IMei = entity.Code, IMsi = entity.Code, Desc = "测试设备", IsOnLine = 1, Observe = 1, Protocol = "LWM2M", Title = entity.Code, Tags = entity.Code + "," + entity.Code }; CreateDeviceResponse result = ONENETService.CreateDevice(reques); if (result.IsSuccess) { entity.DeviceId = result.DeviceId; } int i = SmokeDetectorServices.InsertSmokeDetector(entity); SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog() { Status = entity.Status, BeginTime = DateTimeHelper.GetTimeZoneNow(), ReceivedJsonData = "", SmokeDetectorCode = entity.Code }; if (curentUser.UserType != UserType.Installer) { Logger.WriteLog("Code:" + entity.Code); BindingDevicesApi(entity.Code); } return(Json(new AjaxResult() { Success = true, Message = "添加成功!" })); } }