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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
64 deletions
+121
-64
performance/Performance.Services/DapperService.cs
+121
-64
No files found.
performance/Performance.Services/DapperService.cs
View file @
bb5ddeef
using
Dapper
;
using
MassTransit
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
MySql.Data.MySqlClient
;
using
Performance.DtoModels
;
...
...
@@ -16,10 +17,12 @@ namespace Performance.Services
public
class
DapperService
:
IAutoInjection
{
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
;
_logger
=
logger
;
}
#
region
数据静态存储
...
...
@@ -57,8 +60,10 @@ public void FreezeAllot(int allotId)
i
++;
}
while
(
QueryDiff
(
allotId
)
<
-
50
&&
i
<=
3
);
}
catch
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
void
HanderFreeze
(
int
allotId
)
...
...
@@ -95,14 +100,15 @@ public void SecondUseTempRestore()
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"call proc_second_restore()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
string
sql
=
$@"call proc_second_restore()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
...
...
@@ -120,12 +126,13 @@ public void ClearAllot()
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"call proc_clear_allot()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
string
sql
=
$@"call proc_clear_allot()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
...
...
@@ -133,34 +140,39 @@ public void ClearAllot()
public
void
SyncDataToResult
(
int
allotId
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"call proc_sync_datatoresult(
{
allotId
}
)"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
catch
(
Exception
)
{
throw
;
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
public
void
PerEmployeeBackup
(
int
allotId
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"call proc_per_employee_backup(
{
allotId
}
)"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
catch
(
Exception
)
{
throw
;
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
...
...
@@ -168,11 +180,12 @@ public void PerEmployeeBackup(int allotId)
public
IEnumerable
<
per_dept_dic
>
GetAccountBasicAccountingUnit
(
int
hospitalId
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
@"select * from
(
select distinct
...
...
@@ -189,11 +202,13 @@ from per_dept_dic
where ifnull(accountingunit, '无')<>'无'
order by unittype,accountingunit;"
;
return
connection
.
Query
<
per_dept_dic
>(
sql
,
new
{
hospitalId
},
commandTimeout
:
60
*
60
);
}
catch
(
Exception
)
{
throw
;
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
...
...
@@ -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
);
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
...
...
@@ -257,71 +273,112 @@ Deptdic GetDeptdic(List<per_dept_dic> dics, string department, string hISDeptNam
/// </summary>
/// <param name="allotId"></param>
public
void
RestoreSecondAllot
()
{
{
try
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
try
{
string
sql
=
$@"call proc_restore_secondallot()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
catch
(
Exception
)
{
throw
;
}
}
string
sql
=
$@"call proc_restore_secondallot()"
;
connection
.
Execute
(
sql
,
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
public
IEnumerable
<
dynamic
>
QuerySecondPrintHead
(
int
allotId
,
string
unitType
,
string
accountingUnit
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"select * from view_second_print_header where AllotId = @allotId AND UnitType = @UnitType AND AccountingUnit = @AccountingUnit"
;
return
connection
.
Query
(
sql
,
new
{
allotId
,
unitType
=
unitType
.
Replace
(
"行政后勤"
,
"行政工勤"
),
accountingUnit
},
commandTimeout
:
60
*
60
);
string
sql
=
$@"select * from view_second_print_header where AllotId = @allotId AND UnitType = @UnitType AND AccountingUnit = @AccountingUnit"
;
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
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"select * from view_second_print_row where AllotId = @allotId AND UnitType = @UnitType AND AccountingUnit = @AccountingUnit"
;
return
connection
.
Query
(
sql
,
new
{
allotId
,
unitType
=
unitType
.
Replace
(
"行政后勤"
,
"行政工勤"
),
accountingUnit
},
commandTimeout
:
60
*
60
);
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"select * from view_second_print_row where AllotId = @allotId AND UnitType = @UnitType AND AccountingUnit = @AccountingUnit"
;
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
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"select column_name,ordinal_position from information_schema.`columns` where table_schema= database() and table_name = @tableName"
;
return
connection
.
Query
(
sql
,
new
{
tableName
},
commandTimeout
:
60
*
60
);
string
sql
=
$@"select column_name,ordinal_position from information_schema.`columns` where table_schema= database() and table_name = @tableName"
;
return
connection
.
Query
(
sql
,
new
{
tableName
},
commandTimeout
:
60
*
60
);
}
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
$"SQL执行异常:
{
ex
}
"
);
throw
;
}
}
public
IEnumerable
<
dynamic
>
QueryView
(
string
viewName
,
int
allotID
)
public
IEnumerable
<
dynamic
>
QueryView
(
string
viewName
,
int
allotID
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"select * from
{
viewName
}
where allotID = @allotID"
;
return
connection
.
Query
(
sql
,
new
{
allotID
},
commandTimeout
:
60
*
60
);
string
sql
=
$@"select * from
{
viewName
}
where allotID = @allotID"
;
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
)
{
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
try
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
using
(
var
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(
connection
.
State
!=
ConnectionState
.
Open
)
connection
.
Open
();
string
sql
=
$@"update per_allot set States=@states,Remark=@remark,Generate = @generate where Id = @allotId"
;
return
connection
.
Execute
(
sql
,
new
{
allotId
,
states
,
remark
,
generate
},
commandTimeout
:
60
*
60
);
string
sql
=
$@"update per_allot set States=@states,Remark=@remark,Generate = @generate where Id = @allotId"
;
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