爆肝,重构框架,你懂得

This commit is contained in:
chenchun
2023-01-01 23:06:11 +08:00
parent dbe020dc94
commit b9384afd5d
276 changed files with 5205 additions and 3281 deletions

View File

@@ -1,13 +1,17 @@
using SqlSugar;
using System.Threading.Tasks;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.BBS;
using Yi.Framework.Model.BBS.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.BBS
{
public partial class AgreeService : BaseService<AgreeEntity>, IAgreeService
{
public AgreeService(IRepository<AgreeEntity> repository) : base(repository)
{
}
/// <summary>
/// 点赞操作
/// </summary>

View File

@@ -3,13 +3,18 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.BBS;
using Yi.Framework.Model.BBS.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.BBS
{
public partial class ArticleService : BaseService<ArticleEntity>, IArticleService
{
public ArticleService(IRepository<ArticleEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<ArticleEntity>>> SelctPageList(ArticleEntity entity, PageParModel page)
{
RefAsync<int> total = 0;
@@ -24,6 +29,5 @@ namespace Yi.Framework.Service
return new PageModel<List<ArticleEntity>>(data, total);
}
}
}

View File

@@ -0,0 +1,35 @@
using SqlSugar;
using System.Threading.Tasks;
using Yi.Framework.Interface;
using Yi.Framework.Interface.BBS;
using Yi.Framework.Model.BBS.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service.BBS
{
public partial class CommentService : BaseService<CommentEntity>, ICommentService
{
public CommentService(IRepository<CommentEntity> repository) : base(repository)
{
}
//添加一个评论
public async Task<bool> AddAsync(CommentEntity comment)
{
//如果是一级评论:不用处理
//如果是二级评论ParentId父节点评论数+1
return await _repository.UseTranAsync(async () =>
{
if (comment.ParentId != 0)
{
var parentData = await _repository.GetByIdAsync(comment.ParentId);
parentData.CommentNum += 1;
await _repository.AsUpdateable(parentData).UpdateColumns(u => new { u.CommentNum }).ExecuteCommandAsync();
}
await _repository.InsertReturnSnowflakeIdAsync(comment);
});
}
}
}

View File

@@ -4,14 +4,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.Base;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.Base
{
[AppService]
public class BaseService<T>:IBaseService<T> where T:class,new()
public class BaseService<T> : IBaseService<T> where T : class, new()
{
public IRepository<T> _repository { get; set; }
public BaseService(IRepository<T> iRepository)

View File

@@ -0,0 +1,215 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Interface.Base.Crud;
using Yi.Framework.Model.Base;
using Yi.Framework.Repository;
namespace Yi.Framework.Service.Base.Crud
{
public abstract class AbstractKeyCrudAppService<TEntity, TEntityDto, TKey>
: AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TEntityDto, TEntityDto>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateUpdateInput>
: AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateUpdateInput, TCreateUpdateInput>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateInput, TUpdateInput>
: AbstractKeyCrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TCreateInput, TUpdateInput>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
}
protected override TEntityDto MapToGetListOutputDto(TEntity entity)
{
return MapToGetOutputDto(entity);
}
}
public abstract class AbstractKeyCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
: AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey>,
ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
/// <summary>
/// 创建
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public virtual async Task<TGetOutputDto> CreateAsync(TCreateInput input)
{
var entity = await MapToEntityAsync(input);
TryToSetTenantId(entity);
await Repository.InsertAsync(entity);
var entitydto = await MapToGetOutputDtoAsync(entity);
return entitydto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public virtual async Task DeleteAsync(IEnumerable<TKey> ids)
{
throw new NotImplementedException();
}
protected abstract Task DeleteByIdAsync(TKey id);
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="dto"></param>
/// <returns></returns>
public virtual async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
{
var entity = await GetEntityByIdAsync(id);
await UpdateValidAsync(entity, input);
//TODO: Check if input has id different than given id and normalize if it's default value, throw ex otherwise
await MapToEntityAsync(input, entity);
await Repository.UpdateAsync(entity);
var entitydto = await MapToGetOutputDtoAsync(entity);
return entitydto;
}
/// <summary>
/// 效验更新
/// </summary>
/// <param name="idEntity"></param>
/// <param name="dto"></param>
/// <returns></returns>
protected virtual async Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
{
return;
}
/// <summary>
/// 将 更新输入dto转化为实体的异步
/// </summary>
/// <param name="updateInput"></param>
/// <param name="entity"></param>
protected virtual Task MapToEntityAsync(TUpdateInput updateInput, TEntity entity)
{
MapToEntity(updateInput, entity);
return Task.CompletedTask;
}
/// <summary>
/// 将 更新输入dto转化为实体的同步方法
/// </summary>
/// <param name="updateInput"></param>
/// <param name="entity"></param>
protected virtual void MapToEntity(TUpdateInput updateInput, TEntity entity)
{
ObjectMapper.Map(updateInput, entity);
}
/// <summary>
/// 创建dto 给 实体的转换的异步方法
/// </summary>
/// <param name="createInput"></param>
/// <returns></returns>
protected virtual Task<TEntity> MapToEntityAsync(TCreateInput createInput)
{
return Task.FromResult(MapToEntity(createInput));
}
/// <summary>
/// 创建dto 给 实体的转换
/// </summary>
/// <param name="createInput"></param>
/// <returns></returns>
protected virtual TEntity MapToEntity(TCreateInput createInput)
{
var entity = ObjectMapper.Map<TCreateInput, TEntity>(createInput);
SetIdForGuids(entity);
return entity;
}
/// <summary>
/// 给主键id赋值上guid
/// </summary>
/// <param name="entity"></param>
protected virtual void SetIdForGuids(TEntity entity)
{
if (entity is IEntity<Guid> entityWithGuidId && entityWithGuidId.Id == Guid.Empty)
{
//这里给主键赋值为guid,l临时写死属性名
entity.GetType().GetProperty("Id").SetValue(entity, Guid.NewGuid());
//EntityHelper.TrySetId(
// entityWithGuidId,
// () => GuidGenerator.Create(),
// true
//);
}
}
/// <summary>
/// 给租户id赋值
/// </summary>
/// <param name="entity"></param>
protected virtual void TryToSetTenantId(TEntity entity)
{
//实现多租户接口
//if (entity is IMultiTenant)
//{
// //给属性租户id赋值
// if (ServiceLocator.GetTenantId(out var tid))
// {
// var tenantId = tid;
// var propertyInfo = entity.GetType().GetProperty(nameof(IMultiTenant.TenantId));
// if (propertyInfo == null || propertyInfo.GetSetMethod(true) == null)
// {
// return;
// }
// propertyInfo.SetValue(entity, tenantId);
// }
//}
}
/// <summary>
/// 判断租户id的属性是否为空
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
protected virtual bool HasTenantIdProperty(TEntity entity)
{
return entity.GetType().GetProperty(nameof(IMultiTenant.TenantId)) != null;
}
}
}

View File

@@ -0,0 +1,107 @@
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Interface.Base.Crud;
using Yi.Framework.Model.Base;
using Yi.Framework.Repository;
namespace Yi.Framework.Service.Base.Crud
{
public abstract class AbstractKeyReadOnlyAppService<TEntity, TEntityDto, TKey>
: AbstractKeyReadOnlyAppService<TEntity, TEntityDto, TEntityDto, TKey>
where TEntity : class, IEntity, new()
{
protected AbstractKeyReadOnlyAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey> : ApplicationService,
IReadOnlyAppService<TGetOutputDto, TGetListOutputDto, TKey>
where TEntity : class, IEntity, new()
{
public AbstractKeyReadOnlyAppService(IRepository<TEntity> repository, IMapper mapper) : base(mapper)
{
Repository = repository;
}
protected IRepository<TEntity> Repository { get; set; }
public async Task<TGetOutputDto> GetByIdAsync(TKey id)
{
var entity = await GetEntityByIdAsync(id);
var entityDto = await MapToGetOutputDtoAsync(entity);
return entityDto;
}
/// <summary>
/// 通过id获取实体
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
protected abstract Task<TEntity> GetEntityByIdAsync(TKey id);
/// <summary>
/// 实体向Get输出映射的异步方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
protected virtual Task<TGetOutputDto> MapToGetOutputDtoAsync(TEntity entity)
{
return Task.FromResult(MapToGetOutputDto(entity));
}
/// <summary>
/// 实体向Get输出Dto映射的同步方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
protected virtual TGetOutputDto MapToGetOutputDto(TEntity entity)
{
return ObjectMapper.Map<TEntity, TGetOutputDto>(entity);
}
/// <summary>
/// 多个实体列表映射GetList输出dto列表的异步方法
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
protected virtual async Task<List<TGetListOutputDto>> MapToGetListOutputDtosAsync(IEnumerable<TEntity> entities)
{
var dtos = new List<TGetListOutputDto>();
foreach (var entity in entities)
{
dtos.Add(await MapToGetListOutputDtoAsync(entity));
}
return dtos;
}
/// <summary>
/// 实体列表映射GetList输出dto的异步方法
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
protected virtual Task<TGetListOutputDto> MapToGetListOutputDtoAsync(TEntity entity)
{
return Task.FromResult(MapToGetListOutputDto(entity));
}
/// <summary>
/// 实体列表映射GetList输出dto的同步方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
protected virtual TGetListOutputDto MapToGetListOutputDto(TEntity entity)
{
return ObjectMapper.Map<TEntity, TGetListOutputDto>(entity);
}
}
}

View File

@@ -0,0 +1,16 @@
using AutoMapper;
using AutoMapper.Internal.Mappers;
using Microsoft.Extensions.DependencyInjection;
using Yi.Framework.Interface.Base.Crud;
namespace Yi.Framework.Service.Base.Crud
{
public class ApplicationService : IApplicationService
{
public ApplicationService(IMapper mapper)
{
ObjectMapper = mapper;
}
protected IMapper ObjectMapper { get; set; }
}
}

View File

@@ -0,0 +1,86 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Model.Base;
using Yi.Framework.Repository;
namespace Yi.Framework.Service.Base.Crud
{
public abstract class CrudAppService<TEntity, TEntityDto, TKey>
: CrudAppService<TEntity, TEntityDto, TKey, TEntityDto>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TCreateInput>
: CrudAppService<TEntity, TEntityDto, TKey, TCreateInput, TCreateInput>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TCreateInput, TUpdateInput>
: CrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
}
protected override TEntityDto MapToGetListOutputDto(TEntity entity)
{
return MapToGetOutputDto(entity);
}
}
public abstract class CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
: AbstractKeyCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override async Task DeleteByIdAsync(TKey id)
{
await DeleteAsync(new List<TKey> { id });
}
protected override async Task<TEntity> GetEntityByIdAsync(TKey id)
{
return await Repository.GetByIdAsync(id);
}
protected override void MapToEntity(TUpdateInput updateInput, TEntity entity)
{
if (updateInput is IEntityDto<TKey> entityDto)
{
entityDto.Id = entity.Id;
}
base.MapToEntity(updateInput, entity);
}
public override async Task<Result<bool>> DeleteAsync(IEnumerable<TKey> ids)
{
await Repository.DeleteAsync(e => ids.Contains(e.Id));
return Result<bool>.Success();
}
}
}

View File

@@ -0,0 +1,26 @@
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Model.Base;
using Yi.Framework.Repository;
namespace Yi.Framework.Service.Base.Crud
{
public abstract class ReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey>
: AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey>
where TEntity : class, IEntity<TKey>, new()
{
protected ReadOnlyAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override async Task<TEntity> GetEntityByIdAsync(TKey id)
{
return await Repository.GetByIdAsync(id);
}
}
}

View File

@@ -1,30 +0,0 @@
using SqlSugar;
using System.Threading.Tasks;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class CommentService : BaseService<CommentEntity>, ICommentService
{
//添加一个评论
public async Task<bool> AddAsync(CommentEntity comment)
{
//如果是一级评论:不用处理
//如果是二级评论ParentId父节点评论数+1
return await _repository.UseTranAsync(async () =>
{
if (comment.ParentId != 0)
{
var parentData = await _repository.GetByIdAsync(comment.ParentId);
parentData.CommentNum += 1;
await _repository.AsUpdateable(parentData).UpdateColumns(u => new { u.CommentNum }).ExecuteCommandAsync();
}
await _repository.InsertReturnSnowflakeIdAsync(comment);
});
}
}
}

