431 lines
12 KiB
C#
431 lines
12 KiB
C#
|
|
//--------------------------------------------------------------------
|
|
// 此代码由liquid模板自动生成 byzhouhang 20240909
|
|
// 生成时间 2025-03-27 06:13:33Z
|
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
|
//--------------------------------------------------------------------
|
|
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 AutoMapper.Execution;
|
|
using System.Linq;
|
|
using IRaCIS.Core.Infrastructure;
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
using MassTransit;
|
|
using NPOI.POIFS.Properties;
|
|
using Org.BouncyCastle.Crypto;
|
|
namespace IRaCIS.Core.Application.Service;
|
|
|
|
|
|
[ ApiExplorerSettings(GroupName = "FileRecord")]
|
|
public class AuditDocumentService(IRepository<AuditDocument> _auditDocumentRepository,
|
|
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService
|
|
{
|
|
|
|
/// <summary>
|
|
/// 获取稽查文档
|
|
/// </summary>
|
|
/// <param name="inQuery"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<PageOutput<AuditDocumentView>> GetAuditDocumentList(AuditDocumentQuery inQuery)
|
|
{
|
|
var auditDocumentQueryable =_auditDocumentRepository
|
|
.ProjectTo<AuditDocumentView>(_mapper.ConfigurationProvider);
|
|
var pageList= await auditDocumentQueryable.ToPagedListAsync(inQuery);
|
|
|
|
return pageList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改稽查文档
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> UpdateAuditDocument(AuditDocumentUpdateDto inDto)
|
|
{
|
|
AuditDocumentAddOrEdit addOrEdit = _mapper.Map<AuditDocumentAddOrEdit>(inDto);
|
|
addOrEdit.IsUpdate = true;
|
|
|
|
var result= await AddOrUpdateAuditDocument(addOrEdit);
|
|
|
|
return ResponseOutput.Ok(result.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增稽查文档
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> AddAuditDocument(List<AuditDocumentAddOrEdit> inDto)
|
|
{
|
|
inDto.ForEach(x => x.IsUpdate = false);
|
|
await addData(inDto);
|
|
|
|
async Task addData(List<AuditDocumentAddOrEdit> data)
|
|
{
|
|
foreach(var item in data)
|
|
{
|
|
var result= await AddOrUpdateAuditDocument(item);
|
|
|
|
item.Children.ForEach(x => {
|
|
x.ParentId = result.Id;
|
|
x.IsUpdate = false;
|
|
|
|
});
|
|
|
|
if (item.Children.Count() > 0)
|
|
{
|
|
await addData(item.Children);
|
|
}
|
|
}
|
|
}
|
|
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 通用方法
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
private async Task<AuditDocument> AddOrUpdateAuditDocument(AuditDocumentAddOrEdit inDto)
|
|
{
|
|
if (inDto.ParentId != null)
|
|
{
|
|
var alikeData = await _auditDocumentRepository.Where(x => x.ParentId == inDto.ParentId&&x.Name==inDto.Name&&x.AuditDocumentTypeEnum==inDto.AuditDocumentTypeEnum).FirstOrDefaultAsync();
|
|
if (alikeData != null)
|
|
{
|
|
if (inDto.AuditDocumentTypeEnum == AuditDocumentType.Folder)
|
|
{
|
|
if (inDto.IsUpdate)
|
|
{
|
|
throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotAddFolder"]);
|
|
}
|
|
else
|
|
{
|
|
return alikeData;
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var entityData = await _auditDocumentRepository.InsertOrUpdateAsync(inDto, true);
|
|
|
|
var historicalVersionIds = await _auditDocumentRepository.Where(x => x.MainFileId == alikeData.Id).OrderBy(x => x.Version).Select(x => x.Id).ToListAsync();
|
|
|
|
historicalVersionIds.Add(alikeData.Id);
|
|
|
|
int num = 1;
|
|
foreach (var item in historicalVersionIds)
|
|
{
|
|
await _auditDocumentRepository.UpdatePartialFromQueryAsync(item, x => new AuditDocument()
|
|
{
|
|
MainFileId = entityData.Id,
|
|
ParentId = null,
|
|
Version = num,
|
|
AuditDocumentTypeEnum = AuditDocumentType.HistoricalVersion
|
|
});
|
|
}
|
|
|
|
return entityData;
|
|
}
|
|
}
|
|
}
|
|
|
|
var entity = await _auditDocumentRepository.InsertOrUpdateAsync(inDto, true);
|
|
return entity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取面包屑导航
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> GetBreadcrumbData(GetBreadcrumbDataInDto inDto)
|
|
{
|
|
List<string> result=new List<string>();
|
|
|
|
await findParent(result, inDto.Id);
|
|
async Task findParent(List<string> datas, Guid id)
|
|
{
|
|
var data= await _auditDocumentRepository.Where(x => x.Id == inDto.Id).FirstNotNullAsync();
|
|
datas.Add(data.Name);
|
|
if (data.ParentId != null)
|
|
{
|
|
await findParent(datas, data.ParentId.Value);
|
|
}
|
|
|
|
}
|
|
|
|
result.Reverse();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
///// 新增稽查文档
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//public async Task<IResponseOutput> InsertAuditDocument()
|
|
//{
|
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取文件树形结构 (传Id 根节点就是自己)
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<GetAuditDocumentDataOutDto> GetAuditDocumentData(GetAuditDocumentDataInDto inDto)
|
|
{
|
|
var data= await _auditDocumentRepository
|
|
.Where(x=>x.AuditDocumentTypeEnum!=AuditDocumentType.HistoricalVersion)
|
|
.WhereIf(inDto.IsAuthorization!=null,x=>x.IsAuthorization==inDto.IsAuthorization).ProjectTo<AuditDocumentData>(_mapper.ConfigurationProvider).ToListAsync();
|
|
var root= data
|
|
.WhereIf(inDto.Ids != null, x => inDto.Ids.Contains(x.Id.Value))
|
|
.WhereIf(inDto.Ids == null,x=>x.ParentId==null).ToList();
|
|
|
|
foreach (var item in root)
|
|
{
|
|
GetChildren(item, data);
|
|
|
|
}
|
|
|
|
return new GetAuditDocumentDataOutDto()
|
|
{
|
|
Data = root
|
|
};
|
|
|
|
}
|
|
|
|
private void GetChildren(AuditDocumentData item, List<AuditDocumentData> dataList)
|
|
{
|
|
item.Children = dataList.Where(x => x.ParentId == item.Id).ToList();
|
|
foreach (var x in item.Children)
|
|
{
|
|
GetChildren(x, dataList);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除稽查文档
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> DeleteAuditDocument(DeleteAuditDocumentInDto inDto)
|
|
{
|
|
var data = await _auditDocumentRepository.Select(x => new DeleteAudit (){
|
|
Id=x.Id,
|
|
ParentId= x.ParentId,
|
|
MainFileId= x.MainFileId
|
|
}).ToListAsync();
|
|
|
|
List<Guid> DeleteId= inDto.Ids;
|
|
|
|
finId(inDto.Ids, data);
|
|
|
|
void finId(List<Guid> deletids, List<DeleteAudit> deletes)
|
|
{
|
|
DeleteId.AddRange(deletids);
|
|
|
|
var temp = deletes.Where(x => deletids.Contains(x.ParentId.Value)|| deletids.Contains(x.MainFileId.Value)).Select(x => x.Id).ToList();
|
|
if (temp.Count() > 0)
|
|
{
|
|
finId(temp, deletes);
|
|
}
|
|
}
|
|
|
|
var success = await _auditDocumentRepository.DeleteFromQueryAsync(t => DeleteId.Contains(t.Id), true);
|
|
return ResponseOutput.Ok();
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移动文件或者文件夹 到其他文件夹
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> MovieFileOrFolder(MovieFileOrFolderInDto inDto)
|
|
{
|
|
|
|
var data = await _auditDocumentRepository.Select(x => new DeleteAudit()
|
|
{
|
|
Id = x.Id,
|
|
ParentId = x.ParentId,
|
|
AuditDocumentTypeEnum = x.AuditDocumentTypeEnum,
|
|
MainFileId = x.MainFileId
|
|
}).ToListAsync();
|
|
|
|
foreach (var id in inDto.Ids)
|
|
{
|
|
var file = data.Where(x => x.Id == id).FirstOrDefault();
|
|
if (file.AuditDocumentTypeEnum == AuditDocumentType.Folder)
|
|
{
|
|
|
|
|
|
if (finChild(new List<Guid> { id }, inDto.ParentId, data))
|
|
{
|
|
throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
bool finChild(List<Guid> ids, Guid ChildId, List<DeleteAudit> data)
|
|
{
|
|
var child = data.Where(x => x.ParentId != null && ids.Contains(x.ParentId.Value)).ToList();
|
|
if (child.Count() == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else if (child.Any(x => x.Id == ChildId))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
var newids = child.Select(x => x.Id).ToList();
|
|
|
|
return finChild(newids, ChildId, data);
|
|
|
|
}
|
|
}
|
|
|
|
foreach (var id in inDto.Ids)
|
|
{
|
|
|
|
|
|
|
|
|
|
await _auditDocumentRepository.UpdatePartialFromQueryAsync(id, x => new AuditDocument()
|
|
{
|
|
ParentId = inDto.ParentId
|
|
});
|
|
|
|
await _auditDocumentRepository.SaveChangesAsync();
|
|
}
|
|
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取历史版本
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<GetHistoricalVersionOutDto> GetHistoricalVersion(GetHistoricalVersionInDto inDto)
|
|
{
|
|
return new GetHistoricalVersionOutDto()
|
|
{
|
|
|
|
CurrentData = await _auditDocumentRepository.Where(x => x.Id == inDto.Id).ProjectTo<AuditDocumentData>(_mapper.ConfigurationProvider).FirstNotNullAsync(),
|
|
HistoricalVersionList = await _auditDocumentRepository.Where(x => x.MainFileId == inDto.Id).ProjectTo<AuditDocumentData>(_mapper.ConfigurationProvider).OrderByDescending(x => x.Version).ToListAsync()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 把历史版本设置为当前版本
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> SetCurrentVersion(SetCurrentVersionInDto inDto)
|
|
{
|
|
var file = await _auditDocumentRepository.Where(x => x.Id == inDto.Id).FirstNotNullAsync();
|
|
if (file.AuditDocumentTypeEnum != AuditDocumentType.HistoricalVersion)
|
|
{
|
|
throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotSetCurrentVersion"]);
|
|
}
|
|
|
|
var mainFile = await _auditDocumentRepository.Where(x => x.Id == file.MainFileId).FirstNotNullAsync();
|
|
|
|
var historicalVersionIds= await _auditDocumentRepository.Where(x => x.MainFileId == mainFile.Id&&x.Id!=inDto.Id).OrderBy(x=>x.Version).Select(x=>x.Id).ToListAsync();
|
|
|
|
historicalVersionIds.Add(mainFile.Id);
|
|
await _auditDocumentRepository.UpdatePartialFromQueryAsync(inDto.Id, x => new AuditDocument() {
|
|
MainFileId=null,
|
|
ParentId= mainFile.ParentId,
|
|
AuditDocumentTypeEnum=AuditDocumentType.File,
|
|
});
|
|
|
|
int num = 1;
|
|
foreach (var item in historicalVersionIds)
|
|
{
|
|
await _auditDocumentRepository.UpdatePartialFromQueryAsync(item, x => new AuditDocument()
|
|
{
|
|
MainFileId = inDto.Id,
|
|
ParentId = null,
|
|
Version=num,
|
|
AuditDocumentTypeEnum= AuditDocumentType.HistoricalVersion
|
|
});
|
|
}
|
|
|
|
await _auditDocumentRepository.SaveChangesAsync();
|
|
|
|
|
|
return ResponseOutput.Ok();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置是否授权
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IResponseOutput> SetIsAuthorization(SetIsAuthorizationInDto inDto)
|
|
{
|
|
var data = await _auditDocumentRepository.Select(x => new DeleteAudit()
|
|
{
|
|
Id = x.Id,
|
|
ParentId = x.ParentId,
|
|
MainFileId = x.MainFileId
|
|
}).ToListAsync();
|
|
|
|
List<Guid> allid = new List<Guid>();
|
|
findChild(allid, inDto.Ids, data);
|
|
|
|
await _auditDocumentRepository.UpdatePartialFromQueryAsync(t => allid.Contains(t.Id), x => new AuditDocument() {
|
|
|
|
IsAuthorization = inDto.IsAuthorization
|
|
});
|
|
await _auditDocumentRepository.SaveChangesAsync();
|
|
return ResponseOutput.Ok();
|
|
|
|
void findChild(List<Guid> allId,List<Guid> current, List<DeleteAudit> data)
|
|
{
|
|
allId.AddRange(current);
|
|
|
|
var child = data.Where(x =>(x.ParentId!=null&& current.Contains(x.ParentId.Value))||(x.MainFileId!=null&¤t.Contains(x.MainFileId.Value))).Select(x => x.Id).ToList();
|
|
if (child.Count() > 0)
|
|
{
|
|
|
|
|
|
findChild(allId, child, data);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|