Exemple #1
0
        public ICollection <PlanTrackDetail> GetPredictDetailDatas()
        {
            var userNormConfigs =
                _normConfigQueryService.GetUserOrDefaultNormConfigs(LotteryInfo.Id, _lotterySession.UserId);
            var finalLotteryData = _lotteryDataAppService.GetFinalLotteryData(LotteryInfo.Id);

            var cacheKey = string.Format(RedisKeyConstants.LOTTERY_PLANTRACK_DETAIL_KEY,
                                         LotteryInfo.Id, _userMemberRank == MemberRank.Ordinary ?
                                         LotteryConstants.SystemUser : _lotterySession.UserId, finalLotteryData.Period);

            return(_cacheManager.Get <ICollection <PlanTrackDetail> >(cacheKey, () =>
            {
                var predictDetailDatas = new List <PlanTrackDetail>();
                foreach (var userNorm in userNormConfigs)
                {
                    var planTrackDetail = _planTrackAppService.GetPlanTrackDetail(userNorm, LotteryInfo.LotteryCode, _lotterySession.UserId);
                    predictDetailDatas.Add(planTrackDetail);
                }
                while (predictDetailDatas.Any(p => p.CurrentPredictData == null || p.CurrentPredictData.CurrentPredictPeriod < finalLotteryData.NextPeriod))
                {
                    GetPredictDatas();
                    Thread.Sleep(266);
                    predictDetailDatas.Clear();
                    foreach (var userNorm in userNormConfigs)
                    {
                        var planTrackDetail = _planTrackAppService.GetPlanTrackDetail(userNorm, LotteryInfo.LotteryCode, _lotterySession.UserId);
                        predictDetailDatas.Add(planTrackDetail);
                    }
                }

                return predictDetailDatas.OrderBy(p => p.Sort).ToList();
            }));
        }
Exemple #2
0
        public PlanTrackDetail GetPlanTrackDetail(NormConfigDto userNorm, string lotteryCode, string userId)
        {
            var planInfo           = _planInfoQueryService.GetPlanInfoById(userNorm.PlanId);
            var prodictDatas       = _lotteryPredictDataQueryService.GetNormPredictDatas(userNorm.Id, planInfo.PlanNormTable, userNorm.LookupPeriodCount + 1, lotteryCode);
            var currentPredictData = AutoMapper.Mapper.Map <PredictDataDetail>(prodictDatas.FirstOrDefault(p => p.PredictedResult == 2));

            currentPredictData.PredictType = planInfo.DsType;
            // currentPredictData.LotteryData = _lotteryDataAppService.GetLotteryData(planInfo.LotteryInfo.Id,currentPredictData.CurrentPredictPeriod).Data;
            var historyPredictDatas = AutoMapper.Mapper.Map <ICollection <PredictDataDetail> >(prodictDatas.Where(p => p.PredictedResult != 2).ToList());

            historyPredictDatas.ForEach(item =>
            {
                item.LotteryData = _lotteryDataAppService.GetLotteryData(planInfo.LotteryInfo.Id, item.CurrentPredictPeriod).Data;
                item.PredictType = planInfo.DsType;
            });
            var planTrackDetail = new PlanTrackDetail()
            {
                CurrentPredictData  = currentPredictData,
                FinalLotteryData    = _lotteryDataAppService.GetFinalLotteryData(planInfo.LotteryInfo.Id),
                HistoryPredictDatas = historyPredictDatas,
                NormId        = userNorm.Id,
                PlanId        = planInfo.Id,
                PlanName      = planInfo.PlanName,
                Sort          = userNorm.Sort,
                StatisticData = ComputeStatisticData(currentPredictData, historyPredictDatas, userNorm)
            };

            return(planTrackDetail);
        }
Exemple #3
0
        private async Task AllotDefaultPlanNorm(string userId, string lotteryId)
        {
            var defaultUserNorms = _normConfigAppService.GetNormConfigsByUserIdOrDefault(lotteryId);

            var userNormConfigs       = _normConfigAppService.GetUserNormConfig(lotteryId, userId);
            var userDefaultNormConfig =
                _userNormDefaultConfigService.GetUserNormOrDefaultConfig(userId, lotteryId);
            var finalLotteryData = _lotteryDataAppService.GetFinalLotteryData(lotteryId);

            if (!userNormConfigs.Safe().Any())
            {
                foreach (var userNorm in defaultUserNorms)
                {
                    // 如果用户选中的计划则忽略
                    if (userNormConfigs != null && userNormConfigs.Any(p => p.PlanId == userNorm.PlanId))
                    {
                        continue;
                    }
                    var planInfo           = _planInfoAppService.GetPlanInfoById(userNorm.PlanId);
                    var planNormConfigInfo =
                        _normPlanConfigQueryService.GetNormPlanDefaultConfig(planInfo.LotteryInfo.LotteryCode,
                                                                             planInfo.PredictCode);
                    var planCycle     = userNorm.PlanCycle;
                    var forecastCount = userNorm.ForecastCount;
                    if (planNormConfigInfo != null)
                    {
                        if (planCycle > planNormConfigInfo.MaxPlanCycle)
                        {
                            planCycle = planNormConfigInfo.MaxPlanCycle;
                        }
                        if (forecastCount > planNormConfigInfo.MaxForecastCount)
                        {
                            forecastCount = planNormConfigInfo.MaxForecastCount;
                        }
                    }

                    var command = new AddNormConfigCommand(Guid.NewGuid().ToString(), userId,
                                                           lotteryId, planInfo.Id, planCycle,
                                                           forecastCount, finalLotteryData.Period,
                                                           userDefaultNormConfig.UnitHistoryCount, userDefaultNormConfig.HistoryCount,
                                                           userDefaultNormConfig.MinRightSeries,
                                                           userDefaultNormConfig.MaxRightSeries, userDefaultNormConfig.MinErrorSeries,
                                                           userDefaultNormConfig.MaxErrorSeries, userDefaultNormConfig.LookupPeriodCount,
                                                           userDefaultNormConfig.ExpectMinScore, userDefaultNormConfig.ExpectMaxScore, userNorm.Sort);
                    await SendCommandAsync(command);
                }
            }
        }
