feat(config): 添加配置数据种子和根据key查询配置功能
- 添加初始密码配置项的种子数据 (sys.user.initPassword: 123456) - 在 ConfigService 中新增 GetConfigKeyAsync 方法支持根据key查询配置值
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
using Volo.Abp.Application.Services;
|
using Volo.Abp.Application.Services;
|
||||||
@@ -61,5 +62,18 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
throw new UserFriendlyException(ConfigConst.Exist);
|
throw new UserFriendlyException(ConfigConst.Exist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据key查配置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
///
|
||||||
|
[Route("config/config-key/{configKey}")]
|
||||||
|
public async Task<string> GetConfigKeyAsync(string configKey)
|
||||||
|
{
|
||||||
|
var entity = await _repository.GetAsync(x => x.ConfigKey == configKey);
|
||||||
|
return entity.ConfigValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.Data;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.Guids;
|
||||||
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
||||||
|
{
|
||||||
|
internal class ConfigDataSeed : IDataSeedContributor, ITransientDependency
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<ConfigAggregateRoot> _repository;
|
||||||
|
private IGuidGenerator _guidGenerator;
|
||||||
|
|
||||||
|
public ConfigDataSeed(ISqlSugarRepository<ConfigAggregateRoot> repository, IGuidGenerator guidGenerator)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_guidGenerator = guidGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SeedAsync(DataSeedContext context)
|
||||||
|
{
|
||||||
|
if (!await _repository.IsAnyAsync(x => true))
|
||||||
|
{
|
||||||
|
await _repository.InsertManyAsync(GetSeedData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<ConfigAggregateRoot> GetSeedData()
|
||||||
|
{
|
||||||
|
var entities = new List<ConfigAggregateRoot>();
|
||||||
|
|
||||||
|
ConfigAggregateRoot initPassword = new ConfigAggregateRoot()
|
||||||
|
{
|
||||||
|
ConfigName = "初始密码",
|
||||||
|
ConfigKey = "sys.user.initPassword",
|
||||||
|
ConfigValue = "123456",
|
||||||
|
OrderNum = 1,
|
||||||
|
IsDeleted = false,
|
||||||
|
Remark = "初始密码"
|
||||||
|
};
|
||||||
|
entities.Add(initPassword);
|
||||||
|
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user