using AutoMapper.Internal.Mappers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.DiagnosisTemplates;
using Shentun.Peis.GuidTypes;
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
namespace Shentun.Peis.DiagnosisTemplates
{
///
/// 诊断模板
///
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class DiagnosisTemplateAppService : CrudAppService<
DiagnosisTemplate, //The Book entity
DiagnosisTemplateDto, //Used to show books
Guid, //Primary key of the book entity
PagedAndSortedResultRequestDto, //Used for paging/sorting
CreateDiagnosisTemplateDto,
UpdateDiagnosisTemplateDto>
{
private readonly IRepository _userRepository;
private readonly DiagnosisTemplateManager _manager;
public DiagnosisTemplateAppService(
IRepository repository,
IRepository userRepository,
DiagnosisTemplateManager manager)
: base(repository)
{
this._userRepository = userRepository;
_manager = manager;
}
///
/// 获取通过主键
///
///
///
public override async Task GetAsync(Guid id)
{
var userList = await _userRepository.GetListAsync();
var entityDto = await base.GetAsync(id);
entityDto.CreatorName = EntityHelper.GetUserNameNoSql(userList, entityDto.CreatorId);
entityDto.LastModifierName = EntityHelper.GetUserNameNoSql(userList, entityDto.CreatorId);
return entityDto;
}
///
/// 获取列表 指引类别 遗弃
///
///
///
[RemoteService(false)]
public override async Task> GetListAsync(PagedAndSortedResultRequestDto input)
{
return await base.GetListAsync(input);
}
///
/// 获取列表 指引类别 带搜索
///
///
///
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 DiagnosisTemplateDto
{
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(CreateDiagnosisTemplateDto 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, UpdateDiagnosisTemplateDto 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 async Task DeleteAsync(Guid id)
{
await _manager.CheckAndDeleteAsync(id);
}
///
/// 修改排序 置顶,置底
///
/// 需要修改的ID
/// 修改方式:1 置顶 2 置底
///
[HttpPut("api/app/diagnosistemplate/updatemanysort")]
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await _manager.UpdateManySortAsync(id, SortType);
}
///
/// 修改排序 拖拽
///
///
///
[HttpPut("api/app/diagnosistemplate/updatesortmany")]
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
{
await _manager.UpdateSortManyAsync(input);
}
}
}