Commit 1dcd666a by ruyun.zhang

多线程保存数据

parent 9a0ed827
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
namespace Performance.Services.AllotCompute namespace Performance.Services.AllotCompute
{ {
...@@ -102,7 +103,7 @@ public List<ImportData> ReadSheetData(per_allot allot) ...@@ -102,7 +103,7 @@ public List<ImportData> ReadSheetData(per_allot allot)
Address = cell.Address, Address = cell.Address,
Text = cell.Text?.Clean() ?? "", Text = cell.Text?.Clean() ?? "",
Value = cell.Value?.ToString()?.Clean() ?? "", Value = cell.Value?.ToString()?.Clean() ?? "",
Comment = cell.Comment?.Text ?? "", //Comment = cell.Comment?.Text ?? "",
EndRowIndex = endRowIndex, EndRowIndex = endRowIndex,
EndColIndex = endColIndex, EndColIndex = endColIndex,
Sign = SnowFlake.GetInstance().GetUniqueShortId(), Sign = SnowFlake.GetInstance().GetUniqueShortId(),
...@@ -131,14 +132,24 @@ public List<ImportData> ReadSheetData(per_allot allot) ...@@ -131,14 +132,24 @@ public List<ImportData> ReadSheetData(per_allot allot)
try try
{ {
var connectionString = _configuration.GetValue("AppConnection:PerformanceConnectionString", ""); var connectionString = _configuration.GetValue("AppConnection:PerformanceConnectionString", "");
DapperExtensions.BulkInsert(connectionString, importDatas, tableName: "im_orig_data", commandTimeout: 60 * 60 * 5); var tasks = new List<Task>();
foreach (var sheetName in importDatas.Select(w => w.SheetName).Distinct())
{
var task = Task.Factory.StartNew(() =>
{
var items = importDatas.Where(w => w.SheetName == sheetName).ToList();
DapperExtensions.BulkInsert(connectionString, items, tableName: "im_orig_data", commandTimeout: 60 * 60 * 5);
});
tasks.Add(task);
}
Task.WaitAll(tasks.ToArray());
_logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allot.ID, "ReceiveMessage", true);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logManageService.WriteMsg("保存数据失败", ex.Message.ToString(), 4, allot.ID, "ReceiveMessage", true); _logManageService.WriteMsg("保存数据失败", ex.Message.ToString(), 4, allot.ID, "ReceiveMessage", true);
throw; throw;
} }
_logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allot.ID, "ReceiveMessage", true);
return importDatas; return importDatas;
} }
...@@ -373,10 +384,10 @@ public class ImportData ...@@ -373,10 +384,10 @@ public class ImportData
/// </summary> /// </summary>
public string ColName { get; set; } public string ColName { get; set; }
/// <summary> ///// <summary>
/// 单元格备注 ///// 单元格备注
/// </summary> ///// </summary>
public string Comment { get; set; } //public string Comment { get; set; }
public int SheetType { get; set; } public int SheetType { get; set; }
public long Version { get; set; } public long Version { get; set; }
......
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