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.

282 lines
11 KiB

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
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
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
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.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.EntityFrameworkCore;
  5. using Shentun.Peis.Diagnosises;
  6. using Shentun.Peis.GuidTypes;
  7. using Shentun.Peis.HelperDto;
  8. using Shentun.Peis.Items;
  9. using Shentun.Peis.Models;
  10. using Shentun.Peis.SuggestionDtos;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using Volo.Abp.Application.Dtos;
  17. using Volo.Abp.Application.Services;
  18. using Volo.Abp.Domain.Repositories;
  19. using Volo.Abp.Identity;
  20. namespace Shentun.Peis.Diagnosises
  21. {
  22. /// <summary>
  23. /// 诊断
  24. /// </summary>
  25. [ApiExplorerSettings(GroupName = "Work")]
  26. [Authorize]
  27. public class DiagnosisAppService : CrudAppService<
  28. Diagnosis, //The Book entity
  29. DiagnosisDto, //Used to show books
  30. Guid, //Primary key of the book entity
  31. PagedAndSortedResultRequestDto, //Used for paging/sorting
  32. CreateDiagnosisDto,
  33. UpdateDiagnosisDto>
  34. {
  35. private readonly IRepository<Suggestion, Guid> _suggestionRepository;
  36. private readonly IRepository<IdentityUser, Guid> _userRepository;
  37. private readonly DiagnosisManager _manager;
  38. public DiagnosisAppService(
  39. IRepository<Diagnosis, Guid> repository,
  40. IRepository<Suggestion, Guid> suggestionRepository,
  41. IRepository<IdentityUser, Guid> userRepository,
  42. DiagnosisManager manager)
  43. : base(repository)
  44. {
  45. this._suggestionRepository = suggestionRepository;
  46. this._userRepository = userRepository;
  47. _manager = manager;
  48. }
  49. /// <summary>
  50. /// 获取通过主键
  51. /// </summary>
  52. /// <param name="id"></param>
  53. /// <returns></returns>
  54. public override async Task<DiagnosisDto> GetAsync(Guid id)
  55. {
  56. var entity = await Repository.FindAsync(o => o.Id == id);
  57. //throw new Exception("标准异常测试");
  58. //throw new BusinessException("业务异常测试");
  59. //throw new UserFriendlyException("友好异常测试");
  60. //throw new EntityNotFoundException("未发现实体异常测试");
  61. //return null;
  62. if (entity == null)
  63. return null;
  64. return ObjectMapper.Map<Diagnosis, DiagnosisDto>(entity);
  65. }
  66. /// <summary>
  67. /// 获取列表 诊断 可以按项目类别搜 两个接口组合到一起
  68. /// </summary>
  69. /// <param name="input"></param>
  70. /// <returns></returns>
  71. [HttpPost("api/app/diagnosis/getlistinsuggestion")]
  72. public async Task<List<DiagnosisInSuggestionDto>> GetListInSuggestionAsync(DiagnosisInSuggestionRequestDto input)
  73. {
  74. var query = from a in await Repository.GetQueryableAsync()
  75. join b in await _suggestionRepository.GetQueryableAsync() on a.Id equals b.DiagnosisId into bb
  76. from ab in bb.DefaultIfEmpty()
  77. join c in await _userRepository.GetQueryableAsync() on a.CreatorId equals c.Id into cc
  78. from ac in cc.DefaultIfEmpty()
  79. join d in await _userRepository.GetQueryableAsync() on a.LastModifierId equals d.Id into dd
  80. from ad in dd.DefaultIfEmpty()
  81. join e in await _userRepository.GetQueryableAsync() on ab.CreatorId equals e.Id into ee
  82. from ae in ee.DefaultIfEmpty()
  83. join f in await _userRepository.GetQueryableAsync() on ab.LastModifierId equals f.Id into ff
  84. from af in ff.DefaultIfEmpty()
  85. select new { a, ab, ac, ad, ae, af };
  86. if (input.ItemTypeId != null)
  87. {
  88. query = query.Where(m => m.a.ItemTypeId == input.ItemTypeId);
  89. }
  90. if (!string.IsNullOrEmpty(input.DiagnosisName))
  91. {
  92. query = query.Where(m => m.a.DisplayName == input.DiagnosisName);
  93. }
  94. var entlist = query.GroupBy(g => g.a.Id).Select(s => new DiagnosisInSuggestionDto
  95. {
  96. CreationTime = s.FirstOrDefault().a.CreationTime,
  97. CreatorId = s.FirstOrDefault().a.CreatorId,
  98. DisplayName = s.FirstOrDefault().a.DisplayName,
  99. DisplayOrder = s.FirstOrDefault().a.DisplayOrder,
  100. Id = s.FirstOrDefault().a.Id,
  101. LastModificationTime = s.FirstOrDefault().a.LastModificationTime,
  102. LastModifierId = s.FirstOrDefault().a.LastModifierId,
  103. SimpleCode = s.FirstOrDefault().a.SimpleCode,
  104. CreatorName = s.FirstOrDefault().ac != null ? s.FirstOrDefault().ac.UserName : "",
  105. LastModifierName = s.FirstOrDefault().ad != null ? s.FirstOrDefault().ad.UserName : "",
  106. DiagnosisLevelId = s.FirstOrDefault().a.DiagnosisLevelId,
  107. ForSexId = s.FirstOrDefault().a.ForSexId,
  108. IsIll = s.FirstOrDefault().a.IsIll,
  109. IsSummaryTemplate = s.FirstOrDefault().a.IsSummaryTemplate,
  110. ItemTypeId = s.FirstOrDefault().a.ItemTypeId,
  111. SuggestionName = s.FirstOrDefault().a.SuggestionName,
  112. Suggestions = s.Where(m => m.ab != null).Select(ss => new SuggestionDto
  113. {
  114. CreationTime = ss.ab.CreationTime,
  115. CreatorId = ss.ab.CreatorId,
  116. CreatorName = s.FirstOrDefault().ae != null ? s.FirstOrDefault().ae.UserName : "",
  117. LastModifierName = s.FirstOrDefault().af != null ? s.FirstOrDefault().af.UserName : "",
  118. DiagnosisId = ss.ab.DiagnosisId,
  119. DisplayOrder = ss.ab.DisplayOrder,
  120. Id = ss.ab.Id,
  121. LastModificationTime = ss.ab.LastModificationTime,
  122. LastModifierId = ss.ab.LastModifierId,
  123. SuggestionContent = ss.ab.SuggestionContent
  124. }).OrderBy(o => o.DisplayOrder).ToList(),
  125. }).OrderBy(o => o.DisplayOrder).ToList();
  126. return entlist;
  127. }
  128. ///// <summary>
  129. ///// 获取列表 根据项目类别获取
  130. ///// </summary>
  131. ///// <param name="ItemTypeId"></param>
  132. ///// <returns></returns>
  133. //public async Task<List<DiagnosisDto>> GetListInItemTypeAsync(Guid ItemTypeId)
  134. //{
  135. // var entlist = await Repository.GetListAsync(m => m.ItemTypeId == ItemTypeId);
  136. // var userList = await _userRepository.GetListAsync();
  137. // var entdto = entlist.Select(s => new DiagnosisDto
  138. // {
  139. // CreationTime = s.CreationTime,
  140. // CreatorId = s.CreatorId,
  141. // DisplayName = s.DisplayName,
  142. // DisplayOrder = s.DisplayOrder,
  143. // Id = s.Id,
  144. // LastModificationTime = s.LastModificationTime,
  145. // LastModifierId = s.LastModifierId,
  146. // SimpleCode = s.SimpleCode,
  147. // CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
  148. // LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
  149. // }).ToList();
  150. // return entdto;
  151. //}
  152. ///// <summary>
  153. ///// 获取列表 诊断 带搜索
  154. ///// </summary>
  155. ///// <param name="input"></param>
  156. ///// <returns></returns>
  157. //[HttpPost("api/app/diagnosis/getlistinfilter")]
  158. //public async Task<PagedResultDto<DiagnosisDto>> GetListInFilterAsync(GetListInFilterDto input)
  159. //{
  160. // int totalCount = 0;
  161. // if (!string.IsNullOrEmpty(input.Filter))
  162. // totalCount = (await Repository.GetListAsync()).Where(m => m.DisplayName.Contains(input.Filter)).Count();
  163. // else
  164. // totalCount = await Repository.CountAsync();
  165. // var entlist = await PageHelper.GetPageListInFitler(Repository, _userRepository, input);
  166. // var userList = await _userRepository.GetListAsync();
  167. // var entdto = entlist.Select(s => new DiagnosisDto
  168. // {
  169. // CreationTime = s.CreationTime,
  170. // CreatorId = s.CreatorId,
  171. // DisplayName = s.DisplayName,
  172. // DisplayOrder = s.DisplayOrder,
  173. // Id = s.Id,
  174. // LastModificationTime = s.LastModificationTime,
  175. // LastModifierId = s.LastModifierId,
  176. // SimpleCode = s.SimpleCode,
  177. // CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
  178. // LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
  179. // }).ToList();
  180. // return new PagedResultDto<DiagnosisDto>(totalCount, entdto);
  181. //}
  182. /// <summary>
  183. /// 创建
  184. /// </summary>
  185. /// <param name="input"></param>
  186. /// <returns></returns>
  187. public override async Task<DiagnosisDto> CreateAsync(CreateDiagnosisDto input)
  188. {
  189. var createEntity = ObjectMapper.Map<CreateDiagnosisDto, Diagnosis>(input);
  190. var entity = await _manager.CreateAsync(createEntity);
  191. entity = await Repository.InsertAsync(entity);
  192. var dto = ObjectMapper.Map<Diagnosis, DiagnosisDto>(entity);
  193. return dto;
  194. }
  195. /// <summary>
  196. /// 更新
  197. /// </summary>
  198. /// <param name="id"></param>
  199. /// <param name="input"></param>
  200. /// <returns></returns>
  201. public override async Task<DiagnosisDto> UpdateAsync(Guid id, UpdateDiagnosisDto input)
  202. {
  203. var entity = await Repository.GetAsync(id);
  204. var sourceEntity = ObjectMapper.Map<UpdateDiagnosisDto, Diagnosis>(input);
  205. await _manager.UpdateAsync(sourceEntity, entity);
  206. entity = await Repository.UpdateAsync(entity);
  207. return ObjectMapper.Map<Diagnosis, DiagnosisDto>(entity);
  208. }
  209. /// <summary>
  210. /// 删除
  211. /// </summary>
  212. /// <param name="id"></param>
  213. /// <returns></returns>
  214. public override Task DeleteAsync(Guid id)
  215. {
  216. return base.DeleteAsync(id);
  217. }
  218. /// <summary>
  219. /// 修改排序 相邻之间
  220. /// </summary>
  221. /// <param name="id">需要修改的ID</param>
  222. /// <param name="targetid">目标ID</param>
  223. [HttpPut("api/app/diagnosis/updatesort")]
  224. public async Task UpdateSortAsync(Guid id, Guid targetid)
  225. {
  226. await _manager.UpdateSortAsync(id, targetid);
  227. }
  228. /// <summary>
  229. /// 修改排序 置顶,置底
  230. /// </summary>
  231. /// <param name="id">需要修改的ID</param>
  232. /// <param name="SortType">修改方式:1 置顶 2 置底</param>
  233. /// <returns></returns>
  234. [HttpPut("api/app/diagnosis/updatemanysort")]
  235. public async Task UpdateManySortAsync(Guid id, int SortType)
  236. {
  237. await _manager.UpdateManySortAsync(id, SortType);
  238. }
  239. /// <summary>
  240. /// 修改排序 拖拽
  241. /// </summary>
  242. /// <param name="input"></param>
  243. /// <returns></returns>
  244. [HttpPut("api/app/diagnosis/updatesortmany")]
  245. public async Task UpdateSortManyAsync(UpdateSortManyDto input)
  246. {
  247. await _manager.UpdateSortManyAsync(input);
  248. }
  249. }
  250. }