Compare commits
No commits in common. "feature/dept" and "master" have entirely different histories.
feature/de
...
master
@ -6,16 +6,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface BaseMapper<D, E> {
|
public interface BaseMapper<D, E> {
|
||||||
D toDto(E entity);
|
D toDto(E entity);
|
||||||
|
|
||||||
E toEntity(D dto);
|
E toEntity(D dto);
|
||||||
|
|
||||||
List<D> toDto(List<E> entityList);
|
List<D> toDto(List<E> entityList);
|
||||||
|
|
||||||
List<E> toEntity(List<D> dtoList);
|
List<E> toEntity(List<D> dtoList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新实体类
|
* 更新实体类
|
||||||
*
|
|
||||||
* @param dto
|
* @param dto
|
||||||
* @param entity
|
* @param entity
|
||||||
*/
|
*/
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.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 排序规则Comparator,如:Comparator.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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -65,7 +65,6 @@ public class ApiExceptionHandler {
|
|||||||
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO 跟全局security 冲突
|
|
||||||
@ExceptionHandler(value = {Exception.class})
|
@ExceptionHandler(value = {Exception.class})
|
||||||
public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
|
public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
|
||||||
log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
|
log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
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 排序规则Comparator,如:Comparator.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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.framework.jackson;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class JacksonConfig {
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
|
|
||||||
return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL)
|
|
||||||
.serializationInclusion(JsonInclude.Include.NON_EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
@ -95,11 +95,11 @@ public class EmailSender {
|
|||||||
} else {
|
} else {
|
||||||
helper.setText(message.content);
|
helper.setText(message.content);
|
||||||
}
|
}
|
||||||
// if (Objects.nonNull(message.attachments)) {
|
if (Objects.nonNull(message.attachments)) {
|
||||||
// for (Attachment attachment : message.attachments) {
|
for (Attachment attachment : message.attachments) {
|
||||||
// helper.addAttachment(attachment.fileName, attachmentService.loadAsResource(attachment.id), attachment.mimeType);
|
helper.addAttachment(attachment.fileName, attachmentService.loadAsResource(attachment.id), attachment.mimeType);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
sender.send(mimeMessage);
|
sender.send(mimeMessage);
|
||||||
} catch (MessagingException | IOException | TemplateException e) {
|
} catch (MessagingException | IOException | TemplateException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.framework.response;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Http状态返回枚举
|
|
||||||
*
|
|
||||||
* @author javadog
|
|
||||||
**/
|
|
||||||
@Getter
|
|
||||||
public enum HttpStatusEnum {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 操作成功
|
|
||||||
*/
|
|
||||||
SUCCESS(200, "操作成功"),
|
|
||||||
/**
|
|
||||||
* 对象创建成功
|
|
||||||
*/
|
|
||||||
CREATED(201, "对象创建成功"),
|
|
||||||
/**
|
|
||||||
* 请求已经被接受
|
|
||||||
*/
|
|
||||||
ACCEPTED(202, "请求已经被接受"),
|
|
||||||
/**
|
|
||||||
* 操作已经执行成功,但是没有返回数据
|
|
||||||
*/
|
|
||||||
NO_CONTENT(204, "操作已经执行成功,但是没有返回数据"),
|
|
||||||
/**
|
|
||||||
* 资源已被移除
|
|
||||||
*/
|
|
||||||
MOVED_PERM(301, "资源已被移除"),
|
|
||||||
/**
|
|
||||||
* 重定向
|
|
||||||
*/
|
|
||||||
SEE_OTHER(303, "重定向"),
|
|
||||||
/**
|
|
||||||
* 资源没有被修改
|
|
||||||
*/
|
|
||||||
NOT_MODIFIED(304, "资源没有被修改"),
|
|
||||||
/**
|
|
||||||
* 参数列表错误(缺少,格式不匹配)
|
|
||||||
*/
|
|
||||||
BAD_REQUEST(400, "参数列表错误(缺少,格式不匹配)"),
|
|
||||||
/**
|
|
||||||
* 未授权
|
|
||||||
*/
|
|
||||||
UNAUTHORIZED(401, "未授权"),
|
|
||||||
/**
|
|
||||||
* 访问受限,授权过期
|
|
||||||
*/
|
|
||||||
FORBIDDEN(403, "访问受限,授权过期"),
|
|
||||||
/**
|
|
||||||
* 资源,服务未找到
|
|
||||||
*/
|
|
||||||
NOT_FOUND(404, "资源,服务未找!"),
|
|
||||||
/**
|
|
||||||
* 不允许的http方法
|
|
||||||
*/
|
|
||||||
BAD_METHOD(405, "不允许的http方法"),
|
|
||||||
/**
|
|
||||||
* 资源冲突,或者资源被锁
|
|
||||||
*/
|
|
||||||
CONFLICT(409, "资源冲突,或者资源被锁"),
|
|
||||||
/**
|
|
||||||
* 不支持的数据,媒体类型
|
|
||||||
*/
|
|
||||||
UNSUPPORTED_TYPE(415, "不支持的数据,媒体类型"),
|
|
||||||
/**
|
|
||||||
* 系统内部错误
|
|
||||||
*/
|
|
||||||
ERROR(500, "系统内部错误"),
|
|
||||||
/**
|
|
||||||
* 接口未实现
|
|
||||||
*/
|
|
||||||
NOT_IMPLEMENTED(501, "接口未实现"),
|
|
||||||
/**
|
|
||||||
* 系统警告消息
|
|
||||||
*/
|
|
||||||
WARN(601, "系统警告消息");
|
|
||||||
|
|
||||||
private final Integer code;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
HttpStatusEnum(Integer code, String message) {
|
|
||||||
|
|
||||||
|
|
||||||
this.code = code;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,265 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.framework.response;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回结果集
|
|
||||||
*
|
|
||||||
* @author javadog
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class ResponseResult<T> {
|
|
||||||
|
|
||||||
//TODO 返回封装处理
|
|
||||||
/**
|
|
||||||
* 状态码
|
|
||||||
*/
|
|
||||||
private Integer code;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态信息
|
|
||||||
*/
|
|
||||||
private Boolean status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回信息
|
|
||||||
*/
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据
|
|
||||||
*/
|
|
||||||
private T data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全参数方法
|
|
||||||
*
|
|
||||||
* @param code 状态码
|
|
||||||
* @param status 状态
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param data 返回数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
private static <T> ResponseResult<T> response(Integer code, Boolean status, String message, T data) {
|
|
||||||
|
|
||||||
|
|
||||||
ResponseResult<T> responseResult = new ResponseResult<>();
|
|
||||||
responseResult.setCode(code);
|
|
||||||
responseResult.setStatus(status);
|
|
||||||
responseResult.setMessage(message);
|
|
||||||
responseResult.setData(data);
|
|
||||||
return responseResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全参数方法
|
|
||||||
*
|
|
||||||
* @param code 状态码
|
|
||||||
* @param status 状态
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
private static <T> ResponseResult<T> response(Integer code, Boolean status, String message) {
|
|
||||||
|
|
||||||
|
|
||||||
ResponseResult<T> responseResult = new ResponseResult<>();
|
|
||||||
responseResult.setCode(code);
|
|
||||||
responseResult.setStatus(status);
|
|
||||||
responseResult.setMessage(message);
|
|
||||||
return responseResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(无参)
|
|
||||||
*
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success() {
|
|
||||||
|
|
||||||
// return response(HttpStatus.OK.value(), true, HttpStatus.OK.getReasonPhrase(), null);
|
|
||||||
return response(HttpStatusEnum.SUCCESS.getCode(), true, HttpStatusEnum.SUCCESS.getMessage(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(枚举参数)
|
|
||||||
*
|
|
||||||
* @param httpResponseEnum 枚举参数
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success(HttpStatusEnum httpResponseEnum) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(httpResponseEnum.getCode(), true, httpResponseEnum.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(状态码+返回信息)
|
|
||||||
*
|
|
||||||
* @param code 状态码
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success(Integer code, String message) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(code, true, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(返回信息 + 数据)
|
|
||||||
*
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param data 数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success(String message, T data) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.SUCCESS.getCode(), true, message, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(状态码+返回信息+数据)
|
|
||||||
*
|
|
||||||
* @param code 状态码
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param data 数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success(Integer code, String message, T data) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(code, true, message, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(数据)
|
|
||||||
*
|
|
||||||
* @param data 数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success(T data) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.SUCCESS.getCode(), true, HttpStatusEnum.SUCCESS.getMessage(), data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 成功返回(返回信息)
|
|
||||||
*
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> success(String message) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.SUCCESS.getCode(), true, message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(无参)
|
|
||||||
*
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail() {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.ERROR.getCode(), false, HttpStatusEnum.ERROR.getMessage(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(枚举)
|
|
||||||
*
|
|
||||||
* @param httpResponseEnum 枚举
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail(HttpStatusEnum httpResponseEnum) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(httpResponseEnum.getCode(), false, httpResponseEnum.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(状态码+返回信息)
|
|
||||||
*
|
|
||||||
* @param code 状态码
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail(Integer code, String message) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(code, false, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(返回信息+数据)
|
|
||||||
*
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param data 数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail(String message, T data) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.ERROR.getCode(), false, message, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(状态码+返回信息+数据)
|
|
||||||
*
|
|
||||||
* @param code 状态码
|
|
||||||
* @param message 返回消息
|
|
||||||
* @param data 数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail(Integer code, String message, T data) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(code, false, message, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(数据)
|
|
||||||
*
|
|
||||||
* @param data 数据
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail(T data) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.ERROR.getCode(), false, HttpStatusEnum.ERROR.getMessage(), data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 失败返回(返回信息)
|
|
||||||
*
|
|
||||||
* @param message 返回信息
|
|
||||||
* @param <T> 泛型
|
|
||||||
* @return {@link ResponseResult<T>}
|
|
||||||
*/
|
|
||||||
public static <T> ResponseResult<T> fail(String message) {
|
|
||||||
|
|
||||||
|
|
||||||
return response(HttpStatusEnum.ERROR.getCode(), false, message, null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,6 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.ProviderManager;
|
import org.springframework.security.authentication.ProviderManager;
|
||||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.core.session.SessionRegistry;
|
import org.springframework.security.core.session.SessionRegistry;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
@ -24,8 +23,6 @@ import javax.sql.DataSource;
|
|||||||
* @author harry_yao
|
* @author harry_yao
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
//@EnableMethodSecurity
|
|
||||||
//TODO 加入全局注解会报错
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SpringSecurityConfig {
|
public class SpringSecurityConfig {
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.zsc.edu.gateway.framework.security;
|
package com.zsc.edu.gateway.framework.security;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
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.Authority;
|
||||||
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.Role;
|
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||||
|
@ -77,11 +77,6 @@ public class AttachmentController {
|
|||||||
public Attachment getAttachmentInfo(@PathVariable("id") String id) {
|
public Attachment getAttachmentInfo(@PathVariable("id") String id) {
|
||||||
return service.getById(id);
|
return service.getById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量上传附件
|
|
||||||
*/
|
|
||||||
@PostMapping("uploadMultipleFiles")
|
@PostMapping("uploadMultipleFiles")
|
||||||
public List<Attachment> uploadMultipleFiles(
|
public List<Attachment> uploadMultipleFiles(
|
||||||
@RequestParam(defaultValue = "其他") Attachment.Type type,
|
@RequestParam(defaultValue = "其他") Attachment.Type type,
|
||||||
@ -96,11 +91,4 @@ public class AttachmentController {
|
|||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据附件ID删除附件信息
|
|
||||||
*/
|
|
||||||
@DeleteMapping("delete/{id}")
|
|
||||||
public Boolean delete(@PathVariable("id") String id) {
|
|
||||||
return service.delete(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,11 @@ package com.zsc.edu.gateway.modules.attachment.repo;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
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
|
* @author ftz
|
||||||
* 创建时间:29/1/2024 上午9:55
|
* 创建时间:29/1/2024 上午9:55
|
||||||
|
* 描述: TODO
|
||||||
*/
|
*/
|
||||||
public interface AttachmentRepository extends BaseMapper<Attachment>{
|
public interface AttachmentRepository extends BaseMapper<Attachment>{
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.springframework.core.io.Resource;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author fantianzhi
|
* @author fantianzhi
|
||||||
@ -21,8 +20,4 @@ public interface AttachmentService extends IService<Attachment> {
|
|||||||
Resource loadAsResource(String id);
|
Resource loadAsResource(String id);
|
||||||
|
|
||||||
Attachment.Wrapper loadAsWrapper(String id);
|
Attachment.Wrapper loadAsWrapper(String id);
|
||||||
|
|
||||||
List<Attachment> selectList(List<String> dis);
|
|
||||||
|
|
||||||
Boolean delete(String id);
|
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@ 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.entity.Attachment;
|
||||||
import com.zsc.edu.gateway.modules.attachment.repo.AttachmentRepository;
|
import com.zsc.edu.gateway.modules.attachment.repo.AttachmentRepository;
|
||||||
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.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 jakarta.annotation.PostConstruct;
|
||||||
import org.apache.commons.codec.binary.Hex;
|
import org.apache.commons.codec.binary.Hex;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
@ -45,13 +42,11 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
|||||||
private final AttachmentRepository repo;
|
private final AttachmentRepository repo;
|
||||||
private final Path attachmentPath;
|
private final Path attachmentPath;
|
||||||
private final Path tempPath;
|
private final Path tempPath;
|
||||||
private final BulletinAttachmentRepository bulletin;
|
|
||||||
|
|
||||||
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties, BulletinAttachmentService bulletinAttachmentService, BulletinAttachmentRepository bulletin) {
|
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.attachmentPath = Paths.get(storageProperties.attachment);
|
this.attachmentPath = Paths.get(storageProperties.attachment);
|
||||||
this.tempPath = Paths.get(storageProperties.temp);
|
this.tempPath = Paths.get(storageProperties.temp);
|
||||||
this.bulletin = bulletin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@ -206,19 +201,4 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
|||||||
return attachment;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,6 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class AttachmentVo {
|
public class AttachmentVo {
|
||||||
/**
|
|
||||||
* 附件ID
|
|
||||||
*/
|
|
||||||
public String attachmentId;
|
|
||||||
/**
|
|
||||||
* 附件地址
|
|
||||||
*/
|
|
||||||
public String url;
|
|
||||||
/**
|
|
||||||
* 附件名称
|
|
||||||
*/
|
|
||||||
public String fileName;
|
public String fileName;
|
||||||
|
public String url;
|
||||||
}
|
}
|
||||||
|
@ -34,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,9 +45,10 @@ public class BulletinController {
|
|||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
@GetMapping("/self")
|
@GetMapping("/self")
|
||||||
public IPage<BulletinVo> getBulletins(Page<BulletinVo> pageParam, BulletinQuery query) {
|
public IPage<BulletinVo> getBulletins( BulletinQuery query) {
|
||||||
query.setState(Bulletin.State.publish);
|
query.setState(Bulletin.State.publish);
|
||||||
return service.selectPageByConditions(pageParam, query);
|
Page<BulletinVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||||
|
return service.selectPageByConditions(page, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +150,15 @@ public class BulletinController {
|
|||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@PreAuthorize("hasAuthority('BULLETIN_DELETE')")
|
@PreAuthorize("hasAuthority('BULLETIN_DELETE')")
|
||||||
public Boolean delete(@PathVariable("id") Long id) {
|
public Boolean delete(@PathVariable("id") Long id) {
|
||||||
return service.delete(id);
|
return service.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*为公告添加附件
|
||||||
|
*/
|
||||||
|
@PostMapping("/{id}/add")
|
||||||
|
@PreAuthorize("hasAuthority('BULLETIN_CREATE')")
|
||||||
|
public Boolean insertInto(@PathVariable Long id,@RequestBody Set<String> attachments){
|
||||||
|
return service.insertInto(id, attachments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,19 @@ 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.framework.security.UserDetailsImpl;
|
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||||
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.query.AdminMessageQuery;
|
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.query.UserMessageQuery;
|
||||||
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.AdminMessageVo;
|
|
||||||
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 lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户消息Controller
|
* 用户消息Controller
|
||||||
@ -48,10 +50,11 @@ public class UserMessageController {
|
|||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
@GetMapping("/self")
|
@GetMapping("/self")
|
||||||
public IPage<UserMessageVo> selfPage(Page<UserMessageVo> pageParam, @AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
public IPage<UserMessageVo> selfPage(@AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
||||||
query.userId = userDetails.id;
|
query.userId = userDetails.id;
|
||||||
query.name = null;
|
query.name = null;
|
||||||
return service.page(pageParam, query);
|
Page<UserMessageVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||||
|
return service.page(page, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,13 +83,14 @@ public class UserMessageController {
|
|||||||
/**
|
/**
|
||||||
* 管理查询消息详情
|
* 管理查询消息详情
|
||||||
*
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
* @param messageId 消息ID
|
* @param messageId 消息ID
|
||||||
* @return 用户消息详情
|
* @return 用户消息详情
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{userId}/{messageId}")
|
@GetMapping("/{userId}/{messageId}")
|
||||||
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||||
public UserMessageVo detail(@PathVariable("userId") Long userId, @PathVariable("messageId") Long messageId) {
|
public UserMessageVo detail(@PathVariable("userId") Long userId, @PathVariable("messageId") Long messageId) {
|
||||||
return service.detail(userId, messageId);
|
return service.detail(messageId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,8 +101,9 @@ public class UserMessageController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||||
public IPage<AdminMessageVo> page(Page<UserMessageVo> page, AdminMessageQuery query) {
|
public IPage<UserMessageVo> page(UserMessageQuery query) {
|
||||||
return service.getAdminMessagePage(page, query);
|
Page<UserMessageVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||||
|
return service.page(page, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,4 +117,41 @@ public class UserMessageController {
|
|||||||
public Boolean create(@RequestBody UserMessageDto dto) {
|
public Boolean create(@RequestBody UserMessageDto dto) {
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息推送方式
|
||||||
|
*
|
||||||
|
* @return 消息推送方式列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/setting")
|
||||||
|
@PreAuthorize("hasAuthority('MESSAGE_SETTING')")
|
||||||
|
public List<MessageSetting> getSetting() {
|
||||||
|
return service.getSetting();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息推送方式
|
||||||
|
*
|
||||||
|
* @param settings 表单数据
|
||||||
|
* @return 消息设置
|
||||||
|
*/
|
||||||
|
@PatchMapping("/setting")
|
||||||
|
@PreAuthorize("hasAuthority('MESSAGE_SETTING')")
|
||||||
|
public List<MessageSetting> saveSetting(@RequestBody List<MessageSetting> settings) {
|
||||||
|
return service.saveSetting(settings);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class BulletinDto {
|
|||||||
/**
|
/**
|
||||||
* 是否置顶
|
* 是否置顶
|
||||||
*/
|
*/
|
||||||
public Boolean top;
|
public boolean top;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内容
|
* 内容
|
||||||
@ -36,9 +36,9 @@ public class BulletinDto {
|
|||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
public String remark;
|
public String remark;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 附件ID集合
|
// * 附件ID集合
|
||||||
*/
|
// */
|
||||||
private List<String> attachmentIds;
|
// private List<String> attachmentIds;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package com.zsc.edu.gateway.modules.notice.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.zsc.edu.gateway.framework.common.enums.IState;
|
import com.zsc.edu.gateway.common.enums.IState;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
||||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -30,7 +30,7 @@ public class Message extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 是否系统生成
|
* 是否系统生成
|
||||||
*/
|
*/
|
||||||
public Boolean system = false;
|
public Boolean system;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否需要发送邮件
|
* 是否需要发送邮件
|
||||||
@ -57,4 +57,9 @@ public class Message extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
public String content;
|
public String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件
|
||||||
|
*/
|
||||||
|
public List<Attachment> attachments;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.notice.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息设置
|
||||||
|
*
|
||||||
|
* @author harry_yao
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TableName("sys_message_setting")
|
||||||
|
public class MessageSetting {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息类型
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
public Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否发送邮件
|
||||||
|
*/
|
||||||
|
public Boolean email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否发送短信
|
||||||
|
*/
|
||||||
|
public Boolean sms;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MessageSetting that = (MessageSetting) o;
|
||||||
|
return Objects.equals(id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id.hashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.zsc.edu.gateway.modules.notice.entity;
|
package com.zsc.edu.gateway.modules.notice.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||||
import com.zsc.edu.gateway.framework.common.enums.IState;
|
import com.zsc.edu.gateway.common.enums.IState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息类型
|
* 消息类型
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||||
|
|
||||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
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.Bulletin;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
|
||||||
|
|
||||||
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;
|
|
||||||
import org.mapstruct.ReportingPolicy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zhuang
|
|
||||||
*/
|
|
||||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
|
||||||
public interface MessageMapper extends BaseMapper<UserMessageDto, Message> {
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.modules.notice.query;
|
|
||||||
|
|
||||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zhuang
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class AdminMessageQuery {
|
|
||||||
/**
|
|
||||||
* 用户ID
|
|
||||||
*/
|
|
||||||
public Long userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标题,模糊查询
|
|
||||||
*/
|
|
||||||
public String title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息创建时间区间起始
|
|
||||||
*/
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
public LocalDateTime createAtBegin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息创建时间区间终止
|
|
||||||
*/
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
public LocalDateTime createAtEnd;
|
|
||||||
}
|
|
@ -57,13 +57,16 @@ public class UserMessageQuery {
|
|||||||
/**
|
/**
|
||||||
* 消息创建时间区间起始
|
* 消息创建时间区间起始
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||||
public LocalDateTime createAtBegin;
|
public LocalDateTime createAtBegin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息创建时间区间终止
|
* 消息创建时间区间终止
|
||||||
*/
|
*/
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||||
public LocalDateTime createAtEnd;
|
public LocalDateTime createAtEnd;
|
||||||
|
|
||||||
|
private Integer pageNum = 1;
|
||||||
|
private Integer pageSize = 10;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.notice.repo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息设置Repo
|
||||||
|
*
|
||||||
|
* @author harry_yao
|
||||||
|
*/
|
||||||
|
public interface MessageSettingRepository extends BaseMapper<MessageSetting> {
|
||||||
|
@Select("select * from sys_message_setting")
|
||||||
|
List<MessageSetting> findAll();
|
||||||
|
}
|
@ -4,9 +4,9 @@ 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.entity.UserMessage;
|
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@ -16,10 +16,7 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
* @author harry_yao
|
* @author harry_yao
|
||||||
*/
|
*/
|
||||||
public interface UserMessageRepository extends BaseMapper<UserMessage> {
|
public interface UserMessageRepository extends BaseMapper<UserMessage> {
|
||||||
|
|
||||||
UserMessageVo selectByMessageIdAndUserId(@Param("messageId") Long messageId, @Param("userId") Long userId);
|
UserMessageVo selectByMessageIdAndUserId(@Param("messageId") Long messageId, @Param("userId") Long userId);
|
||||||
|
|
||||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
IPage<UserMessageVo> query(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
||||||
|
|
||||||
IPage<AdminMessageVo> pageAdmin(Page<UserMessageVo> page, @Param("query") AdminMessageQuery query);
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||||
|
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;
|
||||||
@ -20,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);
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ public interface BulletinService extends IService<Bulletin> {
|
|||||||
|
|
||||||
Boolean close(UserDetailsImpl userDetails,Long id);
|
Boolean close(UserDetailsImpl userDetails,Long id);
|
||||||
|
|
||||||
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query);
|
Boolean insertInto(Long bulletinId, Set<String> attachmentIds);
|
||||||
|
|
||||||
Boolean delete(Long id);
|
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
@ -5,13 +5,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||||
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.MessagePayload;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||||
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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户消息Service
|
* 用户消息Service
|
||||||
@ -24,12 +29,17 @@ 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();
|
||||||
|
|
||||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query);
|
IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query);
|
||||||
|
|
||||||
Integer countUnread(UserDetailsImpl userDetails);
|
Integer countUnread(UserDetailsImpl userDetails);
|
||||||
|
|
||||||
Integer markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
Integer markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
List<MessageSetting> saveSetting(List<MessageSetting> settings);
|
||||||
|
|
||||||
IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query);
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ 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.Bulletin;
|
||||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
|
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.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.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;
|
||||||
@ -40,7 +39,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 UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final BulletinAttachmentRepository bulletinAttachmentRepository;
|
|
||||||
/**
|
/**
|
||||||
* 查询公告详情
|
* 查询公告详情
|
||||||
*
|
*
|
||||||
@ -49,15 +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 bulletinVo = repo.selectByBulletinId(id);
|
List<BulletinVo> bulletins = repo.selectByBulletinId(id);
|
||||||
if (state != null) {
|
if (bulletins.isEmpty()) {
|
||||||
bulletinVo.getState().checkStatus(state);
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
bulletinVo.setEditUsername(userRepository.selectNameById(bulletinVo.getEditUserId()));
|
for (BulletinVo bulletin : bulletins) {
|
||||||
bulletinVo.setPublishUsername(userRepository.selectNameById(bulletinVo.getPublishUserId()));
|
if (state != null) {
|
||||||
bulletinVo.setCloseUsername(userRepository.selectNameById(bulletinVo.getCloseUserId()));
|
bulletin.getState().checkStatus(state);
|
||||||
return bulletinVo;
|
}
|
||||||
|
bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId()));
|
||||||
|
bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId()));
|
||||||
|
bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return bulletins;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 新建公告
|
* 新建公告
|
||||||
@ -78,9 +82,6 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
|||||||
bulletin.setCreateBy(userDetails.getName());
|
bulletin.setCreateBy(userDetails.getName());
|
||||||
bulletin.setEditUserId(userDetails.getId());
|
bulletin.setEditUserId(userDetails.getId());
|
||||||
save(bulletin);
|
save(bulletin);
|
||||||
if (dto.getAttachmentIds() != null) {
|
|
||||||
insertInto(bulletin.getId(), dto.getAttachmentIds());
|
|
||||||
}
|
|
||||||
return bulletin;
|
return bulletin;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -182,13 +183,15 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
|||||||
* @param attachmentIds attachments
|
* @param attachmentIds attachments
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
public Boolean insertInto(Long bulletinId, List<String> attachmentIds) {
|
@Override
|
||||||
|
public Boolean insertInto(Long bulletinId, Set<String> attachmentIds) {
|
||||||
List<BulletinAttachment> bulletinAttachments = attachmentIds.stream()
|
List<BulletinAttachment> bulletinAttachments = attachmentIds.stream()
|
||||||
.map(attachmentId -> new BulletinAttachment(bulletinId, attachmentId))
|
.map(attachmentId -> new BulletinAttachment(bulletinId, attachmentId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return bulletinAttachmentService.saveBatch(bulletinAttachments);
|
return bulletinAttachmentService.saveBatch(bulletinAttachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<Bulletin> getBulletinsByIds(List<Long> ids) {
|
private List<Bulletin> getBulletinsByIds(List<Long> ids) {
|
||||||
if (ids == null || ids.isEmpty()) {
|
if (ids == null || ids.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@ -202,15 +205,4 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
|||||||
public IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query) {
|
public IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query) {
|
||||||
return baseMapper.selectPageByConditions(page, 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,61 +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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@ -10,19 +9,18 @@ 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.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.*;
|
||||||
import com.zsc.edu.gateway.modules.notice.mapper.MessageMapper;
|
|
||||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
|
||||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
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.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.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.AdminMessageVo;
|
|
||||||
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;
|
||||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
import com.zsc.edu.gateway.modules.system.service.UserService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -44,12 +42,14 @@ import java.util.stream.Collectors;
|
|||||||
public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, UserMessage> implements UserMessageService {
|
public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, UserMessage> implements UserMessageService {
|
||||||
|
|
||||||
private final MessageRepository messageRepo;
|
private final MessageRepository messageRepo;
|
||||||
|
private final MessageSettingRepository messageSettingRepo;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
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;
|
private final MessageAttachmentService messageAttachmentService;
|
||||||
private final UserRepository userRepository;
|
|
||||||
private final MessageMapper messageMapper;
|
|
||||||
/**
|
/**
|
||||||
* 查询消息详情
|
* 查询消息详情
|
||||||
*
|
*
|
||||||
@ -60,14 +60,6 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserMessageVo detail(Long messageId, Long userId) {
|
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(true);
|
|
||||||
userMessage.setReadTime(LocalDateTime.now());
|
|
||||||
save(userMessage);
|
|
||||||
}
|
|
||||||
return userMessageRepository.selectByMessageIdAndUserId(messageId, userId);
|
return userMessageRepository.selectByMessageIdAndUserId(messageId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +72,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query) {
|
public IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query) {
|
||||||
return userMessageRepository.page(page, query);
|
return userMessageRepository.query(page, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,23 +102,12 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
|||||||
}
|
}
|
||||||
UpdateWrapper<UserMessage> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<UserMessage> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.eq("user_id", userDetails.getId()).in("message_id", messageIds);
|
updateWrapper.eq("user_id", userDetails.getId()).in("message_id", messageIds);
|
||||||
updateWrapper.set("is_read", true);
|
updateWrapper.set("is_read", false);
|
||||||
updateWrapper.set("read_time", LocalDateTime.now());
|
updateWrapper.set("read_time", LocalDateTime.now());
|
||||||
return userMessageRepository.update(updateWrapper);
|
return userMessageRepository.update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员查询消息列表
|
|
||||||
*
|
|
||||||
* @return 消息设置列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query) {
|
|
||||||
return userMessageRepository.pageAdmin(page, query);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理员手动创建用户消息并发送
|
* 管理员手动创建用户消息并发送
|
||||||
*
|
*
|
||||||
@ -136,17 +117,72 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public Boolean createByAdmin(UserMessageDto dto) {
|
public Boolean createByAdmin(UserMessageDto dto) {
|
||||||
Set<User> users = new HashSet<>(userRepository.selectList(new LambdaQueryWrapper<User>().in(User::getId, dto.userIds)));
|
Set<User> users = dto.userIds.stream()
|
||||||
Message message = messageMapper.toEntity(dto);
|
.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,
|
||||||
|
dto.title, dto.content, null);
|
||||||
messageRepo.insert(message);
|
messageRepo.insert(message);
|
||||||
Set<UserMessage> userMessages = users.stream()
|
Set<UserMessage> userMessages = users.stream()
|
||||||
.map(user -> new UserMessage(null, user.getId(), message.getId(), true, null))
|
.map(user -> new UserMessage(null, user.getId(), message.getId(), false, null))
|
||||||
.collect(Collectors.toSet());
|
.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有消息推送方式
|
||||||
|
*
|
||||||
|
* @return 消息设置列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MessageSetting> getSetting() {
|
||||||
|
return messageSettingRepo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息推送方式
|
||||||
|
*
|
||||||
|
* @param settings 消息设置集合
|
||||||
|
* @return 消息设置列表
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public List<MessageSetting> saveSetting(List<MessageSetting> settings) {
|
||||||
|
if (CollectionUtils.isEmpty(settings)) {
|
||||||
|
throw new RuntimeException("settings is NULL!");
|
||||||
|
}
|
||||||
|
for (MessageSetting setting : settings) {
|
||||||
|
try {
|
||||||
|
messageSettingRepo.insert(setting);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("设置失败" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以邮件、短信等形式发送消息,只有非html格式的消息才能以短信方式发送
|
* 以邮件、短信等形式发送消息,只有非html格式的消息才能以短信方式发送
|
||||||
*
|
*
|
||||||
@ -174,15 +210,15 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
|||||||
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);
|
||||||
Optional.of(messageRepo.selectById(payload.type)).ifPresent(message -> {
|
Optional.of(messageSettingRepo.selectById(payload.type)).ifPresent(messageSetting -> {
|
||||||
email.set(message.email);
|
email.set(messageSetting.email);
|
||||||
sms.set(message.sms);
|
sms.set(messageSetting.sms);
|
||||||
});
|
});
|
||||||
Message message = new Message(payload.type, true, email.get(), sms.get(),
|
Message message = new Message(payload.type, true, email.get(), sms.get(),
|
||||||
payload.html, payload.type.name(), payload.content);
|
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.getId(), message.getId(), true, 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);
|
||||||
}
|
}
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
package com.zsc.edu.gateway.modules.notice.vo;
|
|
||||||
|
|
||||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zhuang
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class AdminMessageVo {
|
|
||||||
/**
|
|
||||||
* 用户消息id
|
|
||||||
*/
|
|
||||||
private Long id;
|
|
||||||
/**
|
|
||||||
* 接受用户数
|
|
||||||
*/
|
|
||||||
private Long userCount;
|
|
||||||
/**
|
|
||||||
* 已读用户数
|
|
||||||
*/
|
|
||||||
private Long readCount;
|
|
||||||
/**
|
|
||||||
* 消息类型
|
|
||||||
*/
|
|
||||||
public MessageType type = MessageType.other;
|
|
||||||
/**
|
|
||||||
* 是否系统消息
|
|
||||||
*/
|
|
||||||
public Boolean system;
|
|
||||||
/**
|
|
||||||
* 是否邮件
|
|
||||||
*/
|
|
||||||
public Boolean email;
|
|
||||||
/**
|
|
||||||
* 是否短信
|
|
||||||
*/
|
|
||||||
public Boolean sms;
|
|
||||||
/**
|
|
||||||
* 是否html
|
|
||||||
*/
|
|
||||||
public Boolean html;
|
|
||||||
/**
|
|
||||||
* 标题
|
|
||||||
*/
|
|
||||||
public String title;
|
|
||||||
/**
|
|
||||||
* 内容
|
|
||||||
*/
|
|
||||||
public String content;
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ 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.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||||
import com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo;
|
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;
|
||||||
@ -12,93 +11,35 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhuang
|
* @author zhuang
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@JsonInclude
|
|
||||||
public class BulletinVo {
|
public class BulletinVo {
|
||||||
/**
|
|
||||||
* 公告id
|
|
||||||
*/
|
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
|
||||||
* 公告标题
|
|
||||||
*/
|
|
||||||
private String title;
|
private String title;
|
||||||
/**
|
|
||||||
* 公告属性
|
|
||||||
*/
|
|
||||||
private Bulletin.State state = Bulletin.State.edit;
|
private Bulletin.State state = Bulletin.State.edit;
|
||||||
/**
|
|
||||||
* 公告置顶状态
|
|
||||||
*/
|
|
||||||
private Boolean top;
|
private Boolean top;
|
||||||
/**
|
|
||||||
* 公告编辑者ID
|
|
||||||
*/
|
|
||||||
private Long editUserId;
|
private Long editUserId;
|
||||||
/**
|
|
||||||
* 公告编辑者名称
|
|
||||||
*/
|
|
||||||
private String editUsername;
|
private String editUsername;
|
||||||
/**
|
|
||||||
* 公告编辑时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime editTime;
|
private LocalDateTime editTime;
|
||||||
/**
|
|
||||||
* 公告发布者ID
|
|
||||||
*/
|
|
||||||
private Long publishUserId;
|
private Long publishUserId;
|
||||||
/**
|
|
||||||
* 公告发布者名称
|
|
||||||
*/
|
|
||||||
private String publishUsername;
|
private String publishUsername;
|
||||||
/**
|
|
||||||
* 公告发布时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime publishTime;
|
private LocalDateTime publishTime;
|
||||||
/**
|
|
||||||
* 公告关闭者ID
|
|
||||||
*/
|
|
||||||
private Long closeUserId;
|
private Long closeUserId;
|
||||||
/**
|
|
||||||
* 公告关闭者名称
|
|
||||||
*/
|
|
||||||
private String closeUsername;
|
private String closeUsername;
|
||||||
/**
|
|
||||||
* 公告关闭时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime closeTime;
|
private LocalDateTime closeTime;
|
||||||
/**
|
|
||||||
* 公告内容
|
|
||||||
*/
|
|
||||||
private String content;
|
private String content;
|
||||||
/**
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
/**
|
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||||
* 创建者
|
|
||||||
*/
|
|
||||||
private String createBy;
|
private String createBy;
|
||||||
/**
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
/**
|
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||||
* 更新者
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
private String updateBy;
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
/**
|
|
||||||
* 附件
|
|
||||||
*/
|
|
||||||
List<AttachmentVo> attachmentVos;
|
List<AttachmentVo> attachmentVos;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
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.Message;
|
||||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||||
@ -18,71 +17,35 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class UserMessageVo {
|
public class UserMessageVo {
|
||||||
/**
|
private Long id;
|
||||||
* 用户消息id
|
public Long userId;
|
||||||
*/
|
public User user;
|
||||||
private Long messageId;
|
public Long messageId;
|
||||||
/**
|
public Message message;
|
||||||
* 是否已读
|
|
||||||
*/
|
|
||||||
public Boolean isRead;
|
public Boolean isRead;
|
||||||
/**
|
|
||||||
* 阅读时间
|
|
||||||
*/
|
|
||||||
public LocalDateTime readTime;
|
public LocalDateTime readTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名
|
|
||||||
*/
|
|
||||||
public String username;
|
public String username;
|
||||||
|
public String name;
|
||||||
|
public String avatar;
|
||||||
|
public String address;
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息类型
|
|
||||||
*/
|
|
||||||
public MessageType type = MessageType.other;
|
public MessageType type = MessageType.other;
|
||||||
/**
|
|
||||||
* 是否系统消息
|
|
||||||
*/
|
|
||||||
public Boolean system;
|
public Boolean system;
|
||||||
/**
|
|
||||||
* 是否邮件
|
|
||||||
*/
|
|
||||||
public Boolean email;
|
public Boolean email;
|
||||||
/**
|
|
||||||
* 是否短信
|
|
||||||
*/
|
|
||||||
public Boolean sms;
|
public Boolean sms;
|
||||||
/**
|
|
||||||
* 是否html
|
|
||||||
*/
|
|
||||||
public Boolean html;
|
public Boolean html;
|
||||||
/**
|
|
||||||
* 标题
|
|
||||||
*/
|
|
||||||
public String title;
|
public String title;
|
||||||
/**
|
|
||||||
* 内容
|
|
||||||
*/
|
|
||||||
public String content;
|
public String content;
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
private String remark;
|
||||||
/**
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
/**
|
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||||
* 创建人
|
|
||||||
*/
|
|
||||||
private String createBy;
|
private String createBy;
|
||||||
/**
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
/**
|
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||||
* 更新人
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
private String updateBy;
|
||||||
|
|
||||||
|
public List<Attachment> attachments;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/rest/authority")
|
@RequestMapping("/api/rest/authority")
|
||||||
public class AuthorityController {
|
public class AuthorityController {
|
||||||
//TODO 导入IOT
|
|
||||||
private AuthorityService service;
|
private AuthorityService service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.controller;
|
package com.zsc.edu.gateway.modules.system.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||||
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.entity.User;
|
||||||
|
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.*;
|
||||||
@ -28,12 +31,12 @@ public class DeptController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回管理部门列表 hasAuthority('DEPT_QUERY')
|
* 返回管理部门列表 hasAuthority('DEPT_QUERY')
|
||||||
* @param deptId 部门ID
|
*
|
||||||
* @return 部门列表
|
* @return 部门列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{deptId}")
|
@GetMapping()
|
||||||
public List<Dept> getDeptTree(@PathVariable Long deptId) {
|
public List<DeptTree> getDeptTree() {
|
||||||
return service.getDeptTree(deptId);
|
return service.getDeptTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,6 @@ package com.zsc.edu.gateway.modules.system.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.zsc.edu.gateway.modules.system.vo.UserVo;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@ -48,9 +47,9 @@ public class Dept extends BaseEntity {
|
|||||||
private Boolean enabled = true;
|
private Boolean enabled = true;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
public List<Dept> children = null;
|
public List<Dept> children = new ArrayList<>(0);
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
public List<UserVo> members = null;
|
public List<User> members = new ArrayList<>(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.zsc.edu.gateway.modules.system.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.zsc.edu.gateway.common.enums.EnableState;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.mapper;
|
package com.zsc.edu.gateway.modules.system.mapper;
|
||||||
|
|
||||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.mapper;
|
package com.zsc.edu.gateway.modules.system.mapper;
|
||||||
|
|
||||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||||
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 org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.mapper;
|
package com.zsc.edu.gateway.modules.system.mapper;
|
||||||
|
|
||||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||||
import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
|
import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.RoleAuthority;
|
import com.zsc.edu.gateway.modules.system.entity.RoleAuthority;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.mapper;
|
package com.zsc.edu.gateway.modules.system.mapper;
|
||||||
|
|
||||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||||
import com.zsc.edu.gateway.modules.system.dto.RoleDto;
|
import com.zsc.edu.gateway.modules.system.dto.RoleDto;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.Role;
|
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.mapper;
|
package com.zsc.edu.gateway.modules.system.mapper;
|
||||||
|
|
||||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||||
import com.zsc.edu.gateway.modules.system.dto.UserCreateDto;
|
import com.zsc.edu.gateway.modules.system.dto.UserCreateDto;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -2,6 +2,11 @@ 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;
|
import java.util.List;
|
||||||
|
|
||||||
@ -14,5 +19,6 @@ import java.util.List;
|
|||||||
* @since 2023-04-06
|
* @since 2023-04-06
|
||||||
*/
|
*/
|
||||||
public interface DeptRepository extends BaseMapper<Dept> {
|
public interface DeptRepository extends BaseMapper<Dept> {
|
||||||
List<Dept> selectDeptTree();
|
@Select("SELECT d.*, u.* FROM sys_dept d LEFT JOIN sys_user u ON d.id = u.dept_id")
|
||||||
|
List<Dept> selectAllWithMembers();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ 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;
|
import java.util.List;
|
||||||
|
|
||||||
@ -30,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();
|
||||||
* 生成部门树结构
|
|
||||||
*
|
|
||||||
* @return Dept
|
|
||||||
*/
|
|
||||||
List<Dept> getDeptTree(Long deptId);
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.zsc.edu.gateway.exception.ConstraintException;
|
|||||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
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.dto.RoleAuthorityDto;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||||
|
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.mapper.AuthorityMapper;
|
||||||
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
|
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
|
||||||
import com.zsc.edu.gateway.modules.system.service.AuthorityService;
|
import com.zsc.edu.gateway.modules.system.service.AuthorityService;
|
||||||
|
@ -2,19 +2,23 @@ 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.common.util.TreeUtil;
|
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.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -30,6 +34,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
|||||||
|
|
||||||
private final DeptMapper mapper;
|
private final DeptMapper mapper;
|
||||||
private final DeptRepository repo;
|
private final DeptRepository repo;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dept create(DeptDto dto) {
|
public Dept create(DeptDto dto) {
|
||||||
@ -59,25 +64,14 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Dept> getDeptTree(Long deptId) {
|
public List<DeptTree> getDeptTree() {
|
||||||
List<Dept> deptTrees = repo.selectDeptTree();
|
List<Dept> depots = repo.selectList(null);
|
||||||
List<Dept> deptTree = TreeUtil.makeTree(
|
List<User> users = userRepository.selectList(null);
|
||||||
deptTrees,
|
Map<Long, List<User>> userMap = new HashMap<>();
|
||||||
department -> department.getPid() == null || department.getPid() == -1L,
|
for (User user : users) {
|
||||||
(parent, child) -> parent.getId().equals(child.getPid()),
|
userMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
||||||
Dept::setChildren
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Objects.nonNull(deptId)) {
|
|
||||||
List<Dept> deptChildrenTree = new ArrayList<>();
|
|
||||||
TreeUtil.forLevelOrder(deptTree, node -> {
|
|
||||||
if (node.getId().equals(deptId)) {
|
|
||||||
deptChildrenTree.add(node);
|
|
||||||
}
|
}
|
||||||
}, Dept::getChildren);
|
return DeptTreeUtil.buildDeptTree(depots, userMap);
|
||||||
return deptChildrenTree;
|
|
||||||
}
|
|
||||||
return deptTree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleRepository, Role> implement
|
|||||||
@Override
|
@Override
|
||||||
public RoleVo detail(Long id) {
|
public RoleVo detail(Long id) {
|
||||||
// Role role = getById(id);
|
// Role role = getById(id);
|
||||||
|
// // TODO 联表查询
|
||||||
// // List<RoleAuthority> roleAuthorities = roleAuthService.list(new LambdaQueryWrapper<RoleAuthority>().eq(RoleAuthority::getRoleId, role.id));
|
// // List<RoleAuthority> roleAuthorities = roleAuthService.list(new LambdaQueryWrapper<RoleAuthority>().eq(RoleAuthority::getRoleId, role.id));
|
||||||
// role.authorities = authorityRepository.selectAuthoritiesByRoleId(role.id);
|
// role.authorities = authorityRepository.selectAuthoritiesByRoleId(role.id);
|
||||||
return roleRepository.selectRoleById(id);
|
return roleRepository.selectRoleById(id);
|
||||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author ftz
|
* @author ftz
|
||||||
* 创建时间:16/2/2024 下午6:20
|
* 创建时间:16/2/2024 下午6:20
|
||||||
|
* 描述: TODO
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
package com.zsc.edu.gateway.modules.system.vo;
|
package com.zsc.edu.gateway.modules.system.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zhuang
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public class UserVo {
|
public class UserVo {
|
||||||
/**
|
/**
|
||||||
* 自增主键
|
* 自增主键
|
||||||
*/
|
*/
|
||||||
public Long userId;
|
@TableId(type = IdType.AUTO)
|
||||||
|
public Long id;
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
|
@ -291,31 +291,24 @@ comment on column sys_user.enabled_status is '状态';
|
|||||||
alter table sys_user
|
alter table sys_user
|
||||||
owner to postgres;
|
owner to postgres;
|
||||||
|
|
||||||
CREATE TABLE sys_user_message
|
create table sys_user_message
|
||||||
(
|
(
|
||||||
id bigserial NOT NULL
|
id bigint not null
|
||||||
CONSTRAINT sys_user_message_pk
|
constraint sys_user_message_pk
|
||||||
PRIMARY KEY,
|
primary key,
|
||||||
user_id bigint NOT NULL,
|
user_id bigint not null,
|
||||||
message_id bigint NOT NULL,
|
message_id bigint not null,
|
||||||
is_read boolean NOT NULL,
|
is_read boolean not null,
|
||||||
read_time timestamp
|
read_time timestamp
|
||||||
);
|
);
|
||||||
|
comment on table sys_user_message is '用户消息';
|
||||||
COMMENT ON TABLE sys_user_message IS '用户消息';
|
comment on column sys_user_message.id is '主键';
|
||||||
COMMENT ON COLUMN sys_user_message.id IS '主键';
|
comment on column sys_user_message.user_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.message_id IS '消息';
|
comment on column sys_user_message.is_read is '是否已读';
|
||||||
COMMENT ON COLUMN sys_user_message.is_read IS '是否已读';
|
comment on column sys_user_message.read_time is '阅读时间';
|
||||||
COMMENT ON COLUMN sys_user_message.read_time IS '阅读时间';
|
alter table sys_user_message
|
||||||
|
owner to postgres;
|
||||||
ALTER TABLE sys_user_message
|
|
||||||
OWNER TO postgres;
|
|
||||||
|
|
||||||
-- 确保序列从1开始
|
|
||||||
SELECT setval('sys_user_message_id_seq', 1, false);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
create table sys_users_roles
|
create table sys_users_roles
|
||||||
(
|
(
|
||||||
@ -464,12 +457,20 @@ VALUES (1, TRUE, FALSE),
|
|||||||
(10, FALSE, TRUE);
|
(10, FALSE, TRUE);
|
||||||
|
|
||||||
INSERT INTO attachment (id, file_name, mime_type, url, upload_time)
|
INSERT INTO attachment (id, file_name, mime_type, url, upload_time)
|
||||||
VALUES ('1', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf', CURRENT_TIMESTAMP),
|
VALUES ('8', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf',
|
||||||
('2', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '1 day'),
|
CURRENT_TIMESTAMP - INTERVAL '1 day'),
|
||||||
('3', 'presentation.pptx', 'application/pptx', 'http://example.com/files/presentation.pptx',
|
('9', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '2 days'),
|
||||||
CURRENT_TIMESTAMP - INTERVAL '2 days'),
|
('10', 'presentation.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||||
('4', 'spreadsheet.xlsx', 'application/xlsx', 'http://example.com/files/spreadsheet.xlsx',
|
'http://example.com/files/presentation.pptx', CURRENT_TIMESTAMP - INTERVAL '3 days'),
|
||||||
CURRENT_TIMESTAMP - INTERVAL '3 days'),
|
('11', 'spreadsheet.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
('5', 'audio.mp3', 'audio/mpeg', 'http://example.com/files/audio.mp3', CURRENT_TIMESTAMP - INTERVAL '4 days');
|
'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');
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.BulletinRepository">
|
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.BulletinRepository">
|
||||||
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
|
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo" autoMapping="true">
|
||||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||||
<result column="title" jdbcType="VARCHAR" property="title"/>
|
<result column="title" jdbcType="VARCHAR" property="title"/>
|
||||||
<result column="state" jdbcType="INTEGER" property="state"/>
|
<result column="state" jdbcType="INTEGER" property="state"/>
|
||||||
@ -18,38 +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="create_by" jdbcType="VARCHAR" property="createBy"/>
|
<collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo">
|
||||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||||
<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="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo"
|
|
||||||
autoMapping="true" columnPrefix="attachment_">
|
|
||||||
<id column="id" jdbcType="VARCHAR" property="attachmentId"/>
|
|
||||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||||
<result column="file_ame" jdbcType="VARCHAR" property="fileName"/>
|
|
||||||
</collection>
|
</collection>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="selectByBulletinId" resultMap="BulletinMap">
|
<select id="selectByBulletinId" resultMap="BulletinMap">
|
||||||
SELECT sb.*, a.id as attachment_id,a.url as attachment_url,a.file_name as attachment_file_name
|
SELECT sb.id AS id,
|
||||||
FROM
|
sb.state AS state,
|
||||||
sys_bulletin sb
|
sb.content AS content,
|
||||||
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
sb.title AS title,
|
||||||
LEFT JOIN attachment a ON a.id = sba.attachment_id
|
sb.top AS top,
|
||||||
<where>
|
sb.remark AS remark,
|
||||||
<if test="bulletinId !=null">
|
sb.close_time AS close_time,
|
||||||
sb.id = #{bulletinId}
|
sb.close_user_id AS close_user_id,
|
||||||
</if>
|
sb.create_by AS create_by,
|
||||||
</where>
|
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" resultMap="BulletinMap">
|
<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.url as attachment_url
|
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.file_name AS file_name,
|
||||||
|
a.url AS url
|
||||||
FROM
|
FROM
|
||||||
sys_bulletin sb
|
sys_bulletin sb
|
||||||
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
LEFT JOIN
|
||||||
LEFT JOIN attachment a ON a.id = sba.attachment_id
|
sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||||
<where>
|
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>
|
||||||
@ -59,7 +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>
|
||||||
</where>
|
|
||||||
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>
|
@ -4,10 +4,14 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository">
|
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository">
|
||||||
<resultMap id="userMessageMap" type="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo">
|
<resultMap id="userMessageMap" type="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo">
|
||||||
<id column="message_id" jdbcType="BIGINT" property="messageId"/>
|
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||||
<result column="is_read" jdbcType="BOOLEAN" property="isRead"/>
|
<result column="is_read" jdbcType="BOOLEAN" property="isRead"/>
|
||||||
<result column="read_time" jdbcType="TIMESTAMP" property="readTime"/>
|
<result column="read_time" jdbcType="TIMESTAMP" property="readTime"/>
|
||||||
<result column="username" jdbcType="VARCHAR" property="username"/>
|
<result column="username" jdbcType="VARCHAR" property="username"/>
|
||||||
|
<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="type" jdbcType="INTEGER" property="type"/>
|
||||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
||||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
||||||
@ -20,39 +24,42 @@
|
|||||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||||
</resultMap>
|
<collection property="attachments" ofType="com.zsc.edu.gateway.modules.attachment.entity.Attachment">
|
||||||
|
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||||
<resultMap id="userMessageAdminMap" type="com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo">
|
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
<result column="mime_type" jdbcType="VARCHAR" property="mimeType"/>
|
||||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
<result column="upload_time" jdbcType="TIMESTAMP" property="uploadTime"/>
|
||||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
</collection>
|
||||||
<result column="sms" jdbcType="BOOLEAN" property="sms"/>
|
|
||||||
<result column="html" jdbcType="BOOLEAN" property="html"/>
|
|
||||||
<result column="title" jdbcType="VARCHAR" property="title"/>
|
|
||||||
<result column="content" jdbcType="VARCHAR" property="content"/>
|
|
||||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
|
||||||
<result column="user_count" jdbcType="INTEGER" property="userCount"/>
|
|
||||||
<result column="read_count" jdbcType="INTEGER" property="readCount"/>
|
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="selectByMessageIdAndUserId" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo"
|
<select id="selectByMessageIdAndUserId" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo"
|
||||||
resultMap="userMessageMap">
|
resultMap="userMessageMap">
|
||||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name
|
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.*
|
||||||
from sys_user_message sum
|
from sys_user_message sum
|
||||||
left join sys_user su on sum.user_id = su.id
|
left join sys_user su on sum.id=su.id
|
||||||
left join sys_message sm on sm.id = sum.message_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
|
||||||
<where>
|
<where>
|
||||||
sm.id=#{messageId}
|
sm.id=#{messageId}
|
||||||
and su.id=#{userId}
|
and su.id=#{userId}
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="page" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
<select id="query" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
||||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name
|
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.*
|
||||||
from sys_user_message sum
|
from sys_user_message sum
|
||||||
left join sys_user su on sum.user_id = su.id
|
left join sys_user su on sum.id=su.id
|
||||||
left join sys_message sm on sm.id = sum.message_id
|
left join sys_message sm on sm.id=sum.id
|
||||||
<where>
|
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">
|
<if test="query.userId != null">
|
||||||
AND sum.user_id = #{query.userId}
|
AND sum.user_id = #{query.userId}
|
||||||
</if>
|
</if>
|
||||||
@ -74,36 +81,7 @@
|
|||||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
|
||||||
ORDER BY
|
ORDER BY
|
||||||
sm.create_time DESC
|
sm.create_time DESC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="pageAdmin" resultMap="userMessageAdminMap">
|
|
||||||
SELECT
|
|
||||||
sm.*, -- 获取消息详情
|
|
||||||
COUNT(DISTINCT sum.user_id) AS user_count, -- 统计用户的关联数量
|
|
||||||
SUM(CASE WHEN sum.is_read = true THEN 1 ELSE 0 END) AS read_count -- 统计已读数量
|
|
||||||
FROM
|
|
||||||
sys_user_message sum
|
|
||||||
LEFT JOIN
|
|
||||||
sys_user su ON sum.user_id = su.id
|
|
||||||
LEFT JOIN
|
|
||||||
sys_message sm ON sm.id = sum.message_id
|
|
||||||
GROUP BY
|
|
||||||
sm.id
|
|
||||||
<where>
|
|
||||||
<if test="query.userId != null">
|
|
||||||
AND sum.user_id = #{query.userId}
|
|
||||||
</if>
|
|
||||||
<if test="query.title != null and query.title != ''">
|
|
||||||
AND sm.title LIKE CONCAT('%', #{query.title}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
|
||||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
@ -1,33 +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">
|
||||||
<resultMap id="deptMap" type="com.zsc.edu.gateway.modules.system.entity.Dept">
|
SELECT d.*, u.*
|
||||||
<id column="id" property="id"/>
|
FROM sys_dept d
|
||||||
<result column="sub_count" property="subCount"/>
|
LEFT JOIN sys_user u ON d.id = u.dept_id
|
||||||
<result column="pid" property="pid"/>
|
|
||||||
<result column="name" property="name"/>
|
|
||||||
<result column="dept_sort" property="deptSort"/>
|
|
||||||
<collection
|
|
||||||
property="members"
|
|
||||||
ofType="com.zsc.edu.gateway.modules.system.vo.UserVo"
|
|
||||||
autoMapping="true"
|
|
||||||
columnPrefix="members_"
|
|
||||||
>
|
|
||||||
<id column="id" jdbcType="BIGINT" property="userId"/>
|
|
||||||
<result column="username" jdbcType="VARCHAR" property="username"/>
|
|
||||||
<result column="email" jdbcType="VARCHAR" property="email"/>
|
|
||||||
<result column="phone" jdbcType="VARCHAR" property="phone"/>
|
|
||||||
</collection>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<select id="selectDeptTree" resultMap="deptMap">
|
|
||||||
SELECT sd.*,
|
|
||||||
su.id as members_id,
|
|
||||||
su.username as members_username,
|
|
||||||
su.email as members_email,
|
|
||||||
su.phone as members_phone
|
|
||||||
FROM sys_dept sd
|
|
||||||
left join sys_user su on sd.id = su.dept_id
|
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
@ -28,7 +28,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@WebMvcTest(RoleController.class)
|
@WebMvcTest(RoleController.class)
|
||||||
public class RoleControllerTest extends MockMvcConfigBase {
|
public class RoleControllerTest extends MockMvcConfigBase {
|
||||||
//TODO 公告部分测试
|
|
||||||
private static Role role1;
|
private static Role role1;
|
||||||
|
|
||||||
private static Role role2;
|
private static Role role2;
|
||||||
|
@ -1,89 +1,89 @@
|
|||||||
package com.zsc.edu.gateway.service;
|
//package com.zsc.edu.gateway.service;
|
||||||
|
//
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.zsc.edu.gateway.domain.BulletinBuilder;
|
//import com.zsc.edu.gateway.domain.BulletinBuilder;
|
||||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
//import com.zsc.edu.gateway.exception.ConstraintException;
|
||||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
//import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
//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.Bulletin;
|
||||||
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.BulletinService;
|
//import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||||
import jakarta.annotation.Resource;
|
//import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
//import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
//import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
//import org.junit.jupiter.api.Test;
|
||||||
|
//
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
//import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
//
|
||||||
public class BulletinServiceTest {
|
//public class BulletinServiceTest {
|
||||||
@Resource
|
// @Resource
|
||||||
private BulletinService service;
|
// private BulletinService service;
|
||||||
@Resource
|
// @Resource
|
||||||
private BulletinRepository repo;
|
// private BulletinRepository repo;
|
||||||
|
//
|
||||||
Bulletin bulletin1;
|
// Bulletin bulletin1;
|
||||||
Bulletin bulletin2;
|
// Bulletin bulletin2;
|
||||||
|
//
|
||||||
@BeforeEach
|
// @BeforeEach
|
||||||
void setUp() {
|
// void setUp() {
|
||||||
bulletin1 = BulletinBuilder.bBulletin().title("测试1").build();
|
// bulletin1 = BulletinBuilder.bBulletin().title("测试1").build();
|
||||||
repo.insert(bulletin1);
|
// repo.insert(bulletin1);
|
||||||
bulletin2 = BulletinBuilder.bBulletin().title("测试2").build();
|
// bulletin2 = BulletinBuilder.bBulletin().title("测试2").build();
|
||||||
repo.insert(bulletin2);
|
// repo.insert(bulletin2);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
void list() {
|
// void list() {
|
||||||
LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
// LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
// assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
||||||
assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
// assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
||||||
assertEquals(2, service.list().size());
|
// assertEquals(2, service.list().size());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
void createBulletin() {
|
// void createBulletin() {
|
||||||
BulletinDto dto = new BulletinDto();
|
// BulletinDto dto = new BulletinDto();
|
||||||
dto.setTitle("测试");
|
// dto.setTitle("测试");
|
||||||
dto.setTop(true);
|
// dto.setTop(true);
|
||||||
dto.setContent("测试测试");
|
// dto.setContent("测试测试");
|
||||||
dto.setRemark("测试公告增加");
|
// dto.setRemark("测试公告增加");
|
||||||
BulletinDto dto2 = new BulletinDto();
|
// BulletinDto dto2 = new BulletinDto();
|
||||||
dto2.setTitle(bulletin2.getTitle());
|
// dto2.setTitle(bulletin2.getTitle());
|
||||||
// dto2.setTop(bulletin2.isTop());
|
//// dto2.setTop(bulletin2.isTop());
|
||||||
dto2.setRemark(bulletin2.getRemark());
|
// dto2.setRemark(bulletin2.getRemark());
|
||||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
// UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||||
userDetails.setUsername("admin");
|
// userDetails.setUsername("admin");
|
||||||
Bulletin bulletin = service.create(userDetails, dto);
|
// Bulletin bulletin=service.create(userDetails,dto);
|
||||||
assertNotNull(bulletin.getId());
|
// assertNotNull(bulletin.getId());
|
||||||
List<Bulletin> list = service.list();
|
// List<Bulletin> list = service.list();
|
||||||
assertEquals(3, list.size());
|
// assertEquals(3, list.size());
|
||||||
// 不能创建其他已存在标题公告
|
// // 不能创建其他已存在标题公告
|
||||||
assertThrows(ConstraintException.class, () -> service.create(userDetails, dto2));
|
// assertThrows(ConstraintException.class, () -> service.create(userDetails,dto2));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
void updateBulletin() {
|
// void updateBulletin() {
|
||||||
BulletinDto dto = new BulletinDto();
|
// BulletinDto dto = new BulletinDto();
|
||||||
dto.setTitle("测试3");
|
// dto.setTitle("测试3");
|
||||||
dto.setContent("测试测");
|
// dto.setContent("测试测");
|
||||||
dto.setTop(true);
|
// dto.setTop(true);
|
||||||
dto.setRemark("测试公告更新");
|
// dto.setRemark("测试公告更新");
|
||||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
// UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||||
userDetails.setUsername("admin");
|
// userDetails.setUsername("admin");
|
||||||
assertTrue(service.update(userDetails, dto, bulletin2.id));
|
// assertTrue(service.update(userDetails,dto, bulletin2.id));
|
||||||
Bulletin bulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
// Bulletin bulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
||||||
assertEquals(bulletin.getTitle(), dto.getTitle());
|
// assertEquals(bulletin.getTitle(), dto.getTitle());
|
||||||
assertEquals(bulletin.getId(), bulletin2.id);
|
// assertEquals(bulletin.getId(), bulletin2.id);
|
||||||
// 不能改为其他已存在的同名同代码部门
|
// // 不能改为其他已存在的同名同代码部门
|
||||||
// assertThrows(ConstraintException.class,
|
// assertThrows(ConstraintException.class,
|
||||||
// () -> service.update(userDetails,new BulletinDto(bulletin1.getTitle(),true,null,null), bulletin2.id));
|
// () -> service.update(userDetails,new BulletinDto(bulletin1.getTitle(),true,null,null), bulletin2.id));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@AfterEach
|
// @AfterEach
|
||||||
void tearDown() {
|
// void tearDown() {
|
||||||
repo.delete(new QueryWrapper<>());
|
// repo.delete(new QueryWrapper<>());
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -14,6 +14,7 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author ftz
|
* @author ftz
|
||||||
* 创建时间:29/12/2023 上午11:21
|
* 创建时间:29/12/2023 上午11:21
|
||||||
|
* 描述: TODO
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
|
Loading…
Reference in New Issue
Block a user