Commit 873936cb by 799284587@qq.com

取消抽取数据上传下载TOKEN验证

parent b4cd4e2b
......@@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
......@@ -29,6 +30,8 @@ public class TemplateController : Controller
private Application application;
private WebapiUrl url;
private readonly AllotService allotService;
private readonly ILogger<ExceptionsFilter> logger;
public TemplateController(TemplateService templateService,
HospitalService hospitalService,
ExtractService extractService,
......@@ -36,7 +39,8 @@ public class TemplateController : Controller
ClaimService claim,
IOptions<Application> options,
IOptions<WebapiUrl> url,
AllotService allotService)
AllotService allotService,
ILogger<ExceptionsFilter> logger)
{
this.templateService = templateService;
this.extractService = extractService;
......@@ -46,6 +50,7 @@ public class TemplateController : Controller
this.application = options.Value;
this.url = url.Value;
this.allotService = allotService;
this.logger = logger;
}
/// <summary>
......@@ -166,6 +171,7 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBo
/// </summary>
/// <returns></returns>
[Route("down")]
[NoVerify]
public IActionResult DownFile([FromQuery]AllotRequest request)
{
var allot = allotService.GetAllot(request.ID);
......@@ -193,31 +199,39 @@ public IActionResult DownFile([FromQuery]AllotRequest request)
/// <returns></returns>
[Route("savefile")]
[HttpPost]
[NoVerify]
public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int hospitalId)
{
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
return new ApiResponse(ResponseType.Error, "上传文件无效");
logger.LogInformation($"保存提取文件 参数:allotId:{allotId} hospitalId:{hospitalId}");
try
{
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
return new ApiResponse(ResponseType.Error, "上传文件无效");
var dpath = Path.Combine(evn.ContentRootPath, "Files", $"{hospitalId}", "autoextract");
FileHelper.CreateDirectory(dpath);
var dpath = Path.Combine(evn.ContentRootPath, "Files", $"{hospitalId}", "autoextract");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName));
var path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName));
using (var stream = file.OpenReadStream())
using (var stream = file.OpenReadStream())
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Error, "保存失败");
}
var allot = allotService.GetAllot(allotId);
allot.ExtractPath = path;
allot.IsExtracting = 2;
if (!string.IsNullOrEmpty(path) && allotService.Update(allot))
return new ApiResponse(ResponseType.OK, "上传成功!");
}
catch (Exception ex)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Error, "保存失败");
logger.LogInformation($"保存提取文件异常{ex.ToString()}");
}
var allot = allotService.GetAllot(allotId);
allot.ExtractPath = path;
allot.IsExtracting = 2;
if (!string.IsNullOrEmpty(path) && allotService.Update(allot))
return new ApiResponse(ResponseType.OK, "上传成功!");
else
return new ApiResponse(ResponseType.Error);
return new ApiResponse(ResponseType.Error);
}
}
}
\ No newline at end of file
......@@ -105,7 +105,7 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital, strin
{
LogHelper.Information($"开始执行绩效数据提取任务{new { allotId, mail, hospital }}", "提取绩效数据");
List<PerSheet> sheetList = new List<PerSheet>();
string filepath = "";
try
{
var allotList = perforPerallotRepository.GetEntities(t => t.HospitalId == hospital.ID);
......@@ -157,7 +157,7 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital, strin
FileHelper.CreateDirectory(dpath);
string path = Path.Combine(dpath, $"绩效数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx");
//根据SHEET页信息,列头信息,创建EXCEL文件
if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospital.ID, allotList.First(t => t.ID == allotId), out string filepath))
if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospital.ID, allotList.First(t => t.ID == allotId), out filepath))
{
LogHelper.Information($"基础数据提取完成,文件保存成功{filepath}", "提取绩效数据");
//var allot = allotList.First(t => t.ID == allotId);
......@@ -166,36 +166,30 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital, strin
// perforPerallotRepository.Update(allot);
SendEmail(mail, filepath, $"{hospital.HosName}HIS数据提取成功", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。");
return filepath;
}
return "";
}
catch (PerformanceException ex)
{
logger.LogError(ex.ToString());
LogHelper.Error(ex.ToString(), "提取绩效数据", "异常");
SendEmail(mail, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据失败,{ex.Message}!");
var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
if (allot != null)
{
allot.IsExtracting = 3;
perforPerallotRepository.Update(allot);
}
throw ex;
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
LogHelper.Error(ex.ToString(), "提取绩效数据", "异常");
SendEmail(mail, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!");
}
finally
{
var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
if (allot != null)
{
allot.IsExtracting = 3;
allot.IsExtracting = null;
perforPerallotRepository.Update(allot);
}
throw ex;
}
return filepath;
}
/// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment