Example #1
0
        public ActionResult SearchTest(QueryParams queryParams)
        {
            EquipmentResult result = new EquipmentResult();
            Z_Room          room   = ZRoomService.GetEntity(u => u.F_RoomNo == queryParams.classroom).FirstOrDefault();
            //获取该教室所有的设备
            var       zeList    = ZEquipmentService.GetEntity(u => u.F_RoomId == room.F_Id).ToList();
            byte      fun       = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Search"));
            ClassRoom classRoom = PortService.GetReturnDataTest(queryParams.classroom);

            if (classRoom != null)
            {
                classRoom.Name    = room?.F_FullName;
                classRoom.ClassNo = room.F_EnCode;  //教室编码
                classRoom.Id      = room.F_RoomNo;
                var list = classRoom.SonserList;
                classRoom.AbnormalSonserList = classRoom.SonserList.Where(u => u.Online == StateType.Offline).ToList();
                classRoom.NormalSonserList   = classRoom.SonserList.Where(u => u.Online == StateType.Online).ToList();
                result.Count          = zeList.Count;
                result.ExceptionCount = classRoom.AbnormalSonserList.Count;
                result.NormalCount    = classRoom.NormalSonserList.Count;
                result.AppendData     = classRoom;
            }
            else
            {
                result.Message = "查询设备信息失败!请重试";
            }
            return(Json(result));
        }
Example #2
0
        public ActionResult ControlBuildingEquipment(string buildingName, string equipmentType, string onoff)
        {
            EquipmentResult equipmentResult = new EquipmentResult();

            try
            {
                var classroom = ZRoomService.GetRoomsForBuildingName(buildingName);
                //查找出所有教室里的所有该设备编码的设备
                var equis = ZEquipmentService.GetEntity(e => classroom.Any(r => e.F_RoomId == r.F_Id)).Where(e => e.F_EquipmentType == equipmentType);
                //筛选出教室编码和设备编码
                var val = (from c in classroom
                           join e in equis on c.F_Id equals e.F_RoomId
                           select new EquipmentDto
                {
                    F_RoomNo = c.F_RoomNo,
                    F_EquipmentNo = e.F_EquipmentNo
                }).ToList();
                PortService.ControlMultiEquipment(val, onoff, equipmentType);
                equipmentResult.Message    = "控制整栋楼层设备成功";
                equipmentResult.ResultCode = ResultCode.Ok;
                equipmentResult.Status     = true;
            }
            catch (Exception ex)
            {
                equipmentResult.Message    = "控制整栋楼层设备失败";
                equipmentResult.ResultCode = ResultCode.Error;
                equipmentResult.Status     = false;
                equipmentResult.ErrorData  = ex.Message;
            }
            return(Json(equipmentResult));
        }
