Compare commits

...

4 Commits

Author SHA1 Message Date
396dfc5d2c refactor(notice): 删除冗余注释
- 移除了 BulletinServiceImpl 类中 delete 方法上的 TODO 注释
- 该注释标记了需要解决重复问题,但没有提供具体描述或解决方案
2024-12-09 16:17:09 +08:00
6fd1c6b81d refactor(notice): 重构公告模块
- 优化公告查询接口,新增分页查询功能
- 重构公告发布逻辑,支持批量发布
- 完善公告详情接口,增加用户信息
- 新增公告删除接口
- 优化公告状态切换逻辑
-调整公告附件处理方式
2024-12-09 16:16:21 +08:00
528318ff0a refactor(notice): 重构公告模块
- 优化公告查询接口,新增分页查询功能
- 重构公告发布逻辑,支持批量发布
- 完善公告详情接口,增加用户信息
- 新增公告删除接口
- 优化公告状态切换逻辑
-调整公告附件处理方式
2024-12-09 16:16:04 +08:00
e535b745ea feat(消息模块与部门模块): 修改了消息模块的bug并从新建消息接口中独立出添加附件接口,部门模块新添加了部门树返回接口 2024-12-07 17:31:11 +08:00
43 changed files with 723 additions and 83 deletions

View File

@ -6,12 +6,16 @@ import java.util.List;
public interface BaseMapper<D, E> {
D toDto(E entity);
E toEntity(D dto);
List<D> toDto(List<E> entityList);
List<E> toEntity(List<D> dtoList);
/**
* 更新实体类
*
* @param dto
* @param entity
*/

View File

@ -66,10 +66,10 @@ public class ApiExceptionHandler {
}
//TODO 跟全局security 冲突
// @ExceptionHandler(value = {Exception.class})
// public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
// log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
// return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
// }
@ExceptionHandler(value = {Exception.class})
public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

View File

@ -0,0 +1,69 @@
package com.zsc.edu.gateway.framework;
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.vo.DeptTree;
import com.zsc.edu.gateway.modules.system.vo.UserTree;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* @author zhuang
*/
@Component
public class DeptTreeUtil {
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
return list.stream()
.filter(rootCheck)
.peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren)))
.collect(Collectors.toList());
}
private static <E> List<E> makeChildren(E parent, List<E> allData, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
return allData.stream()
.filter(x -> parentCheck.apply(parent, x))
.peek(x -> setSubChildren.accept(x, makeChildren(x, allData, parentCheck, setSubChildren)))
.collect(Collectors.toList());
}
public static List<DeptTree> buildDeptTree(List<Dept> depots, Map<Long, List<User>> userMap) {
List<DeptTree> deptTrees = depots.stream()
.map(DeptTreeUtil::convertToDeptTree)
.collect(Collectors.toList());
deptTrees.forEach(deptTree -> {
List<User> users = userMap.getOrDefault(deptTree.getId(), Collections.emptyList());
deptTree.setMembers(users.stream()
.map(DeptTreeUtil::convertToUserTree)
.collect(Collectors.toList()));
});
return makeTree(
deptTrees,
deptTree -> deptTree.getPid() == null || deptTree.getPid() == 0L,
(parent, child) -> parent.getId().equals(child.getPid()),
DeptTree::setChildren
);
}
private static DeptTree convertToDeptTree(Dept dept) {
DeptTree deptTree = new DeptTree();
deptTree.setId(dept.getId());
deptTree.setPid(dept.getPid());
deptTree.setName(dept.getName());
return deptTree;
}
private static UserTree convertToUserTree(User user) {
UserTree userTree = new UserTree();
userTree.setId(user.getId());
userTree.setName(user.getName());
return userTree;
}
}

View File

@ -0,0 +1,21 @@
package com.zsc.edu.gateway.framework;
import org.springframework.http.HttpStatus;
import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author harry yao
*/
public class JsonExceptionUtil {
public static Map<String, Object> jsonExceptionResult(HttpStatus code, String message, String path) {
Map<String, Object> exceptionMap = new LinkedHashMap<>();
exceptionMap.put("timestamp", Calendar.getInstance().getTime());
exceptionMap.put("message", message);
exceptionMap.put("path", path);
exceptionMap.put("code", code.value());
return exceptionMap;
}
}

View File

