/// <summary>
        /// 下载报检数据
        /// </summary>
        /// <param name="keyValue">激活码</param>
        /// <param name="machineCode">机器代码</param>
        /// <param name="cusCiqNo">关检关联号</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public string DownloadCiqData(string keyValue, string machineCode, string cusCiqNo, string password)
        {
            LogHelper logHelper = LogHelper.GetInstance();

            try
            {
                if (string.IsNullOrEmpty(cusCiqNo))
                {
                    throw new Exception(Context.ErrCusCiqNoInvalid);
                }
                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception(Context.ErrRPwdInvalid);
                }
                IMessageDataHelper msgDataHelper = DataHelperFactory.GetMessageDataHelper();
                //检查激活码是否有效
                if (!Utility.CheckKey(msgDataHelper.GetKeyInfo(keyValue, machineCode)))
                {
                    return(GetErrInfo(Context.ErrKeyValueInvalid, Context.ErrKeyValueInvalidId));
                }
                ;
                IPreserveDataHelper preDataHelper = DataHelperFactory.GetPreserveDataHelper();
                return(preDataHelper.DownloadCiqData(cusCiqNo, password));
            }
            catch (Exception ex)
            {
                logHelper.LogErrInfo(ex.Message, Context.DownloadCiqDataEventId, "DownloadCiqData", keyValue);
                return(GetErrInfo(Context.ErrDownloadCiqData, Context.DownloadCiqDataEventId));
            }
        }
        /// <summary>
        /// 获取服务器上单据的保存时间
        /// </summary>
        /// <param name="cusCiqNo">关检关联号</param>
        /// <returns>返回暂存时间</returns>
        public DateTime GetSaveTime(string cusCiqNo)
        {
            LogHelper logHelper = LogHelper.GetInstance();

            try
            {
                if (string.IsNullOrEmpty(cusCiqNo))
                {
                    return(DateTime.MinValue);
                }
                IPreserveDataHelper preDataHelper = DataHelperFactory.GetPreserveDataHelper();
                return(preDataHelper.GetSaveTime(cusCiqNo));
            }
            catch (Exception ex)
            {
                logHelper.LogErrInfo(ex.Message, Context.GetSaveTimeEventId, "GetSaveTime", cusCiqNo);
                return(DateTime.MinValue);
            }
        }
        /// <summary>
        /// 获取关检关联号(16位)
        /// </summary>
        /// <param name="ieFlag">进出口标识,1为进口,0为出口</param>
        /// <param name="locationCode">现场代码(4位)</param>
        /// <returns>关检关联号(16位)</returns>
        public string GetCusCiqNo(string ieFlag, string locationCode)
        {
            LogHelper logHelper = LogHelper.GetInstance();

            try
            {
                var cusCiqNo = new CusCiqNoInfo()
                {
                    IeFlag = ieFlag, LocationCode = locationCode, CusCiqNo = string.Empty
                };
                if (!new EntityValidator <CusCiqNoInfo>().Validate(cusCiqNo))
                {
                    throw new Exception(Context.ErrIeFlagOrLocalCodeInValid);
                }
                IPreserveDataHelper dataHelper = DataHelperFactory.GetPreserveDataHelper();
                int    index    = dataHelper.GetCusCiqIndex(cusCiqNo.IeFlag, cusCiqNo.LocationCode);
                string indexStr = index.ToString();
                cusCiqNo.CusCiqNo = string.Format("{0}{1}{2}{3}", ieFlag, DateTime.Now.ToString("yyMMdd"), locationCode, indexStr.PadLeft(5, '0'));
                //记录操作日志
                logHelper.LogOperation(string.Format("GetCusCiqNo 获取关检关联号,IeFlag:{0},LocationCode:{1},CusCiqNo:{2}",
                                                     ieFlag, locationCode, cusCiqNo.CusCiqNo), Context.GetCusCiqNoEventId, "GetCusCiqNo");
                if (ConfigInfo.DeclType == 0 && ieFlag == "1")
                {
                    throw new Exception("目前只允许出口业务类型");
                }
                if (ConfigInfo.DeclType == 1 && ieFlag == "0")
                {
                    throw new Exception("目前只允许进口业务类型");
                }

                return(cusCiqNo.CusCiqNo);
            }
            catch (Exception ex)
            {
                logHelper.LogErrInfo(ex.Message, Context.GetCusCiqNoEventId, "GetCusCiqNo");
                return(GetErrInfo(Context.ErrGetCusCiqNo, Context.GetCusCiqNoEventId));
            }
        }
        /// <summary>
        /// 上传报关和报检数据(暂存数据)
        /// </summary>
        /// <param name="keyValue">激活码</param>
        /// <param name="machineCode">机器代码</param>
        /// <param name="ieFlag">进出口标识,1为进口,0为出口</param>
        /// <param name="locationCode">现场代码(4位)</param>
        /// <param name="cusCiqNo">关检关联号</param>
        /// <param name="status">数据状态(0,暂存;1,报检;2,上载QP;3,申报)</param>
        /// <param name="cusMsgXml">报关数据报文</param>
        /// <param name="ciqMsgXml">报检数据报文</param>
        /// <returns>返回实体消息</returns>
        public SaveModel UploadAllData(string keyValue,
                                       string machineCode, string ieFlag, string locationCode, string cusCiqNo, int status, string cusMsgXml, string ciqMsgXml)
        {
            CusCiqNoInfo cusCiqNoInfo = new CusCiqNoInfo {
                CusCiqNo = cusCiqNo, IeFlag = ieFlag, LocationCode = locationCode
            };

            if (!new EntityValidator <CusCiqNoInfo>().Validate(cusCiqNoInfo))
            {
                throw new Exception(Context.ErrIeFlagOrLocalCodeInValid);
            }
            SaveModel saveModel = new SaveModel()
            {
                CusCiqNo = cusCiqNo, Password = string.Empty, IsSuccess = false
            };
            LogHelper logHelper = LogHelper.GetInstance();

            try
            {
                IMessageDataHelper msgDataHelper = DataHelperFactory.GetMessageDataHelper();
                //检查激活码是否有效
                if (!Utility.CheckKey(msgDataHelper.GetKeyInfo(keyValue, machineCode)))
                {
                    saveModel.Message = GetErrInfo(Context.ErrKeyValueInvalid, Context.ErrKeyValueInvalidId);;
                    return(saveModel);
                }

                PreCusData preData = new PreCusData
                {
                    CusCiqNoInfo = cusCiqNoInfo,
                    KeyValue     = keyValue,
                    MachineCode  = machineCode,
                    CusMsgXml    = cusMsgXml,
                    CiqMsgXml    = ciqMsgXml,
                    UpdateTime   = DateTime.Now,
                    Password     = Utility.GetRandomNumString(6)
                };
                IPreserveDataHelper preDataHelper = DataHelperFactory.GetPreserveDataHelper();
                //如果暂存成功
                if (preDataHelper.UploadPreCusData(preData) == 1)
                {
                    preData.Password    = preDataHelper.GetPasswordByCusCiqNo(cusCiqNo);
                    saveModel.IsSuccess = true;
                    saveModel.Message   = string.Empty;
                    saveModel.Password  = preData.Password;
                }
                if (status > 0)
                {
                    DeclCusData declData = new DeclCusData
                    {
                        CusCiqNoInfo = preData.CusCiqNoInfo,
                        CiqMsgXml    = preData.CiqMsgXml,
                        CusMsgXml    = preData.CusMsgXml,
                        Status       = (DeclCusData.SaveType)status
                    };
                    preDataHelper.UploadDeclData(declData);
                }
            }
            catch (Exception ex)
            {
                saveModel.Message = GetErrInfo(Context.ErrUploadAllData, Context.UploadAllDataEventId);
                logHelper.LogErrInfo(ex.Message, Context.UploadAllDataEventId, "UploadAllData", keyValue);
            }
            return(saveModel);
        }