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.

264 lines
14 KiB

11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
11 months ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Shentun.Peis.BigtextResultTemplates;
  4. using Shentun.Peis.CommonTables;
  5. using Shentun.Peis.HelperDto;
  6. using Shentun.Peis.Items;
  7. using Shentun.Peis.Models;
  8. using SqlSugar;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Volo.Abp.Application.Services;
  15. using Volo.Abp.Domain.Repositories;
  16. namespace Shentun.Peis.BigtextResultTemplates
  17. {
  18. /// <summary>
  19. /// 大文本结果模板
  20. /// </summary>
  21. [ApiExplorerSettings(GroupName = "Work")]
  22. [Authorize]
  23. public class BigtextResultTemplateAppService : ApplicationService
  24. {
  25. private readonly IRepository<BigtextResultTemplate, Guid> _bigtextResultTemplateRepository;
  26. private readonly CacheService _cacheService;
  27. private readonly BigtextResultTemplateManager _bigtextResultTemplateManager;
  28. private readonly IRepository<BigtextResultConclusion, Guid> _bigtextResultConclusionRepository;
  29. private readonly IRepository<BigtextResultDescription, Guid> _bigtextResultDescriptionRepository;
  30. private readonly IRepository<ItemBigtextResultType> _itemBigtextResultTypeRepository;
  31. private readonly IRepository<BigtextResultType, Guid> _bigtextResultTypeRepository;
  32. public BigtextResultTemplateAppService(
  33. IRepository<BigtextResultTemplate, Guid> bigtextResultTemplateRepository,
  34. CacheService cacheService,
  35. BigtextResultTemplateManager bigtextResultTemplateManager,
  36. IRepository<BigtextResultConclusion, Guid> bigtextResultConclusionRepository,
  37. IRepository<BigtextResultDescription, Guid> bigtextResultDescriptionRepository,
  38. IRepository<ItemBigtextResultType> itemBigtextResultTypeRepository,
  39. IRepository<BigtextResultType, Guid> bigtextResultTypeRepository)
  40. {
  41. _bigtextResultTemplateRepository = bigtextResultTemplateRepository;
  42. _cacheService = cacheService;
  43. _bigtextResultTemplateManager = bigtextResultTemplateManager;
  44. _bigtextResultConclusionRepository = bigtextResultConclusionRepository;
  45. _bigtextResultDescriptionRepository = bigtextResultDescriptionRepository;
  46. _itemBigtextResultTypeRepository = itemBigtextResultTypeRepository;
  47. _bigtextResultTypeRepository = bigtextResultTypeRepository;
  48. }
  49. /// <summary>
  50. /// 获取通过主键
  51. /// </summary>
  52. /// <param name="input"></param>
  53. /// <returns></returns>
  54. [HttpPost("api/app/BigtextResultTemplate/Get")]
  55. public async Task<BigtextResultTemplateDto> GetAsync(BigtextResultTemplateIdInputDto input)
  56. {
  57. var bigtextResultTemplateEnt = await _bigtextResultTemplateRepository.GetAsync(input.BigtextResultTemplateId);
  58. var entityDto = ObjectMapper.Map<BigtextResultTemplate, BigtextResultTemplateDto>(bigtextResultTemplateEnt);
  59. entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
  60. entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
  61. return entityDto;
  62. }
  63. /// <summary>
  64. /// 获取列表 可根据条件检索
  65. /// </summary>
  66. /// <returns></returns>
  67. [HttpPost("api/app/BigtextResultTemplate/GetList")]
  68. public async Task<List<BigtextResultTemplateDto>> GetListAsync(BigtextResultTemplateListInputDto input)
  69. {
  70. var query = await _bigtextResultTemplateRepository.GetQueryableAsync();
  71. if (input.BigtextResultTypeId != null)
  72. query = query.Where(m => m.BigtextResultTypeId == input.BigtextResultTypeId);
  73. if (!string.IsNullOrWhiteSpace(input.KeyWord))
  74. query = query.Where(m => m.DisplayName.Contains(input.KeyWord) || m.SimpleCode.Contains(input.KeyWord));
  75. var entdto = query.Select(s => new BigtextResultTemplateDto
  76. {
  77. CreationTime = s.CreationTime,
  78. CreatorId = s.CreatorId,
  79. DisplayName = s.DisplayName,
  80. DisplayOrder = s.DisplayOrder,
  81. Id = s.Id,
  82. BigtextResultTypeId = s.BigtextResultTypeId,
  83. LastModificationTime = s.LastModificationTime,
  84. LastModifierId = s.LastModifierId,
  85. SimpleCode = s.SimpleCode,
  86. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  87. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  88. }).OrderBy(o => o.DisplayOrder).ToList();
  89. return entdto;
  90. }
  91. /// <summary>
  92. /// 创建
  93. /// </summary>
  94. /// <param name="input"></param>
  95. /// <returns></returns>
  96. [HttpPost("api/app/BigtextResultTemplate/Create")]
  97. public async Task<BigtextResultTemplateDto> CreateAsync(CreateBigtextResultTemplateDto input)
  98. {
  99. var createEntity = ObjectMapper.Map<CreateBigtextResultTemplateDto, BigtextResultTemplate>(input);
  100. var entity = await _bigtextResultTemplateManager.CreateAsync(createEntity);
  101. entity = await _bigtextResultTemplateRepository.InsertAsync(entity);
  102. var dto = ObjectMapper.Map<BigtextResultTemplate, BigtextResultTemplateDto>(entity);
  103. dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
  104. dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
  105. return dto;
  106. }
  107. /// <summary>
  108. /// 更新
  109. /// </summary>
  110. /// <param name="input"></param>
  111. /// <returns></returns>
  112. [HttpPost("api/app/BigtextResultTemplate/Update")]
  113. public async Task<BigtextResultTemplateDto> UpdateAsync(UpdateBigtextResultTemplateDto input)
  114. {
  115. var entity = await _bigtextResultTemplateRepository.GetAsync(input.BigtextResultTemplateId);
  116. var sourceEntity = ObjectMapper.Map<UpdateBigtextResultTemplateDto, BigtextResultTemplate>(input);
  117. await _bigtextResultTemplateManager.UpdateAsync(sourceEntity, entity);
  118. entity = await _bigtextResultTemplateRepository.UpdateAsync(entity);
  119. var dto = ObjectMapper.Map<BigtextResultTemplate, BigtextResultTemplateDto>(entity);
  120. dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
  121. dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
  122. return dto;
  123. }
  124. /// <summary>
  125. /// 删除
  126. /// </summary>
  127. /// <param name="input"></param>
  128. /// <returns></returns>
  129. [HttpPost("api/app/BigtextResultTemplate/Delete")]
  130. public async Task DeleteAsync(BigtextResultTemplateIdInputDto input)
  131. {
  132. await _bigtextResultTemplateManager.CheckAndDeleteAsync(input.BigtextResultTemplateId);
  133. }
  134. /// <summary>
  135. /// 修改排序 置顶,置底
  136. /// </summary>
  137. /// <param name="input"></param>
  138. /// <returns></returns>
  139. [HttpPost("api/app/BigtextResultTemplate/UpdateManySort")]
  140. public async Task UpdateManySortAsync(UpdateManySortBigtextResultTemplateInputDto input)
  141. {
  142. await _bigtextResultTemplateManager.UpdateManySortAsync(input.BigtextResultTemplateId, input.SortType);
  143. }
  144. /// <summary>
  145. /// 修改排序 拖拽
  146. /// </summary>
  147. /// <param name="input"></param>
  148. /// <returns></returns>
  149. [HttpPost("api/app/BigtextResultTemplate/UpdateSortMany")]
  150. public async Task UpdateSortManyAsync(UpdateSortManyCommonDto input)
  151. {
  152. await _bigtextResultTemplateManager.UpdateSortManyAsync(input);
  153. }
  154. /// <summary>
  155. /// 获取模板下的描述跟结论
  156. /// </summary>
  157. /// <param name="input"></param>
  158. /// <returns></returns>
  159. [HttpPost("api/app/BigtextResultTemplate/GetBigtextResultTemplateDetail")]
  160. public async Task<GetBigtextResultTemplateDetailDto> GetBigtextResultTemplateDetailAsync(GetBigtextResultTemplateDetailInputDto input)
  161. {
  162. var entDto = new GetBigtextResultTemplateDetailDto();
  163. var descriptionDetail = (from bigtextResultTemplate in await _bigtextResultTemplateRepository.GetQueryableAsync()
  164. join bigtextResultDescription in await _bigtextResultDescriptionRepository.GetQueryableAsync()
  165. on bigtextResultTemplate.Id equals bigtextResultDescription.BigtextResultTemplateId
  166. orderby bigtextResultTemplate.DisplayOrder, bigtextResultDescription.DisplayOrder ascending
  167. select new GetBigtextResultTemplateDetailDescription
  168. {
  169. BigtextResultTemplateId = bigtextResultTemplate.Id,
  170. BigtextResultTemplateName = bigtextResultTemplate.DisplayName,
  171. Description = bigtextResultDescription.Description
  172. });
  173. var conclusionDetail = (from bigtextResultTemplate in await _bigtextResultTemplateRepository.GetQueryableAsync()
  174. join bigtextResultConclusion in await _bigtextResultConclusionRepository.GetQueryableAsync()
  175. on bigtextResultTemplate.Id equals bigtextResultConclusion.BigtextResultTemplateId
  176. orderby bigtextResultTemplate.DisplayOrder, bigtextResultConclusion.DisplayOrder ascending
  177. select new GetBigtextResultTemplateDetailConclusion
  178. {
  179. BigtextResultTemplateId = bigtextResultTemplate.Id,
  180. BigtextResultTemplateName = bigtextResultTemplate.DisplayName,
  181. Conclusion = bigtextResultConclusion.Conclusion,
  182. IsAbnormal = bigtextResultConclusion.IsAbnormal
  183. });
  184. if (input.BigtextResultTemplateIds.Any())
  185. {
  186. descriptionDetail = descriptionDetail.Where(m => input.BigtextResultTemplateIds.Contains(m.BigtextResultTemplateId));
  187. conclusionDetail = conclusionDetail.Where(m => input.BigtextResultTemplateIds.Contains(m.BigtextResultTemplateId));
  188. }
  189. entDto.ConclusionDetail = conclusionDetail.ToList();
  190. entDto.DescriptionDetail = descriptionDetail.ToList();
  191. return entDto;
  192. }
  193. /// <summary>
  194. /// 根据项目获取对应的词条模板、描述跟建议(多条换行合并)
  195. /// </summary>
  196. /// <param name="input"></param>
  197. /// <returns></returns>
  198. [HttpPost("api/app/BigtextResultTemplate/GetBigtextResultTemplateWithDetail")]
  199. public async Task<List<GetBigtextResultTemplateWithDetailDto>> GetBigtextResultTemplateWithDetailAsync(ItemIdInputDto input)
  200. {
  201. var query = (from itemBigtextResultType in await _itemBigtextResultTypeRepository.GetQueryableAsync()
  202. join bigtextResultType in await _bigtextResultTypeRepository.GetQueryableAsync() on itemBigtextResultType.BigtextResultTypeId equals bigtextResultType.Id
  203. join bigtextResultTemplate in await _bigtextResultTemplateRepository.GetQueryableAsync() on bigtextResultType.Id equals bigtextResultTemplate.BigtextResultTypeId
  204. join bigtextResultConclusion in await _bigtextResultConclusionRepository.GetQueryableAsync() on bigtextResultTemplate.Id equals bigtextResultConclusion.BigtextResultTemplateId into bigtextResultConclusionTemp
  205. from bigtextResultConclusionHaveEmpty in bigtextResultConclusionTemp.DefaultIfEmpty()
  206. join bigtextResultDescription in await _bigtextResultDescriptionRepository.GetQueryableAsync() on bigtextResultTemplate.Id equals bigtextResultDescription.BigtextResultTemplateId into bigtextResultDescriptionTemp
  207. from bigtextResultDescriptionHaveEmpty in bigtextResultDescriptionTemp.DefaultIfEmpty()
  208. where itemBigtextResultType.ItemId == input.ItemId
  209. orderby bigtextResultTemplate.DisplayOrder ascending
  210. select new
  211. {
  212. bigtextResultTypeName = bigtextResultType.DisplayName,
  213. bigtextResultTemplateName = bigtextResultTemplate.DisplayName,
  214. bigtextResultTemplateId = bigtextResultTemplate.Id,
  215. bigtextResultConclusionHaveEmpty,
  216. bigtextResultDescriptionHaveEmpty
  217. }).ToList();
  218. var bigtextResultTemplateGroup = query.GroupBy(g => g.bigtextResultTemplateId);
  219. var entListDto = bigtextResultTemplateGroup.Select(s => new GetBigtextResultTemplateWithDetailDto
  220. {
  221. BigtextResultTypeName = s.FirstOrDefault().bigtextResultTypeName,
  222. BigtextResultTemplateName = s.FirstOrDefault().bigtextResultTemplateName,
  223. bigtextResultDescription = string.Join(";", s.Where(m => m.bigtextResultDescriptionHaveEmpty != null).Select(ss => ss.bigtextResultDescriptionHaveEmpty.Description).Distinct()),
  224. bigtextResultConclusion = string.Join(";", s.Where(m => m.bigtextResultConclusionHaveEmpty != null).Select(ss => ss.bigtextResultConclusionHaveEmpty.Conclusion).Distinct())
  225. }).ToList();
  226. return entListDto;
  227. }
  228. }
  229. }