下载文件

parent 72f262ee
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.DtoModels.AppSettings; using Performance.DtoModels.AppSettings;
...@@ -119,5 +120,24 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBo ...@@ -119,5 +120,24 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBo
BackgroundJob.Enqueue(() => extractService.ExtractData(request.ID, user.Mail, hospital)); BackgroundJob.Enqueue(() => extractService.ExtractData(request.ID, user.Mail, hospital));
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!"); return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
} }
/// <summary>
/// 从WebAPI下载文件
/// </summary>
/// <returns></returns>
[Route("down")]
public IActionResult DownFile([FromQuery]AllotRequest request)
{
var allot = allotService.GetAllot(request.ID);
if (allot == null || string.IsNullOrWhiteSpace(allot.ExtractPath) || !FileHelper.IsExistFile(allot.ExtractPath))
{
return new ObjectResult(new ApiResponse(ResponseType.Fail, "文件不存在"));
}
var stream = new FileStream(allot.ExtractPath, FileMode.Open);
string fileExt = Path.GetExtension(allot.ExtractPath);
var provider = new FileExtensionContentTypeProvider();
var memi = provider.Mappings[fileExt];
return File(stream, memi, Path.GetFileName(allot.ExtractPath));
}
} }
} }
\ No newline at end of file
...@@ -83,10 +83,13 @@ public ActionsFilter(ILoggerFactory factory, IMemoryCache cache, IHostingEnviron ...@@ -83,10 +83,13 @@ public ActionsFilter(ILoggerFactory factory, IMemoryCache cache, IHostingEnviron
if (executedContext.Exception != null) if (executedContext.Exception != null)
throw executedContext.Exception; throw executedContext.Exception;
var objectResult = (ObjectResult)executedContext.Result; if (executedContext.Result is ObjectResult)
var jsonData = JsonHelper.Serialize(objectResult.Value); {
_logger.LogInformation($"响应结果:{jsonData}"); var objectResult = (ObjectResult)executedContext.Result;
LogHelper.Information($"请求地址:{context.HttpContext.Request.Path};响应结果:{jsonData}", "响应结果"); var jsonData = JsonHelper.Serialize(objectResult.Value);
_logger.LogInformation($"响应结果:{jsonData}");
LogHelper.Information($"请求地址:{context.HttpContext.Request.Path};响应结果:{jsonData}", "响应结果");
}
} }
} }
......
...@@ -53,5 +53,9 @@ public class AllotResponse ...@@ -53,5 +53,9 @@ public class AllotResponse
/// 提取绩效数据文件生成路径 /// 提取绩效数据文件生成路径
/// </summary> /// </summary>
public string ExtractPath { get; set; } public string ExtractPath { get; set; }
/// <summary>
/// 是否可以下载
/// </summary>
public bool IsDown { get; set; }
} }
} }
...@@ -74,7 +74,9 @@ public List<AllotResponse> GetAllotList(int? hospitalId) ...@@ -74,7 +74,9 @@ public List<AllotResponse> GetAllotList(int? hospitalId)
throw new PerformanceException("hospitalId无效"); throw new PerformanceException("hospitalId无效");
var allotList = _allotRepository.GetEntities(t => t.HospitalId == hospitalId); var allotList = _allotRepository.GetEntities(t => t.HospitalId == hospitalId);
allotList = allotList == null ? allotList : allotList.OrderByDescending(t => t.ID).ToList(); allotList = allotList == null ? allotList : allotList.OrderByDescending(t => t.ID).ToList();
return Mapper.Map<List<AllotResponse>>(allotList); var reuslt = Mapper.Map<List<AllotResponse>>(allotList);
reuslt.ForEach(t => t.IsDown = !string.IsNullOrEmpty(t.ExtractPath));
return reuslt;
} }
/// <summary> /// <summary>
...@@ -199,7 +201,7 @@ public void Generate(per_allot allot, string mail) ...@@ -199,7 +201,7 @@ public void Generate(per_allot allot, string mail)
if (!checkDataService.Check(excel, allot)) if (!checkDataService.Check(excel, allot))
{ {
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.CheckFail, EnumHelper.GetDescription(AllotStates.CheckFail)); _allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.CheckFail, EnumHelper.GetDescription(AllotStates.CheckFail));
SendEmail(allot,mail, 3, time); SendEmail(allot, mail, 3, time);
logdbug.Add(allot.ID, "绩效数据校验失败", JsonHelper.Serialize(allot)); logdbug.Add(allot.ID, "绩效数据校验失败", JsonHelper.Serialize(allot));
return; return;
} }
...@@ -217,13 +219,13 @@ public void Generate(per_allot allot, string mail) ...@@ -217,13 +219,13 @@ public void Generate(per_allot allot, string mail)
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.GenerateSucceed, EnumHelper.GetDescription(AllotStates.GenerateSucceed)); _allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.GenerateSucceed, EnumHelper.GetDescription(AllotStates.GenerateSucceed));
//发送邮件 //发送邮件
SendEmail(allot,mail, 1, time); SendEmail(allot, mail, 1, time);
logdbug.Add(allot.ID, "绩效开始执行", "绩效生成成功"); logdbug.Add(allot.ID, "绩效开始执行", "绩效生成成功");
} }
catch (Exception ex) catch (Exception ex)
{ {
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.GenerateFail, EnumHelper.GetDescription(AllotStates.GenerateFail)); _allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.GenerateFail, EnumHelper.GetDescription(AllotStates.GenerateFail));
SendEmail(allot,mail, 2, time); SendEmail(allot, mail, 2, time);
logdbug.Add(allot.ID, "绩效开始执行", ex.ToString()); logdbug.Add(allot.ID, "绩效开始执行", ex.ToString());
//throw ex; //throw ex;
} }
......
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