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.

311 lines
13 KiB

using AutoMapper.Internal.Mappers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shentun.Peis.Diagnosises;
using Shentun.Peis.Enums;
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
{
/// <summary>
/// 诊断
/// </summary>
[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<Suggestion, Guid> _suggestionRepository;
private readonly IRepository<IdentityUser, Guid> _userRepository;
private readonly DiagnosisManager _manager;
public DiagnosisAppService(
IRepository<Diagnosis, Guid> repository,
IRepository<Suggestion, Guid> suggestionRepository,
IRepository<IdentityUser, Guid> userRepository,
DiagnosisManager manager)
: base(repository)
{
this._suggestionRepository = suggestionRepository;
this._userRepository = userRepository;
_manager = manager;
}
/// <summary>
/// 获取通过主键
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("api/app/diagnosis/getdiagnosis")]
public override async Task<DiagnosisDto> GetAsync(Guid id)
{
var userList = await _userRepository.GetListAsync();
var entity = await Repository.FindAsync(o => o.Id == id);
if (entity == null)
return null;
var entdto = new DiagnosisDto
{
CreationTime = entity.CreationTime,
CreatorId = entity.CreatorId,
DiagnosisLevelId = entity.DiagnosisLevelId,
DisplayName = entity.DisplayName,
DisplayOrder = entity.DisplayOrder,
ForSexId = entity.ForSexId,
Id = entity.Id,
IsIll = entity.IsIll,
IsSummaryTemplate = entity.IsSummaryTemplate,
ItemTypeId = entity.ItemTypeId,
LastModificationTime = entity.LastModificationTime,
LastModifierId = entity.LastModifierId,
CreatorName = EntityHelper.GetUserNameNoSql(userList, entity.CreatorId),
LastModifierName = EntityHelper.GetUserNameNoSql(userList, entity.LastModifierId),
SimpleCode = entity.SimpleCode,
SuggestionName = entity.SuggestionName
};
return entdto;
}
/// <summary>
/// 获取列表 诊断 可以按项目类别搜 两个接口组合到一起
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/diagnosis/getlistinsuggestion")]
public async Task<List<DiagnosisInSuggestionDto>> 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.KeyWords))
{
query = query.Where(m => (string.IsNullOrEmpty(m.a.DisplayName) && m.a.DisplayName.Contains(input.KeyWords))
|| (string.IsNullOrEmpty(m.a.SuggestionName) && m.a.SuggestionName.Contains(input.KeyWords))
|| (string.IsNullOrEmpty(m.a.SimpleCode) && m.a.SimpleCode.Contains(input.KeyWords))
);
}
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,
HealthGuidances = s.Where(m => m.ab != null && m.ab.SuggestionType == SuggestionTypeFlag.HealthGuidance).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(),
MedicalInterpretations = s.Where(m => m.ab != null && m.ab.SuggestionType == SuggestionTypeFlag.MedicalInterpretation).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.ItemTypeId).ThenBy(o => o.DisplayOrder).ToList();
return entlist;
}
///// <summary>
///// 获取列表 根据项目类别获取
///// </summary>
///// <param name="ItemTypeId"></param>
///// <returns></returns>
//public async Task<List<DiagnosisDto>> 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;
//}
///// <summary>
///// 获取列表 诊断 带搜索
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpPost("api/app/diagnosis/getlistinfilter")]
//public async Task<PagedResultDto<DiagnosisDto>> 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<DiagnosisDto>(totalCount, entdto);
//}
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/diagnosis/creatediagnosis")]
public override async Task<DiagnosisDto> CreateAsync(CreateDiagnosisDto input)
{
var createEntity = ObjectMapper.Map<CreateDiagnosisDto, Diagnosis>(input);
var entity = await _manager.CreateAsync(createEntity);
entity = await Repository.InsertAsync(entity, true);
var entdto = await GetAsync(entity.Id);
return entdto;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/diagnosis/updatediagnosis")]
public override async Task<DiagnosisDto> UpdateAsync(Guid id, UpdateDiagnosisDto input)
{
var entity = await Repository.GetAsync(id);
var sourceEntity = ObjectMapper.Map<UpdateDiagnosisDto, Diagnosis>(input);
await _manager.UpdateAsync(sourceEntity, entity);
entity = await Repository.UpdateAsync(entity);
var entdto = await GetAsync(id);
return entdto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("api/app/diagnosis/deletediagnosis")]
public override Task DeleteAsync(Guid id)
{
return base.DeleteAsync(id);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
[HttpPut("api/app/diagnosis/updatemanysort")]
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await _manager.UpdateManySortAsync(id, SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPut("api/app/diagnosis/updatesortmany")]
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
{
await _manager.UpdateSortManyAsync(input);
}
}
}