예제 #1
0
        /// <summary>
        /// 基础数据校验
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        protected override UpgradeResult Execute(UpgradeParameter parameter)
        {
            this.UpgradeRule = parameter.UpgradeRule;
            var ruleConfig = Resolve <IRuleModuleService>().GetConfigValue(this.UpgradeRule.ModuleId, this.UpgradeRule.Value);
            var config     = (dynamic)ruleConfig;

            config.RewardRule = this.UpgradeRule;
            this.Config       = (TConfiguration)config;
            if (Config == null)
            {
                return(UpgradeResult.Failure("DataDependencyRule.Config 维度规则配置为空"));
            }

            //进行参数判断
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            this.UpgradeQueue = parameter.UpgradeQueue;
            if (this.UpgradeQueue == null)
            {
                return(UpgradeResult.Failure("DataDependencyRule.Execute 分润中台订单为空"));
            }
            if (this.UpgradeQueue.Id <= 0)
            {
                return(UpgradeResult.Failure("DataDependencyRule.Execute 分润中台订单Id未找到"));
            }
            //判断当前执行队列
            var upgradeQueue = Alabo.Helpers.Ioc.Resolve <IUpgradeQueueService>().GetSingle(r => r.Id == this.UpgradeQueue.Id);

            if (upgradeQueue == null)
            {
                return(UpgradeResult.Failure($"DataDependencyRule.Execute 升级队列为空,订单Id{this.UpgradeQueue.Id}"));
            }
            if (upgradeQueue.Status != QueueStatus.Pending)
            {
                return(UpgradeResult.Failure($"DataDependencyRule.Execute 升级队列状态不是待处理状态,不触发分润."));
            }

            this.UpgradeQueue = upgradeQueue;

            this.MoneyTypes = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>(r => r.Status == Status.Normal);
            return(new UpgradeResult(true));
        }
예제 #2
0
 /// <summary>
 /// 执行方法
 /// </summary>
 /// <param name="parameter"></param>
 /// <returns></returns>
 protected abstract UpgradeResult Execute(UpgradeParameter parameter);
예제 #3
0
        /// <summary>
        /// 开始执行分润
        /// </summary>
        /// <param name="moduleType"></param>
        /// <param name="shareOrder"></param>
        public void ExecuteTask(Type moduleType, Trade shareOrder)
        {
            var ruleAttribute = moduleType.GetTypeInfo().GetAttribute <RuleAttribute>();

            if (ruleAttribute == null)
            {
                return;
            }

            //从数据库中获取所有分润模块
            var modules = Ioc.Resolve <IRewardRuleService>().GetEnableList(ruleAttribute.Id);

            if (!modules.Any())
            {
                return;
            }

            var  resultList = new List <UpgradeResultItem>();
            long count      = 0;

            foreach (var item in modules)
            {
                if (item.Limit.TriggerType != shareOrder.TriggerType)
                {
                    continue;
                }

                try {
                    UpgradeParameter UpgradeParameter = new UpgradeParameter {
                        RewardRule = item,
                        Trade      = shareOrder
                    };

                    var instance   = Activator.CreateInstance(moduleType);
                    var parameters = new[]
                    {
                        new Parameter("parameter", UpgradeParameter)
                    };
                    var target     = new Interpreter().SetVariable("entityService", instance);
                    var evalString = $"entityService.Execute(parameter)";
                    var result     = (UpgradeResult)target.Eval(evalString, parameters);

                    if (result.Succeeded)
                    {
                        count++;
                        resultList.AddRange(result.Result);
                    }
                    else
                    {
                        Ioc.Resolve <IShareService>().AddMessage(result?.Message, shareOrder, ruleAttribute, item);
                    }
                } catch (Exception ex) {
                    Ioc.Resolve <IShareService>().AddMessage(ex.Message, shareOrder, ruleAttribute, item);
                }
            }

            if (resultList.Count > 0)
            {
                var shareOrderNative = Ioc.Resolve <IShareService>().GetSingleNative(shareOrder.Id);
                if (shareOrderNative.Status == ShareOrderStatus.Pending)
                {
                    // 更新结果
                    Ioc.Resolve <IShareRepository>().UpdatePriceTaskResult(resultList);
                }

                // 更新次数
                Ioc.Resolve <IShareRepository>().UpdateExcuteCount(shareOrder.Id, count);
            }
        }