重构项目,将项目拆分(临时提交)

This commit is contained in:
2025-07-18 22:21:16 +08:00
parent 2cde703f1a
commit 7ca6e4e127
189 changed files with 1090 additions and 1667 deletions

View File

@@ -0,0 +1,103 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using DMS.Infrastructure.Entities;
using DMS.Helper;
namespace DMS.Infrastructure.Repositories;
/// <summary>
/// 用户仓储类用于操作DbUser实体
/// </summary>
public class UserRepository
{
/// <summary>
/// 根据ID获取用户
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public async Task<DbUser> GetByIdAsync(int id)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Queryable<DbUser>().In(id).SingleAsync();
stopwatch.Stop();
NlogHelper.Info($"根据ID '{id}' 获取用户耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
}
/// <summary>
/// 获取所有用户
/// </summary>
/// <returns></returns>
public async Task<List<DbUser>> GetAllAsync()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Queryable<DbUser>().ToListAsync();
stopwatch.Stop();
NlogHelper.Info($"获取所有用户耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="user">用户实体</param>
/// <returns></returns>
public async Task<int> AddAsync(DbUser user)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Insertable(user).ExecuteReturnIdentityAsync();
stopwatch.Stop();
NlogHelper.Info($"新增用户 '{user.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
}
/// <summary>
/// 更新用户
/// </summary>
/// <param name="user">用户实体</param>
/// <returns></returns>
public async Task<int> UpdateAsync(DbUser user)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Updateable(user).ExecuteCommandAsync();
stopwatch.Stop();
NlogHelper.Info($"更新用户 '{user.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
}
/// <summary>
/// 根据ID删除用户
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public async Task<int> DeleteAsync(int id)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Deleteable<DbUser>().In(id).ExecuteCommandAsync();
stopwatch.Stop();
NlogHelper.Info($"删除用户ID '{id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
}
}