using AutoMapper.Internal.Mappers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Shentun.Peis.Diagnosises; using Shentun.Peis.GuidTypes; using Shentun.Peis.HelperDto; using Shentun.Peis.Items; using Shentun.Peis.Models; using Shentun.Peis.SuggestionDtos; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; namespace Shentun.Peis.Diagnosises { /// /// 诊断 /// [ApiExplorerSettings(GroupName = "Work")] [Authorize] public class DiagnosisAppService : CrudAppService< Diagnosis, //The Book entity DiagnosisDto, //Used to show books Guid, //Primary key of the book entity PagedAndSortedResultRequestDto, //Used for paging/sorting CreateDiagnosisDto, UpdateDiagnosisDto> { private readonly IRepository _suggestionRepository; private readonly IRepository _userRepository; private readonly DiagnosisManager _manager; public DiagnosisAppService( IRepository repository, IRepository suggestionRepository, IRepository userRepository, DiagnosisManager manager) : base(repository) { this._suggestionRepository = suggestionRepository; this._userRepository = userRepository; _manager = manager; } /// /// 获取通过主键 /// /// /// public override async Task GetAsync(Guid id) { var entity = await Repository.FindAsync(o => o.Id == id); //throw new Exception("标准异常测试"); //throw new BusinessException("业务异常测试"); //throw new UserFriendlyException("友好异常测试"); //throw new EntityNotFoundException("未发现实体异常测试"); //return null; if (entity == null) return null; return ObjectMapper.Map(entity); } /// /// 获取列表 诊断 可以按项目类别搜 两个接口组合到一起 /// /// /// [HttpPost("api/app/diagnosis/getlistinsuggestion")] public async Task> GetListInSuggestionAsync(DiagnosisInSuggestionRequestDto input) { var query = from a in await Repository.GetQueryableAsync() join b in await _suggestionRepository.GetQueryableAsync() on a.Id equals b.DiagnosisId into bb from ab in bb.DefaultIfEmpty() join c in await _userRepository.GetQueryableAsync() on a.CreatorId equals c.Id into cc from ac in cc.DefaultIfEmpty() join d in await _userRepository.GetQueryableAsync() on a.LastModifierId equals d.Id into dd from ad in dd.DefaultIfEmpty() join e in await _userRepository.GetQueryableAsync() on ab.CreatorId equals e.Id into ee from ae in ee.DefaultIfEmpty() join f in await _userRepository.GetQueryableAsync() on ab.LastModifierId equals f.Id into ff from af in ff.DefaultIfEmpty() select new { a, ab, ac, ad, ae, af }; if (input.ItemTypeId != null) { query = query.Where(m => m.a.ItemTypeId == input.ItemTypeId); } if (!string.IsNullOrEmpty(input.DiagnosisName)) { query = query.Where(m => m.a.DisplayName == input.DiagnosisName); } var entlist = query.GroupBy(g => g.a.Id).Select(s => new DiagnosisInSuggestionDto { CreationTime = s.FirstOrDefault().a.CreationTime, CreatorId = s.FirstOrDefault().a.CreatorId, DisplayName = s.FirstOrDefault().a.DisplayName, DisplayOrder = s.FirstOrDefault().a.DisplayOrder, Id = s.FirstOrDefault().a.Id, LastModificationTime = s.FirstOrDefault().a.LastModificationTime, LastModifierId = s.FirstOrDefault().a.LastModifierId, SimpleCode = s.FirstOrDefault().a.SimpleCode, CreatorName = s.FirstOrDefault().ac != null ? s.FirstOrDefault().ac.UserName : "", LastModifierName = s.FirstOrDefault().ad != null ? s.FirstOrDefault().ad.UserName : "", DiagnosisLevelId = s.FirstOrDefault().a.DiagnosisLevelId, ForSexId = s.FirstOrDefault().a.ForSexId, IsIll = s.FirstOrDefault().a.IsIll, IsSummaryTemplate = s.FirstOrDefault().a.IsSummaryTemplate, ItemTypeId = s.FirstOrDefault().a.ItemTypeId, SuggestionName = s.FirstOrDefault().a.SuggestionName, Suggestions = s.Where(m => m.ab != null).Select(ss => new SuggestionDto { CreationTime = ss.ab.CreationTime, CreatorId = ss.ab.CreatorId, CreatorName = s.FirstOrDefault().ae != null ? s.FirstOrDefault().ae.UserName : "", LastModifierName = s.FirstOrDefault().af != null ? s.FirstOrDefault().af.UserName : "", DiagnosisId = ss.ab.DiagnosisId, DisplayOrder = ss.ab.DisplayOrder, Id = ss.ab.Id, LastModificationTime = ss.ab.LastModificationTime, LastModifierId = ss.ab.LastModifierId, SuggestionContent = ss.ab.SuggestionContent }).OrderBy(o => o.DisplayOrder).ToList(), }).OrderBy(o => o.DisplayOrder).ToList(); return entlist; } ///// ///// 获取列表 根据项目类别获取 ///// ///// ///// //public async Task> GetListInItemTypeAsync(Guid ItemTypeId) //{ // var entlist = await Repository.GetListAsync(m => m.ItemTypeId == ItemTypeId); // var userList = await _userRepository.GetListAsync(); // var entdto = entlist.Select(s => new DiagnosisDto // { // CreationTime = s.CreationTime, // CreatorId = s.CreatorId, // DisplayName = s.DisplayName, // DisplayOrder = s.DisplayOrder, // Id = s.Id, // LastModificationTime = s.LastModificationTime, // LastModifierId = s.LastModifierId, // SimpleCode = s.SimpleCode, // CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId), // LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId) // }).ToList(); // return entdto; //} ///// ///// 获取列表 诊断 带搜索 ///// ///// ///// //[HttpPost("api/app/diagnosis/getlistinfilter")] //public async Task> GetListInFilterAsync(GetListInFilterDto input) //{ // int totalCount = 0; // if (!string.IsNullOrEmpty(input.Filter)) // totalCount = (await Repository.GetListAsync()).Where(m => m.DisplayName.Contains(input.Filter)).Count(); // else // totalCount = await Repository.CountAsync(); // var entlist = await PageHelper.GetPageListInFitler(Repository, _userRepository, input); // var userList = await _userRepository.GetListAsync(); // var entdto = entlist.Select(s => new DiagnosisDto // { // CreationTime = s.CreationTime, // CreatorId = s.CreatorId, // DisplayName = s.DisplayName, // DisplayOrder = s.DisplayOrder, // Id = s.Id, // LastModificationTime = s.LastModificationTime, // LastModifierId = s.LastModifierId, // SimpleCode = s.SimpleCode, // CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId), // LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId) // }).ToList(); // return new PagedResultDto(totalCount, entdto); //} /// /// 创建 /// /// /// public override async Task CreateAsync(CreateDiagnosisDto input) { var createEntity = ObjectMapper.Map(input); var entity = await _manager.CreateAsync(createEntity); entity = await Repository.InsertAsync(entity); var dto = ObjectMapper.Map(entity); return dto; } /// /// 更新 /// /// /// /// public override async Task UpdateAsync(Guid id, UpdateDiagnosisDto input) { var entity = await Repository.GetAsync(id); var sourceEntity = ObjectMapper.Map(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await Repository.UpdateAsync(entity); return ObjectMapper.Map(entity); } /// /// 删除 /// /// /// public override Task DeleteAsync(Guid id) { return base.DeleteAsync(id); } /// /// 修改排序 相邻之间 /// /// 需要修改的ID /// 目标ID [HttpPut("api/app/diagnosis/updatesort")] public async Task UpdateSortAsync(Guid id, Guid targetid) { await _manager.UpdateSortAsync(id, targetid); } /// /// 修改排序 置顶,置底 /// /// 需要修改的ID /// 修改方式:1 置顶 2 置底 /// [HttpPut("api/app/diagnosis/updatemanysort")] public async Task UpdateManySortAsync(Guid id, int SortType) { await _manager.UpdateManySortAsync(id, SortType); } /// /// 修改排序 拖拽 /// /// /// [HttpPut("api/app/diagnosis/updatesortmany")] public async Task UpdateSortManyAsync(UpdateSortManyDto input) { await _manager.UpdateSortManyAsync(input); } } }