feat(消息模块与部门模块): 修改了消息模块的bug并从新建消息接口中独立出添加附件接口,部门模块新添加了部门树返回接口

This commit is contained in:
zhuangtianxiang 2024-12-02 16:26:23 +08:00
parent 2c2e3f8092
commit e894b5aa00
25 changed files with 232 additions and 252 deletions

View File

@ -27,7 +27,6 @@ import java.util.Set;
public class BulletinController { public class BulletinController {
private final BulletinService service; private final BulletinService service;
/** /**
* 普通用户查看公告详情 * 普通用户查看公告详情
* *
@ -35,7 +34,7 @@ public class BulletinController {
* @return 公告 * @return 公告
*/ */
@GetMapping("/self/{id}") @GetMapping("/self/{id}")
public BulletinVo selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails,@PathVariable("id") Long id) { public List<BulletinVo> selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
return service.detail(userDetails,id, Bulletin.State.publish); return service.detail(userDetails,id, Bulletin.State.publish);
} }
@ -45,7 +44,7 @@ public class BulletinController {
* @param query 查询表单 * @param query 查询表单
* @return 分页数据 * @return 分页数据
*/ */
@GetMapping("/query") @GetMapping("/self")
public IPage<BulletinVo> getBulletins( BulletinQuery query) { public IPage<BulletinVo> getBulletins( BulletinQuery query) {
query.setState(Bulletin.State.publish); query.setState(Bulletin.State.publish);
Page<BulletinVo> page = new Page<>(query.getPageNum(), query.getPageSize()); Page<BulletinVo> page = new Page<>(query.getPageNum(), query.getPageSize());
@ -60,7 +59,7 @@ public class BulletinController {
*/ */
@GetMapping("/{id}") @GetMapping("/{id}")
@PreAuthorize("hasAuthority('BULLETIN_QUERY')") @PreAuthorize("hasAuthority('BULLETIN_QUERY')")
public BulletinVo detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) { public List<BulletinVo> detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
return service.detail(userDetails,id, null); return service.detail(userDetails,id, null);
} }

View File

@ -118,6 +118,19 @@ public class UserMessageController {
return service.createByAdmin(dto); return service.createByAdmin(dto);
} }
/**
* 管理员为消息添加附件
*
* @param messageId 消息ID
* @param attachmentIds 附件ID集合
* @return 消息列表
*/
@PostMapping("/attachment/{messageId}")
@PreAuthorize("hasAuthority('MESSAGE_CREATE')")
public Boolean insertInto(@PathVariable("messageId") Long messageId, @RequestBody List<String> attachmentIds) {
return service.insertInto(messageId, attachmentIds);
}
/** /**
* 获取消息推送方式 * 获取消息推送方式
* *
@ -141,16 +154,4 @@ public class UserMessageController {
return service.saveSetting(settings); return service.saveSetting(settings);
} }
/**
* 系统自动创建用户消息并发送
*
* @param receivers 接收者
* @param payload 消息内容
*/
@PostMapping("/system/setting")
@PreAuthorize("hasAuthority('MESSAGE_SETTING')")
public Boolean createBySystem(Set<User> receivers, MessagePayload payload) {
return service.createBySystem(receivers, payload);
}
} }

View File

@ -57,9 +57,5 @@ public class UserMessageDto {
@NotBlank(message = "消息内容不能为空") @NotBlank(message = "消息内容不能为空")
public String content; public String content;
/**
* 附件ID集合
*/
public Set<String> attachmentIds;
} }

View File

@ -1,31 +0,0 @@
package com.zsc.edu.gateway.modules.notice.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* @author zhuang
*/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_bulletin_user")
public class BulletinUser {
/**
* 公告ID
*/
public Long bulletinId;
/**
* 用户ID
*/
public Long userId;
/**
* 是否已读
*/
public Boolean isRead=true;
}

View File

@ -28,22 +28,12 @@ public class UserMessage implements Serializable {
*/ */
public Long userId; public Long userId;
/**
* 用户
*/
@TableField(exist = false)
public User user;
/** /**
* 消息ID * 消息ID
*/ */
public Long messageId; public Long messageId;
/**
* 消息
*/
@TableField(exist = false)
public Message message;
/** /**
* 是否已读 * 是否已读
@ -55,6 +45,4 @@ public class UserMessage implements Serializable {
*/ */
public LocalDateTime readTime; public LocalDateTime readTime;
public UserMessage(Object o, User user, Message message, boolean b, Object o1) {
}
} }

