Пример #1
0
        /// <summary>
        /// 上传 MonitorLog 信息接口
        /// </summary>
        public UploadContract UploadMonitorLog(TransType transType,
                                               MonitorLogContract order, string userId, string token, string unitId)
        {
            string    bizId     = Utils.NewGuid();
            string    methodKey = "ComService.UploadMonitorLog";
            string    ifCode    = "C001";
            var       data      = new UploadContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = null;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = AppType.Client;
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("trans_type", transType);
                htParams.Add("order", order);
                htParams.Add("user_id", userId);
                htParams.Add("token", token);
                htParams.Add("unit_id", unitId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool      statusFlag = false;
                Hashtable htError    = null;
                CertInfo  certInfo   = null;

                #region 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <UploadContract>(htResult));
                }
                //htResult = ErrorService.CheckLength("令牌", token, 1, 32, true, false, ref paramCheckFlag);
                //if (!paramCheckFlag) return ErrorConvert.Export<UploadContract>(htResult);
                //htResult = ErrorService.CheckLength("门店ID", unitId, 1, 32, true, false, ref paramCheckFlag);
                //if (!paramCheckFlag) return ErrorConvert.Export<UploadContract>(htResult);
                #endregion

                #region 检查权限
                Dex.Services.AuthService authService = new Dex.Services.AuthService();

                // 检查User和Customer
                certInfo = authService.GetCertByUserId(userId);
                if (certInfo == null)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A006, "用户ID不存在", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                statusFlag = true;
                //// 检查Token是否不匹配或过期
                //statusFlag = authService.CheckCertToken(token, certInfo.CertId, userId);
                //if (!statusFlag)
                //{
                //    htError = ErrorService.OutputError(ErrorCode.A005, "令牌不匹配或过期", true);
                //    data.status = Utils.GetStatus(false);
                //    data.error_code = htError["error_code"].ToString();
                //    data.error_full_desc = htError["error_desc"].ToString();
                //    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                //    return data;
                //}

                // 查询凭证
                certInfo = authService.GetCertByUserId(userId);
                if (certInfo == null || certInfo.CustomerId == null || certInfo.CustomerId.Length == 0)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A007, "获取后台数据(客户ID)失败", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                string customerId = certInfo.CustomerId;

                htLogExt["customer_code"] = certInfo.CustomerCode;
                htLogExt["customer_id"]   = certInfo.CustomerId;
                htLogExt["user_code"]     = certInfo.UserCode;
                #endregion

                #region 检查单据参数
                Dex.ServicesBs.ComService orderService = new Dex.ServicesBs.ComService();
                if (order.user_id == null || order.user_id.Trim().Length == 0)
                {
                    order.user_id = userId;
                }
                htError = orderService.CheckMonitorLog(order);
                if (!Convert.ToBoolean(htError["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }
                #endregion

                // 保存
                ConfigService cfgService         = new ConfigService();
                bool          enableConnectPosBS = cfgService.GetEnableConnectPosBSCfg();
                if (enableConnectPosBS)
                {
                    try
                    {
                        orderService.SaveMonitorLog(order, customerId, unitId, userId);
                    }
                    catch (Exception ex)
                    {
                        data.status          = Utils.GetStatus(false);
                        data.error_code      = ErrorCode.A018.ToString();
                        data.error_full_desc = ex.ToString();
                        LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                        return(data);
                    }
                }
                else
                {
                    htError              = ErrorService.OutputError(ErrorCode.A012, "连接业务平台数据通道已关闭", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
            }
            return(data);
        }
Пример #2
0
        /// <summary>
        /// 获取日志接口
        /// </summary>
        public GetLogContract GetLog(TransType transType, string userId, string userPwd,
                                     string logId)
        {
            string    bizId     = Utils.NewGuid();
            string    methodKey = "LogService.GetLog";
            string    ifCode    = "C013";
            var       data      = new GetLogContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = null;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = null;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = AppType.Client;
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("trans_type", transType);
                htParams.Add("user_id", userId);
                htParams.Add("user_pwd", userPwd);
                htParams.Add("log_id", logId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool      statusFlag = true;
                Hashtable htError    = null;
                CertInfo  certInfo   = null;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogContract>(htResult));
                }
                htResult = ErrorService.CheckLength("密码", userPwd, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogContract>(htResult));
                }
                htResult = ErrorService.CheckLength("日志ID", logId, 1, 32, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogContract>(htResult));
                }
                #endregion

                Dex.Services.AuthService authService = new Dex.Services.AuthService();

                // 检查User
                Hashtable htUser = new Hashtable();
                htUser.Add("UserId", userId);
                htUser.Add("CertPwd", userPwd);
                statusFlag = authService.Validate(htUser, ref certInfo);
                if (!statusFlag)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A009, "用户ID与密码不匹配", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                // 获取数据
                Services.LogDBService logDBService = new Services.LogDBService();
                LogInfo log = logDBService.GetLogById(logId);
                if (log != null)
                {
                    LogContract logContract = new LogContract();
                    logContract.log_id         = log.LogId;
                    logContract.biz_id         = log.BizId;
                    logContract.biz_name       = log.BizName;
                    logContract.log_type_id    = log.LogTypeId;
                    logContract.log_type_code  = log.LogTypeCode;
                    logContract.log_code       = log.LogCode;
                    logContract.log_body       = log.LogBody;
                    logContract.create_time    = log.CreateTime;
                    logContract.create_user_id = log.CreateUserId;
                    logContract.modify_time    = log.ModifyTime;
                    logContract.modify_user_id = log.ModifyUserId;
                    logContract.customer_code  = log.CustomerCode;
                    logContract.customer_id    = log.CustomerId;
                    logContract.unit_code      = log.UnitCode;
                    logContract.unit_id        = log.UnitId;
                    logContract.user_code      = log.UserCode;
                    logContract.user_id        = log.UserId;
                    logContract.if_code        = log.IfCode;
                    logContract.app_code       = log.AppCode;
                    data.Log = logContract;
                }

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
            }
            return(data);
        }
