139 lines
4.9 KiB
C#
139 lines
4.9 KiB
C#
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using IRaCIS.Application.ExpressionExtend;
|
|
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.Linq;
|
|
using System.Linq.Dynamic.Core;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace IRaCIS.Application.Services.Pay
|
|
{
|
|
public class TrialPaymentPriceService : ITrialPaymentPriceService
|
|
{
|
|
private readonly ITrialPaymentPriceRepository _trialExtRepository;
|
|
private readonly ICRORepository _croRepository;
|
|
private readonly IMapper _mapper;
|
|
private readonly ITrialRepository _trialRepository;
|
|
public TrialPaymentPriceService(ITrialRepository trialRepository, ITrialPaymentPriceRepository trialExtRepository,
|
|
ICRORepository croCompanyRepository, IMapper mapper)
|
|
{
|
|
_trialExtRepository = trialExtRepository;
|
|
_croRepository = croCompanyRepository;
|
|
_mapper = mapper;
|
|
_trialRepository = trialRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或更新项目支付价格信息
|
|
/// </summary>
|
|
public IResponseOutput AddOrUpdateTrialPaymentPrice(TrialPaymentPriceCommand addOrUpdateModel, Guid userId)
|
|
{
|
|
|
|
var trialExistedItem = _trialExtRepository.FindSingleOrDefault(u => u.TrialId == addOrUpdateModel.TrialId);
|
|
if (trialExistedItem == null)//insert
|
|
{
|
|
var trialExt = _mapper.Map<TrialPaymentPrice>(addOrUpdateModel);
|
|
|
|
_trialExtRepository.Add(trialExt);
|
|
|
|
}
|
|
else//update
|
|
{
|
|
_trialExtRepository.Update(_mapper.Map(addOrUpdateModel, trialExistedItem));
|
|
|
|
}
|
|
var success = _trialExtRepository.SaveChanges();
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
public IResponseOutput UploadTrialSOW(Guid userId, TrialSOWPathDTO trialSowPath)
|
|
{
|
|
var trialPaymentPrice= _trialExtRepository.GetAll().FirstOrDefault(u => u.TrialId == trialSowPath.TrialId);
|
|
|
|
if (trialPaymentPrice == null)//添加
|
|
{
|
|
_trialExtRepository.Add(_mapper.Map<TrialPaymentPrice>(trialSowPath));
|
|
}
|
|
else//更新
|
|
{
|
|
_trialExtRepository.Update(_mapper.Map(trialSowPath, trialPaymentPrice));
|
|
}
|
|
|
|
var success = _trialExtRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
public IResponseOutput DeleteTrialSOW(Guid userId, DeleteSowPathDTO trialSowPath)
|
|
{
|
|
var success = _trialExtRepository.Update(u => u.TrialId == trialSowPath.TrialId, s => new TrialPaymentPrice
|
|
{
|
|
SowPath = "",
|
|
SowName = "",
|
|
UpdateTime = DateTime.Now,
|
|
UpdateUserId = userId
|
|
});
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取项目支付价格信息列表
|
|
/// </summary>
|
|
public PageOutput<TrialPaymentPriceDTO> GetTrialPaymentPriceList(TrialPaymentPriceQueryDTO queryParam)
|
|
{
|
|
var trialQueryable2 = _trialExtRepository.GetAll();
|
|
|
|
if (queryParam.CroId != null)
|
|
{
|
|
trialQueryable2 = trialQueryable2.Where(o => o.Trial.CROId == queryParam.CroId);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(queryParam.KeyWord))
|
|
{
|
|
trialQueryable2 = trialQueryable2.Where(o => o.Trial.Indication.Contains(queryParam.KeyWord));
|
|
}
|
|
|
|
var data= trialQueryable2.ProjectTo<TrialPaymentPriceDTO>(_mapper.ConfigurationProvider);
|
|
|
|
// .ForMember(t => t.DoctorsNames, u => u.MapFrom(t => string.Join(",", t.Trial.EnrollList.Select(x => x.Doctor.ChineseName))));
|
|
var trialinfo = this._trialRepository.GetAll().Select(x => new
|
|
{
|
|
TrialId = x.Id,
|
|
Names = x.EnrollList.Select(y => y.Doctor).Select(x=>x.ChineseName).ToList()
|
|
|
|
}).ToList();
|
|
|
|
|
|
var propName = string.IsNullOrWhiteSpace(queryParam.SortField) ? "SowName" : queryParam.SortField;
|
|
data = queryParam.Asc ? data.OrderBy(propName) : data.OrderByDescending(propName);
|
|
|
|
|
|
|
|
|
|
var list = data.Skip((queryParam.PageIndex - 1) * queryParam.PageSize).Take(queryParam.PageSize).ToList();
|
|
list.ForEach(x => {
|
|
x.DoctorsNames = string.Join(",", trialinfo.Where(y => y.TrialId == x.TrialId).SelectMany(y => y.Names).ToList());
|
|
});
|
|
|
|
return new PageOutput<TrialPaymentPriceDTO>(queryParam.PageIndex,
|
|
queryParam.PageSize, data.Count(),
|
|
list
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|