Exemple #1
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 #2
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("更改计划成功");
        }