using IRaCIS.Application.Contracts; using IRaCIS.Application.Interfaces; using Microsoft.AspNetCore.Mvc; using Panda.DynamicWebApi.Attributes; namespace IRaCIS.Core.Application.Service { [ApiExplorerSettings(GroupName = "Financial")] public class TrialRevenuesPriceService(IRepository _trialRepository, IRepository _trialRevenuesPriceRepository, IRepository _croRepository, IRepository _dictionaryRepository, IRepository _trialRevenuesPriceVerificationRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, ITrialRevenuesPriceService { public async Task 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) { //---Please add meaningful data return ResponseOutput.NotOk(_localizer["TRP_AddMeaningful"]); } var trialExistedItem = await _trialRevenuesPriceRepository.FirstOrDefaultAsync(u => u.TrialId == model.TrialId); if (trialExistedItem == null)//insert { var trialCost = _mapper.Map(model); await _trialRevenuesPriceRepository.AddAsync(trialCost); var success = await _trialRevenuesPriceRepository.SaveChangesAsync(); return ResponseOutput.Result(success, trialCost.Id.ToString()); } else//update { //var trialRevenuesPrice = (await _trialRevenuesPriceRepository.AsQueryable().FirstOrDefaultAsync(u => u.TrialId == model.TrialId)).IfNullThrowException(); await _trialRevenuesPriceRepository.UpdateFromDTOAsync(model); // 完善价格的 将对应的列设置为true 变更为有价格了 var aaa = await _trialRevenuesPriceVerificationRepository.BatchUpdateNoTrackingAsync(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 await _trialRevenuesPriceVerificationRepository.BatchDeleteNoTrackingAsync(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 = await _trialRevenuesPriceRepository.SaveChangesAsync(); return ResponseOutput.Result(success); } } [NonDynamicMethod] public async Task DeleteTrialCost(Guid id) { return await _trialRevenuesPriceRepository.BatchDeleteNoTrackingAsync(u => u.Id == id); } /// /// 获取项目收入费用信息列表[New] /// [HttpPost] public async Task> GetTrialRevenuesPriceList(TrialRevenuesPriceQueryDTO inQuery) { var trialQueryable = from trial in _trialRepository.AsQueryable() .Where(u => u.TrialCode.Contains(inQuery.KeyWord) || u.Indication.Contains(inQuery.KeyWord)) .WhereIf(inQuery.CroId != null, o => o.CROId == inQuery.CroId) join cro in _croRepository.AsQueryable() on trial.CROId equals cro.Id into CRO from croInfo in CRO.DefaultIfEmpty() join dic in _dictionaryRepository.AsQueryable() on trial.ReviewModeId equals dic.Id into dict from dic in dict.DefaultIfEmpty() join trialCost in _trialRevenuesPriceRepository.AsQueryable() 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.TrialCode, 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 }; return await trialQueryable.ToPagedListAsync(inQuery); } } }