mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 13:43:41 +08:00
fix:本地消息表优化
This commit is contained in:
@@ -93,8 +93,8 @@ CREATE TABLE `user` (
|
||||
KEY `idx_update_time` (`update_time`) USING BTREE,
|
||||
KEY `idx_active_status_last_opt_time` (`active_status`,`last_opt_time`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=20000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户表';
|
||||
INSERT INTO `mallchat`.`user` (`id`, `name`, `avatar`, `sex`, `open_id`, `last_opt_time`, `ip_info`, `item_id`, `status`, `create_time`, `update_time`) VALUES (10001, 'ChatGPT', 'https://img1.baidu.com/it/u=3613958228,3522035000&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500', 0, '??', '2023-06-29 17:03:03.357', NULL, NULL, 0, '2023-06-29 17:03:03.357', '2023-07-01 14:56:10.271');
|
||||
INSERT INTO `mallchat`.`user` (`id`, `name`, `avatar`, `sex`, `open_id`, `last_opt_time`, `ip_info`, `item_id`, `status`, `create_time`, `update_time`) VALUES (10002, 'ChatGLM2', 'http://mms1.baidu.com/it/u=1979830414,2984779047&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=500&h=500', NULL, '450', '2023-07-01 11:58:24.605', NULL, NULL, 0, '2023-07-01 11:58:24.605', '2023-07-01 12:02:56.900');
|
||||
INSERT INTO `user` (`id`, `name`, `avatar`, `sex`, `open_id`, `last_opt_time`, `ip_info`, `item_id`, `status`, `create_time`, `update_time`) VALUES (10001, 'ChatGPT', 'https://img1.baidu.com/it/u=3613958228,3522035000&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500', 0, '??', '2023-06-29 17:03:03.357', NULL, NULL, 0, '2023-06-29 17:03:03.357', '2023-07-01 14:56:10.271');
|
||||
INSERT INTO `user` (`id`, `name`, `avatar`, `sex`, `open_id`, `last_opt_time`, `ip_info`, `item_id`, `status`, `create_time`, `update_time`) VALUES (10002, 'ChatGLM2', 'http://mms1.baidu.com/it/u=1979830414,2984779047&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=500&h=500', NULL, '450', '2023-07-01 11:58:24.605', NULL, NULL, 0, '2023-07-01 11:58:24.605', '2023-07-01 12:02:56.900');
|
||||
-- ----------------------------
|
||||
-- Table structure for user_backpack
|
||||
-- ----------------------------
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MessageAdapter {
|
||||
ChatMessageResp.Message messageVO = new ChatMessageResp.Message();
|
||||
BeanUtil.copyProperties(message, messageVO);
|
||||
messageVO.setSendTime(message.getCreateTime());
|
||||
AbstractMsgHandler msgHandler = MsgHandlerFactory.getStrategyNoNull(message.getType());
|
||||
AbstractMsgHandler<?> msgHandler = MsgHandlerFactory.getStrategyNoNull(message.getType());
|
||||
if (Objects.nonNull(msgHandler)) {
|
||||
messageVO.setBody(msgHandler.showMsg(message));
|
||||
}
|
||||
|
||||
@@ -44,13 +44,12 @@ public class RecallMsgHandler extends AbstractMsgHandler<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object showMsg(Message msg) {//todo 后期让前端来做
|
||||
public Object showMsg(Message msg) {
|
||||
MsgRecall recall = msg.getExtra().getRecall();
|
||||
User userInfo = userCache.getUserInfo(recall.getRecallUid());
|
||||
if (!Objects.equals(recall.getRecallUid(), msg.getFromUid())) {
|
||||
User userInfo = userCache.getUserInfo(recall.getRecallUid());
|
||||
return "管理员\"" + userInfo.getName() + "\"撤回了一条成员消息";
|
||||
}
|
||||
User userInfo = userCache.getUserInfo(msg.getFromUid());
|
||||
return "\"" + userInfo.getName() + "\"撤回了一条消息";
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,14 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -33,6 +36,14 @@ public class DaoTest {
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
@Test
|
||||
public void sendMQ() {
|
||||
Message<String> build = MessageBuilder.withPayload("123").build();
|
||||
rocketMQTemplate.send("test-topic", build);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jwt() {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.abin.mallchat.transaction.aspect;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.abin.mallchat.transaction.annotation.SecureInvoke;
|
||||
import com.abin.mallchat.transaction.domain.dto.SecureInvokeDTO;
|
||||
import com.abin.mallchat.transaction.domain.entity.SecureInvokeRecord;
|
||||
import com.abin.mallchat.transaction.service.SecureInvokeHolder;
|
||||
import com.abin.mallchat.transaction.service.SecureInvokeService;
|
||||
import com.abin.mallchat.utils.JsonUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -17,6 +19,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -39,7 +42,7 @@ public class SecureInvokeAspect {
|
||||
boolean async = secureInvoke.async();
|
||||
boolean inTransaction = TransactionSynchronizationManager.isActualTransactionActive();
|
||||
//非事务状态,直接执行,不做任何保证。
|
||||
if (!inTransaction) {
|
||||
if (SecureInvokeHolder.isInvoking() || !inTransaction) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
|
||||
@@ -53,6 +56,7 @@ public class SecureInvokeAspect {
|
||||
SecureInvokeRecord record = SecureInvokeRecord.builder()
|
||||
.secureInvokeDTO(dto)
|
||||
.maxRetryTimes(secureInvoke.maxRetryTimes())
|
||||
.nextRetryTime(DateUtil.offsetMinute(new Date(), (int) SecureInvokeService.RETRY_INTERVAL_MINUTES))
|
||||
.build();
|
||||
secureInvokeService.invoke(record, async);
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.abin.mallchat.transaction.service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-10-02
|
||||
*/
|
||||
public class SecureInvokeHolder {
|
||||
private static final ThreadLocal<Boolean> INVOKE_THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
public static boolean isInvoking() {
|
||||
return Objects.nonNull(INVOKE_THREAD_LOCAL.get());
|
||||
}
|
||||
|
||||
public static void setInvoking() {
|
||||
INVOKE_THREAD_LOCAL.set(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public static void invoked() {
|
||||
INVOKE_THREAD_LOCAL.remove();
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@ public class SecureInvokeService {
|
||||
public void doInvoke(SecureInvokeRecord record) {
|
||||
SecureInvokeDTO secureInvokeDTO = record.getSecureInvokeDTO();
|
||||
try {
|
||||
SecureInvokeHolder.setInvoking();
|
||||
Class<?> beanClass = Class.forName(secureInvokeDTO.getClassName());
|
||||
Object bean = SpringUtil.getBean(beanClass);
|
||||
List<String> parameterStrings = JsonUtils.toList(secureInvokeDTO.getParameterTypes(), String.class);
|
||||
@@ -118,6 +119,8 @@ public class SecureInvokeService {
|
||||
log.error("SecureInvokeService invoke fail", e);
|
||||
//执行失败,等待下次执行
|
||||
retryRecord(record, e.getMessage());
|
||||
} finally {
|
||||
SecureInvokeHolder.invoked();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user