简化对象映射Mapper,简化自定义仓储

This commit is contained in:
橙子
2023-02-06 23:08:12 +08:00
parent 1d7c17e253
commit fdd1eda9ec
37 changed files with 64 additions and 523 deletions

View File

@@ -23,11 +23,15 @@ namespace Yi.RBAC.Application.Dictionary
private IDictionaryRepository _dictionaryRepository { get; set; }
public override async Task<PagedResultDto<DictionaryGetListOutputDto>> GetListAsync(DictionaryGetListInputVo input)
{
var data = await _dictionaryRepository.SelectGetListAsync(await MapToEntityAsync(input), input);
int total = 0;
var entities = await _DbQueryable.WhereIF(input.DictType is not null, x => x.DictType == input.DictType)
.WhereIF(input.DictLabel is not null, x => x.DictLabel!.Contains(input.DictLabel!))
.WhereIF(input.State is not null, x => x.State == input.State)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<DictionaryGetListOutputDto>
{
Total = data.Total,
Items = await MapToGetListOutputDtosAsync(data.Items)
Total = total,
Items = await MapToGetListOutputDtosAsync(entities)
};
}

View File

@@ -5,6 +5,7 @@ using Yi.RBAC.Domain.Dictionary.Entities;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Domain.Dictionary.Repositories;
using Yi.Framework.Ddd.Dtos;
using SqlSugar;
namespace Yi.RBAC.Application.Dictionary
{
@@ -21,11 +22,18 @@ namespace Yi.RBAC.Application.Dictionary
public async override Task<PagedResultDto<DictionaryTypeGetListOutputDto>> GetListAsync(DictionaryTypeGetListInputVo input)
{
var data = await _dictionaryTypeRepository.SelectGetListAsync(await MapToEntityAsync(input), input);
int total = 0;
var entities = await _DbQueryable.WhereIF(input.DictName is not null, x => x.DictName.Contains(input.DictName!))
.WhereIF(input.DictType is not null, x => x.DictType!.Contains(input.DictType!))
.WhereIF(input.State is not null, x => x.State == input.State)
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<DictionaryTypeGetListOutputDto>
{
Total = data.Total,
Items = await MapToGetListOutputDtosAsync(data.Items)
Total = total,
Items = await MapToGetListOutputDtosAsync(entities)
};
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Dictionary.Dtos;
using Yi.RBAC.Domain.Dictionary.Entities;
namespace Yi.RBAC.Application.Dictionary.MapperConfig
{
public class DictionaryProfile: Profile
{
public DictionaryProfile()
{
CreateMap<DictionaryGetListInputVo, DictionaryEntity>();
CreateMap<DictionaryCreateInputVo, DictionaryEntity>();
CreateMap<DictionaryUpdateInputVo, DictionaryEntity>();
CreateMap<DictionaryEntity, DictionaryGetListOutputDto>();
CreateMap<DictionaryEntity, DictionaryGetOutputDto>();
}
}
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Dictionary.Dtos;
using Yi.RBAC.Domain.Dictionary.Entities;
namespace Yi.RBAC.Application.Dictionary.MapperConfig
{
public class DictionaryTypeProfile: Profile
{
public DictionaryTypeProfile()
{
CreateMap<DictionaryTypeGetListInputVo, DictionaryTypeEntity>();
CreateMap<DictionaryTypeCreateInputVo, DictionaryTypeEntity>();
CreateMap<DictionaryTypeUpdateInputVo, DictionaryTypeEntity>();
CreateMap<DictionaryTypeEntity, DictionaryTypeGetListOutputDto>();
CreateMap<DictionaryTypeEntity, DictionaryTypeGetOutputDto>();
}
}
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Application.Identity.MapperConfig
{
public class DeptProfile: Profile
{
public DeptProfile()
{
CreateMap<DeptGetListInputVo, DeptEntity>();
CreateMap<DeptCreateInputVo, DeptEntity>();
CreateMap<DeptUpdateInputVo, DeptEntity>();
CreateMap<DeptEntity, DeptGetListOutputDto>();
CreateMap<DeptEntity, DeptGetOutputDto>();
}
}
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Application.Identity.MapperConfig
{
public class MenuProfile: Profile
{
public MenuProfile()
{
CreateMap<MenuGetListInputVo, MenuEntity>();
CreateMap<MenuCreateInputVo, MenuEntity>();
CreateMap<MenuUpdateInputVo, MenuEntity>();
CreateMap<MenuEntity, MenuGetListOutputDto>();
CreateMap<MenuEntity, MenuGetOutputDto>();
}
}
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Application.Identity.MapperConfig
{
public class PostProfile: Profile
{
public PostProfile()
{
CreateMap<PostGetListInputVo, PostEntity>();
CreateMap<PostCreateInputVo, PostEntity>();
CreateMap<PostUpdateInputVo, PostEntity>();
CreateMap<PostEntity, PostGetListOutputDto>();
CreateMap<PostEntity, PostGetOutputDto>();
}
}
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Application.Identity.MapperConfig
{
public class RoleProfile: Profile
{
public RoleProfile()
{
CreateMap<RoleGetListInputVo, RoleEntity>();
CreateMap<RoleCreateInputVo, RoleEntity>();
CreateMap<RoleUpdateInputVo, RoleEntity>();
CreateMap<RoleEntity, RoleGetListOutputDto>();
CreateMap<RoleEntity, RoleGetOutputDto>();
}
}
}

View File

@@ -1,23 +0,0 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Application.Identity.MapperConfig
{
public class UserProfile: Profile
{
public UserProfile()
{
CreateMap<UserGetListInputVo, UserEntity>();
CreateMap<UserCreateInputVo, UserEntity>();
CreateMap<UserUpdateInputVo, UserEntity>();
CreateMap<UserEntity, UserGetListOutputDto>();
CreateMap<UserEntity, UserGetOutputDto>();
}
}
}

View File

@@ -35,10 +35,17 @@ namespace Yi.RBAC.Application.Identity
public override async Task<PagedResultDto<UserGetListOutputDto>> GetListAsync(UserGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
var entities = await _userRepository.SelctGetListAsync(entity, input);
int total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.UserName), x => x.UserName.Contains(input.UserName!)).
WhereIF(input.Phone is not null, x => x.Phone.ToString()!.Contains(input.Phone.ToString()!)).
WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name!.Contains(input.Name!)).
WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime).ToPageListAsync(input.PageNum, input.PageSize, total);
var result = new PagedResultDto<UserGetListOutputDto>();
result.Items = await MapToGetListOutputDtosAsync(entities);
result.Total = await _repository.CountAsync(_ => true);
result.Total = total;
return result;
}

View File

@@ -669,14 +669,6 @@
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Domain.Identity.Repositories.IUserRepository.SelctGetListAsync(Yi.RBAC.Domain.Identity.Entities.UserEntity,Yi.Framework.Ddd.Dtos.Abstract.IPagedAllResultRequestDto)">
<summary>
动态分页选择
</summary>
<param name="input"></param>
<param name="pageInput"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Domain.Identity.UserManager.GiveUserSetRoleAsync(System.Collections.Generic.List{System.Int64},System.Collections.Generic.List{System.Int64})">
<summary>
给用户设置角色

View File

@@ -21,12 +21,5 @@ namespace Yi.RBAC.Domain.Identity.Repositories
/// <returns></returns>
Task<UserRoleMenuDto> GetUserAllInfoAsync(long userId);
/// <summary>
/// 动态分页选择
/// </summary>
/// <param name="input"></param>
/// <param name="pageInput"></param>
/// <returns></returns>
Task<List<UserEntity>> SelctGetListAsync(UserEntity input, IPagedAllResultRequestDto pageInput);
}
}

View File

@@ -1,36 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Sqlsugar.Repositories;
using Yi.Framework.Ddd.Dtos;
using Yi.Framework.Ddd.Dtos.Abstract;
using Yi.RBAC.Domain.Dictionary.Entities;
using Yi.RBAC.Domain.Dictionary.Repositories;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.RBAC.Domain.Identity.Repositories;
namespace Yi.RBAC.Sqlsugar.Repositories
{
[AppService]
public class DictionaryRepository : SqlsugarRepository<DictionaryEntity>, IDictionaryRepository
{
public DictionaryRepository(ISqlSugarClient context) : base(context)
{
}
public async Task<PagedDto<DictionaryEntity>> SelectGetListAsync(DictionaryEntity input, IPagedAndSortedResultRequestDto pageInput)
{
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(input.DictType is not null, x => x.DictType == input.DictType)
.WhereIF(input.DictLabel is not null, x => x.DictLabel!.Contains(input.DictLabel!))
.WhereIF(input.State is not null,x => x.State == input.State)
.ToPageListAsync(pageInput.PageNum, pageInput.PageSize, total);
return new PagedDto<DictionaryEntity>(total, entities);
}
}
}

View File

@@ -1,35 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Sqlsugar.Repositories;
using Yi.Framework.Ddd.Dtos;
using Yi.Framework.Ddd.Dtos.Abstract;
using Yi.RBAC.Domain.Dictionary.Entities;
using Yi.RBAC.Domain.Dictionary.Repositories;
namespace Yi.RBAC.Sqlsugar.Repositories
{
[AppService]
public class DictionaryTypeRepository : SqlsugarRepository<DictionaryTypeEntity>, IDictionaryTypeRepository
{
public DictionaryTypeRepository(ISqlSugarClient context) : base(context)
{
}
public async Task<PagedDto<DictionaryTypeEntity>> SelectGetListAsync(DictionaryTypeEntity input, IPagedAllResultRequestDto pageInput)
{
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(input.DictName is not null, x => x.DictName.Contains(input.DictName!))
.WhereIF(input.DictType is not null, x => x.DictType!.Contains(input.DictType!))
.WhereIF(input.State is not null, x => x.State == input.State)
.WhereIF(pageInput.StartTime is not null && pageInput.EndTime is not null ,x=>x.CreationTime>=pageInput.StartTime && x.CreationTime<=pageInput.EndTime)
.ToPageListAsync(pageInput.PageNum, pageInput.PageSize, total);
return new PagedDto<DictionaryTypeEntity>(total, entities);
}
}
}

View File

@@ -24,15 +24,6 @@ namespace Yi.RBAC.Sqlsugar.Repositories
}
public async Task<List<UserEntity>> SelctGetListAsync(UserEntity input, IPagedAllResultRequestDto pageInput)
{
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.UserName), x => x.UserName.Contains(input.UserName!)).
WhereIF(input.Phone is not null, x => x.Phone.ToString()! .Contains(input.Phone.ToString()!)).
WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name!.Contains(input.Name!)).
WhereIF(pageInput.StartTime is not null && pageInput.EndTime is not null, x => x.CreationTime >= pageInput.StartTime && x.CreationTime <= pageInput.EndTime).ToPageListAsync(pageInput.PageNum, pageInput.PageSize);
return entities;
}
/// <summary>
/// 获取用户id的全部信息