Commit 7cc5d5f8 authored by liwei's avatar liwei

移动了定时任务的位置

parent c0ebe58d
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("用户点赞数据定时任务执行中...");
}
}
......@@ -27,6 +27,7 @@ import org.rcisoft.sys.rbac.user.entity.SysUserRbac;
import org.rcisoft.sys.rbac.user.enums.UserInfoExceptionEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
......@@ -69,9 +70,17 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
private CyRedisService cyRedisServiceImpl;
@Autowired
private DictionaryService dictionaryService;
@Autowired
private CyRedisService cyRedisService;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private MemInfoRepository memInfoRepository;
@Value("${cy.init.password}")
private String password;
/**
* 保存 会员表
* @param memInfo
......@@ -542,7 +551,9 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
return new CyPersistModel(line);
}
/***/
/**
* 用户点赞
*/
@Override
public CyPersistModel addLike(MemLikeDTO likeDTO) {
Integer userId = Integer.valueOf(CyUserUtil.getAuthenBusinessId());
......@@ -605,4 +616,42 @@ public class MemInfoServiceImpl extends ServiceImpl<MemInfoRepository,MemInfo>
return baseMapper.queryRankPaged(paginationUtility,memInfo);
}
/**
* 用户点赞 定时任务
*/
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("用户点赞数据定时任务执行中...");
}
}
package org.rcisoft.core.schedule;
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.business.memInfo.service.MemInfoService;
import org.rcisoft.business.memInfo.service.impl.MemInfoServiceImpl;
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 ScheduleTasks {
@Autowired
private MemInfoServiceImpl memInfoService;
/**
* 用户点赞数据定时任务 将点赞数据同步到对应的表中
* 会员表 点赞表
*/
@Scheduled(cron = "0 0 13 * * ?")
public void userLikeSchedule() {
memInfoService.userLikeSchedule();
}
}
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