请求聊天总数 设置已读改为websocket模式
This commit is contained in:
@@ -3,8 +3,10 @@ package com.dd.admin.business.chat.controller;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||
import com.dd.admin.business.chat.domain.AuthorChat;
|
||||
import com.dd.admin.business.chat.domain.MessageBean;
|
||||
import com.dd.admin.business.api.domain.UnReadCountBean;
|
||||
import com.dd.admin.business.chat.domain.*;
|
||||
import com.dd.admin.common.aop.operationLog.aop.OperLog;
|
||||
import com.dd.admin.common.aop.operationLog.aop.OperType;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -16,8 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import com.dd.admin.business.chat.entity.Chat;
|
||||
import com.dd.admin.business.chat.domain.ChatVo;
|
||||
import com.dd.admin.business.chat.domain.ChatDto;
|
||||
import com.dd.admin.business.chat.service.ChatService;
|
||||
|
||||
import java.util.*;
|
||||
@@ -52,6 +52,16 @@ public class ChatController {
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "查询客服未读消息数量")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@GetMapping("/admin/chat/getUnReadCount")
|
||||
@OperLog(operModule = "查询客服未读消息数量",operType = OperType.OTHER,operDesc = "查询客服未读消息数量")
|
||||
public ResultBean getUnReadCount() {
|
||||
Integer chatUnReadCount = chatService.selectUnReadCount("8");
|
||||
return ResultBean.success(chatUnReadCount);
|
||||
};
|
||||
|
||||
@ApiOperation(value = "作者列表")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@GetMapping("/admin/chat/authorList")
|
||||
@@ -98,6 +108,17 @@ public class ChatController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "读取聊天消息")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@PostMapping("/admin/chat/readAuthorMessage")
|
||||
@OperLog(operModule = "读取回复消息", operType = OperType.OTHER, operDesc = "读取聊天消息")
|
||||
public ResultBean readReplyMessage(@RequestBody AuthorParam authorParam) {
|
||||
chatService.readMessage(authorParam.getAuthorId(),"8");
|
||||
return ResultBean.success("noAlert");
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "-分页列表")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@GetMapping("/admin/chat/page")
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package com.dd.admin.business.chat.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AuthorParam {
|
||||
private String authorId;
|
||||
}
|
@@ -113,58 +113,52 @@
|
||||
|
||||
|
||||
<select id="selectAuthorChatList" resultType="com.dd.admin.business.chat.domain.AuthorChat">
|
||||
SELECT
|
||||
wa.AUTHOR_ID id,
|
||||
wa.AUTHOR_NAME displayName,
|
||||
wa.AVATAR_URL avatar,
|
||||
wa.AUTHOR_NAME AS 'index',
|
||||
wb.unReadCount unRead,
|
||||
wb.content lastContent,
|
||||
wb.create_time
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
a.FROM_ID AS id,
|
||||
b.AUTHOR_NAME AS displayName,
|
||||
b.AUTHOR_NAME AS 'index',
|
||||
b.AVATAR_URL AS avatar,
|
||||
a.content lastContent,
|
||||
a.create_time,
|
||||
(
|
||||
SELECT
|
||||
count(1)
|
||||
FROM
|
||||
business_chat ca
|
||||
WHERE
|
||||
ca.FROM_ID = a.FROM_ID
|
||||
AND ca.to_id = '8'
|
||||
AND ca.MESSAGE_STATUS = 0
|
||||
) AS unRead
|
||||
FROM
|
||||
business_author wa
|
||||
LEFT JOIN (
|
||||
business_chat a
|
||||
LEFT JOIN business_author b ON a.FROM_ID = b.AUTHOR_ID
|
||||
WHERE
|
||||
a.TO_ID = '8'
|
||||
UNION ALL
|
||||
SELECT
|
||||
a.FROM_ID AS authorId,
|
||||
a.FROM_NAME AS authorName,
|
||||
b.AVATAR_URL AS authorAvatar,
|
||||
a.content,
|
||||
a.TO_ID AS id,
|
||||
b.AUTHOR_NAME AS displayName,
|
||||
b.AUTHOR_NAME AS 'index',
|
||||
b.AVATAR_URL AS avatar,
|
||||
a.content lastContent,
|
||||
a.create_time,
|
||||
(
|
||||
SELECT
|
||||
count(1)
|
||||
FROM
|
||||
business_chat ca
|
||||
WHERE
|
||||
ca.FROM_ID = a.FROM_ID
|
||||
AND ca.to_id = #{authorId}
|
||||
AND ca.MESSAGE_STATUS = 0
|
||||
) AS unReadCount
|
||||
0 AS unRead
|
||||
FROM
|
||||
business_chat a
|
||||
LEFT JOIN business_author b ON a.FROM_ID = b.AUTHOR_ID
|
||||
LEFT JOIN business_author b ON a.TO_ID = b.AUTHOR_ID
|
||||
WHERE
|
||||
a.TO_ID = #{authorId}
|
||||
UNION ALL
|
||||
SELECT
|
||||
a.TO_ID AS authorId,
|
||||
a.TO_NAME AS authorName,
|
||||
b.AVATAR_URL AS authorAvatar,
|
||||
a.content,
|
||||
a.create_time,
|
||||
0 AS unReadCount
|
||||
FROM
|
||||
business_chat a
|
||||
LEFT JOIN business_author b ON a.TO_ID = b.AUTHOR_ID
|
||||
WHERE
|
||||
a.FROM_ID = #{authorId}
|
||||
ORDER BY
|
||||
create_time DESC
|
||||
) wb ON wa.author_id = wb.authorId
|
||||
where wa.AUTHOR_ID != #{authorId}
|
||||
GROUP BY
|
||||
wa.author_id
|
||||
ORDER BY
|
||||
wb.create_time DESC
|
||||
a.FROM_ID = '8'
|
||||
ORDER BY
|
||||
create_time DESC
|
||||
) a1
|
||||
GROUP BY
|
||||
a1.id
|
||||
ORDER BY
|
||||
create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
@@ -27,6 +27,10 @@ public class OperationLogVo {
|
||||
@ApiModelProperty(value = "日志id")
|
||||
private String operId;
|
||||
|
||||
@ApiModelProperty(value = "操作ip")
|
||||
@TableField("OPER_IP_ADDRESS")
|
||||
private String operIpAddress;
|
||||
|
||||
@ApiModelProperty(value = "请求模块")
|
||||
private String operModule;
|
||||
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package com.dd.admin.business.webSocket.handler;
|
||||
|
||||
import com.dd.admin.business.chat.service.ChatService;
|
||||
import com.dd.admin.business.webSocket.MsgHandlerInterface;
|
||||
import com.dd.admin.business.webSocket.util.TioUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.tio.core.ChannelContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service("8")
|
||||
public class GetReadCoutMessageHandler implements MsgHandlerInterface {
|
||||
@Autowired
|
||||
ChatService chatService;
|
||||
@Override
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.dd.admin.business.webSocket.handler;
|
||||
|
||||
import com.dd.admin.business.chat.service.ChatService;
|
||||
import com.dd.admin.business.webSocket.MsgHandlerInterface;
|
||||
import com.dd.admin.business.webSocket.util.TioUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.tio.core.ChannelContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service("7")
|
||||
public class ReadMessageHandler implements MsgHandlerInterface {
|
||||
@Autowired
|
||||
ChatService chatService;
|
||||
@Override
|
||||
public Object handler(Map map, ChannelContext context) {
|
||||
String authorId = String.valueOf(map.get("authorId"));
|
||||
String loginId = String.valueOf(map.get("loginId"));
|
||||
chatService.readMessage(authorId,loginId);
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user