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
db020cf1
Commit
db020cf1
authored
Dec 01, 2021
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志修改
parent
525d7c3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
36 deletions
+40
-36
performance/Performance.Api/Controllers/AllotController.cs
+7
-7
performance/Performance.Services/Hubs/AllotLogHub.cs
+33
-29
No files found.
performance/Performance.Api/Controllers/AllotController.cs
View file @
db020cf1
...
...
@@ -257,12 +257,12 @@ public ApiResponse GenerateAsync([CustomizeValidator(RuleSet = "Delete"), FromBo
_logManageService
.
WriteMsg
(
"生成绩效准备中"
,
$"准备生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效,请稍等!"
,
1
,
allot
.
ID
,
"ReceiveMessage"
,
true
);
_allotService
.
UpdateAllotStates
(
allot
.
ID
,
(
int
)
AllotStates
.
Wait
,
EnumHelper
.
GetDescription
(
AllotStates
.
Wait
),
allot
.
Generate
);
if
(
_evn
.
IsEnvironment
(
"Localhost"
))
{
_allotService
.
Generate
(
allot
);
}
else
{
//
if (_evn.IsEnvironment("Localhost"))
//
{
//
_allotService.Generate(allot);
//
}
//
else
//
{
_backgroundTaskQueue
.
QueueBackgroundWorkItem
(
async
token
=>
{
using
(
var
scope
=
_serviceScopeFactory
.
CreateScope
())
...
...
@@ -274,7 +274,7 @@ public ApiResponse GenerateAsync([CustomizeValidator(RuleSet = "Delete"), FromBo
});
//_publishEndpoint.Publish(allot).Wait();
}
//
}
_logManageService
.
WriteMsg
(
"等待绩效生成"
,
$"等待绩效生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效!"
,
1
,
allot
.
ID
,
"ReceiveMessage"
);
//_allotService.Generate(allot, email);
...
...
performance/Performance.Services/Hubs/AllotLogHub.cs
View file @
db020cf1
...
...
@@ -3,70 +3,74 @@
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Logging
;
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Performance.Services
{
public
class
HubGroupInfo
{
public
DateTime
AddTime
{
get
;
set
;
}
public
string
ConnectionId
{
get
;
set
;
}
}
public
class
AllotLogHub
:
Hub
{
private
readonly
ILogger
<
AllotLogHub
>
logger
;
private
readonly
IMemoryCache
cache
;
private
static
ConcurrentDictionary
<
int
,
List
<
ConnectionUser
>>
_pairs
=
new
ConcurrentDictionary
<
int
,
List
<
ConnectionUser
>>();
public
AllotLogHub
(
ILogger
<
AllotLogHub
>
logger
,
IMemoryCache
cache
)
public
AllotLogHub
(
ILogger
<
AllotLogHub
>
logger
)
{
this
.
logger
=
logger
;
this
.
cache
=
cache
;
}
public
override
Task
OnConnectedAsync
()
{
logger
.
LogDebug
(
$"日志推送 连接
{
Context
.
ConnectionId
}
"
);
return
base
.
OnConnectedAsync
();
}
public
override
Task
OnDisconnectedAsync
(
Exception
exception
)
{
var
connectionId
=
Context
.
ConnectionId
;
logger
.
LogDebug
(
$"日志推送 断开连接
{
connectionId
}
"
)
;
var
userId
=
Context
.
User
?.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
"id"
).
Value
??
""
;
string
key
=
$"AllotLogGroup_
{
connectionId
}
"
;
//1 查询用户分组信息
var
groupName
=
""
;
//2 删除数据库中用户分组数据
if
(
cache
.
TryGetValue
(
key
,
out
string
value
))
if
(!
string
.
IsNullOrEmpty
(
userId
))
{
cache
.
Remove
(
key
);
foreach
(
var
item
in
_pairs
)
{
var
conn
=
item
.
Value
.
FirstOrDefault
(
w
=>
w
.
ConnectionId
==
connectionId
);
if
(
conn
!=
null
)
{
Groups
.
RemoveFromGroupAsync
(
connectionId
,
item
.
Key
.
ToString
()).
Wait
();
logger
.
LogDebug
(
$"日志推送 断开连接
{
connectionId
}
-
{
item
.
Key
}
-
{
userId
}
"
);
}
}
}
logger
.
LogDebug
(
$"日志推送 断开连接
{
connectionId
}
-
{
groupName
}
"
);
//3 分组中删除用户
Groups
.
RemoveFromGroupAsync
(
connectionId
,
groupName
);
return
base
.
OnDisconnectedAsync
(
exception
);
}
public
async
Task
AddGroup
(
string
token
,
int
groupName
)
{
var
connectionId
=
Context
.
ConnectionId
;
string
key
=
$"AllotLogGroup_
{
connectionId
}
"
;
if
(
cache
.
TryGetValue
(
key
,
out
string
value
))
var
userId
=
Context
.
User
?.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
"id"
).
Value
??
""
;
if
(!
string
.
IsNullOrEmpty
(
userId
))
{
cache
.
Remove
(
key
);
if
(
_pairs
.
ContainsKey
(
groupName
))
_pairs
[
groupName
].
Add
(
new
ConnectionUser
{
ConnectionId
=
connectionId
,
UserId
=
userId
});
else
_pairs
[
groupName
]
=
new
List
<
ConnectionUser
>
{
new
ConnectionUser
{
ConnectionId
=
connectionId
,
UserId
=
userId
}
};
await
Groups
.
AddToGroupAsync
(
connectionId
,
groupName
.
ToString
());
}
cache
.
Set
(
key
,
groupName
,
new
TimeSpan
(
1
,
0
,
0
));
logger
.
LogDebug
(
$"日志推送 添加用户组
{
connectionId
}
-
{
groupName
}
"
);
logger
.
LogDebug
(
$"日志推送 添加用户组
{
connectionId
}
-
{
groupName
}
-
{
userId
}
"
);
}
//2 将用户插入分组
await
Groups
.
AddToGroupAsync
(
connectionId
,
groupName
.
ToString
());
}
class
ConnectionUser
{
public
string
ConnectionId
{
get
;
set
;
}
public
string
UserId
{
get
;
set
;
}
}
}
}
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