/// <summary> /// 注册后事件,通过队列来处理 /// </summary> /// <param name="userId"></param> public void AfterUserRegTask(long userId) { var afterConfig = Resolve <IAutoConfigService>().GetValue <UserAfterRegConfig>(); var user = Resolve <IUserService>().GetUserDetail(userId); if (user != null) { if (afterConfig.CreateCode) { try { //TODO 动态调用有错误 // 生成用户二维码 ServiceInterpreter.Eval("IUserQrCodeService", "CreateCode", user); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (afterConfig.AddParnter) { // 添加内部合伙人关系 AddParnter(user); } if (afterConfig.UpdateTeamInfo) { //更新:User_Map表:更新会员本身的团队信息 LevelNumber,ChildNode,TeamNumber 字段 Ioc.Resolve <IUserMapService>().UpdateTeamInfo(user.Id); } // 继承IUserRegAfter的方法 // ExecuteUserAfter(user); } }
public void EvalTest_2() { var defaultUser = Resolve <IUserService>().GetRandom(1); var result = ServiceInterpreter.Eval <User>("User", "GetSingle", defaultUser.Id); Assert.NotNull(result); Assert.Equal(defaultUser.Id, result.Id); }
public void EvalTest() { var defaultUser = Resolve <IUserService>().PlatformUser(); var result = ServiceInterpreter.Eval <User>("User", "PlatformUser"); Assert.NotNull(result); Assert.Equal(defaultUser.Id, result.Id); }
public void Save(Type type, object model) { var key = type.FullName; var config = Resolve <IAlaboAutoConfigService>().GetConfig(type.FullName); if (config == null) { config = new AutoConfig { Type = key, AppName = Resolve <ITypeService>().GetAppName(type.FullName), LastUpdated = DateTime.Now }; } var classDescription = type.FullName.GetClassDescription(); if (classDescription.ClassPropertyAttribute.PageType == ViewPageType.Edit) { config.Value = model.ToJsons(); } else { var list = ServiceInterpreter.Eval <List <JObject> >("IAutoConfigService", "GetList", key); var idValue = Reflection.GetPropertyValue("Id", model); var guid = idValue.ConvertToGuid(); //如果Id不存在则创建Id if (guid.IsGuidNullOrEmpty()) { Reflection.SetPropertyValue("Id", model, Guid.NewGuid()); } else { JObject current = null; foreach (var item in list) { if (idValue.ToGuid() == item["Id"].ToGuid()) { current = item; break; } } list.Remove(current); } list.Add(JObject.FromObject(model)); config.Value = list.ToJsons(); } Ioc.Resolve <IAlaboAutoConfigService>().AddOrUpdate(config); }
private void AddAccount(DbTransaction transaction, long userId, List <MoneyTypeConfig> moneyTypes) { foreach (var item in moneyTypes) { var sql = @"INSERT INTO [dbo].[Asset_Account] ([UserId],[MoneyTypeId],[Amount],[FreezeAmount],[HistoryAmount],[Token]) VALUES (@UserId,@MoneyTypeId,0,0,0,@Token)"; // 动态调用方法 var token = ServiceInterpreter.Eval <string>("IAccountService", "GetToken", userId, item); var parameters = new[] { RepositoryContext.CreateParameter("@UserId", userId), RepositoryContext.CreateParameter("@MoneyTypeId", item.Id), RepositoryContext.CreateParameter("@Token", token) }; RepositoryContext.ExecuteScalar(transaction, sql, parameters); } }
/// <summary> /// 删除前判断级联数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> private ServiceResult RelationCheck(TEntity entity) { if (entity.Id.IsNullOrEmpty()) { return(ServiceResult.Failure($"{typeof(TEntity).Name}Id不能为空")); } var deleteAttribute = typeof(TEntity).FullName.GetAutoDeleteAttribute(); if (deleteAttribute == null) { return(ServiceResult.Failure($"{typeof(TEntity).Name}未配置删除特性,不能删除")); } if (deleteAttribute.IsAuto && deleteAttribute.EntityType == null) { return(ServiceResult.Success); } if (deleteAttribute.EntityType == null) { return(ServiceResult.Failure($"{typeof(TEntity).Name}未配置删除级联,不能删除")); } if (deleteAttribute.RelationId.IsNullOrEmpty()) { return(ServiceResult.Failure($"{typeof(TEntity).Name}未配置RelationId,不能删除")); } var find = ServiceInterpreter.Eval <object>($"{deleteAttribute.EntityType.Name}Service", "GetSingle", deleteAttribute.RelationId, entity.Id); if (find != null) { var classDescription = deleteAttribute.EntityType.FullName.GetClassDescription(); return(ServiceResult.Failure($"有关联的{classDescription.ClassPropertyAttribute.Name}数据,不能删除")); } return(ServiceResult.Success); }
/// <summary> /// 获取后台管理模板菜单 /// </summary> /// <returns></returns> public List <ThemeOneMenu> GetAdminThemeMenus() { var result = ServiceInterpreter.Eval <List <ThemeOneMenu> >("ThemeService", "GetAdminThemeMenus"); return(result); }
public ApiResult <List <KeyValue> > GetKeyValue([FromQuery] string type) { if (type.IsNullOrEmpty() || type == "undefined") { return(ApiResult.Failure <List <KeyValue> >("类型不能为空")); } if (type == "IAutoTable") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoTableKeyValues())); } if (type == "IAutoForm") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoFormKeyValues())); } if (type == "IAutoList") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoListKeyValues())); } if (type == "IAutoPreview") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoPreviewKeyValues())); } if (type == "IAutoNews") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoNewsKeyValues())); } if (type == "IAutoArticle") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoArticleKeyValues())); } if (type == "IAutoReport") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoReportKeyValues())); } if (type == "IAutoFaq") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoFaqsKeyValues())); } if (type == "IAutoImage") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoImagesKeyValues())); } if (type == "IAutoIndex") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoIndexKeyValues())); } if (type == "IAutoIntro") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoIntroKeyValues())); } if (type == "IAutoTask") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoTaskKeyValues())); } if (type == "IAutoVideo") { return(ApiResult.Success(Resolve <IAutoUIService>().AutoVideoKeyValues())); } if (type == "CatalogEntity") { return(ApiResult.Success(Resolve <ITableService>().CatalogEntityKeyValues())); } if (type == "SqlServcieCatalogEntity") { return(ApiResult.Success(Resolve <ITableService>().SqlServcieCatalogEntityKeyValues())); } if (type == "MongodbCatalogEntity") { return(ApiResult.Success(Resolve <ITableService>().MongodbCatalogEntityKeyValues())); } var find = type.GetTypeByName(); if (find == null) { return(ApiResult.Failure <List <KeyValue> >($"类型不存在,请确认{type}输入是否正确")); } var intances = type.GetInstanceByName(); if (intances is IRelation) { var result = ServiceInterpreter.Eval <IEnumerable <KeyValue> >("IRelationService", "GetKeyValues2", type); return(ApiResult.Success(result.ToList())); } //enum if (find.IsEnum) { var keyValues = KeyValueExtesions.EnumToKeyValues(type); if (keyValues == null) { return(ApiResult.Failure <List <KeyValue> >("枚举不存在")); } return(ApiResult.Success(keyValues.ToList())); } // auto config if (intances is IAutoConfig) { var configValue = Resolve <ITypeService>().GetAutoConfigDictionary(type); if (configValue == null) { return(ApiResult.Failure <List <KeyValue> >($"{type}不存在")); } var keyValues = new List <KeyValue>(); foreach (var item in configValue) { keyValues.Add(new KeyValue { Key = item.Key, Value = item.Value }); } return(ApiResult.Success(keyValues)); } return(null); }
/// <summary> /// 包含 /// 1.用户名和密码登录, /// 2.手机号和密码登录 /// 3.微信OpenId登录 /// 4.手机号和手机验证码登录 /// 5.后台管理员登录 /// 注意:全局登录行数只维护这个,满足所有的登录场景 /// </summary> /// <param name="loginInput"></param> /// <returns></returns> public Tuple <ServiceResult, UserOutput> Login(LoginInput loginInput) { var config = Resolve <IAutoConfigService>().GetValue <AdminCenterConfig>(); if (!config.IsAllowUserLogin) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("系统维护升级中,禁止会员登录,请稍后重试"), null)); } // 根据OpenId登录 User find = null; if (!loginInput.OpenId.IsNullOrEmpty()) { // 根据OpenId登录 find = Resolve <IUserService>().GetUserDetailByOpenId(loginInput.OpenId); } else if (!loginInput.UserName.IsNullOrEmpty() && !loginInput.VerifyCode.IsNullOrEmpty()) { if (!Resolve <ISmsService>() .CheckVerifiyCode(loginInput.UserName, loginInput.VerifyCode.ConvertToLong())) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("手机验证码错误"), null)); } } else { // 根据用户名和密码登录 if (loginInput.UserName.IsNullOrEmpty()) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("用户名不能为空"), null)); } if (loginInput.Password.IsNullOrEmpty()) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("密码不能为空"), null)); } find = Resolve <IUserService>().GetSingleByUserNameOrMobile(loginInput.UserName); if (find == null) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("用户不存在"), null)); } if (find.Status != Status.Normal) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("用户状态不正确,禁止登录"), null)); } if (find.Detail.Password != loginInput.Password.ToMd5HashString()) { if (!loginInput.Password.Equals(find.Detail.Password, StringComparison.OrdinalIgnoreCase)) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("密码不正确"), null)); } } } if (find == null) { return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("用户不存在 "), null)); } if (find.Email.IsNullOrEmpty()) { var userConfig = Resolve <IAutoConfigService>().GetValue <UserConfig>(); find.Email = find.UserName + userConfig.RegEmailPostfix; } //更新用户信息 find.Detail.LastLoginTime = DateTime.Now; find.Detail.LastLoginIp = HttpWeb.Ip; find.Detail.LoginNum += 1; if (!loginInput.OpenId.IsNullOrEmpty()) { find.Detail.OpenId = loginInput.OpenId; } Ioc.Resolve <IUserDetailService>().Update(find.Detail); // 动态初始化用户数据资产数据 ServiceInterpreter.Eval("AccountService", "InitSingleUserAccount", find.Id); var userOutput = Resolve <IUserDetailService>().GetUserOutput(find.Id); return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Success, userOutput)); }
/// <summary> /// 获取AutoConfig 的字典类型,可用于构建下拉菜单,复选框,表格等 /// 其中AutoConfig中,必须要指定Main字段特性,才可以识别值object /// </summary> /// <param name="configName">Name of the configuration.</param> /// <param name="isAllSelect"></param> /// <returns>Dictionary<System.String, System.Object>.</returns> public Dictionary <string, object> GetAutoConfigDictionary(string configName, bool isAllSelect = false) { var config = GetAutoConfigType(configName); if (config == null) { return(null); } //读取数据库问题 var dictionary = new Dictionary <string, object>(); if (isAllSelect) { dictionary.Add("-1", "所有"); } IList <JObject> list = ServiceInterpreter.Eval <List <JObject> >("IAutoConfigService", "GetList", config.FullName); if (!list.Any()) { return(dictionary); } var textField = string.Empty; //如果不存在Main特性则取Id字段显示 var allPropertys = config.FullName.GetAllPropertys(); foreach (var item in allPropertys) { if (item.FieldAttribute.IsMain) { textField = item.Name; break; } } if (textField.IsNullOrEmpty()) { foreach (var item in config.GetProperties()) { if (item.Name == "Name") { textField = item.Name; } } } if (textField.IsNullOrEmpty()) { textField = "Id"; } // 判断是否包括status字段,如果包含则显示状态为正常的 var hasStatus = false; foreach (var item in config.GetProperties()) { var statusField = item.Name; if (statusField.ToLower() == "status") { hasStatus = true; break; } } foreach (var data in list) { if (hasStatus) { var status = data["Status"].ConvertToInt(); if (status != 1) { continue; } } var key = data["Id"].ToString(); var value = data[textField]; if (!dictionary.Keys.Contains(key)) { dictionary.Add(key, value); } } return(dictionary); }
public Tuple <ServiceResult, AutoTable> Table(string type, object query, AutoBaseModel autoBaseModel) { Type typeFind = null; object instanceFind = null; var checkType = Resolve <IUIBaseService>().CheckType(type, ref typeFind, ref instanceFind); if (!checkType.Succeeded) { return(new Tuple <ServiceResult, AutoTable>(checkType, new AutoTable())); } var autoTable = AutoTableMapping.Convert(typeFind.FullName); #region IAutoTable类型 // 如果是IAutoTable类型,则数据从AutoTable中获取,否则从Api接口中获取 if (instanceFind is IAutoTable) { var target = new Interpreter().SetVariable("autoTable", instanceFind); var parameters = new[] { new Parameter("query", query), new Parameter("baseModel", autoBaseModel) }; try { autoTable.Result = target.Eval("autoTable.PageTable(query,baseModel)", parameters); } catch (Exception ex) { return(new Tuple <ServiceResult, AutoTable>(ServiceResult.Failure(ex.Message), new AutoTable())); } } #endregion IAutoTable类型 #region autoConfig类型 else if (instanceFind is IAutoConfig) { var data = Resolve <IAlaboAutoConfigService>().GetObjectList(typeFind); var result = PagedList <object> .Create(data, data.Count, 100, 1); var apiRusult = new PageResult <object> { PageCount = result.PageCount, Result = result, RecordCount = result.RecordCount, CurrentSize = result.CurrentSize, PageIndex = result.PageIndex, PageSize = result.PageSize }; autoTable.Result = apiRusult; } else if (instanceFind is IEntity) { var serviceName = $"{typeFind.Name}Service"; var result = ServiceInterpreter.Eval <object>(serviceName, "GetApiPagedList", query, autoBaseModel); autoTable.Result = result; } #endregion autoConfig类型 return(new Tuple <ServiceResult, AutoTable>(ServiceResult.Success, autoTable)); }