Ejemplo n.º 1
0
        /// <summary>
        ///     转换成自动表单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        protected AutoForm ToAutoForm(object model)
        {
            if (model != null)
            {
                return(AutoFormMapping.Convert(model));
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void ConvertTest_Reg()
        {
            var regAutoForm      = AutoFormMapping.Convert <RegInput>();
            var classDescription = typeof(RegInput).FullName.GetClassDescription();
            var content          = regAutoForm.ToJson();

            Assert.True(regAutoForm.Name == classDescription.ClassPropertyAttribute.Name);
            Assert.NotNull(regAutoForm);
        } /*end*/
Ejemplo n.º 3
0
        public void ConvertTest_RechargeAddInput()
        {
            var regAutoForm      = AutoFormMapping.Convert <RechargeAddInput>();
            var classDescription = typeof(RechargeAddInput).FullName.GetClassDescription();
            var content          = regAutoForm.ToJson();

            Assert.True(content.Contains("Api/Common/GetKeyValuesByEnum?type",
                                         StringComparison.CurrentCultureIgnoreCase));

            Assert.True(regAutoForm.Name == classDescription.ClassPropertyAttribute.Name);
            Assert.NotNull(regAutoForm);
        }
Ejemplo n.º 4
0
        public AutoForm GetAutoForm(Guid moduleId)
        {
            var taskModuleAttribute = Resolve <ITaskQueueService>().GetTaskModuleAttribute(moduleId);

            if (taskModuleAttribute == null)
            {
                return(null);
            }

            var autoForm = AutoFormMapping.Convert(taskModuleAttribute.ConfigurationType.FullName);

            return(autoForm);
        }
Ejemplo n.º 5
0
        public Tuple <ServiceResult, RewardRuleOutput> GetEditView(Guid moduleId, ObjectId id)
        {
            #region 安全验证

            var taskModuleAttribute = Resolve <ITaskQueueService>().GetTaskModuleAttribute(moduleId);
            if (taskModuleAttribute == null)
            {
                return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.FailedWithMessage("类型不存在,请确定Id是否输入正确"),
                                                                   null));
            }

            #endregion 安全验证

            var view = new RewardRuleOutput
            {
                AutoForm = AutoFormMapping.Convert(taskModuleAttribute.ConfigurationType.FullName),
                Base     = new RewardEditOutputBase
                {
                    Name    = taskModuleAttribute.Name,
                    Title   = taskModuleAttribute.Name,
                    Intro   = taskModuleAttribute.Intro,
                    Summary = $"{taskModuleAttribute.Name}的简要说明"
                },
                ModuleId = moduleId
            };

            IList <AssetsRule> ruleItems = new List <AssetsRule>();
            var rule = new AssetsRule
            {
                MoneyTypeId = Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid(),
                Ratio       = 0.8m
            };
            ruleItems.Add(rule);
            var moneyType = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>().FirstOrDefault(r =>
                                                                                                      r.Id != Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid() && r.Status == Status.Normal);
            rule = new AssetsRule
            {
                MoneyTypeId = moneyType.Id,
                Ratio       = 0.2m
            };
            ruleItems.Add(rule);
            view.RuleItems = ruleItems;

            return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.Success, view));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     get auto form
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public AutoForm GetAutoForm(object obj)
        {
            //data
            if (obj == null)
            {
                return(null);
            }

            var discountList = obj.MapTo <MemberDiscountActivity>()?.DiscountList;

            if (discountList == null || discountList.Count <= 0)
            {
                return(null);
            }

            //builder auto form
            var fieldGroups = AutoFormMapping.GetFormFields(discountList).ToList();

            fieldGroups.ForEach(group =>
            {
                var fields    = new List <FormFieldProperty>();
                var gradeItem = group.Items.ToList().Find(i => i.Field == "gradeItems");
                var jsonItems = gradeItem?.JsonItems;
                jsonItems.Foreach(item =>
                {
                    var tempField = item.Items.ToList().Find(i => i.Field == "price");
                    if (tempField == null)
                    {
                        return;
                    }

                    tempField.Name  = item.Items.ToList().Find(i => i.Field == "name").Value?.ToString();
                    tempField.Field = item.Items.ToList().Find(i => i.Field == "id").Value?.ToString();
                    fields.Add(tempField);
                });
                group.Items.Remove(gradeItem);
                //add
                group.Items.AddRange(fields);
            });
            var autoForm = AutoFormMapping.Convert <MemberDiscountActivity>();

            autoForm.Groups[0].Items[0].JsonItems = fieldGroups;
            return(autoForm);
        }
