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.

185 lines
7.4 KiB

2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Shentun.Peis.Models;
  4. using Shentun.Peis.ReportFormats;
  5. using Shentun.Peis.ReportFormatTemplates;
  6. using Shentun.Peis.Reports;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Volo.Abp.Application.Dtos;
  13. using Volo.Abp.Application.Services;
  14. using Volo.Abp.Domain.Repositories;
  15. using Volo.Abp.Identity;
  16. using Volo.Abp.ObjectMapping;
  17. namespace Shentun.Peis.ReportPrinters
  18. {
  19. //[Authorize]
  20. public class ReportPrinterAppService : ApplicationService
  21. {
  22. private readonly IRepository<ReportPrinter, string> _repository;
  23. private readonly IRepository<IdentityUser, Guid> _userRepository;
  24. private readonly ReportPrinterManager _manager;
  25. public ReportPrinterAppService(
  26. IRepository<ReportPrinter, string> repository,
  27. IRepository<IdentityUser, Guid> userRepository,
  28. ReportPrinterManager manager)
  29. {
  30. _repository = repository;
  31. _userRepository = userRepository;
  32. _manager = manager;
  33. }
  34. /// <summary>
  35. /// 获取通过主键
  36. /// </summary>
  37. /// <param name="id"></param>
  38. /// <returns></returns>
  39. [HttpPost("api/app/ReportPrinter/GetById")]
  40. public async Task<ReportPrinterDto> GetByIdAsync(ReportPrinterIdDto input)
  41. {
  42. var entity = await _repository.GetAsync(input.Id);
  43. var aEntity = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
  44. var userList = await _userRepository.GetListAsync();
  45. aEntity.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId);
  46. aEntity.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId);
  47. return aEntity;
  48. }
  49. [HttpPost("api/app/ReportPrinter/GetMaxId")]
  50. public async Task<ReportPrinterDto> GetMaxIdAsync()
  51. {
  52. var ent = (await _repository.GetListAsync()).Max(x => x.Id);
  53. var entdto = new ReportPrinterDto
  54. {
  55. Id = !string.IsNullOrEmpty(ent) ? ent : "0001"
  56. };
  57. return entdto;
  58. }
  59. [HttpPost("api/app/ReportPrinter/GetLocalPrinterByComputerName")]
  60. public async Task<ReportPrinterDto> GetLocalPrinter(ComputerNameInputDto input)
  61. {
  62. var ent = (await _repository.GetListAsync()).Where(m => m.ReportId == input.ReportId && m.ComputerName.Equals(input.ComputerName)).FirstOrDefault();
  63. if (ent != null)
  64. {
  65. var userList = await _userRepository.GetListAsync();
  66. var dto = new ReportPrinterDto
  67. {
  68. CreationTime = ent.CreationTime,
  69. CreatorId = ent.CreatorId,
  70. ComputerName = ent.ComputerName,
  71. Id = ent.Id,
  72. ReportId = ent.ReportId,
  73. LastModificationTime = ent.LastModificationTime,
  74. LastModifierId = ent.LastModifierId,
  75. PrinterName = ent.PrinterName,
  76. CreatorName = EntityHelper.GetSurnameNoSql(userList, ent.CreatorId),
  77. LastModifierName = EntityHelper.GetSurnameNoSql(userList, ent.LastModifierId)
  78. };
  79. return dto;
  80. }
  81. else
  82. {
  83. return null;
  84. }
  85. }
  86. /// <summary>
  87. /// 获取列表 项目
  88. /// </summary>
  89. /// <param name="input"></param>
  90. /// <returns></returns>
  91. [HttpPost("api/app/ReportPrinter/GetList")]
  92. public async Task<List<ReportPrinterDto>> GetListAsync(PagedAndSortedResultRequestDto input)
  93. {
  94. var reportList = await _repository.GetListAsync();
  95. List<ReportPrinterDto> formats = new List<ReportPrinterDto>();
  96. foreach (var format in reportList)
  97. {
  98. var aEntity = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(format);
  99. var userList = await _userRepository.GetListAsync();
  100. aEntity.CreatorName = EntityHelper.GetSurnameNoSql(userList, format.CreatorId);
  101. aEntity.LastModifierName = EntityHelper.GetSurnameNoSql(userList, format.LastModifierId);
  102. formats.Add(aEntity);
  103. }
  104. return formats;
  105. }
  106. [HttpPost("api/app/ReportPrinter/GetListByReportId")]
  107. public async Task<PagedResultDto<ReportPrinterDto>> GetListByReportIdAsync(ReportIdInputDto input)
  108. {
  109. int totalCount = 0;
  110. var entlist = (await _repository.GetListAsync()).Where(m => m.ReportId == input.Id);
  111. totalCount = entlist.Count();
  112. var userList = await _userRepository.GetListAsync();
  113. var entdto = entlist.Select(s => new ReportPrinterDto
  114. {
  115. CreationTime = s.CreationTime,
  116. CreatorId = s.CreatorId,
  117. ComputerName = s.ComputerName,
  118. Id = s.Id,
  119. ReportId = s.ReportId,
  120. LastModificationTime = s.LastModificationTime,
  121. LastModifierId = s.LastModifierId,
  122. PrinterName = s.PrinterName,
  123. CreatorName = EntityHelper.GetSurnameNoSql(userList, s.CreatorId),
  124. LastModifierName = EntityHelper.GetSurnameNoSql(userList, s.LastModifierId)
  125. }).ToList();
  126. return new PagedResultDto<ReportPrinterDto>(totalCount, entdto);
  127. }
  128. /// <summary>
  129. /// 创建
  130. /// </summary>
  131. /// <param name="input"></param>
  132. /// <returns></returns>
  133. [HttpPost("api/app/ReportPrinter/Create")]
  134. public async Task<ReportPrinterDto> CreateAsync(CreateReportPrinterDto input)
  135. {
  136. var createEntity = ObjectMapper.Map<CreateReportPrinterDto, ReportPrinter>(input);
  137. var entity = await _manager.CreateAsync(createEntity);
  138. entity = await _repository.InsertAsync(entity);
  139. var dto = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
  140. return dto;
  141. }
  142. /// <summary>
  143. /// 更新
  144. /// </summary>
  145. /// <param name="id"></param>
  146. /// <param name="input"></param>
  147. /// <returns></returns>
  148. [HttpPost("api/app/ReportPrinter/Update")]
  149. public async Task<ReportPrinterDto> UpdateAsync(string id, UpdateReportPrinterDto input)
  150. {
  151. var userList = await _userRepository.GetListAsync();
  152. var entity = await _repository.GetAsync(id);
  153. var sourceEntity = ObjectMapper.Map< UpdateReportPrinterDto, ReportPrinter>(input);
  154. await _manager.UpdateAsync(sourceEntity, entity);
  155. entity = await _repository.UpdateAsync(entity);
  156. var dto= ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(entity);
  157. dto.CreatorName = EntityHelper.GetSurnameNoSql(userList, entity.CreatorId);
  158. dto.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entity.LastModifierId);
  159. return dto;
  160. }
  161. /// <summary>
  162. /// 删除
  163. /// </summary>
  164. /// <param name="id"></param>
  165. /// <returns></returns>
  166. [HttpPost("api/app/ReportPrinter/Delete")]
  167. public Task DeleteAsync(ReportPrinterIdDto input)
  168. {
  169. return _repository.DeleteAsync(input.Id);
  170. }
  171. }
  172. }