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
bb5ddeef
Commit
bb5ddeef
authored
Jan 28, 2023
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
记录异常
parent
d30ad5a2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
23 deletions
+80
-23
performance/Performance.Services/DapperService.cs
+80
-23
No files found.
performance/Performance.Services/DapperService.cs
View file @
bb5ddeef
using
Dapper
;
using
Dapper
;
using
MassTransit
;
using
MassTransit
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
Microsoft.Extensions.Options
;
using
MySql.Data.MySqlClient
;
using
MySql.Data.MySqlClient
;
using
Performance.DtoModels
;
using
Performance.DtoModels
;
...
@@ -16,10 +17,12 @@ namespace Performance.Services
...
@@ -16,10 +17,12 @@ namespace Performance.Services
public
class
DapperService
:
IAutoInjection
public
class
DapperService
:
IAutoInjection
{
{
private
readonly
IOptions
<
AppConnection
>
_options
;
private
readonly
IOptions
<
AppConnection
>
_options
;
private
readonly
ILogger
<
DapperService
>
_logger
;
public
DapperService
(
IOptions
<
AppConnection
>
options
)
public
DapperService
(
IOptions
<
AppConnection
>
options
,
ILogger
<
DapperService
>
logger
)
{
{
_options
=
options
;
_options
=
options
;
_logger
=
logger
;
}
}
#
region
数据静态存储
#
region
数据静态存储
...
@@ -57,8 +60,10 @@ public void FreezeAllot(int allotId)
...
@@ -57,8 +60,10 @@ public void FreezeAllot(int allotId)
i
++;
i
++;
}
while
(
QueryDiff
(
allotId
)
<
-
50
&&
i
<=
3
);
}
while
(
QueryDiff
(
allotId
)
<
-
50
&&
i
<=
3
);
}
}
catch
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
void
HanderFreeze
(
int
allotId
)
void
HanderFreeze
(
int
allotId
)
...
@@ -101,8 +106,9 @@ public void SecondUseTempRestore()
...
@@ -101,8 +106,9 @@ public void SecondUseTempRestore()
}
}
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
...
@@ -124,8 +130,9 @@ public void ClearAllot()
...
@@ -124,8 +130,9 @@ public void ClearAllot()
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
...
@@ -133,46 +140,52 @@ public void ClearAllot()
...
@@ -133,46 +140,52 @@ public void ClearAllot()
public
void
SyncDataToResult
(
int
allotId
)
public
void
SyncDataToResult
(
int
allotId
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
{
string
sql
=
$@"call proc_sync_datatoresult(
{
allotId
}
)"
;
string
sql
=
$@"call proc_sync_datatoresult(
{
allotId
}
)"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
)
}
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
}
public
void
PerEmployeeBackup
(
int
allotId
)
public
void
PerEmployeeBackup
(
int
allotId
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
{
string
sql
=
$@"call proc_per_employee_backup(
{
allotId
}
)"
;
string
sql
=
$@"call proc_per_employee_backup(
{
allotId
}
)"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
}
#
region
数据提取
#
region
数据提取
public
IEnumerable
<
per_dept_dic
>
GetAccountBasicAccountingUnit
(
int
hospitalId
)
public
IEnumerable
<
per_dept_dic
>
GetAccountBasicAccountingUnit
(
int
hospitalId
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
{
string
sql
=
@"select * from
string
sql
=
@"select * from
(
(
select distinct
select distinct
...
@@ -189,13 +202,15 @@ from per_dept_dic
...
@@ -189,13 +202,15 @@ from per_dept_dic
where ifnull(accountingunit, '无')<>'无'
where ifnull(accountingunit, '无')<>'无'
order by unittype,accountingunit;"
;
order by unittype,accountingunit;"
;
return
connection
.
Query
<
per_dept_dic
>(
sql
,
new
{
hospitalId
},
commandTimeout
:
60
*
60
);
return
connection
.
Query
<
per_dept_dic
>(
sql
,
new
{
hospitalId
},
commandTimeout
:
60
*
60
);
}
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
}
public
IEnumerable
<
DeptdicResponse
>
GetDepartments
(
int
allotId
)
public
IEnumerable
<
DeptdicResponse
>
GetDepartments
(
int
allotId
)
{
{
...
@@ -243,8 +258,9 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
...
@@ -243,8 +258,9 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
return
result
.
OrderBy
(
w
=>
w
.
IsVerify
).
ThenByDescending
(
t
=>
t
.
CreateTime
).
ThenBy
(
t
=>
t
.
Department
);
return
result
.
OrderBy
(
w
=>
w
.
IsVerify
).
ThenByDescending
(
t
=>
t
.
CreateTime
).
ThenBy
(
t
=>
t
.
Department
);
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
...
@@ -258,23 +274,26 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
...
@@ -258,23 +274,26 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
/// <param name="allotId"></param>
/// <param name="allotId"></param>
public
void
RestoreSecondAllot
()
public
void
RestoreSecondAllot
()
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
{
string
sql
=
$@"call proc_restore_secondallot()"
;
string
sql
=
$@"call proc_restore_secondallot()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
)
}
catch
(
Exception
ex
)
{
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
throw
;
}
}
}
}
}
public
IEnumerable
<
dynamic
>
QuerySecondPrintHead
(
int
allotId
,
string
unitType
,
string
accountingUnit
)
public
IEnumerable
<
dynamic
>
QuerySecondPrintHead
(
int
allotId
,
string
unitType
,
string
accountingUnit
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
...
@@ -283,9 +302,17 @@ public IEnumerable<dynamic> QuerySecondPrintHead(int allotId, string unitType, s
...
@@ -283,9 +302,17 @@ public IEnumerable<dynamic> QuerySecondPrintHead(int allotId, string unitType, s
return
connection
.
Query
(
sql
,
new
{
allotId
,
unitType
=
unitType
.
Replace
(
"行政后勤"
,
"行政工勤"
),
accountingUnit
},
commandTimeout
:
60
*
60
);
return
connection
.
Query
(
sql
,
new
{
allotId
,
unitType
=
unitType
.
Replace
(
"行政后勤"
,
"行政工勤"
),
accountingUnit
},
commandTimeout
:
60
*
60
);
}
}
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
public
IEnumerable
<
dynamic
>
QuerySecondPrintRow
(
int
allotId
,
string
unitType
,
string
accountingUnit
)
public
IEnumerable
<
dynamic
>
QuerySecondPrintRow
(
int
allotId
,
string
unitType
,
string
accountingUnit
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
...
@@ -293,8 +320,16 @@ public IEnumerable<dynamic> QuerySecondPrintRow(int allotId, string unitType, st
...
@@ -293,8 +320,16 @@ public IEnumerable<dynamic> QuerySecondPrintRow(int allotId, string unitType, st
return
connection
.
Query
(
sql
,
new
{
allotId
,
unitType
=
unitType
.
Replace
(
"行政后勤"
,
"行政工勤"
),
accountingUnit
},
commandTimeout
:
60
*
60
);
return
connection
.
Query
(
sql
,
new
{
allotId
,
unitType
=
unitType
.
Replace
(
"行政后勤"
,
"行政工勤"
),
accountingUnit
},
commandTimeout
:
60
*
60
);
}
}
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
public
IEnumerable
<
dynamic
>
QueryTableStructure
(
string
tableName
)
public
IEnumerable
<
dynamic
>
QueryTableStructure
(
string
tableName
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
...
@@ -303,19 +338,35 @@ public IEnumerable<dynamic> QueryTableStructure(string tableName)
...
@@ -303,19 +338,35 @@ public IEnumerable<dynamic> QueryTableStructure(string tableName)
return
connection
.
Query
(
sql
,
new
{
tableName
},
commandTimeout
:
60
*
60
);
return
connection
.
Query
(
sql
,
new
{
tableName
},
commandTimeout
:
60
*
60
);
}
}
}
}
public
IEnumerable
<
dynamic
>
QueryView
(
string
viewName
,
int
allotID
)
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
public
IEnumerable
<
dynamic
>
QueryView
(
string
viewName
,
int
allotID
)
{
try
{
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"select * from
{
viewName
}
where allotID = @allotID"
;
string
sql
=
$@"select * from
{
viewName
}
where allotID = @allotID"
;
return
connection
.
Query
(
sql
,
new
{
allotID
},
commandTimeout
:
60
*
60
);
return
connection
.
Query
(
sql
,
new
{
allotID
},
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
}
}
public
int
UpdateAllotStates
(
int
allotId
,
int
states
,
string
remark
,
int
generate
=
0
)
public
int
UpdateAllotStates
(
int
allotId
,
int
states
,
string
remark
,
int
generate
=
0
)
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
...
@@ -324,5 +375,11 @@ public int UpdateAllotStates(int allotId, int states, string remark, int generat
...
@@ -324,5 +375,11 @@ public int UpdateAllotStates(int allotId, int states, string remark, int generat
return
connection
.
Execute
(
sql
,
new
{
allotId
,
states
,
remark
,
generate
},
commandTimeout
:
60
*
60
);
return
connection
.
Execute
(
sql
,
new
{
allotId
,
states
,
remark
,
generate
},
commandTimeout
:
60
*
60
);
}
}
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
}
}
}
}
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