@ -0,0 +1,130 @@
package com.zsc.edu.gateway.framework;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* @Description: 树操作方法工具类
* @Copyright: Copyright (c) 赵侠客
* @Date: 2024-07-22 10:42
* @Version: 1.0
*/
public class TreeUtil {
/**
* 将list合成树
*
* @param list 需要合成树的List
* @param rootCheck 判断E中为根节点的条件x->x.getPId()==-1L , x->x.getParentId()==null,x->x.getParentMenuId()==0
* @param parentCheck 判断E中为父节点条件(x,y)->x.getId().equals(y.getPId())
* @param setSubChildren E中设置下级数据方法Menu::setSubMenus
* @param <E> 泛型实体对象
* @return 合成好的树
*/
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
return list.stream().filter(rootCheck).peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren))).collect(Collectors.toList());
}
/**
* 将树打平成tree
*
* @param tree 需要打平的树
* @param getSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param setSubChildren 将下级数据置空方法x->x.setSubMenus(null)
* @param <E> 泛型实体对象
* @return 打平后的数据
*/
public static <E> List<E> flat(List<E> tree, Function<E, List<E>> getSubChildren, Consumer<E> setSubChildren) {
List<E> res = new ArrayList<>();
forPostOrder(tree, item -> {
setSubChildren.accept(item);
res.add(item);
}, getSubChildren);
return res;
}
/**
* 前序遍历
*
* @param tree 需要遍历的树
* @param consumer 遍历后对单个元素的处理方法x-> System.out.println(x) System.out::println打印元素
* @param setSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param <E> 泛型实体对象
*/
public static <E> void forPreOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
for (E l : tree) {
consumer.accept(l);
List<E> es = setSubChildren.apply(l);
if (es != null && es.size() > 0) {
forPreOrder(es, consumer, setSubChildren);
}
}
}
/**
* 层序遍历
*
* @param tree 需要遍历的树
* @param consumer 遍历后对单个元素的处理方法x-> System.out.println(x) System.out::println打印元素
* @param setSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param <E> 泛型实体对象
*/
public static <E> void forLevelOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
Queue<E> queue = new LinkedList<>(tree);
while (!queue.isEmpty()) {
E item = queue.poll();
consumer.accept(item);
List<E> childList = setSubChildren.apply(item);
if (childList != null && !childList.isEmpty()) {
queue.addAll(childList);
}
}
}
/**
* 后序遍历
*
* @param tree 需要遍历的树
* @param consumer 遍历后对单个元素的处理方法x-> System.out.println(x) System.out::println打印元素
* @param setSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param <E> 泛型实体对象
*/
public static <E> void forPostOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
for (E item : tree) {
List<E> childList = setSubChildren.apply(item);
if (childList != null && !childList.isEmpty()) {
forPostOrder(childList, consumer, setSubChildren);
}
consumer.accept(item);
}
}
/**
* 对树所有子节点按comparator排序
*
* @param tree 需要排序的树
* @param comparator 排序规则ComparatorComparator.comparing(MenuVo::getRank)按Rank正序 ,(x,y)->y.getRank().compareTo(x.getRank())按Rank倒序
* @param getChildren 获取下级数据方法MenuVo::getSubMenus
* @param <E> 泛型实体对象
* @return 排序好的树
*/
public static <E> List<E> sort(List<E> tree, Comparator<? super E> comparator, Function<E, List<E>> getChildren) {
for (E item : tree) {
List<E> childList = getChildren.apply(item);
if (childList != null && !childList.isEmpty()) {
sort(childList, comparator, getChildren);
}
}
tree.sort(comparator);
return tree;
}
private static <E> List<E> makeChildren(E parent, List<E> allData, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> children) {
return allData.stream().filter(x -> parentCheck.apply(parent, x)).peek(x -> children.accept(x, makeChildren(x, allData, parentCheck, children))).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,23 @@
package com.zsc.edu.gateway.framework.common.enums;
import com.baomidou.mybatisplus.annotation.IEnum;
public enum EnableState implements IEnum<Boolean> {
ENABLE(Boolean.TRUE),
DISABLE(Boolean.FALSE);
private boolean value;
EnableState(Boolean value) {
this.value = value;
}
@Override
public Boolean getValue() {
return this.value;
}
public EnableState reverse() {
return this == ENABLE ? DISABLE : ENABLE;
}
}

View File

@ -0,0 +1,36 @@
package com.zsc.edu.gateway.framework.common.enums;
import com.zsc.edu.gateway.exception.StateException;
import java.util.EnumSet;
/**
* @author harry_yao
*/
public interface IState<T extends Enum<T>> {
/**
* 用于检查对象当前状态是否等于correctStatus
*
* @param correctState 正确状态
*/
default void checkStatus(T correctState) {
if (this != correctState) {
throw new StateException(correctState.getClass(), this, correctState);
}
}
/**
* 用于检查对象当前状态是否在集合correctStates中
*
* @param correctStates 正确状态集合
*/
@SuppressWarnings("SuspiciousMethodCalls")
default void checkStatus(EnumSet<T> correctStates) {
if (!correctStates.contains(this)) {
throw new StateException(this.getClass(), this, correctStates);
}
}
}

View File

@ -0,0 +1,19 @@
package com.zsc.edu.gateway.framework.common.mapstruct;
import org.mapstruct.MappingTarget;
import java.util.List;
public interface BaseMapper<D, E> {
D toDto(E entity);
E toEntity(D dto);
List<D> toDto(List<E> entityList);
List<E> toEntity(List<D> dtoList);
/**
* 更新实体类
* @param dto
* @param entity
*/
void convert(D dto, @MappingTarget E entity);
}

View File

@ -0,0 +1,130 @@
package com.zsc.edu.gateway.framework.common.util;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* @Description: 树操作方法工具类
* @Copyright: Copyright (c) 赵侠客
* @Date: 2024-07-22 10:42
* @Version: 1.0
*/
public class TreeUtil {
/**
* 将list合成树
*
* @param list 需要合成树的List
* @param rootCheck 判断E中为根节点的条件x->x.getPId()==-1L , x->x.getParentId()==null,x->x.getParentMenuId()==0
* @param parentCheck 判断E中为父节点条件(x,y)->x.getId().equals(y.getPId())
* @param setSubChildren E中设置下级数据方法Menu::setSubMenus
* @param <E> 泛型实体对象
* @return 合成好的树
*/
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
return list.stream().filter(rootCheck).peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren))).collect(Collectors.toList());
}
/**
* 将树打平成tree
*
* @param tree 需要打平的树
* @param getSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param setSubChildren 将下级数据置空方法x->x.setSubMenus(null)
* @param <E> 泛型实体对象
* @return 打平后的数据
*/
public static <E> List<E> flat(List<E> tree, Function<E, List<E>> getSubChildren, Consumer<E> setSubChildren) {
List<E> res = new ArrayList<>();
forPostOrder(tree, item -> {
setSubChildren.accept(item);
res.add(item);
}, getSubChildren);
return res;
}
/**
* 前序遍历
*
* @param tree 需要遍历的树
* @param consumer 遍历后对单个元素的处理方法x-> System.out.println(x) System.out::println打印元素
* @param setSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param <E> 泛型实体对象
*/
public static <E> void forPreOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
for (E l : tree) {
consumer.accept(l);
List<E> es = setSubChildren.apply(l);
if (es != null && es.size() > 0) {
forPreOrder(es, consumer, setSubChildren);
}
}
}
/**
* 层序遍历
*
* @param tree 需要遍历的树
* @param consumer 遍历后对单个元素的处理方法x-> System.out.println(x) System.out::println打印元素
* @param setSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param <E> 泛型实体对象
*/
public static <E> void forLevelOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
Queue<E> queue = new LinkedList<>(tree);
while (!queue.isEmpty()) {
E item = queue.poll();
consumer.accept(item);
List<E> childList = setSubChildren.apply(item);
if (childList != null && !childList.isEmpty()) {
queue.addAll(childList);
}
}
}
/**
* 后序遍历
*
* @param tree 需要遍历的树
* @param consumer 遍历后对单个元素的处理方法x-> System.out.println(x) System.out::println打印元素
* @param setSubChildren 设置下级数据方法Menu::getSubMenus,x->x.setSubMenus(null)
* @param <E> 泛型实体对象
*/
public static <E> void forPostOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
for (E item : tree) {
List<E> childList = setSubChildren.apply(item);
if (childList != null && !childList.isEmpty()) {
forPostOrder(childList, consumer, setSubChildren);
}
consumer.accept(item);
}
}
/**
* 对树所有子节点按comparator排序
*
* @param tree 需要排序的树
* @param comparator 排序规则ComparatorComparator.comparing(MenuVo::getRank)按Rank正序 ,(x,y)->y.getRank().compareTo(x.getRank())按Rank倒序
* @param getChildren 获取下级数据方法MenuVo::getSubMenus
* @param <E> 泛型实体对象
* @return 排序好的树
*/
public static <E> List<E> sort(List<E> tree, Comparator<? super E> comparator, Function<E, List<E>> getChildren) {
for (E item : tree) {
List<E> childList = getChildren.apply(item);
if (childList != null && !childList.isEmpty()) {
sort(childList, comparator, getChildren);
}
}
tree.sort(comparator);
return tree;
}
private static <E> List<E> makeChildren(E parent, List<E> allData, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> children) {
return allData.stream().filter(x -> parentCheck.apply(parent, x)).peek(x -> children.accept(x, makeChildren(x, allData, parentCheck, children))).collect(Collectors.toList());
}
}

