mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 22:23:42 +08:00
用户徽章佩戴和发放
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.abin.mallchat.custom.common.event;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class MessageSendEvent extends ApplicationEvent {
|
||||
private Long msgId;
|
||||
|
||||
public MessageSendEvent(Object source, Long msgId) {
|
||||
super(source);
|
||||
this.msgId = msgId;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.abin.mallchat.custom.common.event;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class UserOfflineEvent extends ApplicationEvent {
|
||||
private User user;
|
||||
|
||||
public UserOfflineEvent(Object source, User user) {
|
||||
super(source);
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.abin.mallchat.custom.common.event;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
public class UserOnlineEvent extends ApplicationEvent {
|
||||
private User user;
|
||||
|
||||
public UserOnlineEvent(Object source, User user) {
|
||||
super(source);
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.abin.mallchat.custom.common.event;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class UserRegisterEvent extends ApplicationEvent {
|
||||
private User user;
|
||||
|
||||
public UserRegisterEvent(Object source, User user) {
|
||||
super(source);
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
@@ -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.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.enums.MessageMarkTypeEnum;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
|
||||
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
|
||||
import com.abin.mallchat.custom.common.event.MessageMarkEvent;
|
||||
import com.abin.mallchat.common.common.event.MessageMarkEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -36,19 +36,19 @@ public class MessageMarkListener {
|
||||
@Async
|
||||
@EventListener(classes = MessageMarkEvent.class)
|
||||
public void changeMsgType(MessageMarkEvent event) {
|
||||
ChatMessageMarkReq req = event.getReq();
|
||||
Message msg = messageDao.getById(req.getMsgId());
|
||||
ChatMessageMarkDTO dto = event.getDto();
|
||||
Message msg = messageDao.getById(dto.getMsgId());
|
||||
if (!Objects.equals(msg, MessageTypeEnum.NORMAL.getType())) {//普通消息才需要升级
|
||||
return;
|
||||
}
|
||||
//消息被标记次数
|
||||
Integer markCount = messageMarkDao.getMarkCount(req.getMsgId(), req.getMarkType());
|
||||
MessageMarkTypeEnum markTypeEnum = MessageMarkTypeEnum.of(req.getMarkType());
|
||||
Integer markCount = messageMarkDao.getMarkCount(dto.getMsgId(), dto.getMarkType());
|
||||
MessageMarkTypeEnum markTypeEnum = MessageMarkTypeEnum.of(dto.getMarkType());
|
||||
if (markCount < markTypeEnum.getRiseNum()) {
|
||||
return;
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.domain.entity.Message;
|
||||
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.user.service.WebSocketService;
|
||||
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.domain.entity.User;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.common.event.UserOfflineEvent;
|
||||
import com.abin.mallchat.custom.common.event.UserOnlineEvent;
|
||||
import com.abin.mallchat.common.common.event.UserOfflineEvent;
|
||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
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.domain.entity.User;
|
||||
import com.abin.mallchat.common.user.service.IpService;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||
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.common.common.event.UserOnlineEvent;
|
||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||
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.enums.ItemEnum;
|
||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.common.event.UserOnlineEvent;
|
||||
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 com.abin.mallchat.common.common.event.UserOnlineEvent;
|
||||
import com.abin.mallchat.common.common.event.UserRegisterEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -24,15 +21,9 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class UserRegisterListener {
|
||||
@Autowired
|
||||
private WebSocketService webSocketService;
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
@Autowired
|
||||
private UserCache userCache;
|
||||
@Autowired
|
||||
private WSAdapter wsAdapter;
|
||||
@Autowired
|
||||
private IUserBackpackService iUserBackpackService;
|
||||
|
||||
@Async
|
||||
@@ -48,6 +39,11 @@ public class UserRegisterListener {
|
||||
public void sendBadge(UserOnlineEvent event) {
|
||||
User user = event.getUser();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user