diff --git a/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java b/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java index 893977c..78ec64a 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java @@ -1,5 +1,6 @@ package com.bx.implatform.controller.third; +import com.bx.implatform.dto.MessageTotalDto; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageInfoDTO; @@ -7,6 +8,7 @@ import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageSendDTO; import com.bx.implatform.result.Result; import com.bx.implatform.result.ResultUtils; import com.bx.implatform.service.third.ThirdPrivateMsgService; +import com.bx.implatform.vo.MessageTotalVo; import com.bx.implatform.vo.PrivateMessageVO; import com.bx.implatform.vo.third.ThirdTableVO; import com.bx.implatform.vo.third.privatemsg.ThirdPrivateMessageVO; @@ -59,4 +61,11 @@ public class ThirdPrivateMsgController { return ResultUtils.success(vo); } + @PostMapping("/total") + @Operation(summary = "私聊消息发送消息的统计", description = "私聊消息发送消息的统计") + public Result> total(@Valid @RequestBody MessageTotalDto dto) { + List vo = thirdPrivateMsgService.total(dto); + return ResultUtils.success(vo); + } + } diff --git a/im-platform/src/main/java/com/bx/implatform/dto/MessageTotalDto.java b/im-platform/src/main/java/com/bx/implatform/dto/MessageTotalDto.java new file mode 100644 index 0000000..1f24001 --- /dev/null +++ b/im-platform/src/main/java/com/bx/implatform/dto/MessageTotalDto.java @@ -0,0 +1,25 @@ +package com.bx.implatform.dto; + +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class MessageTotalDto { + + /** + * 发送人id + */ + private Long sendId; + + /** + * 接收人id + */ + private Long receiveId; + + /** + * 发送时间范围 + */ + private LocalDateTime[] timeRange; + +} diff --git a/im-platform/src/main/java/com/bx/implatform/mapper/PrivateMessageMapper.java b/im-platform/src/main/java/com/bx/implatform/mapper/PrivateMessageMapper.java index 75abc2f..304324d 100644 --- a/im-platform/src/main/java/com/bx/implatform/mapper/PrivateMessageMapper.java +++ b/im-platform/src/main/java/com/bx/implatform/mapper/PrivateMessageMapper.java @@ -1,7 +1,9 @@ package com.bx.implatform.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bx.implatform.dto.MessageTotalDto; import com.bx.implatform.entity.PrivateMessage; +import com.bx.implatform.vo.MessageTotalVo; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -18,4 +20,6 @@ public interface PrivateMessageMapper extends BaseMapper { ) List> getDailyMessageCount(@Param("days") Integer days); + List total(@Param("dto") MessageTotalDto dto); + } diff --git a/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java b/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java index 00580d6..078dd77 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java @@ -1,9 +1,11 @@ package com.bx.implatform.service.third; +import com.bx.implatform.dto.MessageTotalDto; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageInfoDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageSendDTO; +import com.bx.implatform.vo.MessageTotalVo; import com.bx.implatform.vo.PrivateMessageVO; import com.bx.implatform.vo.third.ThirdTableVO; import com.bx.implatform.vo.third.privatemsg.ThirdPrivateMessageVO; @@ -33,4 +35,9 @@ public interface ThirdPrivateMsgService { * 按天统计私聊消息量 */ List> getDailyMessageCount(@Valid ThirdPrivateMessageCountDTO dto); + + /** + * 私聊消息发送消息的统计 + */ + List total(@Valid MessageTotalDto dto); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java index e28c2e8..5fb2665 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java @@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.bx.imclient.IMClient; import com.bx.imcommon.model.IMPrivateMessage; import com.bx.imcommon.model.IMUserInfo; +import com.bx.implatform.dto.MessageTotalDto; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO; import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageInfoDTO; @@ -29,6 +30,7 @@ import com.bx.implatform.session.SessionContext; import com.bx.implatform.session.UserSession; import com.bx.implatform.util.BeanUtils; import com.bx.implatform.util.SensitiveFilterUtil; +import com.bx.implatform.vo.MessageTotalVo; import com.bx.implatform.vo.PrivateMessageVO; import com.bx.implatform.vo.third.ThirdTableVO; import com.bx.implatform.vo.third.privatemsg.ThirdPrivateMessageVO; @@ -47,6 +49,7 @@ import java.util.*; public class ThirdPrivateMsgServiceImpl extends ServiceImpl implements ThirdPrivateMsgService { private final UserMapper userMapper; + private final PrivateMessageMapper privateMessageMapper; private final IMClient imClient; private final FriendService friendService; @@ -151,6 +154,43 @@ public class ThirdPrivateMsgServiceImpl extends ServiceImpl total(MessageTotalDto dto) { + List totalList = privateMessageMapper.total(dto); + disposeTotalList(totalList); + return totalList; + } + + private void disposeTotalList(List totalList) { + if (ObjectUtil.isEmpty(totalList)) return; + List sendIdList = totalList.stream().map(MessageTotalVo::getSendId).distinct().filter(ObjectUtil::isNotEmpty).toList(); + List receiveIdList = totalList.stream().map(MessageTotalVo::getReceiveId).distinct().filter(ObjectUtil::isNotEmpty).toList(); + HashSet userIdList = new HashSet<>(); + userIdList.addAll(sendIdList); + userIdList.addAll(receiveIdList); + if (ObjectUtil.isNotEmpty(userIdList)) { + List users = userMapper.selectList(new LambdaQueryWrapper() + .in(User::getId, userIdList.stream().toList()) + ); + if (ObjectUtil.isNotEmpty(users)) { + Map map = IterUtil.toMap(users, User::getId); + for (MessageTotalVo total : totalList) { + User sendUser = map.get(total.getSendId()); + if (ObjectUtil.isNotEmpty(sendUser)) { + total.setSendName(sendUser.getNickName()); + } + User receiveUser = map.get(total.getReceiveId()); + if (ObjectUtil.isNotEmpty(receiveUser)) { + total.setReceiveName(receiveUser.getNickName()); + } + } + } + } + } + private LambdaQueryWrapper buildQueryWrapper(ThirdPrivateMessageDTO bo) { List sendIds = new ArrayList<>(); List recvIds = new ArrayList<>(); diff --git a/im-platform/src/main/java/com/bx/implatform/vo/MessageTotalVo.java b/im-platform/src/main/java/com/bx/implatform/vo/MessageTotalVo.java new file mode 100644 index 0000000..5b2e18b --- /dev/null +++ b/im-platform/src/main/java/com/bx/implatform/vo/MessageTotalVo.java @@ -0,0 +1,33 @@ +package com.bx.implatform.vo; + +import lombok.Data; + +@Data +public class MessageTotalVo { + + /** + * 发送者id + */ + private Long sendId; + + /** + * 发送名 + */ + private String sendName; + + /** + * 接受者id + */ + private Long receiveId; + + /** + * 接收者名称 + */ + private String receiveName; + + /** + * 消息总数 + */ + private Long messageTotal; + +} diff --git a/im-platform/src/main/resources/application.yml b/im-platform/src/main/resources/application.yml index ae5abb0..e7585f2 100644 --- a/im-platform/src/main/resources/application.yml +++ b/im-platform/src/main/resources/application.yml @@ -21,6 +21,7 @@ mybatis-plus: map-underscore-to-camel-case: true #开启自动驼峰命名规则 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + jwt: accessToken: expireIn: 1800 #半个小时 @@ -31,3 +32,4 @@ jwt: + diff --git a/im-platform/src/main/resources/mapper/PrivateMessageMapper.xml b/im-platform/src/main/resources/mapper/PrivateMessageMapper.xml new file mode 100644 index 0000000..97ec3bb --- /dev/null +++ b/im-platform/src/main/resources/mapper/PrivateMessageMapper.xml @@ -0,0 +1,28 @@ + + + + + + + + and a.send_id = #{dto.sendId} + + + and a.recv_id = #{dto.recvId} + + + and a.send_time between #{dto.timeRange[0]} and #{dto.timeRange[1]} + + + + + +