第三方私聊记录、敏感词

This commit is contained in:
dzc committed 2025-11-26 11:05:16 +08:00
1 parent 3e8cc7d20e
commit 9564bb8c7f
14 files changed
+644 -4

No files matched your search

@@ -1,12 +1,22 @@
package cn.iocoder.yudao.module.member.client.service;
import cn.iocoder.yudao.module.member.client.vo.ChatTableRespVO;
import cn.iocoder.yudao.module.member.client.vo.friend.ChatAddFriendReqVo;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageCountReqVO;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageInfoReqVO;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageReqVO;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageRespVO;
import cn.iocoder.yudao.module.member.client.vo.sensitive.*;
import cn.iocoder.yudao.module.member.client.vo.user.*;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
public interface ChatApi {
/* *************************************** start 用户相关 start *************************************** */
/**
* 聊天用户登录
*/
@@ -27,4 +37,49 @@ public interface ChatApi {
*/
boolean addFriend(@Valid ChatAddFriendReqVo dto);
/* *************************************** end 用户相关 end *************************************** */
/* *************************************** start 敏感词 start *************************************** */
/**
* 敏感词分页
*/
ChatTableRespVO<ChatSensitiveRespVO> sensitivePage(ChatSensitiveReqVo dto);
/**
* 敏感词详情
*/
ChatSensitiveRespVO sensitiveGetInfo(ChatSensitiveInfoReqVo dto);
/**
* 创建或者更新敏感词
*/
boolean sensitiveCreateOrUpdate(ChatSensitiveSaveReqVo dto);
/**
* 删除敏感词
*/
boolean sensitiveDelByIds(ChatSensitiveDelReqVO dto);
/* *************************************** end 敏感词 end *************************************** */
/* *************************************** start 私聊 start *************************************** */
/**
* 私聊消息分页
*/
ChatTableRespVO<ChatPrivateMessageRespVO> privateMsgPage(ChatPrivateMessageReqVO dto);
/**
* 私聊消息详情
*/
ChatPrivateMessageRespVO privateMsgGetInfo(ChatPrivateMessageInfoReqVO dto);
/**
* 私聊消息统计
*/
List<Map> privateCount(ChatPrivateMessageCountReqVO dto);
/* *************************************** end 私聊 end *************************************** */
}
@@ -6,7 +6,13 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.module.member.client.tool.ChatApiTool;
import cn.iocoder.yudao.module.member.client.vo.ChatBaseRespVo;
import cn.iocoder.yudao.module.member.client.vo.ChatTableRespVO;
import cn.iocoder.yudao.module.member.client.vo.friend.ChatAddFriendReqVo;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageCountReqVO;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageInfoReqVO;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageReqVO;
import cn.iocoder.yudao.module.member.client.vo.privatemsg.ChatPrivateMessageRespVO;
import cn.iocoder.yudao.module.member.client.vo.sensitive.*;
import cn.iocoder.yudao.module.member.client.vo.user.*;
import cn.iocoder.yudao.module.member.framework.web.config.ChatProperties;
import lombok.extern.slf4j.Slf4j;
@@ -24,6 +30,8 @@ public class ChatApiImpl implements ChatApi {
@Resource
private ChatProperties chatProperties;
/* *************************************** start 用户相关 start *************************************** */
/**
* 聊天用户登录
*/
@@ -142,6 +150,249 @@ public class ChatApiImpl implements ChatApi {
}
}
/* *************************************** end 用户相关 end *************************************** */
/* *************************************** start 敏感词 start *************************************** */
/**
* 敏感词分页
*/
@Override
public ChatTableRespVO<ChatSensitiveRespVO> sensitivePage(ChatSensitiveReqVo dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.SENSITIVE_PAGE);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("敏感词分页,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("敏感词分页,res为空");
return null;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("敏感词分页,返回错误");
return null;
}
ChatTableRespVO vo = JSONUtil.toBean(baseRes.getData(), ChatTableRespVO.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("敏感词分页,返回json解析错误");
return null;
}
if (ObjectUtil.isEmpty(vo.getRows())) {
log.error("敏感词分页,rows为空");
return null;
}
vo.setRows(JSONUtil.toList(String.valueOf(vo.getRows()), ChatSensitiveRespVO.class));
return vo;
} catch (Exception e) {
e.printStackTrace();
log.error("敏感词分页,意外的错误", e);
return null;
}
}
/**
* 敏感词详情
*/
@Override
public ChatSensitiveRespVO sensitiveGetInfo(ChatSensitiveInfoReqVo dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.SENSITIVE_INFO);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("敏感词详情,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("敏感词详情,res为空");
return null;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("敏感词详情,返回错误");
return null;
}
ChatSensitiveRespVO vo = JSONUtil.toBean(baseRes.getData(), ChatSensitiveRespVO.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("敏感词详情,返回json解析错误");
return null;
}
return vo;
} catch (Exception e) {
e.printStackTrace();
log.error("敏感词详情,意外的错误", e);
return null;
}
}
/**
* 创建或者更新敏感词
*/
@Override
public boolean sensitiveCreateOrUpdate(ChatSensitiveSaveReqVo dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.SENSITIVE_CREATE_OR_UPDATE);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("创建或者更新敏感词,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("创建或者更新敏感词,res为空");
return false;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("创建或者更新敏感词,返回错误");
return false;
}
ChatPrivateMessageRespVO vo = JSONUtil.toBean(baseRes.getData(), ChatPrivateMessageRespVO.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("创建或者更新敏感词,返回json解析错误");
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("创建或者更新敏感词,意外的错误", e);
return false;
}
}
/**
* 删除敏感词
*/
@Override
public boolean sensitiveDelByIds(ChatSensitiveDelReqVO dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.SENSITIVE_DELETAE);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("删除敏感词,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("删除敏感词,res为空");
return false;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("删除敏感词,返回错误");
return false;
}
ChatPrivateMessageRespVO vo = JSONUtil.toBean(baseRes.getData(), ChatPrivateMessageRespVO.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("删除敏感词,返回json解析错误");
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("删除敏感词,意外的错误", e);
return false;
}
}
/* *************************************** end 敏感词 end *************************************** */
/* *************************************** start 私聊 start *************************************** */
/**
* 私聊消息分页
*/
@Override
public ChatTableRespVO<ChatPrivateMessageRespVO> privateMsgPage(ChatPrivateMessageReqVO dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.PRIVATE_MSG_PAGE);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("私聊消息分页,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("私聊消息分页,res为空");
return null;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("私聊消息分页,返回错误");
return null;
}
ChatTableRespVO vo = JSONUtil.toBean(baseRes.getData(), ChatTableRespVO.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("私聊消息分页,返回json解析错误");
return null;
}
if (ObjectUtil.isEmpty(vo.getRows())) {
log.error("私聊消息分页,rows为空");
return null;
}
vo.setRows(JSONUtil.toList(String.valueOf(vo.getRows()), ChatPrivateMessageRespVO.class));
return vo;
} catch (Exception e) {
e.printStackTrace();
log.error("私聊消息分页,意外的错误", e);
return null;
}
}
/**
* 私聊消息详情
*/
@Override
public ChatPrivateMessageRespVO privateMsgGetInfo(ChatPrivateMessageInfoReqVO dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.PRIVATE_MSG_INFO);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("私聊消息详情,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("私聊消息详情,res为空");
return null;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("私聊消息详情,返回错误");
return null;
}
ChatPrivateMessageRespVO vo = JSONUtil.toBean(baseRes.getData(), ChatPrivateMessageRespVO.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("私聊消息详情,返回json解析错误");
return null;
}
return vo;
} catch (Exception e) {
e.printStackTrace();
log.error("聊天用户登录,意外的错误", e);
return null;
}
}
/**
* 私聊消息统计
*/
@Override
public List<Map> privateCount(ChatPrivateMessageCountReqVO dto) {
ChatApiTool.API api = setApiConfig(ChatApiTool.PRIVATE_MSG_COUNT);
try {
String body = JSONUtil.toJsonStr(dto);
String res = HttpRequest.post(api.getFullPath()).header(apiCountersign(body)).body(body).execute().body();
log.debug("私聊消息统计,res:{}", res);
if (ObjectUtil.isEmpty(res)) {
log.error("私聊消息统计,res为空");
return null;
}
ChatBaseRespVo baseRes = JSONUtil.toBean(res, ChatBaseRespVo.class);
if (ObjectUtil.isEmpty(baseRes) || !baseRes.isSuccess()) {
log.error("私聊消息统计,返回错误");
return null;
}
List<Map> vo = JSONUtil.toList(baseRes.getData(), Map.class);
if (ObjectUtil.isEmpty(vo)) {
log.error("私聊消息统计,返回json解析错误");
return null;
}
return null;
} catch (Exception e) {
e.printStackTrace();
log.error("私聊消息统计,意外的错误", e);
return null;
}
}
/* *************************************** end 私聊 end *************************************** */
private ChatApiTool.API setApiConfig(ChatApiTool.API api) {
if (ObjectUtil.isNotEmpty(api)) {
api.setHost(chatProperties.getBaseUrl());
@@ -17,12 +17,25 @@ import java.util.Map;
*/
public class ChatApiTool {
// 用户相关
public static final API USER_LOGIN = API.builder().summary("用户登录").url("/third/user/login").method(HttpMethod.POST).build();
public static final API USER_GET = API.builder().summary("根据userId查询用户详情").url("/third/user/getUserByUserId").method(HttpMethod.POST).build();
public static final API USER_SAVE_OR_UPDATE = API.builder().summary("创建或者更新用户").url("/third/user/createOrUpdate").method(HttpMethod.POST).build();
// 朋友圈
public static final API FRIEND_ADD = API.builder().summary("添加好友").url("/third/friend/add").method(HttpMethod.POST).build();
// 私聊
public static final API PRIVATE_MSG_PAGE = API.builder().summary("私聊分页").url("/third/privateMsg/page").method(HttpMethod.POST).build();
public static final API PRIVATE_MSG_INFO = API.builder().summary("私聊详情").url("/third/privateMsg/getById").method(HttpMethod.POST).build();
public static final API PRIVATE_MSG_COUNT = API.builder().summary("私聊统计").url("/third/privateMsg/dailyCount").method(HttpMethod.POST).build();
// 敏感词
public static final API SENSITIVE_PAGE = API.builder().summary("敏感词分页").url("/third/sensitive/page").method(HttpMethod.POST).build();
public static final API SENSITIVE_INFO = API.builder().summary("敏感词详情").url("/third/sensitive/getById").method(HttpMethod.POST).build();
public static final API SENSITIVE_CREATE_OR_UPDATE = API.builder().summary("敏感词创建或者更新").url("/third/sensitive/createOrUpdate").method(HttpMethod.POST).build();
public static final API SENSITIVE_DELETAE = API.builder().summary("敏感词删除").url("/third/sensitive/delByIds").method(HttpMethod.POST).build();
@Data
@Builder
@AllArgsConstructor
@@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.member.client.vo;
import cn.hutool.http.HttpStatus;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* chat表格分页数据对象
*/
@Data
@NoArgsConstructor
public class ChatTableRespVO<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 总记录数
*/
private long total;
/**
* 列表数据
*/
private List<T> rows;
/**
* 消息状态码
*/
private int code;
/**
* 消息内容
*/
private String msg;
/**
* 分页
*
* @param list 列表数据
* @param total 总记录数
*/
public ChatTableRespVO(List<T> list, long total) {
this.rows = list;
this.total = total;
}
/**
* 根据分页对象构建表格分页数据对象
*/
public static <T> ChatTableRespVO<T> build(IPage<T> page) {
ChatTableRespVO<T> rspData = new ChatTableRespVO<>();
rspData.setCode(HttpStatus.HTTP_OK);
rspData.setMsg("查询成功");
rspData.setRows(page.getRecords());
rspData.setTotal(page.getTotal());
return rspData;
}
/**
* 根据数据列表构建表格分页数据对象
*/
public static <T> ChatTableRespVO<T> build(List<T> list) {
ChatTableRespVO<T> rspData = new ChatTableRespVO<>();
rspData.setCode(HttpStatus.HTTP_OK);
rspData.setMsg("查询成功");
rspData.setRows(list);
rspData.setTotal(list.size());
return rspData;
}
/**
* 构建表格分页数据对象
*/
public static <T> ChatTableRespVO<T> build() {
ChatTableRespVO<T> rspData = new ChatTableRespVO<>();
rspData.setCode(HttpStatus.HTTP_OK);
rspData.setMsg("查询成功");
return rspData;
}
}
@@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.member.client.vo.privatemsg;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@Schema(description = "third私聊记录DTO")
public class ChatPrivateMessageCountReqVO {
@NotNull(message = "统计天数不存在")
@Schema(description = "统计天数")
private Integer days;
}
@@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.member.client.vo.privatemsg;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@Schema(description = "third私聊记录详情DTO")
public class ChatPrivateMessageInfoReqVO {
@NotNull(message = "msgId不存在")
@Schema(description = "msgId")
private Long msgId;
}
@@ -0,0 +1,44 @@
package cn.iocoder.yudao.module.member.client.vo.privatemsg;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Data
@Schema(description = "third私聊记录DTO")
public class ChatPrivateMessageReqVO {
@Schema(description = "分页大小")
private Integer pageSize;
@Schema(description = "当前页数")
private Integer pageNum;
@Schema(description = "id")
private Long id;
@Schema(description = "发送用户id")
private Long sendId;
@Schema(description = "接收用户id")
private Long recvId;
@Schema(description = "发送内容")
private String content;
@Schema(description = "消息类型 0:文字 1:图片 2:文件")
private Long type;
@Schema(description = "状态 0:未读 1:已读")
private Long status;
@Schema(description = "发送时间")
private Date sendTime;
@Schema(description = "请求参数")
private Map<String, Object> params = new HashMap<>();
}
@@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.member.client.vo.privatemsg;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
@Data
@Schema(description = "third私聊记录VO")
public class ChatPrivateMessageRespVO {
@Schema(description = "id")
private Long id;
@Schema(description = "发送用户id")
private Long sendId;
@Schema(description = "发送用户")
private String sendUserName;
@Schema(description = "接收用户id")
private Long recvId;
@Schema(description = "接收用户")
private String recvUserName;
@Schema(description = "发送内容")
private String content;
@Schema(description = "消息类型")
private Long type;
@Schema(description = "状态")
private Long status;
@Schema(description = "发送时间")
private Date sendTime;
}
@@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.member.client.vo.sensitive;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
@Schema(description = "third敏感词删除DTO")
public class ChatSensitiveDelReqVO {
@NotEmpty(message = "敏感词ids不能为空")
@Schema(description = "敏感词ids")
private List<Long> sensitiveIds;
}
@@ -0,0 +1,13 @@
package cn.iocoder.yudao.module.member.client.vo.sensitive;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "third敏感词详情DTO")
public class ChatSensitiveInfoReqVo {
@Schema(description = "敏感词id")
private Long sensitiveId;
}
@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.member.client.vo.sensitive;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
@Data
@Schema(description = "third敏感词DTO")
public class ChatSensitiveReqVo {
@Schema(description = "分页大小")
private Integer pageSize;
@Schema(description = "当前页数")
private Integer pageNum;
@Schema(description = "敏感词内容")
private String content;
@Schema(description = "是否启用")
private Boolean enabled;
@Schema(description = "创建者")
private Long creator;
@Schema(description = "创建时间")
private Date createTime;
}
@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.member.client.vo.sensitive;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
@Data
@Schema(description = "third敏感词VO")
public class ChatSensitiveRespVO {
@Schema(description = "id")
private Long id;
@Schema(description = "敏感词内容")
private String content;
@Schema(description = "是否启用")
private Boolean enabled;
@Schema(description = "创建者")
private Long creator;
@Schema(description = "创建者")
private String creatorName;
@Schema(description = "创建时间")
private Date createTime;
}
@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.member.client.vo.sensitive;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@Data
@Schema(description = "third新增或修改DTO")
public class ChatSensitiveSaveReqVo {
@Schema(description = "id")
private Long id;
@NotEmpty(message = "敏感词内容不能为空")
@Schema(description = "敏感词内容")
private String content;
@Schema(description = "是否启用")
private Boolean enabled;
}
@@ -25,10 +25,19 @@ public class AppMemeberChatController {
@GetMapping("/add-friend")
@Operation(summary = "创建用户反馈")
public CommonResult<Boolean> createFeedback(@RequestParam("friendUserId") Long friendUserId) {
ChatAddFriendReqVo createReqVO = new ChatAddFriendReqVo();
createReqVO.setUserId(getLoginUserId());
createReqVO.setTargetUserId(friendUserId);
return success(chatApi.addFriend(createReqVO));
Long currentUserId = getLoginUserId();
// 相互添加一下好友
ChatAddFriendReqVo self = new ChatAddFriendReqVo();
self.setUserId(currentUserId);
self.setTargetUserId(friendUserId);
chatApi.addFriend(self);
ChatAddFriendReqVo target = new ChatAddFriendReqVo();
target.setUserId(friendUserId);
target.setTargetUserId(currentUserId);
chatApi.addFriend(target);
return success(true);
}
}