View File

@ -31,5 +31,4 @@ public class BulletinQuery {
private LocalDateTime publishTimeBegin; private LocalDateTime publishTimeBegin;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime publishTimeEnd; private LocalDateTime publishTimeEnd;
private Boolean isRead;
} }

View File

@ -6,12 +6,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zsc.edu.gateway.modules.notice.dto.PageDto;
import com.zsc.edu.gateway.modules.notice.entity.Bulletin; import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery; import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo; import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** /**
* 公告Repo * 公告Repo
@ -21,7 +21,7 @@ import org.apache.ibatis.annotations.Select;
public interface BulletinRepository extends BaseMapper<Bulletin> { public interface BulletinRepository extends BaseMapper<Bulletin> {
BulletinVo selectByBulletinId(@Param("bulletinId") Long bulletinId); List<BulletinVo> selectByBulletinId(@Param("bulletinId") Long bulletinId);
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, @Param("query") BulletinQuery query); IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, @Param("query") BulletinQuery query);
} }

View File

@ -1,16 +0,0 @@
package com.zsc.edu.gateway.modules.notice.repo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* @author zhuang
*/
public interface BulletinUserRepository extends BaseMapper<BulletinUser> {
// @Select("select * from sys_bulletin_user sbu where sbu.bulletin_id=#{bulletinId} and sbu.user_id=#{userId}")
// Boolean selectByBulletinIdAndUserId(@Param("bulletinId") Long bulletinId, @Param("userId") Long userId);
}

View File

@ -21,7 +21,7 @@ import java.util.Set;
public interface BulletinService extends IService<Bulletin> { public interface BulletinService extends IService<Bulletin> {
BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state); List<BulletinVo> detail(UserDetailsImpl userDetails, Long id, Bulletin.State state);
Bulletin create(UserDetailsImpl userDetails, BulletinDto dto); Bulletin create(UserDetailsImpl userDetails, BulletinDto dto);

View File

@ -1,16 +0,0 @@
package com.zsc.edu.gateway.modules.notice.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
/**
* @author zhuang
*/
public interface BulletinUserService extends IService<BulletinUser> {
Boolean isRead(UserDetailsImpl userDetails, Long id);
void toggleIsRead(Long id);
}

View File

@ -29,6 +29,8 @@ public interface UserMessageService extends IService<UserMessage> {
UserMessageVo detail(Long messageId, Long userId); UserMessageVo detail(Long messageId, Long userId);
Boolean insertInto(Long messageId, List<String> attachmentIds);
List<MessageSetting> getSetting(); List<MessageSetting> getSetting();
IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query); IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query);
@ -40,6 +42,4 @@ public interface UserMessageService extends IService<UserMessage> {
@Transactional @Transactional
List<MessageSetting> saveSetting(List<MessageSetting> settings); List<MessageSetting> saveSetting(List<MessageSetting> settings);
@Transactional
Boolean createBySystem(Set<User> receivers, MessagePayload payload);
} }

View File

