Ejemplo n.º 1
0
        /// <summary>
        /// 更新SmokeDetectorStatusLog信息
        /// </summary>
        public static void UpdateSmokeDetectorStatusLog(SmokeDetectorStatusLog entity)
        {
            DataCommand cmd = new DataCommand("UpdateSmokeDetectorStatusLog");

            cmd.SetParameter <SmokeDetectorStatusLog>(entity);
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 2
0
        public static SmokeDetectorStatusLog LoadSmokeDetectorStatusLogByDeviceCode(string code)
        {
            DataCommand cmd = new DataCommand("LoadSmokeDetectorStatusLogByDeviceCode");

            cmd.SetParameter("@SmokeDetectorCode", DbType.String, code);
            SmokeDetectorStatusLog result = cmd.ExecuteEntity <SmokeDetectorStatusLog>();

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取单个SmokeDetectorStatusLog信息
        /// </summary>
        public static SmokeDetectorStatusLog LoadSmokeDetectorStatusLog(int sysNo)
        {
            DataCommand cmd = new DataCommand("LoadSmokeDetectorStatusLog");

            cmd.SetParameter("@SysNo", DbType.Int32, sysNo);
            SmokeDetectorStatusLog result = cmd.ExecuteEntity <SmokeDetectorStatusLog>();

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建SmokeDetectorStatusLog信息
        /// </summary>
        public static int InsertSmokeDetectorStatusLog(SmokeDetectorStatusLog entity)
        {
            DataCommand cmd = new DataCommand("InsertSmokeDetectorStatusLog");

            cmd.SetParameter <SmokeDetectorStatusLog>(entity);
            int result = cmd.ExecuteScalar <int>();

            return(result);
        }
Ejemplo n.º 5
0
        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 HttpResponseMessage SyncDeviceStatus()
        {
            Stream reqstream = HttpContext.Current.Request.InputStream;

            reqstream.Seek(0, System.IO.SeekOrigin.Begin);
            string body = new StreamReader(reqstream).ReadToEnd();

            Logger.WriteLog("API接收数据:" + body);
            List <SyncDeviceStatusRequest> list     = JsonConvert.DeserializeObject <List <SyncDeviceStatusRequest> >(body);
            SyncDeviceStatusResponse       response = new SyncDeviceStatusResponse();

            if (list == null || list.Count <= 0)
            {
                response.IsSuccess = false;
                response.Message   = "参数错误。";
            }
            else
            {
                SyncDeviceStatusRequest request = null;
                foreach (var item in list)
                {
                    if (SMOKE_STATUS_CODE.Contains(item.Status))
                    {
                        request = item;
                        break;
                    }
                }
                if (request == null)
                {
                    response.IsSuccess = false;
                    response.Message   = "参数错误。";
                }
                else
                {
                    SmokeDetector detecor = SmokeDetectorServices.LoadSmokeDetailByDeviceID(request.DeviceID);

                    if (detecor == null)
                    {
                        response.Message = "设备不存在。";
                    }
                    else
                    {
                        SmokeDetectorStatus status = MatchDeviceStatus(request.Status);
                        if (detecor.Status != status)//两次设备状态不一致
                        {
                            SmokeDetectorStatusLog lastLog = SmokeDetectorServices.LoadSmokeDetectorStatusLogByDeviceCode(detecor.Code);

                            #region  更新设备状态,写状态变更日志
                            DateTime dt;
                            DateTime.TryParse(request.CDatetime, out dt);
                            SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog()
                            {
                                PreStatus         = detecor.Status.Value,
                                Status            = status,
                                BeginTime         = dt == DateTime.MinValue ? DateTimeHelper.GetTimeZoneNow() : dt,
                                ReceivedJsonData  = body,
                                SmokeDetectorCode = detecor.Code
                            };
                            detecor.Status = status;
                            if (lastLog != null && statusLog.BeginTime.HasValue && lastLog.BeginTime.HasValue)
                            {
                                statusLog.DurationSeconds = (int)(statusLog.BeginTime.Value - lastLog.BeginTime.Value).TotalSeconds;
                            }
                            using (var trans = TransactionManager.Create())
                            {
                                SmokeDetectorServices.InsertSmokeDetectorStatusLog(statusLog);
                                SmokeDetectorServices.UpdateSmokeDetector(detecor);
                                trans.Complete();
                            }
                            #endregion

                            #region 更新首页地图数据缓存

                            (new MapDataService(detecor.CompanySysNo)).DataChangeAsync();

                            #endregion

                            #region 发送消息

                            if (detecor.Status == SmokeDetectorStatus.Warning ||
                                detecor.Status == SmokeDetectorStatus.TestWarning)
                            {
                                Task.Factory.StartNew(() =>//火灾报警
                                {
                                    DevicesWarningTemplateTemplate devicesWarningTemplate = new DevicesWarningTemplateTemplate
                                    {
                                        SerID       = detecor.Code,
                                        DeviceName  = "烟感设备报警",
                                        Type        = "火灾报警",
                                        WarningTime = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),
                                        Memo        = $"此设备地址为{detecor.AddressName}",
                                        MasterID    = detecor.Code,
                                        DateStr     = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),//短信通知时间
                                        Address     = detecor.AddressName
                                    };
                                    if (detecor.InstallerSysNo.HasValue && detecor.InstallerSysNo < 0)
                                    {
                                        devicesWarningTemplate.Address = detecor.Position;
                                        devicesWarningTemplate.Memo    = detecor.Position;
                                    }
                                    SendMessageService.SendMessage(devicesWarningTemplate, detecor.Code);
                                });
                            }
                            else if (detecor.Status == SmokeDetectorStatus.Lost ||
                                     detecor.Status == SmokeDetectorStatus.Offline ||
                                     detecor.Status == SmokeDetectorStatus.OutNet)
                            {
                                Task.Factory.StartNew(() =>//离线报警
                                {
                                    DevicesOfflineTemplateTemplate devicesOfflintTemplate = new DevicesOfflineTemplateTemplate
                                    {
                                        SerID          = detecor.Code,
                                        DeviceName     = "烟感设备离线",
                                        DeviceAddress  = $"此设备地址为{detecor.AddressName}",
                                        OffLineTimeStr = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),
                                        Memo           = "请尽快处理!",
                                        MasterID       = detecor.Code,
                                        DateStr        = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),//短信通知时间
                                        Address        = detecor.AddressName
                                    };
                                    if (detecor.InstallerSysNo.HasValue && detecor.InstallerSysNo < 0)
                                    {
                                        devicesOfflintTemplate.Address = detecor.Position;
                                        devicesOfflintTemplate.Memo    = detecor.Position;
                                    }
                                    SendMessageService.SendMessage(devicesOfflintTemplate, detecor.Code);
                                });
                            }
                            else if (detecor.Status == SmokeDetectorStatus.LowPower)
                            {
                                Task.Factory.StartNew(() =>//低电压报警
                                {
                                    DevicesWarningTemplateTemplate devicesWarningTemplate = new DevicesWarningTemplateTemplate
                                    {
                                        SerID       = detecor.Code,
                                        DeviceName  = "烟感设备电量过低",
                                        Type        = "低电量报警",
                                        WarningTime = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),
                                        Memo        = $"此设备地址为{detecor.AddressName}",
                                        MasterID    = detecor.Code,
                                        DateStr     = DateTimeHelper.GetTimeZoneNow().ToString("yyyy-MM-dd HH:mm:ss"),//短信通知时间
                                        Address     = detecor.AddressName
                                    };
                                    if (detecor.InstallerSysNo.HasValue && detecor.InstallerSysNo < 0)
                                    {
                                        devicesWarningTemplate.Address = detecor.Position;
                                        devicesWarningTemplate.Memo    = detecor.Position;
                                    }
                                    SendMessageService.SendMessage(devicesWarningTemplate, detecor.Code);
                                });
                            }
                            #endregion
                        }
                        response.IsSuccess = true;
                    }
                }
            }
            string result = JsonConvert.SerializeObject(response);
            return(new HttpResponseMessage()
            {
                Content = new StringContent(result, Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 7
0
 public static int InsertSmokeDetectorStatusLog(SmokeDetectorStatusLog entity)
 {
     return(SmokeDetectorStatusLogDA.InsertSmokeDetectorStatusLog(entity));
 }
Ejemplo n.º 8
0
        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 = "添加成功!"
                }));
            }
        }