绩效数据调整

parent 2e468456
......@@ -115,8 +115,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绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
}
}
......
......@@ -22,7 +22,7 @@ public List<CustomExecute> ExecuteScript(IDbConnection connection, string sql, s
List<CustomExecute> result = new List<CustomExecute>();
using (connection)
{
var dataReader = connection.ExecuteReader(sql, param);
var dataReader = connection.ExecuteReader(sql, param, commandTimeout: 1000 * 3600 * 24);
int row = 0;
while (dataReader.Read())
{
......
......@@ -138,16 +138,16 @@ public void ExtractData(int allotId, string mail, sys_hospital hospital)
/// <param name="body"></param>
private void SendEmail(string mail, string path, string subject, string body)
{
var message = new EmailMessage
{
To = new List<string> { mail },
DisplayName = "溯直健康",
Subject = subject,
Body = body
};
if (!string.IsNullOrEmpty(path))
message.Attachments = new List<string> { path };
emailService.Send(message);
//var message = new EmailMessage
//{
// To = new List<string> { mail },
// DisplayName = "溯直健康",
// Subject = subject,
// Body = body
//};
//if (!string.IsNullOrEmpty(path))
// message.Attachments = new List<string> { path };
//emailService.Send(message);
}
/// <summary>
......@@ -167,10 +167,12 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
throw new PerformanceException($"{originalPath}文件路径无效");
var scriptList = perforExtractRepository.GetEntities(t => t.HospitalId == hospitalId);
var connection = ConnectionBuilder.Create(DatabaseType.SqlServer, hospitalConfig.DbSource, hospitalConfig.DbName, hospitalConfig.DbUser, hospitalConfig.DbPassword);
//根据SHEET页信息,列头信息,创建EXCEL文件
IWorkbook workbook = new XSSFWorkbook(originalPath);
IWorkbook workbook = null;
try
{
workbook = new XSSFWorkbook(originalPath);
foreach (var sheet in sheetList)
{
var importSheet = workbook.GetSheet(sheet.SheetName);
......@@ -238,6 +240,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))
{
var connection = ConnectionBuilder.Create(DatabaseType.SqlServer, hospitalConfig.DbSource, hospitalConfig.DbName, hospitalConfig.DbUser, hospitalConfig.DbPassword);
var dataList = perforExtractRepository.ExecuteScript(connection, script.ExecuteScript, null);
//创建数据行
foreach (var pointRow in dataList.Select(t => t.RowNumber).Distinct().OrderBy(t => t))
......@@ -261,6 +264,15 @@ private bool WriteExcel(string newpath, string originalPath, List<PerSheet> shee
filepath = newpath;
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
workbook.Close();
}
}
/// <summary>
/// 从数据库中获取sheet及列头
......@@ -318,8 +330,11 @@ private List<PerSheet> GetFileData(string path)
if (!FileHelper.IsExistFile(path))
throw new PerformanceException($"{path}文件不存在");
List<PerSheet> sheetList = new List<PerSheet>();
using (FileStream fs = new FileStream(path, FileMode.Open))
FileStream fs = null;
try
{
fs = new FileStream(path, FileMode.Open);
var version = FileHelper.GetExtension(path) == ".xlsx" ? ExcelVersion.xlsx : ExcelVersion.xls;
IWorkbook workbook = (version == ExcelVersion.xlsx) ? (IWorkbook)(new XSSFWorkbook(fs)) : (IWorkbook)(new HSSFWorkbook(fs));
for (int i = 0; i < workbook.NumberOfSheets; i++)
......@@ -348,6 +363,15 @@ private List<PerSheet> GetFileData(string path)
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
fs.Close();
}
return sheetList;
}
......
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