using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
namespace Shentun.Peis.Asbitems
{
///
/// 组合项目设置
///
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class AsbitemAppService : CrudAppService<
Asbitem, //The Book entity
AsbitemDto, //Used to show books
Guid, //Primary key of the book entity
PagedAndSortedResultRequestDto, //Used for paging/sorting
CreateAsbitemDto,
UpdateAsbitemDto>
{
private readonly IRepository _userRepository;
private readonly IDistributedCache _asbitemCache;
private readonly AsbitemManager _manager;
private readonly IRepository- _itemRepository;
private readonly IRepository _asbitemDetailRepository;
private readonly CacheService _cacheService;
public AsbitemAppService(
IRepository repository,
IRepository userRepository,
AsbitemManager manager,
IDistributedCache asbitemCache,
IRepository
- itemRepository,
IRepository asbitemDetailRepository,
CacheService cacheService)
: base(repository)
{
_userRepository = userRepository;
_manager = manager;
_asbitemCache = asbitemCache;
_itemRepository = itemRepository;
_asbitemDetailRepository = asbitemDetailRepository;
_cacheService = cacheService;
}
///
/// 获取通过主键
///
///
///
public override async Task GetAsync(Guid id)
{
var entityDto = await base.GetAsync(id);
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
return entityDto;
}
///
/// 获取列表 组合项目设置
///
///
///
[RemoteService(false)]
public override async Task> GetListAsync(PagedAndSortedResultRequestDto input)
{
return await base.GetListAsync(input);
}
///
/// 获取列表 整合多条件查询 项目类别、名字、拼音简码、是否只显示启用的数据(默认显示全部)
///
///
///
[HttpPost("api/app/asbitem/getasbitemlist")]
public async Task
> GetAsbitemListAsync(GetAsbitemListDto input)
{
var query = from a in await Repository.GetQueryableAsync()
join b in await _userRepository.GetQueryableAsync() on a.CreatorId equals b.Id into bb
from ab in bb.DefaultIfEmpty()
join c in await _userRepository.GetQueryableAsync() on a.LastModifierId equals c.Id into cc
from ac in cc.DefaultIfEmpty()
select new { a, ab, ac };
if (input.ItemTypeId != null && input.ItemTypeId != Guid.Empty)
{
query = query.Where(m => m.a.ItemTypeId == input.ItemTypeId);
}
if (!string.IsNullOrEmpty(input.AsbitemName))
{
query = query.Where(m => (!string.IsNullOrEmpty(m.a.DisplayName) && m.a.DisplayName.Contains(input.AsbitemName))
|| (!string.IsNullOrEmpty(m.a.SimpleCode) && m.a.SimpleCode.Contains(input.AsbitemName)));
}
if (input.IsFilterActive == 'Y')
{
query = query.Where(m => m.a.IsActive == 'Y');
}
var entdto = query.Select(s => new AsbitemDto
{
ClinicalMeaning = s.a.ClinicalMeaning,
ItemTypeId = s.a.ItemTypeId,
CreationTime = s.a.CreationTime,
CreatorId = s.a.CreatorId,
DefaultResult = s.a.DefaultResult,
DeviceTypeId = s.a.DeviceTypeId,
DiagnosisFunction = s.a.DiagnosisFunction,
DisplayName = s.a.DisplayName,
DisplayOrder = s.a.DisplayOrder,
ForSexId = s.a.ForSexId,
MaritalStatusId = s.a.MaritalStatusId,
Id = s.a.Id,
CollectItemTypeId = s.a.CollectItemTypeId,
//InvoiceItemTypeId = s.a.InvoiceItemTypeId,
IsActive = s.a.IsActive,
IsBeforeEat = s.a.IsBeforeEat,
IsCheck = s.a.IsCheck,
IsContinueProcess = s.a.IsContinueProcess,
IsDiagnosisFunction = s.a.IsDiagnosisFunction,
IsItemResultMerger = s.a.IsItemResultMerger,
IsPictureRotate = s.a.IsPictureRotate,
LastModificationTime = s.a.LastModificationTime,
LastModifierId = s.a.LastModifierId,
Price = s.a.Price,
QueueTime = s.a.QueueTime,
ShortName = s.a.ShortName,
SimpleCode = s.a.SimpleCode,
BarcodeMode = s.a.BarcodeMode,
IsWebAppoint = s.a.IsWebAppoint,
DiseaseScreeningTypeId = s.a.DiseaseScreeningTypeId,
Warn = s.a.Warn,
ForPregnantFlag = s.a.ForPregnantFlag,
CriticalValueFunction = s.a.CriticalValueFunction,
FollowUpFunction = s.a.FollowUpFunction,
IsCriticalValueFunction = s.a.IsCriticalValueFunction,
IsFollowUpFunction = s.a.IsFollowUpFunction,
IsPrivacy = s.a.IsPrivacy,
//IsDisablePregnancy = s.a.IsDisablePregnancy,
//IsDisablePreparePregnancy = s.a.IsDisablePreparePregnancy,
CreatorName = s.ab != null ? s.ab.Surname : "",
LastModifierName = s.ac != null ? s.ac.Surname : "",
IsOutsend = s.a.IsOutsend
}).OrderBy(o => o.DisplayOrder).ToList();
return entdto;
}
[HttpPost("api/app/asbitem/GetBasicList")]
public async Task> GetBasicListAsync(GetAsbitemListDto input)
{
var query = await Repository.GetQueryableAsync();
if (input.ItemTypeId != null && input.ItemTypeId != Guid.Empty)
{
query = query.Where(m => m.ItemTypeId == input.ItemTypeId);
}
if (!string.IsNullOrEmpty(input.AsbitemName))
{
query = query.Where(m => (!string.IsNullOrEmpty(m.DisplayName) && m.DisplayName.Contains(input.AsbitemName))
|| (!string.IsNullOrEmpty(m.SimpleCode) && m.SimpleCode.Contains(input.AsbitemName)));
}
if (input.IsFilterActive == 'Y')
{
query = query.Where(m => m.IsActive == 'Y');
}
var entdto = query.Select(s => new BasicAsbitemDto
{
ClinicalMeaning = s.ClinicalMeaning,
ItemTypeId = s.ItemTypeId,
DisplayName = s.DisplayName,
DisplayOrder = s.DisplayOrder,
ForSexId = s.ForSexId,
Id = s.Id,
IsActive = s.IsActive,
IsBeforeEat = s.IsBeforeEat,
IsCheck = s.IsCheck,
IsItemResultMerger = s.IsItemResultMerger,
Price = s.Price,
ShortName = s.ShortName,
SimpleCode = s.SimpleCode,
ForPregnantFlag = s.ForPregnantFlag,
MaritalStatusId = s.MaritalStatusId,
}).OrderBy(o => o.DisplayOrder).ToList();
return entdto;
}
///
/// 创建
///
///
///
public override async Task CreateAsync(CreateAsbitemDto input)
{
var createEntity = ObjectMapper.Map(input);
var entity = await _manager.CreateAsync(createEntity);
entity = await Repository.InsertAsync(entity);
_asbitemCache.Set(entity.Id, entity);
var dto = ObjectMapper.Map(entity);
return dto;
}
///
/// 更新
///
///
///
///
public override async Task UpdateAsync(Guid id, UpdateAsbitemDto input)
{
var entity = await Repository.GetAsync(id);
var sourceEntity = ObjectMapper.Map(input);
await _manager.UpdateAsync(sourceEntity, entity);
entity = await Repository.UpdateAsync(entity);
_asbitemCache.Set(entity.Id, entity);
return ObjectMapper.Map(entity);
}
///
/// 删除
///
///
///
public override async Task DeleteAsync(Guid id)
{
await _manager.CheckAndDeleteAsync(id);
}
///
/// 修改排序 置顶,置底
///
/// 需要修改的ID
/// 修改方式:1 置顶 2 置底
///
[HttpPut("api/app/asbitem/updatemanysort")]
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await _manager.UpdateManySortAsync(id, SortType);
}
///
/// 修改排序 拖拽
///
///
///
[HttpPut("api/app/asbitem/updatesortmany")]
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
{
await _manager.UpdateSortManyAsync(input);
}
///
/// 查询组合项目的子项目名称列表 登记页面用
///
///
[HttpPost("api/app/Asbitem/GetSimpleAsbitemWithDetails")]
public async Task> GetSimpleAsbitemWithDetailsAsync()
{
var query = from asbtiem in await Repository.GetQueryableAsync()
join asbitemDetail in await _asbitemDetailRepository.GetQueryableAsync() on asbtiem.Id equals asbitemDetail.AsbitemId
join item in await _itemRepository.GetQueryableAsync() on asbitemDetail.ItemId equals item.Id
orderby asbtiem.DisplayOrder, item.DisplayOrder ascending
select new
{
AsbitemId = asbtiem.Id,
ItemName = item.DisplayName
};
var result = query.Select(s => new SimpleAsbitemWithDetailsDto
{
AsbitemId = s.AsbitemId,
ItemName = s.ItemName
}).ToList();
return result;
}
///
/// 获取组合项目的缓存信息
///
///
///
[HttpPost("api/app/Asbitem/GetAsbitemCacheByAsbitemId")]
public async Task GetAsbitemCacheByAsbitemIdAsync(Guid AsbitemId)
{
//var asbitemEnt = await _cacheService.GetAsbitemAsync(AsbitemId);
var asbitemEnt = await _asbitemCache.GetAsync(AsbitemId);
return asbitemEnt;
}
}
}