156 lines
8.8 KiB
C#
156 lines
8.8 KiB
C#
using AutoMapper;
|
|
using IRaCIS.Application.ExpressionExtend;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using IRaCIS.Infra.Data.ExpressionExtend;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using IRaCIS.Core.Domain.Interfaces;
|
|
using IRaCIS.Core.Domain.Models;
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
public class TrialRevenuesPriceService : ITrialRevenuesPriceService
|
|
{
|
|
private readonly ITrialRepository _trialRepository;
|
|
private readonly ITrialRevenuesPriceRepository _trialRevenuesPriceRepository;
|
|
private readonly ICRORepository _croRepository;
|
|
private readonly IDictionaryRepository _dictionaryRepository;
|
|
private readonly ITrialRevenuesPriceVerificationRepository _trialRevenuesPriceVerificationRepository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public TrialRevenuesPriceService(ITrialRepository trialRepository, ITrialRevenuesPriceRepository trialCostRepository, ICRORepository croCompanyRepository, IDictionaryRepository dictionaryRepository, ITrialRevenuesPriceVerificationRepository trialRevenuesPriceVerificationRepository, IMapper mapper)
|
|
{
|
|
_trialRepository = trialRepository;
|
|
_trialRevenuesPriceRepository = trialCostRepository;
|
|
_croRepository = croCompanyRepository;
|
|
_dictionaryRepository = dictionaryRepository;
|
|
_trialRevenuesPriceVerificationRepository = trialRevenuesPriceVerificationRepository;
|
|
_mapper = mapper;
|
|
}
|
|
public IResponseOutput AddOrUpdateTrialRevenuesPrice(TrialRevenuesPriceDTO model)
|
|
{
|
|
var count = model.Timepoint +
|
|
model.TimepointIn24H +
|
|
model.TimepointIn48H +
|
|
model.Adjudication +
|
|
model.AdjudicationIn24H +
|
|
model.AdjudicationIn48H +
|
|
model.Downtime +
|
|
model.Global +
|
|
model.Training;
|
|
|
|
if (count <= 0)
|
|
{
|
|
return ResponseOutput.NotOk("Please add meaningful data");
|
|
}
|
|
var trialExistedItem = _trialRevenuesPriceRepository.FindSingleOrDefault(u => u.TrialId == model.TrialId);
|
|
if (trialExistedItem == null)//insert
|
|
{
|
|
var trialCost = _mapper.Map<TrialRevenuesPrice>(model);
|
|
_trialRevenuesPriceRepository.Add(trialCost);
|
|
var success = _trialRevenuesPriceRepository.SaveChanges();
|
|
return ResponseOutput.Result(success, trialCost.Id.ToString());
|
|
}
|
|
else//update
|
|
{
|
|
var trialRevenuesPrice = _trialRevenuesPriceRepository.GetAll()
|
|
.FirstOrDefault(u => u.TrialId == model.TrialId);
|
|
|
|
_trialRevenuesPriceRepository.Update(_mapper.Map(model, trialRevenuesPrice));
|
|
|
|
// 完善价格的 将对应的列设置为true 变更为有价格了
|
|
|
|
var aaa = _trialRevenuesPriceVerificationRepository.Update(t => t.TrialId == model.TrialId, u => new TrialRevenuesPriceVerification()
|
|
{
|
|
//有价格 则设置为true 否则 该列不变
|
|
Timepoint = model.Timepoint > 0 || u.Timepoint,
|
|
TimepointIn24H = model.TimepointIn24H > 0 || u.TimepointIn24H,
|
|
TimepointIn48H = model.TimepointIn48H > 0 || u.TimepointIn48H,
|
|
Adjudication = model.Adjudication > 0 || u.Adjudication,
|
|
AdjudicationIn24H =
|
|
model.AdjudicationIn24H > 0 || u.AdjudicationIn24H,
|
|
AdjudicationIn48H =
|
|
model.AdjudicationIn48H > 0 || u.AdjudicationIn48H,
|
|
Global = model.Global > 0 || u.Global,
|
|
Downtime = model.Downtime > 0 || u.Downtime,
|
|
Training = model.Training > 0 || u.Training,
|
|
RefresherTraining = model.RefresherTraining > 0 || u.RefresherTraining,
|
|
});
|
|
|
|
//删除所有有价格的记录 为true 表示有价格或者不需要价格 缺价格的为false
|
|
_trialRevenuesPriceVerificationRepository.Delete(t => t.TrialId == model.TrialId &&
|
|
t.Timepoint&&
|
|
t.TimepointIn24H&&
|
|
t.TimepointIn48H &&
|
|
t.Adjudication &&
|
|
t.AdjudicationIn24H &&
|
|
t.AdjudicationIn48H &&
|
|
t.Global &&
|
|
t.Training &&t.RefresherTraining);
|
|
|
|
|
|
|
|
var success = _trialRevenuesPriceRepository.SaveChanges();
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
}
|
|
|
|
public bool DeleteTrialCost(Guid id)
|
|
{
|
|
return _trialRevenuesPriceRepository.Delete(u => u.Id == id);
|
|
}
|
|
|
|
public PageOutput<TrialRevenuesPriceDetialDTO> GetTrialRevenuesPriceList(TrialRevenuesPriceQueryDTO queryParam)
|
|
{
|
|
Expression<Func<Trial, bool>> trialLambda = x => true;
|
|
if (queryParam.CroId != Guid.Empty && queryParam.CroId != null)
|
|
{
|
|
trialLambda = trialLambda.And(o => o.CROId == queryParam.CroId);
|
|
}
|
|
var trialQueryable = from trial in _trialRepository.Find(u => u.Code.Contains(queryParam.KeyWord)
|
|
|| u.Indication.Contains(queryParam.KeyWord)).Where(trialLambda)
|
|
join cro in _croRepository.GetAll() on trial.CROId equals cro.Id into CRO
|
|
from croInfo in CRO.DefaultIfEmpty()
|
|
join dic in _dictionaryRepository.GetAll() on trial.ReviewModeId equals dic.Id into dict
|
|
from dic in dict.DefaultIfEmpty()
|
|
join trialCost in _trialRevenuesPriceRepository.GetAll()
|
|
on trial.Id equals trialCost.TrialId into trialInfo
|
|
from trialCostItem in trialInfo.DefaultIfEmpty()
|
|
select new TrialRevenuesPriceDetialDTO
|
|
{
|
|
Id = trialCostItem == null ? Guid.Empty : trialCostItem.Id,
|
|
TrialId = trial.Id,
|
|
TrialCode = trial.Code,
|
|
Indication = trial.Indication,
|
|
Cro = croInfo == null ? string.Empty : croInfo.CROName,
|
|
ReviewMode = dic == null ? string.Empty : dic.Value,
|
|
Timepoint = trialCostItem == null ? 0 : trialCostItem.Timepoint,
|
|
TimepointIn24H = trialCostItem == null ? 0 : trialCostItem.TimepointIn24H,
|
|
TimepointIn48H = trialCostItem == null ? 0 : trialCostItem.TimepointIn48H,
|
|
Adjudication = trialCostItem == null ? 0 : trialCostItem.Adjudication,
|
|
AdjudicationIn24H = trialCostItem == null ? 0 : trialCostItem.AdjudicationIn24H,
|
|
AdjudicationIn48H = trialCostItem == null ? 0 : trialCostItem.AdjudicationIn48H,
|
|
Downtime = trialCostItem == null ? 0 : trialCostItem.Downtime,
|
|
Global = trialCostItem == null ? 0 : trialCostItem.Global,
|
|
Training = trialCostItem == null ? 0 : trialCostItem.Training,
|
|
RefresherTraining= trialCostItem == null ? 0 : trialCostItem.RefresherTraining,
|
|
Expedited = trial.Expedited
|
|
|
|
};
|
|
var count = trialQueryable.Count();
|
|
var propName = string.IsNullOrWhiteSpace(queryParam.SortField) ? "TrialCode" : queryParam.SortField;
|
|
trialQueryable = queryParam.Asc ? trialQueryable.OrderBy(propName) : trialQueryable.OrderByDescending(propName);
|
|
trialQueryable = trialQueryable.Skip((queryParam.PageIndex - 1) * queryParam.PageSize)
|
|
.Take(queryParam.PageSize);
|
|
|
|
var trialList = trialQueryable.ToList();
|
|
return new PageOutput<TrialRevenuesPriceDetialDTO>(queryParam.PageIndex, queryParam.PageSize, count, trialList);
|
|
}
|
|
|
|
|
|
}
|
|
}
|