refactor(notice): 重构公告模块

- 优化公告查询接口,新增分页查询功能
- 重构公告发布逻辑,支持批量发布
- 完善公告详情接口,增加用户信息
- 新增公告删除接口
- 优化公告状态切换逻辑
-调整公告附件处理方式
This commit is contained in:
zhuangtianxiang 2024-12-09 16:16:04 +08:00
parent e535b745ea
commit 528318ff0a
26 changed files with 91 additions and 68 deletions

View File

@ -1,4 +1,4 @@
package com.zsc.edu.gateway.common.enums;
package com.zsc.edu.gateway.framework.common.enums;
import com.baomidou.mybatisplus.annotation.IEnum;

View File

@ -1,4 +1,4 @@
package com.zsc.edu.gateway.common.enums;
package com.zsc.edu.gateway.framework.common.enums;
import com.zsc.edu.gateway.exception.StateException;

View File

@ -1,4 +1,4 @@
package com.zsc.edu.gateway.common.mapstruct;
package com.zsc.edu.gateway.framework.common.mapstruct;
import org.mapstruct.MappingTarget;

View File

@ -1,4 +1,4 @@
package com.zsc.edu.gateway.common.util;
package com.zsc.edu.gateway.framework.common.util;
import java.util.*;
import java.util.function.*;

View File

@ -1,7 +1,6 @@
package com.zsc.edu.gateway.framework.security;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.zsc.edu.gateway.common.enums.EnableState;
import com.zsc.edu.gateway.modules.system.entity.Authority;
import com.zsc.edu.gateway.modules.system.entity.Dept;
import com.zsc.edu.gateway.modules.system.entity.Role;

View File

@ -77,6 +77,11 @@ public class AttachmentController {
public Attachment getAttachmentInfo(@PathVariable("id") String id) {
return service.getById(id);
}
/**
* 批量上传附件
*/
@PostMapping("uploadMultipleFiles")
public List<Attachment> uploadMultipleFiles(
@RequestParam(defaultValue = "其他") Attachment.Type type,

View File

@ -6,6 +6,7 @@ import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
* @author fantianzhi
@ -21,5 +22,7 @@ public interface AttachmentService extends IService<Attachment> {
Attachment.Wrapper loadAsWrapper(String id);
List<Attachment> selectList(List<String> dis);
Boolean delete(String id);
}

View File

@ -1,7 +1,6 @@
package com.zsc.edu.gateway.modules.attachment.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.framework.storage.StorageProperties;
import com.zsc.edu.gateway.framework.storage.exception.StorageFileEmptyException;
@ -9,6 +8,9 @@ import com.zsc.edu.gateway.framework.storage.exception.StorageFileNotFoundExcept
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
import com.zsc.edu.gateway.modules.attachment.repo.AttachmentRepository;
import com.zsc.edu.gateway.modules.attachment.service.AttachmentService;
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
import com.zsc.edu.gateway.modules.notice.repo.BulletinAttachmentRepository;
import com.zsc.edu.gateway.modules.notice.service.BulletinAttachmentService;
import jakarta.annotation.PostConstruct;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
@ -43,11 +45,13 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
private final AttachmentRepository repo;
private final Path attachmentPath;
private final Path tempPath;
private final BulletinAttachmentRepository bulletin;
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties) {
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties, BulletinAttachmentService bulletinAttachmentService, BulletinAttachmentRepository bulletin) {
this.repo = repo;
this.attachmentPath = Paths.get(storageProperties.attachment);
this.tempPath = Paths.get(storageProperties.temp);
this.bulletin = bulletin;
}
@PostConstruct
@ -203,10 +207,18 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
}
@Override
public Boolean delete(String id) {
QueryWrapper<Attachment> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", id);
return remove(queryWrapper);
public List<Attachment> selectList(List<String> dis) {
return repo.selectList(new LambdaQueryWrapper<Attachment>().in(Attachment::getId, dis));
}
@Override
public Boolean delete(String id) {
LambdaQueryWrapper<BulletinAttachment> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BulletinAttachment::getAttachmentId, id);
List<BulletinAttachment> bulletinAttachments = bulletin.selectList(wrapper);
if (!bulletinAttachments.isEmpty()) {
bulletin.delete(wrapper);
}
return removeById(id);
}
}

View File

@ -7,7 +7,16 @@ import lombok.Data;
*/
@Data
public class AttachmentVo {
public Long attachmentId;
public String fileName;
/**
* 附件ID
*/
public String attachmentId;
/**
* 附件地址
*/
public String url;
/**
* 附件名称
*/
public String fileName;
}

View File

@ -149,7 +149,7 @@ public class BulletinController {
@DeleteMapping("/{id}")
@PreAuthorize("hasAuthority('BULLETIN_DELETE')")
public Boolean delete(@PathVariable("id") Long id) {
return service.removeById(id);
return service.delete(id);
}
}

View File

@ -3,7 +3,7 @@ package com.zsc.edu.gateway.modules.notice.entity;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zsc.edu.gateway.common.enums.IState;
import com.zsc.edu.gateway.framework.common.enums.IState;
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
import lombok.*;

View File

