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
ccff03f0
Commit
ccff03f0
authored
Jun 28, 2019
by
guanchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加Redis缓存支持到relation接口
parent
5c1364fe
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
10 deletions
+83
-10
PartnerApplication.java
...main/java/com/lanren/huhu/partner/PartnerApplication.java
+2
-0
RedisConfiguration.java
...va/com/lanren/huhu/partner/config/RedisConfiguration.java
+12
-1
UserController.java
...va/com/lanren/huhu/partner/controller/UserController.java
+15
-2
UserAgentManager.java
...ava/com/lanren/huhu/partner/manager/UserAgentManager.java
+0
-1
UserManager.java
...ain/java/com/lanren/huhu/partner/manager/UserManager.java
+22
-5
User.java
src/main/java/com/lanren/huhu/partner/model/User.java
+30
-0
Result.java
src/main/java/com/lanren/huhu/partner/result/Result.java
+2
-1
No files found.
src/main/java/com/lanren/huhu/partner/PartnerApplication.java
View file @
ccff03f0
...
...
@@ -6,11 +6,13 @@ import org.springframework.boot.SpringApplication;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
;
import
org.springframework.cache.annotation.EnableCaching
;
/**
* @author houseme
*/
@SpringBootApplication
@EnableCaching
public
class
PartnerApplication
extends
SpringBootServletInitializer
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PartnerApplication
.
class
);
...
...
src/main/java/com/lanren/huhu/partner/config/RedisConfiguration.java
View file @
ccff03f0
package
com
.
lanren
.
huhu
.
partner
.
config
;
import
com.alibaba.fastjson.parser.ParserConfig
;
import
com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer
;
import
com.lanren.huhu.partner.controller.UserController
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -18,8 +22,15 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* File
*/
@Configuration
@EnableCaching
public
class
RedisConfiguration
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
RedisConfiguration
.
class
);
static
{
logger
.
info
(
"加载redis配置"
);
ParserConfig
.
getGlobalInstance
().
addAccept
(
"com.lanren.huhu.partner.model."
);
ParserConfig
.
getGlobalInstance
().
addAccept
(
"com.lanren.huhu.partner.result."
);
ParserConfig
.
getGlobalInstance
().
setAutoTypeSupport
(
true
);
}
@Bean
public
RedisCacheManager
getRedisCacheManager
(
RedisConnectionFactory
connectionFactory
)
{
...
...
src/main/java/com/lanren/huhu/partner/controller/UserController.java
View file @
ccff03f0
...
...
@@ -26,9 +26,22 @@ public class UserController {
@RequestMapping
(
value
=
"/relation"
,
method
=
RequestMethod
.
POST
)
public
Result
<
User
>
getRelation
(
@RequestBody
@Valid
User
user
,
@RequestHeader
HttpHeaders
headers
)
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"get
PartnerLevel
userId:{ },header:{},time:{}"
,
user
.
getUserId
(),
headers
.
keySet
().
toArray
(),
LocalDateTime
.
now
());
logger
.
info
(
"get
Relation
userId:{ },header:{},time:{}"
,
user
.
getUserId
(),
headers
.
keySet
().
toArray
(),
LocalDateTime
.
now
());
}
return
userManager
.
getRelation
(
user
);
User
resutrnUser
=
userManager
.
getRelationByUserId
(
user
.
getUserId
());
Result
<
User
>
result
=
new
Result
<
User
>();
result
.
setData
(
resutrnUser
);
return
result
;
}
@RequestMapping
(
value
=
"/relation/delete"
,
method
=
RequestMethod
.
POST
)
public
Result
<
String
>
deletrRelation
(
@RequestBody
@Valid
User
user
,
@RequestHeader
HttpHeaders
headers
)
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"deletrRelation userId:{ },header:{},time:{}"
,
user
.
getUserId
(),
headers
.
keySet
().
toArray
(),
LocalDateTime
.
now
());
}
userManager
.
deleteRalationByUserId
(
user
.
getUserId
());
Result
<
String
>
result
=
new
Result
<
String
>();
result
.
setData
(
"删除成功"
);
return
result
;
}
}
src/main/java/com/lanren/huhu/partner/manager/UserAgentManager.java
View file @
ccff03f0
...
...
@@ -2,7 +2,6 @@ package com.lanren.huhu.partner.manager;
import
com.lanren.huhu.partner.domain.UserAgent
;
import
com.lanren.huhu.partner.model.AgentRsp
;
import
com.lanren.huhu.partner.model.PartnerRsp
;
import
com.lanren.huhu.partner.result.Result
;
import
com.lanren.huhu.partner.service.UserAgentService
;
import
org.slf4j.Logger
;
...
...
src/main/java/com/lanren/huhu/partner/manager/UserManager.java
View file @
ccff03f0
...
...
@@ -11,6 +11,9 @@ import com.lanren.huhu.partner.service.UserAgentService;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
...
...
@@ -19,6 +22,7 @@ import java.util.ArrayList;
* @author houseme
*/
@Component
@CacheConfig
(
cacheNames
=
"user_cache"
)
public
class
UserManager
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UserManager
.
class
);
...
...
@@ -30,18 +34,31 @@ public class UserManager {
/**
* @description: 根据用户id, 查找一个用户的全部合伙人上级 和 代理商上级
* @param user
* 缓存用户邀请关系和代理商关系数据
* 缓存不能带有构造方法的Bean 所以只能返回User的Bean
* 包装Result在Cacheable注解的方法之外进行操作
* @param userId
* @return Result<User>
* @throws
* @author chen
* @date 2019-06-26 20:01
*/
public
Result
<
User
>
getRelation
(
User
user
)
{
@Cacheable
public
User
getRelationByUserId
(
Integer
userId
)
{
logger
.
info
(
"new a user object "
);
User
user
=
new
User
();
user
.
setUserId
(
userId
);
setPartnerList
(
user
);
setAgentList
(
user
);
Result
<
User
>
result
=
new
Result
<
User
>();
result
.
setData
(
user
);
return
result
;
return
user
;
}
/**
* 清理用户缓存
*/
@CacheEvict
(
key
=
"#userId"
)
public
void
deleteRalationByUserId
(
Integer
userId
)
{
logger
.
info
(
"delete user relation cache, userId: {}"
,
userId
);
}
/**
...
...
src/main/java/com/lanren/huhu/partner/model/User.java
View file @
ccff03f0
package
com
.
lanren
.
huhu
.
partner
.
model
;
import
com.lanren.huhu.partner.controller.UserController
;
import
com.lanren.huhu.partner.model.base.BaseModel
;
import
lombok.Data
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
/**
...
...
@@ -17,6 +21,8 @@ import java.util.ArrayList;
*/
@Data
public
class
User
extends
BaseModel
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
User
.
class
);
@NotNull
(
message
=
"userId 不能为空"
)
@Min
(
value
=
1
,
message
=
"userId 需要大于0"
)
private
int
userId
;
...
...
@@ -24,4 +30,28 @@ public class User extends BaseModel {
private
ArrayList
<
ParentPartner
>
partnerList
;
private
ArrayList
<
ParentAgent
>
agentList
;
/**
* 坑哦!!!!
* 这里不能添加任何的构造方法
* 不然autotype哪里会报错
* com.alibaba.fastjson.parser.ParserConfig.checkAutoType(ParserConfig.java:1180)
* if (beanInfo.creatorConstructor != null && autoTypeSupport) {
* throw new JSONException("autoType is not support. " + typeName);
* }
* 问题出在第一个判定 如果自己写了构造方法
*/
// public User(@NotNull(message = "userId 不能为空") @Min(value = 1, message = "userId 需要大于0") int userId) {
// this.userId = userId;
// logger.info("do set name");
// this.name = "testName";
// }
@Override
public
String
toString
()
{
return
"User{"
+
"userId="
+
userId
+
", partnerList="
+
partnerList
+
", agentList="
+
agentList
+
'}'
;
}
}
src/main/java/com/lanren/huhu/partner/result/Result.java
View file @
ccff03f0
package
com
.
lanren
.
huhu
.
partner
.
result
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.lanren.huhu.partner.model.base.BaseModel
;
import
com.lanren.huhu.partner.util.MessageUtil
;
/**
...
...
@@ -10,7 +11,7 @@ import com.lanren.huhu.partner.util.MessageUtil;
* @version 1.0
* @date 2016年7月18日 上午10:27:00
*/
public
class
Result
<
T
>
{
public
class
Result
<
T
>
extends
BaseModel
{
@JSONField
(
name
=
"errorCode"
)
private
int
code
;
private
String
message
;
...
...
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