Пример #1
0
        /// <summary>
        /// 处理发送保安命令请求
        /// </summary>
        /// <returns></returns>
        private string HandleSecurityCommandRequest()
        {
            var ret = "[]";

            try
            {
                var id = ParseInt(Utility.Decrypt(data));
                using (var bll = new EquipmentBLL())
                {
                    var obj = bll.Find(f => f.id == id && f.Deleted == false);
                    if (null != obj)
                    {
                        if ((int?)null != obj.Terminal)
                        {
                            ret = "";
                            // 查看是否发送的保安命令
                            var command = CommandUtility.GetCommand(cmd);
                            if (command.Security && command.Code.Equals("6007"))
                            {
                                ret = HandleSecurityStatus(obj.LockStatus, command.Param);
                            }
                            if (string.IsNullOrEmpty(ret))
                            {
                                // 查看当前设备的链接状态然后确定命令的发送方式
                                ret = HandleTerminalCommandRequest(obj.TB_Terminal);
                            }
                        }
                        else
                        {
                            ret = ResponseMessage(-1, "No terminal bond with this equipment.");
                        }
                    }
                    else
                    {
                        ret = ResponseMessage(-1, "Equipment is not exist.");
                    }
                }
            }
            catch (Exception e) { ret = ResponseMessage(-1, "Handle Security command error:" + e.Message); }
            return(ret);
        }
Пример #2
0
        /// <summary>
        /// 查询命令历史记录
        /// </summary>
        /// <param name="security">是否查询保安命令</param>
        /// <returns></returns>
        private string HandleCommandHistoryRequest(bool security)
        {
            var ret = "[]";

            try
            {
                var id = ParseInt(Utility.Decrypt(data));
                using (var ebll = new EquipmentBLL())
                {
                    var obj = ebll.Find(f => f.id == id && f.Deleted == false);
                    if (null != obj)
                    {
                        // 终端不为空时才查询
                        if ((int?)null != obj.Terminal)
                        {
                            var start = DateTime.Parse(GetParamenter("start") + " 00:00:00");
                            var end   = DateTime.Parse(GetParamenter("end") + " 23:59:59");
                            var sim   = obj.TB_Terminal.Sim;
                            if (sim[0] == '8' && sim[1] == '9' && sim.Length < 11)
                            {
                                sim += "000";
                            }
                            // 查询的命令
                            //string _command = "";
                            Command command = null;
                            if (!string.IsNullOrEmpty(cmd))
                            {
                                command = CommandUtility.GetCommand(cmd);
                                //_command = command.Code;
                            }
                            using (var bll = new CommandBLL())
                            {
                                var list = bll.FindList <TB_Command>(f => f.DestinationNo.Equals(sim) &&
                                                                     f.ScheduleTime >= start && f.ScheduleTime <= end && f.Command != "0xBB0F", "ScheduleTime", true);
                                if (security)
                                {
                                    list = list.Where(w => w.Command == "0x6007" || w.Command == "0x4000" || w.Command == "0x3000" || w.Command == "0xDD02");
                                }
                                else
                                {
                                    list = list.Where(w => w.Command != "0x6007" && w.Command != "0x4000" && w.Command != "0x3000" && w.Command != "0xDD02");
                                }
                                //&&
                                //    (string.IsNullOrEmpty(_command) ? f.u_sms_command.IndexOf("0x") >= 0 : f.u_sms_command.IndexOf(_command) >= 0),
                                //    "u_sms_schedule_time", true);
                                if (null != command)
                                {
                                    list = list.Where(w => w.Command.IndexOf(command.Code) >= 0);
                                    if (security && command.Code.Equals("6007"))
                                    {
                                        list = list.Where(w => w.Content.Substring(w.Content.Length - 2) == command.Param);
                                    }
                                    else if (security && command.Code.Equals("3000"))
                                    {
                                        list = list.Where(w => w.Content.Substring(w.Content.Length - 4, 2) == command.Param);
                                    }
                                    else if (security && command.Code.Equals("4000"))
                                    {
                                        list = list.Where(w => w.Content.Substring(w.Content.Length - 4, 2) == command.Param);
                                    }
                                }
                                if (list.Count() > 0)
                                {
                                    // 将command_id替换
                                    //List<Command> commands = CommandUtility.GetCommand();
                                    foreach (var record in list)
                                    {
                                        string param = "";
                                        if (record.Command == "0x6007")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 2);
                                        }
                                        if (record.Command == "0x3000")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 4, 2);
                                        }
                                        if (record.Command == "0x4000")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 4, 2);
                                        }
                                        if (record.Command == "0xDD02")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 8, 2);
                                        }
                                        Command _cmd   = CommandUtility.GetCommand(record.Command.Replace("0x", ""), param);
                                        var     func   = (EquipmentFunctional)obj.Functional;
                                        var     called = (func == EquipmentFunctional.Mechanical || func == EquipmentFunctional.Electric) ? "Equipment" : "Loader";
                                        record.Command = (null == _cmd ? "" : _cmd.Title.Replace("Equipment", called).Replace("Loader", called));
                                        // 加入命令发送者  2015/09/18 10:36
                                        record.Content = (int?)null == record.SendUser ? "Server" : record.TB_Account.Name;
                                    }
                                }
                                ret = JsonConverter.ToJson(list);
                            }
                        }
                        else
                        {
                            ret = ResponseMessage(-1, "No terminal bond with this equipment.");
                        }
                    }
                    else
                    {
                        ret = ResponseMessage(-1, "Equipment is not exist.");
                    }
                }
            }
            catch (Exception e)
            { ret = ResponseMessage(-1, "Handle History request error:" + e.Message); }
            return(ret);
        }
