Commit 8f813702 by 799284587@qq.com

sql带入参数

parent 15e62c9a
......@@ -116,8 +116,8 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBo
return new ApiResponse(ResponseType.Fail, "医院无效");
var user = claim.At(request.Token);
//extractService.ExtractData(request.ID, user.Mail, hospital);
BackgroundJob.Enqueue(() => extractService.ExtractData(request.ID, user.Mail, hospital));
extractService.ExtractData(request.ID, user.Mail, hospital);
//BackgroundJob.Enqueue(() => extractService.ExtractData(request.ID, user.Mail, hospital));
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
}
......
......@@ -109,10 +109,9 @@ public void ExtractData(int allotId, string mail, sys_hospital hospital)
{
LogHelper.Information($"当前绩效为非首次提取,从数据库中获取信息", "提取绩效数据");
//非首次 从数据库中获取人员信息,SHEET页信息,列头信息
allotList = allotList.Where(t => t.Path != null && t.Path != "").ToList();
if (allotList != null && allotList.Count > 0)
if (allotList.Any(t => t.Path != null && t.Path != ""))
{
var allot = allotList.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
var allot = allotList.Where(t => t.Path != null && t.Path != "").OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
sheetList = GetRepositoryData(allot.ID);
originalPath = allot.Path;
}
......@@ -127,10 +126,10 @@ public void ExtractData(int allotId, string mail, sys_hospital hospital)
FileHelper.CreateDirectory(dpath);
string path = Path.Combine(dpath, $"绩效数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx");
//根据SHEET页信息,列头信息,创建EXCEL文件
if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospital.ID, out string filepath))
if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospital.ID, allotList.First(t => t.ID == allotId), out string filepath))
{
LogHelper.Information($"基础数据提取完成,文件保存成功{filepath}", "提取绩效数据");
var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
var allot = allotList.First(t => t.ID == allotId);
allot.ExtractPath = filepath;
if (!string.IsNullOrEmpty(filepath))
perforPerallotRepository.Update(allot);
......@@ -183,7 +182,7 @@ private void SendEmail(string mail, string path, string subject, string body)
/// <param name="sheetList"></param>
/// <param name="hospitalConfig"></param>
/// <param name="hospitalId"></param>
private bool WriteExcel(string newpath, string originalPath, List<PerSheet> sheetList, sys_hospitalconfig hospitalConfig, int hospitalId, out string filepath)
private bool WriteExcel(string newpath, string originalPath, List<PerSheet> sheetList, sys_hospitalconfig hospitalConfig, int hospitalId, per_allot allot, out string filepath)
{
LogHelper.Information($"开始向EXCEL中写入数据,", "提取绩效数据");
if (string.IsNullOrEmpty(originalPath))
......@@ -323,6 +322,7 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
var script = scriptList.First(t => sheet.SheetName.Contains(t.SheetName));
if (!string.IsNullOrEmpty(script.ExecuteScript))
{
script.ExecuteScript = ReplaceParameter(script.ExecuteScript, allot);
LogHelper.Information($"SQL脚本{script.ExecuteScript},", "提取绩效数据");
var children = new List<PerHeader>();
foreach (var item in sheet.PerHeader?.Select(t => t.Children))
......@@ -407,6 +407,22 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
}
/// <summary>
/// 替换SQL参数
/// </summary>
/// <param name="executeScript"></param>
/// <param name="allot"></param>
/// <returns></returns>
private string ReplaceParameter(string executeScript, per_allot allot)
{
var basicTime = new DateTime(allot.Year, allot.Month, 1);
string beginTime = basicTime.ToString("yyyy-MM-dd HH:mm:ss");
string endTime = basicTime.AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss");
executeScript = Regex.Replace(executeScript, "@beginTime", $"'{beginTime}'", RegexOptions.IgnoreCase);
executeScript = Regex.Replace(executeScript, "@endTime", $"'{endTime}'", RegexOptions.IgnoreCase);
return executeScript;
}
/// <summary>
/// 从数据库中获取sheet及列头
/// </summary>
/// <param name="allotId"></param>
......
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