Пример #1
0
        public virtual async Task <List <PriceResultOutput> > Handle(IndoorPriceAndSaveCommand request, CancellationToken cancellationToken)
        {
            // 获取报价结果
            var result = await _priceAppService.IndoorPriceBatch(request.IndoorPrice);

            if (result.IsSuccess)
            {
                // 获取用户分成配置
                var rateInfo = _settingRepository.GetAll().Where(i => i.Id == request.IndoorPrice.UserId).Select(i => new
                {
                    i.Rate,
                    i.RateType
                }).FirstOrDefault();
                if (rateInfo != null)
                {
                    // 处理返回报价信息,写分成
                    await UpdateAskPriceViolationInfo(request.IndoorPrice.CarNumber, request.IndoorPrice.BatchId, rateInfo.Rate, rateInfo.RateType, result.Data);

                    // 更新报价缓存的状态
                    if (!request.GlobalKey.IsNullOrWhiteSpace())
                    {
                        try
                        {
                            //等待3分钟
                            _mut.WaitOne(TimeSpan.FromMinutes(3));
                            var globalKey   = request.GlobalKey;
                            var cacheObject = await _cacheManager.GetCache(globalKey).GetOrDefaultAsync(globalKey);

                            if (cacheObject != null)
                            {
                                QuotePriceStation station = (QuotePriceStation)cacheObject;
                                station.CompleteCount = station.CompleteCount + 1;
                                await _cacheManager.GetCache(globalKey).SetAsync(globalKey, station);
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.ErrorFormat("Action:IndoorPriceAndSaveCommand-UpdateCacheObject,Request:{0},Exception{1}", request, ex);
                        }
                        finally
                        {
                            _mut.ReleaseMutex();
                        }
                    }
                }
                return(result.Data);
            }
            return(null);
        }
Пример #2
0
        public async Task <ApiResult> QuotePrice(PriceInput input)
        {
            ApiResult apiResult = new ApiResult();
            Hashtable hst       = new Hashtable();

            if (!Limit(hst, input.BatchId, "QueryViolation_Agent", out string globalKey))
            {
                return(apiResult.Error());
            }
            var batchInfo = await _batchInfoRepository.GetAsync(input.BatchId);

            var carList = await _batchCarRepository.GetAllListAsync(o => o.WebSiteId == AbpSession.WebSiteId && o.BatchId == input.BatchId);

            if (carList == null || carList.Count == 0)
            {
                return(ApiResult.DataNotFound());
            }
            // 缓存报价进度
            var station = new QuotePriceStation
            {
                Id            = input.BatchId,
                AllCount      = carList.Count,
                CompleteCount = 0,
            };
            await _cacheManager.GetCache(globalKey).SetAsync(globalKey, station);

            // 后台处理
            await Task.WhenAll(carList.Select(i =>
            {
                var priceRequest       = i.MapTo <IndoorPriceInput>();
                priceRequest.UserId    = batchInfo.ProxyUserId;
                priceRequest.WebSiteId = AbpSession.WebSiteId;
                return(_bus.Send(new IndoorPriceAndSaveCommand
                {
                    GlobalKey = globalKey,
                    IndoorPrice = priceRequest
                }));
            })).ConfigureAwait(false);

            return(apiResult.Success());
        }