Ejemplo n.º 7
0
        public Tuple <ServiceResult, RewardEditSimpleView> GetEditSimpleView(Guid moduleId)
        {
            var taskModuleAttribute = Resolve <ITaskQueueService>().GetTaskModuleAttribute(moduleId);

            if (taskModuleAttribute == null)
            {
                return(new Tuple <ServiceResult, RewardEditSimpleView>(
                           ServiceResult.FailedWithMessage("类型不存在,请确定Id是否输入正确"), null));
            }

            var view = new RewardEditSimpleView
            {
                Name     = taskModuleAttribute.Name,
                Intro    = taskModuleAttribute.Intro,
                AutoForm = AutoFormMapping.Convert(taskModuleAttribute.ConfigurationType.FullName)
            };

            return(new Tuple <ServiceResult, RewardEditSimpleView>(ServiceResult.Success, view));
        }
Ejemplo n.º 8
0
        public Tuple <ServiceResult, AutoForm> GetView(string type, object id, AutoBaseModel autoModel)
        {
            Type     typeFind     = null;
            object   instanceFind = null;
            AutoForm autoForm     = null;
            var      checkType    = Resolve <IUIBaseService>().CheckType(type, ref typeFind, ref instanceFind);

            if (!checkType.Succeeded)
            {
                return(new Tuple <ServiceResult, AutoForm>(checkType, new AutoForm()));
            }

            if (instanceFind is IAutoConfig)
            {
                autoForm = Resolve <IApIAlaboAutoConfigService>().GetView(instanceFind.GetType(), id);
                return(new Tuple <ServiceResult, AutoForm>(ServiceResult.Success, autoForm));
            }

            if (instanceFind is IAutoForm set)
            {
                autoForm = set.GetView(id, autoModel);
                return(new Tuple <ServiceResult, AutoForm>(ServiceResult.Success, autoForm));
            }

            if (instanceFind is IEntity)
            {
                var result = DynamicService.ResolveMethod(typeFind.Name, "GetViewById", id);
                if (result.Item1.Succeeded)
                {
                    autoForm = AutoFormMapping.Convert(result.Item2);
                }
                else
                {
                    autoForm = AutoFormMapping.Convert(typeFind.FullName);
                }

                return(new Tuple <ServiceResult, AutoForm>(ServiceResult.Success, autoForm));
            }

            return(new Tuple <ServiceResult, AutoForm>(ServiceResult.Failure("未知类型"), new AutoForm()));
        }
Ejemplo n.º 9
0
        public ApiResult <AutoForm> GetPasswordForm()
        {
            var form = AutoFormMapping.Convert <PasswordInput>();

            return(ApiResult.Success(form));
        }
Ejemplo n.º 10
0
        public ApiResult <AutoForm> GetLoginForm()
        {
            var form = AutoFormMapping.Convert <LoginInput>();

            return(ApiResult.Success(form));
        }
