refactor: 重构项目基础架构与实体体系

- 替换原有自定义生命周期接口为通用基础服务体系
- 将所有实体基类替换为带雪花ID的SqlSugarBaseEntity
- 迁移DTO到Models项目并统一管理
- 移除冗余的Repository层实现,改用通用基础服务
- 添加Yitter.IdGenerator雪花ID生成支持
- 重构SqlSugar数据库上下文与依赖注入配置
- 新增微信用户、用户勋章、背包等实体与配套服务
- 整理分页查询与结果封装类
- 优化WebApi控制器结构
This commit is contained in:
glz
2026-06-02 14:10:43 +08:00
parent 831f8ba7f5
commit 8ed012bba8
51 changed files with 1762 additions and 1141 deletions

View File

@ -1,88 +1,102 @@

using QYZH.InteractiveMagazine.Models.Dto;
using SqlSugar;
using System.Data;
using System.Linq.Expressions;
namespace QYZH.InteractiveMagazine.Repository;
/// <summary>
/// 基础仓储接口
/// </summary>
/// <typeparam name="T">实体类型</typeparam>
public interface IBaseRepository<T> where T : class, new()
namespace QYZH.InteractiveMagazine.Repository
{
/// <summary>
/// 根据Id获取实体
/// </summary>
/// <param name="id">主键Id</param>
/// <returns>实体对象</returns>
Task<T?> GetByIdAsync(long id);
public interface IBaseRepository<T> : ISimpleClient<T> where T : class, new()
{
#region add
int Add(T t, bool ignoreNull = true);
/// <summary>
/// 获取所有列表
/// </summary>
/// <returns>实体列表</returns>
Task<List<T>> GetListAsync();
int Insert(List<T> t);
int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
/// <summary>
/// 根据条件获取列表
/// </summary>
/// <param name="where">查询条件</param>
/// <returns>实体列表</returns>
Task<List<T>> GetListByWhereAsync(Expression<Func<T, bool>> where);
IInsertable<T> Insertable(T t);
/// <summary>
/// 分页查询
/// </summary>
/// <param name="where">查询条件</param>
/// <param name="pageQuery">分页参数</param>
/// <returns>分页结果</returns>
Task<PageListModel<T>> GetPageListAsync(Expression<Func<T, bool>> where, PageQueryModel pageQuery);
IUpdateable<T> Updateable();
#endregion add
/// <summary>
/// 插入单条记录
/// </summary>
/// <param name="entity">实体对象</param>
/// <returns>是否成功</returns>
Task<bool> InsertAsync(T entity);
#region update
int Update(T entity, bool ignoreNullColumns = false, object data = null);
/// <summary>
/// 批量插入记录
/// </summary>
/// <param name="entities">实体列表</param>
/// <returns>是否成功</returns>
Task<bool> InsertRangeAsync(List<T> entities);
/// <summary>
/// 只更新表达式的值
/// </summary>
/// <param name="entity"></param>
/// <param name="expression"></param>
/// <returns></returns>
int Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false);
/// <summary>
/// 更新单条记录
/// </summary>
/// <param name="entity">实体对象</param>
/// <returns>是否成功</returns>
Task<bool> UpdateAsync(T entity);
int Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
/// <summary>
/// 批量更新记录
/// </summary>
/// <param name="entities">实体列表</param>
/// <returns>是否成功</returns>
Task<bool> UpdateRangeAsync(List<T> entities);
int Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> where);
Task<int> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> where);
/// <summary>
/// 根据Id删除记录软删除
/// </summary>
/// <param name="id">主键Id</param>
/// <returns>是否成功</returns>
Task<bool> DeleteByIdAsync(long id);
#endregion update
/// <summary>
/// 根据条件删除记录(软删除)
/// </summary>
/// <param name="where">删除条件</param>
/// <returns>是否成功</returns>
Task<bool> DeleteByWhereAsync(Expression<Func<T, bool>> where);
/// <summary>
/// 事务 同步
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
Task UseTranAsync(Func<Task> action);
/// <summary>
/// 根据条件获取记录数
/// </summary>
/// <param name="where">查询条件</param>
/// <returns>记录数</returns>
Task<int> GetCountAsync(Expression<Func<T, bool>> where);
/// <summary>
/// 事务 异步
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
Task<bool> UseTranAsync(Func<Task<bool>> action);
#region delete
IDeleteable<T> Deleteable();
int Delete(object id, string title = "");
int DeleteTable();
bool Truncate();
#endregion delete
#region query
/// <summary>
/// 根据条件查询分页数据
/// </summary>
/// <param name="where"></param>
/// <param name="parm"></param>
/// <returns></returns>
PageListModel<T> GetPages(Expression<Func<T, bool>> where, PageQueryModel parm);
PageListModel<T> GetPages(Expression<Func<T, bool>> where, PageQueryModel parm, Expression<Func<T, object>> order, OrderByType orderEnum = OrderByType.Asc);
PageListModel<T> GetPages(Expression<Func<T, bool>> where, PageQueryModel parm, Expression<Func<T, object>> order, string orderByType);
bool Any(Expression<Func<T, bool>> expression);
ISugarQueryable<T> Queryable();
List<T> GetAll(bool useCache = false, int cacheSecond = 3600);
List<T> SqlQueryToList(string sql, object obj = null);
/// <summary>
/// 根据主值查询单条数据
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>泛型实体</returns>
R GetById<R>(object pkValue) where R : class;
Task<R> GetByExpression<R>(Expression<Func<T, bool>> expression) where R : class;
Task<List<T2>> GetListByExpression<T2>(Expression<Func<T, bool>> expression) where T2 : class;
#endregion query
#region Procedure
DataTable UseStoredProcedureToDataTable(string procedureName, List<SugarParameter> parameters);
(DataTable, List<SugarParameter>) UseStoredProcedureToTuple(string procedureName, List<SugarParameter> parameters);
#endregion Procedure
}
}