|
|
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<IdentityUser, Guid> _userRepository; private readonly ReportPrinterManager _manager; public ReportPrinterAppService( IRepository<ReportPrinter, string> repository, IRepository<IdentityUser, Guid> userRepository, ReportPrinterManager manager) : base(repository) { _userRepository = userRepository; _manager = manager; }
/// <summary>
/// 获取通过主键
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task<ReportPrinterDto> GetAsync(string id) { return await base.GetAsync(id); }
public async Task<ReportPrinterDto> 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<ReportPrinterDto> 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; } }
/// <summary>
/// 获取列表 项目
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PagedResultDto<ReportPrinterDto>> GetListAsync(PagedAndSortedResultRequestDto input) { return await base.GetListAsync(input); }
public async Task<PagedResultDto<ReportPrinterDto>> 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<ReportPrinterDto>(totalCount, entdto);
}
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<ReportPrinterDto> CreateAsync(CreateReportPrinterDto input) { var createEntity = ObjectMapper.Map<CreateReportPrinterDto, ReportPrinter>(input); var entity = await _manager.CreateAsync(createEntity); entity = await Repository.InsertAsync(entity); var dto = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity); return dto; }
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<ReportPrinterDto> 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<ReportPrinter, ReportPrinterDto>(entity); dto.CreatorName = EntityHelper.GetUserName(_userRepository, entity.CreatorId); dto.LastModifierName = EntityHelper.GetUserName(_userRepository, entity.LastModifierId); return dto; } /// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override Task DeleteAsync(string id) { return base.DeleteAsync(id); } }}
|