145 lines
6.4 KiB
C#
145 lines
6.4 KiB
C#
using AutoMapper;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using IRaCIS.Core.Domain.Interfaces;
|
|
using IRaCIS.Core.Domain.Models;
|
|
using IRaCIS.Infra.Data.ExpressionExtend;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
public class TrialAttachmentService : ITrialAttachmentService
|
|
{
|
|
private readonly IAcquisitionSpecificationRepository _specificationRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly ITrialRepository _trialRepository;
|
|
private readonly IDictionaryRepository _dictionaryRepository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public TrialAttachmentService(IAcquisitionSpecificationRepository specificationRepository,
|
|
IUserRepository userRepository, ITrialRepository trialRepository, IDictionaryRepository dictionaryRepository,IMapper mapper)
|
|
{
|
|
_specificationRepository = specificationRepository;
|
|
_userRepository = userRepository;
|
|
_trialRepository = trialRepository;
|
|
_dictionaryRepository = dictionaryRepository;
|
|
_mapper = mapper;
|
|
}
|
|
public IResponseOutput AddOrUpdateSpecification(TrialAttachmentCommand model, Guid userId)
|
|
{
|
|
var temp = _mapper.Map<TrialAttachment>(model);
|
|
if (model.Id == Guid.Empty|| model.Id ==null) //insert
|
|
{
|
|
var returnItem = _specificationRepository.Add(temp);
|
|
var isSuccess = _specificationRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(isSuccess, temp.Id.ToString());
|
|
|
|
}
|
|
else
|
|
{
|
|
var specification= _specificationRepository.GetAll().FirstOrDefault(t => t.Id == model.Id);
|
|
|
|
_mapper.Map(model, specification);
|
|
|
|
_specificationRepository.Update(specification);
|
|
|
|
var isSuccess = _specificationRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(isSuccess);
|
|
|
|
}
|
|
}
|
|
|
|
public IResponseOutput DeleteSpecification(Guid id)
|
|
{
|
|
var result = _specificationRepository.Delete(u => u.Id == id);
|
|
|
|
return ResponseOutput.Result(result);
|
|
|
|
}
|
|
|
|
public IEnumerable<AcquisitionSpecificationDTO> GetSpecificationList(Guid trialId, string type)
|
|
{
|
|
Expression < Func<TrialAttachment, bool> > trialAttachmentLambda = x => x.TrialId==trialId;
|
|
|
|
if (!string.IsNullOrEmpty(type))
|
|
{
|
|
var attachmentType = type.Trim();
|
|
trialAttachmentLambda = trialAttachmentLambda.And(x => x.Type == attachmentType);
|
|
}
|
|
|
|
var query = from specification in _specificationRepository.Find(trialAttachmentLambda)
|
|
join user in _userRepository.GetAll() on specification.UpdateUserId equals user.Id into h
|
|
from userItem in h.DefaultIfEmpty()
|
|
join trial in _trialRepository.Find(u => u.Id == trialId) on specification.TrialId equals trial.Id into g
|
|
from trialItem in g.DefaultIfEmpty()
|
|
|
|
select new AcquisitionSpecificationDTO()
|
|
{
|
|
Id = specification.Id,
|
|
TrialId = trialItem.Id,
|
|
TrialCode = trialItem.Code,
|
|
Indication = trialItem.Indication,
|
|
OptUserName = userItem.RealName,
|
|
Type = specification.Type,
|
|
|
|
DocumentName = specification.DocumentName,
|
|
DocumentPath = specification.DocumentPath,
|
|
CreateTime = specification.CreateTime
|
|
};
|
|
|
|
return query.ToList();
|
|
}
|
|
|
|
//public PageOutput<AcquisitionSpecificationDTO> GetSpecificationList(ImageAcquisitionSpecificationQueryDTO param)
|
|
//{
|
|
|
|
// var query = from specification in _specificationRepository.Find(u => u.TrialId == param.TrialId)
|
|
// join user in _userRepository.GetAll() on specification.UpdateUserId equals user.Id into h
|
|
// from userItem in h.DefaultIfEmpty()
|
|
// join trial in _trialRepository.Find(u => u.Id == param.TrialId) on specification.TrialId equals trial.Id into g
|
|
// from trialItem in g.DefaultIfEmpty()
|
|
// join dic in _dictionaryRepository.GetAll() on specification.DeviceTypeId equals dic.Id into e
|
|
// from dicItem in e.DefaultIfEmpty()
|
|
// select new AcquisitionSpecificationDTO()
|
|
// {
|
|
// Id = specification.Id,
|
|
// TrialId = trialItem.Id,
|
|
// TrialCode = trialItem.Code,
|
|
// Indication = trialItem.Indication,
|
|
// OptUserName = userItem.RealName,
|
|
// AcquisitionPeriod = specification.AcquisitionPeriod,
|
|
// DeviceParam = specification.DeviceParam,
|
|
// Type = specification.DeviceTypeId,
|
|
// DeviceTypeName = dicItem.Value,
|
|
// LayerThickness = specification.LayerThickness,
|
|
// SeriesCount = specification.SeriesCount,
|
|
// SeriesDescription = specification.SeriesDescription,
|
|
// DocumentCode = specification.DocumentCode,
|
|
// DocumentName = specification.DocumentName,
|
|
// DocumentPath = specification.DocumentPath,
|
|
// CreateTime = specification.CreateTime
|
|
// };
|
|
// var count = query.Count();
|
|
// var propName = param.SortField == string.Empty ? "CreateTime" : param.SortField;
|
|
|
|
// query = param.Asc
|
|
// ? query.OrderBy(propName)
|
|
// : query.OrderByDescending(propName);
|
|
|
|
// query = query.Skip((param.PageIndex - 1) * param.PageSize).Take(param.PageSize);
|
|
// var list = query.ToList();
|
|
|
|
// return new PageOutput<AcquisitionSpecificationDTO>(param.PageIndex,
|
|
// param.PageSize, count, list);
|
|
|
|
//}
|
|
}
|
|
}
|