View File

@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class ResponseResult<T> {
//TODO 返回封装处理
/**
* 状态码
*/

View File

@ -24,7 +24,7 @@ import javax.sql.DataSource;
* @author harry_yao
*/
@AllArgsConstructor
@EnableMethodSecurity
//@EnableMethodSecurity
//TODO 加入全局注解会报错
@Configuration
public class SpringSecurityConfig {

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,
@ -91,4 +96,11 @@ public class AttachmentController {
return attachments;
}
/**
* 根据附件ID删除附件信息
*/
@DeleteMapping("delete/{id}")
public Boolean delete(@PathVariable("id") String id) {
return service.delete(id);
}
}

View File

@ -2,6 +2,9 @@ package com.zsc.edu.gateway.modules.attachment.repo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* @author ftz

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
@ -20,4 +21,8 @@ public interface AttachmentService extends IService<Attachment> {
Resource loadAsResource(String id);
Attachment.Wrapper loadAsWrapper(String id);
List<Attachment> selectList(List<String> dis);
Boolean delete(String id);
}

View File

@ -8,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;
@ -42,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
@ -201,4 +206,19 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
return attachment;
}
@Override
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

@ -0,0 +1,31 @@
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

@ -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

@ -0,0 +1,15 @@
package com.zsc.edu.gateway.modules.notice.mapper;
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
import com.zsc.edu.gateway.modules.notice.dto.BulletinAttachmentDto;
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author zhuang
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface BulletinAttachmentMapper extends BaseMapper<BulletinAttachmentDto, BulletinAttachment> {
}

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

