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.

205 lines
7.9 KiB

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