Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
huhu-partner
Project
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guanchen
huhu-partner
Commits
faa5cc0e
Commit
faa5cc0e
authored
Jul 02, 2019
by
guanchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加分布式锁
parent
7c77db91
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
4 deletions
+26
-4
pom.xml
pom.xml
+5
-0
PartnerApplication.java
...main/java/com/lanren/huhu/partner/PartnerApplication.java
+2
-0
Constants.java
...ain/java/com/lanren/huhu/partner/constants/Constants.java
+1
-0
AgentRewardQueueTask.java
...om/lanren/huhu/partner/schedule/AgentRewardQueueTask.java
+16
-2
application.yml
src/main/resources/application.yml
+2
-2
No files found.
pom.xml
View file @
faa5cc0e
...
...
@@ -132,6 +132,11 @@
<artifactId>
snakeyaml
</artifactId>
<version>
1.24
</version>
</dependency>
<dependency>
<groupId>
org.redisson
</groupId>
<artifactId>
redisson
</artifactId>
<version>
3.7.5
</version>
</dependency>
</dependencies>
<profiles>
...
...
src/main/java/com/lanren/huhu/partner/PartnerApplication.java
View file @
faa5cc0e
...
...
@@ -33,6 +33,8 @@ public class PartnerApplication extends SpringBootServletInitializer {
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"PartnerApplication>>服务启动失败"
,
e
);
e
.
printStackTrace
();
...
...
src/main/java/com/lanren/huhu/partner/constants/Constants.java
View file @
faa5cc0e
...
...
@@ -24,6 +24,7 @@ public class Constants {
public
static
final
int
AGENT_LEVEL_3
=
3
;
public
static
final
int
AGENT_LEVEL_4
=
4
;
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd hh:mm:ss"
;
public
static
final
String
DISTRIBUTE_REDIS_LOCK_KEY
=
"huhu:partner:distribute:redis:key"
;
static
{
AGENT_RATE_MAP
.
put
(
AGENT_REWARD_TYPE_YEAR_VIP
,
new
HashMap
<
Integer
,
BigDecimal
>());
...
...
src/main/java/com/lanren/huhu/partner/schedule/AgentRewardQueueTask.java
View file @
faa5cc0e
...
...
@@ -11,6 +11,7 @@ import com.lanren.huhu.partner.service.AgentRewardService;
import
com.lanren.huhu.partner.service.PartnerAccountService
;
import
com.lanren.huhu.partner.service.UserAgentService
;
import
com.lanren.huhu.partner.service.UserService
;
import
com.lanren.huhu.partner.util.LockUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -52,7 +53,7 @@ public class AgentRewardQueueTask {
@Autowired
PartnerAccountService
partnerAccountService
;
@Scheduled
(
fixedDelay
=
1
000L
)
@Scheduled
(
fixedDelay
=
5
000L
)
public
void
runScheduledTask
()
{
logger
.
info
(
"run AgentRewardQueueTask"
);
runConsume
();
...
...
@@ -64,7 +65,19 @@ public class AgentRewardQueueTask {
while
(
null
!=
ops
&&
null
!=
ops
.
size
(
AGENT_REWARD_QUEUE_KEY
)
&&
ops
.
size
(
AGENT_REWARD_QUEUE_KEY
)
>
0L
)
{
String
msg
=
""
;
try
{
/**
* 加分布式锁
*/
LockUtil
.
lock
(
DISTRIBUTE_REDIS_LOCK_KEY
);
try
{
msg
=
ops
.
rightPop
(
AGENT_REWARD_QUEUE_KEY
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
continue
;
}
finally
{
LockUtil
.
unlock
(
DISTRIBUTE_REDIS_LOCK_KEY
);
}
logger
.
info
(
"msg is {}"
,
msg
);
JSONObject
json
=
JSON
.
parseObject
(
msg
);
AgentRewardMessage
message
=
json
.
toJavaObject
(
AgentRewardMessage
.
class
);
...
...
@@ -179,7 +192,8 @@ public class AgentRewardQueueTask {
agentReward
.
setAmount
(
message
.
getAgentReward
().
multiply
(
commissionRate
));
agentReward
.
setSourceOrder
(
message
.
getReferenceId
());
agentReward
.
setSourceUserLevel
(
sourceUserLevel
);
if
(
agentRewardService
.
insertOrUpdate
(
agentReward
)
>
0
)
{
agentReward
.
setCreatedAt
(
System
.
currentTimeMillis
()
/
1000L
);
if
(
agentRewardService
.
save
(
agentReward
))
{
return
true
;
}
else
{
return
false
;
...
...
src/main/resources/application.yml
View file @
faa5cc0e
...
...
@@ -92,15 +92,15 @@ mybatis:
configuration
:
#配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性。
map-underscore-to-camel-case
:
true
log-impl
:
org.apache.ibatis.logging.slf4j.Slf4jImpl
mybatis-plus
:
type-aliases-package
:
com.lanren.huhu.partner.domain
mapper-locations
:
classpath:mapper/*.xml
logging
:
level
:
#打印SQL信息
com.
hehe.mapper
:
debug
com.
lanren.huhu.partner.dao
:
debug
...
...
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