优化推送逻辑
This commit is contained in:
@@ -49,6 +49,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.dd.admin.business.webSocket.WsConst.*;
|
||||||
import static com.dd.admin.common.consts.XhsConst.TRUE;
|
import static com.dd.admin.common.consts.XhsConst.TRUE;
|
||||||
@ApiModel("用户操作类Api")
|
@ApiModel("用户操作类Api")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -95,7 +96,7 @@ public class AuthActionApi {
|
|||||||
oneByFollow.setFollowName(follow.getAuthorName());
|
oneByFollow.setFollowName(follow.getAuthorName());
|
||||||
followService.save(oneByFollow);
|
followService.save(oneByFollow);
|
||||||
|
|
||||||
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),author.getAuthorId(),"4",oneByFollow);
|
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),author.getAuthorId(),HANDLER_FOLLOW,oneByFollow);
|
||||||
}else{
|
}else{
|
||||||
throw new ApiException("已经关注过了~");
|
throw new ApiException("已经关注过了~");
|
||||||
}
|
}
|
||||||
@@ -150,7 +151,7 @@ public class AuthActionApi {
|
|||||||
upNotesService.save(upNotes);
|
upNotesService.save(upNotes);
|
||||||
|
|
||||||
//发送点赞信息
|
//发送点赞信息
|
||||||
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),"1",upNotes);
|
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),HANDLER_UP,upNotes);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
//在则表示取消赞删除数据
|
//在则表示取消赞删除数据
|
||||||
@@ -182,7 +183,7 @@ public class AuthActionApi {
|
|||||||
starNotesService.save(starNotes);
|
starNotesService.save(starNotes);
|
||||||
|
|
||||||
//发送点赞信息
|
//发送点赞信息
|
||||||
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),"2",starNotes);
|
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),noteDto.getAuthorId(),HANDLER_STAR,starNotes);
|
||||||
}else{
|
}else{
|
||||||
//在则表示取消赞删除数据
|
//在则表示取消赞删除数据
|
||||||
starNotesService.removeById(starNotes);
|
starNotesService.removeById(starNotes);
|
||||||
@@ -261,7 +262,7 @@ public class AuthActionApi {
|
|||||||
Reply reply = BeanUtil.copyProperties(replyDto, Reply.class);
|
Reply reply = BeanUtil.copyProperties(replyDto, Reply.class);
|
||||||
replyService.save(reply);
|
replyService.save(reply);
|
||||||
|
|
||||||
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),reply.getParentAuthorId(),"3",reply);
|
TioUtil.sendChatMessageToUser( bootstrap.getServerGroupContext(),reply.getParentAuthorId(),HANDLER_REPLY,reply);
|
||||||
|
|
||||||
return ResultBean.success();
|
return ResultBean.success();
|
||||||
}
|
}
|
||||||
|
@@ -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.notice.domain.SendNoticeDto;
|
||||||
import com.dd.admin.business.receive.entity.Receive;
|
import com.dd.admin.business.receive.entity.Receive;
|
||||||
import com.dd.admin.business.receive.service.ReceiveService;
|
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.dd.admin.common.exception.ApiException;
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -27,6 +28,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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>
|
* <p>
|
||||||
@@ -46,6 +50,9 @@ public class NoticeController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ReceiveService receiveService;
|
ReceiveService receiveService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TioWebSocketServerBootstrap bootstrap;
|
||||||
|
|
||||||
@ApiOperation(value = "通知公告表-添加")
|
@ApiOperation(value = "通知公告表-添加")
|
||||||
@ApiOperationSupport(order = 3)
|
@ApiOperationSupport(order = 3)
|
||||||
@PostMapping("/admin/notice/sendNotice")
|
@PostMapping("/admin/notice/sendNotice")
|
||||||
@@ -61,7 +68,11 @@ public class NoticeController {
|
|||||||
receive.setNoticeId(notice.getNoticeId());
|
receive.setNoticeId(notice.getNoticeId());
|
||||||
receive.setAuthorId(author.getAuthorId());
|
receive.setAuthorId(author.getAuthorId());
|
||||||
receive.setAuthorName(author.getAuthorName());
|
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);
|
receiveService.saveBatch(receiveList);
|
||||||
|
34
src/main/java/com/dd/admin/business/webSocket/WsConst.java
Normal file
34
src/main/java/com/dd/admin/business/webSocket/WsConst.java
Normal 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";
|
||||||
|
}
|
@@ -18,6 +18,8 @@ import org.tio.core.ChannelContext;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.dd.admin.business.webSocket.WsConst.HANDLER_TOTAL_COUNT;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service("9")
|
@Service("9")
|
||||||
@@ -49,7 +51,7 @@ public class GetApiReadCountMessageHandler implements MsgHandlerInterface {
|
|||||||
UnReadCountBean unReadCountBean = new UnReadCountBean(chatUnReadCount,upNotesUnReadCount,starNotesUnReadCount,replyUnReadCount,followUnReadCount,receiveUnReadCount,totalUnReadCount);
|
UnReadCountBean unReadCountBean = new UnReadCountBean(chatUnReadCount,upNotesUnReadCount,starNotesUnReadCount,replyUnReadCount,followUnReadCount,receiveUnReadCount,totalUnReadCount);
|
||||||
unReadCountBean.calculateTotalUnReadCount();
|
unReadCountBean.calculateTotalUnReadCount();
|
||||||
|
|
||||||
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,"9",unReadCountBean);
|
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,HANDLER_TOTAL_COUNT,unReadCountBean);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,8 @@ import org.tio.core.ChannelContext;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.dd.admin.business.webSocket.WsConst.HANDLER_CHAT_COUNT;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service("8")
|
@Service("8")
|
||||||
@@ -22,7 +24,7 @@ public class GetReadCountMessageHandler implements MsgHandlerInterface {
|
|||||||
public Object handler(Map map, ChannelContext context) {
|
public Object handler(Map map, ChannelContext context) {
|
||||||
String authorId = String.valueOf(map.get("authorId"));
|
String authorId = String.valueOf(map.get("authorId"));
|
||||||
Integer unReadCount = chatService.selectUnReadCount(authorId);
|
Integer unReadCount = chatService.selectUnReadCount(authorId);
|
||||||
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,"8",unReadCount);
|
TioUtil.sendChatMessageToUser(context.getGroupContext(),authorId,HANDLER_CHAT_COUNT,unReadCount);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
package com.dd.admin.business.webSocket.handler;
|
package com.dd.admin.business.webSocket.handler;
|
@@ -1 +1 @@
|
|||||||
package com.dd.admin.business.webSocket.handler;
|
package com.dd.admin.business.webSocket.handler;
|
Reference in New Issue
Block a user