public static void Save(long buid, int lastnewcar, IQuoteReqCarinfoRepository repository)
        {
            var newquotereq = new bx_quotereq_carinfo
            {
                b_uid         = buid,
                is_lastnewcar = lastnewcar,
                //is_public=request.IsPublic,
                create_time = DateTime.Now,
                update_time = DateTime.Now
            };

            repository.Add(newquotereq);
        }
Exemple #2
0
        /// <summary>
        /// 普通查询车型接口,第二版
        /// </summary>
        /// <param name="request"></param>
        /// <param name="pairs"></param>
        /// <returns></returns>
        public async Task <GetNewCarVehicleInfoResponse> GetCarVehicle(GetVehicleRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            GetNewCarVehicleInfoResponse response = new GetNewCarVehicleInfoResponse();
            //校验:1基础校验
            BaseResponse baseResponse = _validateService.Validate(request, pairs);

            if (baseResponse.Status == HttpStatusCode.Forbidden)
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }

            var topagent = request.Agent;

            //微信端逻辑 次级代理
            if (request.ChildAgent > 0)
            {
                request.Agent = request.ChildAgent;
            }
            //针对车架号+发动机号的逻辑
            bx_userinfo userinfo = null;
            string      xuBaoCacheKey;

            if (!string.IsNullOrWhiteSpace(request.EngineNo) && !string.IsNullOrWhiteSpace(request.CarVin))
            {
                userinfo = _userInfoRepository.FindByCarvin(request.CarVin, request.EngineNo, request.CustKey,
                                                            request.Agent.ToString(), request.CarType);
                xuBaoCacheKey = CommonCacheKeyFactory.CreateKeyWithLicense(string.Format("{0}-{1}-{2}-{3}", topagent, request.CarVin, request.EngineNo, "moldname" + request.CarType));
            }
            else
            {
                userinfo = _userInfoRepository.FindByOpenIdAndLicense(request.CustKey, request.LicenseNo,
                                                                      request.Agent.ToString(), request.CarType);
                xuBaoCacheKey = CommonCacheKeyFactory.CreateKeyWithLicense(string.Format("{0}-{1}-{2}", topagent, request.LicenseNo, "moldname" + request.CarType));
            }
            #region 新增逻辑 平安报价需要区分类型
            if (userinfo != null)
            {
                var reqItem = _quoteReqCarinfoRepository.Find(userinfo.Id);
                if (reqItem != null)
                {
                    reqItem.pingan_quote_type = request.IsNeedCarVin;
                    _quoteReqCarinfoRepository.Update(reqItem);
                }
                else
                {
                    reqItem = new bx_quotereq_carinfo
                    {
                        pingan_quote_type = request.IsNeedCarVin
                    };
                    _quoteReqCarinfoRepository.Add(reqItem);
                }
            }
            #endregion
            if (request.IsNeedCarVin == 0 && request.MoldName.Trim().Length == 0)
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }
            var xuBaoKey = string.Format("{0}-{1}-carmodelListV2-key", xuBaoCacheKey, request.IsNeedCarVin);
            CacheProvider.Remove(xuBaoKey);
            //获取品牌型号
            var moldNameViewModle = await _getMoldNameFromCenter.GetMoldNameService(request.CarVin, request.MoldName, topagent, request.CityCode);

            if (moldNameViewModle != null && !string.IsNullOrEmpty(moldNameViewModle.MoldName))
            {
                request.MoldName = moldNameViewModle.MoldName;
            }
            var msgBody = new
            {
                Agent          = topagent,
                B_Uid          = 0,
                VehicleName    = request.MoldName,
                cityId         = request.CityCode.ToString(),
                NotifyCacheKey = xuBaoCacheKey,
                IsNeedVin      = request.IsNeedCarVin,
                CarVin         = request.CarVin,
                //安心保险需要的2个参数
                LicenseNo    = request.LicenseNo,
                RegisterDate = request.RegisterDate
            };
            //发送信息
            //var msgbody = _messageCenter.SendToMessageCenter(msgBody.ToJson(),
            //    ConfigurationManager.AppSettings["MessageCenter"],
            //    ConfigurationManager.AppSettings["BxVechileQueue2"]);
            try
            {
                string strurl             = string.Format("{0}/service/carModelsv2queue", ConfigurationManager.AppSettings["CenterNewUrl"]);
                string returnServerIpPort = string.Empty;
                string result             = ProxyCenterHttpClient.Post(strurl, msgBody.ToJson(), 60, ref returnServerIpPort);

                var cacheKey = CacheProvider.Get <string>(xuBaoKey);
                if (cacheKey == null)
                {
                    for (int i = 0; i < 60; i++)
                    {
                        cacheKey = CacheProvider.Get <string>(xuBaoKey);
                        if (!string.IsNullOrWhiteSpace(cacheKey))
                        {
                            break;
                        }
                        else
                        {
                            await Task.Delay(TimeSpan.FromSeconds(1));
                        }
                    }
                }
                response.Vehicles = new List <NewBxCarVehicleInfo>();
                if (cacheKey == null)
                {
                    response.BusinessStatus  = -1;//超时
                    response.BusinessMessage = "请求超时";
                }
                else
                {
                    string itemsCache = string.Format("{0}-{1}-carmodelListV2", xuBaoCacheKey, request.IsNeedCarVin);
                    response.BusinessStatus = 1;
                    if (cacheKey == "1")
                    {
                        var temp = CacheProvider.Get <string>(itemsCache);
                        response.Vehicles = temp.FromJson <List <NewBxCarVehicleInfo> >();
                        if (response.Vehicles != null && response.Vehicles.Count > 1)
                        {
                            response.Vehicles = response.Vehicles.OrderBy(x => x.PriceT).ToList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response        = new GetNewCarVehicleInfoResponse();
                response.Status = HttpStatusCode.ExpectationFailed;
                logError.Info("获取车型请求发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }
            return(response);
        }
        public static void QuoteAdd(PostPrecisePriceRequest request, long buid, int publictype, IQuoteReqCarinfoRepository repository)
        {
            bx_quotereq_carinfo newquotereq = new bx_quotereq_carinfo
            {
                is_loans      = request.IsLoans,
                b_uid         = buid,
                car_type      = request.CarType,
                car_used_type = request.CarUsedType,
                seat_count    = request.SeatCount,
                is_newcar     = request.IsNewCar,
                car_ton_count = request.TonCount,
                create_time   = DateTime.Now,
                update_time   = DateTime.Now
            };

            //经办人、送修码、归属人等设置,重写source值
            //if (!string.IsNullOrWhiteSpace(request.ConfigCode))
            //{
            //    //将用户传的configcode的source改为旧值。
            //    var configcodemodel = request.ConfigCode.FromJson<Dictionary<string, Dictionary<string, string>>>();
            //    var newconfigcodemodel = new Dictionary<string, Dictionary<string, string>>();
            //    foreach (var item in configcodemodel)
            //    {
            //        newconfigcodemodel.Add(SourceGroupAlgorithm.GetOldSource(long.Parse(item.Key)).ToString(), item.Value);
            //    }
            //    request.ConfigCode = newconfigcodemodel.ToJson();
            //}
            newquotereq.account_relation = request.ConfigCode;

            //浮动价格
            if (request.NegotiatePrice >= 0)
            {
                newquotereq.co_real_value = request.NegotiatePrice;
            }
            else
            {
                newquotereq.co_real_value = 0;
            }
            //车型选择source
            if (request.VehicleSource > 0)
            {
                newquotereq.moldcode_company = request.VehicleSource;
            }
            //过户车日期逻辑
            if (!string.IsNullOrWhiteSpace(request.TransferDate))
            {
                newquotereq.transfer_date = DateTime.Parse(request.TransferDate);
            }
            else
            {
                newquotereq.transfer_date = null;
            }
            if (!string.IsNullOrWhiteSpace(request.BizStartDate))
            {
                newquotereq.biz_start_date = DateTime.Parse(request.BizStartDate);
            }
            else
            {
                newquotereq.biz_start_date = null;
            }
            if (!string.IsNullOrWhiteSpace(request.ForceStartDate))
            {
                newquotereq.force_start_date = DateTime.Parse(request.ForceStartDate);
            }
            else
            {
                newquotereq.force_start_date = null;
            }
            //精友编码
            if (!string.IsNullOrWhiteSpace(request.AutoMoldCode))
            {
                newquotereq.auto_model_code        = request.AutoMoldCode.Trim();
                newquotereq.auto_model_code_source = 2;
            }
            else
            {
                //20181119,解决续保车补充到其他保司的精友码,中心查到carmold的车型信息跟平安保司不匹配
                //如果是平安,则把数据库的精友码删掉
                if (request.QuoteGroup == 2)
                {
                    newquotereq.auto_model_code        = null;
                    newquotereq.auto_model_code_source = null;
                }
            }
            if (request.AutoMoldCodeSource > 0)
            {
                newquotereq.auto_model_code_source = request.AutoMoldCodeSource;
            }
            //平安备注
            if (!string.IsNullOrWhiteSpace(request.Remark))
            {
                newquotereq.pa_remark = request.Remark;
            }
            else
            {
                newquotereq.pa_remark = string.Empty;
            }
            //时间戳支持
            if (!string.IsNullOrWhiteSpace(request.BizTimeStamp))
            {
                newquotereq.biz_start_date =
                    DateTime.Parse(request.BizTimeStamp.UnixTimeToDateTime().ToString("yyyy-MM-dd HH") +
                                   ":00:00");
            }
            //else
            //{
            //    newquotereq.biz_start_date = null;
            //}
            if (!string.IsNullOrWhiteSpace(request.ForceTimeStamp))
            {
                newquotereq.force_start_date =
                    DateTime.Parse(request.ForceTimeStamp.UnixTimeToDateTime().ToString("yyyy-MM-dd HH") +
                                   ":00:00");
            }
            //else
            //{
            //    newquotereq.force_start_date = null;
            //}
            //商业险短时起保
            if (!string.IsNullOrWhiteSpace(request.BizShortEndDate))
            {
                newquotereq.biz_end_date =
                    DateTime.Parse(request.BizShortEndDate.UnixTimeToDateTime().ToString("yyyy-MM-dd HH") +
                                   ":00:00");
                newquotereq.IsShortQuote = 1;
            }
            else
            {
                newquotereq.biz_end_date = null;
                newquotereq.IsShortQuote = 0;
            }
            //if (request.IsPublic > 0)
            //{
            //    newquotereq.is_public = request.IsPublic;
            //}
            if (request.CarUsedType == 6 || request.CarUsedType == 7 || request.CarUsedType == 20)
            {
            }
            else
            {
                if (publictype > 0)
                {
                    newquotereq.is_public = publictype;
                }
            }
            if (request.ClauseType > 0)
            {
                newquotereq.clause_type = request.ClauseType;
            }
            if (request.FuelType > 0)
            {
                newquotereq.fuel_type = request.FuelType;
            }
            if (request.ProofType > 0)
            {
                newquotereq.proof_type = request.ProofType;
            }
            if (request.RunMiles > 0)
            {
                newquotereq.run_miles = request.RunMiles;
            }
            if (request.RateFactor4 > 0)
            {
                newquotereq.special_rate = request.RateFactor4;
            }
            if (request.LicenseColor > 0)
            {
                newquotereq.license_color = request.LicenseColor;
            }
            if (request.SeatCount > 0)
            {
                newquotereq.seat_count = request.SeatCount;
            }
            if (request.ExhaustScale > 0)
            {
                newquotereq.exhaust_scale = request.ExhaustScale;
            }
            if (request.PurchasePrice > 0)
            {
                newquotereq.PriceT = request.PurchasePrice;
            }
            newquotereq.drivlicense_cartype_name  = request.DriveLicenseTypeName;
            newquotereq.drivlicense_cartype_value = request.DriveLicenseTypeValue;
            if (!string.IsNullOrWhiteSpace(request.OwnerOrg))
            {
                newquotereq.ownerOrg = request.OwnerOrg;
            }
            if (!string.IsNullOrWhiteSpace(request.PolicyOrg))
            {
                newquotereq.policyOrg = request.PolicyOrg;
            }
            if (!string.IsNullOrWhiteSpace(request.RenBaoRateSplit))
            {
                newquotereq.renBaoRateSplit = request.RenBaoRateSplit; //.ToJson();
            }
            //特殊折扣申请
            if (request.SpecialDiscount > 0)
            {
                newquotereq.special_discount_application = request.SpecialDiscount;
            }
            //是否修改座位数
            if (request.SeatUpdated != -1)
            {
                newquotereq.seatflag = request.SeatUpdated;
            }
            //太平洋实际折扣系数 20180725by gpj
            newquotereq.ActualDiscounts = request.ActualDiscounts;
            newquotereq.VehicleAlias    = request.VehicleAlias;
            newquotereq.VehicleYear     = request.VehicleYear;

            if (string.IsNullOrWhiteSpace(request.DiscountJson))
            {
                newquotereq.TrCausesWhy           = "";
                newquotereq.SubmitRate            = 0;
                newquotereq.ChannelRate           = 0;
                newquotereq.actualdiscounts_ratio = "";
            }
            else
            {
                //前端传折扣json进来
                List <DiscountViewModel> dclist = new List <DiscountViewModel>();
                try
                {
                    //将折扣json转成对象
                    dclist = request.DiscountJson.FromJson <List <DiscountViewModel> >();
                }
                catch (Exception ex)
                {
                }
                if (dclist.Any())
                {
                    //拼接actualdiscounts_ratio的数组
                    Dictionary <int, decimal> dictionary = new Dictionary <int, decimal>();
                    foreach (var dc in dclist)
                    {
                        if (dc.Source == 1)
                        {//兼容之前逻辑,把太平洋单独字段存ActualDiscounts中
                            newquotereq.ActualDiscounts = dc.AD;
                        }
                        if (dc.Source == 2)
                        {//平安单独保存3个字段
                            newquotereq.TrCausesWhy = dc.TRCR;
                            newquotereq.SubmitRate  = dc.SR;
                            newquotereq.ChannelRate = dc.CR;
                        }
                        //其他折扣率直接存json
                        dictionary.Add(SourceGroupAlgorithm.GetOldSource(dc.Source), dc.AD);
                    }
                    //只有当折扣率有值的时候才保存进来//不过此处肯定有值,除非参数有问题
                    if (dictionary.Any())
                    {
                        newquotereq.actualdiscounts_ratio = dictionary.ToJson();
                    }
                }
            }


            newquotereq.ActualSalesForceRatio = request.ActualSalesForceRatio;
            newquotereq.ActualSalesBizRatio   = request.ActualSalesBizRatio;
            newquotereq.ActualDtaryForceRatio = request.ActualDtaryForceRatio;
            newquotereq.ActualDtaryBizRatio   = request.ActualDtaryBizRatio;
            //是否暂存
            newquotereq.IsTempStorage = request.IsTempStorage;

            //平安底价报价
            newquotereq.IsPaFloorPrice = request.IsPaFloorPrice;
            newquotereq.DriverCard     = request.DriverCard;
            newquotereq.DriverCardType = request.DriverCardType;
            repository.Add(newquotereq);
        }