Example #3
0
        /// <summary>
        /// 初始化设备节点
        /// </summary>
        /// <param name="classroom">教室地址</param>
        /// <returns></returns>
        public ActionResult Init(string classroom)
        {
            byte b   = 0x00;
            byte fun = 0x1f;

            EResult         = PortService.SendConvertCmd(fun, classroom, "00", b);
            EResult.Message = EResult.Status ? "查询设备信息成功" : "查询设备信息失败";
            ClassRoom          classRoom = PortService.GetReturnData(classroom);
            var                list      = classRoom.SonserList;
            List <Z_Equipment> zeList    = new List <Z_Equipment>();
            Z_Room             room      = ZRoomService.GetEntity(u => u.F_RoomNo == classroom).FirstOrDefault();

            ZEquipmentService.DeleteEntitys(ZEquipmentService.GetEntity(u => u.F_RoomId == room.F_Id).ToList());
            if (room != null)
            {
                foreach (var item in list)
                {
                    var zEquipment = new Z_Equipment
                    {
                        F_Id            = Guid.NewGuid().ToString(),
                        F_RoomId        = room.F_Id,
                        F_FullName      = item.Name,
                        F_EquipmentType = item.Type + "",
                        F_EnabledMark   = true,
                        F_EquipmentNo   = item.Id.IndexOf('_') != -1 ? item.Id.Split('_')[0] : item.Id
                    };
                    zeList.Add(zEquipment);
                }
            }
            ZEquipmentService.AddEntitys(zeList);
            EResult.AppendData = list;
            return(Json(EResult, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        /// <summary>
        /// 操作后
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (!isCheck)
            {
                return;
            }
            string token;

            token = filterContext.HttpContext.Request.Headers["Access"];
            token = token ?? filterContext.HttpContext.Request["Access"];
            token = token ?? filterContext.HttpContext.Request.Cookies["Access"]?.Value;

            var payload = Cache.GetCache <Payload>(token);
            //操作日志记录
            JsonResult jsonResult = filterContext.Result as JsonResult;
            string     roomId     = filterContext.HttpContext.Request["classroom"];
            string     nodeId     = filterContext.HttpContext.Request["nodeAdd"] ?? "00";

            if (nodeId?.IndexOf("_") != -1)
            {
                nodeId = nodeId.Split('_')[0];
            }
            string onoff = filterContext.HttpContext.Request["onoff"];

            onoff = string.IsNullOrEmpty(onoff) ? "" : onoff;
            EquipmentResult equipmentResult = jsonResult?.Data as EquipmentResult;

            if (equipmentResult != null)
            {
                //开启线程处理后续日志操作
                ThreadPool.QueueUserWorkItem(oo =>
                {
                    Z_EquipmentLog zEquipmentLog = new Z_EquipmentLog();
                    zEquipmentLog.F_Id           = Guid.NewGuid().ToString();
                    zEquipmentLog.F_Account      = payload.Account;
                    zEquipmentLog.F_Date         = DateTime.Now;
                    zEquipmentLog.F_RoomNo       = roomId;
                    string roomName = ZRoomService.GetEntity(z => z.F_RoomNo.ToLower() == roomId.ToLower()).Select(z => z.F_FullName).FirstOrDefault();
                    string nodeName = ZEquipmentService.GetEntity(e => e.F_EquipmentNo.ToLower() == nodeId.ToLower())
                                      .Select(e => e.F_FullName).FirstOrDefault();
                    var user = SysUserService.GetEntity(u => u.F_Account == payload.Account).Select(o => new { o.F_NickName, o.F_RealName })
                               .FirstOrDefault();
                    zEquipmentLog.F_EquipmentNo      = nodeId;
                    zEquipmentLog.F_Description      = equipmentResult.Message;
                    zEquipmentLog.F_EquipmentLogType = onoff == StateType.OPEN ? EQUOPEN : onoff == StateType.CLOSE ? EQUCLOSE : EQUSEARCH;
                    zEquipmentLog.F_RoomName         = roomName;
                    zEquipmentLog.F_EquipmentName    = nodeName;
                    zEquipmentLog.F_NickName         = user?.F_NickName;
                    zEquipmentLog.F_FullName         = user?.F_RealName;

                    ZEquipmentLogService.AddEntity(zEquipmentLog);
                });
            }
        }
Example #5
0
        /// <summary>
        /// 查询的教室设备节点信息
        /// </summary>
        /// <param name="classroom">教室</param>
        /// <param name="result">记录结果</param>
        /// <returns>返回记录结果</returns>
        public ClassRoom Search(Z_Room room, ref EquipmentResult result)
        {
            //获取该教室所有的设备
            var  zeList = ZEquipmentService.GetEntity(u => u.F_RoomId == room.F_Id).ToList();
            byte fun    = (byte)Convert.ToInt32(AppSettingUtils.GetValue("Search"));

            //向串口发送查询指令
            result = SendConvertSearchCmd(fun, room.F_RoomNo);
            ClassRoom classRoom = GetReturnData(room.F_RoomNo);

            if (classRoom == null) //没有数据就重新发一次
            {
                Thread.Sleep(300);
                //向串口发送指令
                result    = SendConvertSearchCmd(fun, room.F_RoomNo);
                classRoom = GetReturnData(room.F_RoomNo);
            }
            if (classRoom != null)
            {
                classRoom.Name               = room.F_FullName;
                classRoom.ClassNo            = room.F_EnCode; //教室编码
                classRoom.Id                 = room.F_RoomNo;
                classRoom.AbnormalSonserList = classRoom.SonserList.Where(u => u.Online == StateType.Offline).ToList();
                classRoom.NormalSonserList   = classRoom.SonserList.Where(u => u.Online == StateType.Online).ToList();
                result.Count                 = zeList.Count;
                result.ExceptionCount        = zeList.Count - classRoom.NormalSonserList.Count;
                result.NormalCount           = classRoom.NormalSonserList.Count;
                result.Message               = "查询设备信息成功";
            }
            else
            {
                result.Status     = false;
                result.ResultCode = ResultCode.Error;
                result.Message    = "查询设备信息失败!请重试";
            }
            return(classRoom);
        }
Example #6
0
        public ActionResult ControlFloorEquipment(string buildingName, string floorName, string equipmentType, string onoff)
        {
            EquipmentResult equipmentResult = new EquipmentResult();

            try
            {
                //Z_Room room = ZRoomService.GetEntity(u => u.F_FullName == buildingName).FirstOrDefault();//查找该楼栋
                //var floor = ZRoomService.GetEntity(u => u.F_ParentId == room.F_Id).Where(u => u.F_FullName == floorName);     //该楼栋的该楼层
                //var classroom = ZRoomService.GetEntity(u => floor.Any(f => f.F_Id == u.F_ParentId));  //楼层中所有教室
                var classroom = ZRoomService.GetRoomsForBuildingName(buildingName, floorName);
                //查询该楼层下的该设备型号的所有设备
                var equis = ZEquipmentService.GetEntity(e => classroom.Any(r => e.F_RoomId == r.F_Id)).Where(e => e.F_EquipmentType == equipmentType);
                //筛选出教室编码和设备编码
                var val = (from c in classroom
                           join e in equis on c.F_Id equals e.F_RoomId
                           select new EquipmentDto()
                {
                    F_RoomNo = c.F_RoomNo,
                    F_EquipmentNo = e.F_EquipmentNo
                }).ToList();
                PortService.ControlMultiEquipment(val, onoff, equipmentType);
                PortService.ControlMultiEquipment(val, onoff, equipmentType);
                equipmentResult.Message    = "控制整栋楼层设备成功";
                equipmentResult.ResultCode = ResultCode.Ok;
                equipmentResult.Status     = true;
            }
            catch (Exception ex)
            {
                equipmentResult.Message    = "控制整栋楼层设备失败";
                equipmentResult.ResultCode = ResultCode.Error;
                equipmentResult.Status     = false;
                equipmentResult.ErrorData  = ex.Message;
            }

            return(Json(equipmentResult));
        }