集成im
This commit is contained in:
@@ -1,8 +1,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.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -18,7 +20,7 @@ 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.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -37,18 +39,63 @@ public class ChatController {
|
||||
@Autowired
|
||||
ChatService chatService;
|
||||
|
||||
/**
|
||||
* 将给定的Date对象转换为对应东八区(Asia/Shanghai)的时间戳
|
||||
*
|
||||
* @param createTime 要转换的Date对象
|
||||
* @return 对应东八区的时间戳(以毫秒为单位)
|
||||
*/
|
||||
public static long convertToShanghaiTimeZoneTimestamp(Date createTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(createTime);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "作者列表")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@GetMapping("/admin/chat/authorList")
|
||||
public ResultBean<List<AuthorChat>> authorList() {
|
||||
List<AuthorChat> authorChats = chatService.selectAuthorChatList();
|
||||
public ResultBean<List<AuthorChat>> authorList(String authorId) {
|
||||
List<AuthorChat> authorChats = chatService.selectAuthorChatList(authorId);
|
||||
authorChats.stream().forEach(authorChat -> {
|
||||
authorChat.setIndex(String.valueOf(PinyinUtil.getFirstLetter(authorChat.getIndex().charAt(0))));
|
||||
if(authorChat.getCreateTime()!=null){
|
||||
authorChat.setLastSendTime(convertToShanghaiTimeZoneTimestamp( authorChat.getCreateTime()));
|
||||
}
|
||||
});
|
||||
return ResultBean.success(authorChats);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "作者相关聊天信息")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@GetMapping("/admin/chat/getAuthorChat")
|
||||
public ResultBean<IPage<MessageBean>> getAuthorChat(String authorId, String fromId) {
|
||||
ChatDto chatDto = new ChatDto();
|
||||
chatDto.setFromId(fromId);
|
||||
chatDto.setToId(authorId);
|
||||
|
||||
IPage chatPage = chatService.selectChatPage(chatDto);
|
||||
List<ChatVo> records = chatPage.getRecords();
|
||||
List<MessageBean> messageBeanList = new ArrayList<>();
|
||||
records.stream().forEach(chatVo -> {
|
||||
MessageBean messageBean = new MessageBean();
|
||||
messageBean.setId(chatVo.getChatId());
|
||||
messageBean.setContent(chatVo.getContent());
|
||||
messageBean.setSendTime(convertToShanghaiTimeZoneTimestamp(chatVo.getCreateTime()));
|
||||
messageBean.setStatus("succeed");
|
||||
messageBean.setType("text");
|
||||
messageBean.setToContactId(chatVo.getToId());
|
||||
MessageBean.FromUser fromUser = new MessageBean.FromUser();
|
||||
fromUser.setAvatar(chatVo.getFromAvatar());
|
||||
fromUser.setDisplayName(chatVo.getFromName());
|
||||
fromUser.setId(chatVo.getFromId());
|
||||
messageBean.setFromUser(fromUser);
|
||||
messageBeanList.add(messageBean);
|
||||
});
|
||||
chatPage.setRecords(messageBeanList);
|
||||
|
||||
return ResultBean.success(chatPage);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "-分页列表")
|
||||
|
@@ -1,10 +1,13 @@
|
||||
package com.dd.admin.business.chat.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -36,4 +39,7 @@ public class AuthorChat {
|
||||
// 最近一条消息的发送时间,通常是时间戳形式(单位可能是毫秒)
|
||||
@ApiModelProperty(value = "最近一条消息发送时间")
|
||||
private Long lastSendTime;
|
||||
|
||||
@JsonIgnore
|
||||
private Date CreateTime;
|
||||
}
|
||||
|
@@ -119,7 +119,8 @@
|
||||
wa.AVATAR_URL avatar,
|
||||
wa.AUTHOR_NAME AS 'index',
|
||||
wb.unReadCount unRead,
|
||||
UNIX_TIMESTAMP(CONVERT_TZ(wb.CREATE_TIME, '+08:00', '+00:00')) lastSendTime
|
||||
wb.content lastContent,
|
||||
wb.create_time
|
||||
FROM
|
||||
business_author wa
|
||||
LEFT JOIN (
|
||||
|
@@ -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;
|
@@ -55,8 +55,11 @@ public class ApiInterceptor implements HandlerInterceptor {
|
||||
request.setAttribute("authorId",authorId);
|
||||
|
||||
Author author = authorService.getById(authorId);
|
||||
if(author==null){
|
||||
throw new ApiException(700,"token已失效");
|
||||
}
|
||||
request.setAttribute("author",author);
|
||||
if(author.getAuthorStatus().equals(1)){
|
||||
if(author.getAuthorStatus()!=null&&author.getAuthorStatus().equals(1)){
|
||||
throw new ApiException(700,"当前用户已冻结~");
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user