@ -1,7 +1,7 @@
package com.zsc.edu.gateway.modules.notice.entity;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.zsc.edu.gateway.common.enums.IState;
import com.zsc.edu.gateway.framework.common.enums.IState;
/**
* 消息类型

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.notice.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
import org.mapstruct.Mapper;

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.notice.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
import com.zsc.edu.gateway.modules.notice.entity.Message;
import org.mapstruct.Mapper;

View File

@ -33,4 +33,6 @@ public interface BulletinService extends IService<Bulletin> {
Boolean close(UserDetailsImpl userDetails,Long id);
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query);
Boolean delete(Long id);
}

View File

@ -12,6 +12,7 @@ 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.entity.BulletinAttachment;
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
import com.zsc.edu.gateway.modules.notice.repo.BulletinAttachmentRepository;
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.BulletinService;
@ -39,6 +40,7 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
private final BulletinRepository repo;
private final BulletinAttachmentService bulletinAttachmentService;
private final UserRepository userRepository;
private final BulletinAttachmentRepository bulletinAttachmentRepository;
/**
* 查询公告详情
*
@ -200,4 +202,16 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
public IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query) {
return baseMapper.selectPageByConditions(page, query);
}
@Override
//TODO 解决重复
public Boolean delete(Long id) {
LambdaQueryWrapper<BulletinAttachment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BulletinAttachment::getAttachmentId, id);
List<BulletinAttachment> bulletinAttachments = bulletinAttachmentRepository.selectList(queryWrapper);
if (!bulletinAttachments.isEmpty()) {
bulletinAttachmentRepository.delete(queryWrapper);
}
return removeById(id);
}
}

View File

@ -2,6 +2,7 @@ package com.zsc.edu.gateway.modules.notice.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonInclude;
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;
@ -17,6 +18,7 @@ import java.util.Set;
* @author zhuang
*/
@Data
@JsonInclude
public class BulletinVo {
/**
* 公告id

View File

@ -3,7 +3,6 @@ package com.zsc.edu.gateway.modules.system.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.zsc.edu.gateway.common.enums.EnableState;
import lombok.*;
/**

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.system.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
import com.zsc.edu.gateway.modules.system.entity.Authority;
import org.mapstruct.Mapper;

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.system.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
import com.zsc.edu.gateway.modules.system.entity.Dept;
import org.mapstruct.Mapper;

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.system.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
import com.zsc.edu.gateway.modules.system.entity.RoleAuthority;
import org.mapstruct.Mapper;

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.system.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.system.dto.RoleDto;
import com.zsc.edu.gateway.modules.system.entity.Role;
import org.mapstruct.Mapper;

View File

@ -1,6 +1,6 @@
package com.zsc.edu.gateway.modules.system.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.system.dto.UserCreateDto;
import com.zsc.edu.gateway.modules.system.entity.User;
import org.mapstruct.Mapper;

View File

@ -2,21 +2,16 @@ package com.zsc.edu.gateway.modules.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.common.util.TreeUtil;
import com.zsc.edu.gateway.exception.ConstraintException;
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
//import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
import com.zsc.edu.gateway.modules.system.entity.Authority;
import com.zsc.edu.gateway.modules.system.entity.Dept;
import com.zsc.edu.gateway.modules.system.entity.Role;
import com.zsc.edu.gateway.modules.system.mapper.AuthorityMapper;
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
import com.zsc.edu.gateway.modules.system.service.AuthorityService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**

View File

@ -2,7 +2,7 @@ package com.zsc.edu.gateway.modules.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.exception.ConstraintException;
import com.zsc.edu.gateway.common.util.TreeUtil;
import com.zsc.edu.gateway.framework.common.util.TreeUtil;
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.mapper.DeptMapper;

View File

@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.BulletinRepository">
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo" autoMapping="true">
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="state" jdbcType="INTEGER" property="state"/>
@ -25,49 +25,31 @@
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo"
autoMapping="true" columnPrefix="attachment_">
<id column="id" property="attachmentId"/>
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
<id column="id" jdbcType="VARCHAR" property="attachmentId"/>
<result column="url" jdbcType="VARCHAR" property="url"/>
<result column="file_ame" jdbcType="VARCHAR" property="fileName"/>
</collection>
</resultMap>
<select id="selectByBulletinId" resultMap="BulletinMap">
SELECT sb.*, a.id as attachment_id, a.file_name as attachment_file_name, a.url as attachment_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 id="selectPageByConditions" resultType="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
SELECT
sb.id AS id,
sb.state AS state,
sb.content AS content,
sb.title AS title,
sb.top AS top,
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.id AS id,
a.file_name AS file_name,
a.url AS url
SELECT sb.*, a.id as attachment_id,a.url as attachment_url,a.file_name as attachment_file_name
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
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
LEFT JOIN attachment a ON a.id = sba.attachment_id
<where>
<if test="bulletinId !=null">
sb.id = #{bulletinId}
</if>
</where>
</select>
<select id="selectPageByConditions" resultMap="BulletinMap">
SELECT sb.*, a.id as attachment_id,a.file_name as attachment_file_name,a.url as attachment_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>
<if test="query.title != null and query.title != ''">
AND sb.title LIKE CONCAT('%', #{query.title}, '%')
</if>
@ -77,6 +59,7 @@
<if test="query.publishTimeBegin != null and query.publishTimeEnd != null">
AND sb.publish_time BETWEEN #{query.publishTimeBegin} AND #{query.publishTimeEnd}
</if>
</where>
order by sb.top DESC,sb.publish_time DESC,sb.create_time DESC
</select>
</mapper>