View File

@@ -1,29 +1,32 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class ConfigService : BaseService<ConfigEntity>, IConfigService
{
public ConfigService(IRepository<ConfigEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<ConfigEntity>>> SelctPageList(ConfigEntity config, PageParModel page)
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(config.ConfigName), u => u.ConfigName.Contains(config.ConfigName))
.WhereIF(!string.IsNullOrEmpty(config.ConfigKey), u => u.ConfigKey.Contains(config.ConfigKey))
.WhereIF(page.StartTime.IsNotNull() && page.EndTime.IsNotNull(), u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(config.IsDeleted.IsNotNull(), u => u.IsDeleted == config.IsDeleted)
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(config.IsDeleted is not null, u => u.IsDeleted == config.IsDeleted)
.OrderBy(u => u.OrderNum, OrderByType.Desc)
.ToPageListAsync(page.PageNum, page.PageSize, total);
return new PageModel<List<ConfigEntity>>(data, total);
}
}
}

View File

@@ -1,21 +1,24 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class DeptService
public partial class DeptService : BaseService<DeptEntity>, IDeptService
{
public DeptService(IRepository<DeptEntity> repository) : base(repository)
{
}
public async Task<List<DeptEntity>> SelctGetList(DeptEntity dept)
{
var data = await _repository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(dept.DeptName), u => u.DeptName.Contains(dept.DeptName))
.WhereIF(dept.IsDeleted.IsNotNull(), u => u.IsDeleted == dept.IsDeleted)
.WhereIF(dept.IsDeleted is not null, u => u.IsDeleted == dept.IsDeleted)
.OrderBy(u => u.OrderNum, OrderByType.Desc)
.ToListAsync();

View File

@@ -3,13 +3,18 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class DictionaryInfoService : BaseService<DictionaryInfoEntity>, IDictionaryInfoService
{
public DictionaryInfoService(IRepository<DictionaryInfoEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<DictionaryInfoEntity>>> SelctPageList(DictionaryInfoEntity dicInfo, PageParModel page)
{
RefAsync<int> total = 0;
@@ -23,4 +28,4 @@ namespace Yi.Framework.Service
return new PageModel<List<DictionaryInfoEntity>>(data, total);
}
}
}
}

