优化推送逻辑

This commit is contained in:
wangxulei
2025-01-15 11:25:49 +08:00
parent 3ba2d600c2
commit 2bdf00f7f7
7 changed files with 59 additions and 9 deletions

View File

@@ -49,6 +49,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.List;
import static com.dd.admin.business.webSocket.WsConst.*;
import static com.dd.admin.common.consts.XhsConst.TRUE;
@ApiModel("用户操作类Api")
@RestController
@@ -95,7 +96,7 @@ public class AuthActionApi {
oneByFollow.setFollowName(follow.getAuthorName());
followService.save(oneByFollow);
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),author.getAuthorId(),"4",oneByFollow);
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),author.getAuthorId(),HANDLER_FOLLOW,oneByFollow);
}else{
throw new ApiException("已经关注过了~");
}
@@ -150,7 +151,7 @@ public class AuthActionApi {
upNotesService.save(upNotes);
//发送点赞信息
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),"1",upNotes);
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),HANDLER_UP,upNotes);
}else{
//在则表示取消赞删除数据
@@ -182,7 +183,7 @@ public class AuthActionApi {
starNotesService.save(starNotes);
//发送点赞信息
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),"2",starNotes);
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),HANDLER_STAR,starNotes);
}else{
//在则表示取消赞删除数据
starNotesService.removeById(starNotes);
@@ -261,7 +262,7 @@ public class AuthActionApi {
Reply reply = BeanUtil.copyProperties(replyDto, Reply.class);
replyService.save(reply);
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),reply.getParentAuthorId(),"3",reply);
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),reply.getParentAuthorId(),HANDLER_REPLY,reply);
return ResultBean.success();
}

View File

@@ -7,6 +7,7 @@ import com.dd.admin.business.note.service.NoteService;
import com.dd.admin.business.notice.domain.SendNoticeDto;
import com.dd.admin.business.receive.entity.Receive;
import com.dd.admin.business.receive.service.ReceiveService;
import com.dd.admin.business.webSocket.util.TioUtil;
import com.dd.admin.common.exception.ApiException;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
@@ -27,6 +28,9 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
import org.tio.websocket.starter.TioWebSocketServerBootstrap;
import static com.dd.admin.business.webSocket.WsConst.HANDLER_NOTICE_COUNT;
/**
* <p>
@@ -46,6 +50,9 @@ public class NoticeController {
@Autowired
ReceiveService receiveService;
@Autowired
private TioWebSocketServerBootstrap bootstrap;
@ApiOperation(value = "通知公告表-添加")
@ApiOperationSupport(order = 3)
@PostMapping("/admin/notice/sendNotice")
@@ -61,7 +68,11 @@ public class NoticeController {
receive.setNoticeId(notice.getNoticeId());
receive.setAuthorId(author.getAuthorId());
receive.setAuthorName(author.getAuthorName());
receiveList.add(receive);
boolean add = receiveList.add(receive);
//给指定用户发送
if(add){
TioUtil.sendChatMessageToUser(bootstrap.getServerGroupContext(),author.getAuthorId(),HANDLER_NOTICE_COUNT,receive);
}
});
receiveService.saveBatch(receiveList);

View File

@@ -0,0 +1,34 @@
package com.dd.admin.business.webSocket;
public class WsConst {
//点赞
public final static String HANDLER_UP = "1";
//收藏
public final static String HANDLER_STAR = "2";
//回复
public final static String HANDLER_REPLY = "3";
//关注
public final static String HANDLER_FOLLOW = "4";
//聊天
public final static String HANDLER_CHAT = "5";
//客服
public final static String HANDLER_SERVE = "6";
//客服
public final static String HANDLER_READ_CHAT = "7";
//客服
public final static String HANDLER_CHAT_COUNT = "8";
//客服
public final static String HANDLER_TOTAL_COUNT = "9";
//客服
public final static String HANDLER_NOTICE_COUNT = "10";
}

View File

@@ -18,6 +18,8 @@ import org.tio.core.ChannelContext;
import java.util.Map;
import static com.dd.admin.business.webSocket.WsConst.HANDLER_TOTAL_COUNT;
@Slf4j
@Service("9")
@@ -49,7 +51,7 @@ public class GetApiReadCountMessageHandler implements MsgHandlerInterface {
UnReadCountBean unReadCountBean = new UnReadCountBean(chatUnReadCount,upNotesUnReadCount,starNotesUnReadCount,replyUnReadCount,followUnReadCount,receiveUnReadCount,totalUnReadCount);
unReadCountBean.calculateTotalUnReadCount();
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,"9",unReadCountBean);
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,HANDLER_TOTAL_COUNT,unReadCountBean);
return null;
}
}

View File

@@ -11,6 +11,8 @@ import org.tio.core.ChannelContext;
import java.util.Map;
import static com.dd.admin.business.webSocket.WsConst.HANDLER_CHAT_COUNT;
@Slf4j
@Service("8")
@@ -22,7 +24,7 @@ public class GetReadCountMessageHandler implements MsgHandlerInterface {
public Object handler(Map map, ChannelContext context) {
String authorId = String.valueOf(map.get("authorId"));
Integer unReadCount = chatService.selectUnReadCount(authorId);
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,"8",unReadCount);
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,HANDLER_CHAT_COUNT,unReadCount);
return null;
}
}

View File

@@ -1 +1 @@
package com.dd.admin.business.webSocket.handler;
package com.dd.admin.business.webSocket.handler;

View File

@@ -1 +1 @@
package com.dd.admin.business.webSocket.handler;
package com.dd.admin.business.webSocket.handler;