Exemple #4
0
        public async Task <string> UpdateUserPlans(UserPlanInfoInput input)
        {
            var validatorResult = await _planInfoInputValidator.ValidateAsync(input);

            if (!validatorResult.IsValid)
            {
                throw new LotteryDataException(validatorResult.Errors.Select(p => p.ErrorMessage + "</br>").ToString(";"));
            }

            var authRankInfo =
                _authRankQueryService.GetAuthRankByLotteryIdAndRank(_lotterySession.SystemTypeId,
                                                                    _userMemberRank);

            if (input.PlanIds.Count > authRankInfo.PlanCount)
            {
                throw new LotteryException($"您至多允许选择{authRankInfo.PlanCount}个计划,如果需要选择更多计划,请先升级授权版本");
            }

            _cacheManager.RemoveByPattern("Lottery.PlanTrack");
            var finalLotteryData = _lotteryDataAppService.GetFinalLotteryData(LotteryInfo.Id);

            var userDefaultNormConfig =
                _userNormDefaultConfigService.GetUserNormOrDefaultConfig(_lotterySession.UserId, LotteryInfo.Id);

            var userNormConfigs = _normConfigAppService.GetUserNormConfig(LotteryInfo.Id, _lotterySession.UserId);

            if (userNormConfigs != null && userNormConfigs.Any())
            {
                var deleteUserNormConfigsPlanIds = userNormConfigs.Select(p => p.PlanId).Except(input.PlanIds.Select(p => p.PlanId));
                var deleteUserNormConfigs        =
                    userNormConfigs.Where(p => deleteUserNormConfigsPlanIds.Any(q => q == p.PlanId));
                // 移出本次未选中但是之前选中的计划
                foreach (var config in deleteUserNormConfigs)
                {
                    await SendCommandAsync(new DeteteNormConfigCommand(config.Id));
                }
            }

            foreach (var plan in input.PlanIds)
            {
                // 如果用户选中的计划则忽略
                if (userNormConfigs != null && userNormConfigs.Any(p => p.PlanId == plan.PlanId))
                {
                    continue;
                }
                var planInfo           = _planInfoAppService.GetPlanInfoById(plan.PlanId);
                var planNormConfigInfo =
                    _normPlanConfigQueryService.GetNormPlanDefaultConfig(planInfo.LotteryInfo.LotteryCode,
                                                                         planInfo.PredictCode);
                var planCycle     = userDefaultNormConfig.PlanCycle;
                var forecastCount = userDefaultNormConfig.ForecastCount;
                if (planNormConfigInfo != null)
                {
                    if (planCycle > planNormConfigInfo.MaxPlanCycle)
                    {
                        planCycle = planNormConfigInfo.MaxPlanCycle;
                    }
                    if (forecastCount > planNormConfigInfo.MaxForecastCount)
                    {
                        forecastCount = planNormConfigInfo.MaxForecastCount;
                    }
                }

                if (planInfo.PredictCode == PredictCodeDefinition.RxNumCode)
                {
                    var rxCount = Convert.ToInt32(planInfo.PlanCode.Substring(planInfo.PlanCode.Length - 1));

                    forecastCount = rxCount;
                }

                var command = new AddNormConfigCommand(Guid.NewGuid().ToString(), _lotterySession.UserId,
                                                       LotteryInfo.Id, plan.PlanId, planCycle,
                                                       forecastCount, finalLotteryData.Period,
                                                       userDefaultNormConfig.UnitHistoryCount, userDefaultNormConfig.HistoryCount,
                                                       userDefaultNormConfig.MinRightSeries,
                                                       userDefaultNormConfig.MaxRightSeries, userDefaultNormConfig.MinErrorSeries,
                                                       userDefaultNormConfig.MaxErrorSeries, userDefaultNormConfig.LookupPeriodCount,
                                                       userDefaultNormConfig.ExpectMinScore, userDefaultNormConfig.ExpectMaxScore, plan.Sort);
                await SendCommandAsync(command);
            }

            return("更改计划成功");
        }