feat(消息模块与部门模块): 修改了消息模块的bug并从新建消息接口中独立出添加附件接口,部门模块新添加了部门树返回接口
This commit is contained in:
parent
5b6a97b668
commit
8d6fa0b244
@ -12,6 +12,9 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Component
|
||||
public class DeptTreeUtil {
|
||||
|
||||
|
@ -4,19 +4,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessagePayload;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户消息Controller
|
||||
|
@ -16,6 +16,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface UserMessageRepository extends BaseMapper<UserMessage> {
|
||||
|
||||
UserMessageVo selectByMessageIdAndUserId(@Param("messageId") Long messageId, @Param("userId") Long userId);
|
||||
|
||||
IPage<UserMessageVo> query(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
||||
|
@ -44,7 +44,6 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
private final MessageRepository messageRepo;
|
||||
private final MessageSettingRepository messageSettingRepo;
|
||||
private final UserService userService;
|
||||
private final AttachmentService attachmentService;
|
||||
private final EmailSender emailSender;
|
||||
private final SmsSender smsSender;
|
||||
private final UserMessageRepository userMessageRepository;
|
||||
@ -60,6 +59,14 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
|
||||
@Override
|
||||
public UserMessageVo detail(Long messageId, Long userId) {
|
||||
if (userMessageRepository.selectByMessageIdAndUserId(messageId, userId) == null) {
|
||||
UserMessage userMessage = new UserMessage();
|
||||
userMessage.setUserId(userId);
|
||||
userMessage.setMessageId(messageId);
|
||||
userMessage.setIsRead(false);
|
||||
userMessage.setReadTime(LocalDateTime.now());
|
||||
save(userMessage);
|
||||
}
|
||||
return userMessageRepository.selectByMessageIdAndUserId(messageId, userId);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
@ -18,10 +19,6 @@ import java.util.List;
|
||||
@Data
|
||||
public class UserMessageVo {
|
||||
private Long id;
|
||||
public Long userId;
|
||||
public User user;
|
||||
public Long messageId;
|
||||
public Message message;
|
||||
public Boolean isRead;
|
||||
public LocalDateTime readTime;
|
||||
|
||||
@ -47,5 +44,5 @@ public class UserMessageVo {
|
||||
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||
private String updateBy;
|
||||
|
||||
public List<Attachment> attachments;
|
||||
public List<AttachmentVo> attachments;
|
||||
}
|
||||
|
@ -291,24 +291,31 @@ comment on column sys_user.enabled_status is '状态';
|
||||
alter table sys_user
|
||||
owner to postgres;
|
||||
|
||||
create table sys_user_message
|
||||
CREATE TABLE sys_user_message
|
||||
(
|
||||
id bigint not null
|
||||
constraint sys_user_message_pk
|
||||
primary key,
|
||||
user_id bigint not null,
|
||||
message_id bigint not null,
|
||||
is_read boolean not null,
|
||||
id bigserial NOT NULL
|
||||
CONSTRAINT sys_user_message_pk
|
||||
PRIMARY KEY,
|
||||
user_id bigint NOT NULL,
|
||||
message_id bigint NOT NULL,
|
||||
is_read boolean NOT NULL,
|
||||
read_time timestamp
|
||||
);
|
||||
comment on table sys_user_message is '用户消息';
|
||||
comment on column sys_user_message.id is '主键';
|
||||
comment on column sys_user_message.user_id is '用户';
|
||||
comment on column sys_user_message.message_id is '消息';
|
||||
comment on column sys_user_message.is_read is '是否已读';
|
||||
comment on column sys_user_message.read_time is '阅读时间';
|
||||
alter table sys_user_message
|
||||
owner to postgres;
|
||||
|
||||
COMMENT ON TABLE sys_user_message IS '用户消息';
|
||||
COMMENT ON COLUMN sys_user_message.id IS '主键';
|
||||
COMMENT ON COLUMN sys_user_message.user_id IS '用户';
|
||||
COMMENT ON COLUMN sys_user_message.message_id IS '消息';
|
||||
COMMENT ON COLUMN sys_user_message.is_read IS '是否已读';
|
||||
COMMENT ON COLUMN sys_user_message.read_time IS '阅读时间';
|
||||
|
||||
ALTER TABLE sys_user_message
|
||||
OWNER TO postgres;
|
||||
|
||||
-- 确保序列从1开始
|
||||
SELECT setval('sys_user_message_id_seq', 1, false);
|
||||
|
||||
|
||||
|
||||
create table sys_users_roles
|
||||
(
|
||||
@ -457,20 +464,12 @@ VALUES (1, TRUE, FALSE),
|
||||
(10, FALSE, TRUE);
|
||||
|
||||
INSERT INTO attachment (id, file_name, mime_type, url, upload_time)
|
||||
VALUES ('8', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf',
|
||||
CURRENT_TIMESTAMP - INTERVAL '1 day'),
|
||||
('9', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '2 days'),
|
||||
('10', 'presentation.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'http://example.com/files/presentation.pptx', CURRENT_TIMESTAMP - INTERVAL '3 days'),
|
||||
('11', 'spreadsheet.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'http://example.com/files/spreadsheet.xlsx', CURRENT_TIMESTAMP - INTERVAL '4 days'),
|
||||
('12', 'audio1.mp3', 'audio/mpeg', 'http://example.com/files/audio1.mp3', CURRENT_TIMESTAMP - INTERVAL '5 days'),
|
||||
('13', 'video1.mp4', 'video/mp4', 'http://example.com/files/video1.mp4', CURRENT_TIMESTAMP - INTERVAL '6 days'),
|
||||
('14', 'archive.zip', 'application/zip', 'http://example.com/files/archive.zip',
|
||||
CURRENT_TIMESTAMP - INTERVAL '7 days'),
|
||||
('15', 'textfile.txt', 'text/plain', 'http://example.com/files/textfile.txt',
|
||||
CURRENT_TIMESTAMP - INTERVAL '8 days'),
|
||||
('16', 'image2.png', 'image/png', 'http://example.com/files/image2.png', CURRENT_TIMESTAMP - INTERVAL '9 days'),
|
||||
('17', 'document2.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'http://example.com/files/document2.docx', CURRENT_TIMESTAMP - INTERVAL '10 days');
|
||||
VALUES ('1', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf', CURRENT_TIMESTAMP),
|
||||
('2', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '1 day'),
|
||||
('3', 'presentation.pptx', 'application/pptx', 'http://example.com/files/presentation.pptx',
|
||||
CURRENT_TIMESTAMP - INTERVAL '2 days'),
|
||||
('4', 'spreadsheet.xlsx', 'application/xlsx', 'http://example.com/files/spreadsheet.xlsx',
|
||||
CURRENT_TIMESTAMP - INTERVAL '3 days'),
|
||||
('5', 'audio.mp3', 'audio/mpeg', 'http://example.com/files/audio.mp3', CURRENT_TIMESTAMP - INTERVAL '4 days');
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
<result column="address" jdbcType="VARCHAR" property="address"/>
|
||||
<result column="avatar" jdbcType="VARCHAR" property="avatar"/>
|
||||
<result column="name" jdbcType="VARCHAR" property="name"/>
|
||||
<result column="email" jdbcType="VARCHAR" property="email"/>
|
||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
||||
@ -24,25 +23,19 @@
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
<collection property="attachments" ofType="com.zsc.edu.gateway.modules.attachment.entity.Attachment">
|
||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<collection property="attachments" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo">
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||
<result column="mime_type" jdbcType="VARCHAR" property="mimeType"/>
|
||||
<result column="upload_time" jdbcType="TIMESTAMP" property="uploadTime"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="selectByMessageIdAndUserId" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo"
|
||||
resultMap="userMessageMap">
|
||||
select sum.id as user_message_id,sum.user_id as user_message_user_id,sum.message_id as
|
||||
user_message_message_id,sum.is_read as user_message_is_read,sum.read_time as user_message_read_time,su.id as
|
||||
user_id,su.username as user_username,su.address as user_address,su.avatar as user_avatar,su.name as
|
||||
user_name,su.phone as user_phone,sm.*,sm.email as message_email,a.*
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name,a.*
|
||||
from sys_user_message sum
|
||||
left join sys_user su on sum.id=su.id
|
||||
left join sys_message sm on sm.id=sum.id
|
||||
left join sys_message_attachment sma on sm.id=sma.message_id
|
||||
left join attachment a on sma.attachment_id=a.id
|
||||
left join sys_user su on sum.user_id = su.id
|
||||
left join sys_message sm on sm.id = sum.message_id
|
||||
left join sys_message_attachment sma on sm.id = sma.message_id
|
||||
left join attachment a on sma.attachment_id = a.id
|
||||
<where>
|
||||
sm.id=#{messageId}
|
||||
and su.id=#{userId}
|
||||
@ -50,15 +43,12 @@
|
||||
</select>
|
||||
|
||||
<select id="query" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
||||
select sum.id as user_message_id,sum.user_id as user_message_user_id,sum.message_id as
|
||||
user_message_message_id,sum.is_read as user_message_is_read,sum.read_time as user_message_read_time,su.id as
|
||||
user_id,su.username as user_username,su.address as user_address,su.avatar as user_avatar,su.name as
|
||||
user_name,su.email as user_email,su.phone as user_phone,sm.*,sm.email as message_email,a.*
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name,a.*
|
||||
from sys_user_message sum
|
||||
left join sys_user su on sum.id=su.id
|
||||
left join sys_message sm on sm.id=sum.id
|
||||
left join sys_message_attachment sma on sm.id=sma.message_id
|
||||
left join attachment a on sma.attachment_id=a.id
|
||||
left join sys_user su on sum.user_id = su.id
|
||||
left join sys_message sm on sm.id = sum.message_id
|
||||
left join sys_message_attachment sma on sm.id = sma.message_id
|
||||
left join attachment a on sma.attachment_id = a.id
|
||||
where 1=1
|
||||
<if test="query.userId != null">
|
||||
AND sum.user_id = #{query.userId}
|
||||
|
@ -1,89 +1,89 @@
|
||||
//package com.zsc.edu.gateway.service;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.zsc.edu.gateway.domain.BulletinBuilder;
|
||||
//import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
//import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
//import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
//import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
//import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
//import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.junit.jupiter.api.AfterEach;
|
||||
//import org.junit.jupiter.api.BeforeEach;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.jupiter.api.Assertions.*;
|
||||
//
|
||||
//public class BulletinServiceTest {
|
||||
// @Resource
|
||||
// private BulletinService service;
|
||||
// @Resource
|
||||
// private BulletinRepository repo;
|
||||
//
|
||||
// Bulletin bulletin1;
|
||||
// Bulletin bulletin2;
|
||||
//
|
||||
// @BeforeEach
|
||||
// void setUp() {
|
||||
// bulletin1 = BulletinBuilder.bBulletin().title("测试1").build();
|
||||
// repo.insert(bulletin1);
|
||||
// bulletin2 = BulletinBuilder.bBulletin().title("测试2").build();
|
||||
// repo.insert(bulletin2);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void list() {
|
||||
// LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
||||
// assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
||||
// assertEquals(2, service.list().size());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void createBulletin() {
|
||||
// BulletinDto dto = new BulletinDto();
|
||||
// dto.setTitle("测试");
|
||||
// dto.setTop(true);
|
||||
// dto.setContent("测试测试");
|
||||
// dto.setRemark("测试公告增加");
|
||||
// BulletinDto dto2 = new BulletinDto();
|
||||
// dto2.setTitle(bulletin2.getTitle());
|
||||
//// dto2.setTop(bulletin2.isTop());
|
||||
// dto2.setRemark(bulletin2.getRemark());
|
||||
// UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
// userDetails.setUsername("admin");
|
||||
// Bulletin bulletin=service.create(userDetails,dto);
|
||||
// assertNotNull(bulletin.getId());
|
||||
// List<Bulletin> list = service.list();
|
||||
// assertEquals(3, list.size());
|
||||
// // 不能创建其他已存在标题公告
|
||||
// assertThrows(ConstraintException.class, () -> service.create(userDetails,dto2));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void updateBulletin() {
|
||||
// BulletinDto dto = new BulletinDto();
|
||||
// dto.setTitle("测试3");
|
||||
// dto.setContent("测试测");
|
||||
// dto.setTop(true);
|
||||
// dto.setRemark("测试公告更新");
|
||||
// UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
// userDetails.setUsername("admin");
|
||||
// assertTrue(service.update(userDetails,dto, bulletin2.id));
|
||||
// Bulletin bulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
||||
// assertEquals(bulletin.getTitle(), dto.getTitle());
|
||||
// assertEquals(bulletin.getId(), bulletin2.id);
|
||||
// // 不能改为其他已存在的同名同代码部门
|
||||
// assertThrows(ConstraintException.class,
|
||||
// () -> service.update(userDetails,new BulletinDto(bulletin1.getTitle(),true,null,null), bulletin2.id));
|
||||
// }
|
||||
//
|
||||
// @AfterEach
|
||||
// void tearDown() {
|
||||
// repo.delete(new QueryWrapper<>());
|
||||
// }
|
||||
//}
|
||||
package com.zsc.edu.gateway.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zsc.edu.gateway.domain.BulletinBuilder;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class BulletinServiceTest {
|
||||
@Resource
|
||||
private BulletinService service;
|
||||
@Resource
|
||||
private BulletinRepository repo;
|
||||
|
||||
Bulletin bulletin1;
|
||||
Bulletin bulletin2;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
bulletin1 = BulletinBuilder.bBulletin().title("测试1").build();
|
||||
repo.insert(bulletin1);
|
||||
bulletin2 = BulletinBuilder.bBulletin().title("测试2").build();
|
||||
repo.insert(bulletin2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() {
|
||||
LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||
assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
||||
assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
||||
assertEquals(2, service.list().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBulletin() {
|
||||
BulletinDto dto = new BulletinDto();
|
||||
dto.setTitle("测试");
|
||||
dto.setTop(true);
|
||||
dto.setContent("测试测试");
|
||||
dto.setRemark("测试公告增加");
|
||||
BulletinDto dto2 = new BulletinDto();
|
||||
dto2.setTitle(bulletin2.getTitle());
|
||||
// dto2.setTop(bulletin2.isTop());
|
||||
dto2.setRemark(bulletin2.getRemark());
|
||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
userDetails.setUsername("admin");
|
||||
Bulletin bulletin = service.create(userDetails, dto);
|
||||
assertNotNull(bulletin.getId());
|
||||
List<Bulletin> list = service.list();
|
||||
assertEquals(3, list.size());
|
||||
// 不能创建其他已存在标题公告
|
||||
assertThrows(ConstraintException.class, () -> service.create(userDetails, dto2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBulletin() {
|
||||
BulletinDto dto = new BulletinDto();
|
||||
dto.setTitle("测试3");
|
||||
dto.setContent("测试测");
|
||||
dto.setTop(true);
|
||||
dto.setRemark("测试公告更新");
|
||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
userDetails.setUsername("admin");
|
||||
assertTrue(service.update(userDetails, dto, bulletin2.id));
|
||||
Bulletin bulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
||||
assertEquals(bulletin.getTitle(), dto.getTitle());
|
||||
assertEquals(bulletin.getId(), bulletin2.id);
|
||||
// 不能改为其他已存在的同名同代码部门
|
||||
assertThrows(ConstraintException.class,
|
||||
() -> service.update(userDetails, new BulletinDto(bulletin1.getTitle(), true, null, null), bulletin2.id));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
repo.delete(new QueryWrapper<>());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user