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.

130 lines
4.5 KiB

using Shentun.Peis.Enums;
using Shentun.Peis.Models;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp;
using Volo.Abp.Domain.Services;
using Shentun.Peis.HelperDto;
namespace Shentun.Peis.ThirdInterfaces
{
public class ThirdInterfaceManager : DomainService
{
private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
public ThirdInterfaceManager(
IRepository<ThirdInterface, Guid> thirdInterfaceRepository
)
{
_thirdInterfaceRepository = thirdInterfaceRepository;
}
/// <summary>
/// 创建
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<ThirdInterface> CreateAsync(
ThirdInterface entity
)
{
Verify(entity);
return new ThirdInterface
{
DisplayName = entity.DisplayName,
DisplayOrder = await EntityHelper.CreateMaxDisplayOrder<ThirdInterface>(_thirdInterfaceRepository),
IsActive = entity.IsActive,
MedicalCenterId = entity.MedicalCenterId,
ParmValue = entity.ParmValue,
ThirdInterfaceType = entity.ThirdInterfaceType
};
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public void UpdateAsync(
ThirdInterface sourceEntity,
ThirdInterface targetEntity
)
{
DataHelper.CheckEntityIsNull(targetEntity);
Verify(sourceEntity);
if (sourceEntity.DisplayName != targetEntity.DisplayName)
{
targetEntity.DisplayName = sourceEntity.DisplayName;
}
targetEntity.IsActive = sourceEntity.IsActive;
targetEntity.MedicalCenterId = sourceEntity.MedicalCenterId;
targetEntity.ParmValue = sourceEntity.ParmValue;
targetEntity.ThirdInterfaceType = sourceEntity.ThirdInterfaceType;
}
/// <summary>
/// 删除项目时,同步删除项目结果模板( item_result_template)、参考范围(reference_range)、结果匹配(item_result_match)、组合项目包含的项目(asbitem_detail),项目模板明细(ItemTemplateDetail)。
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task CheckAndDeleteAsync(Guid id)
{
await _thirdInterfaceRepository.DeleteAsync(id);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await EntityHelper.UpdateManySortAsync(_thirdInterfaceRepository, id, SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
{
await EntityHelper.UpdateSortManyAsync(_thirdInterfaceRepository, input);
}
private void Verify(ThirdInterface entity)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckStringIsNull(entity.DisplayName, "名称");
DataHelper.CheckStringIsNull(entity.ParmValue, "配置参数");
DataHelper.CheckCharIsYOrN(entity.IsActive, "是否启用");
if (entity.ThirdInterfaceType != ThirdInterfaceTypeFlag.LisRequest
&& entity.ThirdInterfaceType != ThirdInterfaceTypeFlag.ChargeRequest
&& entity.ThirdInterfaceType != ThirdInterfaceTypeFlag.ImportLisResult
&& entity.ThirdInterfaceType != ThirdInterfaceTypeFlag.ImportPacsResult)
{
throw new ArgumentException($"接口类型参数为:{entity.ThirdInterfaceType},是无效值");
}
}
}
}