@ -15,7 +15,6 @@ import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository; import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
import com.zsc.edu.gateway.modules.notice.service.BulletinAttachmentService; import com.zsc.edu.gateway.modules.notice.service.BulletinAttachmentService;
import com.zsc.edu.gateway.modules.notice.service.BulletinService; import com.zsc.edu.gateway.modules.notice.service.BulletinService;
import com.zsc.edu.gateway.modules.notice.service.BulletinUserService;
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo; import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
import com.zsc.edu.gateway.modules.system.repo.UserRepository; import com.zsc.edu.gateway.modules.system.repo.UserRepository;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -39,7 +38,6 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
private final BulletinRepository repo; private final BulletinRepository repo;
private final BulletinAttachmentService bulletinAttachmentService; private final BulletinAttachmentService bulletinAttachmentService;
private final BulletinUserService bulletinUserService;
private final UserRepository userRepository; private final UserRepository userRepository;
/** /**
* 查询公告详情 * 查询公告详情
@ -49,16 +47,21 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
* @return 公告详情 * @return 公告详情
*/ */
@Override @Override
public BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) { public List<BulletinVo> detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) {
BulletinVo bulletin = repo.selectByBulletinId(id); List<BulletinVo> bulletins = repo.selectByBulletinId(id);
if (state != null) { if (bulletins.isEmpty()) {
bulletin.getState().checkStatus(state); return Collections.emptyList();
} }
bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId())); for (BulletinVo bulletin : bulletins) {
bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId())); if (state != null) {
bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId())); bulletin.getState().checkStatus(state);
bulletinUserService.isRead(userDetails, id); }
return bulletin; bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId()));
bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId()));
bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId()));
}
return bulletins;
} }
/** /**
* 新建公告 * 新建公告
@ -96,7 +99,6 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
bulletin.setCreateBy(userDetails.getName()); bulletin.setCreateBy(userDetails.getName());
bulletin.setCreateTime(LocalDateTime.now()); bulletin.setCreateTime(LocalDateTime.now());
bulletin.state = edit; bulletin.state = edit;
bulletinUserService.toggleIsRead(id);
return updateById(bulletin); return updateById(bulletin);
} }
/** /**
@ -178,12 +180,14 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
*为公告添加附件 *为公告添加附件
* *
* @param bulletinId bulletinId * @param bulletinId bulletinId
* @param attachments attachments * @param attachmentIds attachments
* @return true * @return true
*/ */
@Override @Override
public Boolean insertInto(Long bulletinId, Set<String> attachments) { public Boolean insertInto(Long bulletinId, Set<String> attachmentIds) {
List<BulletinAttachment> bulletinAttachments=attachments.stream().map(bulletinAttachment->new BulletinAttachment(bulletinId, attachments.toString())).toList(); List<BulletinAttachment> bulletinAttachments = attachmentIds.stream()
.map(attachmentId -> new BulletinAttachment(bulletinId, attachmentId))
.collect(Collectors.toList());
return bulletinAttachmentService.saveBatch(bulletinAttachments); return bulletinAttachmentService.saveBatch(bulletinAttachments);
} }

View File

@ -1,60 +0,0 @@
package com.zsc.edu.gateway.modules.notice.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
import com.zsc.edu.gateway.modules.notice.repo.BulletinUserRepository;
import com.zsc.edu.gateway.modules.notice.service.BulletinUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* @author zhuang
*/
@AllArgsConstructor
@Service
public class BulletinUserServiceImpl extends ServiceImpl<BulletinUserRepository, BulletinUser> implements BulletinUserService {
/**
* 已读公告每次已读自动获取用户id与公告id加入联表
*
* @param userDetails userDetails
* @param id id
* return true
*/
@Override
public Boolean isRead(UserDetailsImpl userDetails,Long id) {
if (id == null || userDetails.getId() == null) {
throw new IllegalArgumentException("Bulletin ID and User ID cannot be null");
}
QueryWrapper<BulletinUser> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("bulletin_id", id)
.eq("user_id", userDetails.getId());
BulletinUser existingUser = getOne(queryWrapper);
if (existingUser == null) {
BulletinUser newUser = new BulletinUser();
newUser.setBulletinId(id);
newUser.setUserId(userDetails.getId());
newUser.setIsRead(false);
save(newUser);
} else {
UpdateWrapper<BulletinUser> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("bulletin_id", id).eq("user_id", userDetails.getId()).set("is_read",false);
}
return true;
}
/**
* 更新公告后修改已读状态
*
* @param id id
*/
@Override
public void toggleIsRead(Long id) {
UpdateWrapper<BulletinUser> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("bulletin_id",id).set("is_read",true);
}
}

View File

