mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2025-12-26 04:47:53 +08:00
fix:代码优化
This commit is contained in:
parent
2027d8f220
commit
f9c45d9d0b
@ -3,8 +3,6 @@ package com.abin.mallchat.common.chat.controller;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.dto.MsgReadInfoDTO;
|
||||
import com.abin.mallchat.common.chat.domain.vo.request.*;
|
||||
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberListResp;
|
||||
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberStatisticResp;
|
||||
import com.abin.mallchat.common.chat.domain.vo.response.ChatMessageReadResp;
|
||||
import com.abin.mallchat.common.chat.domain.vo.response.ChatMessageResp;
|
||||
import com.abin.mallchat.common.chat.service.ChatService;
|
||||
@ -13,7 +11,6 @@ import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.common.user.domain.enums.BlackTypeEnum;
|
||||
import com.abin.mallchat.common.user.domain.vo.response.ws.ChatMemberResp;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -24,7 +21,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -45,39 +41,10 @@ public class ChatController {
|
||||
@Autowired
|
||||
private UserCache userCache;
|
||||
|
||||
@GetMapping("/public/member/page")
|
||||
@ApiOperation("群成员列表(废弃)")
|
||||
@Deprecated
|
||||
// @FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMemberResp>> getMemberPage(@Valid MemberReq request) {
|
||||
CursorPageBaseResp<ChatMemberResp> memberPage = chatService.getMemberPage(null, request);
|
||||
filterBlackMember(memberPage);
|
||||
return ApiResult.success(memberPage);
|
||||
}
|
||||
|
||||
@GetMapping("/member/list")
|
||||
@ApiOperation("房间内的所有群成员列表-@专用(废弃)")
|
||||
@Deprecated
|
||||
public ApiResult<List<ChatMemberListResp>> getMemberList(@Valid ChatMessageMemberReq chatMessageMemberReq) {
|
||||
return ApiResult.success(chatService.getMemberList(chatMessageMemberReq));
|
||||
}
|
||||
|
||||
private void filterBlackMember(CursorPageBaseResp<ChatMemberResp> memberPage) {
|
||||
Set<String> blackMembers = getBlackUidSet();
|
||||
memberPage.getList().removeIf(a -> blackMembers.contains(a.getUid().toString()));
|
||||
}
|
||||
|
||||
private Set<String> getBlackUidSet() {
|
||||
return userCache.getBlackMap().getOrDefault(BlackTypeEnum.UID.getType(), new HashSet<>());
|
||||
}
|
||||
|
||||
@GetMapping("public/member/statistic")
|
||||
@ApiOperation("群成员人数统计")
|
||||
@Deprecated
|
||||
public ApiResult<ChatMemberStatisticResp> getMemberStatistic() {
|
||||
return ApiResult.success(chatService.getMemberStatistic());
|
||||
}
|
||||
|
||||
@GetMapping("/public/msg/page")
|
||||
@ApiOperation("消息列表")
|
||||
// @FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
@ -97,7 +64,7 @@ public class ChatController {
|
||||
@FrequencyControl(time = 5, count = 3, target = FrequencyControl.Target.UID)
|
||||
@FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.UID)
|
||||
@FrequencyControl(time = 60, count = 10, target = FrequencyControl.Target.UID)
|
||||
public ApiResult<ChatMessageResp> sendMsg(@Valid @RequestBody ChatMessageReq request) {//todo 发送给单聊
|
||||
public ApiResult<ChatMessageResp> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
||||
Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid());
|
||||
//返回完整消息格式,方便前端展示
|
||||
return ApiResult.success(chatService.getMsgResp(msgId, RequestHolder.get().getUid()));
|
||||
|
||||
@ -205,7 +205,7 @@ public class RoomAppServiceImpl implements RoomAppService {
|
||||
List<Long> memberUidList = groupMemberCache.getMemberUidList(roomGroup.getRoomId());
|
||||
WSBaseResp<WSMemberChange> ws = MemberAdapter.buildMemberRemoveWS(roomGroup.getRoomId(), member.getUid());
|
||||
pushService.sendPushMsg(ws, memberUidList);
|
||||
groupMemberCache.evictMemberUidList(member.getId());
|
||||
groupMemberCache.evictMemberUidList(room.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.event.TransactionPhase;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
|
||||
@ -82,11 +81,14 @@ public class MessageSendListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean isHotRoom(Room room) {
|
||||
return Objects.equals(HotFlagEnum.YES.getType(), room.getHotFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
* 给用户微信推送艾特好友的消息通知
|
||||
* (这个没开启,微信不让推)
|
||||
*/
|
||||
@TransactionalEventListener(classes = MessageSendEvent.class, fallbackExecution = true)
|
||||
public void publishChatToWechat(@NotNull MessageSendEvent event) {
|
||||
Message message = messageDao.getById(event.getMsgId());
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
package com.abin.mallchat.common;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
||||
import com.abin.mallchat.common.common.utils.JwtUtils;
|
||||
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||
import com.abin.mallchat.common.user.service.LoginService;
|
||||
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.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.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-08-27
|
||||
*/
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
public class DaoTest {
|
||||
public static final long UID = 12717L;
|
||||
@Autowired
|
||||
private WxMpService wxMpService;
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
|
||||
@Test
|
||||
public void jwt() {
|
||||
String login = loginService.login(UID);
|
||||
System.out.println(login);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private LoginService loginService;
|
||||
|
||||
@Test
|
||||
public void redis() {
|
||||
String s = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjExMDAyLCJjcmVhdGVUaW1lIjoxNjkzNjYzOTU1fQ.qISTe8UDzggilWqz0HKtGLrkgiG1IRGafS10qHih9iM";
|
||||
Long validUid = loginService.getValidUid(s);
|
||||
System.out.println(validUid);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private IUserBackpackService iUserBackpackService;
|
||||
|
||||
@Test
|
||||
public void acquireItem() {
|
||||
iUserBackpackService.acquireItem(UID, ItemEnum.REG_TOP100_BADGE.getId(), IdempotentEnum.UID, UID + "");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
@Test
|
||||
public void thread() throws InterruptedException {
|
||||
threadPoolTaskExecutor.execute(() -> {
|
||||
if (1 == 1) {
|
||||
log.error("123");
|
||||
throw new RuntimeException("1243");
|
||||
}
|
||||
});
|
||||
Thread.sleep(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws WxErrorException {
|
||||
WxMpQrCodeTicket wxMpQrCodeTicket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(1, 10000);
|
||||
String url = wxMpQrCodeTicket.getUrl();
|
||||
System.out.println(url);
|
||||
}
|
||||
}
|
||||
@ -113,13 +113,11 @@
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.3.19</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user