mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-17 00:03:48 +08:00
用户徽章佩戴和发放
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
package com.abin.mallchat.common.chat.domain.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 消息标记请求
|
||||||
|
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||||
|
* Date: 2023-03-29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ChatMessageMarkDTO {
|
||||||
|
@ApiModelProperty("消息id")
|
||||||
|
private Long msgId;
|
||||||
|
|
||||||
|
@ApiModelProperty("标记类型 1点赞 2举报")
|
||||||
|
private Integer markType;
|
||||||
|
|
||||||
|
@ApiModelProperty("动作类型 1确认 2取消")
|
||||||
|
private Integer actType;
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import org.aspectj.lang.reflect.MethodSignature;
|
|||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.expression.EvaluationContext;
|
import org.springframework.expression.EvaluationContext;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
@@ -35,6 +36,7 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
|
@Order(0)//确保比事务注解先执行,分布式锁在事务外
|
||||||
public class RedissonLockAspect {
|
public class RedissonLockAspect {
|
||||||
@Autowired
|
@Autowired
|
||||||
private LockService lockService;
|
private LockService lockService;
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.abin.mallchat.common.common.event;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.UserBackpack;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class ItemReceiveEvent extends ApplicationEvent {
|
||||||
|
private UserBackpack userBackpack;
|
||||||
|
|
||||||
|
public ItemReceiveEvent(Object source, UserBackpack userBackpack) {
|
||||||
|
super(source);
|
||||||
|
this.userBackpack = userBackpack;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.abin.mallchat.common.common.event;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class MessageMarkEvent extends ApplicationEvent {
|
||||||
|
private ChatMessageMarkDTO dto;
|
||||||
|
|
||||||
|
public MessageMarkEvent(Object source, ChatMessageMarkDTO dto) {
|
||||||
|
super(source);
|
||||||
|
this.dto = dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.abin.mallchat.custom.common.event;
|
package com.abin.mallchat.common.common.event;
|
||||||
|
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.abin.mallchat.custom.common.event;
|
package com.abin.mallchat.common.common.event;
|
||||||
|
|
||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.abin.mallchat.custom.common.event;
|
package com.abin.mallchat.common.common.event;
|
||||||
|
|
||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.abin.mallchat.custom.common.event;
|
package com.abin.mallchat.common.common.event;
|
||||||
|
|
||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -18,8 +18,8 @@ import java.util.stream.Collectors;
|
|||||||
public enum ItemEnum {
|
public enum ItemEnum {
|
||||||
MODIFY_NAME_CARD(1L, ItemTypeEnum.MODIFY_NAME_CARD, "改名卡"),
|
MODIFY_NAME_CARD(1L, ItemTypeEnum.MODIFY_NAME_CARD, "改名卡"),
|
||||||
LIKE_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
|
LIKE_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
|
||||||
REG_TOP10_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
|
REG_TOP10_BADGE(3L, ItemTypeEnum.BADGE, "前十注册徽章"),
|
||||||
REG_TOP100_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
|
REG_TOP100_BADGE(4L, ItemTypeEnum.BADGE, "前100注册徽章"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.abin.mallchat.common.user.service.impl;
|
|||||||
import com.abin.mallchat.common.common.annotation.RedissonLock;
|
import com.abin.mallchat.common.common.annotation.RedissonLock;
|
||||||
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
||||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||||
|
import com.abin.mallchat.common.common.event.ItemReceiveEvent;
|
||||||
import com.abin.mallchat.common.user.dao.ItemConfigDao;
|
import com.abin.mallchat.common.user.dao.ItemConfigDao;
|
||||||
import com.abin.mallchat.common.user.dao.UserBackpackDao;
|
import com.abin.mallchat.common.user.dao.UserBackpackDao;
|
||||||
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
|
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
|
||||||
@@ -11,7 +12,10 @@ import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
|
|||||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||||
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.event.SpringApplicationEvent;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -31,6 +35,8 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
|
|||||||
private ItemConfigDao itemConfigDao;
|
private ItemConfigDao itemConfigDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ItemCache itemCache;
|
private ItemCache itemCache;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RedissonLock(key = "#uid")
|
@RedissonLock(key = "#uid")
|
||||||
@@ -56,6 +62,8 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
|
|||||||
.idempotent(idempotent)
|
.idempotent(idempotent)
|
||||||
.build();
|
.build();
|
||||||
userBackpackDao.save(insert);
|
userBackpackDao.save(insert);
|
||||||
|
//用户收到物品的事件
|
||||||
|
applicationEventPublisher.publishEvent(new ItemReceiveEvent(this, insert));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIdempotent(Long itemId, IdempotentEnum idempotentEnum, String businessId) {
|
private String getIdempotent(Long itemId, IdempotentEnum idempotentEnum, String businessId) {
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ import javax.validation.Valid;
|
|||||||
public class ChatController {
|
public class ChatController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
|
|
||||||
@GetMapping("/public/room/page")
|
@GetMapping("/public/room/page")
|
||||||
@ApiOperation("会话列表")
|
@ApiOperation("会话列表")
|
||||||
public ApiResult<CursorPageBaseResp<ChatRoomResp>> getRoomPage(CursorPageBaseReq request) {
|
public ApiResult<CursorPageBaseResp<ChatRoomResp>> getRoomPage(CursorPageBaseReq request) {
|
||||||
return ApiResult.success(chatService.getRoomPage(request, RequestHolder.get().getUid()));
|
return ApiResult.success(chatService.getRoomPage(request, RequestHolder.get().getUid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/public/member/page")
|
@GetMapping("/public/member/page")
|
||||||
@ApiOperation("群成员列表")
|
@ApiOperation("群成员列表")
|
||||||
public ApiResult<CursorPageBaseResp<ChatMemberResp>> getMemberPage(CursorPageBaseReq request) {
|
public ApiResult<CursorPageBaseResp<ChatMemberResp>> getMemberPage(CursorPageBaseReq request) {
|
||||||
@@ -61,19 +63,22 @@ public class ChatController {
|
|||||||
|
|
||||||
@PostMapping("/msg")
|
@PostMapping("/msg")
|
||||||
@ApiOperation("发送消息")
|
@ApiOperation("发送消息")
|
||||||
@FrequencyControl(time = 5,count = 2,target = FrequencyControl.Target.UID)
|
@FrequencyControl(time = 5, count = 2, target = FrequencyControl.Target.UID)
|
||||||
@FrequencyControl(time = 30,count = 5,target = FrequencyControl.Target.UID)
|
@FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.UID)
|
||||||
@FrequencyControl(time = 60,count = 10,target = FrequencyControl.Target.UID)
|
@FrequencyControl(time = 60, count = 10, target = FrequencyControl.Target.UID)
|
||||||
public ApiResult<IdRespVO> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
public ApiResult<ChatMessageResp> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
||||||
return ApiResult.success(IdRespVO.id(chatService.sendMsg(request, RequestHolder.get().getUid())));
|
Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid());
|
||||||
|
//返回完整消息格式,方便前展示
|
||||||
|
return ApiResult.success(chatService.getMsgResp(msgId, RequestHolder.get().getUid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/msg/mark")
|
@PutMapping("/msg/mark")
|
||||||
@ApiOperation("消息标记")
|
@ApiOperation("消息标记")
|
||||||
@FrequencyControl(time = 20,count = 3,target = FrequencyControl.Target.UID)
|
@FrequencyControl(time = 20, count = 3, target = FrequencyControl.Target.UID)
|
||||||
public ApiResult<Void> setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁
|
public ApiResult<Void> setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁
|
||||||
chatService.setMsgMark(RequestHolder.get().getUid(),request);
|
chatService.setMsgMark(RequestHolder.get().getUid(), request);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ public interface ChatService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ChatMessageResp getMsgResp(Message message,Long receiveUid);
|
ChatMessageResp getMsgResp(Message message,Long receiveUid);
|
||||||
|
/**
|
||||||
|
* 根据消息获取消息前端展示的物料
|
||||||
|
* @param msgId
|
||||||
|
* @param receiveUid 接受消息的uid,可null
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ChatMessageResp getMsgResp(Long msgId,Long receiveUid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取群成员列表
|
* 获取群成员列表
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cn.hutool.core.lang.Pair;
|
|||||||
import com.abin.mallchat.common.chat.dao.MessageDao;
|
import com.abin.mallchat.common.chat.dao.MessageDao;
|
||||||
import com.abin.mallchat.common.chat.dao.MessageMarkDao;
|
import com.abin.mallchat.common.chat.dao.MessageMarkDao;
|
||||||
import com.abin.mallchat.common.chat.dao.RoomDao;
|
import com.abin.mallchat.common.chat.dao.RoomDao;
|
||||||
|
import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.MessageMark;
|
import com.abin.mallchat.common.chat.domain.entity.MessageMark;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Room;
|
import com.abin.mallchat.common.chat.domain.entity.Room;
|
||||||
@@ -28,11 +29,12 @@ import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
|||||||
import com.abin.mallchat.custom.chat.service.adapter.MemberAdapter;
|
import com.abin.mallchat.custom.chat.service.adapter.MemberAdapter;
|
||||||
import com.abin.mallchat.custom.chat.service.adapter.RoomAdapter;
|
import com.abin.mallchat.custom.chat.service.adapter.RoomAdapter;
|
||||||
import com.abin.mallchat.custom.chat.service.helper.ChatMemberHelper;
|
import com.abin.mallchat.custom.chat.service.helper.ChatMemberHelper;
|
||||||
import com.abin.mallchat.custom.common.event.MessageMarkEvent;
|
import com.abin.mallchat.common.common.event.MessageMarkEvent;
|
||||||
import com.abin.mallchat.custom.common.event.MessageSendEvent;
|
import com.abin.mallchat.common.common.event.MessageSendEvent;
|
||||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
import com.abin.mallchat.custom.chat.service.ChatService;
|
||||||
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
|
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -76,19 +78,19 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Long sendMsg(ChatMessageReq request, Long uid) {
|
public Long sendMsg(ChatMessageReq request, Long uid) {
|
||||||
//校验下回复消息
|
//校验下回复消息
|
||||||
Message replyMsg =null;
|
Message replyMsg = null;
|
||||||
if(Objects.nonNull(request.getReplyMsgId())){
|
if (Objects.nonNull(request.getReplyMsgId())) {
|
||||||
replyMsg = messageDao.getById(request.getReplyMsgId());
|
replyMsg = messageDao.getById(request.getReplyMsgId());
|
||||||
AssertUtil.isNotEmpty(replyMsg,"回复消息不存在");
|
AssertUtil.isNotEmpty(replyMsg, "回复消息不存在");
|
||||||
AssertUtil.equal(replyMsg.getRoomId(),request.getRoomId(),"只能回复相同会话内的消息");
|
AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
|
||||||
|
|
||||||
}
|
}
|
||||||
Message insert = MessageAdapter.buildMsgSave(request, uid);
|
Message insert = MessageAdapter.buildMsgSave(request, uid);
|
||||||
messageDao.save(insert);
|
messageDao.save(insert);
|
||||||
//如果有回复消息
|
//如果有回复消息
|
||||||
if(Objects.nonNull(replyMsg)){
|
if (Objects.nonNull(replyMsg)) {
|
||||||
Integer gapCount = messageDao.getGapCount(request.getRoomId(), replyMsg.getId(), insert.getId());
|
Integer gapCount = messageDao.getGapCount(request.getRoomId(), replyMsg.getId(), insert.getId());
|
||||||
messageDao.updateGapCount(insert.getId(),gapCount);
|
messageDao.updateGapCount(insert.getId(), gapCount);
|
||||||
}
|
}
|
||||||
//发布消息发送事件
|
//发布消息发送事件
|
||||||
applicationEventPublisher.publishEvent(new MessageSendEvent(this, insert.getId()));
|
applicationEventPublisher.publishEvent(new MessageSendEvent(this, insert.getId()));
|
||||||
@@ -100,6 +102,12 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
return CollUtil.getFirst(getMsgRespBatch(Collections.singletonList(message), receiveUid));
|
return CollUtil.getFirst(getMsgRespBatch(Collections.singletonList(message), receiveUid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatMessageResp getMsgResp(Long msgId, Long receiveUid) {
|
||||||
|
Message msg = messageDao.getById(msgId);
|
||||||
|
return getMsgResp(msg, receiveUid);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CursorPageBaseResp<ChatMemberResp> getMemberPage(CursorPageBaseReq request) {
|
public CursorPageBaseResp<ChatMemberResp> getMemberPage(CursorPageBaseReq request) {
|
||||||
Pair<ChatActiveStatusEnum, String> pair = ChatMemberHelper.getCursorPair(request.getCursor());
|
Pair<ChatActiveStatusEnum, String> pair = ChatMemberHelper.getCursorPair(request.getCursor());
|
||||||
@@ -108,10 +116,10 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
List<ChatMemberResp> resultList = new ArrayList<>();//最终列表
|
List<ChatMemberResp> resultList = new ArrayList<>();//最终列表
|
||||||
Boolean isLast = Boolean.FALSE;
|
Boolean isLast = Boolean.FALSE;
|
||||||
if (activeStatusEnum == ChatActiveStatusEnum.ONLINE) {//在线列表
|
if (activeStatusEnum == ChatActiveStatusEnum.ONLINE) {//在线列表
|
||||||
CursorPageBaseResp<Pair<Long, Double>> cursorPage = userCache.getOnlineCursorPage(new CursorPageBaseReq(request.getPageSize(), timeCursor));
|
CursorPageBaseResp<Pair<Long, Double>> cursorPage = userCache.getOnlineCursorPage(new CursorPageBaseReq(request.getPageSize(), timeCursor));
|
||||||
resultList.addAll(memberAdapter.buildMember(cursorPage.getList(), ChatActiveStatusEnum.ONLINE));//添加在线列表
|
resultList.addAll(memberAdapter.buildMember(cursorPage.getList(), ChatActiveStatusEnum.ONLINE));//添加在线列表
|
||||||
if (cursorPage.getIsLast()) {//如果是最后一页,从离线列表再补点数据
|
if (cursorPage.getIsLast()) {//如果是最后一页,从离线列表再补点数据
|
||||||
Integer leftSize = request.getPageSize() - cursorPage.getList().size();
|
Integer leftSize = request.getPageSize() - cursorPage.getList().size();
|
||||||
cursorPage = userCache.getOfflineCursorPage(new CursorPageBaseReq(leftSize, null));
|
cursorPage = userCache.getOfflineCursorPage(new CursorPageBaseReq(leftSize, null));
|
||||||
resultList.addAll(memberAdapter.buildMember(cursorPage.getList(), ChatActiveStatusEnum.OFFLINE));//添加离线线列表
|
resultList.addAll(memberAdapter.buildMember(cursorPage.getList(), ChatActiveStatusEnum.OFFLINE));//添加离线线列表
|
||||||
activeStatusEnum = ChatActiveStatusEnum.OFFLINE;
|
activeStatusEnum = ChatActiveStatusEnum.OFFLINE;
|
||||||
@@ -179,7 +187,9 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
.build();
|
.build();
|
||||||
messageMarkDao.save(insert);
|
messageMarkDao.save(insert);
|
||||||
//发布消息标记事件
|
//发布消息标记事件
|
||||||
applicationEventPublisher.publishEvent(new MessageMarkEvent(this,request));
|
ChatMessageMarkDTO dto = new ChatMessageMarkDTO();
|
||||||
|
BeanUtils.copyProperties(request, dto);
|
||||||
|
applicationEventPublisher.publishEvent(new MessageMarkEvent(this, dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer transformAct(Integer actType) {
|
private Integer transformAct(Integer actType) {
|
||||||
@@ -207,7 +217,7 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
userMap = userCache.getUserInfoBatch(uidSet);
|
userMap = userCache.getUserInfoBatch(uidSet);
|
||||||
//查询消息标志
|
//查询消息标志
|
||||||
List<MessageMark> msgMark = messageMarkDao.getValidMarkByMsgIdBatch(messages.stream().map(Message::getId).collect(Collectors.toList()));
|
List<MessageMark> msgMark = messageMarkDao.getValidMarkByMsgIdBatch(messages.stream().map(Message::getId).collect(Collectors.toList()));
|
||||||
return MessageAdapter.buildMsgResp(messages, replyMap, userMap,msgMark,receiveUid);
|
return MessageAdapter.buildMsgResp(messages, replyMap, userMap, msgMark, receiveUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.abin.mallchat.custom.common.event;
|
|
||||||
|
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class MessageMarkEvent extends ApplicationEvent {
|
|
||||||
private ChatMessageMarkReq req;
|
|
||||||
|
|
||||||
public MessageMarkEvent(Object source, ChatMessageMarkReq req) {
|
|
||||||
super(source);
|
|
||||||
this.req = req;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.abin.mallchat.custom.common.event.listener;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.user.dao.UserDao;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.UserBackpack;
|
||||||
|
import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
|
||||||
|
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
||||||
|
import com.abin.mallchat.common.common.event.ItemReceiveEvent;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户收到物品监听器
|
||||||
|
*
|
||||||
|
* @author zhongzb create on 2022/08/26
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class ItemReceiveListener {
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
@Autowired
|
||||||
|
private ItemCache itemCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 徽章类型,帮忙默认佩戴
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
@EventListener(classes = ItemReceiveEvent.class)
|
||||||
|
public void wear(ItemReceiveEvent event) {
|
||||||
|
UserBackpack userBackpack = event.getUserBackpack();
|
||||||
|
ItemConfig itemConfig = itemCache.getById(userBackpack.getItemId());
|
||||||
|
if (ItemTypeEnum.BADGE.getType().equals(itemConfig.getType())) {
|
||||||
|
User user = userDao.getById(userBackpack.getUid());
|
||||||
|
if (Objects.isNull(user.getItemId())) {
|
||||||
|
userDao.wearingBadge(userBackpack.getUid(), userBackpack.getItemId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,14 +2,14 @@ package com.abin.mallchat.custom.common.event.listener;
|
|||||||
|
|
||||||
import com.abin.mallchat.common.chat.dao.MessageDao;
|
import com.abin.mallchat.common.chat.dao.MessageDao;
|
||||||
import com.abin.mallchat.common.chat.dao.MessageMarkDao;
|
import com.abin.mallchat.common.chat.dao.MessageMarkDao;
|
||||||
|
import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||||
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
|
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
|
||||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||||
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
||||||
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
||||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
|
import com.abin.mallchat.common.common.event.MessageMarkEvent;
|
||||||
import com.abin.mallchat.custom.common.event.MessageMarkEvent;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@@ -36,19 +36,19 @@ public class MessageMarkListener {
|
|||||||
@Async
|
@Async
|
||||||
@EventListener(classes = MessageMarkEvent.class)
|
@EventListener(classes = MessageMarkEvent.class)
|
||||||
public void changeMsgType(MessageMarkEvent event) {
|
public void changeMsgType(MessageMarkEvent event) {
|
||||||
ChatMessageMarkReq req = event.getReq();
|
ChatMessageMarkDTO dto = event.getDto();
|
||||||
Message msg = messageDao.getById(req.getMsgId());
|
Message msg = messageDao.getById(dto.getMsgId());
|
||||||
if (!Objects.equals(msg, MessageTypeEnum.NORMAL.getType())) {//普通消息才需要升级
|
if (!Objects.equals(msg, MessageTypeEnum.NORMAL.getType())) {//普通消息才需要升级
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//消息被标记次数
|
//消息被标记次数
|
||||||
Integer markCount = messageMarkDao.getMarkCount(req.getMsgId(), req.getMarkType());
|
Integer markCount = messageMarkDao.getMarkCount(dto.getMsgId(), dto.getMarkType());
|
||||||
MessageMarkTypeEnum markTypeEnum = MessageMarkTypeEnum.of(req.getMarkType());
|
MessageMarkTypeEnum markTypeEnum = MessageMarkTypeEnum.of(dto.getMarkType());
|
||||||
if (markCount < markTypeEnum.getRiseNum()) {
|
if (markCount < markTypeEnum.getRiseNum()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean updateSuccess = messageDao.riseOptimistic(msg.getId(), msg.getType(), markTypeEnum.getRiseEnum().getType());
|
boolean updateSuccess = messageDao.riseOptimistic(msg.getId(), msg.getType(), markTypeEnum.getRiseEnum().getType());
|
||||||
if (MessageMarkTypeEnum.LIKE.getType().equals(req.getMarkType()) && updateSuccess) {//尝试给用户发送一张徽章
|
if (MessageMarkTypeEnum.LIKE.getType().equals(dto.getMarkType()) && updateSuccess) {//尝试给用户发送一张徽章
|
||||||
iUserBackpackService.acquireItem(msg.getFromUid(), ItemEnum.LIKE_BADGE.getId(), IdempotentEnum.MSG_ID, msg.getId().toString());
|
iUserBackpackService.acquireItem(msg.getFromUid(), ItemEnum.LIKE_BADGE.getId(), IdempotentEnum.MSG_ID, msg.getId().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.abin.mallchat.custom.common.event.listener;
|
|||||||
import com.abin.mallchat.common.chat.dao.MessageDao;
|
import com.abin.mallchat.common.chat.dao.MessageDao;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||||
import com.abin.mallchat.custom.common.event.MessageSendEvent;
|
import com.abin.mallchat.common.common.event.MessageSendEvent;
|
||||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
import com.abin.mallchat.custom.chat.service.ChatService;
|
||||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ package com.abin.mallchat.custom.common.event.listener;
|
|||||||
import com.abin.mallchat.common.user.dao.UserDao;
|
import com.abin.mallchat.common.user.dao.UserDao;
|
||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||||
import com.abin.mallchat.custom.common.event.UserOfflineEvent;
|
import com.abin.mallchat.common.common.event.UserOfflineEvent;
|
||||||
import com.abin.mallchat.custom.common.event.UserOnlineEvent;
|
|
||||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
package com.abin.mallchat.custom.common.event.listener;
|
package com.abin.mallchat.custom.common.event.listener;
|
||||||
|
|
||||||
import com.abin.mallchat.common.chat.dao.MessageDao;
|
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
|
||||||
import com.abin.mallchat.common.user.dao.UserDao;
|
import com.abin.mallchat.common.user.dao.UserDao;
|
||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import com.abin.mallchat.common.user.service.IpService;
|
import com.abin.mallchat.common.user.service.IpService;
|
||||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
import com.abin.mallchat.common.common.event.UserOnlineEvent;
|
||||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
|
||||||
import com.abin.mallchat.custom.common.event.MessageSendEvent;
|
|
||||||
import com.abin.mallchat.custom.common.event.UserOnlineEvent;
|
|
||||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ import com.abin.mallchat.common.user.dao.UserDao;
|
|||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
||||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
import com.abin.mallchat.common.common.event.UserOnlineEvent;
|
||||||
import com.abin.mallchat.custom.common.event.UserOnlineEvent;
|
import com.abin.mallchat.common.common.event.UserRegisterEvent;
|
||||||
import com.abin.mallchat.custom.common.event.UserRegisterEvent;
|
|
||||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
|
||||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@@ -24,15 +21,9 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class UserRegisterListener {
|
public class UserRegisterListener {
|
||||||
@Autowired
|
|
||||||
private WebSocketService webSocketService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserDao userDao;
|
private UserDao userDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserCache userCache;
|
|
||||||
@Autowired
|
|
||||||
private WSAdapter wsAdapter;
|
|
||||||
@Autowired
|
|
||||||
private IUserBackpackService iUserBackpackService;
|
private IUserBackpackService iUserBackpackService;
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@@ -48,6 +39,11 @@ public class UserRegisterListener {
|
|||||||
public void sendBadge(UserOnlineEvent event) {
|
public void sendBadge(UserOnlineEvent event) {
|
||||||
User user = event.getUser();
|
User user = event.getUser();
|
||||||
int count = userDao.count();
|
int count = userDao.count();
|
||||||
|
if (count <= 10) {
|
||||||
|
iUserBackpackService.acquireItem(user.getId(), ItemEnum.REG_TOP10_BADGE.getId(), IdempotentEnum.UID, user.getId().toString());
|
||||||
|
} else if (count <= 100) {
|
||||||
|
iUserBackpackService.acquireItem(user.getId(), ItemEnum.REG_TOP100_BADGE.getId(), IdempotentEnum.UID, user.getId().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.abin.mallchat.custom.user.service.impl;
|
package com.abin.mallchat.custom.user.service.impl;
|
||||||
|
|
||||||
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
|
||||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||||
import com.abin.mallchat.common.user.dao.ItemConfigDao;
|
import com.abin.mallchat.common.user.dao.ItemConfigDao;
|
||||||
import com.abin.mallchat.common.user.dao.UserBackpackDao;
|
import com.abin.mallchat.common.user.dao.UserBackpackDao;
|
||||||
@@ -13,7 +12,7 @@ import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
|
|||||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||||
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
||||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||||
import com.abin.mallchat.custom.common.event.UserRegisterEvent;
|
import com.abin.mallchat.common.common.event.UserRegisterEvent;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.request.user.ModifyNameReq;
|
import com.abin.mallchat.custom.user.domain.vo.request.user.ModifyNameReq;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.request.user.WearingBadgeReq;
|
import com.abin.mallchat.custom.user.domain.vo.request.user.WearingBadgeReq;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.response.user.BadgeResp;
|
import com.abin.mallchat.custom.user.domain.vo.response.user.BadgeResp;
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import com.abin.mallchat.common.common.config.ThreadPoolConfig;
|
import com.abin.mallchat.common.common.config.ThreadPoolConfig;
|
||||||
import com.abin.mallchat.common.user.dao.UserDao;
|
import com.abin.mallchat.common.user.dao.UserDao;
|
||||||
import com.abin.mallchat.common.user.domain.entity.User;
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import com.abin.mallchat.custom.common.event.UserOfflineEvent;
|
import com.abin.mallchat.common.common.event.UserOfflineEvent;
|
||||||
import com.abin.mallchat.custom.user.domain.dto.ws.WSChannelExtraDTO;
|
import com.abin.mallchat.custom.user.domain.dto.ws.WSChannelExtraDTO;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.request.ws.WSAuthorize;
|
import com.abin.mallchat.custom.user.domain.vo.request.ws.WSAuthorize;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSBaseResp;
|
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSBaseResp;
|
||||||
import com.abin.mallchat.custom.common.event.UserOnlineEvent;
|
import com.abin.mallchat.common.common.event.UserOnlineEvent;
|
||||||
import com.abin.mallchat.custom.user.service.LoginService;
|
import com.abin.mallchat.custom.user.service.LoginService;
|
||||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||||
|
|||||||
Reference in New Issue
Block a user