Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cust-api
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李伟
cust-api
Commits
3ca5c1b4
Commit
3ca5c1b4
authored
Jan 22, 2025
by
liwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了会员点赞功能
parent
381f8618
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
8 deletions
+105
-8
likeTask.java
src/main/java/org/rcisoft/app/task/likeTask.java
+70
-0
MemberInfoRedisBean.java
...rg/rcisoft/business/memInfo/bean/MemberInfoRedisBean.java
+1
-1
MemInfoRepository.java
...a/org/rcisoft/business/memInfo/dao/MemInfoRepository.java
+17
-3
MemInfoServiceImpl.java
...oft/business/memInfo/service/impl/MemInfoServiceImpl.java
+4
-4
MemInfoMapper.xml
...esources/mapper/business/memInfo/mapper/MemInfoMapper.xml
+13
-0
No files found.
src/main/java/org/rcisoft/app/task/likeTask.java
0 → 100644
View file @
3ca5c1b4
package
org
.
rcisoft
.
app
.
task
;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.business.memInfo.bean.MemberInfoRedisBean
;
import
org.rcisoft.business.memInfo.dao.MemInfoRepository
;
import
org.rcisoft.business.memInfo.entity.MemLikeDTO
;
import
org.rcisoft.core.service.CyRedisService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
java.util.Set
;
@Component
@Slf4j
@EnableScheduling
public
class
likeTask
{
@Autowired
private
CyRedisService
cyRedisService
;
@Autowired
private
StringRedisTemplate
redisTemplate
;
@Autowired
private
MemInfoRepository
memInfoRepository
;
/**
* 用户点赞数据定时任务 将点赞数据同步到对应的表中
* 会员表 点赞表
*/
@Scheduled
(
cron
=
"0 0 10 * * ?"
)
public
void
userLikeSchedule
()
{
//将redis中存储的点赞数同步到opm_user_like表中
Set
<
String
>
keys
=
redisTemplate
.
keys
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
"*"
);
if
(
keys
!=
null
&&
!
keys
.
isEmpty
())
{
for
(
String
key
:
keys
)
{
//截取key最后一个:后的值,为userId
int
lastIndex
=
key
.
lastIndexOf
(
':'
);
Integer
userId
=
Integer
.
valueOf
(
key
.
substring
(
lastIndex
+
1
));
//获取key的所有value
Map
<
Object
,
Object
>
hmget
=
cyRedisService
.
hmget
(
key
);
if
(
hmget
!=
null
&&
!
hmget
.
isEmpty
())
{
//遍历map
for
(
Map
.
Entry
<
Object
,
Object
>
entry
:
hmget
.
entrySet
())
{
//获取目标
String
targetId
=
(
String
)
entry
.
getKey
();
//获取点赞数
Integer
likeCount
=
(
Integer
)
entry
.
getValue
();
//将redis中存储的点赞数同步到opm_user_like表中
MemLikeDTO
memLikeDTO
=
new
MemLikeDTO
();
memLikeDTO
.
setUserId
(
userId
);
memLikeDTO
.
setLikeCount
(
likeCount
);
memLikeDTO
.
setTargetId
(
Integer
.
valueOf
(
targetId
));
//对点赞表 进行增加点赞数
memInfoRepository
.
addLikeCount
(
memLikeDTO
);
//对会员表 进行增加被点赞数
memInfoRepository
.
addMemLikeCount
(
memLikeDTO
);
}
}
}
}
else
{
System
.
out
.
println
(
"No keys found."
);
}
log
.
info
(
"用户点赞数据定时任务执行中..."
);
}
}
src/main/java/org/rcisoft/business/memInfo/bean/MemberInfoRedisBean.java
View file @
3ca5c1b4
...
@@ -9,7 +9,7 @@ package org.rcisoft.business.memInfo.bean;
...
@@ -9,7 +9,7 @@ package org.rcisoft.business.memInfo.bean;
*/
*/
public
class
MemberInfoRedisBean
{
public
class
MemberInfoRedisBean
{
//总共的点赞key
//总共的点赞key
public
static
final
String
MEMBERINFO_USERLIKE
_ALL
=
"memberInfo:userLike:a
ll:"
;
public
static
final
String
MEMBERINFO_USERLIKE
ALL
=
"memberInfo:userLikeA
ll:"
;
//对每个人点赞的key
//对每个人点赞的key
public
static
final
String
MEMBERINFO_USERLIKE
=
"memberInfo:userLike:"
;
public
static
final
String
MEMBERINFO_USERLIKE
=
"memberInfo:userLike:"
;
}
}
src/main/java/org/rcisoft/business/memInfo/dao/MemInfoRepository.java
View file @
3ca5c1b4
...
@@ -38,15 +38,19 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
...
@@ -38,15 +38,19 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
*/
*/
List
<
Integer
>
selectRoleByKey
(
@Param
(
"roleKey"
)
String
roleKey
);
List
<
Integer
>
selectRoleByKey
(
@Param
(
"roleKey"
)
String
roleKey
);
//校验手机号是否重复
/**
* 校验手机号是否重复
*/
SysUserRbacDTO
checkPhoneRepeat
(
@Param
(
"userId"
)
Integer
userId
,
@Param
(
"phone"
)
String
phone
);
SysUserRbacDTO
checkPhoneRepeat
(
@Param
(
"userId"
)
Integer
userId
,
@Param
(
"phone"
)
String
phone
);
//校验身份证是否重复
/**
* 校验身份证是否重复
*/
SysUserRbacDTO
checkIdcardRepeat
(
@Param
(
"userId"
)
Integer
userId
,
@Param
(
"Idcard"
)
String
Idcard
);
SysUserRbacDTO
checkIdcardRepeat
(
@Param
(
"userId"
)
Integer
userId
,
@Param
(
"Idcard"
)
String
Idcard
);
/**
/**
* 查询详情
* 查询详情
* @param
i
d
* @param
businessI
d
* @return
* @return
*/
*/
MemInfo
selectDetailById
(
@Param
(
"businessId"
)
int
businessId
);
MemInfo
selectDetailById
(
@Param
(
"businessId"
)
int
businessId
);
...
@@ -118,6 +122,16 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
...
@@ -118,6 +122,16 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
*/
*/
Integer
addLike
(
@Param
(
"entity"
)
MemLikeDTO
likeDTO
);
Integer
addLike
(
@Param
(
"entity"
)
MemLikeDTO
likeDTO
);
/**
* 点赞表 增加点赞数
*/
Integer
addLikeCount
(
@Param
(
"entity"
)
MemLikeDTO
likeDTO
);
/**
* 会员表 增加点赞数
*/
Integer
addMemLikeCount
(
@Param
(
"entity"
)
MemLikeDTO
likeDTO
);
/**
/**
* 查询关注的id集合
* 查询关注的id集合
*/
*/
...
...
src/main/java/org/rcisoft/business/memInfo/service/impl/MemInfoServiceImpl.java
View file @
3ca5c1b4
...
@@ -553,13 +553,13 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
...
@@ -553,13 +553,13 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
//一天最多给某个人点赞的总次数
//一天最多给某个人点赞的总次数
Integer
dicCountToPersonal
=
Integer
.
valueOf
(
userLikeConfig
.
get
(
1
).
getDictValue
());
Integer
dicCountToPersonal
=
Integer
.
valueOf
(
userLikeConfig
.
get
(
1
).
getDictValue
());
//redis中 该用户对所有用户的点赞次数
//redis中 该用户对所有用户的点赞次数
Object
redisCountToAll
=
cyRedisServiceImpl
.
get
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
_
ALL
+
userId
);
Object
redisCountToAll
=
cyRedisServiceImpl
.
get
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKEALL
+
userId
);
//redis中 该用户对目标用户的点赞次数
//redis中 该用户对目标用户的点赞次数
Object
redisCountToPersonal
=
cyRedisServiceImpl
.
hget
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()));
Object
redisCountToPersonal
=
cyRedisServiceImpl
.
hget
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()));
if
(
redisCountToAll
==
null
&&
redisCountToPersonal
==
null
){
if
(
redisCountToAll
==
null
&&
redisCountToPersonal
==
null
){
//用户第一次进行点赞 设置redis缓存 24小时
//用户第一次进行点赞 设置redis缓存 24小时
//对所有用户的点赞次数存储
//对所有用户的点赞次数存储
cyRedisServiceImpl
.
set
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
_
ALL
+
userId
,
1
,
86400L
);
cyRedisServiceImpl
.
set
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKEALL
+
userId
,
1
,
86400L
);
cyRedisServiceImpl
.
hset
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()),
1
,
86400L
);
cyRedisServiceImpl
.
hset
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()),
1
,
86400L
);
likeDTO
.
setUserId
(
userId
);
likeDTO
.
setUserId
(
userId
);
int
line
=
baseMapper
.
addLike
(
likeDTO
);
int
line
=
baseMapper
.
addLike
(
likeDTO
);
...
@@ -569,7 +569,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
...
@@ -569,7 +569,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
//判断点赞总数限制
//判断点赞总数限制
if
(((
int
)
redisCountToAll
<
dicCountToAll
)){
if
(((
int
)
redisCountToAll
<
dicCountToAll
)){
//条件限制都满足 点赞次数都+1
//条件限制都满足 点赞次数都+1
cyRedisServiceImpl
.
incr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
_
ALL
+
userId
,
1L
);
cyRedisServiceImpl
.
incr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKEALL
+
userId
,
1L
);
cyRedisServiceImpl
.
hincr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()),
(
double
)
1L
);
cyRedisServiceImpl
.
hincr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()),
(
double
)
1L
);
likeDTO
.
setUserId
(
userId
);
likeDTO
.
setUserId
(
userId
);
int
line
=
baseMapper
.
addLike
(
likeDTO
);
int
line
=
baseMapper
.
addLike
(
likeDTO
);
...
@@ -583,7 +583,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
...
@@ -583,7 +583,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
//判断个人点赞次数限制
//判断个人点赞次数限制
if
((
int
)
redisCountToPersonal
<
dicCountToPersonal
){
if
((
int
)
redisCountToPersonal
<
dicCountToPersonal
){
//条件限制都满足 点赞次数都+1
//条件限制都满足 点赞次数都+1
cyRedisServiceImpl
.
incr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
_
ALL
+
userId
,
1L
);
cyRedisServiceImpl
.
incr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKEALL
+
userId
,
1L
);
cyRedisServiceImpl
.
hincr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()),
(
double
)
1L
);
cyRedisServiceImpl
.
hincr
(
MemberInfoRedisBean
.
MEMBERINFO_USERLIKE
+
userId
,
String
.
valueOf
(
likeDTO
.
getTargetId
()),
(
double
)
1L
);
}
else
{
}
else
{
throw
new
CyServiceException
(
"点赞失败,今日对该用户的点赞次数已达上限"
);
throw
new
CyServiceException
(
"点赞失败,今日对该用户的点赞次数已达上限"
);
...
...
src/main/resources/mapper/business/memInfo/mapper/MemInfoMapper.xml
View file @
3ca5c1b4
...
@@ -561,4 +561,17 @@
...
@@ -561,4 +561,17 @@
insert into opm_user_like (target_id,user_id,create_date,like_count)
insert into opm_user_like (target_id,user_id,create_date,like_count)
values(#{entity.targetId},#{entity.userId},NOW(),#{entity.likeCount})
values(#{entity.targetId},#{entity.userId},NOW(),#{entity.likeCount})
</insert>
</insert>
<insert
id=
"addLikeCount"
>
update opm_user_like
set like_count = like_count + #{entity.likeCount}
where 1=1
and target_id = #{entity.targetId}
and user_id = #{entity.userId}
</insert>
<insert
id=
"addMemLikeCount"
>
update mem_info
set mem_liked_count = mem_liked_count + #{entity.likeCount}
where 1=1
and user_id = #{entity.targetId}
</insert>
</mapper>
</mapper>
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