refactor: 重构项目基础架构与实体体系
- 替换原有自定义生命周期接口为通用基础服务体系 - 将所有实体基类替换为带雪花ID的SqlSugarBaseEntity - 迁移DTO到Models项目并统一管理 - 移除冗余的Repository层实现,改用通用基础服务 - 添加Yitter.IdGenerator雪花ID生成支持 - 重构SqlSugar数据库上下文与依赖注入配置 - 新增微信用户、用户勋章、背包等实体与配套服务 - 整理分页查询与结果封装类 - 优化WebApi控制器结构
This commit is contained in:
@ -1,96 +0,0 @@
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 管理员创建/更新输入
|
||||
/// </summary>
|
||||
public class AdminUserInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 密码(创建时必填,更新时为空表示不修改密码)
|
||||
/// </summary>
|
||||
public string? Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 管理员类型: SuperAdmin, Editor
|
||||
/// </summary>
|
||||
public string Type { get; set; } = "Editor";
|
||||
|
||||
/// <summary>
|
||||
/// 状态: Active, Inactive
|
||||
/// </summary>
|
||||
public string Status { get; set; } = "Active";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 管理员输出
|
||||
/// </summary>
|
||||
public class AdminUserOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键ID
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 管理员类型
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public string Status { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新人
|
||||
/// </summary>
|
||||
public string? UpdatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 管理员分页查询输入
|
||||
/// </summary>
|
||||
public class AdminUserQueryInput : PageQueryModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户名(模糊查询)
|
||||
/// </summary>
|
||||
public string? UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 管理员类型
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public string? Status { get; set; }
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
namespace QYZH.InteractiveMagazine.IService.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 登录输入
|
||||
/// </summary>
|
||||
public class LoginInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 账号
|
||||
/// </summary>
|
||||
public string Account { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册输入
|
||||
/// </summary>
|
||||
public class RegisterInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 账号
|
||||
/// </summary>
|
||||
public string Account { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录输出
|
||||
/// </summary>
|
||||
public class LoginOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 访问令牌
|
||||
/// </summary>
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public long UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 刷新令牌
|
||||
/// </summary>
|
||||
public string RefreshToken { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class AdminLoginInput
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class AdminLoginOutput
|
||||
{
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
public long UserId { get; set; }
|
||||
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string Type { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class AdminUserInfoOutput
|
||||
{
|
||||
public long UserId { get; set; }
|
||||
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
public string Status { get; set; } = string.Empty;
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
namespace QYZH.InteractiveMagazine.IService.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 微信登录输出
|
||||
/// </summary>
|
||||
public class WeChatLoginOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 访问令牌
|
||||
/// </summary>
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public long UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 微信OpenId
|
||||
/// </summary>
|
||||
public string OpenId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信手机号获取输出
|
||||
/// </summary>
|
||||
public class WeChatPhoneNumberOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 手机号
|
||||
/// </summary>
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
using QYZH.InteractiveMagazine.IService.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
public interface IAdminAuthService
|
||||
public interface IAdminAuthService : IBaseService<AdminUser>
|
||||
{
|
||||
Task<AdminLoginOutput> LoginAsync(AdminLoginInput input);
|
||||
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
using QYZH.InteractiveMagazine.IService.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
/// <summary>
|
||||
/// 管理员用户服务接口
|
||||
/// </summary>
|
||||
public interface IAdminUserService
|
||||
public interface IAdminUserService : IBaseService<AdminUser>
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建管理员
|
||||
|
||||
@ -1,51 +1,39 @@
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
/// <summary>
|
||||
/// 基础服务接口
|
||||
/// 基础服务定义
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类型</typeparam>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IBaseService<T> where T : class, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取实体
|
||||
/// </summary>
|
||||
/// <param name="id">实体ID</param>
|
||||
/// <returns>实体对象</returns>
|
||||
Task<T?> GetByIdAsync(long id);
|
||||
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有实体列表
|
||||
/// 根据条件表达式查询单条数据
|
||||
/// </summary>
|
||||
/// <returns>实体列表</returns>
|
||||
Task<List<T>> GetListAsync();
|
||||
/// <param name="expression">表达式</param>
|
||||
/// <returns>泛型实体</returns>
|
||||
Task<R> GetByIdAsync<R>(Expression<Func<T, bool>> expression) where R : class;
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页列表
|
||||
/// </summary>
|
||||
/// <param name="pageQuery">分页查询参数</param>
|
||||
/// <returns>分页数据</returns>
|
||||
Task<PageListModel<T>> GetPageListAsync(PageQueryModel pageQuery);
|
||||
Task<R> GetByExpressionAsync<R>(Expression<Func<T, bool>> expression) where R : class;
|
||||
|
||||
/// <summary>
|
||||
/// 新增实体
|
||||
/// </summary>
|
||||
/// <param name="entity">实体对象</param>
|
||||
/// <returns>是否成功</returns>
|
||||
Task<bool> InsertAsync(T entity);
|
||||
Task<List<T2>> GetListByExpression<T2>(Expression<Func<T, bool>> expression) where T2 : class;
|
||||
|
||||
/// <summary>
|
||||
/// 更新实体
|
||||
/// </summary>
|
||||
/// <param name="entity">实体对象</param>
|
||||
/// <returns>是否成功</returns>
|
||||
Task<bool> UpdateAsync(T entity);
|
||||
Task<bool> UpdateAsync(T updateObj);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID删除实体
|
||||
/// </summary>
|
||||
/// <param name="id">实体ID</param>
|
||||
/// <returns>是否成功</returns>
|
||||
Task<bool> DeleteByIdAsync(long id);
|
||||
///// <summary>
|
||||
///// 根据指定条件更新指定列 eg:Update(new SysUser(){ Status = 1 }, it => new { it.Status }, f => f.Userid == 1));
|
||||
///// 只更新Status列,条件是包含
|
||||
///// </summary>
|
||||
///// <param name="entity">实体类</param>
|
||||
///// <param name="expression">要更新列的表达式</param>
|
||||
///// <param name="where">where表达式</param>
|
||||
///// <returns></returns>
|
||||
//Task<bool> UpdateAsync(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
|
||||
Task<bool> UpdateAsync(Expression<Func<T, bool>> columns, Expression<Func<T, bool>> where);
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
/// <summary>
|
||||
/// 单例生命周期标记接口
|
||||
/// </summary>
|
||||
public interface ISingletonDependency
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 瞬时生命周期标记接口
|
||||
/// </summary>
|
||||
public interface ITransientDependency
|
||||
{
|
||||
}
|
||||
33
QYZH.InteractiveMagazine.IService/IWxUserService.cs
Normal file
33
QYZH.InteractiveMagazine.IService/IWxUserService.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using QYZH.InteractiveMagazine.IService.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
public interface IWxUserService : IBaseService<WxUser>
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建微信用户
|
||||
/// </summary>
|
||||
Task<WxUserOutput> CreateAsync(WxUserInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 更新微信用户
|
||||
/// </summary>
|
||||
Task<WxUserOutput> UpdateAsync(long id, WxUserInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 删除微信用户(软删除)
|
||||
/// </summary>
|
||||
Task DeleteAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取微信用户
|
||||
/// </summary>
|
||||
Task<WxUserOutput> GetByIdAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询微信用户列表
|
||||
/// </summary>
|
||||
Task<PageListModel<WxUserOutput>> GetListAsync(WxUserQueryInput input);
|
||||
}
|
||||
Reference in New Issue
Block a user