Commit ddf312c5 by wyc

SqlSugar

parent 2c602f14
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
}, },
"AppConnection": { "AppConnection": {
//"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;", //"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
//"PerformanceConnectionString": "server=192.168.18.166;database=db_test_beiliu;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;" "PerformanceConnectionString": "server=192.168.18.166;database=db_test_beiliu;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
"PerformanceConnectionString": "server=112.124.15.49;database=db_performance_cxjx;uid=cxjx;pwd=Suvalue@cxjx;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;" //"PerformanceConnectionString": "server=112.124.15.49;database=db_performance_cxjx;uid=cxjx;pwd=Suvalue@cxjx;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
}, },
"AppOptions": { "AppOptions": {
"OpenOAuth": true "OpenOAuth": true
......
using SqlSugar;
namespace Performance.Repository
{
public class InfraRepository
{
public static SqlSugarClient GetDbclient(string connectionString)
{
return new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = connectionString,
DbType = SqlSugar.DbType.MySql,
IsAutoCloseConnection = true
},
db =>
{
});
}
}
}
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Npgsql" Version="5.0.18" /> <PackageReference Include="Npgsql" Version="5.0.18" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.4" /> <PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.100" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" /> <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
</ItemGroup> </ItemGroup>
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Infrastructure.Extensions; using Performance.Infrastructure.Extensions;
using Performance.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
...@@ -131,18 +133,24 @@ public List<ImportData> ReadSheetData(per_allot allot) ...@@ -131,18 +133,24 @@ public List<ImportData> ReadSheetData(per_allot allot)
try try
{ {
//var connectionString = _configuration.GetValue("AppConnection:PerformanceConnectionString", "");
//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());
var connectionString = _configuration.GetValue("AppConnection:PerformanceConnectionString", ""); var connectionString = _configuration.GetValue("AppConnection:PerformanceConnectionString", "");
var tasks = new List<Task>(); var db = InfraRepository.GetDbclient(connectionString);
foreach (var sheetName in importDatas.Select(w => w.SheetName).Distinct()) if (importDatas.Any())
{ {
var task = Task.Factory.StartNew(() => db.Fastest<ImportData>().AS("im_orig_data").PageSize(100000).BulkCopy(importDatas);
{
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); _logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allot.ID, "ReceiveMessage", true);
} }
catch (Exception ex) catch (Exception ex)
......
using System; using AutoMapper;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Dapper; using Dapper;
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using MySql.Data.MySqlClient;
using NPOI.HSSF.UserModel; using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
...@@ -16,6 +9,13 @@ ...@@ -16,6 +9,13 @@
using Performance.DtoModels.AppSettings; using Performance.DtoModels.AppSettings;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Performance.Services.AllotCompute namespace Performance.Services.AllotCompute
{ {
...@@ -49,10 +49,13 @@ public class ImportDataService : IAutoInjection ...@@ -49,10 +49,13 @@ public class ImportDataService : IAutoInjection
public PerExcel ReadDataAndSave(per_allot allot) public PerExcel ReadDataAndSave(per_allot allot)
{ {
var excel = Import(allot); var excel = Import(allot);
Save(excel, allot.ID); bool isSave = Save(excel, allot.ID);
var item = excel.PerSheet.FirstOrDefault(w => w.SheetType == SheetType.AccountBasicSpecial); if (isSave)
if (item != null) {
excel.PerSheet.Remove(item); var item = excel.PerSheet.FirstOrDefault(w => w.SheetType == SheetType.AccountBasicSpecial);
if (item != null)
excel.PerSheet.Remove(item);
}
return excel; return excel;
} }
...@@ -123,57 +126,27 @@ private PerExcel Import(per_allot allot) ...@@ -123,57 +126,27 @@ private PerExcel Import(per_allot allot)
private bool Save(PerExcel excel, int allotId) private bool Save(PerExcel excel, int allotId)
{ {
var tasks = new List<Task>(); var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
var allotList = db.Ado.SqlQuery<per_allot>("SELECT * FROM per_allot WHERE allotId = @allotId ORDER BY Year DESC, Month DESC", new { allotId }).ToList();
var allot = allotList.FirstOrDefault();
var sheets = db.Ado.SqlQuery<per_sheet>("select * from per_sheet where AllotID = @allotId", new { allotId }).ToList();
foreach (var sheet in excel.PerSheet)
{ {
foreach (var sheet in excel.PerSheet) _logManageService.WriteMsg("准备保存数据", $"正在准备保存数据“{sheet.SheetName}”", 1, allotId, "ReceiveMessage", true);
Func<int> saveHandler = sheet.SheetType switch
{ {
_logManageService.WriteMsg("准备保存数据", $"正在准备保存数据“{sheet.SheetName}”", 1, allotId, "ReceiveMessage", true); SheetType.Employee => () => SaveEmployee(sheet, allot, allotList),
SheetType.LogisticsEmployee => () => SaveLogisticsEmployee(sheet, allot, allotList),
var allot = connection.Get<per_allot>(allotId); SheetType.ClinicEmployee => () => SaveClinicEmployee(sheet, allot, allotList),
var allotList = connection.Query<per_allot>("select * from per_allot where HospitalId = @HospitalId", new { allot.HospitalId }).ToList(); SheetType.AccountBasic => () => SaveAccountBasic(sheet, allot, sheets),
var sheets = connection.Query<per_sheet>("select * from per_sheet where AllotID = @allotId", new { allotId }).ToList(); SheetType.SpecialUnit => () => SaveSpecialUnit(sheet, allot),
_ => () => SaveCommon(sheet, allot, sheets),
var task = Task.Factory.StartNew(() => };
{ var imsheetid = saveHandler();
if (sheet.SheetType == SheetType.Employee) SaveHeader(sheet, allot, imsheetid);
{
var imsheetid = SaveEmployee(sheet, allot, allotList);
SaveHeader(sheet, allot, imsheetid);
}
else if (sheet.SheetType == SheetType.LogisticsEmployee)
{
var imsheetid = SaveLogisticsEmployee(sheet, allot, allotList);
SaveHeader(sheet, allot, imsheetid);
}
else if (sheet.SheetType == SheetType.ClinicEmployee)
{
var imsheetid = SaveClinicEmployee(sheet, allot, allotList);
SaveHeader(sheet, allot, imsheetid);
}
else if (sheet.SheetType == SheetType.AccountBasic)
{
var imsheetid = SaveAccountBasic(sheet, allot, sheets);
SaveHeader(sheet, allot, imsheetid);
}
else if (sheet.SheetType == SheetType.SpecialUnit)
{
var imsheetid = SaveSpecialUnit(sheet, allot);
SaveHeader(sheet, allot, imsheetid);
}
else
{
var imsheetid = SaveCommon(sheet, allot, sheets);
SaveHeader(sheet, allot, imsheetid);
}
});
tasks.Add(task);
}
} }
_logManageService.WriteMsg("保存基础数据", $"基础数据保存中...当前操作需要一点时间,请耐心等待", 1, allotId, "ReceiveMessage", true); //_logManageService.WriteMsg("保存基础数据", $"基础数据保存中...当前操作需要一点时间,请耐心等待", 1, allotId, "ReceiveMessage", true);
Task.WaitAll(tasks.ToArray());
_logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allotId, "ReceiveMessage", true); _logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allotId, "ReceiveMessage", true);
return true; return true;
} }
...@@ -186,38 +159,42 @@ private bool Save(PerExcel excel, int allotId) ...@@ -186,38 +159,42 @@ private bool Save(PerExcel excel, int allotId)
/// <returns></returns> /// <returns></returns>
public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotList) public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotList)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
{ var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; imsheet.ID = db.Insertable(imsheet).AS("per_sheet").ExecuteReturnIdentity();
imsheet.ID = (int)connection.Insert(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataEmployee)t); var dataList = sheet.PerData.Select(t => (PerDataEmployee)t);
//新上传名单中无人员名单,取到最后日期的数据 //新上传名单中无人员名单,取到当前绩效月下的,还是没有就取倒叙日期的数据
if (dataList == null || dataList.Count() <= 0) if (!dataList.Any())
{
var empList = db.Ado.SqlQuery<im_employee>("select * from im_employee where AllotID = @allotid", new { AllotID = allot.ID }).ToList();
if (empList.Any())
{
dataList = _mapper.Map<List<PerDataEmployee>>(empList);
}
else
{ {
empList = db.Ado.SqlQuery<im_employee>("select * from im_employee ").ToList();
foreach (var item in allotList) foreach (var item in allotList)
{ {
var employeeList = connection.Query<im_employee>("select * from im_employee where AllotID = @allotid", new { AllotID = allot.ID }); var emp = empList.Where(w => w.AllotID == item.ID).ToList();
if (employeeList != null && employeeList.Count() > 0) if (!emp.Any()) continue;
{ dataList = _mapper.Map<List<PerDataEmployee>>(emp);
dataList = _mapper.Map<List<PerDataEmployee>>(employeeList); break;
break;
}
} }
} }
List<im_employee> addList = new List<im_employee>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_employee>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
//imdata.OtherPerfor = data.OthePerfor;
addList.Add(imdata);
}
connection.Insert(addList.ToArray());
return imsheet.ID;
} }
var addList = new List<im_employee>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_employee>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
addList.Add(imdata);
}
db.Insertable(addList).ExecuteCommand();
return imsheet.ID;
#region 旧代码
//var imsheet = new per_sheet { AllotID =allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; //var imsheet = new per_sheet { AllotID =allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
//perforPerSheetRepository.Add(imsheet); //perforPerSheetRepository.Add(imsheet);
//var dataList = sheet.PerData.Select(t => (PerDataEmployee)t); //var dataList = sheet.PerData.Select(t => (PerDataEmployee)t);
...@@ -248,6 +225,7 @@ public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotLi ...@@ -248,6 +225,7 @@ public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotLi
//} //}
//perforImEmployeeRepository.BulkInsert(addList.ToArray()); //perforImEmployeeRepository.BulkInsert(addList.ToArray());
//return imsheet.ID; //return imsheet.ID;
#endregion
} }
/// <summary> /// <summary>
...@@ -258,37 +236,43 @@ public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotLi ...@@ -258,37 +236,43 @@ public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotLi
/// <returns></returns> /// <returns></returns>
public int SaveClinicEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotList) public int SaveClinicEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotList)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
{ var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; imsheet.ID = db.Insertable(imsheet).AS("per_sheet").ExecuteReturnIdentity();
imsheet.ID = (int)connection.Insert(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataClinicEmployee)t); var dataList = sheet.PerData.Select(t => (PerDataClinicEmployee)t);
//新上传名单中无人员名单,取到最后日期的数据 //新上传名单中无人员名单,取到最后日期的数据
if (dataList == null || dataList.Count() <= 0) if (!dataList.Any())
{
var empList = db.Ado.SqlQuery<im_employee_clinic>("select * from im_employee_clinic where AllotID = @allotid", new { AllotID = allot.ID }).ToList();
if (empList.Any())
{ {
dataList = _mapper.Map<List<PerDataClinicEmployee>>(empList);
}
else
{
empList = db.Ado.SqlQuery<im_employee_clinic>("select * from im_employee_clinic ").ToList();
foreach (var item in allotList) foreach (var item in allotList)
{ {
var employeeList = connection.Query<im_employee_clinic>("select * from im_employee_clinic where AllotID = @allotid", new { AllotID = allot.ID }); var emp = empList.Where(w => w.AllotID == item.ID).ToList();
if (employeeList != null && employeeList.Count() > 0) if (!emp.Any()) continue;
{ dataList = _mapper.Map<List<PerDataClinicEmployee>>(emp);
dataList = _mapper.Map<List<PerDataClinicEmployee>>(employeeList); break;
break;
}
} }
} }
List<im_employee_clinic> addList = new List<im_employee_clinic>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_employee_clinic>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
imdata.OtherPerfor = data.OthePerfor;
addList.Add(imdata);
}
connection.Insert(addList);
return imsheet.ID;
} }
List<im_employee_clinic> addList = new List<im_employee_clinic>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_employee_clinic>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
imdata.OtherPerfor = data.OthePerfor;
addList.Add(imdata);
}
db.Insertable(addList).ExecuteCommand();
return imsheet.ID;
} }
/// <summary> /// <summary>
...@@ -299,37 +283,42 @@ public int SaveClinicEmployee(PerSheet sheet, per_allot allot, List<per_allot> a ...@@ -299,37 +283,42 @@ public int SaveClinicEmployee(PerSheet sheet, per_allot allot, List<per_allot> a
/// <returns></returns> /// <returns></returns>
public int SaveLogisticsEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotList) public int SaveLogisticsEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotList)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
{ var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; imsheet.ID = db.Insertable(imsheet).AS("per_sheet").ExecuteReturnIdentity();
imsheet.ID = (int)connection.Insert(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataLogisticsEmployee)t); var dataList = sheet.PerData.Select(t => (PerDataLogisticsEmployee)t);
//新上传名单中无人员名单,取到最后日期的数据 //新上传名单中无人员名单,取到最后日期的数据
if (dataList == null || dataList.Count() <= 0) if (!dataList.Any())
{
var empList = db.Ado.SqlQuery<im_employee_logistics>("select * from im_employee_logistics where AllotID = @allotid", new { AllotID = allot.ID }).ToList();
if (empList.Any())
{ {
foreach (var item in allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month)) dataList = _mapper.Map<List<PerDataLogisticsEmployee>>(empList);
{
var employeeList = connection.Query<im_employee_logistics>("select * from im_employee_logistics where AllotID = @allotid", new { AllotID = allot.ID });
if (employeeList != null && employeeList.Count() > 0)
{
dataList = _mapper.Map<List<PerDataLogisticsEmployee>>(employeeList);
break;
}
}
} }
List<im_employee_logistics> addList = new List<im_employee_logistics>(); else
foreach (var data in dataList)
{ {
var imdata = _mapper.Map<im_employee_logistics>(data); empList = db.Ado.SqlQuery<im_employee_logistics>("select * from im_employee_logistics ").ToList();
imdata.SheetID = imsheet.ID; foreach (var item in allotList)
imdata.AllotID = allot.ID; {
imdata.OtherPerfor = data.OthePerfor; var emp = empList.Where(w => w.AllotID == item.ID).ToList();
addList.Add(imdata); if (!emp.Any()) continue;
dataList = _mapper.Map<List<PerDataLogisticsEmployee>>(emp);
break;
}
} }
connection.Insert(addList);
return imsheet.ID;
} }
List<im_employee_logistics> addList = new List<im_employee_logistics>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_employee_logistics>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
imdata.OtherPerfor = data.OthePerfor;
addList.Add(imdata);
}
db.Insertable(addList).ExecuteCommand();
return imsheet.ID;
} }
/// <summary> /// <summary>
...@@ -340,36 +329,31 @@ public int SaveLogisticsEmployee(PerSheet sheet, per_allot allot, List<per_allot ...@@ -340,36 +329,31 @@ public int SaveLogisticsEmployee(PerSheet sheet, per_allot allot, List<per_allot
/// <returns></returns> /// <returns></returns>
public int SaveAccountBasic(PerSheet sheet, per_allot allot, List<per_sheet> sheets) public int SaveAccountBasic(PerSheet sheet, per_allot allot, List<per_sheet> sheets)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
List<int> types = new List<int> { (int)SheetType.AccountBasicSpecial, (int)SheetType.AccountBasic };
var imsheet = sheets?.FirstOrDefault(w => w.AllotID == allot.ID && w.SheetType.HasValue && types.Contains(w.SheetType.Value));
if (imsheet != null)
{ {
//var imsheet = new per_sheet { AllotID =allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; imsheet.SheetType = (int)SheetType.AccountBasic;
//perforPerSheetRepository.Add(imsheet); db.Updateable(imsheet);
List<int> types = new List<int> { (int)SheetType.AccountBasicSpecial, (int)SheetType.AccountBasic };
var imsheet = sheets?.FirstOrDefault(w => w.AllotID == allot.ID && w.SheetType.HasValue && types.Contains(w.SheetType.Value));
if (imsheet != null)
{
imsheet.SheetType = (int)SheetType.AccountBasic;
connection.Update(imsheet);
}
else
{
imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
imsheet.ID = (int)connection.Insert(imsheet);
}
var dataList = sheet.PerData.Select(t => (PerDataAccountBaisc)t);
List<im_accountbasic> addList = new List<im_accountbasic>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_accountbasic>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
imdata.DoctorExtra = data.Extra;
addList.Add(imdata);
}
connection.Insert(addList.ToArray());
return imsheet.ID;
} }
else
{
imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
imsheet.ID = db.Insertable(imsheet).AS("per_sheet").ExecuteReturnIdentity();
}
var dataList = sheet.PerData.Select(t => (PerDataAccountBaisc)t);
List<im_accountbasic> addList = new List<im_accountbasic>();
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_accountbasic>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
imdata.DoctorExtra = data.Extra;
addList.Add(imdata);
}
db.Insertable(addList).ExecuteCommand();
return imsheet.ID;
} }
/// <summary> /// <summary>
...@@ -380,23 +364,22 @@ public int SaveAccountBasic(PerSheet sheet, per_allot allot, List<per_sheet> she ...@@ -380,23 +364,22 @@ public int SaveAccountBasic(PerSheet sheet, per_allot allot, List<per_sheet> she
/// <returns></returns> /// <returns></returns>
public int SaveSpecialUnit(PerSheet sheet, per_allot allot) public int SaveSpecialUnit(PerSheet sheet, per_allot allot)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
{ var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
var imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; imsheet.ID = db.Insertable(imsheet).AS("per_sheet").ExecuteReturnIdentity();
imsheet.ID = (int)connection.Insert(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataSpecialUnit)t); var dataList = sheet.PerData.Select(t => (PerDataSpecialUnit)t);
List<im_specialunit> addList = new List<im_specialunit>(); List<im_specialunit> addList = new List<im_specialunit>();
foreach (var data in dataList) foreach (var data in dataList)
{ {
var imdata = _mapper.Map<im_specialunit>(data); var imdata = _mapper.Map<im_specialunit>(data);
imdata.SheetID = imsheet.ID; imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID; imdata.AllotID = allot.ID;
addList.Add(imdata); addList.Add(imdata);
}
connection.Insert(addList.ToArray());
return imsheet.ID;
} }
db.Insertable(addList).ExecuteCommand();
return imsheet.ID;
} }
/// <summary> /// <summary>
...@@ -407,75 +390,83 @@ public int SaveSpecialUnit(PerSheet sheet, per_allot allot) ...@@ -407,75 +390,83 @@ public int SaveSpecialUnit(PerSheet sheet, per_allot allot)
/// <returns></returns> /// <returns></returns>
public int SaveCommon(PerSheet sheet, per_allot allot, List<per_sheet> sheets) public int SaveCommon(PerSheet sheet, per_allot allot, List<per_sheet> sheets)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
per_sheet imsheet = null;
List<int> types = new List<int> { (int)SheetType.AccountBasicSpecial, (int)SheetType.AccountBasic };
if (types.Any(type => type == (int)sheet.SheetType))
{ {
per_sheet imsheet = null; imsheet = sheets?.FirstOrDefault(w => w.AllotID == allot.ID && w.SheetType.HasValue && types.Contains(w.SheetType.Value));
List<int> types = new List<int> { (int)SheetType.AccountBasicSpecial, (int)SheetType.AccountBasic }; if (imsheet != null)
if (types.Any(type => type == (int)sheet.SheetType))
{
imsheet = sheets?.FirstOrDefault(w => w.AllotID == allot.ID && w.SheetType.HasValue && types.Contains(w.SheetType.Value));
if (imsheet != null)
{
imsheet.SheetType = (int)SheetType.AccountBasic;
connection.Update(imsheet);
}
}
if (imsheet == null)
{ {
imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType }; imsheet.SheetType = (int)SheetType.AccountBasic;
imsheet.ID = (int)connection.Insert(imsheet); db.Updateable(imsheet);
} }
}
if (imsheet == null)
{
imsheet = new per_sheet { AllotID = allot.ID, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
imsheet.ID = db.Insertable(imsheet).AS("per_sheet").ExecuteReturnIdentity();
}
List<im_data> addDataList = new List<im_data>();
var dataList = sheet.PerData.Select(t => (PerData)t);
foreach (var data in dataList)
{
var imdata = _mapper.Map<im_data>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allot.ID;
addDataList.Add(imdata);
}
if (addDataList.Any())
{
int batchSize = 1000; // 每批插入1000条记录
int total = addDataList.Count;
List<im_data> addDataList = new List<im_data>(); for (int i = 0; i < total; i += batchSize)
var dataList = sheet.PerData.Select(t => (PerData)t);
foreach (var data in dataList)
{ {
var imdata = _mapper.Map<im_data>(data); var batch = addDataList.Skip(i).Take(batchSize).ToList();
imdata.SheetID = imsheet.ID; db.Insertable(batch).ExecuteCommand();
imdata.AllotID = allot.ID;
addDataList.Add(imdata);
} }
if (addDataList != null && addDataList.Any())
{
int rows = 500;
for (int i = 0; i < Math.Ceiling((double)addDataList.Count / rows); i++)
{
connection.Insert(addDataList.Skip(rows * i).Take(rows).ToArray());
}
}
return imsheet.ID;
} }
return imsheet.ID;
} }
public void SaveHeader(PerSheet sheet, per_allot allot, int imsheetid) public void SaveHeader(PerSheet sheet, per_allot allot, int imsheetid)
{ {
using (IDbConnection connection = new MySqlConnection(_options.Value.PerformanceConnectionString)) var db = InfraRepository.GetDbclient(_options.Value.PerformanceConnectionString);
List<im_header> addHeadList = new List<im_header>();
foreach (var header in sheet.PerHeader)
{ {
List<im_header> addHeadList = new List<im_header>(); var imheader = _mapper.Map<im_header>(header);
foreach (var header in sheet.PerHeader) imheader.SheetID = imsheetid;
{ imheader.AllotID = allot.ID;
var imheader = _mapper.Map<im_header>(header); imheader.ID = db.Insertable(imheader).AS("im_header").ExecuteReturnIdentity();
imheader.SheetID = imsheetid;
imheader.AllotID = allot.ID;
imheader.ID = (int)connection.Insert(imheader);
if (header.IsHasChildren) if (header.IsHasChildren)
{
foreach (var child in header.Children)
{ {
foreach (var child in header.Children) var imheaderChild = _mapper.Map<im_header>(child);
{ imheaderChild.SheetID = imsheetid;
var imheaderChild = _mapper.Map<im_header>(child); imheaderChild.ParentID = imheader.ID;
imheaderChild.SheetID = imsheetid; imheaderChild.AllotID = allot.ID;
imheaderChild.ParentID = imheader.ID; addHeadList.Add(imheaderChild);
imheaderChild.AllotID = allot.ID;
addHeadList.Add(imheaderChild);
}
} }
} }
if (addHeadList != null && addHeadList.Any()) }
connection.Insert(addHeadList); if (addHeadList.Any())
{
int batchSize = 1000; // 每批插入1000条记录
int total = addHeadList.Count;
for (int i = 0; i < total; i += batchSize)
{
var batch = addHeadList.Skip(i).Take(batchSize).ToList();
db.Insertable(batch).ExecuteCommand();
}
} }
} }
} }
} }
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