feat: 消息接受和发送连表查询显示用户名

This commit is contained in:
Bunny 2024-10-30 23:44:21 +08:00
parent d4e2ec92ac
commit 5ebff699a2
14 changed files with 72 additions and 112 deletions

View File

@ -31,7 +31,6 @@ public class ${originalName}ServiceImpl extends ServiceImpl<${originalName}Mappe
*/
@Override
public PageResult<${originalName}Vo> get${originalName}List(Page<${originalName}> pageParams, ${originalName}Dto dto) {
// 分页查询菜单图标
IPage<${originalName}> page = baseMapper.selectListByPage(pageParams, dto);
List<${originalName}Vo> voList = page.getRecords().stream().map(${lowercaseName} -> {

View File

@ -14,7 +14,7 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "MessageAddDto对象", title = "系统消息", description = "系统消息")
@Schema(name = "MessageAddDto对象", title = "添加系统消息", description = "添加系统消息")
public class MessageAddDto {
@Schema(name = "title", title = "消息标题")
@ -22,18 +22,13 @@ public class MessageAddDto {
@NotBlank(message = "消息标题 不能为空")
private String title;
@Schema(name = "receivedUserId", title = "接收人用户ID")
private List<Long> receivedUserId;
@Schema(name = "receivedUserIds", title = "接收人用户ID")
private List<Long> receivedUserIds;
@Schema(name = "sendUserId", title = "发送人用户ID")
@NotNull(message = "发送人用户ID 不能为空")
private Long sendUserId;
@Schema(name = "sendNickName", title = "发送人昵称")
@NotBlank(message = "发送人昵称 不能为空")
@NotNull(message = "发送人昵称 不能为空")
private String sendNickName;
@Schema(name = "messageType", title = "消息类型")
@NotBlank(message = "消息类型 不能为空")
@NotNull(message = "消息类型 不能为空")

View File

@ -16,14 +16,8 @@ public class MessageDto {
@Schema(name = "title", title = "消息标题")
private String title;
@Schema(name = "receivedUserId", title = "接收人用户ID")
private Long receivedUserId;
@Schema(name = "sendUserId", title = "发送人用户ID")
private Long sendUserId;
@Schema(name = "sendNickName", title = "发送人昵称")
private String sendNickName;
@Schema(name = "sendNickname", title = "发送人用户昵称")
private String sendNickname;
@Schema(name = "messageType", title = "消息类型")
private String messageType;

View File

@ -26,18 +26,13 @@ public class MessageUpdateDto {
@NotBlank(message = "消息标题 不能为空")
private String title;
@Schema(name = "receivedUserId", title = "接收人用户ID")
private List<Long> receivedUserId;
@Schema(name = "receivedUserIds", title = "接收人用户ID")
private List<Long> receivedUserIds;
@Schema(name = "sendUserId", title = "发送人用户ID")
@NotNull(message = "发送人用户ID 不能为空")
private Long sendUserId;
@Schema(name = "sendNickName", title = "发送人昵称")
@NotBlank(message = "发送人昵称 不能为空")
@NotNull(message = "发送人昵称 不能为空")
private String sendNickName;
@Schema(name = "messageType", title = "消息类型")
@NotBlank(message = "消息类型 不能为空")
@NotNull(message = "消息类型 不能为空")

View File

@ -25,15 +25,12 @@ public class Message extends BaseEntity {
@Schema(name = "title", title = "消息标题")
private String title;
@Schema(name = "receivedUserId", title = "接收人用户ID")
private Long receivedUserId;
@Schema(name = "receivedUserIds", title = "接收人用户ID")
private String receivedUserIds;
@Schema(name = "sendUserId", title = "发送人用户ID")
private Long sendUserId;
@Schema(name = "sendNickName", title = "发送人昵称")
private String sendNickName;
@Schema(name = "messageType", title = "sys:系统消息,user用户消息")
private String messageType;

View File

@ -1,6 +1,6 @@
package cn.bunny.dao.vo.system.message;
import cn.bunny.dao.common.vo.BaseVo;
import cn.bunny.dao.common.vo.BaseUserVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -10,7 +10,7 @@ import lombok.*;
@NoArgsConstructor
@Builder
@Schema(name = "MessageTypeVo对象", title = "系统消息类型", description = "系统消息类型")
public class MessageTypeVo extends BaseVo {
public class MessageTypeVo extends BaseUserVo {
@Schema(name = "messageName", title = "消息名称")
private String messageName;

View File

@ -1,6 +1,9 @@
package cn.bunny.dao.vo.system.message;
import cn.bunny.dao.common.vo.BaseVo;
import cn.bunny.dao.common.vo.BaseUserVo;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -10,19 +13,21 @@ import lombok.*;
@NoArgsConstructor
@Builder
@Schema(name = "MessageVo对象", title = "系统消息返回内容", description = "系统消息返回内容")
public class MessageVo extends BaseVo {
public class MessageVo extends BaseUserVo {
@Schema(name = "title", title = "消息标题")
private String title;
@Schema(name = "receivedUserId", title = "接收人用户ID")
private Long receivedUserId;
@Schema(name = "sendUserId", title = "发送人用户ID")
@JsonFormat(shape = JsonFormat.Shape.STRING)
@JSONField(serializeUsing = ToStringSerializer.class)
private Long sendUserId;
@Schema(name = "sendNickName", title = "发送人昵称")
private String sendNickName;
@Schema(name = "sendNickname", title = "发送人昵称")
private String sendNickname;
@Schema(name = "receivedUserIds", title = "接收人用户ID")
private String receivedUserIds;
@Schema(name = "messageType", title = "sys:系统消息,user用户消息")
private String messageType;

View File

@ -1,7 +1,5 @@
package cn.bunny.services.factory;
import cn.bunny.dao.common.vo.TreeSelectVo;
import cn.bunny.dao.vo.system.router.RouterManageVo;
import cn.bunny.dao.vo.system.router.UserRouterVo;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
@ -30,33 +28,4 @@ public class RouterServiceFactory {
return list;
}
/**
* * 递归调用设置管理子路由
*
* @param nodeId 主键
* @param nodeList 返回VO列表
* @return 返回路由列表
*/
public List<RouterManageVo> handleGetChildrenWithRouterControllerVo(Long nodeId, List<RouterManageVo> nodeList) {
return nodeList.stream()
.filter(node -> node.getParentId().equals(nodeId))
.peek(node -> node.setChildren(handleGetChildrenWithRouterControllerVo(node.getId(), nodeList)))
.toList();
}
/**
* * 整理树形结构
*
* @param nodeId 节点ID
* @param nodeList 节点列表
* @return 树形列表
*/
public List<TreeSelectVo> handleGetTreeSelectList(Object nodeId, @NotNull List<TreeSelectVo> nodeList) {
// 使用 Stream API 找到所有子节点
return nodeList.stream()
.filter(node -> node.getParentId().equals(nodeId))
.peek(node -> node.setChildren(handleGetTreeSelectList(node.getValue(), nodeList)))
.toList();
}
}

View File

@ -2,6 +2,7 @@ package cn.bunny.services.mapper;
import cn.bunny.dao.dto.system.message.MessageDto;
import cn.bunny.dao.entity.system.Message;
import cn.bunny.dao.vo.system.message.MessageVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -28,7 +29,7 @@ public interface MessageMapper extends BaseMapper<Message> {
* @param dto 系统消息查询表单
* @return 系统消息分页结果
*/
IPage<Message> selectListByPage(@Param("page") Page<Message> pageParams, @Param("dto") MessageDto dto);
IPage<MessageVo> selectListByPage(@Param("page") Page<Message> pageParams, @Param("dto") MessageDto dto);
/**
* 物理删除系统消息

View File

@ -2,6 +2,7 @@ package cn.bunny.services.mapper;
import cn.bunny.dao.dto.system.message.MessageTypeDto;
import cn.bunny.dao.entity.system.MessageType;
import cn.bunny.dao.vo.system.message.MessageTypeVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -28,7 +29,7 @@ public interface MessageTypeMapper extends BaseMapper<MessageType> {
* @param dto 系统消息类型查询表单
* @return 系统消息类型分页结果
*/
IPage<MessageType> selectListByPage(@Param("page") Page<MessageType> pageParams, @Param("dto") MessageTypeDto dto);
IPage<MessageTypeVo> selectListByPage(@Param("page") Page<MessageType> pageParams, @Param("dto") MessageTypeDto dto);
/**
* 物理删除系统消息类型

View File

@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import jodd.util.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@ -37,15 +38,13 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
*/
@Override
public PageResult<MessageVo> getMessageList(Page<Message> pageParams, MessageDto dto) {
// 分页查询菜单图标
IPage<Message> page = baseMapper.selectListByPage(pageParams, dto);
IPage<MessageVo> page = baseMapper.selectListByPage(pageParams, dto);
List<MessageVo> voList = page.getRecords().stream().map(message -> {
MessageVo messageVo = new MessageVo();
BeanUtils.copyProperties(message, messageVo);
return messageVo;
List<MessageVo> voList = page.getRecords().stream().map(messageVo -> {
MessageVo vo = new MessageVo();
BeanUtils.copyProperties(messageVo, vo);
return vo;
}).toList();
return PageResult.<MessageVo>builder()
.list(voList)
.pageNo(page.getCurrent())
@ -64,6 +63,10 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
// 保存数据
Message message = new Message();
BeanUtils.copyProperties(dto, message);
// 将发送用户逗号分隔
String receivedUserIds = StringUtil.join(dto.getReceivedUserIds(), ",");
message.setReceivedUserIds(receivedUserIds);
save(message);
}
@ -77,6 +80,10 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
// 更新内容
Message message = new Message();
BeanUtils.copyProperties(dto, message);
// 将发送用户逗号分隔
String receivedUserIds = StringUtil.join(dto.getReceivedUserIds(), ",");
message.setReceivedUserIds(receivedUserIds);
updateById(message);
}

View File

@ -39,16 +39,10 @@ public class MessageTypeServiceImpl extends ServiceImpl<MessageTypeMapper, Messa
@Override
public PageResult<MessageTypeVo> getMessageTypeList(Page<MessageType> pageParams, MessageTypeDto dto) {
// 分页查询菜单图标
IPage<MessageType> page = baseMapper.selectListByPage(pageParams, dto);
List<MessageTypeVo> voList = page.getRecords().stream().map(messageType -> {
MessageTypeVo messageTypeVo = new MessageTypeVo();
BeanUtils.copyProperties(messageType, messageTypeVo);
return messageTypeVo;
}).toList();
IPage<MessageTypeVo> page = baseMapper.selectListByPage(pageParams, dto);
return PageResult.<MessageTypeVo>builder()
.list(voList)
.list(page.getRecords())
.pageNo(page.getCurrent())
.pageSize(page.getSize())
.total(page.getTotal())

View File

@ -13,7 +13,6 @@
<id column="title" property="title"/>
<id column="received_user_id" property="receivedUserId"/>
<id column="send_user_id" property="sendUserId"/>
<id column="send_nick_name" property="sendNickName"/>
<id column="message_type" property="messageType"/>
<id column="content" property="content"/>
<id column="editor_type" property="editorType"/>
@ -26,35 +25,35 @@
</sql>
<!-- 分页查询系统消息内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.Message">
<select id="selectListByPage" resultType="cn.bunny.dao.vo.system.message.MessageVo">
select
<include refid="Base_Column_List"/>
from sys_message
message.*,
create_user.username as create_username,
update_user.username as update_username,
send_user.nickname as send_nickname
from sys_message message
left join sys_user create_user on create_user.id = message.create_user
left join sys_user update_user on update_user.id = message.update_user
left join sys_user send_user on send_user.id = message.send_user_id
<where>
is_deleted = 0
message.is_deleted = 0
<if test="dto.title != null and dto.title != ''">
and title like CONCAT('%',#{dto.title},'%')
and message.title like CONCAT('%',#{dto.title},'%')
</if>
<if test="dto.receivedUserId != null and dto.receivedUserId != ''">
and received_user_id like CONCAT('%',#{dto.receivedUserId},'%')
</if>
<if test="dto.sendUserId != null and dto.sendUserId != ''">
and send_user_id like CONCAT('%',#{dto.sendUserId},'%')
</if>
<if test="dto.sendNickName != null and dto.sendNickName != ''">
and send_nick_name like CONCAT('%',#{dto.sendNickName},'%')
<if test="dto.sendNickname != null and dto.sendNickname != ''">
and send_user.nickname like CONCAT('%',#{dto.sendNickname},'%')
</if>
<if test="dto.messageType != null and dto.messageType != ''">
and message_type like CONCAT('%',#{dto.messageType},'%')
and message.message_type like CONCAT('%',#{dto.messageType},'%')
</if>
<if test="dto.content != null and dto.content != ''">
and content like CONCAT('%',#{dto.content},'%')
and message.content like CONCAT('%',#{dto.content},'%')
</if>
<if test="dto.editorType != null and dto.editorType != ''">
and editor_type like CONCAT('%',#{dto.editorType},'%')
and message.editor_type = #{dto.editorType}
</if>
<if test="dto.status != null and dto.status != ''">
and status like CONCAT('%',#{dto.status},'%')
<if test="dto.status != null">
and message.status = #{dto.status}
</if>
</where>
</select>

View File

@ -22,23 +22,27 @@
</sql>
<!-- 分页查询系统消息类型内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.MessageType">
<select id="selectListByPage" resultType="cn.bunny.dao.vo.system.message.MessageTypeVo">
select
<include refid="Base_Column_List"/>
from sys_message_type
message_type.*,
create_user.username as create_username,
update_user.username as update_username
from sys_message_type message_type
left join sys_user create_user on create_user.id = message_type.create_user
left join sys_user update_user on update_user.id = message_type.update_user
<where>
is_deleted = 0
message_type.is_deleted = 0
<if test="dto.status != null">
and status = #{dto.status}
</if>
<if test="dto.messageName != null and dto.messageName != ''">
and message_name like CONCAT('%',#{dto.messageName},'%')
and message_type.message_name like CONCAT('%',#{dto.messageName},'%')
</if>
<if test="dto.messageType != null and dto.messageType != ''">
and message_type like CONCAT('%',#{dto.messageType},'%')
and message_type.message_type like CONCAT('%',#{dto.messageType},'%')
</if>
<if test="dto.summary != null and dto.summary != ''">
and summary like CONCAT('%',#{dto.summary},'%')
and message_type.summary like CONCAT('%',#{dto.summary},'%')
</if>
</where>
</select>