Пример #3
0
        /// <summary>
        /// 用户凭证验证
        /// </summary>
        public ValidateContract Validate(TransType transType, string userCode,
                                         string customerCode, string password, string type)
        {
            string    bizId     = Utils.NewGuid();
            string    methodKey = "AuthService.Validate";
            string    ifCode    = "C003";
            var       data      = new ValidateContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = customerCode;
            htLogExt["customer_id"]   = null;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = null;
            htLogExt["user_code"]     = userCode;
            htLogExt["user_id"]       = null;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = AppType.Client;
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("trans_type", transType);
                htParams.Add("user_code", userCode);
                htParams.Add("customer_code", customerCode);
                htParams.Add("password", password);
                htParams.Add("type", type);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, null, htLogExt);

                bool      statusFlag = false;
                Hashtable htError    = null;
                string    userId     = string.Empty;
                string    token      = string.Empty;
                CertInfo  certInfo   = null;

                if (type == null || type == string.Empty)
                {
                    type = CertType.POS.ToString();
                }

                Dex.Services.AuthService authService = new Dex.Services.AuthService();

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户代码", userCode, 1, 40, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <ValidateContract>(htResult));
                }
                htResult = ErrorService.CheckLength("用户密码", password, 1, 40, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <ValidateContract>(htResult));
                }

                if (type == CertType.POS.ToString())
                {
                    htResult = ErrorService.CheckLength("客户代码", customerCode, 1, 40, true, false, ref paramCheckFlag);
                    if (!paramCheckFlag)
                    {
                        return(ErrorConvert.Export <ValidateContract>(htResult));
                    }
                }
                else
                {
                    htResult = ErrorService.CheckLength("客户代码", customerCode, 0, 40, true, false, ref paramCheckFlag);
                    if (!paramCheckFlag)
                    {
                        return(ErrorConvert.Export <ValidateContract>(htResult));
                    }
                }
                #endregion

                // 查询用户或客户是否存在
                //certInfo = authService.GetCertByUserId(userId);
                //if (certInfo == null)
                //{
                //    htError = ErrorService.OutputError(ErrorCode.A006, "用户ID不存在", true);
                //    data.status = Utils.GetStatus(false);
                //    data.error_code = htError["error_code"].ToString();
                //    data.error_desc = htError["error_desc"].ToString();
                //    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId);
                //    return data;
                //}

                // 查询凭证
                Hashtable htCert = new Hashtable();
                htCert["UserCode"]     = userCode;
                htCert["CustomerCode"] = customerCode;
                htCert["CertPwd"]      = password;
                if (type == CertType.MOBILE.ToString())
                {
                    htCert["CustomerCode"] = null;
                    htCert["CertTypeCode"] = type.ToLower();
                }
                statusFlag = authService.Validate(htCert, ref certInfo);
                if (!statusFlag)
                {
                    htError = ErrorService.OutputError(ErrorCode.A009, "用户代码与密码/用户代码与客户代码不匹配", true);
                    if (type == CertType.MOBILE.ToString())
                    {
                        htError = ErrorService.OutputError(ErrorCode.A009, "用户代码与密码不匹配", true);
                    }
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                }
                else
                {
                    userId = certInfo.UserId;
                    // 获取令牌
                    var certTokenInfo = GetCertToken(certInfo.CertId, certInfo.UserId, true);
                    token               = certTokenInfo.CertToken;
                    data.user_id        = userId;
                    data.token          = token;
                    htLogExt["user_id"] = userId;
                }

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), null, htLogExt);
            }
            return(data);
        }