@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.framework.message.email.EmailSender; import com.zsc.edu.gateway.framework.message.email.EmailSender;
import com.zsc.edu.gateway.framework.message.sms.SmsSender; import com.zsc.edu.gateway.framework.message.sms.SmsSender;
import com.zsc.edu.gateway.framework.security.UserDetailsImpl; import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
import com.zsc.edu.gateway.modules.attachment.service.AttachmentService; import com.zsc.edu.gateway.modules.attachment.service.AttachmentService;
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto; import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
import com.zsc.edu.gateway.modules.notice.entity.*; import com.zsc.edu.gateway.modules.notice.entity.*;
@ -17,6 +16,7 @@ import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
import com.zsc.edu.gateway.modules.notice.repo.MessageRepository; import com.zsc.edu.gateway.modules.notice.repo.MessageRepository;
import com.zsc.edu.gateway.modules.notice.repo.MessageSettingRepository; import com.zsc.edu.gateway.modules.notice.repo.MessageSettingRepository;
import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository; import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository;
import com.zsc.edu.gateway.modules.notice.service.MessageAttachmentService;
import com.zsc.edu.gateway.modules.notice.service.UserMessageService; import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo; import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
import com.zsc.edu.gateway.modules.system.entity.User; import com.zsc.edu.gateway.modules.system.entity.User;
@ -48,6 +48,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
private final EmailSender emailSender; private final EmailSender emailSender;
private final SmsSender smsSender; private final SmsSender smsSender;
private final UserMessageRepository userMessageRepository; private final UserMessageRepository userMessageRepository;
private final MessageAttachmentService messageAttachmentService;
/** /**
* 查询消息详情 * 查询消息详情
@ -116,18 +117,39 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
@Transactional @Transactional
@Override @Override
public Boolean createByAdmin(UserMessageDto dto) { public Boolean createByAdmin(UserMessageDto dto) {
Set<User> users = dto.userIds.stream().map(userService::getById).collect(Collectors.toSet()); Set<User> users = dto.userIds.stream()
List<Attachment> attachments = attachmentService.listByIds(dto.attachmentIds); .map(userService::getById)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (users.isEmpty()) {
throw new RuntimeException("No valid users found for the provided userIds.");
}
Message message = new Message(dto.type, false, dto.email, dto.sms, dto.html, Message message = new Message(dto.type, false, dto.email, dto.sms, dto.html,
dto.title, dto.content, attachments); dto.title, dto.content, null);
messageRepo.insert(message); messageRepo.insert(message);
Set<UserMessage> userMessages = users.stream().map(user -> Set<UserMessage> userMessages = users.stream()
new UserMessage(null, user, message, false, null)).collect(Collectors.toSet()); .map(user -> new UserMessage(null, user.getId(), message.getId(), false, null))
.collect(Collectors.toSet());
send(users, message); send(users, message);
return saveBatch(userMessages); return saveBatch(userMessages);
} }
/**
* 将附件关联信息插入数据库
*
* @param messageId 消息ID用于关联消息和附件
* @param attachmentIds 附件ID列表表示需要插入的附件
* @return 返回一个布尔值表示批量插入是否成功
*/
@Override
public Boolean insertInto(Long messageId, List<String> attachmentIds) {
List<MessageAttachment> messageAttachments = attachmentIds.stream()
.map(attachmentId -> new MessageAttachment(messageId, attachmentId))
.collect(Collectors.toList());
return messageAttachmentService.saveBatch(messageAttachments);
}
/** /**
* 获取所有消息推送方式 * 获取所有消息推送方式
* *
@ -185,7 +207,6 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
* @param payload 消息内容 * @param payload 消息内容
*/ */
@Transactional @Transactional
@Override
public Boolean createBySystem(Set<User> receivers, MessagePayload payload) { public Boolean createBySystem(Set<User> receivers, MessagePayload payload) {
AtomicBoolean email = new AtomicBoolean(false); AtomicBoolean email = new AtomicBoolean(false);
AtomicBoolean sms = new AtomicBoolean(false); AtomicBoolean sms = new AtomicBoolean(false);
@ -197,7 +218,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
payload.html, payload.type.name(), payload.content, null); payload.html, payload.type.name(), payload.content, null);
messageRepo.insert(message); messageRepo.insert(message);
Set<UserMessage> userMessages = receivers.stream().map(user -> Set<UserMessage> userMessages = receivers.stream().map(user ->
new UserMessage(null, user, message, false, null)).collect(Collectors.toSet()); new UserMessage(null, user.getId(), message.getId(), false, null)).collect(Collectors.toSet());
send(receivers, message); send(receivers, message);
return saveBatch(userMessages); return saveBatch(userMessages);
} }

View File

@ -2,10 +2,15 @@ package com.zsc.edu.gateway.modules.notice.vo;
import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
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.Bulletin; import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* @author zhuang * @author zhuang
@ -26,12 +31,6 @@ public class BulletinVo {
private String closeUsername; private String closeUsername;
private LocalDateTime closeTime; private LocalDateTime closeTime;
private String content; private String content;
private Boolean isRead;
private String fileName;
private String mimeType;
private LocalDateTime uploadTime;
private String url;
private String remark;
@TableField(value = "create_time", fill = FieldFill.INSERT) @TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime; private LocalDateTime createTime;
@TableField(value = "create_by", fill = FieldFill.INSERT) @TableField(value = "create_by", fill = FieldFill.INSERT)
@ -40,5 +39,7 @@ public class BulletinVo {
private LocalDateTime updateTime; private LocalDateTime updateTime;
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE) @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
private String updateBy; private String updateBy;
List<AttachmentVo> attachmentVos;
} }

