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.

196 lines
7.4 KiB

3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using AutoMapper.Internal.Mappers;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Shentun.Peis.ItemResultTemplates;
  4. using Shentun.Peis.GuidTypes;
  5. using Shentun.Peis.HelperDto;
  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 Shentun.Peis.SexHormoneReferenceRanges;
  16. using Shentun.Peis.Models;
  17. using Microsoft.AspNetCore.Authorization;
  18. namespace Shentun.Peis.ItemResultTemplates
  19. {
  20. /// <summary>
  21. /// 项目结果模板
  22. /// </summary>
  23. [ApiExplorerSettings(GroupName = "Work")]
  24. [Authorize]
  25. public class ItemResultTemplateAppService : CrudAppService<
  26. ItemResultTemplate, //The Book entity
  27. ItemResultTemplateDto, //Used to show books
  28. Guid, //Primary key of the book entity
  29. PagedAndSortedResultRequestDto, //Used for paging/sorting
  30. CreateItemResultTemplateDto,
  31. UpdateItemResultTemplateDto>
  32. {
  33. private readonly IRepository<IdentityUser, Guid> _userRepository;
  34. private readonly ItemResultTemplateManager _manager;
  35. public ItemResultTemplateAppService(
  36. IRepository<ItemResultTemplate, Guid> repository,
  37. IRepository<IdentityUser, Guid> userRepository,
  38. ItemResultTemplateManager manager)
  39. : base(repository)
  40. {
  41. this._userRepository = userRepository;
  42. _manager = manager;
  43. }
  44. /// <summary>
  45. /// 获取通过主键
  46. /// </summary>
  47. /// <param name="id"></param>
  48. /// <returns></returns>
  49. public override async Task<ItemResultTemplateDto> GetAsync(Guid id)
  50. {
  51. var entity = await Repository.FindAsync(o => o.Id == id);
  52. //throw new Exception("标准异常测试");
  53. //throw new BusinessException("业务异常测试");
  54. //throw new UserFriendlyException("友好异常测试");
  55. //throw new EntityNotFoundException("未发现实体异常测试");
  56. //return null;
  57. if (entity == null)
  58. return null;
  59. return ObjectMapper.Map<ItemResultTemplate, ItemResultTemplateDto>(entity);
  60. }
  61. /// <summary>
  62. /// 获取列表 项目结果模板
  63. /// </summary>
  64. /// <param name="input"></param>
  65. /// <returns></returns>
  66. public override async Task<PagedResultDto<ItemResultTemplateDto>> GetListAsync(PagedAndSortedResultRequestDto input)
  67. {
  68. int totalCount = await Repository.CountAsync();
  69. var entlist = await Repository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, input.Sorting);
  70. var userList = await _userRepository.GetListAsync();
  71. var entdto = entlist.Select(s => new ItemResultTemplateDto
  72. {
  73. CreationTime = s.CreationTime,
  74. CreatorId = s.CreatorId,
  75. ItemId = s.ItemId,
  76. Id = s.Id,
  77. LastModificationTime = s.LastModificationTime,
  78. LastModifierId = s.LastModifierId,
  79. DiagnosisId = s.DiagnosisId,
  80. SimpleCode = s.SimpleCode,
  81. ResultStatusId = s.ResultStatusId,
  82. Result = s.Result,
  83. IsResultIntoSummary = s.IsResultIntoSummary,
  84. DisplayOrder = s.DisplayOrder,
  85. IsNameIntoSummary = s.IsNameIntoSummary,
  86. CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
  87. LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
  88. }).ToList();
  89. return new PagedResultDto<ItemResultTemplateDto>(totalCount, entdto);
  90. }
  91. /// <summary>
  92. /// 获取项目结果模板列表 根据项目ID
  93. /// </summary>
  94. /// <param name="ItemId">项目ID</param>
  95. /// <returns></returns>
  96. public async Task<List<ItemResultTemplateDto>> GetListInItemIdAsync(Guid ItemId)
  97. {
  98. var entlist = await Repository.GetListAsync(m => m.ItemId == ItemId);
  99. var userList = await _userRepository.GetListAsync();
  100. var entdto = entlist.Select(s => new ItemResultTemplateDto
  101. {
  102. CreationTime = s.CreationTime,
  103. CreatorId = s.CreatorId,
  104. ItemId = s.ItemId,
  105. Id = s.Id,
  106. LastModificationTime = s.LastModificationTime,
  107. LastModifierId = s.LastModifierId,
  108. DiagnosisId = s.DiagnosisId,
  109. SimpleCode = s.SimpleCode,
  110. ResultStatusId = s.ResultStatusId,
  111. Result = s.Result,
  112. IsResultIntoSummary = s.IsResultIntoSummary,
  113. DisplayOrder = s.DisplayOrder,
  114. IsNameIntoSummary = s.IsNameIntoSummary,
  115. CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
  116. LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
  117. }).ToList();
  118. return entdto;
  119. }
  120. /// <summary>
  121. /// 创建
  122. /// </summary>
  123. /// <param name="input"></param>
  124. /// <returns></returns>
  125. public override async Task<ItemResultTemplateDto> CreateAsync(CreateItemResultTemplateDto input)
  126. {
  127. var createEntity = ObjectMapper.Map<CreateItemResultTemplateDto, ItemResultTemplate>(input);
  128. var entity = await _manager.CreateAsync(createEntity);
  129. entity = await Repository.InsertAsync(entity);
  130. var dto = ObjectMapper.Map<ItemResultTemplate, ItemResultTemplateDto>(entity);
  131. return dto;
  132. }
  133. /// <summary>
  134. /// 更新
  135. /// </summary>
  136. /// <param name="id"></param>
  137. /// <param name="input"></param>
  138. /// <returns></returns>
  139. public override async Task<ItemResultTemplateDto> UpdateAsync(Guid id, UpdateItemResultTemplateDto input)
  140. {
  141. var entity = await Repository.GetAsync(id);
  142. var sourceEntity = ObjectMapper.Map<UpdateItemResultTemplateDto, ItemResultTemplate>(input);
  143. _manager.UpdateAsync(sourceEntity, entity);
  144. entity = await Repository.UpdateAsync(entity);
  145. return ObjectMapper.Map<ItemResultTemplate, ItemResultTemplateDto>(entity);
  146. }
  147. /// <summary>
  148. /// 删除
  149. /// </summary>
  150. /// <param name="id"></param>
  151. /// <returns></returns>
  152. public override Task DeleteAsync(Guid id)
  153. {
  154. return base.DeleteAsync(id);
  155. }
  156. /// <summary>
  157. /// 修改排序 置顶,置底
  158. /// </summary>
  159. /// <param name="id">需要修改的ID</param>
  160. /// <param name="SortType">修改方式:1 置顶 2 置底</param>
  161. /// <returns></returns>
  162. [HttpPut("api/app/itemresulttemplate/updatemanysort")]
  163. public async Task UpdateManySortAsync(Guid id, int SortType)
  164. {
  165. await _manager.UpdateManySortAsync(id, SortType);
  166. }
  167. /// <summary>
  168. /// 修改排序 拖拽
  169. /// </summary>
  170. /// <param name="input"></param>
  171. /// <returns></returns>
  172. [HttpPut("api/app/itemresulttemplate/updatesortmany")]
  173. public async Task UpdateSortManyAsync(UpdateSortManyDto input)
  174. {
  175. await _manager.UpdateSortManyAsync(input);
  176. }
  177. }
  178. }