临时提交3
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Interfaces;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Infrastructure.Data;
|
||||
|
||||
namespace DMS.Infrastructure.Repositories;
|
||||
@@ -10,95 +9,10 @@ namespace DMS.Infrastructure.Repositories;
|
||||
/// <summary>
|
||||
/// 用户仓储类,用于操作DbUser实体
|
||||
/// </summary>
|
||||
public class UserRepository : IUserRepository
|
||||
public class UserRepository : BaseRepository<DbUser, User>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取用户
|
||||
/// </summary>
|
||||
/// <param name="id">主键ID</param>
|
||||
/// <returns></returns>
|
||||
public async Task<DbUser> GetByIdAsync(int id)
|
||||
public UserRepository(IMapper mapper, ITransaction transaction)
|
||||
: base(mapper, transaction)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user