@ -0,0 +1,16 @@
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

@ -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

@ -0,0 +1,16 @@
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

@ -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;
/**
* 查询公告详情
*
@ -48,20 +50,6 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
*/
@Override
public BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) {
// List<BulletinVo> bulletins = repo.selectByBulletinId(id);
// if (bulletins.isEmpty()) {
// return Collections.emptyList();
// }
// for (BulletinVo bulletin : bulletins) {
// if (state != null) {
// bulletin.getState().checkStatus(state);
// }
// bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId()));
// bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId()));
// bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId()));
// }
//
// return bulletins;
BulletinVo bulletinVo = repo.selectByBulletinId(id);
if (state != null) {
bulletinVo.getState().checkStatus(state);
@ -214,4 +202,15 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
public IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query) {
return baseMapper.selectPageByConditions(page, query);
}
@Override
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

@ -0,0 +1,61 @@
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

@ -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

@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/rest/authority")
public class AuthorityController {
//TODO 导入IOT
private AuthorityService service;
/**

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

@ -0,0 +1,26 @@
package com.zsc.edu.gateway.modules.system.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zsc.edu.gateway.modules.system.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
/**
* @author zhuang
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DeptTree {
private Long id;
@JsonIgnore
private Long pid;
private String name;
List<DeptTree> children = new ArrayList<>();
List<UserTree> members = new ArrayList<>();
}

View File

@ -0,0 +1,16 @@
package com.zsc.edu.gateway.modules.system.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author zhuang
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserTree {
private Long id;
private String name;
}

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,50 +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">
//TODO 查询数据问题已经修改
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>
@ -78,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>

View File

@ -28,7 +28,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebMvcTest(RoleController.class)
public class RoleControllerTest extends MockMvcConfigBase {
//TODO 公告部分测试
private static Role role1;
private static Role role2;