You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.9 KiB

2 years ago
  1. using Shentun.Peis.Models;
  2. using Shentun.Peis.ReportFormats;
  3. using Shentun.Peis.ReportFormatTemplates;
  4. using Shentun.Peis.Reports;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Volo.Abp.Application.Dtos;
  11. using Volo.Abp.Application.Services;
  12. using Volo.Abp.Domain.Repositories;
  13. using Volo.Abp.Identity;
  14. using Volo.Abp.ObjectMapping;
  15. namespace Shentun.Peis.ReportPrinters
  16. {
  17. public class ReportPrinterAppService : CrudAppService<
  18. ReportPrinter, //The Book entity
  19. ReportPrinterDto, //Used to show books
  20. string, //Primary key of the book entity
  21. PagedAndSortedResultRequestDto, //Used for paging/sorting
  22. CreateReportPrinterDto,
  23. UpdateReportPrinterDto>
  24. {
  25. private readonly IRepository<IdentityUser, Guid> _userRepository;
  26. private readonly ReportPrinterManager _manager;
  27. public ReportPrinterAppService(
  28. IRepository<ReportPrinter, string> repository,
  29. IRepository<IdentityUser, Guid> userRepository,
  30. ReportPrinterManager manager)
  31. : base(repository)
  32. {
  33. _userRepository = userRepository;
  34. _manager = manager;
  35. }
  36. /// <summary>
  37. /// 获取通过主键
  38. /// </summary>
  39. /// <param name="id"></param>
  40. /// <returns></returns>
  41. public override async Task<ReportPrinterDto> GetAsync(string id)
  42. {
  43. return await base.GetAsync(id);
  44. }
  45. public async Task<ReportPrinterDto> GetMaxByIdAsync()
  46. {
  47. var ent = (await Repository.GetListAsync()).Max(x => x.Id);
  48. var entdto = new ReportPrinterDto
  49. {
  50. Id = !string.IsNullOrEmpty(ent) ? ent : "0001"
  51. };
  52. return entdto;
  53. }
  54. public async Task<ReportPrinterDto> GetLocalPrinter(string reportId,string computerName)
  55. {
  56. var ent = (await Repository.GetListAsync()).Where(m => m.ReportId == reportId && m.ComputerName.Equals(computerName)).FirstOrDefault();
  57. if (ent != null)
  58. {
  59. var dto = new ReportPrinterDto
  60. {
  61. CreationTime = ent.CreationTime,
  62. CreatorId = ent.CreatorId,
  63. ComputerName = ent.ComputerName,
  64. Id = ent.Id,
  65. ReportId = ent.ReportId,
  66. LastModificationTime = ent.LastModificationTime,
  67. LastModifierId = ent.LastModifierId,
  68. PrinterName = ent.PrinterName,
  69. CreatorName = EntityHelper.GetUserName(_userRepository, ent.CreatorId),
  70. LastModifierName = EntityHelper.GetUserName(_userRepository, ent.LastModifierId)
  71. };
  72. return dto;
  73. }
  74. else
  75. {
  76. return null;
  77. }
  78. }
  79. /// <summary>
  80. /// 获取列表 项目
  81. /// </summary>
  82. /// <param name="input"></param>
  83. /// <returns></returns>
  84. public override async Task<PagedResultDto<ReportPrinterDto>> GetListAsync(PagedAndSortedResultRequestDto input)
  85. {
  86. return await base.GetListAsync(input);
  87. }
  88. public async Task<PagedResultDto<ReportPrinterDto>> GetListInReportAsync(string reportId)
  89. {
  90. int totalCount = 0;
  91. var entlist = (await Repository.GetListAsync()).Where(m => m.ReportId == reportId);
  92. totalCount = entlist.Count();
  93. var entdto = entlist.Select(s => new ReportPrinterDto
  94. {
  95. CreationTime = s.CreationTime,
  96. CreatorId = s.CreatorId,
  97. ComputerName = s.ComputerName,
  98. Id = s.Id,
  99. ReportId = s.ReportId,
  100. LastModificationTime = s.LastModificationTime,
  101. LastModifierId = s.LastModifierId,
  102. PrinterName = s.PrinterName,
  103. CreatorName = EntityHelper.GetUserName(_userRepository, s.CreatorId),
  104. LastModifierName = EntityHelper.GetUserName(_userRepository, s.LastModifierId)
  105. }).ToList();
  106. return new PagedResultDto<ReportPrinterDto>(totalCount, entdto);
  107. }
  108. /// <summary>
  109. /// 创建
  110. /// </summary>
  111. /// <param name="input"></param>
  112. /// <returns></returns>
  113. public override async Task<ReportPrinterDto> CreateAsync(CreateReportPrinterDto input)
  114. {
  115. var createEntity = ObjectMapper.Map<CreateReportPrinterDto, ReportPrinter>(input);
  116. var entity = await _manager.CreateAsync(createEntity);
  117. entity = await Repository.InsertAsync(entity);
  118. var dto = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
  119. return dto;
  120. }
  121. /// <summary>
  122. /// 更新
  123. /// </summary>
  124. /// <param name="id"></param>
  125. /// <param name="input"></param>
  126. /// <returns></returns>
  127. public override async Task<ReportPrinterDto> UpdateAsync(string id, UpdateReportPrinterDto input)
  128. {
  129. var entity = await Repository.GetAsync(id);
  130. var sourceEntity = ObjectMapper.Map< UpdateReportPrinterDto, ReportPrinter>(input);
  131. await _manager.UpdateAsync(sourceEntity, entity);
  132. entity = await Repository.UpdateAsync(entity);
  133. var dto= ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
  134. dto.CreatorName = EntityHelper.GetUserName(_userRepository, entity.CreatorId);
  135. dto.LastModifierName = EntityHelper.GetUserName(_userRepository, entity.LastModifierId);
  136. return dto;
  137. }
  138. /// <summary>
  139. /// 删除
  140. /// </summary>
  141. /// <param name="id"></param>
  142. /// <returns></returns>
  143. public override Task DeleteAsync(string id)
  144. {
  145. return base.DeleteAsync(id);
  146. }
  147. }
  148. }