Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
d0d91b94
Commit
d0d91b94
authored
Nov 29, 2024
by
wyc
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ORM' into develop
parents
0650f856
ddf312c5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
257 additions
and
237 deletions
+257
-237
performance/Performance.Repository/InfraRepository.cs
+20
-0
performance/Performance.Repository/Performance.Repository.csproj
+2
-1
performance/Performance.Services/AllotCompute/EPImportDataService.cs
+17
-9
performance/Performance.Services/AllotCompute/ImportDataService.cs
+218
-227
No files found.
performance/Performance.Repository/InfraRepository.cs
0 → 100644
View file @
d0d91b94
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
=>
{
});
}
}
}
performance/Performance.Repository/Performance.Repository.csproj
View file @
d0d91b94
...
...
@@ -6,8 +6,9 @@
<ItemGroup>
<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="SqlSugarCore" Version="5.1.4.170" />
</ItemGroup>
...
...
performance/Performance.Services/AllotCompute/EPImportDataService.cs
View file @
d0d91b94
...
...
@@ -10,9 +10,11 @@
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Infrastructure.Extensions
;
using
Performance.Repository
;
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
...
...
@@ -131,18 +133,24 @@ public List<ImportData> ReadSheetData(per_allot allot)
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
tasks
=
new
List
<
Task
>(
);
foreach
(
var
sheetName
in
importDatas
.
Select
(
w
=>
w
.
SheetName
).
Distinct
())
var
db
=
InfraRepository
.
GetDbclient
(
connectionString
);
if
(
importDatas
.
Any
())
{
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
);
db
.
Fastest
<
ImportData
>().
AS
(
"im_orig_data"
).
PageSize
(
100000
).
BulkCopy
(
importDatas
);
}
Task
.
WaitAll
(
tasks
.
ToArray
());
_logManageService
.
WriteMsg
(
"保存基础数据"
,
$"基础数据保存完成!"
,
1
,
allot
.
ID
,
"ReceiveMessage"
,
true
);
}
catch
(
Exception
ex
)
...
...
performance/Performance.Services/AllotCompute/ImportDataService.cs
View file @
d0d91b94
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.IO
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
AutoMapper
;
using
AutoMapper
;
using
Dapper
;
using
Dapper.Contrib.Extensions
;
using
Microsoft.Extensions.Options
;
using
MySql.Data.MySqlClient
;
using
NPOI.HSSF.UserModel
;
using
NPOI.SS.UserModel
;
using
NPOI.XSSF.UserModel
;
...
...
@@ -16,6 +9,13 @@
using
Performance.DtoModels.AppSettings
;
using
Performance.EntityModels
;
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
{
...
...
@@ -49,10 +49,13 @@ public class ImportDataService : IAutoInjection
public
PerExcel
ReadDataAndSave
(
per_allot
allot
)
{
var
excel
=
Import
(
allot
);
Save
(
excel
,
allot
.
ID
);
var
item
=
excel
.
PerSheet
.
FirstOrDefault
(
w
=>
w
.
SheetType
==
SheetType
.
AccountBasicSpecial
);
if
(
item
!=
null
)
excel
.
PerSheet
.
Remove
(
item
);
bool
isSave
=
Save
(
excel
,
allot
.
ID
);
if
(
isSave
)
{
var
item
=
excel
.
PerSheet
.
FirstOrDefault
(
w
=>
w
.
SheetType
==
SheetType
.
AccountBasicSpecial
);
if
(
item
!=
null
)
excel
.
PerSheet
.
Remove
(
item
);
}
return
excel
;
}
...
...
@@ -123,57 +126,27 @@ private PerExcel Import(per_allot allot)
private
bool
Save
(
PerExcel
excel
,
int
allotId
)
{
var
tasks
=
new
List
<
Task
>();
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
var
db
=
InfraRepository
.
GetDbclient
(
_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
);
var
allot
=
connection
.
Get
<
per_allot
>(
allotId
);
var
allotList
=
connection
.
Query
<
per_allot
>(
"select * from per_allot where HospitalId = @HospitalId"
,
new
{
allot
.
HospitalId
}).
ToList
();
var
sheets
=
connection
.
Query
<
per_sheet
>(
"select * from per_sheet where AllotID = @allotId"
,
new
{
allotId
}).
ToList
();
var
task
=
Task
.
Factory
.
StartNew
(()
=>
{
if
(
sheet
.
SheetType
==
SheetType
.
Employee
)
{
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
);
}
SheetType
.
Employee
=>
()
=>
SaveEmployee
(
sheet
,
allot
,
allotList
),
SheetType
.
LogisticsEmployee
=>
()
=>
SaveLogisticsEmployee
(
sheet
,
allot
,
allotList
),
SheetType
.
ClinicEmployee
=>
()
=>
SaveClinicEmployee
(
sheet
,
allot
,
allotList
),
SheetType
.
AccountBasic
=>
()
=>
SaveAccountBasic
(
sheet
,
allot
,
sheets
),
SheetType
.
SpecialUnit
=>
()
=>
SaveSpecialUnit
(
sheet
,
allot
),
_
=>
()
=>
SaveCommon
(
sheet
,
allot
,
sheets
),
};
var
imsheetid
=
saveHandler
();
SaveHeader
(
sheet
,
allot
,
imsheetid
);
}
_logManageService
.
WriteMsg
(
"保存基础数据"
,
$"基础数据保存中...当前操作需要一点时间,请耐心等待"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
Task
.
WaitAll
(
tasks
.
ToArray
());
//_logManageService.WriteMsg("保存基础数据", $"基础数据保存中...当前操作需要一点时间,请耐心等待", 1, allotId, "ReceiveMessage", true);
_logManageService
.
WriteMsg
(
"保存基础数据"
,
$"基础数据保存完成!"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
return
true
;
}
...
...
@@ -186,38 +159,42 @@ private bool Save(PerExcel excel, int allotId)
/// <returns></returns>
public
int
SaveEmployee
(
PerSheet
sheet
,
per_allot
allot
,
List
<
per_allot
>
allotList
)
{
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
var
imsheet
=
new
per_sheet
{
AllotID
=
allot
.
ID
,
SheetName
=
sheet
.
SheetName
,
Source
=
1
,
SheetType
=
(
int
)
sheet
.
SheetType
};
imsheet
.
ID
=
(
int
)
connection
.
Insert
(
imsheet
);
var
db
=
InfraRepository
.
GetDbclient
(
_options
.
Value
.
PerformanceConnectionString
);
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
();
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataEmployee
)
t
);
//新上传名单中无人员名单,取到最后日期的数据
if
(
dataList
==
null
||
dataList
.
Count
()
<=
0
)
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataEmployee
)
t
);
//新上传名单中无人员名单,取到当前绩效月下的,还是没有就取倒叙日期的数据
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
)
{
var
employeeList
=
connection
.
Query
<
im_employee
>(
"select * from im_employee where AllotID = @allotid"
,
new
{
AllotID
=
allot
.
ID
});
if
(
employeeList
!=
null
&&
employeeList
.
Count
()
>
0
)
{
dataList
=
_mapper
.
Map
<
List
<
PerDataEmployee
>>(
employeeList
);
break
;
}
var
emp
=
empList
.
Where
(
w
=>
w
.
AllotID
==
item
.
ID
).
ToList
();
if
(!
emp
.
Any
())
continue
;
dataList
=
_mapper
.
Map
<
List
<
PerDataEmployee
>>(
emp
);
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 };
//perforPerSheetRepository.Add(imsheet);
//var dataList = sheet.PerData.Select(t => (PerDataEmployee)t);
...
...
@@ -248,6 +225,7 @@ public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotLi
//}
//perforImEmployeeRepository.BulkInsert(addList.ToArray());
//return imsheet.ID;
#
endregion
}
/// <summary>
...
...
@@ -258,37 +236,43 @@ public int SaveEmployee(PerSheet sheet, per_allot allot, List<per_allot> allotLi
/// <returns></returns>
public
int
SaveClinicEmployee
(
PerSheet
sheet
,
per_allot
allot
,
List
<
per_allot
>
allotList
)
{
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
var
imsheet
=
new
per_sheet
{
AllotID
=
allot
.
ID
,
SheetName
=
sheet
.
SheetName
,
Source
=
1
,
SheetType
=
(
int
)
sheet
.
SheetType
};
imsheet
.
ID
=
(
int
)
connection
.
Insert
(
imsheet
);
var
db
=
InfraRepository
.
GetDbclient
(
_options
.
Value
.
PerformanceConnectionString
);
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
();
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataClinicEmployee
)
t
);
//新上传名单中无人员名单,取到最后日期的数据
if
(
dataList
==
null
||
dataList
.
Count
()
<=
0
)
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataClinicEmployee
)
t
);
//新上传名单中无人员名单,取到最后日期的数据
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
)
{
var
employeeList
=
connection
.
Query
<
im_employee_clinic
>(
"select * from im_employee_clinic where AllotID = @allotid"
,
new
{
AllotID
=
allot
.
ID
});
if
(
employeeList
!=
null
&&
employeeList
.
Count
()
>
0
)
{
dataList
=
_mapper
.
Map
<
List
<
PerDataClinicEmployee
>>(
employeeList
);
break
;
}
var
emp
=
empList
.
Where
(
w
=>
w
.
AllotID
==
item
.
ID
).
ToList
();
if
(!
emp
.
Any
())
continue
;
dataList
=
_mapper
.
Map
<
List
<
PerDataClinicEmployee
>>(
emp
);
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>
...
...
@@ -299,37 +283,42 @@ public int SaveClinicEmployee(PerSheet sheet, per_allot allot, List<per_allot> a
/// <returns></returns>
public
int
SaveLogisticsEmployee
(
PerSheet
sheet
,
per_allot
allot
,
List
<
per_allot
>
allotList
)
{
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
var
imsheet
=
new
per_sheet
{
AllotID
=
allot
.
ID
,
SheetName
=
sheet
.
SheetName
,
Source
=
1
,
SheetType
=
(
int
)
sheet
.
SheetType
};
imsheet
.
ID
=
(
int
)
connection
.
Insert
(
imsheet
);
var
db
=
InfraRepository
.
GetDbclient
(
_options
.
Value
.
PerformanceConnectionString
);
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
();
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataLogisticsEmployee
)
t
);
//新上传名单中无人员名单,取到最后日期的数据
if
(
dataList
==
null
||
dataList
.
Count
()
<=
0
)
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataLogisticsEmployee
)
t
);
//新上传名单中无人员名单,取到最后日期的数据
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
))
{
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
;
}
}
dataList
=
_mapper
.
Map
<
List
<
PerDataLogisticsEmployee
>>(
empList
);
}
List
<
im_employee_logistics
>
addList
=
new
List
<
im_employee_logistics
>();
foreach
(
var
data
in
dataList
)
else
{
var
imdata
=
_mapper
.
Map
<
im_employee_logistics
>(
data
);
imdata
.
SheetID
=
imsheet
.
ID
;
imdata
.
AllotID
=
allot
.
ID
;
imdata
.
OtherPerfor
=
data
.
OthePerfor
;
addList
.
Add
(
imdata
);
empList
=
db
.
Ado
.
SqlQuery
<
im_employee_logistics
>(
"select * from im_employee_logistics "
).
ToList
();
foreach
(
var
item
in
allotList
)
{
var
emp
=
empList
.
Where
(
w
=>
w
.
AllotID
==
item
.
ID
).
ToList
();
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>
...
...
@@ -340,36 +329,31 @@ public int SaveLogisticsEmployee(PerSheet sheet, per_allot allot, List<per_allot
/// <returns></returns>
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 };
//perforPerSheetRepository.Add(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
;
imsheet
.
SheetType
=
(
int
)
SheetType
.
AccountBasic
;
db
.
Updateable
(
imsheet
);
}
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>
...
...
@@ -380,23 +364,22 @@ public int SaveAccountBasic(PerSheet sheet, per_allot allot, List<per_sheet> she
/// <returns></returns>
public
int
SaveSpecialUnit
(
PerSheet
sheet
,
per_allot
allot
)
{
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
var
imsheet
=
new
per_sheet
{
AllotID
=
allot
.
ID
,
SheetName
=
sheet
.
SheetName
,
Source
=
1
,
SheetType
=
(
int
)
sheet
.
SheetType
};
imsheet
.
ID
=
(
int
)
connection
.
Insert
(
imsheet
);
var
db
=
InfraRepository
.
GetDbclient
(
_options
.
Value
.
PerformanceConnectionString
);
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
();
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataSpecialUnit
)
t
);
List
<
im_specialunit
>
addList
=
new
List
<
im_specialunit
>();
foreach
(
var
data
in
dataList
)
{
var
imdata
=
_mapper
.
Map
<
im_specialunit
>(
data
);
imdata
.
SheetID
=
imsheet
.
ID
;
imdata
.
AllotID
=
allot
.
ID
;
addList
.
Add
(
imdata
);
}
connection
.
Insert
(
addList
.
ToArray
());
return
imsheet
.
ID
;
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerDataSpecialUnit
)
t
);
List
<
im_specialunit
>
addList
=
new
List
<
im_specialunit
>();
foreach
(
var
data
in
dataList
)
{
var
imdata
=
_mapper
.
Map
<
im_specialunit
>(
data
);
imdata
.
SheetID
=
imsheet
.
ID
;
imdata
.
AllotID
=
allot
.
ID
;
addList
.
Add
(
imdata
);
}
db
.
Insertable
(
addList
).
ExecuteCommand
();
return
imsheet
.
ID
;
}
/// <summary>
...
...
@@ -407,75 +390,83 @@ public int SaveSpecialUnit(PerSheet sheet, per_allot allot)
/// <returns></returns>
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
;
List
<
int
>
types
=
new
List
<
int
>
{
(
int
)
SheetType
.
AccountBasicSpecial
,
(
int
)
SheetType
.
AccountBasic
};
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
=
sheets
?.
FirstOrDefault
(
w
=>
w
.
AllotID
==
allot
.
ID
&&
w
.
SheetType
.
HasValue
&&
types
.
Contains
(
w
.
SheetType
.
Value
));
if
(
imsheet
!=
null
)
{
imsheet
=
new
per_sheet
{
AllotID
=
allot
.
ID
,
SheetName
=
sheet
.
SheetName
,
Source
=
1
,
SheetType
=
(
int
)
sheet
.
SheetType
}
;
imsheet
.
ID
=
(
int
)
connection
.
Insert
(
imsheet
);
imsheet
.
SheetType
=
(
int
)
SheetType
.
AccountBasic
;
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
>();
var
dataList
=
sheet
.
PerData
.
Select
(
t
=>
(
PerData
)
t
);
foreach
(
var
data
in
dataList
)
for
(
int
i
=
0
;
i
<
total
;
i
+=
batchSize
)
{
var
imdata
=
_mapper
.
Map
<
im_data
>(
data
);
imdata
.
SheetID
=
imsheet
.
ID
;
imdata
.
AllotID
=
allot
.
ID
;
addDataList
.
Add
(
imdata
);
var
batch
=
addDataList
.
Skip
(
i
).
Take
(
batchSize
).
ToList
();
db
.
Insertable
(
batch
).
ExecuteCommand
();
}
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
)
{
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
>();
foreach
(
var
header
in
sheet
.
PerHeader
)
{
var
imheader
=
_mapper
.
Map
<
im_header
>(
header
);
imheader
.
SheetID
=
imsheetid
;
imheader
.
AllotID
=
allot
.
ID
;
imheader
.
ID
=
(
int
)
connection
.
Insert
(
imheader
);
var
imheader
=
_mapper
.
Map
<
im_header
>(
header
);
imheader
.
SheetID
=
imsheetid
;
imheader
.
AllotID
=
allot
.
ID
;
imheader
.
ID
=
db
.
Insertable
(
imheader
).
AS
(
"im_header"
).
ExecuteReturnIdentity
();
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
;
imheaderChild
.
ParentID
=
imheader
.
ID
;
imheaderChild
.
AllotID
=
allot
.
ID
;
addHeadList
.
Add
(
imheaderChild
);
}
var
imheaderChild
=
_mapper
.
Map
<
im_header
>(
child
);
imheaderChild
.
SheetID
=
imsheetid
;
imheaderChild
.
ParentID
=
imheader
.
ID
;
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
();
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment