Commit 4f89e919 authored by 罗林杰's avatar 罗林杰

Merge remote-tracking branch 'origin/master'

parents a7c610b6 d687221d
......@@ -30,6 +30,8 @@ import redis.clients.jedis.params.ScanParams;
import redis.clients.jedis.resps.ScanResult;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
......@@ -75,6 +77,14 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
MemInfo info = memInfoRepository.getInfoByUserId(userId);
if (!"1".equals(info.getMemRealAuthen()))
throw new CyServiceException("请先进行实名认证");
//获取当前日期 例2025/2/20 获取02和20
LocalDate today = LocalDate.now();
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("MM");
DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("dd");
// 格式化并获取月份和日期
String month = today.format(monthFormatter);
String day = today.format(dayFormatter);
String date = month + day;
//获取留言每天限制条数
List<DictData> leaveMessageConfig = dictionaryService.selectByTypes("user_leave_message_config");
DictData dictData1 = leaveMessageConfig.stream().filter(item -> item.getDictLabel().equals("leave_message_limit_count")).findFirst().orElse(null);
......@@ -85,8 +95,8 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
Integer personalAllCount = leaveMessageLimitCount + payLeaveMessageLimitCount;//(个人)免费+付费 次数限制
Integer allCount = Integer.valueOf(dictData3.getDictValue());//(所有人)总共留言次数限制
//获取redis中已存储的限制次数
Object redisLeaveMessageCount = cyRedisServiceImpl.hget(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()));
Object redisLeaveMessageCountAll = cyRedisServiceImpl.get(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + userId);
Object redisLeaveMessageCount = cyRedisServiceImpl.hget(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()));
Object redisLeaveMessageCountAll = cyRedisServiceImpl.get(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId);
//1.进行总数对比
if (redisLeaveMessageCountAll != null && (int)redisLeaveMessageCountAll <= allCount){
//没超出总次数限制
......@@ -146,8 +156,8 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
}
if (line1 > 0) {
//插入对话表成功,则更新redis
this.redisTemplate.opsForHash().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()), (double) 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + userId, (long) 1L);
this.redisTemplate.opsForHash().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), (double) 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
}
return new CyPersistModel(line);
} else if (redisLeaveMessageCount == null){
......@@ -176,8 +186,8 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
int line1 = memLeaveMessageRepository.updateUserTalk(memUserTalk);
if (line1 > 0) {
//插入对话表成功,则更新redis
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + userId, (long) 1L);
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
}
return new CyPersistModel(line1);
} else {
......@@ -185,8 +195,8 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
int line1 = memLeaveMessageRepository.insertUserTalk(memUserTalk);
if (line1 > 0) {
//插入对话表成功,则更新redis
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + userId, (long) 1L);
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
this.redisTemplate.opsForValue().increment(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId, (long) 1L);
}
}
return new CyPersistModel(line);
......@@ -223,9 +233,9 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
}
//插入对话表成功,则更新redis
if ( line1 > 0 ){
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
cyRedisServiceImpl.set(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + userId,1L, Long.valueOf(24 * 60 * 60));
cyRedisServiceImpl.expire(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, 24 * 60 * 60); // 24小时
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
cyRedisServiceImpl.set(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + date + ":" + userId,1L, Long.valueOf(48 * 60 * 60));
cyRedisServiceImpl.expire(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + date + ":" + userId, 48 * 60 * 60); // 24小时
}
return new CyPersistModel(line1);
} else {
......@@ -274,19 +284,6 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
return userLeaveMessageIPage;
}
/**
* 留言定时任务 24点时,清除redis中的留言数据
*/
public void userLeaveMessageSchedule() {
Set<String> keys1 = redisTemplate.keys(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + "*");
Set<String> keys2 = redisTemplate.keys(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE_All + "*");
for (String key : keys1) {
redisTemplate.delete(key);
}
for (String key : keys2) {
redisTemplate.delete(key);
}
}
@Override
public CyPersistModel deleteMessage(MemLeaveMessage memLeaveMessage) {
......
......@@ -46,15 +46,6 @@ public class ScheduleTasks {
}
/**
* 用户留言数据定时任务 24点时将redis中的留言数据清除
*/
@Scheduled(cron = "0 0 0 * * ?")
public void userLeaveMessageSchedule() {
memLeaveMessageService.userLeaveMessageSchedule();
}
/**
* redis订单落库
*/
......
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