public async Task <ActionResult> UpdateTerminalSetting(TerminalSettingsIssuedModel model)
        {
            ActionResult            result  = null;
            List <TerminalWCfModel> wcfList = null;

            if (!this.CheckWCF(model.ListVehicles, out result, out wcfList))
            {
                return(result);
            }
            // 记录错误信息
            string errorMsg       = string.Empty;
            bool   updateTerminal = true;

            // 调用wcf服务 如果终端属于同一个wcf地址 那么可以公用一个client实例
            try
            {
                var syncResult = await this.DoOperation <TerminalSettingsIssuedModel, OperationResultGeneralRep>(wcfList, model, SyncSetTerminalParas).ConfigureAwait(false);

                int           index            = 0;
                string        valuesSql        = string.Empty;
                string        setInfo          = GetProperties <TerminalSettingsIssuedModel>(model);
                string        wanIP            = GetRemoteAddress();
                DateTime      setDTime         = DateTime.Now;
                List <string> listTerminalCode = new List <string>();
                foreach (var item in syncResult)
                {
                    string plateNum       = wcfList[index].PlateNum;
                    string terminalCode   = wcfList[index].TerminalCode;
                    string resultResponse = "Code:" + (int)(OperationResultCode)item.Code + ";Message:" + item.Message;

                    // 记录日志 文本消息下发 这里拼接sql语句 批量插入
                    valuesSql += string.Format("('{0}','{1}',{2},'{3}',{4},'{5}','{6}',{7},'{8}'),",
                                               terminalCode, plateNum, (byte)TerminalSettingTypeEnum.TerminalSetup_Update,
                                               setInfo, item.State ? 1 : 0, resultResponse, wanIP, base.CurrentUserID, setDTime);
                    if (!item.State)
                    {
                        //errorMsg += string.Format("<div style='font-weight:bolder;'>" + UIText.TerminalSetting_PlateNumber +
                        //                                              ":{0}{1},"+PromptInformation.FailReason+":{2}{3}</div>", plateNum, "<br/>",
                        //                                             item.Code.ToString(), "<hr/>");
                        errorMsg += ErrorMesage(plateNum, item.Code.ToString());
                    }
                    else
                    {
                        //这里记录修改成功的终端值
                        listTerminalCode.Add(terminalCode);
                    }
                    index++;
                }

                //如果下发终端成功了 则修改TMS表中对应终端的数据
                if (listTerminalCode.Count > 0)
                {
                    TerminalSettingsSectionModel sectionModel = new TerminalSettingsSectionModel()
                    {
                        最高速度       = model.最高速度,
                        超速持续时间     = model.最高速度,
                        连续驾驶时间门限   = model.最高速度,
                        最小休息时间     = model.最小休息时间,
                        当天累计驾驶时间门限 = model.当天累计驾驶时间门限,
                        最长停车时间     = model.最长停车时间
                    };
                    updateTerminal = TerminalBLL.UpdateTerminals(listTerminalCode, sectionModel);
                }
                // 批量插入日志
                TerminalSettingsBLL.BatchInsertTerminalOperationsLog(valuesSql.TrimEnd(','));
            }
            catch (Exception ex)
            {
                LogHelper.TerminalSettingsErrorLog("下发终端设置异常:" + ex.Message);
                return(Json(new { Success = false, Message = PromptInformation.RemotingError }));
            }

            if (!updateTerminal)
            {
                return(Json(new { Success = false, Message = PromptInformation.TerminalSetting_UpdateTerminalSettingFail }));
            }
            if (string.IsNullOrEmpty(errorMsg))
            {
                return(Json(new { Success = true, Message = PromptInformation.TerminalSetting_UpdateTerminalSettingSuccess }));
            }
            else
            {
                return(Json(new { Success = false, Message = errorMsg }));
            }
        }
        public async Task <ActionResult> QueryTerminalFlags(TerminalSettingsReadModel model)
        {
            // 根据终端号获取终端所属服务器的wcf链接地址
            ActionResult            actionResult = null;
            List <TerminalWCfModel> wcfList      = null;

            if (!this.CheckWCF(model.ListVehicles, out actionResult, out wcfList))
            {
                return(actionResult);
            }
            // 记录错误信息
            string errorMsg = string.Empty;
            OperationResultQueryTerminalParaRespData syncResult;

            try
            {
                var entity = wcfList[0];
                var checkedParamArrayLength  = model.CheckedParamArray.Length;
                TerminalParaID[] paramIDs    = new TerminalParaID[checkedParamArrayLength];
                var    checkedParamArrayData = model.CheckedParamArray;
                string checkedTerminalPara   = PromptInformation.QueryContent + ":";
                for (int i = 0; i < checkedParamArrayLength; i++)
                {
                    paramIDs[i]          = (TerminalParaID)checkedParamArrayData[i];
                    checkedTerminalPara += (TerminalParaID)checkedParamArrayData[i] + ",";
                }

                var tempResult = await this.DoOperation <TerminalParaID[], OperationResultQueryTerminalParaRespData>(wcfList, paramIDs, SyncQuerySpecifiedTerminalParas);

                syncResult = tempResult.Single();
                string setInfo        = checkedTerminalPara.TrimEnd(',');
                string plateNum       = entity.PlateNum;
                string resultResponse = "Code:" + (int)(OperationResultCode)syncResult.Code + ";Message:" + syncResult.Message;

                // 记录日志 文本消息下发 这里拼接sql语句 批量插入
                string valuesSql = string.Format("('{0}','{1}',{2},'{3}',{4},'{5}','{6}',{7},'{8}'),",
                                                 entity.TerminalCode, plateNum, (byte)TerminalSettingTypeEnum.TerminalSetup_Query,
                                                 setInfo, syncResult.State ? 1 : 0, resultResponse, GetRemoteAddress(), base.CurrentUserID, DateTime.Now);
                if (!syncResult.State)
                {
                    //errorMsg += string.Format("<div style='font-weight:bolder;'>{0}:{1}{2}{3}:{4}{5}</div>",
                    //    UIText.TerminalSetting_PlateNumber, plateNum, "<br/>", PromptInformation.FailReason,syncResult.Code.ToString(), "<hr/>");
                    errorMsg += ErrorMesage(plateNum, syncResult.Code.ToString());
                }
                // 插入日志
                TerminalSettingsBLL.BatchInsertTerminalOperationsLog(valuesSql.TrimEnd(','));
            }
            catch (Exception ex)
            {
                LogHelper.TerminalSettingsErrorLog("终端设置读取异常:" + ex.Message);
                return(Json(new { Success = false, Message = PromptInformation.RemotingError }));
            }

            if (string.IsNullOrEmpty(errorMsg))
            {
                #region 返回数据
                var    responseData = syncResult.ResultData.ParaItems;
                string plateColor   = null;
                if (responseData.车牌颜色.HasValue)
                {
                    plateColor = responseData.车牌颜色.ToString();
                }

                dynamic result = new ExpandoObject();
                result.HeartbeatInterval          = responseData.终端心跳发送间隔;
                result.PrimaryServerIP            = responseData.主服务器IP地址或域名;
                result.BackupServerIP             = responseData.备份服务器IP地址或域名;
                result.ServerTCPPort              = responseData.务器TCP端口;
                result.StateRepotrIntervalSleep   = responseData.休眠时汇报时间间隔;
                result.StateRepotrIntervalUrgent  = responseData.紧急报警时汇报时间间隔;
                result.StateRepotrIntervalGeneral = responseData.缺省时间汇报间隔;
                result.MaximumSpeed                   = responseData.最高速度;
                result.OverspeedCheckTime             = responseData.超速持续时间;
                result.MaximumDrivingTime             = responseData.连续驾驶时间门限;
                result.MaximumDrivingTimeToday        = responseData.当天累计驾驶时间门限;
                result.MinimumBreakTime               = responseData.最小休息时间;
                result.MaximumStoppingTime            = responseData.最长停车时间;
                result.DifferenceOfOverspeedValues    = responseData.超速报警预警差值;
                result.DifferenceOfFatigueDrivingTime = responseData.疲劳驾驶预警差值;
                result.TotalODO          = responseData.车辆里程表读数;
                result.MotorNumberPlate  = responseData.公安交通管理部门颁发的机动车号牌;
                result.LicensePlateColor = plateColor;
                #endregion
                return(Json(new { Success = true, Message = JsonConvert.SerializeObject(result) }));
            }
            else
            {
                return(Json(new { Success = false, Message = errorMsg }));
            }
        }
        public async Task <ActionResult> SendTextMessage(SendTextMessageModel model)
        {
            ActionResult            result  = null;
            List <TerminalWCfModel> wcfList = null;

            if (!this.CheckWCF(model.ListVehicles, out result, out wcfList))
            {
                return(result);
            }
            //升级指令包含<>,但是为了安全性是不允许提交<>这样的html字符的,虽然可以通过一下方式让MVC项目的请求允许通过html字符,但是不合适,所以
            //这里呢要求数据本身是html编码,到后台再转回成已解码的字符串
            //比如 升级指令 <EXT87DDE2B7AE0B45FX-GPS000000000000000000PP> ,在文本框里输入&lt;EXT87DDE2B7AE0B45FX-GPS000000000000000000PP&gt;
            //到后台再解码成<>就行了

            /**
             * web.config里面加上
             *
             *  <system.web>
             *      <httpRuntime requestValidationMode="2.0" />
             *  </system.web>
             */
            var realMessageText = System.Web.HttpUtility.HtmlDecode(model.MessageText);

            model.MessageText = realMessageText;

            // 记录错误信息
            string errorMsg = string.Empty;

            try
            {
                // 所有任务完成时获取返回结果
                var syncResult = await this.DoOperation <SendTextMessageModel, OperationResultGeneralRep>(wcfList, model, SyncSendTextInfo).ConfigureAwait(false);

                int      index     = 0;
                string   valuesSql = string.Empty;
                string   setInfo   = "Flags:" + (TextInformationFlag)model.Flags + ",MessageText:" + model.MessageText;
                string   wanIP     = GetRemoteAddress();
                DateTime setDTime  = DateTime.Now;

                foreach (var item in syncResult)
                {
                    string plateNum       = wcfList[index].PlateNum;
                    string resultResponse = "Code:" + (int)(OperationResultCode)item.Code + ";Message:" + item.Message;

                    // 记录日志 文本消息下发 这里拼接sql语句 批量插入
                    valuesSql += string.Format("('{0}','{1}',{2},'{3}',{4},'{5}','{6}',{7},'{8}'),",
                                               wcfList[index].TerminalCode, plateNum, (byte)TerminalSettingTypeEnum.TextMessage,
                                               setInfo, item.State ? 1 : 0, resultResponse, wanIP, base.CurrentUserID, setDTime);
                    if (!item.State)
                    {
                        //errorMsg += string.Format("<div style='font-weight:bolder;'>" + UIText.TerminalSetting_PlateNumber + ":{0}{1}," + PromptInformation.FailReason+ ":{2}{3}</div>", plateNum, "<br/>",
                        //                                             item.Code.ToString(), "<hr/>");
                        errorMsg += ErrorMesage(plateNum, item.Code.ToString());
                    }
                    index++;
                }
                // 批量插入日志
                TerminalSettingsBLL.BatchInsertTerminalOperationsLog(valuesSql.TrimEnd(','));
            }
            catch (Exception ex)
            {
                LogHelper.TerminalSettingsErrorLog("下发文本消息异常:" + ex.Message);
                return(Json(new { Success = false, Message = PromptInformation.RemotingError }));
            }

            if (string.IsNullOrEmpty(errorMsg))
            {
                return(Json(new { Success = true, Message = PromptInformation.TerminalSetting_SendTextMessageSuccess }));
            }
            else
            {
                return(Json(new { Success = false, Message = errorMsg }));
            }
        }