View File

@ -9,10 +9,13 @@ import com.zsc.edu.gateway.modules.system.entity.User;
import com.zsc.edu.gateway.modules.system.query.DeptQuery; import com.zsc.edu.gateway.modules.system.query.DeptQuery;
import com.zsc.edu.gateway.modules.system.service.DeptService; import com.zsc.edu.gateway.modules.system.service.DeptService;
import com.zsc.edu.gateway.modules.system.service.UserService; import com.zsc.edu.gateway.modules.system.service.UserService;
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 部门Controller * 部门Controller
* *
@ -29,14 +32,12 @@ public class DeptController {
/** /**
* 返回管理部门列表 hasAuthority('DEPT_QUERY') * 返回管理部门列表 hasAuthority('DEPT_QUERY')
* *
* @param query 查询表单
* @return 部门列表 * @return 部门列表
*/ */
// @GetMapping @GetMapping()
// @PreAuthorize("hasAuthority('DEPT_QUERY')") public List<DeptTree> getDeptTree() {
// public Dept query(DeptQuery query, Page<Dept> page) { return service.getDeptTree();
// return service.page(page, query.wrapper()); }
// }
/** /**
* 新建管理部门 hasAuthority('DEPT_CREATE') * 新建管理部门 hasAuthority('DEPT_CREATE')

View File

@ -40,7 +40,6 @@ public class UserController {
private final RoleService roleService; private final RoleService roleService;
private final DeptService deptService; private final DeptService deptService;
private final RoleAuthService roleAuthService;
private final AuthorityService authorityService; private final AuthorityService authorityService;
/** /**

View File

@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -45,6 +47,9 @@ public class Dept extends BaseEntity {
private Boolean enabled = true; private Boolean enabled = true;
@TableField(exist = false) @TableField(exist = false)
public Set<Dept> children = new HashSet<>(0); public List<Dept> children = new ArrayList<>(0);
@TableField(exist = false)
public List<User> members = new ArrayList<>(0);
} }

View File

@ -2,6 +2,13 @@ package com.zsc.edu.gateway.modules.system.repo;
import com.zsc.edu.gateway.modules.system.entity.Dept; import com.zsc.edu.gateway.modules.system.entity.Dept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsc.edu.gateway.modules.system.entity.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** /**
* <p> * <p>
@ -12,5 +19,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @since 2023-04-06 * @since 2023-04-06
*/ */
public interface DeptRepository extends BaseMapper<Dept> { public interface DeptRepository extends BaseMapper<Dept> {
@Select("SELECT d.*, u.* FROM sys_dept d LEFT JOIN sys_user u ON d.id = u.dept_id")
List<Dept> selectAllWithMembers();
} }

View File

@ -3,6 +3,9 @@ package com.zsc.edu.gateway.modules.system.service;
import com.zsc.edu.gateway.modules.system.dto.DeptDto; import com.zsc.edu.gateway.modules.system.dto.DeptDto;
import com.zsc.edu.gateway.modules.system.entity.Dept; import com.zsc.edu.gateway.modules.system.entity.Dept;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
import java.util.List;
/** /**
* <p> * <p>
@ -28,11 +31,13 @@ public interface DeptService extends IService<Dept> {
Boolean edit(DeptDto dto, Long id); Boolean edit(DeptDto dto, Long id);
Boolean toggle(Long id); Boolean toggle(Long id);
//
// /**
// * 生成部门树结构
// * @param id
// * @return
// */
//// Dept listTree(Long id);
/** List<DeptTree> getDeptTree();
* 生成部门树结构
* @param id
* @return
*/
// Dept listTree(Long id);
} }

View File

