Commit 1dcd666a by ruyun.zhang

多线程保存数据

parent 9a0ed827
......@@ -16,6 +16,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Performance.Services.AllotCompute
{
......@@ -102,7 +103,7 @@ public List<ImportData> ReadSheetData(per_allot allot)
Address = cell.Address,
Text = cell.Text?.Clean() ?? "",
Value = cell.Value?.ToString()?.Clean() ?? "",
Comment = cell.Comment?.Text ?? "",
//Comment = cell.Comment?.Text ?? "",
EndRowIndex = endRowIndex,
EndColIndex = endColIndex,
Sign = SnowFlake.GetInstance().GetUniqueShortId(),
......@@ -131,14 +132,24 @@ public List<ImportData> ReadSheetData(per_allot allot)
try
{
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)
{
_logManageService.WriteMsg("保存数据失败", ex.Message.ToString(), 4, allot.ID, "ReceiveMessage", true);
throw;
}
_logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allot.ID, "ReceiveMessage", true);
return importDatas;
}
......@@ -373,10 +384,10 @@ public class ImportData
/// </summary>
public string ColName { get; set; }
/// <summary>
/// 单元格备注
/// </summary>
public string Comment { get; set; }
///// <summary>
///// 单元格备注
///// </summary>
//public string Comment { get; set; }
public int SheetType { 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