|
|
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{
/// <summary>
/// 组合项目设置
/// </summary>
[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<IdentityUser, Guid> _userRepository; private readonly IDistributedCache<Asbitem, Guid> _asbitemCache; private readonly AsbitemManager _manager; private readonly IRepository<Item, Guid> _itemRepository; private readonly IRepository<AsbitemDetail> _asbitemDetailRepository; private readonly CacheService _cacheService; public AsbitemAppService( IRepository<Asbitem, Guid> repository, IRepository<IdentityUser, Guid> userRepository, AsbitemManager manager, IDistributedCache<Asbitem, Guid> asbitemCache, IRepository<Item, Guid> itemRepository, IRepository<AsbitemDetail> asbitemDetailRepository, CacheService cacheService) : base(repository) { _userRepository = userRepository; _manager = manager; _asbitemCache = asbitemCache; _itemRepository = itemRepository; _asbitemDetailRepository = asbitemDetailRepository; _cacheService = cacheService; } /// <summary>
/// 获取通过主键
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task<AsbitemDto> 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; } /// <summary>
/// 获取列表 组合项目设置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[RemoteService(false)] public override async Task<PagedResultDto<AsbitemDto>> GetListAsync(PagedAndSortedResultRequestDto input) { return await base.GetListAsync(input); }
/// <summary>
/// 获取列表 整合多条件查询 项目类别、名字、拼音简码、是否只显示启用的数据(默认显示全部)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/asbitem/getasbitemlist")] public async Task<List<AsbitemDto>> 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<List<BasicAsbitemDto>> 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; } /// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<AsbitemDto> CreateAsync(CreateAsbitemDto input) { var createEntity = ObjectMapper.Map<CreateAsbitemDto, Asbitem>(input); var entity = await _manager.CreateAsync(createEntity); entity = await Repository.InsertAsync(entity); _asbitemCache.Set(entity.Id, entity); var dto = ObjectMapper.Map<Asbitem, AsbitemDto>(entity); return dto; } /// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<AsbitemDto> UpdateAsync(Guid id, UpdateAsbitemDto input) { var entity = await Repository.GetAsync(id); var sourceEntity = ObjectMapper.Map<UpdateAsbitemDto, Asbitem>(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await Repository.UpdateAsync(entity); _asbitemCache.Set(entity.Id, entity); return ObjectMapper.Map<Asbitem, AsbitemDto>(entity); } /// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task DeleteAsync(Guid id) { await _manager.CheckAndDeleteAsync(id); }
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
[HttpPut("api/app/asbitem/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/asbitem/updatesortmany")] public async Task UpdateSortManyAsync(UpdateSortManyDto input) { await _manager.UpdateSortManyAsync(input); }
/// <summary>
/// 查询组合项目的子项目名称列表 登记页面用
/// </summary>
/// <returns></returns>
[HttpPost("api/app/Asbitem/GetSimpleAsbitemWithDetails")] public async Task<List<SimpleAsbitemWithDetailsDto>> 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; }
/// <summary>
/// 获取组合项目的缓存信息
/// </summary>
/// <param name="AsbitemId"></param>
/// <returns></returns>
[HttpPost("api/app/Asbitem/GetAsbitemCacheByAsbitemId")] public async Task<Asbitem> GetAsbitemCacheByAsbitemIdAsync(Guid AsbitemId) { //var asbitemEnt = await _cacheService.GetAsbitemAsync(AsbitemId);
var asbitemEnt = await _asbitemCache.GetAsync(AsbitemId); return asbitemEnt; } }}
|