@ -2,15 +2,24 @@ package com.zsc.edu.gateway.modules.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.exception.ConstraintException; import com.zsc.edu.gateway.exception.ConstraintException;
import com.zsc.edu.gateway.framework.DeptTreeUtil;
import com.zsc.edu.gateway.modules.system.dto.DeptDto; import com.zsc.edu.gateway.modules.system.dto.DeptDto;
import com.zsc.edu.gateway.modules.system.entity.Dept; import com.zsc.edu.gateway.modules.system.entity.Dept;
import com.zsc.edu.gateway.modules.system.entity.User;
import com.zsc.edu.gateway.modules.system.mapper.DeptMapper; import com.zsc.edu.gateway.modules.system.mapper.DeptMapper;
import com.zsc.edu.gateway.modules.system.repo.DeptRepository; import com.zsc.edu.gateway.modules.system.repo.DeptRepository;
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
import com.zsc.edu.gateway.modules.system.service.DeptService; import com.zsc.edu.gateway.modules.system.service.DeptService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* <p> * <p>
* 部门 服务实现类 * 部门 服务实现类
@ -24,6 +33,8 @@ import org.springframework.stereotype.Service;
public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implements DeptService { public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implements DeptService {
private final DeptMapper mapper; private final DeptMapper mapper;
private final DeptRepository repo;
private final UserRepository userRepository;
@Override @Override
public Dept create(DeptDto dto) { public Dept create(DeptDto dto) {
@ -52,15 +63,15 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
return updateById(dept); return updateById(dept);
} }
// @Override @Override
// public Dept listTree(Long deptId) { public List<DeptTree> getDeptTree() {
// Dept rootDept; List<Dept> depots = repo.selectList(null);
// List<Dept> all = list(null); List<User> users = userRepository.selectList(null);
// HashSet<Dept> deptList = new HashSet<>(all); Map<Long, List<User>> userMap = new HashMap<>();
// rootDept = DeptTreeUtil.initTree(deptList); for (User user : users) {
// if (deptId != null) { userMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
// return rootDept.id.equals(deptId) ? rootDept : DeptTreeUtil.getChildNode(rootDept.children, deptId); }
// } return DeptTreeUtil.buildDeptTree(depots, userMap);
// return rootDept; }
// }
} }

View File