Пример #4
0
        /// <summary>
        /// 获取日志集合接口
        /// </summary>
        public GetLogsContract GetLogs(TransType transType, string userId, string userPwd,
                                       long startRow, long rowsCount, LogQueryInfo queryInfo)
        {
            string    bizId     = Utils.NewGuid();
            string    methodKey = "LogService.GetLogs";
            string    ifCode    = "C011";
            var       data      = new GetLogsContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = null;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = null;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = AppType.Client;
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("trans_type", transType);
                htParams.Add("user_id", userId);
                htParams.Add("user_pwd", userPwd);
                htParams.Add("start_row", startRow);
                htParams.Add("rows_count", rowsCount);
                htParams.Add("query_info", queryInfo);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool      statusFlag = true;
                Hashtable htError    = null;
                CertInfo  certInfo   = null;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("密码", userPwd, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }

                // queryInfo
                htResult = ErrorService.CheckLength("日志ID", queryInfo.log_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("业务ID", queryInfo.biz_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("业务名称", queryInfo.biz_name, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("日志类型ID", queryInfo.log_type_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("日志类型代码", queryInfo.log_type_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("日志代码", queryInfo.log_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("日志内容", queryInfo.log_body, 0, 200, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("开始创建时间", queryInfo.create_time_begin, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("结束创建时间", queryInfo.create_time_end, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("创建人ID", queryInfo.create_user_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("开始修改时间", queryInfo.modify_time_begin, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("结束修改时间", queryInfo.modify_time_end, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("修改人ID", queryInfo.modify_user_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("客户代码", queryInfo.customer_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("客户ID", queryInfo.customer_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("门店代码", queryInfo.unit_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("门店ID", queryInfo.unit_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("用户代码", queryInfo.user_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("用户ID", queryInfo.user_id, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("接口代码", queryInfo.if_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                htResult = ErrorService.CheckLength("平台代码", queryInfo.app_code, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <GetLogsContract>(htResult));
                }
                #endregion

                Hashtable htQueryInfo = new Hashtable();
                htQueryInfo.Add("LogId", queryInfo.log_id);
                htQueryInfo.Add("BizId", queryInfo.biz_id);
                htQueryInfo.Add("BizName", queryInfo.biz_name);
                htQueryInfo.Add("LogTypeId", queryInfo.log_type_id);
                htQueryInfo.Add("LogTypeCode", queryInfo.log_type_code);
                htQueryInfo.Add("LogCode", queryInfo.log_code);
                htQueryInfo.Add("LogBody", queryInfo.log_body);
                htQueryInfo.Add("CreateTimeBegin", queryInfo.create_time_begin);
                htQueryInfo.Add("CreateTimeEnd", queryInfo.create_time_end);
                htQueryInfo.Add("CreateUserId", queryInfo.create_user_id);
                htQueryInfo.Add("ModifyTimeBegin", queryInfo.modify_time_begin);
                htQueryInfo.Add("ModifyTimeEnd", queryInfo.modify_time_end);
                htQueryInfo.Add("ModifyUserId", queryInfo.modify_user_id);
                htQueryInfo.Add("CustomerCode", queryInfo.customer_code);
                htQueryInfo.Add("CustomerId", queryInfo.customer_id);
                htQueryInfo.Add("UnitCode", queryInfo.unit_code);
                htQueryInfo.Add("UnitId", queryInfo.unit_id);
                htQueryInfo.Add("UserCode", queryInfo.user_code);
                htQueryInfo.Add("UserId", queryInfo.user_id);
                htQueryInfo.Add("IfCode", queryInfo.if_code);
                htQueryInfo.Add("AppCode", queryInfo.app_code);

                Dex.Services.AuthService authService = new Dex.Services.AuthService();

                // 检查User
                Hashtable htUser = new Hashtable();
                htUser.Add("UserId", userId);
                htUser.Add("CertPwd", userPwd);
                statusFlag = authService.Validate(htUser, ref certInfo);
                if (!statusFlag)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A009, "用户ID与密码不匹配", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                // 获取数据
                Services.LogDBService logDBService = new Services.LogDBService();
                IList <LogInfo>       logs         = logDBService.GetLogs(htQueryInfo, startRow, rowsCount);
                if (logs != null)
                {
                    data.Logs = new List <LogContract>();
                    foreach (var log in logs)
                    {
                        LogContract logContract = new LogContract();
                        logContract.log_id         = log.LogId;
                        logContract.biz_id         = log.BizId;
                        logContract.biz_name       = log.BizName;
                        logContract.log_type_id    = log.LogTypeId;
                        logContract.log_type_code  = log.LogTypeCode;
                        logContract.log_code       = log.LogCode;
                        logContract.log_body       = log.LogBody;
                        logContract.create_time    = log.CreateTime;
                        logContract.create_user_id = log.CreateUserId;
                        logContract.modify_time    = log.ModifyTime;
                        logContract.modify_user_id = log.ModifyUserId;
                        logContract.customer_code  = log.CustomerCode;
                        logContract.customer_id    = log.CustomerId;
                        logContract.unit_code      = log.UnitCode;
                        logContract.unit_id        = log.UnitId;
                        logContract.user_code      = log.UserCode;
                        logContract.user_id        = log.UserId;
                        logContract.if_code        = log.IfCode;
                        logContract.app_code       = log.AppCode;
                        data.Logs.Add(logContract);
                    }
                }

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
            }
            return(data);
        }
Пример #5
0
        /// <summary>
        /// 修改用户密码接口
        /// </summary>
        public BaseContract ChangePassword(TransType transType,
                                           string userId, string token, string unitId, string newPassword)
        {
            string    bizId     = Utils.NewGuid();
            string    methodKey = "AuthService.ChangePassword";
            string    ifCode    = "C029";
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = null;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = AppType.Client;
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("trans_type", transType);
                htParams.Add("user_id", userId);
                htParams.Add("token", token);
                htParams.Add("unit_id", unitId);
                htParams.Add("new_password", newPassword);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, null, htLogExt);

                bool      statusFlag = false;
                Hashtable htError    = null;
                CertInfo  certInfo   = null;

                Dex.Services.AuthService authService = new Dex.Services.AuthService();

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <BaseContract>(htResult));
                }
                //htResult = ErrorService.CheckLength("令牌", token, 1, 32, true, false, ref paramCheckFlag);
                //if (!paramCheckFlag) return ErrorConvert.Export<BaseContract>(htResult);
                htResult = ErrorService.CheckLength("门店ID", unitId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <BaseContract>(htResult));
                }
                htResult = ErrorService.CheckLength("用户新密码", newPassword, 1, 40, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <BaseContract>(htResult));
                }
                #endregion

                // 检查User和Customer
                certInfo = authService.GetCertByUserId(userId);
                if (certInfo == null)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A006, "用户ID不存在", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                statusFlag = true;
                // 检查Token是否不匹配或过期
                //statusFlag = authService.CheckCertToken(token, certInfo.CertId, userId);
                //if (!statusFlag)
                //{
                //    htError = ErrorService.OutputError(ErrorCode.A005, "令牌不匹配或过期", true);
                //    data.status = Utils.GetStatus(false);
                //    data.error_code = htError["error_code"].ToString();
                //    data.error_full_desc = htError["error_desc"].ToString();
                //    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                //    return data;
                //}

                // 查询凭证
                certInfo = authService.GetCertByUserId(userId);
                if (certInfo == null || certInfo.CustomerId == null || certInfo.CustomerId.Length == 0)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A007, "获取后台数据(客户ID)失败", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                string customerId = certInfo.CustomerId;

                htLogExt["customer_code"] = certInfo.CustomerCode;
                htLogExt["customer_id"]   = certInfo.CustomerId;
                htLogExt["user_code"]     = certInfo.UserCode;

                // 提交
                var bsAuthService = new ServicesBs.AuthService();
                bsAuthService.ChangePassword(customerId, unitId, userId, newPassword);
                authService.UpdateCertPwdByUserId(userId, newPassword);

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), null, htLogExt);
            }
            return(data);
        }