lizizhou 3c308bcadf | 2 years ago | |
---|---|---|
BPA_Kitchen.bak | 2 years ago | |
Project.Standard.png | 2 years ago | |
Service.Define.pdf | 2 years ago | |
bpa服务分析.xlsx | 2 years ago | |
k8s集群地址信息.xls | 2 years ago | |
readme.md | 2 years ago | |
服务定义.png | 2 years ago | |
问题.docx | 2 years ago |
目前攻击分配服务节点如下所示:
完整PDF文件在BPA.Documents项目中
创建与开发文档相关的仓库:http://10.2.1.24:10244/Bpa.Software.Development/BPA.Documents
服务拆分需要由原有业务设计的编码人员进行拆分,在保证业务分离、不过分拆分的前提下,将代码和业务剥离到其他新的服务中
原有框架使用Furion做应用程序框架,简单、易用,对于小型快速建站,它绝对是非常优秀的AppFramework,但同样也由于过度封装,导致耦合过高,拆分困难,灵活性低,不适用于企业级服务中,可查看BPA.Documents中的“问题.docx”描述。
只定义接口的对外(集群外)暴露。
定义和实现该服务节点下的【业务接口和业务实现】,包括IService和Service两个项目。
定义和实现该服务节点下的【仓储接口和持久化实现】,包括IRepository和Repository两个项目。
实体定义和映射,包括DTO,Entity,Model。
定义和配置该服务节点的所有组件,无业务实现。
定义和配置该服务节点对内(集群内)需要暴露的接口,无业务实现。
该服务节点的所有接口的单元测试。
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IAuthRepository _authRepository;
private readonly CSRedisClient _redisClient;
private readonly BasicApiConfig _basicApiConfig;
/// <summary>
/// 构造函数
/// </summary>
public AuthService(IHttpContextAccessor httpContextAccessor, IAuthRepository authRepository, CSRedisClient redisClient, BasicApiConfig basicApiConfig)
{
_httpContextAccessor = httpContextAccessor;
_authRepository = authRepository;
_redisClient = redisClient;
_basicApiConfig = basicApiConfig;
}
public interface IAuthService
{
/// <summary>
/// 获取用户
/// </summary>
/// <param name="logintype"></param>
/// <returns></returns>
Task<BaseResult<LoginOutput>> GetLoginUserAsync(EnumLoginType logintype);
/// <summary>
/// 登录
/// </summary>
/// <param name="logintype"></param>
/// <param name="input"></param>
/// <returns></returns>
Task<BaseResult<LoginOutInfo>> LoginAsync(EnumLoginType logintype, LoginInput input);
/// <summary>
/// 登出
/// </summary>
/// <returns></returns>
Task<BaseResult<string>> LogoutAsync();
}
public interface IAuthRepository
{
/// <summary>
/// 获取登录用户信息
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
Task<BPA_Users> GetLoginUserAsync(string userId);
/// <summary>
/// 查询登录登录
/// </summary>
/// <param name="LoginType"></param>
/// <param name="input"></param>
/// <returns></returns>
Task<(BPA_Users user, BPA_Company company)> LoginAsync(EnumLoginType LoginType, LoginInput input);
}
var result = rows.MapToList<ProductCodeDto, BPA_ProductCode>().ToList();
/// <summary>
/// StockMySqlDb
/// </summary>
[AutoWrite]
public new DbConfig StockMySqlDb { get; set; }
/// <summary>
/// RedisConfig
/// </summary>
[AutoWrite]
public new List<string> RedisConfig { set; get; }
/// <summary>
/// 是否打印SQL
/// </summary>
[AutoWrite]
public bool IsLogSql { get; set; } = true;
/// <summary>
/// RabbitMQ配置
/// </summary>
[AutoWrite]
public new RabbitMqConnectionConfig RabbitMqConfig { get; set; }
//获取rabbitMqProvider
var rabbitMqProvider = serviceProvider.UseRabbitMQProvider<RabbitMQProvider>();
//创建交换机配置对象
var createBizLogExchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.CreateBizLogExchange);
//启用交换机
createBizLogExchangeConfig.UseExchange();
//启用生产者
createBizLogExchangeConfig.UseProducer<CreateBizLogMsgBody, CreateBizLogProducer>();
//创建交换机配置对象
var addMessageExchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.BatchAddMessageExchange, ExchangeType.Fanout);
//启用交换机
addMessageExchangeConfig.UseExchange();
//启用生产者
addMessageExchangeConfig.UseProducer<BatchAddMessageMsgBody, BatchAddMessageProduct>();
/// <summary>
/// 注入redis
/// </summary>
/// <param name="services"></param>
public static void AddRedis(this IServiceCollection services)
{
services.UseRedisSingleton(sp => GetRedisSingletonConnectionString(sp.GetService<StockApiConfig>()!));
}
// 缓存Token令牌
var key = BasicRedisKey.UserAccessToken(user.Id);
await _redisClient.DelAsync(key);
await _redisClient.SetAsync(key, accessToken, _basicApiConfig.TokenExpireInterval);
public interface IAuthServiceApi
{
/// <summary>
/// 获取用户
/// </summary>
/// <param name="logintype"></param>
/// <param name="authToken"></param>
/// <returns></returns>
[Get("/api/Auth/GetLoginUser")]
Task<BaseResult<LoginOutput>> GetLoginUserAsync(EnumLoginType logintype, [Header("Authorization")] string authToken);
/// <summary>
/// 登录
/// </summary>
/// <param name="logintype"></param>
/// <param name="input"></param>
/// <returns></returns>
[Post("/api/Auth/Login")]
Task<BaseResult<LoginOutInfo>> LoginAsync(EnumLoginType logintype, LoginInput input);
/// <summary>
/// 登出
/// </summary>
/// <returns></returns>
[Post("/api/Auth/Logout")]
Task<BaseResult<string>> LogoutAsync([Header("Authorization")] string authToken);
}
调用时注入当前需要调用服务SDK即可,例如BasicWebApiSDK。
/// <summary>
/// 认证服务API
/// </summary>
public IAuthServiceApi AuthServiceApi;
/// <summary>
/// 分页
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost, Anonymous, BizLogQuery] //BizLogQuery查询审计
public Task<BaseResultPage<UserDtoOutput>> UserPage(UserDtoPageInput input) => _userService.UserPage(input);
public BasicDbSugarClient(ILogger<BasicDbSugarClient> logger,
Lazy<BizLogProducer> bizLogProducer, //懒加载注入
BasicApiConfig config)
: base(BuildConnectionConfig(config.BasicMySqlDb), bizLogProducer, true, logger)
未完待续...