|
|
|
@ -6,9 +6,11 @@ import com.xht.springboot.Entity.UserComment;
|
|
|
|
|
import com.xht.springboot.Entity.UserReply;
|
|
|
|
|
import com.xht.springboot.Entity.UserText;
|
|
|
|
|
import com.xht.springboot.Utils.BloomFilterUtils;
|
|
|
|
|
import com.xht.springboot.Utils.FunctionsForDB;
|
|
|
|
|
import com.xht.springboot.Utils.FuncInterFaces.DeleteFunctionForDB;
|
|
|
|
|
import com.xht.springboot.Utils.FuncInterFaces.InsertFunctionForDB;
|
|
|
|
|
import com.xht.springboot.Utils.FuncInterFaces.QueryFunctionForDB;
|
|
|
|
|
import com.xht.springboot.Utils.FuncInterFaces.UpdateFunctionForDB;
|
|
|
|
|
import com.xht.springboot.Utils.RedisAndDbOpsUtils;
|
|
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
|
|
import org.redisson.RedissonMultiLock;
|
|
|
|
|
import org.redisson.api.RLock;
|
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
@ -18,22 +20,20 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class WebHomeService {
|
|
|
|
|
@Autowired
|
|
|
|
|
WebHomeMapper webHomeMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
RedisTemplate redisTemplate;
|
|
|
|
|
@Autowired
|
|
|
|
|
BloomFilterUtils bloomFilterUtils;
|
|
|
|
|
RedisAndDbOpsUtils redisAndDbOpsUtils;
|
|
|
|
|
@Autowired
|
|
|
|
|
RedissonClient redissonClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
RedisAndDbOpsUtils redisAndDbOpsUtils;
|
|
|
|
|
RedisTemplate redisTemplate;
|
|
|
|
|
@Autowired
|
|
|
|
|
BloomFilterUtils bloomFilterUtils;
|
|
|
|
|
|
|
|
|
|
String webHomeDataCacheName = "userTxt&Cmt::";
|
|
|
|
|
String webHomeDataKey = "all";
|
|
|
|
@ -51,234 +51,140 @@ public class WebHomeService {
|
|
|
|
|
|
|
|
|
|
//获得所有文章除了评论的回复
|
|
|
|
|
public List<UserText> getWebHomeData(){
|
|
|
|
|
FunctionsForDB<List<UserText>> functionsForDB = new FunctionsForDB<List<UserText>>() {
|
|
|
|
|
QueryFunctionForDB<List<UserText>> queryFunctionForDB = new QueryFunctionForDB<List<UserText>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public List<UserText> queryFunctionForDB(String token) {
|
|
|
|
|
List<UserText> userTexts = webHomeMapper.findAllTextAndComments();
|
|
|
|
|
return userTexts;
|
|
|
|
|
public List<UserText> queryForDB(String token) {
|
|
|
|
|
List<UserText> userTexts = webHomeMapper.findAllTextAndComments();//没有返回空集合
|
|
|
|
|
if(userTexts.size()==0)
|
|
|
|
|
return null;
|
|
|
|
|
else
|
|
|
|
|
return userTexts;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return redisAndDbOpsUtils.queryNoFilter(webHomeDataCacheName,webHomeDataKey,webHomeDataLockName,functionsForDB,"");
|
|
|
|
|
return redisAndDbOpsUtils.queryNoFilter(webHomeDataCacheName,webHomeDataKey,webHomeDataLockName,queryFunctionForDB,"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<UserReply> getUserReplies(int commentid){
|
|
|
|
|
FunctionsForDB<List<UserReply>> functionsForDB = new FunctionsForDB<List<UserReply>>() {
|
|
|
|
|
QueryFunctionForDB<List<UserReply>> queryFunctionForDB = new QueryFunctionForDB<List<UserReply>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public List<UserReply> queryFunctionForDB(String token) {
|
|
|
|
|
public List<UserReply> queryForDB(String token) {
|
|
|
|
|
List<UserReply> userReplies = webHomeMapper.findRepliesByCommentId(Integer.parseInt(token));
|
|
|
|
|
return userReplies;
|
|
|
|
|
if(userReplies.size()==0)
|
|
|
|
|
return null;
|
|
|
|
|
else
|
|
|
|
|
return userReplies;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!bloomFilterUtils.queryKey(userRepliesOfCmtCacheName+commentid))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
List<UserReply> userReplies = (List<UserReply>) redisTemplate.opsForValue().get(userRepliesOfCmtCacheName+commentid);
|
|
|
|
|
if(userReplies!=null)
|
|
|
|
|
return userReplies;
|
|
|
|
|
else{
|
|
|
|
|
synchronized (WebHomeService.class){
|
|
|
|
|
userReplies = (List<UserReply>) redisTemplate.opsForValue().get(userRepliesOfCmtCacheName+commentid);
|
|
|
|
|
if(userReplies!=null)
|
|
|
|
|
return userReplies;
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userRepliesOfCmtLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if(userReplies!=null)
|
|
|
|
|
redisTemplate.opsForValue().set(userRepliesOfCmtCacheName+commentid,userReplies);
|
|
|
|
|
else
|
|
|
|
|
redisTemplate.opsForValue().set(userRepliesOfCmtCacheName+commentid,null,30,TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return userReplies;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.queryNoFilter(userRepliesOfCmtCacheName,commentid+"",userRepliesOfCmtLockName,queryFunctionForDB,commentid+"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean postUserText(UserText userText){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.insertUserText(userText);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("insert text OK "+rows);
|
|
|
|
|
System.out.println("textid "+userText.getTextid());
|
|
|
|
|
|
|
|
|
|
bloomFilterUtils.putIntoBloomFilter(userTxtCacheName+userText.getTextid());
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
InsertFunctionForDB<UserText> insertFunctionForDB = new InsertFunctionForDB<UserText>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean insertForDB(UserText data) {
|
|
|
|
|
int rows = webHomeMapper.insertUserText(data);
|
|
|
|
|
System.out.println("insert userText "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return redisAndDbOpsUtils.insertHaveFilter(userTxtCacheName,userText.getTextid()+"" ,userText,insertFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean deleteUserText(UserText userText){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.deleteUserText(userText);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("delete text OK "+rows);
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userTxtLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
redisTemplate.delete(userTxtCacheName+userText.getTextid());//删除缓存中数据
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
DeleteFunctionForDB<UserText> deleteFunctionForDB = new DeleteFunctionForDB<UserText>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteForDB(UserText data) {
|
|
|
|
|
int rows = webHomeMapper.deleteUserText(data);
|
|
|
|
|
System.out.println("delete userText "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.baseDelete(userTxtCacheName,userText.getTextid()+"",userTxtLockName,userText,deleteFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean updateUserText(UserText userText){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.updateUserText(userText);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("update text OK "+rows);
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userTxtLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
redisTemplate.delete(userTxtCacheName+userText.getTextid());//删除缓存中数据
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
UpdateFunctionForDB<UserText> userTextUpdateFunctionForDB = new UpdateFunctionForDB<UserText>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateForDB(UserText data) {
|
|
|
|
|
int rows = webHomeMapper.updateUserText(data);
|
|
|
|
|
System.out.println("update userText "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.baseUpdate(userTxtCacheName,userText.getTextid()+"",userTxtLockName,userText,userTextUpdateFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public List<UserText> findUserText(String token){
|
|
|
|
|
if(!bloomFilterUtils.queryKey(userFindTxtCacheName+token))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
List<UserText> userTexts = (List<UserText>) redisTemplate.opsForValue().get(userFindTxtCacheName+token);
|
|
|
|
|
if(userTexts!=null)
|
|
|
|
|
return userTexts;
|
|
|
|
|
else{
|
|
|
|
|
synchronized (WebHomeService.class){
|
|
|
|
|
userTexts = (List<UserText>) redisTemplate.opsForValue().get(userFindTxtCacheName+token);
|
|
|
|
|
if(userTexts!=null)
|
|
|
|
|
QueryFunctionForDB<List<UserText>> queryFunctionForDB = new QueryFunctionForDB<List<UserText>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public List<UserText> queryForDB(String token) {
|
|
|
|
|
List<UserText> userTexts = webHomeMapper.findOfTextContains(token);//查询文本中是否包含
|
|
|
|
|
userTexts.addAll(webHomeMapper.findOfTitleContains(token));//查询标题中是否包含
|
|
|
|
|
if(userTexts.size()==0)
|
|
|
|
|
return userTexts;
|
|
|
|
|
else{
|
|
|
|
|
userTexts = webHomeMapper.findOfTextContains(token);//查询文本中是否包含
|
|
|
|
|
userTexts.addAll(webHomeMapper.findOfTitleContains(token));//查询标题中是否包含
|
|
|
|
|
else
|
|
|
|
|
return userTexts;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userFindTxtLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
return redisAndDbOpsUtils.queryNoFilter(userFindTxtCacheName,token,userFindTxtLockName,queryFunctionForDB,token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if(userTexts!=null)
|
|
|
|
|
redisTemplate.opsForValue().set(userFindTxtCacheName+token,userTexts);
|
|
|
|
|
else
|
|
|
|
|
redisTemplate.opsForValue().set(userFindTxtCacheName+token,null,30,TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return userTexts;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean postUserComment(UserComment userComment){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.insertUserComment(userComment);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("insert comment OK "+rows);
|
|
|
|
|
System.out.println("commentid "+userComment.getCommentid());
|
|
|
|
|
|
|
|
|
|
bloomFilterUtils.putIntoBloomFilter(userCmtCacheName+userComment.getCommentid());
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
InsertFunctionForDB<UserComment> insertFunctionForDB = new InsertFunctionForDB<UserComment>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean insertForDB(UserComment data) {
|
|
|
|
|
int rows = webHomeMapper.insertUserComment(data);
|
|
|
|
|
System.out.println("insert userComment "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return redisAndDbOpsUtils.insertHaveFilter(userCmtCacheName,userComment.getCommentid()+"",userComment,insertFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean deleteUserComment(UserComment userComment){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.deleteUserComment(userComment);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("delete comment OK "+rows);
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userCmtLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
redisTemplate.delete(userCmtCacheName+userComment.getCommentid());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
DeleteFunctionForDB<UserComment> deleteFunctionForDB = new DeleteFunctionForDB<UserComment>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteForDB(UserComment data) {
|
|
|
|
|
int rows = webHomeMapper.deleteUserComment(data);
|
|
|
|
|
System.out.println("delete userComment "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.baseDelete(userCmtCacheName,userComment.getCommentid()+"",userCmtLockName,userComment,deleteFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean updateUserComment(UserComment userComment){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.updateUserComment(userComment);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("update comment OK "+rows);
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userCmtLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
redisTemplate.delete(userCmtCacheName+userComment.getCommentid());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
UpdateFunctionForDB<UserComment> updateFunctionForDB = new UpdateFunctionForDB<UserComment>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateForDB(UserComment data) {
|
|
|
|
|
int rows = webHomeMapper.updateUserComment(data);
|
|
|
|
|
System.out.println("update userComment "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.baseUpdate(userCmtCacheName,userComment.getCommentid()+"",userCmtLockName,userComment,updateFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -286,69 +192,48 @@ public class WebHomeService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean postUserReply(UserReply userReply){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.insertUserReply(userReply);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("insert reply OK "+rows);
|
|
|
|
|
System.out.println("replyid "+userReply.getReplyid());
|
|
|
|
|
|
|
|
|
|
bloomFilterUtils.putIntoBloomFilter(userReplyCacheName+userReply.getReplyid());
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
InsertFunctionForDB<UserReply> insertFunctionForDB = new InsertFunctionForDB<UserReply>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean insertForDB(UserReply data) {
|
|
|
|
|
int rows = webHomeMapper.insertUserReply(data);
|
|
|
|
|
System.out.println("insert userReply "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return redisAndDbOpsUtils.insertHaveFilter(userReplyCacheName,userReply.getReplyid()+"",userReply,insertFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean deleteUserReply(UserReply userReply){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.deleteUserReply(userReply);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("delete reply OK "+rows);
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userReplyLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
redisTemplate.delete(userReplyCacheName+userReply.getReplyid());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
DeleteFunctionForDB<UserReply> userReplyDeleteFunctionForDB = new DeleteFunctionForDB<UserReply>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteForDB(UserReply data) {
|
|
|
|
|
int rows = webHomeMapper.deleteUserReply(data);
|
|
|
|
|
System.out.println("delete userReply "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.baseDelete(userReplyCacheName,userReply.getReplyid()+"",userReplyLockName,userReply,userReplyDeleteFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean updateUserReply(UserReply userReply){
|
|
|
|
|
int rows=0;
|
|
|
|
|
rows = webHomeMapper.updateUserReply(userReply);
|
|
|
|
|
if(rows >= 1){
|
|
|
|
|
System.out.println("update reply OK "+rows);
|
|
|
|
|
|
|
|
|
|
RLock lock = redissonClient.getLock(userReplyLockName);
|
|
|
|
|
RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
|
|
|
|
|
|
|
|
|
|
redissonMultiLock.lock();
|
|
|
|
|
try {
|
|
|
|
|
redisTemplate.delete(userReplyCacheName+userReply.getReplyid());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
redissonMultiLock.unlock();
|
|
|
|
|
UpdateFunctionForDB<UserReply> updateFunctionForDB = new UpdateFunctionForDB<UserReply>() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateForDB(UserReply data) {
|
|
|
|
|
int rows = webHomeMapper.updateUserReply(data);
|
|
|
|
|
System.out.println("update userReply "+rows);
|
|
|
|
|
return rows >= 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return redisAndDbOpsUtils.baseUpdate(userReplyCacheName,userReply.getReplyid()+"",userReplyLockName,userReply,updateFunctionForDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Cacheable(cacheNames = "userReply",key = "#p0")
|
|
|
|
|
public UserReply selectUserReply(int id){
|
|
|
|
|
return webHomeMapper.selectUserReply(id);
|
|
|
|
|