Пример #3
0
        /// <summary>
        /// 显示普通可发送的命令列表
        /// </summary>
        private void ShowCustomCommands()
        {
            var id         = ParseInt(Utility.Decrypt(_key));
            var equipment  = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
            var functional = null == equipment ? EquipmentFunctional.Mechanical : (EquipmentFunctional)equipment.Functional;
            var commands   = CommandUtility.GetCommand(false);

            // 链接未知时,不能发送任何命令  2015/09/18 18:20
            if ((byte?)null == equipment.OnlineStyle)
            {
                return;
            }

            var link = (LinkType)equipment.OnlineStyle;
            var html = "";

            foreach (var command in commands)
            {
                // 卫星链接时,不能发送以下几个命令  2015/09/16 15:40
                if (link == LinkType.SATELLITE)
                {
                    if (command.Flag == "signal" || command.Flag == "ld_daily" || command.Flag == "ld_worktime" ||
                        command.Flag == "monitor" || command.Flag == "fault" || command.Flag == "worktime")
                    {
                        continue;
                    }
                }
                else
                {
                    if (command.Flag == "ld_daily")
                    {
                        continue;
                    }
                }
                if (functional == EquipmentFunctional.Mechanical)
                {
                    // 机械式的挖掘机,不显示装载机的命令
                    if (command.Title.IndexOf("Loader") < 0)
                    {
                        // 未启动时不能发送EPOS命令
                        var vol = equipment.Voltage;
                        if (!vol.Contains("G2") && command.Title.Contains("Equipment"))
                        {
                            continue;
                        }

                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Electric)
                {
                    // 电子式的挖掘机,不显示普通挖掘机的EPOS命令
                    if (command.Title.IndexOf("Equipment") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title.Replace("Loader", "Equipment") + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Loader)
                {
                    // 装载机不显示挖掘机的命令
                    if (command.Title.IndexOf("Equipment") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
            }
            menuCommands.InnerHtml = html;
        }
Пример #4
0
        /// <summary>
        /// 显示普通可发送的命令列表
        /// </summary>
        private void ShowSecurityCommands()
        {
            var id         = ParseInt(Utility.Decrypt(_key));
            var equipment  = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
            var functional = null == equipment ? EquipmentFunctional.Mechanical : (EquipmentFunctional)equipment.Functional;

            // 链接未知时,不能发送任何命令  2015/09/18 18:20
            if ((byte?)null == equipment.OnlineStyle)
            {
                return;
            }

            var link     = (LinkType)equipment.OnlineStyle;
            var commands = CommandUtility.GetCommand(true);
            var html     = "";

            foreach (var command in commands)
            {
                // 禁止在这里发送启用或禁用卫星命令 2015/11/26 16:35
                if (command.Flag == "satenable" || command.Flag == "satdisable" || command.Flag == "reset_gsm")
                {
                    continue;
                }
                // 卫星链接时,不能发送以下几个命令  2015/09/16 15:50
                if (link == LinkType.SATELLITE)
                {
                    if (command.Flag == "satenable" || command.Flag == "satdisable" || command.Flag == "reset_sat")
                    {
                        continue;
                    }
                }
                else
                {
                    // 睡眠模式下禁止发送转Satellite命令  2015/09/18 11:00
                    if (command.Flag == "reset_gsm" || (equipment.OnlineStyle == (byte)LinkType.SLEEP && command.Flag == "reset_sat"))
                    {
                        continue;
                    }
                }
                if (functional == EquipmentFunctional.Mechanical)
                {
                    // 机械式的挖掘机,不显示装载机的命令
                    if (command.Title.IndexOf("Loader") < 0)
                    {
                        var lok = equipment.LockStatus;
                        if (string.IsNullOrEmpty(lok))
                        {
                            lok = "00";
                        }
                        // 未锁车时不显示解锁
                        if (lok.Equals("00"))
                        {
                            if (command.Flag.Equals("enable"))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (command.Flag.Equals("full"))
                            {
                                // 锁车时不显示锁车
                                continue;
                            }
                        }
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Electric)
                {
                    // 电子式的挖掘机,不显示普通挖掘机的EPOS命令
                    if (command.Title.IndexOf("Security") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title.Replace("Loader", "Equipment") + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Loader)
                {
                    // 装载机不显示挖掘机的命令
                    if (command.Title.IndexOf("Security") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
            }
            menuCommands.InnerHtml = html;
        }