View File

@@ -1,29 +1,32 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class DictionaryService : BaseService<DictionaryEntity>, IDictionaryService
{
public DictionaryService(IRepository<DictionaryEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<DictionaryEntity>>> SelctPageList(DictionaryEntity dic, PageParModel page)
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(dic.DictName), u => u.DictName.Contains(dic.DictName))
.WhereIF(!string.IsNullOrEmpty(dic.DictType), u => u.DictType.Contains(dic.DictType))
.WhereIF(page.StartTime.IsNotNull() && page.EndTime.IsNotNull(), u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.Where(u => u.IsDeleted == false)
.OrderBy(u => u.OrderNum, OrderByType.Desc)
.ToPageListAsync(page.PageNum, page.PageSize, total);
return new PageModel<List<DictionaryEntity>>(data, total);
}
}
}

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class FileService : BaseService<FileEntity>, IFileService
{

View File

@@ -3,13 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class LogService
public partial class LogService : BaseService<LogEntity>, ILogService
{
public LogService(IRepository<LogEntity> repository) : base(repository)
{
}
public async Task<List<long>> AddListTest(List<LogEntity> logEntities)
{
return await _repository._Db.Insertable(logEntities).SplitTable().ExecuteReturnSnowflakeIdListAsync();
@@ -17,7 +22,11 @@ namespace Yi.Framework.Service
public async Task<List<LogEntity>> GetListTest()
{
return await _repository._DbQueryable.SplitTable(tas => tas.Where(u => u.TableName.Contains("2020") || u.TableName.Contains("2021"))).ToListAsync();
return await _repository._DbQueryable.SplitTable(tas =>
tas.Where(u => u.TableName.Contains("2020") || u.TableName.Contains("2021"))
).ToListAsync();
}
}
}

View File

@@ -1,24 +1,29 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class LoginLogService : BaseService<LoginLogEntity>, ILoginLogService
{
public LoginLogService(IRepository<LoginLogEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<LoginLogEntity>>> SelctPageList(LoginLogEntity loginLog, PageParModel page)
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(loginLog.LoginIp), u => u.LoginIp.Contains(loginLog.LoginIp))
.WhereIF(!string.IsNullOrEmpty(loginLog.LoginUser), u => u.LoginUser.Contains(loginLog.LoginUser))
.WhereIF(loginLog.IsDeleted.IsNotNull(), u => u.IsDeleted == loginLog.IsDeleted)
.WhereIF(page.StartTime.IsNotNull() && page.EndTime.IsNotNull(), u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(loginLog.IsDeleted is not null, u => u.IsDeleted == loginLog.IsDeleted)
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.OrderBy(u => u.CreateTime, OrderByType.Desc)
.ToPageListAsync(page.PageNum, page.PageSize, total);
return new PageModel<List<LoginLogEntity>>(data, total);

View File

@@ -1,15 +1,19 @@
using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class MenuService : BaseService<MenuEntity>, IMenuService
{
public MenuService(IRepository<MenuEntity> repository) : base(repository)
{
}
public async Task<List<MenuEntity>> SelctGetList(MenuEntity menu)
{
var data = await _repository._DbQueryable
@@ -29,7 +33,7 @@ namespace Yi.Framework.Service
public async Task<List<MenuEntity>> GetListByRoleId(long roleId)
{
return (await _repository._Db.Queryable<RoleEntity>().Includes(r => r.Menus).SingleAsync(r=>r.Id==roleId)).Menus;
return (await _repository._Db.Queryable<RoleEntity>().Includes(r => r.Menus).SingleAsync(r => r.Id == roleId)).Menus;
}
}
}

View File

@@ -1,25 +1,29 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class OperationLogService : BaseService<OperationLogEntity>, IOperationLogService
{
public OperationLogService(IRepository<OperationLogEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<OperationLogEntity>>> SelctPageList(OperationLogEntity operationLog, PageParModel page)
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(operationLog.Title), u => u.Title.Contains(operationLog.Title))
.WhereIF(!string.IsNullOrEmpty(operationLog.OperUser), u => u.OperUser.Contains(operationLog.OperUser))
.WhereIF(operationLog.OperType is not null, u => u.OperType==operationLog.OperType.GetHashCode())
.WhereIF(operationLog.IsDeleted.IsNotNull(), u => u.IsDeleted == operationLog.IsDeleted)
.WhereIF(page.StartTime.IsNotNull() && page.EndTime.IsNotNull(), u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(operationLog.OperType is not null, u => u.OperType == operationLog.OperType.GetHashCode())
.WhereIF(operationLog.IsDeleted is not null, u => u.IsDeleted == operationLog.IsDeleted)
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.OrderBy(u => u.CreateTime, OrderByType.Desc)
.ToPageListAsync(page.PageNum, page.PageSize, total);

View File

@@ -1,23 +1,28 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class PostService : BaseService<PostEntity>, IPostService
{
public PostService(IRepository<PostEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<PostEntity>>> SelctPageList(PostEntity post, PageParModel page)
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.WhereIF(!string.IsNullOrEmpty(post.PostName), u => u.PostName.Contains(post.PostName))
.WhereIF(!string.IsNullOrEmpty(post.PostCode), u => u.PostCode.Contains(post.PostCode))
.WhereIF(post.IsDeleted.IsNotNull(), u => u.IsDeleted == post.IsDeleted)
.WhereIF(post.IsDeleted is not null, u => u.IsDeleted == post.IsDeleted)
.OrderBy(u => u.OrderNum, OrderByType.Desc)
.ToPageListAsync(page.PageNum, page.PageSize, total);

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class RoleDeptService : BaseService<RoleDeptEntity>, IRoleDeptService
{

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class RoleMenuService : BaseService<RoleMenuEntity>, IRoleMenuService
{

View File

@@ -1,19 +1,24 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System;
using Yi.Framework.Common.Base;
using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
using Yi.Framework.Uow.Interceptors;
using Yi.Framework.Interface.RABC;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class RoleService
public partial class RoleService : BaseService<RoleEntity>, IRoleService
{
public RoleService(IRepository<RoleEntity> repository) : base(repository)
{
}
public async Task<List<RoleEntity>> DbTest()
{
return await _repository._Db.Queryable<RoleEntity>().ToListAsync();
@@ -24,7 +29,7 @@ namespace Yi.Framework.Service
{
var res = await _repository.InsertReturnSnowflakeIdAsync(new RoleEntity { RoleName = "测试", RoleCode = "tt" });
throw new ApplicationException("测试uow");
return res>0;
return res > 0;
}
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class TenantService : BaseService<TenantEntity>, ITenantService
{

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class UserPostService : BaseService<UserPostEntity>, IUserPostService
{

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class UserRoleService : BaseService<UserRoleEntity>, IUserRoleService
{

View File

@@ -1,23 +1,26 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System;
using Yi.Framework.Common.Base;
using Yi.Framework.Common.Const;
using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Helper;
using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
using Yi.Framework.Interface.RABC;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.RABC
{
public partial class UserService
public partial class UserService : BaseService<UserEntity>, IUserService
{
public UserService(IRepository<UserEntity> repository) : base(repository)
{
}
public async Task<List<UserEntity>> GetListInRole()
{
return await _repository._DbQueryable.Includes(u => u.Roles).ToListAsync();
@@ -55,7 +58,7 @@ namespace Yi.Framework.Service
if (await Exist(userName, o => user = o))
{
userAction.Invoke(user);
if (user.Password ==MD5Helper.SHA2Encode(password, user.Salt))
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
{
return true;
}
@@ -82,30 +85,30 @@ namespace Yi.Framework.Service
//多次操作,需要事务确保原子性
return await _repositoryUserRole.UseTranAsync(async () =>
{
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
await _repositoryUserRole.DeleteAsync(u => userIds.Contains((long)u.UserId));
{
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
await _repositoryUserRole.DeleteAsync(u => userIds.Contains((long)u.UserId));
if (roleIds is not null)
{
//遍历用户
foreach (var userId in userIds)
{
//添加新的关系
List<UserRoleEntity> userRoleEntities = new();
if (roleIds is not null)
{
//遍历用户
foreach (var userId in userIds)
{
//添加新的关系
List<UserRoleEntity> userRoleEntities = new();
foreach (var roleId in roleIds)
{
userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId });
}
foreach (var roleId in roleIds)
{
userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId });
}
//一次性批量添加
await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities);
}
}
//一次性批量添加
await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities);
}
}
});
});
}
@@ -312,6 +315,5 @@ namespace Yi.Framework.Service
userDto.User.DeptId = null;
return await _repository.UpdateIgnoreNullAsync(userDto.User);
}
}
}

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.SHOP;
using Yi.Framework.Model.SHOP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.SHOP
{
public partial class CategoryService : BaseService<CategoryEntity>, ICategoryService
{

View File

@@ -3,13 +3,18 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.SHOP;
using Yi.Framework.Model.SHOP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.SHOP
{
public partial class SkuService : BaseService<SkuEntity>, ISkuService
{
public SkuService(IRepository<SkuEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<SkuEntity>>> SelctPageList(SkuEntity enetity, PageParModel page)
{
RefAsync<int> total = 0;

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.SHOP;
using Yi.Framework.Model.SHOP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.SHOP
{
public partial class SpecsGroupService : BaseService<SpecsGroupEntity>, ISpecsGroupService
{

View File

@@ -1,9 +1,10 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.SHOP;
using Yi.Framework.Model.SHOP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.SHOP
{
public partial class SpecsService : BaseService<SpecsEntity>, ISpecsService
{

View File

@@ -3,18 +3,23 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface.SHOP;
using Yi.Framework.Model.SHOP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base;
namespace Yi.Framework.Service
namespace Yi.Framework.Service.SHOP
{
public partial class SpuService : BaseService<SpuEntity>, ISpuService
{
public SpuService(IRepository<SpuEntity> repository) : base(repository)
{
}
public async Task<PageModel<List<SpuEntity>>> SelctPageList(SpuEntity enetity, PageParModel page)
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.Includes(spu=>spu.Skus)
.Includes(spu => spu.Skus)
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(enetity.IsDeleted is not null, u => u.IsDeleted == enetity.IsDeleted)
.OrderBy(u => u.CreateTime, OrderByType.Desc)

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class AgreeService : BaseService<AgreeEntity>, IAgreeService
{
public AgreeService(IRepository<AgreeEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class ArticleService : BaseService<ArticleEntity>, IArticleService
{
public ArticleService(IRepository<ArticleEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class CommentService : BaseService<CommentEntity>, ICommentService
{
public CommentService(IRepository<CommentEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class ConfigService : BaseService<ConfigEntity>, IConfigService
{
public ConfigService(IRepository<ConfigEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class DeptService : BaseService<DeptEntity>, IDeptService
{
public DeptService(IRepository<DeptEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class DictionaryInfoService : BaseService<DictionaryInfoEntity>, IDictionaryInfoService
{
public DictionaryInfoService(IRepository<DictionaryInfoEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class DictionaryService : BaseService<DictionaryEntity>, IDictionaryService
{
public DictionaryService(IRepository<DictionaryEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class LogService : BaseService<LogEntity>, ILogService
{
public LogService(IRepository<LogEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class LoginLogService : BaseService<LoginLogEntity>, ILoginLogService
{
public LoginLogService(IRepository<LoginLogEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class MenuService : BaseService<MenuEntity>, IMenuService
{
public MenuService(IRepository<MenuEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class OperationLogService : BaseService<OperationLogEntity>, IOperationLogService
{
public OperationLogService(IRepository<OperationLogEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class PostService : BaseService<PostEntity>, IPostService
{
public PostService(IRepository<PostEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class RoleService : BaseService<RoleEntity>, IRoleService
{
public RoleService(IRepository<RoleEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class SkuService : BaseService<SkuEntity>, ISkuService
{
public SkuService(IRepository<SkuEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class SpuService : BaseService<SpuEntity>, ISpuService
{
public SpuService(IRepository<SpuEntity> repository) : base(repository)
{
}
}
}

View File

@@ -1,14 +0,0 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class UserService : BaseService<UserEntity>, IUserService
{
public UserService(IRepository<UserEntity> repository) : base(repository)
{
}
}
}