Ejemplo n.º 11
0
        public ApiResult <AutoForm> GetRegForm()
        {
            var regForm = AutoFormMapping.Convert <RegInput>();

            return(ApiResult.Success(regForm));
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     get view for activity
        /// </summary>
        /// <param name="activityInput"></param>
        /// <returns></returns>
        public ActivityEditOutput GetView(ActivityEditInput activityInput)
        {
            //check
            var type = activityInput.Key.GetTypeByFullName();

            if (type == null)
            {
                throw new ValidException($"类型{activityInput.Key}不存在,请确定Url是否正确");
            }

            var instance = Activator.CreateInstance(type);

            if (!(instance is IActivity))
            {
                throw new ValidException("该类型不属于活动实体");
            }

            var activityEntityInstance = instance as IActivity;

            //check product
            if (activityInput.ProductId <= 0)
            {
                throw new ValidException("商品不存在");
            }

            var product = Resolve <IProductService>().GetSingle(activityInput.ProductId);

            if (product == null)
            {
                throw new ValidException("商品不存在");
            }

            //check activity
            var model = Resolve <IActivityService>()
                        .GetSingle(e => e.ProductId == activityInput.ProductId && e.Key == type.FullName);

            if (activityInput.Id > 0)
            {
                model = Resolve <IActivityService>().GetSingle(e => e.Id == activityInput.Id);
            }
            //builder
            var view = AutoMapping.SetValue <ActivityEditOutput>(activityInput);

            if (model != null)
            {
                view.Activity = model;
                view          = AutoMapping.SetValue(model, view);
                //user range
                view.UserRange = model.LimitGradeId.IsGuidNullOrEmpty()
                    ? UserRange.AllUser
                    : UserRange.ByUserGrade;
                //time range
                view.DateTimeRange = $"{model.StartTime.ToTimeString()} / {model.EndTime.ToTimeString()}";
                //support sigle product
                var attribute = Resolve <IActivityAdminService>().GetActivityModuleAttribute(type.FullName);
                if (attribute != null && attribute.IsSupportSigleProduct)
                {
                    activityInput.ProductId = model.ActivityExtension.ProductIds.FirstOrDefault();
                    view.ProductId          = activityInput.ProductId;
                }
            }
            else
            {
                view.Activity = new Activity {
                    Key       = type.FullName,
                    Status    = ActivityStatus.Processing,
                    ProductId = activityInput.ProductId
                };
                view.UserRange     = UserRange.AllUser;
                view.DateTimeRange =
                    $"{DateTime.Now.AddDays(1).Date.ToTimeString()} / {DateTime.Now.AddDays(7).Date.ToTimeString()}";
            }

            //get default value
            view.ActivityRules = activityEntityInstance.GetDefaultValue(activityInput, view.Activity);
            if (view.ActivityRules == null && !view.Activity.Value.IsNullOrEmpty())
            {
                view.ActivityRules = JsonConvert.DeserializeObject(view.Activity.Value, type);
            }

            //get form
            try {
                view.AutoForm = activityEntityInstance.GetAutoForm(view.ActivityRules);
            } catch (Exception) {
            }

            if (view.AutoForm == null)
            {
                view.AutoForm = view.ActivityRules == null
                    ? AutoFormMapping.Convert(type.FullName)
                    : AutoFormMapping.Convert(view.ActivityRules);
            }

            return(view);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 获取视图
        /// </summary>
        /// <param name="moduleId"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public Tuple <ServiceResult, RewardRuleOutput> GetEditView(Guid moduleId, ObjectId id)
        {
            #region 安全验证

            RewardRule find = null;
            if (!id.IsObjectIdNullOrEmpty())
            {
                find     = Resolve <IRewardRuleAdminService>().GetSingle(id);
                moduleId = find.ModuleId;
            }
            if (!id.IsObjectIdNullOrEmpty())
            {
            }
            var taskModuleAttribute = Resolve <IRuleModuleService>().GetRuleAttribute(moduleId);
            if (taskModuleAttribute == null)
            {
                return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.Failure("类型不存在,请确定Id是否输入正确"),
                                                                   null));
            }

            #endregion 安全验证

            var view = new RewardRuleOutput {
                ModuleConfig = new RewardRuleOutputModuleConfig {
                    Title = taskModuleAttribute.Name,
                    Intro = taskModuleAttribute.Intro,
                }
            };

            if (find == null)
            {
                // 添加视图
                view.Base = new RewardRuleBase {
                    Name    = taskModuleAttribute.Name,
                    Summary = $"{taskModuleAttribute.Name}的简要说明"
                };

                // 配置资产
                IList <RewardRuleAssetsRule> ruleItems = new List <RewardRuleAssetsRule>();
                var rule = new RewardRuleAssetsRule {
                    MoneyTypeId = Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid(),
                    Ratio       = 0.8m
                };
                ruleItems.Add(rule);
                var moneyType = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>().FirstOrDefault(r =>
                                                                                                          r.Id != Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid() && r.Status == Status.Normal);
                rule = new RewardRuleAssetsRule {
                    MoneyTypeId = moneyType.Id,
                    Ratio       = 0.2m
                };
                ruleItems.Add(rule);
                view.AssetsRules = ruleItems;
            }
            else
            {
                // 编辑视图
                view = find.MapTo <RewardRuleOutput>();
            }

            view.ModuleId = moduleId;

            object moduleConfig = Resolve <IRuleModuleService>().GetConfigValue(moduleId, view.Value);
            view.AutoForm = AutoFormMapping.Convert(moduleConfig);

            view.Value = string.Empty;

            return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.Success, view));
        }
Ejemplo n.º 14
0
        public ApiResult <AutoForm> GetAddAddressForm()
        {
            var view = AutoFormMapping.Convert <UserAddress>();

            return(null);
        }
Ejemplo n.º 15
0
        public AutoForm GetView(Type type, object id)
        {
            var config = GetConfig(type, id);

            return(AutoFormMapping.Convert(config));
        }
Ejemplo n.º 16
0
        public ApiResult <AutoForm> GetWithDrawForm()
        {
            var view = AutoFormMapping.Convert <WithDrawInput>();

            return(ApiResult.Success(view));
        }