@ -145,9 +145,7 @@ create index inx_pid
create table sys_message create table sys_message
( (
id integer not null id SERIAL PRIMARY KEY,
constraint sys_message_pk
primary key,
type integer not null, type integer not null,
system boolean not null, system boolean not null,
email boolean not null, email boolean not null,
@ -177,6 +175,7 @@ comment on column sys_message.update_by is '更新人';
alter table sys_message alter table sys_message
owner to postgres; owner to postgres;
create table sys_message_attach create table sys_message_attach
( (
message_id bigint not null, message_id bigint not null,
@ -398,17 +397,29 @@ INSERT INTO "sys_user" VALUES (1, 210, 50, 'admin', '{bcrypt}$2a$10$lwEbMpGYMIcV
INSERT INTO "sys_user" VALUES (2, 215, 51, 'user', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '12324352313', 'zsc3456@qq.com', '帐篷', '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '电子科技大学四川',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1'); INSERT INTO "sys_user" VALUES (2, 215, 51, 'user', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '12324352313', 'zsc3456@qq.com', '帐篷', '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '电子科技大学四川',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1');
INSERT INTO "sys_user" VALUES (3, 218, 54, 'auditor', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '12345678901', 'zsc3456@qq.com', '王超', '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '电子科技大学中山',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1'); INSERT INTO "sys_user" VALUES (3, 218, 54, 'auditor', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '12345678901', 'zsc3456@qq.com', '王超', '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '电子科技大学中山',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1');
INSERT INTO "attachment" VALUES ('195bd3517bfcd9915906957730bdd6fef7fa5a86', 'Snipaste_2024-02-08_09-26-22.jpg', 'image/jpeg','2024-03-21 15:20:03'); INSERT INTO "attachment"
INSERT INTO "attachment" VALUES ('1f744e54c23c388d890a6a3822a87eae32617f29', '6.25-07.jpg', 'image/jpeg','2024-03-07 07:59:34'); VALUES ('195bd3517bfcd9915906957730bdd6fef7fa5a86', 'Snipaste_2024-02-08_09-26-22.jpg', '1', 'image/jpeg',
INSERT INTO "attachment" VALUES ('35bd7d32843a413f3cd2486114318d6ccd5f9d62', 'Snipaste_2024-03-22_08-11-52.jpg', 'image/jpeg','2024-03-22 00:12:05'); '2024-03-21 15:20:03');
INSERT INTO "attachment" VALUES ('5440f9aa9266589413f015fa673f2f372a86c74e', '各组织活动申报表模板.png', 'image/png','2024-02-11 17:37:44'); INSERT INTO "attachment"
INSERT INTO "attachment" VALUES ('5ad6601fd1cf58aa66b25b4f12a83d63b61a681e', '申请表1模板计算机学院素质拓展活动申请表.doc', 'application/msword','2024-02-05 14:37:10'); VALUES ('1f744e54c23c388d890a6a3822a87eae32617f29', '6.25-07.jpg', '1', 'image/jpeg', '2024-03-07 07:59:34');
INSERT INTO "attachment" VALUES ('6853fd7cf5b0621678377227d299d86d6f90cc97', 'logo02.png', 'image/png','2024-03-07 07:59:11'); INSERT INTO "attachment"
INSERT INTO "attachment" VALUES ('84fa4f586f190886ea8708c49e8645f5a9a1ea04', '屏幕截图(1).png', 'image/png','2024-03-21 16:12:46'); VALUES ('35bd7d32843a413f3cd2486114318d6ccd5f9d62', 'Snipaste_2024-03-22_08-11-52.jpg', '1', 'image/jpeg',
'2024-03-22 00:12:05');
INSERT INTO "attachment"
VALUES ('5440f9aa9266589413f015fa673f2f372a86c74e', '各组织活动申报表模板.png', '1', 'image/png',
'2024-02-11 17:37:44');
INSERT INTO "attachment"
VALUES ('5ad6601fd1cf58aa66b25b4f12a83d63b61a681e', '申请表1模板计算机学院素质拓展活动申请表.doc', '1',
'application/msword', '2024-02-05 14:37:10');
INSERT INTO "attachment"
VALUES ('6853fd7cf5b0621678377227d299d86d6f90cc97', 'logo02.png', '1', 'image/png', '2024-03-07 07:59:11');
INSERT INTO "attachment"
VALUES ('84fa4f586f190886ea8708c49e8645f5a9a1ea04', '屏幕截图(1).png', '1', 'image/png', '2024-03-21 16:12:46');
INSERT INTO "sys_bulletin" VALUES (1,'测试测试测试测试测试测试测试',1,true,50,'2024-03-21 15:20:03',51,'2024-03-21 15:20:03',54,'2024-03-21 15:20:03','测试测试测试数据',null,null,null,null); INSERT INTO "sys_bulletin" VALUES (1,'测试测试测试测试测试测试测试',1,true,50,'2024-03-21 15:20:03',51,'2024-03-21 15:20:03',54,'2024-03-21 15:20:03','测试测试测试数据',null,null,null,null);
INSERT INTO "sys_bulletin_attach" VALUES (1,'195bd3517bfcd9915906957730bdd6fef7fa5a86') INSERT INTO "sys_bulletin_attach"
VALUES (1, '195bd3517bfcd9915906957730bdd6fef7fa5a86');
INSERT INTO sys_message (id, type, system, email, sms, html, title, content, remark, create_time, create_by, INSERT INTO sys_message (id, type, system, email, sms, html, title, content, remark, create_time, create_by,
update_time, update_by) update_time, update_by)
@ -445,3 +456,21 @@ VALUES (1, TRUE, FALSE),
(9, TRUE, FALSE), (9, TRUE, FALSE),
(10, FALSE, TRUE); (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');

View File

@ -18,30 +18,64 @@
<result column="edit_user_name" jdbcType="VARCHAR" property="editUsername"/> <result column="edit_user_name" jdbcType="VARCHAR" property="editUsername"/>
<result column="publish_user_name" jdbcType="VARCHAR" property="publishUsername"/> <result column="publish_user_name" jdbcType="VARCHAR" property="publishUsername"/>
<result column="close_user_name" jdbcType="VARCHAR" property="closeUsername"/> <result column="close_user_name" jdbcType="VARCHAR" property="closeUsername"/>
<result column="file_name" jdbcType="VARCHAR" property="fileName"/> <collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo">
<result column="mime_type" jdbcType="VARCHAR" property="mimeType"/> <result column="file_name" jdbcType="VARCHAR" property="fileName"/>
<result column="upload_time" jdbcType="TIMESTAMP" property="uploadTime"/> <result column="url" jdbcType="VARCHAR" property="url"/>
<result column="url" jdbcType="VARCHAR" property="url"/> </collection>
<result column="is_read" jdbcType="BOOLEAN" property="isRead"/>
</resultMap> </resultMap>
<select id="selectByBulletinId" resultMap="BulletinMap"> <select id="selectByBulletinId" resultMap="BulletinMap">
select sb.*,a.id as attachment_id,a.file_name as attachment_file_name,a.mime_type as attachment_mime_type,a.url as attachment_url,a.upload_time as attachment_upload_time,sbu.is_read SELECT sb.id AS id,
from sys_bulletin sb sb.state AS state,
left join sys_bulletin_attach sba on sb.id=sba.bulletin_id sb.content AS content,
left join attachment a on a.id=sba.attachment_id sb.title AS title,
left join sys_bulletin_user sbu on sb.id=sbu.bulletin_id sb.top AS top,
left join sys_user su on sbu.user_id=su.id sb.remark AS remark,
where sb.id=#{bulletinId} sb.close_time AS close_time,
sb.close_user_id AS close_user_id,
sb.create_by AS create_by,
sb.create_time AS create_time,
sb.edit_user_id AS edit_user_id,
sb.publish_time AS publish_time,
sb.publish_user_id AS publish_user_id,
sb.update_by AS update_by,
sb.update_time AS update_time,
a.file_name AS file_name,
a.url AS url
FROM sys_bulletin sb
LEFT JOIN
sys_bulletin_attach sba ON sb.id = sba.bulletin_id
LEFT JOIN
attachment a ON a.id = sba.attachment_id
WHERE sb.id = #{bulletinId}
</select> </select>
<select id="selectPageByConditions" resultType="com.zsc.edu.gateway.modules.notice.vo.BulletinVo"> <select id="selectPageByConditions" resultType="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
select sb.*,a.id as attachment_id,a.file_name as attachment_file_name,a.mime_type as attachment_mime_type,a.url SELECT
as attachment_url,a.upload_time as attachment_upload_time,sbu.is_read sb.id AS id,
from sys_bulletin sb sb.state AS state,
left join sys_bulletin_attach sba on sb.id=sba.bulletin_id sb.content AS content,
left join attachment a on a.id=sba.attachment_id sb.title AS title,
left join sys_bulletin_user sbu on sb.id=sbu.bulletin_id sb.top AS top,
left join sys_user su on sbu.user_id=su.id where 1=1 sb.remark AS remark,
sb.close_time AS close_time,
sb.close_user_id AS close_user_id,
sb.create_by AS create_by,
sb.create_time AS create_time,
sb.edit_user_id AS edit_user_id,
sb.publish_time AS publish_time,
sb.publish_user_id AS publish_user_id,
sb.update_by AS update_by,
sb.update_time AS update_time,
a.file_name AS file_name,
a.url AS url
FROM
sys_bulletin sb
LEFT JOIN
sys_bulletin_attach sba ON sb.id = sba.bulletin_id
LEFT JOIN
attachment a ON a.id = sba.attachment_id
where 1=1
<if test="query.title != null and query.title != ''"> <if test="query.title != null and query.title != ''">
AND sb.title LIKE CONCAT('%', #{query.title}, '%') AND sb.title LIKE CONCAT('%', #{query.title}, '%')
</if> </if>
@ -51,9 +85,6 @@
<if test="query.publishTimeBegin != null and query.publishTimeEnd != null"> <if test="query.publishTimeBegin != null and query.publishTimeEnd != null">
AND sb.publish_time BETWEEN #{query.publishTimeBegin} AND #{query.publishTimeEnd} AND sb.publish_time BETWEEN #{query.publishTimeBegin} AND #{query.publishTimeEnd}
</if> </if>
<if test="query.isRead != null">
AND sbu.is_read = #{query.isRead}
</if>
order by sb.top DESC,sb.publish_time DESC,sb.create_time DESC order by sb.top DESC,sb.publish_time DESC,sb.create_time DESC
</select> </select>
</mapper> </mapper>

View File

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zsc.edu.gateway.modules.system.repo.DeptRepository"> <mapper namespace="com.zsc.edu.gateway.modules.system.repo.DeptRepository">
<select id="selectAllWithMembers" resultType="com.zsc.edu.gateway.modules.system.entity.Dept">
SELECT d.*, u.*
FROM sys_dept d
LEFT JOIN sys_user u ON d.id = u.dept_id
</select>
</mapper> </mapper>

View File

@ -3,6 +3,7 @@ package com.zsc.edu.gateway.domain;
import com.zsc.edu.gateway.modules.system.entity.Dept; import com.zsc.edu.gateway.modules.system.entity.Dept;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
public class DeptBuilder extends BaseEntityBuilder { public class DeptBuilder extends BaseEntityBuilder {
@ -43,7 +44,7 @@ public class DeptBuilder extends BaseEntityBuilder {
Dept dept = new Dept(); Dept dept = new Dept();
dept.setName(name); dept.setName(name);
dept.setPid(pid); dept.setPid(pid);
dept.setChildren(children); dept.setChildren((List<Dept>) children);
return dept; return dept;
} }