导入代码修改

This commit is contained in:
he
2024-09-24 14:14:49 +08:00
parent 721ab8dfd3
commit b097ca1db3
6 changed files with 75 additions and 5 deletions
@@ -2,7 +2,10 @@
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infra.EFCore.Common;
using MassTransit;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using MiniExcelLibs;
using System.Data;
using System.Text;
namespace IRaCIS.Core.Application.Service.ReadingCalculate
@@ -46,6 +49,41 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository;
}
/// <summary>
/// 从上传文件中获取Datatable
/// </summary>
/// <returns></returns>
public async Task<DataTable> GetDataTableFromUpload(IFormFile file)
{
DataTable result = new DataTable();
var fileFolder = "Upload\\";
if (!Directory.Exists(fileFolder))
{
Directory.CreateDirectory(fileFolder);
}
var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") +
Path.GetExtension(file.FileName);
var filePath = Path.Combine(fileFolder, fileName);
try
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
file.CopyTo(stream);
stream.Position = 0;
result = stream.QueryAsDataTable(useHeaderRow: false);
}
}
catch (Exception)
{
File.Delete(filePath);
}
File.Delete(filePath);
return result;
}
/// <summary>
/// 添加计算错误日志
/// </summary>
@@ -2,7 +2,10 @@
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using System.Data;
namespace IRaCIS.Core.Application.Service.ReadingCalculate
{
@@ -45,6 +48,8 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrialRepository;
}
/// <summary>
/// 获取Service
/// </summary>