feat:发送消息限制
This commit is contained in:
1 parent
d44a87efee
commit
b24ed26504
7 files changed
+174
-1
No files matched your search
+5
@@ -65,6 +65,11 @@ public interface ChatApi {
|
||||
|
||||
/* *************************************** start 私聊 start *************************************** */
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
ChatPrivateMessageSendResVO send(ChatPrivateMessageSendReqVO dto);
|
||||
|
||||
/**
|
||||
* 私聊消息分页
|
||||
*/
|
||||
|
||||
+32
@@ -290,6 +290,38 @@ public class ChatApiImpl implements ChatApi {
|
||||
|
||||
/* *************************************** start 私聊 start *************************************** */
|
||||
|
||||
/**
|
||||
* 发私聊送消息
|
||||
*/
|
||||
@Override
|
||||
public ChatPrivateMessageSendResVO send(ChatPrivateMessageSendReqVO 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;
|
||||
}
|
||||
ChatPrivateMessageSendResVO vo = JSONUtil.toBean(baseRes.getData(), ChatPrivateMessageSendResVO.class);
|
||||
if (ObjectUtil.isEmpty(vo)) {
|
||||
log.error("发私聊送消息,返回json解析错误");
|
||||
return null;
|
||||
}
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("聊天用户登录,意外的错误", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 私聊消息分页
|
||||
*/
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package cn.iocoder.yudao.module.member.client.vo.chat.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@Schema(description = "chat用户发送消息req")
|
||||
public class ChatPrivateMessageSendReqVO {
|
||||
|
||||
@Schema(description = "发送用户id")
|
||||
private Long sendId;
|
||||
|
||||
/**
|
||||
* +0:web
|
||||
* +1:app
|
||||
* +2:pc
|
||||
* -1:未知
|
||||
*/
|
||||
@Schema(description = "发送终端类型")
|
||||
private Integer terminal = 1;
|
||||
|
||||
@Schema(description = "临时id")
|
||||
private String tmpId;
|
||||
|
||||
@NotNull(message = "接收用户id不可为空")
|
||||
@Schema(description = "接收用户id")
|
||||
private Long recvId;
|
||||
|
||||
@Length(max = 1024, message = "内容长度不得大于1024")
|
||||
@NotEmpty(message = "发送内容不可为空")
|
||||
@Schema(description = "发送内容")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "消息类型不可为空")
|
||||
@Schema(description = "消息类型 0:文字 1:图片 2:文件 3:语音 4:视频")
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.member.client.vo.chat.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(description = "chat用户发送消息resp")
|
||||
public class ChatPrivateMessageSendResVO {
|
||||
|
||||
@Schema(description = " 消息id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "临时id")
|
||||
private String tmpId;
|
||||
|
||||
@Schema(description = " 发送者id")
|
||||
private Long sendId;
|
||||
|
||||
@Schema(description = " 接收者id")
|
||||
private Long recvId;
|
||||
|
||||
@Schema(description = " 发送内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "消息内容类型 MessageType")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = " 状态")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = " 发送时间")
|
||||
private Date sendTime;
|
||||
|
||||
}
|
||||
+10
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.member.controller.app.chat;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.member.client.service.ChatApi;
|
||||
import cn.iocoder.yudao.module.member.client.vo.chat.friend.ChatAddFriendReqVo;
|
||||
import cn.iocoder.yudao.module.member.client.vo.chat.user.ChatPrivateMessageSendReqVO;
|
||||
import cn.iocoder.yudao.module.member.client.vo.chat.user.ChatPrivateMessageSendResVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -22,6 +24,14 @@ public class AppChatController {
|
||||
@Resource
|
||||
private ChatApi chatApi;
|
||||
|
||||
@GetMapping("/send-private-msg")
|
||||
@Operation(summary = "创建用户反馈")
|
||||
public CommonResult<ChatPrivateMessageSendResVO> sendPrivateMsg(@RequestBody ChatPrivateMessageSendReqVO body) {
|
||||
body.setSendId(getLoginUserId());
|
||||
body.setTerminal(1);
|
||||
return success(chatApi.send(body));
|
||||
}
|
||||
|
||||
@GetMapping("/add-friend")
|
||||
@Operation(summary = "创建用户反馈")
|
||||
public CommonResult<Boolean> createFeedback(@RequestParam("friendUserId") Long friendUserId) {
|
||||
|
||||
+5
@@ -48,4 +48,9 @@ public interface OpenTypeService {
|
||||
* 购买会员
|
||||
*/
|
||||
Long payOpenType(AppPayOpenReqType dto);
|
||||
|
||||
/**
|
||||
* 判断用户是否还可以发送消息
|
||||
*/
|
||||
boolean isUserCanSendMessage(Long userId);
|
||||
}
|
||||
+44
-1
@@ -2,6 +2,10 @@ package cn.iocoder.yudao.module.member.service.opentype;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import cn.iocoder.yudao.module.member.client.service.ChatApi;
|
||||
import cn.iocoder.yudao.module.member.client.vo.chat.ChatTableRespVO;
|
||||
import cn.iocoder.yudao.module.member.client.vo.chat.privatemsg.ChatPrivateMessageReqVO;
|
||||
import cn.iocoder.yudao.module.member.client.vo.chat.privatemsg.ChatPrivateMessageRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.opentype.vo.AppPayOpenReqType;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.opentype.OpenTypeUserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
@@ -9,6 +13,7 @@ import cn.iocoder.yudao.module.member.dal.mysql.opentype.OpenTypeUserMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.MemberErrorCode;
|
||||
import cn.iocoder.yudao.module.member.enums.opentype.OpenTypeUserStatusEnum;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -24,7 +29,11 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.opentype.OpenTypeMapper;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -32,6 +41,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
||||
/**
|
||||
* 会员类型 Service 实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Validated
|
||||
public class OpenTypeServiceImpl implements OpenTypeService {
|
||||
@@ -43,6 +53,9 @@ public class OpenTypeServiceImpl implements OpenTypeService {
|
||||
@Resource
|
||||
private OpenTypeUserMapper openTypeUserMapper;
|
||||
|
||||
@Resource
|
||||
private ChatApi chatApi;
|
||||
|
||||
|
||||
/**
|
||||
* 创建会员类型
|
||||
@@ -128,12 +141,42 @@ public class OpenTypeServiceImpl implements OpenTypeService {
|
||||
} else {
|
||||
openTypeUserObj.setEndTime(now.plusDays(openType.getDuration()));
|
||||
}
|
||||
|
||||
|
||||
// 新增会员开通表
|
||||
openTypeUserMapper.insert(openTypeUserObj);
|
||||
return openTypeUserObj.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否还可以发送消息
|
||||
*/
|
||||
@Override
|
||||
public boolean isUserCanSendMessage(Long userId) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
Date startDate = Date.from(now.withHour(0).withMinute(0).withSecond(0).atZone(ZoneId.systemDefault()).toInstant());
|
||||
Date endDate = Date.from(now.withHour(23).withMinute(59).withSecond(59).atZone(ZoneId.systemDefault()).toInstant());
|
||||
|
||||
ChatPrivateMessageReqVO dto = new ChatPrivateMessageReqVO();
|
||||
dto.setPageNum(1);
|
||||
dto.setPageSize(100);
|
||||
dto.setSendId(userId);
|
||||
dto.setSendTimeList(new ArrayList<Date>() {{
|
||||
add(startDate);
|
||||
add(endDate);
|
||||
}});
|
||||
try {
|
||||
ChatTableRespVO<ChatPrivateMessageRespVO> page = chatApi.privateMsgPage(dto);
|
||||
if (ObjectUtil.isEmpty(page) || ObjectUtil.isEmpty(page.getRows())) return true;
|
||||
List<ChatPrivateMessageRespVO> rows = page.getRows();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|判断用户是否还可以发送消息|意外的错误:{}", e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void validateOpenTypeExists(Long id) {
|
||||
if (openTypeMapper.selectById(id) == null) {
|
||||
throw exception(MemberErrorCode.OPEN_TYPE_NOT_EXISTS);
|
||||
|
||||
Reference in new issue
Block a user