Commit 980923c5 by lcx

自定义提取日志推送

parent fae509c7
...@@ -61,13 +61,13 @@ public ApiResponse CustomExtract(int allotId) ...@@ -61,13 +61,13 @@ public ApiResponse CustomExtract(int allotId)
} }
else else
{ {
scopedQueue.Send(new Notification(allotId, "Notification", new TextContent("自定义数据提取数据失败", NotificationLevel.ERR))); scopedQueue.Send(new Notification(allotId, "ReceiveMessage", new TextContent("自定义数据提取数据失败", NotificationLevel.ERR)));
} }
await Task.Delay(TimeSpan.FromSeconds(5), token); await Task.Delay(TimeSpan.FromSeconds(5), token);
} }
}); });
_notificationQueue.Send(new Notification(allotId, "Notification", new TextContent("自定义数据提取任务开始执行"))); _notificationQueue.Send(new Notification(allotId, "ReceiveMessage", new TextContent("自定义数据提取任务开始执行")));
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Repository; using Performance.Repository;
using Performance.Services.ExtractExcelService; using Performance.Services.ExtractExcelService;
using Performance.Services.Queues;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
...@@ -26,6 +27,7 @@ public class CustomExtractService : IAutoInjection ...@@ -26,6 +27,7 @@ public class CustomExtractService : IAutoInjection
private readonly PerforPerdeptdicRepository _perforPerdeptdicRepository; private readonly PerforPerdeptdicRepository _perforPerdeptdicRepository;
private readonly PerforHospitalconfigRepository _perforHospitalconfigRepository; private readonly PerforHospitalconfigRepository _perforHospitalconfigRepository;
private readonly PerforCustscriptRepository _perforcustscriptRepository; private readonly PerforCustscriptRepository _perforcustscriptRepository;
private readonly IHubNotificationQueue _notificationQueue;
public CustomExtractService( public CustomExtractService(
ILogger<CustomExtractService> logger, ILogger<CustomExtractService> logger,
...@@ -35,7 +37,8 @@ public class CustomExtractService : IAutoInjection ...@@ -35,7 +37,8 @@ public class CustomExtractService : IAutoInjection
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
PerforPerdeptdicRepository perforPerdeptdicRepository, PerforPerdeptdicRepository perforPerdeptdicRepository,
PerforHospitalconfigRepository perforHospitalconfigRepository, PerforHospitalconfigRepository perforHospitalconfigRepository,
PerforCustscriptRepository perforcustscriptRepository) PerforCustscriptRepository perforcustscriptRepository,
IHubNotificationQueue notificationQueue)
{ {
_logger = logger; _logger = logger;
_options = options; _options = options;
...@@ -45,6 +48,7 @@ public class CustomExtractService : IAutoInjection ...@@ -45,6 +48,7 @@ public class CustomExtractService : IAutoInjection
_perforPerdeptdicRepository = perforPerdeptdicRepository; _perforPerdeptdicRepository = perforPerdeptdicRepository;
_perforHospitalconfigRepository = perforHospitalconfigRepository; _perforHospitalconfigRepository = perforHospitalconfigRepository;
_perforcustscriptRepository = perforcustscriptRepository; _perforcustscriptRepository = perforcustscriptRepository;
_notificationQueue = notificationQueue;
} }
public bool CheckConfigScript(int userId, int allotId) public bool CheckConfigScript(int userId, int allotId)
...@@ -136,6 +140,7 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri ...@@ -136,6 +140,7 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri
var conf = configs.FirstOrDefault(w => w.Id == item.ConfigId); var conf = configs.FirstOrDefault(w => w.Id == item.ConfigId);
if (conf != null) if (conf != null)
{ {
_notificationQueue.Send(new Notification(allot.ID, "ReceiveMessage", new TextContent($"正在提取“{item.Name}”的数据")));
var execsql = item.Script; var execsql = item.Script;
var dynamics = QueryData(conf, execsql, parameters); var dynamics = QueryData(conf, execsql, parameters);
...@@ -150,8 +155,12 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri ...@@ -150,8 +155,12 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri
var sheet = workbook.CreateSheet(item.Name); var sheet = workbook.CreateSheet(item.Name);
// 没数据跳过 // 没数据跳过
if (dynamics == null || dynamics.Count() == 0) if (dynamics == null || dynamics.Count() == 0)
{
_notificationQueue.Send(new Notification(allot.ID, "ReceiveMessage", new TextContent($"“{item.Name}”提取的数据为空")));
continue; continue;
}
_notificationQueue.Send(new Notification(allot.ID, "ReceiveMessage", new TextContent($"正在写入“{item.Name}”的数据")));
var headers = ((IDictionary<string, object>)dynamics.ElementAt(0)).Keys; var headers = ((IDictionary<string, object>)dynamics.ElementAt(0)).Keys;
for (int col = 0; col < headers.Count; col++) for (int col = 0; col < headers.Count; col++)
{ {
...@@ -219,6 +228,7 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri ...@@ -219,6 +228,7 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri
} }
row++; row++;
} }
_notificationQueue.Send(new Notification(allot.ID, "ReceiveMessage", new TextContent($"“{item.Name}”的数据写入完成")));
} }
catch (Exception ex) catch (Exception 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