NewsService.cs 2 KB
using Antis.Erp.Application.Contracts.Dtos.News;
using Antis.Erp.Application.Contracts.IServices;
using Antis.Erp.Domain.Entities;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Ddd.Application;
using Yi.Framework.SqlSugarCore.Abstractions;

namespace Antis.Erp.Application.Services
{
    /// <summary>
    /// 新闻服务实现
    /// </summary>
    public class NewsService : YiCrudAppService<TestNewAggregateRoot, NewsGetOutputDto, NewsGetListOutputDto, Guid,
            NewsGetListInputVo, NewsCreateInputVo, NewsUpdateInputVo>,
        INewsService
    {
        private ISqlSugarRepository<TestNewAggregateRoot, Guid> _repository;

        public NewsService(ISqlSugarRepository<TestNewAggregateRoot, Guid> repository) : base(repository)
        {
            _repository = repository;
        }

        /// <summary>
        /// 多查(分页查询)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<NewsGetListOutputDto>> GetListAsync(NewsGetListInputVo input)
        {
            RefAsync<int> total = 0;

            var entities = await _repository._DbQueryable
                .WhereIF(!string.IsNullOrEmpty(input.Title), x => x.Title.Contains(input.Title!))
                .WhereIF(!string.IsNullOrEmpty(input.Author), x => x.Author != null && x.Author.Contains(input.Author!))
                .WhereIF(!string.IsNullOrEmpty(input.Category), x => x.Category == input.Category)
                .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)
                .OrderByDescending(x => x.CreationTime)
                .ToPageListAsync(input.SkipCount, input.MaxResultCount, total);

            return new PagedResultDto<NewsGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
        }
    }
}