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
e36acb62
Commit
e36acb62
authored
Mar 23, 2021
by
lcx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改返回日志方式
parent
9182833f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
140 additions
and
74 deletions
+140
-74
performance/Performance.Api/Controllers/AllotController.cs
+7
-6
performance/Performance.Api/Controllers/TemplateController.cs
+5
-13
performance/Performance.DtoModels/Hubs/SingleData.cs
+23
-0
performance/Performance.Services/AllotCompute/ImportDataService.cs
+8
-11
performance/Performance.Services/AllotCompute/ProcessComputService.cs
+4
-4
performance/Performance.Services/AllotService.cs
+0
-0
performance/Performance.Services/ConfigService.cs
+12
-17
performance/Performance.Services/Hubs/AllotLogHub.cs
+6
-19
performance/Performance.Services/Hubs/NotificationsService.cs
+75
-4
No files found.
performance/Performance.Api/Controllers/AllotController.cs
View file @
e36acb62
...
...
@@ -3,6 +3,7 @@
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http.Internal
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
Performance.DtoModels
;
...
...
@@ -235,13 +236,13 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody] A
if
(
allot
.
States
==
(
int
)
AllotStates
.
Wait
)
return
new
ApiResponse
(
ResponseType
.
OK
,
"当前绩效正在等待生成"
);
int
userId
=
_claim
.
GetUserId
()
;
var
uuid
=
Guid
.
NewGuid
().
ToString
(
"N"
);
_notificationsService
.
SendGenerateMessage
(
userId
,
allot
.
ID
,
$"准备生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效,请稍等!"
);
string
key
=
NotificationsService
.
AllotGenerateKeyPrefix
+
allot
.
ID
;
_notificationsService
.
SetCache
(
key
,
new
SingleData
(
Guid
.
NewGuid
().
ToString
(
"N"
),
_claim
.
GetUserId
())
);
_notificationsService
.
SendGenerateMessage
(
allot
.
ID
,
$"准备生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效,请稍等!"
);
_allotService
.
UpdateAllotStates
(
allot
.
ID
,
(
int
)
AllotStates
.
Wait
,
EnumHelper
.
GetDescription
(
AllotStates
.
Wait
),
allot
.
Generate
);
if
(
_evn
.
IsEnvironment
(
"Localhost"
))
{
_allotService
.
Generate
(
allot
,
email
,
uuid
,
userId
);
_allotService
.
Generate
(
allot
,
email
);
}
else
{
...
...
@@ -252,13 +253,13 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody] A
using
(
var
scope
=
_serviceScopeFactory
.
CreateScope
())
{
var
scopedServices
=
scope
.
ServiceProvider
.
GetRequiredService
<
AllotService
>();
scopedServices
.
Generate
(
allot
,
email
,
uuid
,
userId
);
scopedServices
.
Generate
(
allot
,
email
);
await
Task
.
Delay
(
TimeSpan
.
FromSeconds
(
5
),
token
);
}
});
}
_notificationsService
.
SendGenerateMessage
(
userId
,
allot
.
ID
,
$"等待绩效生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效,请稍等!"
);
_notificationsService
.
SendGenerateMessage
(
allot
.
ID
,
$"等待绩效生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效,请稍等!"
);
//_allotService.Generate(allot, email);
////BackgroundJob.Enqueue(() => _allotService.Generate(allot, email));
return
new
ApiResponse
(
ResponseType
.
OK
);
...
...
performance/Performance.Api/Controllers/TemplateController.cs
View file @
e36acb62
...
...
@@ -35,7 +35,7 @@ public class TemplateController : Controller
private
readonly
ExConfigService
configService
;
private
readonly
HospitalService
hospitalService
;
private
readonly
AllotService
allotService
;
private
readonly
LogManageService
log
Service
;
private
readonly
NotificationsService
notifications
Service
;
private
readonly
IServiceScopeFactory
serviceScopeFactory
;
public
TemplateController
(
...
...
@@ -49,7 +49,7 @@ public class TemplateController : Controller
ExConfigService
configService
,
HospitalService
hospitalService
,
AllotService
allotService
,
LogManageService
log
Service
,
NotificationsService
notifications
Service
,
IServiceScopeFactory
serviceScopeFactory
)
{
this
.
logger
=
logger
;
...
...
@@ -62,7 +62,7 @@ public class TemplateController : Controller
this
.
configService
=
configService
;
this
.
hospitalService
=
hospitalService
;
this
.
allotService
=
allotService
;
this
.
logService
=
log
Service
;
this
.
notificationsService
=
notifications
Service
;
this
.
serviceScopeFactory
=
serviceScopeFactory
;
}
...
...
@@ -365,18 +365,10 @@ public ApiResponse SaveFile()
/// <param name="request"></param>
[
Route
(
"returnlog"
)]
[
HttpPost
]
[
AllowAnonymous
]
public
void
ReturnLog
([
FromBody
]
SignalrLogRequest
request
)
public
void
ReturnLog
([
FromBody
]
MessageInfo
request
)
{
logger
.
LogInformation
(
"返回日志:"
+
JsonHelper
.
Serialize
(
request
));
if
(
request
.
Type
==
3
)
{
logService
.
Schedule
(
request
.
GroupName
,
ConvertHelper
.
To
<
decimal
>(
request
.
Message
),
request
.
Level
);
}
else
{
logService
.
ExtractLog
(
request
.
GroupName
,
request
.
Tag
,
request
.
Message
,
request
.
Level
);
}
notificationsService
.
SendMessage
(
claim
.
GetUserId
(),
request
);
}
/// <summary>
...
...
performance/Performance.DtoModels/Hubs/SingleData.cs
0 → 100644
View file @
e36acb62
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Performance.DtoModels
{
public
class
SingleData
{
public
string
Uuid
{
get
;
set
;
}
public
int
UserId
{
get
;
set
;
}
public
SingleData
()
{
}
public
SingleData
(
string
uuid
,
int
userId
)
{
Uuid
=
uuid
;
UserId
=
userId
;
}
}
}
performance/Performance.Services/AllotCompute/ImportDataService.cs
View file @
e36acb62
...
...
@@ -30,8 +30,7 @@ public class ImportDataService : IAutoInjection
private
PerforImspecialunitRepository
perforImspecialunitRepository
;
private
PerforImemployeeclinicRepository
perforImemployeeclinicRepository
;
private
PerforImemployeelogisticsRepository
perforImemployeelogisticsRepository
;
//private PerforLogdbugRepository logdbug;
private
readonly
LogManageService
logManageService
;
private
readonly
NotificationsService
notificationsService
;
private
ILogger
<
ImportDataService
>
logger
;
public
ImportDataService
(
PerSheetService
perSheetService
,
...
...
@@ -44,8 +43,7 @@ public class ImportDataService : IAutoInjection
PerforImspecialunitRepository
perforImspecialunitRepository
,
PerforImemployeeclinicRepository
perforImemployeeclinicRepository
,
PerforImemployeelogisticsRepository
perforImemployeelogisticsRepository
,
//PerforLogdbugRepository logdbug
LogManageService
logManageService
,
NotificationsService
notificationsService
,
ILogger
<
ImportDataService
>
logger
)
{
this
.
perSheetService
=
perSheetService
;
...
...
@@ -58,8 +56,7 @@ public class ImportDataService : IAutoInjection
this
.
perforImspecialunitRepository
=
perforImspecialunitRepository
;
this
.
perforImemployeeclinicRepository
=
perforImemployeeclinicRepository
;
this
.
perforImemployeelogisticsRepository
=
perforImemployeelogisticsRepository
;
//this.logdbug = logdbug;
this
.
logManageService
=
logManageService
;
this
.
notificationsService
=
notificationsService
;
this
.
logger
=
logger
;
}
...
...
@@ -111,7 +108,7 @@ private PerExcel Import(per_allot allot)
}
if
(
SheetType
.
Unidentifiable
!=
sheetType
)
{
logManageService
.
WriteMsg
(
"开始读取excel文件"
,
$"开始读取sheet --
{
sheet
.
SheetName
}
"
,
1
,
allot
.
ID
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allot
.
ID
,
$"开始读取excel文件:开始读取sheet --
{
sheet
.
SheetName
}
"
);
try
{
var
st
=
perSheetService
.
Sheet
(
sheet
,
isnew
);
...
...
@@ -119,7 +116,7 @@ private PerExcel Import(per_allot allot)
}
catch
(
Exception
ex
)
{
logManageService
.
WriteMsg
(
"读取excel文件"
,
ex
.
Message
.
ToString
(),
4
,
allot
.
ID
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allot
.
ID
,
$"读取excel文件:
{
ex
.
Message
}
。"
,
ComponentType
.
error
);
throw
ex
;
}
}
...
...
@@ -129,7 +126,7 @@ private PerExcel Import(per_allot allot)
isnew
=
true
;
}
}
logManageService
.
WriteMsg
(
"开始读取excel文件"
,
$"excel文件基础数据读取完成!"
,
1
,
allot
.
ID
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allot
.
ID
,
$"开始读取excel文件:excel文件基础数据读取完成!"
);
return
excel
;
}
}
...
...
@@ -391,7 +388,7 @@ private bool Save(PerExcel excel, int allotId)
{
foreach
(
var
sheet
in
excel
.
PerSheet
)
{
logManageService
.
WriteMsg
(
"保存基础数据"
,
$"开始保存数据 --
{
sheet
.
SheetName
}
"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allotId
,
$"保存基础数据:开始保存数据 --
{
sheet
.
SheetName
}
。"
);
if
(
sheet
.
SheetType
==
SheetType
.
Employee
)
{
var
imsheetid
=
SaveEmployee
(
sheet
,
allotId
);
...
...
@@ -423,7 +420,7 @@ private bool Save(PerExcel excel, int allotId)
SaveHeader
(
sheet
,
allotId
,
imsheetid
);
}
}
logManageService
.
WriteMsg
(
"保存基础数据"
,
$"基础数据保存完成!"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allotId
,
$"保存基础数据:基础数据保存完成!"
);
return
true
;
}
}
...
...
performance/Performance.Services/AllotCompute/ProcessComputService.cs
View file @
e36acb62
...
...
@@ -27,7 +27,7 @@ public class ProcessComputService : IAutoInjection
private
PerforCofdrugtypeRepository
perforCofdrugtypeRepository
;
private
PerforCofworkitemRepository
perforCofworkitemRepository
;
private
readonly
PerforRescomputeRepository
perforRescomputeRepository
;
private
readonly
LogManageService
logManage
Service
;
private
readonly
NotificationsService
notifications
Service
;
private
readonly
GuaranteeService
guaranteeService
;
private
readonly
PerforHospitalRepository
hospitalRepository
;
private
readonly
PerforPerallotRepository
perallotRepository
;
...
...
@@ -44,7 +44,7 @@ public class ProcessComputService : IAutoInjection
PerforCofdrugtypeRepository
perforCofdrugtypeRepository
,
PerforCofworkitemRepository
perforCofworkitemRepository
,
PerforRescomputeRepository
perforRescomputeRepository
,
LogManageService
logManage
Service
,
NotificationsService
notifications
Service
,
GuaranteeService
guaranteeService
,
PerforHospitalRepository
hospitalRepository
,
PerforPerallotRepository
perallotRepository
)
...
...
@@ -60,7 +60,7 @@ public class ProcessComputService : IAutoInjection
this
.
perforCofdrugtypeRepository
=
perforCofdrugtypeRepository
;
this
.
perforCofworkitemRepository
=
perforCofworkitemRepository
;
this
.
perforRescomputeRepository
=
perforRescomputeRepository
;
this
.
logManageService
=
logManage
Service
;
this
.
notificationsService
=
notifications
Service
;
this
.
guaranteeService
=
guaranteeService
;
this
.
hospitalRepository
=
hospitalRepository
;
this
.
perallotRepository
=
perallotRepository
;
...
...
@@ -162,7 +162,7 @@ public void Save(List<PerSheet> perSheets, int allotId)
{
foreach
(
var
sheet
in
perSheets
)
{
logManageService
.
WriteMsg
(
"正在生成绩效"
,
$"保存核算数据 -
{
sheet
.
SheetName
}
"
,
1
,
allotId
,
"ReceiveMessage
"
);
notificationsService
.
SendGenerateMessage
(
allotId
,
$"正在生成绩效:保存核算数据 -
{
sheet
.
SheetName
}
"
);
if
(
sheet
.
SheetType
==
SheetType
.
ComputeDoctorAccount
||
sheet
.
SheetType
==
SheetType
.
ComputeNurseAccount
)
{
SaveComputeAccount
(
sheet
,
allotId
);
...
...
performance/Performance.Services/AllotService.cs
View file @
e36acb62
This diff is collapsed.
Click to expand it.
performance/Performance.Services/ConfigService.cs
View file @
e36acb62
...
...
@@ -17,7 +17,6 @@ public class ConfigService : IAutoInjection
{
#
region
private
PerforCofdirectorRepository
_directorRepository
;
//private PerforCofdrugpropRepository _drugpropRepository;
private
PerforCofworkitemRepository
_workitemRepository
;
private
PerforCofagainRepository
_againRepository
;
private
PerforCofdrugtypeRepository
_drugtypeRepository
;
...
...
@@ -27,14 +26,12 @@ public class ConfigService : IAutoInjection
private
PerforImheaderRepository
perforImheaderRepository
;
private
PerforCofdepttypeRepository
perforCofdepttypeRepository
;
private
PerforPerapramountRepository
perapramountRepository
;
//private PerforCofcmiRepository perforCofcmiRepository;
private
PerforCofHrpDeptRepository
perforCofHrpDeptRepository
;
private
PersonService
personService
;
private
LogManageService
logManage
Service
;
private
NotificationsService
notifications
Service
;
private
ILogger
<
ConfigService
>
logger
;
public
ConfigService
(
PerforCofdirectorRepository
cofdirectorRepository
,
//PerforCofdrugpropRepository cofdrugpropRepository,
PerforCofagainRepository
againRepository
,
PerforCofdrugtypeRepository
drugtypeRepository
,
PerforPerallotRepository
perforPerAllotRepository
,
...
...
@@ -44,14 +41,12 @@ public class ConfigService : IAutoInjection
PerforImheaderRepository
perforImheaderRepository
,
PerforCofdepttypeRepository
perforCofdepttypeRepository
,
PerforPerapramountRepository
perapramountRepository
,
//PerforCofcmiRepository perforCofcmiRepository,
PerforCofHrpDeptRepository
perforCofHrpDeptRepository
,
PersonService
personService
,
LogManageService
logManage
Service
,
NotificationsService
notifications
Service
,
ILogger
<
ConfigService
>
logger
)
{
this
.
_directorRepository
=
cofdirectorRepository
;
//this._drugpropRepository = cofdrugpropRepository;
this
.
_workitemRepository
=
workitemRepository
;
this
.
_againRepository
=
againRepository
;
this
.
_drugtypeRepository
=
drugtypeRepository
;
...
...
@@ -64,7 +59,7 @@ public class ConfigService : IAutoInjection
//this.perforCofcmiRepository = perforCofcmiRepository;
this
.
perforCofHrpDeptRepository
=
perforCofHrpDeptRepository
;
this
.
personService
=
personService
;
this
.
logManageService
=
logManage
Service
;
this
.
notificationsService
=
notifications
Service
;
this
.
logger
=
logger
;
}
...
...
@@ -753,7 +748,7 @@ public void Copy(per_allot allot)
public
void
Clear
(
int
allotId
)
{
var
count
=
_directorRepository
.
DeleteData
(
allotId
);
logManageService
.
WriteMsg
(
"清理无效数据"
,
$"清理无效数据,受影响行数:
{
count
}
"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allotId
,
$"清理无效数据:清理无效数据,受影响行数:
{
count
}
。"
);
}
/// <summary>
...
...
@@ -763,7 +758,7 @@ public void Clear(int allotId)
public
void
ClearAllotData
(
int
allotId
)
{
var
count
=
_directorRepository
.
DeleteAllotData
(
allotId
);
logManageService
.
WriteMsg
(
"清理无效数据"
,
$"清理无效数据,受影响行数:
{
count
}
"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allotId
,
$"清理无效数据:清理无效数据,受影响行数:
{
count
}
。"
);
}
/// <summary>
...
...
@@ -773,7 +768,7 @@ public void ClearAllotData(int allotId)
public
void
ClearResData
(
int
allotId
)
{
var
count
=
_directorRepository
.
DeleteResData
(
allotId
);
logManageService
.
WriteMsg
(
"清理无效数据"
,
$"清理无效数据,受影响行数:
{
count
}
"
,
1
,
allotId
,
"ReceiveMessage"
,
true
);
notificationsService
.
SendGenerateMessage
(
allotId
,
$"清理无效数据:清理无效数据,受影响行数:
{
count
}
。"
);
}
/// <summary>
...
...
@@ -783,7 +778,7 @@ public void ClearResData(int allotId)
public
void
ClearAgain
(
int
againId
)
{
var
count
=
_directorRepository
.
DelAgain
(
againId
);
logManageService
.
WriteMsg
(
"清理无效数据"
,
$"清除二次绩效中无效数据,受影响行数:
{
count
}
"
,
1
,
againId
,
"ReceiveMessage"
,
true
);
//notificationsService.SendGenerateMessage(againId, $"清理无效数据:清除二次绩效中无效数据,受影响行数:{count}。"
);
}
#
endregion
...
...
@@ -838,7 +833,7 @@ private void CopyAprData(int prevAllotId, int allotId)
}
}
public
HandsonTable
GetHrpDeptHands
(
int
HospitalId
,
int
AllotId
)
public
HandsonTable
GetHrpDeptHands
(
int
HospitalId
,
int
AllotId
)
{
var
result
=
new
HandsonTable
((
int
)
SheetType
.
Unidentifiable
,
HrpDept
.
Select
(
t
=>
t
.
Value
).
ToArray
(),
HrpDept
.
Select
(
t
=>
new
collect_permission
{
...
...
@@ -866,9 +861,9 @@ public HandsonTable GetHrpDeptHands(int HospitalId,int AllotId)
return
result
;
}
public
void
SaveDepttypeHands
(
int
hospitalId
,
int
allotId
,
SaveCollectData
request
)
public
void
SaveDepttypeHands
(
int
hospitalId
,
int
allotId
,
SaveCollectData
request
)
{
var
dicData
=
CreateDataRow
(
hospitalId
,
allotId
,
request
,
HrpDept
);
var
dicData
=
CreateDataRow
(
hospitalId
,
allotId
,
request
,
HrpDept
);
List
<
cof_hrp_department
>
depts
=
new
List
<
cof_hrp_department
>();
foreach
(
var
item
in
dicData
)
...
...
@@ -884,7 +879,7 @@ public void SaveDepttypeHands(int hospitalId, int allotId,SaveCollectData reques
}
perforCofHrpDeptRepository
.
Execute
(
"delete from cof_hrp_department where HospitalId=@hospitalId and allotid = @allotid"
,
new
{
hospitalId
,
allotId
});
,
new
{
hospitalId
,
allotId
});
perforCofHrpDeptRepository
.
AddRange
(
depts
.
ToArray
());
}
...
...
@@ -897,7 +892,7 @@ public void SaveDepttypeHands(int hospitalId, int allotId,SaveCollectData reques
// 创建固定数据列
Dictionary
<
string
,
string
>
baseData
=
CreateBaseData
(
request
,
config
,
r
);
baseData
.
Add
(
nameof
(
cof_hrp_department
.
AllotId
),
allotId
.
ToString
());
baseData
.
Add
(
nameof
(
cof_hrp_department
.
HospitalId
),
hospitalId
.
ToString
());
baseData
.
Add
(
nameof
(
cof_hrp_department
.
HospitalId
),
hospitalId
.
ToString
());
allData
.
Add
(
baseData
);
}
...
...
performance/Performance.Services/Hubs/AllotLogHub.cs
View file @
e36acb62
...
...
@@ -13,29 +13,22 @@ namespace Performance.Services
[
Authorize
]
public
class
AllotLogHub
:
Hub
{
private
readonly
IMemoryCache
cache
;
private
readonly
ILogger
<
AllotLogHub
>
logger
;
private
readonly
NotificationsService
service
;
public
AllotLogHub
(
I
MemoryCache
cache
,
ILogger
<
AllotLogHub
>
logger
I
Logger
<
AllotLogHub
>
logger
,
NotificationsService
service
)
{
this
.
cache
=
cache
;
this
.
logger
=
logger
;
this
.
service
=
service
;
}
public
override
Task
OnConnectedAsync
()
{
string
key
=
Context
.
User
.
Claims
.
FirstOrDefault
(
t
=>
t
.
Type
==
"id"
)?.
Value
;
if
(!
string
.
IsNullOrEmpty
(
key
))
{
if
(
cache
.
TryGetValue
(
key
,
out
_
))
{
cache
.
Remove
(
key
);
}
cache
.
Set
(
key
,
Context
.
ConnectionId
);
}
service
.
SetCache
(
key
,
Context
.
ConnectionId
);
logger
.
LogInformation
(
$"用户在
{
DateTime
.
Now
.
ToString
(
"yyyy年MM月dd日 hh时mm分ss秒"
)}
创建连接"
);
return
base
.
OnConnectedAsync
();
}
...
...
@@ -43,13 +36,7 @@ public override Task OnConnectedAsync()
public
override
Task
OnDisconnectedAsync
(
Exception
exception
)
{
string
key
=
Context
.
User
.
Claims
.
FirstOrDefault
(
t
=>
t
.
Type
==
"id"
)?.
Value
;
if
(!
string
.
IsNullOrEmpty
(
key
))
{
if
(
cache
.
TryGetValue
(
key
,
out
_
))
{
cache
.
Remove
(
key
);
}
}
service
.
RemoveCache
(
key
);
logger
.
LogInformation
(
$"用户在
{
DateTime
.
Now
.
ToString
(
"yyyy年MM月dd日 hh时mm分ss秒"
)}
断开连接"
);
return
base
.
OnDisconnectedAsync
(
exception
);
}
...
...
performance/Performance.Services/Hubs/NotificationsService.cs
View file @
e36acb62
...
...
@@ -32,18 +32,30 @@ PerforLogdsignalrRepository repository
this
.
repository
=
repository
;
}
public
void
SendGenerateMessage
(
int
userId
,
int
allotId
,
string
message
,
ComponentType
type
=
ComponentType
.
info
)
public
const
string
AllotGenerateKeyPrefix
=
"Allot-Generate-"
;
public
void
SendGenerateMessage
(
int
allotId
,
string
message
,
ComponentType
type
=
ComponentType
.
info
)
{
var
info
=
new
MessageInfo
(
""
,
allotId
,
"生成绩效"
,
message
,
Component
.
Notification
,
type
);
SendMessage
(
userId
,
info
);
}
var
data
=
GetCache
<
SingleData
>(
AllotGenerateKeyPrefix
+
allotId
);
if
(
data
==
null
||
data
.
UserId
==
0
)
return
;
var
info
=
new
MessageInfo
(
data
.
Uuid
,
allotId
,
"生成绩效"
,
message
,
Component
.
Notification
,
type
);
SendMessage
(
data
.
UserId
,
info
);
}
public
void
SendMessage
(
int
userId
,
MessageInfo
data
)
{
string
key
=
userId
.
ToString
();
if
(
cache
.
TryGetValue
(
key
,
out
string
connectionId
)
&&
!
string
.
IsNullOrEmpty
(
connectionId
))
{
if
(
data
.
Component
==
Component
.
Progress
)
{
var
percentage
=
ConvertHelper
.
To
<
decimal
>(
data
.
Message
);
data
.
Message
=
(
data
.
Status
==
ComponentType
.
success
?
100
:
(
data
.
Status
!=
ComponentType
.
success
&&
percentage
>=
100
)
?
99
:
percentage
).
ToString
();
}
SendMessageToClient
(
connectionId
,
data
);
}
}
...
...
@@ -57,5 +69,64 @@ private void SendMessageToClient(string connectionId, MessageInfo data, string m
{
hubContext
.
Clients
.
Client
(
connectionId
).
SendAsync
(
method
,
data
.
Title
,
data
);
}
#
region
缓存
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
public
void
SetCache
(
string
key
,
object
value
)
{
if
(!
string
.
IsNullOrEmpty
(
key
))
{
if
(
cache
.
TryGetValue
(
key
,
out
_
))
{
cache
.
Remove
(
key
);
}
cache
.
Set
(
key
,
value
);
}
}
/// <summary>
/// 删除缓存
/// </summary>
/// <param name="key">缓存Key</param>
public
void
RemoveCache
(
string
key
)
{
if
(!
string
.
IsNullOrEmpty
(
key
))
{
cache
.
Remove
(
key
);
}
}
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public
T
GetCache
<
T
>(
string
key
)
where
T
:
class
{
if
(
key
==
null
)
throw
new
ArgumentNullException
(
nameof
(
key
));
return
cache
.
Get
(
key
)
as
T
;
}
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public
object
GetCache
(
string
key
)
{
if
(
key
==
null
)
throw
new
ArgumentNullException
(
nameof
(
key
));
return
cache
.
Get
(
key
);
}
#
endregion
}
}
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