public BaseOutput SetApiGatewayConfiguration([FromBody] SetApiGatewayConfigurationInput input) { var configInfo = new ApiGatewayConfigurationModel { GatewayId = input.GatewayId, BaseUrl = input.BaseUrl, DownstreamScheme = input.DownstreamScheme, GatewayKey = input.GatewayKey, HttpHandlerOptions = Json.ToJson(input.HttpHandlerOptions), LoadBalancerOptions = Json.ToJson(input.LoadBalancerOptions), QoSOptions = Json.ToJson(input.QoSOptions), RateLimitOptions = Json.ToJson(input.RateLimitOptions), RequestIdKey = input.RequestIdKey, ServiceDiscoveryProvider = Json.ToJson(input.ServiceDiscoveryProvider) }; if (configInfo.GatewayId > 0) { _adminDbContext.Updateable(configInfo).ExecuteCommand(); } else { _adminDbContext.Insertable(configInfo).ExecuteCommand(); } return(new BaseOutput { }); }
public async Task <SetAppConfigInfoOutput> SetAppConfigInfo(SetAppConfigInfoInput input) { // 环境库 Enum.TryParse <Env>(input.Environment, out var env); var tableName = "tb_appconfig_test"; switch (env) { case Env.dev: tableName = $"tb_appconfig_{Env.dev.ToString()}"; break; case Env.pro: tableName = $"tb_appconfig_{Env.pro.ToString()}"; break; case Env.prepro: tableName = $"tb_appconfig_{Env.prepro.ToString()}"; break; case Env.uat: tableName = $"tb_appconfig_{Env.uat.ToString()}"; break; default: throw new BucketException("plm_001", "环境不存在"); } // 编辑或新增 var model = _mapper.Map <AppConfigInfo>(input); if (model.Id > 0) { // 基础字段不容许更新 model.LastTime = DateTime.Now; model.Version = _dbContext.Queryable <AppConfigInfo>().AS(tableName).Max(it => it.Version) + 1; await _dbContext.Updateable(model).AS(tableName) .IgnoreColumns(it => new { it.CreateTime }) .ExecuteCommandAsync(); } else { model.CreateTime = DateTime.Now; model.LastTime = DateTime.Now; model.Version = _dbContext.Queryable <AppConfigInfo>().AS(tableName).Max(it => it.Version) + 1; await _dbContext.Insertable(model).AS(tableName) .ExecuteCommandAsync(); } return(new SetAppConfigInfoOutput { }); }
/// <summary> /// 设置项目信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <SetProjectOutput> SetProject(SetProjectInput input) { var model = _mapper.Map <SetProjectInput, ProjectInfo>(input); if (model.Id > 0) { // 基础字段不容许更新 model.LastTime = DateTime.Now; model.LastUid = _user.Id.ToLong(); await _dbContext.Updateable(model) .IgnoreColumns(it => new { it.CreateUid, it.CreateTime }) .ExecuteCommandAsync(); } else { model.CreateTime = DateTime.Now; model.CreateUid = _user.Id.ToLong(); model.LastTime = DateTime.Now; model.LastUid = model.CreateUid; await _dbContext.Insertable(model) .ExecuteCommandAsync(); } return(new SetProjectOutput { }); }
public BaseOutput SetAppInfo([FromBody] SetAppInfoInput input) { var model = _mapper.Map <SetAppInfoInput, AppModel>(input); if (model.Id > 0) { // 基础字段不容许更新 _adminDbContext.Updateable(model).ExecuteCommand(); } else { _adminDbContext.Insertable(model).ExecuteCommand(); } return(new BaseOutput { }); }
/// <summary> /// 设置平台信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <SetPlatformOutput> SetPlatform(SetPlatformInput input) { try { _dbContext.Ado.BeginTran(); var model = _mapper.Map <PlatformInfo>(input); if (model.Id > 0) { await _dbContext.Updateable(model).ExecuteCommandAsync(); } else { model.AddTime = DateTime.Now; model.IsDel = false; await _dbContext.Insertable(model).ExecuteCommandAsync(); } var redis = _redisClient.GetDatabase(_configCenter.StringGet(SysConfig.RedisConnectionKey), 2); await redis.KeyDeleteAsync(CacheKeys.PlatformKey); _dbContext.Ado.CommitTran(); } catch (Exception ex) { _dbContext.Ado.RollbackTran(); throw new Exception("事务执行失败", ex); } return(new SetPlatformOutput { }); }
public BaseOutput SetProject([FromBody] SetProjectInput input) { var model = _mapper.Map <SetProjectInput, ProjectModel>(input); if (model.Id > 0) { // 基础字段不容许更新 model.LastTime = DateTime.Now; model.LastUid = _user.Id.ToLong(); _adminDbContext.Updateable(model) .IgnoreColumns(it => new { it.CreateUid, it.CreateTime }) .ExecuteCommand(); } else { model.CreateTime = DateTime.Now; model.CreateUid = _user.Id.ToLong(); model.LastTime = DateTime.Now; model.LastUid = model.CreateUid; _adminDbContext.Insertable(model) .ExecuteCommand(); } return(new BaseOutput { }); }
public BaseOutput SetPlatform([FromBody] SetMenuInput input) { var model = _mapper.Map <MenuModel>(input); if (model.Id > 0) { _adminDbContext.Updateable(model).ExecuteCommand(); } else { _adminDbContext.Insertable(model).ExecuteCommand(); } return(new BaseOutput { }); }
/// <summary> /// 设置平台菜单信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <SetMenuOutput> SetPlatform(SetMenuInput input) { var model = _mapper.Map <MenuInfo>(input); if (model.Id > 0) { await _dbContext.Updateable(model).ExecuteCommandAsync(); } else { await _dbContext.Insertable(model).ExecuteCommandAsync(); } return(new SetMenuOutput { }); }
public BaseOutput SetPlatform([FromBody] SetPlatformInput input) { var model = _mapper.Map <PlatformModel>(input); if (model.Id > 0) { _adminDbContext.Updateable(model).ExecuteCommand(); } else { model.AddTime = DateTime.Now; model.IsDel = false; _adminDbContext.Insertable(model).ExecuteCommand(); } return(new BaseOutput { }); }
/// <summary> /// 设置Api资源 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <SetApiOutput> SetApi(SetApiInput input) { var model = _mapper.Map <ApiInfo>(input); if (model.Id > 0) { model.UpdateTime = DateTime.Now; await _dbContext.Updateable(model).IgnoreColumns(it => new { it.CreateTime }).ExecuteCommandAsync(); } else { model.UpdateTime = DateTime.Now; model.CreateTime = DateTime.Now; await _dbContext.Insertable(model).ExecuteCommandAsync(); } return(new SetApiOutput { }); }
public BaseOutput SetApi([FromBody] SetApiInput input) { var model = _mapper.Map <ApiModel>(input); if (model.Id > 0) { model.UpdateTime = DateTime.Now; _adminDbContext.Updateable(model).IgnoreColumns(it => new { it.CreateTime }).ExecuteCommand(); } else { model.UpdateTime = DateTime.Now; model.CreateTime = DateTime.Now; _adminDbContext.Insertable(model).ExecuteCommand(); } return(new BaseOutput { }); }
/// <summary> /// 设置角色信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <SetRoleOutput> SetRole(SetRoleInput input) { try { _dbContext.Ado.BeginTran(); #region 基础信息更新 var redis = _redisClient.GetDatabase(_configCenter.StringGet(SysConfig.RedisConnectionKey), 2); var model = _mapper.Map <RoleInfo>(input); if (model.Id > 0) { model.UpdateTime = DateTime.Now; await _dbContext.Updateable(model) .IgnoreColumns(it => new { it.PlatformKey, it.CreateTime, it.IsSys }) .ExecuteCommandAsync(); } else { model.CreateTime = DateTime.Now; model.IsDel = false; model.Id = await _dbContext.Insertable(model) .ExecuteReturnIdentityAsync(); } #endregion #region 菜单权限 // 用户角色操作 List <RoleMenuInfo> roleMenuList = new List <RoleMenuInfo>(); foreach (var id in input.MenuIdList) { // 防止重复数据 if (!roleMenuList.Exists(it => it.MenuId == id)) { roleMenuList.Add(new RoleMenuInfo { MenuId = id, RoleId = model.Id }); } } // 删除用户当前角色 await _dbContext.Deleteable <RoleMenuInfo>().Where(f => f.RoleId == model.Id).ExecuteCommandAsync(); // 添加用户角色 if (roleMenuList.Count > 0) { await _dbContext.Insertable(roleMenuList).ExecuteCommandAsync(); } #endregion #region 菜单权限 // 用户角色操作 List <RoleApiInfo> roleApiList = new List <RoleApiInfo>(); foreach (var id in input.ApiIdList) { // 防止重复数据 if (!roleApiList.Exists(it => it.ApiId == id)) { roleApiList.Add(new RoleApiInfo { ApiId = id, RoleId = model.Id }); } } // 删除用户当前角色 await _dbContext.Deleteable <RoleApiInfo>().Where(f => f.RoleId == model.Id).ExecuteCommandAsync(); // 添加用户角色 if (roleApiList.Count > 0) { await _dbContext.Insertable(roleApiList).ExecuteCommandAsync(); } #endregion #region 缓存更新 await redis.KeyDeleteAsync(CacheKeys.RoleAllUseKey); // 应该立即更新缓存 #endregion _dbContext.Ado.CommitTran(); } catch (Exception ex) { _dbContext.Ado.RollbackTran(); throw new Exception("事务执行失败", ex); } return(new SetRoleOutput { }); }
public BaseOutput SetUser([FromBody] SetUserInput input) { try { _adminDbContext.Ado.BeginTran(); var model = _mapper.Map <SetUserInput, UserModel>(input); if (model.Id > 0) { model.UpdateTime = DateTime.Now; if (!model.Password.IsEmpty()) { model.Salt = Randoms.CreateRandomValue(8, false); model.Password = Encrypt.SHA256(model.Password + model.Salt); // 基础字段不容许更新 _adminDbContext.Updateable(model) .IgnoreColumns(it => new { it.UserName, it.Mobile, it.CreateTime }) .ExecuteCommand(); } else { // 基础字段不容许更新 _adminDbContext.Updateable(model) .IgnoreColumns(it => new { it.UserName, it.Password, it.Salt, it.Mobile, it.CreateTime }) .ExecuteCommand(); } } else { model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; model.Salt = Randoms.CreateRandomValue(8, false); model.Password = Encrypt.SHA256(model.Password + model.Salt); model.Id = Convert.ToInt64($"{Time.GetUnixTimestamp()}{ Randoms.CreateRandomValue(3, true) }"); _adminDbContext.Insertable(model).ExecuteCommand(); } // 用户角色操作 var userRoleList = new List <UserRoleModel>(); foreach (var id in input.RoleIdList) { // 防止重复数据 if (!userRoleList.Exists(it => it.RoleId == id)) { userRoleList.Add(new UserRoleModel { Uid = model.Id, RoleId = id }); } } // 删除用户当前角色 _adminDbContext.Deleteable <UserRoleModel>().Where(f => f.Uid == model.Id).ExecuteCommand(); // 添加用户角色 if (userRoleList.Count > 0) { _adminDbContext.Insertable(userRoleList).ExecuteCommand(); } _adminDbContext.Ado.CommitTran(); } catch (Exception ex) { _adminDbContext.Ado.RollbackTran(); throw new Exception("事务执行失败", ex); } return(new BaseOutput { }); }
public BaseOutput SetRole([FromBody] SetRoleInput input) { try { _adminDbContext.Ado.BeginTran(); #region 基础信息更新 var model = _mapper.Map <RoleModel>(input); if (model.Id > 0) { model.UpdateTime = DateTime.Now; _adminDbContext.Updateable(model) .IgnoreColumns(it => new { it.PlatformKey, it.CreateTime, it.IsSys }) .ExecuteCommand(); } else { model.CreateTime = DateTime.Now; model.IsDel = false; model.Id = _adminDbContext.Insertable(model).ExecuteReturnIdentity(); } #endregion #region 菜单权限 // 用户角色操作 List <RoleMenuModel> roleMenuList = new List <RoleMenuModel>(); foreach (var id in input.MenuIdList) { // 防止重复数据 if (!roleMenuList.Exists(it => it.MenuId == id)) { roleMenuList.Add(new RoleMenuModel { MenuId = id, RoleId = model.Id }); } } // 删除用户当前角色 _adminDbContext.Deleteable <RoleMenuModel>().Where(f => f.RoleId == model.Id).ExecuteCommand(); // 添加用户角色 if (roleMenuList.Count > 0) { _adminDbContext.Insertable(roleMenuList).ExecuteCommand(); } #endregion #region 接口权限 // 用户角色操作 List <RoleApiModel> roleApiList = new List <RoleApiModel>(); foreach (var id in input.ApiIdList) { // 防止重复数据 if (!roleApiList.Exists(it => it.ApiId == id)) { roleApiList.Add(new RoleApiModel { ApiId = id, RoleId = model.Id }); } } // 删除用户当前角色 _adminDbContext.Deleteable <RoleApiModel>().Where(f => f.RoleId == model.Id).ExecuteCommand(); // 添加用户角色 if (roleApiList.Count > 0) { _adminDbContext.Insertable(roleApiList).ExecuteCommand(); } #endregion _adminDbContext.Ado.CommitTran(); } catch (Exception ex) { _adminDbContext.Ado.RollbackTran(); throw new Exception("事务执行失败", ex); } return(new BaseOutput { }); }