Commit b932b898 by lcx

抽取修改

parent 123c69f4
...@@ -223,7 +223,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody]ExtractRequest r ...@@ -223,7 +223,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody]ExtractRequest r
// 判断是那种抽取 // 判断是那种抽取
try try
{ {
string message = newExtractService.Judge(request.AllotId, request.HospitalId, request.UseScheme); string message = newExtractService.Judge(request.AllotId, request.HospitalId, request.UseScheme, out string filePath);
if (!string.IsNullOrEmpty(message)) if (!string.IsNullOrEmpty(message))
return new ApiResponse(ResponseType.Fail, message); return new ApiResponse(ResponseType.Fail, message);
...@@ -233,18 +233,14 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody]ExtractRequest r ...@@ -233,18 +233,14 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody]ExtractRequest r
allot.IsExtracting = 1; allot.IsExtracting = 1;
allotService.Update(allot); allotService.Update(allot);
//request.Email = claim.GetUserClaim(JwtClaimTypes.Mail);
var email = claim.GetUserClaim(JwtClaimTypes.Mail);
request.Email = email;
//if (request.UseScheme == (int)UseTemplate.Config)
//{
logger.LogInformation("提取绩效数据请求路径:" + url.HttpPost + "/extract/extract"); logger.LogInformation("提取绩效数据请求路径:" + url.HttpPost + "/extract/extract");
HttpHelper.HttpPostNoRequest(url.HttpPost + "/extract/extract", JsonHelper.Serialize(request), true); //HttpHelper.HttpPostNoRequest(url.HttpPost + "/extract/extract", JsonHelper.Serialize(request), true);
//} if (string.IsNullOrEmpty(filePath))
//else HttpHelper.HttpPostNoRequest(url.HttpPost + $"/extract/extract?allotId={request.AllotId}&hospitalId={request.HospitalId}&email={claim.GetUserClaim(JwtClaimTypes.Mail)}", "");
//{ else
// return new ApiResponse(ResponseType.Fail, "该功能暂未实现!"); HttpHelper.HttpClient(url.HttpPost + $"/extract/extract?allotId={request.AllotId}&hospitalId={request.HospitalId}&email={claim.GetUserClaim(JwtClaimTypes.Mail)}", filePath);
//}
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!"); return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -118,14 +118,48 @@ public void Index([FromBody]AllotRequest request) ...@@ -118,14 +118,48 @@ public void Index([FromBody]AllotRequest request)
/// <returns></returns> /// <returns></returns>
[Route("extract")] [Route("extract")]
[HttpPost] [HttpPost]
public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request) public void ExtractData([FromForm] IFormCollection form, int allotId, int hospitalId, string email)
{ {
logger.LogInformation("提取绩效数据请求参数:" + JsonHelper.Serialize(request)); logger.LogInformation("提取绩效数据请求参数:" + JsonHelper.Serialize(new { allotId, hospitalId, email }));
//string filePath = newExtractService.ExtractData(request.AllotId, request.Email, request.HospitalId); if (allotId == 0 || hospitalId == 0)
string filePath = dfExtractService.ExtractData(request.AllotId, request.Email, request.HospitalId); return;
var path = string.Empty;
#region 保存历史绩效文件
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
logger.LogInformation($"文件为空!");
else
{
var dpath = Path.Combine(evn.ContentRootPath, "Files", "HospitalAllot", $"{hospitalId}");
FileHelper.CreateDirectory(dpath);
path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName));
logger.LogInformation($"保存历史绩效文件保存路径:" + path);
using (var stream = file.OpenReadStream())
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
{
logger.LogInformation($"保存历史绩效文件保存失败");
}
}
}
#endregion
//string filePath = newExtractService.ExtractData(allotId, request.Email, hospitalId);
string filePath = dfExtractService.ExtractData(allotId, email, hospitalId, path); //抽取
if (!string.IsNullOrEmpty(path) && FileHelper.IsExistFile(path))
FileHelper.DeleteFile(path);
#region 保存文件到网站下
if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath)) if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath))
{ {
logger.LogInformation("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new { allotId = request.AllotId, hospitalId = request.HospitalId })); logger.LogInformation("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new { allotId, hospitalId }));
int i = 1; int i = 1;
while (i <= 5) while (i <= 5)
{ {
...@@ -135,7 +169,7 @@ public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request) ...@@ -135,7 +169,7 @@ public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request)
logger.LogInformation($"正在尝试第{i}次保存!"); logger.LogInformation($"正在尝试第{i}次保存!");
//保存文件 //保存文件
string retJson = HttpHelper.HttpClient(url.ImportFile + $"?allotId={request.AllotId}&hospitalId={request.HospitalId}", filePath); string retJson = HttpHelper.HttpClient(url.ImportFile + $"?allotId={allotId}&hospitalId={hospitalId}", filePath);
logger.LogInformation("保存提取文件返回结果:" + JsonHelper.Serialize(retJson)); logger.LogInformation("保存提取文件返回结果:" + JsonHelper.Serialize(retJson));
logger.LogInformation(retJson); logger.LogInformation(retJson);
var ret = JsonHelper.Deserialize<ApiResponse>(retJson); var ret = JsonHelper.Deserialize<ApiResponse>(retJson);
...@@ -149,6 +183,8 @@ public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request) ...@@ -149,6 +183,8 @@ public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request)
} }
else else
logger.LogInformation($"保存提取文件提取文件不存在!"); logger.LogInformation($"保存提取文件提取文件不存在!");
#endregion
} }
#endregion #endregion
......
...@@ -82,12 +82,14 @@ public class DFExtractService : IAutoInjection ...@@ -82,12 +82,14 @@ public class DFExtractService : IAutoInjection
#region 抽取 #region 抽取
public string ExtractData(int allotId, string email, int hospitalId) public string ExtractData(int allotId, string email, int hospitalId, string filePath = null)
{
var hospital = perforHospitalRepository.GetEntity(t => t.ID == hospitalId);
try
{ {
var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId); var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
Allot = allot ?? throw new PerformanceException(""); Allot = allot ?? throw new PerformanceException("");
var hospital = perforHospitalRepository.GetEntity(t => t.ID == hospitalId);
var configs = perforHospitalconfigRepository.GetEntities(t => t.HospitalId == hospitalId); var configs = perforHospitalconfigRepository.GetEntities(t => t.HospitalId == hospitalId);
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive }; var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
...@@ -112,7 +114,23 @@ public string ExtractData(int allotId, string email, int hospitalId) ...@@ -112,7 +114,23 @@ public string ExtractData(int allotId, string email, int hospitalId)
extractIds = extractIds.Distinct().ToList(); extractIds = extractIds.Distinct().ToList();
var extracts = perforModextractRepository.GetEntities(t => extractIds.Contains(t.Id)); var extracts = perforModextractRepository.GetEntities(t => extractIds.Contains(t.Id));
return lastAllot == null ? TemplateExecute(email, lastAllot, hospital, configs, modules, items, specials, extracts) : AlllotExecute(email, lastAllot, hospital, configs, modules, items, specials, extracts); return lastAllot == null ? TemplateExecute(email, lastAllot, hospital, configs, modules, items, specials, extracts) : AlllotExecute(email, lastAllot, hospital, configs, modules, items, specials, extracts, filePath);
}
catch (Exception ex)
{
logManageService.WriteMsg("提取数据异常", $"数据写入出现异常", 4, Allot.ID, "ReceiveMessage");
logger.LogError($"提取绩效数据异常 数据写入出现异常{ex.ToString()}");
SendEmail(email, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!");
throw ex;
}
finally
{
Allot.IsExtracting = null;
perforPerallotRepository.Update(Allot);
if (workbook != null)
workbook.Close();
GC.Collect();
}
} }
/// <summary> /// <summary>
...@@ -129,8 +147,6 @@ public string ExtractData(int allotId, string email, int hospitalId) ...@@ -129,8 +147,6 @@ public string ExtractData(int allotId, string email, int hospitalId)
/// <returns></returns> /// <returns></returns>
public string TemplateExecute(string email, per_allot lastAllot, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts) public string TemplateExecute(string email, per_allot lastAllot, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts)
{ {
try
{
string originalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "东方医院绩效模板.xlsx"); string originalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "东方医院绩效模板.xlsx");
var (tempPath, newPath) = CopyOriginalFile(hospital.ID, originalPath); var (tempPath, newPath) = CopyOriginalFile(hospital.ID, originalPath);
workbook = new XSSFWorkbook(tempPath); workbook = new XSSFWorkbook(tempPath);
...@@ -178,21 +194,6 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho ...@@ -178,21 +194,6 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho
SendEmail(email, newPath, $"{hospital.HosName}HIS数据提取成功", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。"); SendEmail(email, newPath, $"{hospital.HosName}HIS数据提取成功", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。");
return newPath; return newPath;
} }
catch (Exception ex)
{
logManageService.WriteMsg("提取数据异常", $"数据写入出现异常", 4, Allot.ID, "ReceiveMessage");
logger.LogError($"提取绩效数据异常 数据写入出现异常{ex.ToString()}");
SendEmail(email, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!");
throw ex;
}
finally
{
Allot.IsExtracting = null;
perforPerallotRepository.Update(Allot);
workbook.Close();
GC.Collect();
}
}
/// <summary> /// <summary>
/// 历史绩效为模板 /// 历史绩效为模板
...@@ -206,11 +207,11 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho ...@@ -206,11 +207,11 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho
/// <param name="specials"></param> /// <param name="specials"></param>
/// <param name="extracts"></param> /// <param name="extracts"></param>
/// <returns></returns> /// <returns></returns>
public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts) public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts, string path)
{
try
{ {
var (tempPath, newPath) = CopyOriginalFile(hospital.ID, lastAllot.Path); if (string.IsNullOrEmpty(path)) throw new PerformanceException("历史绩效文件不存在!");
var (tempPath, newPath) = CopyOriginalFile(hospital.ID, path);
workbook = new XSSFWorkbook(tempPath); workbook = new XSSFWorkbook(tempPath);
CreateNotExistSheet(modules, workbook); CreateNotExistSheet(modules, workbook);
...@@ -261,21 +262,6 @@ public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hosp ...@@ -261,21 +262,6 @@ public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hosp
SendEmail(email, newPath, $"{hospital.HosName}HIS数据提取成功", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。"); SendEmail(email, newPath, $"{hospital.HosName}HIS数据提取成功", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。");
return newPath; return newPath;
} }
catch (Exception ex)
{
logManageService.WriteMsg("提取数据异常", $"数据写入出现异常", 4, Allot.ID, "ReceiveMessage");
logger.LogError($"提取绩效数据 异常 数据写入出现异常{ex.ToString()}");
SendEmail(email, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!");
throw ex;
}
finally
{
Allot.IsExtracting = null;
perforPerallotRepository.Update(Allot);
workbook.Close();
GC.Collect();
}
}
#endregion #endregion
......
...@@ -888,9 +888,10 @@ public void OutToExcelCell(ICell cell, object obj) ...@@ -888,9 +888,10 @@ public void OutToExcelCell(ICell cell, object obj)
/// <param name="allotId"></param> /// <param name="allotId"></param>
/// <param name="hospitalId"></param> /// <param name="hospitalId"></param>
/// <param name="useTemplate"></param> /// <param name="useTemplate"></param>
public string Judge(int allotId, int hospitalId, int useTemplate) public string Judge(int allotId, int hospitalId, int useTemplate, out string filePath)
{ {
string result = null; string result = null;
filePath = "";
try try
{ {
// 获取绩效信息 // 获取绩效信息
...@@ -909,6 +910,8 @@ public string Judge(int allotId, int hospitalId, int useTemplate) ...@@ -909,6 +910,8 @@ public string Judge(int allotId, int hospitalId, int useTemplate)
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive }; var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var allotList = perforPerallotRepository.GetEntities(t => t.HospitalId == hospitalId && statesArray.Contains(t.States)); var allotList = perforPerallotRepository.GetEntities(t => t.HospitalId == hospitalId && statesArray.Contains(t.States));
var allotLast = allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First(); var allotLast = allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
if (allotLast != null)
filePath = allotLast.Path;
// 获取当前医院模版信息 // 获取当前医院模版信息
var modulesList = perforModmoduleRepository.GetEntities(t => t.HospitalId == hospitalId); var modulesList = perforModmoduleRepository.GetEntities(t => t.HospitalId == hospitalId);
if (modulesList == null || modulesList.Count == 0) if (modulesList == null || modulesList.Count == 0)
......
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