using Shentun.Peis.Models; using Shentun.Peis.ReportFormats; using Shentun.Peis.ReportFormatTemplates; using Shentun.Peis.Reports; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using Volo.Abp.ObjectMapping; namespace Shentun.Peis.ReportPrinters { public class ReportPrinterAppService : CrudAppService< ReportPrinter, //The Book entity ReportPrinterDto, //Used to show books string, //Primary key of the book entity PagedAndSortedResultRequestDto, //Used for paging/sorting CreateReportPrinterDto, UpdateReportPrinterDto> { private readonly IRepository _userRepository; private readonly ReportPrinterManager _manager; public ReportPrinterAppService( IRepository repository, IRepository userRepository, ReportPrinterManager manager) : base(repository) { _userRepository = userRepository; _manager = manager; } /// /// 获取通过主键 /// /// /// public override async Task GetAsync(string id) { return await base.GetAsync(id); } public async Task GetMaxByIdAsync() { var ent = (await Repository.GetListAsync()).Max(x => x.Id); var entdto = new ReportPrinterDto { Id = !string.IsNullOrEmpty(ent) ? ent : "0001" }; return entdto; } public async Task GetLocalPrinter(string reportId,string computerName) { var ent = (await Repository.GetListAsync()).Where(m => m.ReportId == reportId && m.ComputerName.Equals(computerName)).FirstOrDefault(); if (ent != null) { var dto = new ReportPrinterDto { CreationTime = ent.CreationTime, CreatorId = ent.CreatorId, ComputerName = ent.ComputerName, Id = ent.Id, ReportId = ent.ReportId, LastModificationTime = ent.LastModificationTime, LastModifierId = ent.LastModifierId, PrinterName = ent.PrinterName, CreatorName = EntityHelper.GetUserName(_userRepository, ent.CreatorId), LastModifierName = EntityHelper.GetUserName(_userRepository, ent.LastModifierId) }; return dto; } else { return null; } } /// /// 获取列表 项目 /// /// /// public override async Task> GetListAsync(PagedAndSortedResultRequestDto input) { return await base.GetListAsync(input); } public async Task> GetListInReportAsync(string reportId) { int totalCount = 0; var entlist = (await Repository.GetListAsync()).Where(m => m.ReportId == reportId); totalCount = entlist.Count(); var entdto = entlist.Select(s => new ReportPrinterDto { CreationTime = s.CreationTime, CreatorId = s.CreatorId, ComputerName = s.ComputerName, Id = s.Id, ReportId = s.ReportId, LastModificationTime = s.LastModificationTime, LastModifierId = s.LastModifierId, PrinterName = s.PrinterName, CreatorName = EntityHelper.GetUserName(_userRepository, s.CreatorId), LastModifierName = EntityHelper.GetUserName(_userRepository, s.LastModifierId) }).ToList(); return new PagedResultDto(totalCount, entdto); } /// /// 创建 /// /// /// public override async Task CreateAsync(CreateReportPrinterDto input) { var createEntity = ObjectMapper.Map(input); var entity = await _manager.CreateAsync(createEntity); entity = await Repository.InsertAsync(entity); var dto = ObjectMapper.Map(entity); return dto; } /// /// 更新 /// /// /// /// public override async Task UpdateAsync(string id, UpdateReportPrinterDto input) { var entity = await Repository.GetAsync(id); var sourceEntity = ObjectMapper.Map< UpdateReportPrinterDto, ReportPrinter>(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await Repository.UpdateAsync(entity); var dto= ObjectMapper.Map(entity); dto.CreatorName = EntityHelper.GetUserName(_userRepository, entity.CreatorId); dto.LastModifierName = EntityHelper.GetUserName(_userRepository, entity.LastModifierId); return dto; } /// /// 删除 /// /// /// public override Task DeleteAsync(string id) { return base.DeleteAsync(id); } } }