120 lines
4.8 KiB
C#
120 lines
4.8 KiB
C#
|
|
//--------------------------------------------------------------------
|
|
// 此代码由liquid模板自动生成 byzhouhang 20240909
|
|
// 生成时间 2025-02-21 07:47:30Z
|
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
|
//--------------------------------------------------------------------
|
|
using IRaCIS.Core.Domain.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using IRaCIS.Core.Application.Interfaces;
|
|
using IRaCIS.Core.Application.ViewModel;
|
|
using IRaCIS.Core.Infrastructure.Extention;
|
|
using System.Threading.Tasks;
|
|
using IRaCIS.Core.Infra.EFCore;
|
|
using IRaCIS.Core.Infrastructure;
|
|
namespace IRaCIS.Core.Application.Service;
|
|
|
|
/// <summary>
|
|
/// 项目定稿记录
|
|
/// </summary>
|
|
/// <param name="_trialFinalRecordRepository"></param>
|
|
/// <param name="_mapper"></param>
|
|
/// <param name="_userInfo"></param>
|
|
/// <param name="_localizer"></param>
|
|
[ApiExplorerSettings(GroupName = "FileRecord")]
|
|
public class TrialFinalRecordService(IRepository<TrialFinalRecord> _trialFinalRecordRepository,
|
|
IRepository<TrialFile> _trialFileRepository,
|
|
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, ITrialFinalRecordService
|
|
{
|
|
|
|
|
|
[HttpPost]
|
|
public async Task<PageOutput<TrialFinalRecordView>> GetTrialFinalRecordList(TrialFinalRecordQuery inDto)
|
|
{
|
|
|
|
var trialFinalRecordQueryable = _trialFinalRecordRepository
|
|
.Where(x=>x.TrialFileTypeId==inDto.TrialFileTypeId)
|
|
.WhereIf(inDto.Name.IsNotNullOrEmpty(),x=>x.Name.Contains(inDto.Name))
|
|
.WhereIf(inDto.Version.IsNotNullOrEmpty(), x => x.Version.Contains(inDto.Version))
|
|
.WhereIf(inDto.IsAuthorizedView!=null, x => x.IsAuthorizedView==inDto.IsAuthorizedView)
|
|
// .Include(x=>x.PDFFileRecord).Include(x => x.WordFileRecord).Include(x => x.SignFileRecord).Include(x => x.HistoryFileRecord)
|
|
.ProjectTo<TrialFinalRecordView>(_mapper.ConfigurationProvider);
|
|
|
|
var pageList = await trialFinalRecordQueryable.ToPagedListAsync(inDto);
|
|
|
|
return pageList;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增或者修改文档
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
public async Task<IResponseOutput> AddOrUpdateTrialFinalRecord(TrialFinalRecordAddOrEdit inDto)
|
|
{
|
|
// 在此处拷贝automapper 映射
|
|
if (inDto.PDFFileRecord != null) inDto.PDFFileRecord.TrialFileTypeId = inDto.TrialFileTypeId;
|
|
if (inDto.WordFileRecord != null) inDto.WordFileRecord.TrialFileTypeId = inDto.TrialFileTypeId;
|
|
if (inDto.SignFileRecord != null) inDto.SignFileRecord.TrialFileTypeId = inDto.TrialFileTypeId;
|
|
if (inDto.HistoryFileRecord != null) inDto.HistoryFileRecord.TrialFileTypeId = inDto.TrialFileTypeId;
|
|
|
|
|
|
if (await _trialFinalRecordRepository.AnyAsync(x => x.Id != inDto.Id && x.TrialFileTypeId == inDto.TrialFileTypeId && x.Name == inDto.Name && x.Version == inDto.Version))
|
|
{
|
|
throw new BusinessValidationFailedException(_localizer["TrialFinalRecord_NameRepeat"]);
|
|
}
|
|
|
|
if (inDto.Id != null)
|
|
{
|
|
var trialFinalRecord = await _trialFinalRecordRepository.Where(x => x.Id == inDto.Id.Value).FirstNotNullAsync();
|
|
|
|
List<Guid?> ids= new List<Guid?>() {
|
|
trialFinalRecord.WordFileRecordId,
|
|
trialFinalRecord.PDFFileRecordId,
|
|
trialFinalRecord.SignFileRecordId,
|
|
trialFinalRecord.HistoryFileRecordId
|
|
|
|
};
|
|
|
|
var fileIds = ids.Where(x => x != null).Select(x => (Guid)x).ToList();
|
|
await _trialFileRepository.BatchDeleteNoTrackingAsync(x => fileIds.Contains(x.Id));
|
|
}
|
|
var entity = await _trialFinalRecordRepository.InsertOrUpdateAsync(inDto, true);
|
|
|
|
|
|
|
|
|
|
return ResponseOutput.Ok(entity.Id.ToString());
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 授权文档
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
public async Task<IResponseOutput> AuthorizedTrialFinalRecord(AuthorizedTrialFinalRecordInDto inDto)
|
|
{
|
|
await _trialFinalRecordRepository.UpdatePartialFromQueryAsync(t =>inDto.Ids.Contains(t.Id), t => new TrialFinalRecord() { IsAuthorizedView = inDto.IsAuthorizedView });
|
|
await _trialFinalRecordRepository.SaveChangesAsync();
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除文档
|
|
/// </summary>
|
|
/// <param name="trialFinalRecordId"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{trialFinalRecordId:guid}")]
|
|
public async Task<IResponseOutput> DeleteTrialFinalRecord(Guid trialFinalRecordId)
|
|
{
|
|
var success = await _trialFinalRecordRepository.DeleteFromQueryAsync(t => t.Id == trialFinalRecordId, true);
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|