Commit 1a591f1e authored by liwei's avatar liwei

修改了排行榜查询以及修改了点赞和定时任务

parent bc3ceeb0
......@@ -338,6 +338,7 @@ public class AppMemInfoController extends CyPaginationController<MemInfo> {
@CyEncryptSm4Anno
public CyResult like( @RequestBody MemLikeDTO likeDTO) {
CyPersistModel data = memInfoServiceImpl.addLike(likeDTO);
likeDTO.setWxOpenid(null);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
......
......@@ -156,6 +156,11 @@ public interface MemInfoRepository extends CyBaseMapper<MemInfo> {
*/
Integer addMemLikeCount(@Param("entity") MemLikeDTO likeDTO);
/**
* 点赞表 点赞数+1
*/
Integer addLikeCount(@Param("entity") MemLikeDTO likeDTO);
/**
* 查询关注的id集合
*/
......
package org.rcisoft.business.memInfo.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
@Data
......
......@@ -672,7 +672,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
String userId = CyUserUtil.getAuthenBusinessId();
//添加实名判断
userUtil.checkUserAuth("请先进行实名认证!");
//获取当前日期 例2025/2/20 获取02和20
//获取当前日期 例2025/2/20 获取02和20 用来存redis
LocalDate today = LocalDate.now();
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("MM");
DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("dd");
......@@ -696,7 +696,7 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
if (redisUserLikeCountAll != null && (int)redisUserLikeCountAll <= allCount){
//没超出总次数限制
//2.进行判断对目标用户的点赞总次数
if (redisUserLikeCount != null && (int)redisUserLikeCount <= personalAllCount){
if (redisUserLikeCount != null && (int)redisUserLikeCount < personalAllCount){
//没超出对目标用户的点赞总次数(免费+付费)
//3.判断对目标用户的点赞留言次数
if (redisUserLikeCount != null && (int)redisUserLikeCount >= userLikeLimitCount) {
......@@ -742,8 +742,20 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
throw new CyServiceException(1001,"今日对该用户点赞次数超出限制");
}
}
//给被点赞人+1点赞数
memInfoRepository.addMemLikeCount(likeDTO);
//当天 点赞表对应的记录+1
// 获取今天的最小时间(00:00:00)
LocalDateTime startOfDay = today.atStartOfDay();
// 获取今天的最大时间(23:59:59)
LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 最大时间 和 最小时间
String beginTime = startOfDay.format(formatter);
String endTime = endOfDay.format(formatter);
likeDTO.setBeginTime(beginTime);
likeDTO.setEndTime(endTime);
likeDTO.setUserId(Integer.valueOf(userId));
memInfoRepository.addLikeCount(likeDTO);
//没超出免费点赞次数
this.redisTemplate.opsForHash().increment(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, String.valueOf(likeDTO.getTargetId()), (double) 1L);
this.redisTemplate.opsForValue().increment(MemberInfoRedisBean.USER_LIKE_ALL + date + ":" + userId, (long) 1L);
......@@ -755,10 +767,8 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
cyRedisServiceImpl.expire(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, 48 * 60 * 60); // 24小时
//新增点赞数据
likeDTO.setUserId(Integer.valueOf(userId));
likeDTO.setLikeCount(0);
likeDTO.setLikeCount(1);
memInfoRepository.addLike(likeDTO);
//给被点赞人+1点赞数
memInfoRepository.addMemLikeCount(likeDTO);
return new CyPersistModel(1);
} else {
throw new CyServiceException(1001,"今日对该用户点赞次数超出限制");
......@@ -770,10 +780,8 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
cyRedisServiceImpl.expire(MemberInfoRedisBean.USER_LIKE + date + ":" + userId, 48 * 60 * 60); // 24小时
//新增点赞数据
likeDTO.setUserId(Integer.valueOf(userId));
likeDTO.setLikeCount(0);
likeDTO.setLikeCount(1);
memInfoRepository.addLike(likeDTO);
//给被点赞人+1点赞数
memInfoRepository.addMemLikeCount(likeDTO);
return new CyPersistModel(1);
} else {
//超出总次数限制
......@@ -788,73 +796,8 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
*/
@Override
public IPage<MemInfo> findRankByPagination(CyPageInfo<MemInfo> paginationUtility, MemInfo memInfo){
return baseMapper.queryRankPaged(paginationUtility,memInfo);
}
/**
* 用户点赞 定时任务
*/
public void userLikeSchedule() {
log.info("用户点赞数据定时任务执行中...");
//获取当前日期
LocalDate today = LocalDate.now();
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("MM");
DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("dd");
// 格式化并获取月份和日期 例2025/2/20 date为0220 用来获取redis的key
String month = today.format(monthFormatter);
String day = today.format(dayFormatter);
String date = month + day;
// 获取今天的最小时间(00:00:00)
LocalDateTime startOfDay = today.atStartOfDay();
// 获取今天的最大时间(23:59:59)
LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 最大时间 和 最小时间 用来查询数据库当天的数据 用来落库
String beginTime = startOfDay.format(formatter);
String endTime = endOfDay.format(formatter);
//将redis中存储的点赞数同步到opm_user_like表中
Set<String> keys = redisTemplate.keys(MemberInfoRedisBean.USER_LIKE + date + ":" + "*");
//删除1对多的key 并更新数据库
if (keys != null && !keys.isEmpty()) {
for (String key : keys) {
//截取key最后一个:后的值,为userId
int lastIndex = key.lastIndexOf(':');
Integer userId = Integer.valueOf(key.substring(lastIndex + 1));
//获取hash里的所有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));
memLikeDTO.setBeginTime(beginTime);
memLikeDTO.setEndTime(endTime);
//对点赞表 进行修改点赞数
Integer integer = memInfoRepository.updateLikeCount(memLikeDTO);
}
}
}
} else {
System.out.println("No keys found.");
}
SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog();
sysScheduledTaskLog.setTaskName("用户点赞数据定时任务");
sysScheduledTaskLog.setTaskState("成功");
sysScheduledTaskLog.setTaskTime("每2小时执行一次");
sysScheduledTaskLog.setCreateDate(new Date());
sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog);
log.info("用户点赞数据定时任务结束---");
IPage<MemInfo> memInfoIPage = baseMapper.queryRankPaged(paginationUtility, memInfo);
return memInfoIPage;
}
......
......@@ -90,15 +90,6 @@ public class ScheduleTasks {
}
/**
* 每俩小时 执行一次点赞数据定时任务 将点赞数据同步到点赞表表中
*/
@Scheduled(cron = "0 0 */2 * * ?")
public void userLikeSchedule() {
memInfoService.userLikeSchedule();
}
/**
* 定时更新访问量表
*/
......@@ -118,9 +109,9 @@ public class ScheduleTasks {
/**
* 定时更新会员表 刷新会员的被关注数和被点赞数
* 每4小时执行一次
* 每2小时执行一次
*/
@Scheduled(cron = "0 0 */4 * * ?")
@Scheduled(cron = "0 0 */2 * * ?")
public void refreshMemLikeAndFollowCountSchedule() { memInfoService.refreshMemLikeAndFollowCountSchedule(); }
}
......@@ -587,24 +587,22 @@
and ouf.target_id = #{entity.targetId}),0) AS isFollowed;
</select>
<select id="queryRankPaged" resultType="org.rcisoft.business.memInfo.entity.MemInfo">
select
m.mem_nick_name,
m.mem_liked_count,
m.mem_code,
m.avatar,
m.business_id
from mem_info m
where m.del_flag = 0
SELECT mi.business_id,mi.avatar,mi.mem_code,mi.mem_nick_name,SUM(oul.like_count) as memLikedCount
from opm_user_like oul
LEFT JOIN mem_info mi ON mi.user_id = oul.target_id
where 1=1
and mi.del_flag = '0'
<if test="entity.memSex !=null and entity.memSex != '' ">
and m.mem_sex = #{entity.memSex}
and mi.mem_sex = #{entity.memSex}
</if>
<if test="entity.beginTime !=null and entity.beginTime != '' ">
and m.create_date &gt;= #{entity.beginTime}
and oul.create_date &gt;= #{entity.beginTime}
</if>
<if test="entity.endTime !=null and entity.endTime != '' ">
and m.create_date &lt;= #{entity.endTime}
and oul.create_date &lt;= #{entity.endTime}
</if>
order by m.mem_liked_count desc
group by oul.target_id
order by memLikedCount desc
</select>
<select id="queryFollowIdById" resultType="java.lang.Integer">
select ouf.target_id from opm_user_follow ouf WHERE ouf.user_id = #{userId}
......@@ -677,6 +675,15 @@
where 1=1
and user_id = #{entity.targetId}
</insert>
<insert id="addLikeCount">
update opm_user_like
set like_count = like_count + 1
where 1=1
and user_id = #{entity.userId}
and target_id = #{entity.targetId}
and create_date &gt;= #{entity.beginTime}
and create_date &lt;= #{entity.endTime}
</insert>
<insert id="leaveMessage">
insert into mem_user_leave_message (target_id,create_by,create_date,update_by,update_date,content)
values(#{targetId},#{userId},NOW(),#{userId},NOW(),#{content})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment