Compare commits
11 Commits
master
...
feature/de
Author | SHA1 | Date | |
---|---|---|---|
8da7e6a32a | |||
396dfc5d2c | |||
6fd1c6b81d | |||
528318ff0a | |||
e535b745ea | |||
30338520cf | |||
dbbc9e82db | |||
8521262f69 | |||
13372326c0 | |||
8706f58ebb | |||
8d6fa0b244 |
@ -6,12 +6,16 @@ import java.util.List;
|
||||
|
||||
public interface BaseMapper<D, E> {
|
||||
D toDto(E entity);
|
||||
|
||||
E toEntity(D dto);
|
||||
|
||||
List<D> toDto(List<E> entityList);
|
||||
|
||||
List<E> toEntity(List<D> dtoList);
|
||||
|
||||
/**
|
||||
* 更新实体类
|
||||
*
|
||||
* @param dto
|
||||
* @param entity
|
||||
*/
|
||||
|
130
src/main/java/com/zsc/edu/gateway/common/util/TreeUtil.java
Normal file
130
src/main/java/com/zsc/edu/gateway/common/util/TreeUtil.java
Normal file
@ -0,0 +1,130 @@
|
||||
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,6 +65,7 @@ public class ApiExceptionHandler {
|
||||
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
//TODO 跟全局security 冲突
|
||||
@ExceptionHandler(value = {Exception.class})
|
||||
public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
|
||||
log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
|
||||
|
@ -1,66 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.zsc.edu.gateway.framework.common.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
|
||||
public enum EnableState implements IEnum<Boolean> {
|
||||
ENABLE(Boolean.TRUE),
|
||||
DISABLE(Boolean.FALSE);
|
||||
|
||||
private boolean value;
|
||||
|
||||
EnableState(Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public EnableState reverse() {
|
||||
return this == ENABLE ? DISABLE : ENABLE;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.zsc.edu.gateway.framework.common.enums;
|
||||
|
||||
|
||||
import com.zsc.edu.gateway.exception.StateException;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface IState<T extends Enum<T>> {
|
||||
|
||||
/**
|
||||
* 用于检查对象当前状态是否等于correctStatus
|
||||
*
|
||||
* @param correctState 正确状态
|
||||
*/
|
||||
default void checkStatus(T correctState) {
|
||||
if (this != correctState) {
|
||||
throw new StateException(correctState.getClass(), this, correctState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于检查对象当前状态是否在集合correctStates中
|
||||
*
|
||||
* @param correctStates 正确状态集合
|
||||
*/
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
default void checkStatus(EnumSet<T> correctStates) {
|
||||
if (!correctStates.contains(this)) {
|
||||
throw new StateException(this.getClass(), this, correctStates);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.zsc.edu.gateway.framework.common.mapstruct;
|
||||
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BaseMapper<D, E> {
|
||||
D toDto(E entity);
|
||||
E toEntity(D dto);
|
||||
List<D> toDto(List<E> entityList);
|
||||
List<E> toEntity(List<D> dtoList);
|
||||
|
||||
/**
|
||||
* 更新实体类
|
||||
* @param dto
|
||||
* @param entity
|
||||
*/
|
||||
void convert(D dto, @MappingTarget E entity);
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package com.zsc.edu.gateway.framework.common.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @Description: 树操作方法工具类
|
||||
* @Copyright: Copyright (c) 赵侠客
|
||||
* @Date: 2024-07-22 10:42
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class TreeUtil {
|
||||
|
||||
/**
|
||||
* 将list合成树
|
||||
*
|
||||
* @param list 需要合成树的List
|
||||
* @param rootCheck 判断E中为根节点的条件,如:x->x.getPId()==-1L , x->x.getParentId()==null,x->x.getParentMenuId()==0
|
||||
* @param parentCheck 判断E中为父节点条件,如:(x,y)->x.getId().equals(y.getPId())
|
||||
* @param setSubChildren E中设置下级数据方法,如:Menu::setSubMenus
|
||||
* @param <E> 泛型实体对象
|
||||
* @return 合成好的树
|
||||
*/
|
||||
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
|
||||
return list.stream().filter(rootCheck).peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将树打平成tree
|
||||
*
|
||||
* @param tree 需要打平的树
|
||||
* @param getSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param setSubChildren 将下级数据置空方法,如:x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
* @return 打平后的数据
|
||||
*/
|
||||
public static <E> List<E> flat(List<E> tree, Function<E, List<E>> getSubChildren, Consumer<E> setSubChildren) {
|
||||
List<E> res = new ArrayList<>();
|
||||
forPostOrder(tree, item -> {
|
||||
setSubChildren.accept(item);
|
||||
res.add(item);
|
||||
}, getSubChildren);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前序遍历
|
||||
*
|
||||
* @param tree 需要遍历的树
|
||||
* @param consumer 遍历后对单个元素的处理方法,如:x-> System.out.println(x)、 System.out::println打印元素
|
||||
* @param setSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
*/
|
||||
public static <E> void forPreOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
|
||||
for (E l : tree) {
|
||||
consumer.accept(l);
|
||||
List<E> es = setSubChildren.apply(l);
|
||||
if (es != null && es.size() > 0) {
|
||||
forPreOrder(es, consumer, setSubChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 层序遍历
|
||||
*
|
||||
* @param tree 需要遍历的树
|
||||
* @param consumer 遍历后对单个元素的处理方法,如:x-> System.out.println(x)、 System.out::println打印元素
|
||||
* @param setSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
*/
|
||||
public static <E> void forLevelOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
|
||||
Queue<E> queue = new LinkedList<>(tree);
|
||||
while (!queue.isEmpty()) {
|
||||
E item = queue.poll();
|
||||
consumer.accept(item);
|
||||
List<E> childList = setSubChildren.apply(item);
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
queue.addAll(childList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后序遍历
|
||||
*
|
||||
* @param tree 需要遍历的树
|
||||
* @param consumer 遍历后对单个元素的处理方法,如:x-> System.out.println(x)、 System.out::println打印元素
|
||||
* @param setSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
*/
|
||||
public static <E> void forPostOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
|
||||
for (E item : tree) {
|
||||
List<E> childList = setSubChildren.apply(item);
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
forPostOrder(childList, consumer, setSubChildren);
|
||||
}
|
||||
consumer.accept(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对树所有子节点按comparator排序
|
||||
*
|
||||
* @param tree 需要排序的树
|
||||
* @param comparator 排序规则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());
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
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 {
|
||||
helper.setText(message.content);
|
||||
}
|
||||
if (Objects.nonNull(message.attachments)) {
|
||||
for (Attachment attachment : message.attachments) {
|
||||
helper.addAttachment(attachment.fileName, attachmentService.loadAsResource(attachment.id), attachment.mimeType);
|
||||
}
|
||||
}
|
||||
// if (Objects.nonNull(message.attachments)) {
|
||||
// for (Attachment attachment : message.attachments) {
|
||||
// helper.addAttachment(attachment.fileName, attachmentService.loadAsResource(attachment.id), attachment.mimeType);
|
||||
// }
|
||||
// }
|
||||
sender.send(mimeMessage);
|
||||
} catch (MessagingException | IOException | TemplateException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -0,0 +1,93 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,265 @@
|
||||
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,6 +8,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.ProviderManager;
|
||||
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.core.session.SessionRegistry;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
@ -23,6 +24,8 @@ import javax.sql.DataSource;
|
||||
* @author harry_yao
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
//@EnableMethodSecurity
|
||||
//TODO 加入全局注解会报错
|
||||
@Configuration
|
||||
public class SpringSecurityConfig {
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.zsc.edu.gateway.framework.security;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.zsc.edu.gateway.common.enums.EnableState;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||
|
@ -77,6 +77,11 @@ public class AttachmentController {
|
||||
public Attachment getAttachmentInfo(@PathVariable("id") String id) {
|
||||
return service.getById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传附件
|
||||
*/
|
||||
@PostMapping("uploadMultipleFiles")
|
||||
public List<Attachment> uploadMultipleFiles(
|
||||
@RequestParam(defaultValue = "其他") Attachment.Type type,
|
||||
@ -91,4 +96,11 @@ public class AttachmentController {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据附件ID删除附件信息
|
||||
*/
|
||||
@DeleteMapping("delete/{id}")
|
||||
public Boolean delete(@PathVariable("id") String id) {
|
||||
return service.delete(id);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,13 @@ package com.zsc.edu.gateway.modules.attachment.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author ftz
|
||||
* 创建时间:29/1/2024 上午9:55
|
||||
* 描述: TODO
|
||||
*/
|
||||
public interface AttachmentRepository extends BaseMapper<Attachment>{
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fantianzhi
|
||||
@ -20,4 +21,8 @@ public interface AttachmentService extends IService<Attachment> {
|
||||
Resource loadAsResource(String id);
|
||||
|
||||
Attachment.Wrapper loadAsWrapper(String id);
|
||||
|
||||
List<Attachment> selectList(List<String> dis);
|
||||
|
||||
Boolean delete(String id);
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import com.zsc.edu.gateway.framework.storage.exception.StorageFileNotFoundExcept
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.repo.AttachmentRepository;
|
||||
import com.zsc.edu.gateway.modules.attachment.service.AttachmentService;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinAttachmentRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinAttachmentService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
@ -42,11 +45,13 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
||||
private final AttachmentRepository repo;
|
||||
private final Path attachmentPath;
|
||||
private final Path tempPath;
|
||||
private final BulletinAttachmentRepository bulletin;
|
||||
|
||||
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties) {
|
||||
public AttachmentServiceImpl(AttachmentRepository repo, StorageProperties storageProperties, BulletinAttachmentService bulletinAttachmentService, BulletinAttachmentRepository bulletin) {
|
||||
this.repo = repo;
|
||||
this.attachmentPath = Paths.get(storageProperties.attachment);
|
||||
this.tempPath = Paths.get(storageProperties.temp);
|
||||
this.bulletin = bulletin;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@ -201,4 +206,19 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentRepository, Att
|
||||
return attachment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Attachment> selectList(List<String> dis) {
|
||||
return repo.selectList(new LambdaQueryWrapper<Attachment>().in(Attachment::getId, dis));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(String id) {
|
||||
LambdaQueryWrapper<BulletinAttachment> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BulletinAttachment::getAttachmentId, id);
|
||||
List<BulletinAttachment> bulletinAttachments = bulletin.selectList(wrapper);
|
||||
if (!bulletinAttachments.isEmpty()) {
|
||||
bulletin.delete(wrapper);
|
||||
}
|
||||
return removeById(id);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,16 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class AttachmentVo {
|
||||
public String fileName;
|
||||
/**
|
||||
* 附件ID
|
||||
*/
|
||||
public String attachmentId;
|
||||
/**
|
||||
* 附件地址
|
||||
*/
|
||||
public String url;
|
||||
/**
|
||||
* 附件名称
|
||||
*/
|
||||
public String fileName;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@GetMapping("/self/{id}")
|
||||
public List<BulletinVo> selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
public BulletinVo selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
return service.detail(userDetails,id, Bulletin.State.publish);
|
||||
}
|
||||
|
||||
@ -45,10 +45,9 @@ public class BulletinController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping("/self")
|
||||
public IPage<BulletinVo> getBulletins( BulletinQuery query) {
|
||||
public IPage<BulletinVo> getBulletins(Page<BulletinVo> pageParam, BulletinQuery query) {
|
||||
query.setState(Bulletin.State.publish);
|
||||
Page<BulletinVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
return service.selectPageByConditions(page, query);
|
||||
return service.selectPageByConditions(pageParam, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +58,7 @@ public class BulletinController {
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('BULLETIN_QUERY')")
|
||||
public List<BulletinVo> detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
public BulletinVo detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
return service.detail(userDetails,id, null);
|
||||
}
|
||||
|
||||
@ -150,15 +149,7 @@ public class BulletinController {
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('BULLETIN_DELETE')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
return service.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*为公告添加附件
|
||||
*/
|
||||
@PostMapping("/{id}/add")
|
||||
@PreAuthorize("hasAuthority('BULLETIN_CREATE')")
|
||||
public Boolean insertInto(@PathVariable Long id,@RequestBody Set<String> attachments){
|
||||
return service.insertInto(id, attachments);
|
||||
}
|
||||
}
|
||||
|
@ -4,19 +4,17 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessagePayload;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户消息Controller
|
||||
@ -50,11 +48,10 @@ public class UserMessageController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping("/self")
|
||||
public IPage<UserMessageVo> selfPage(@AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
||||
public IPage<UserMessageVo> selfPage(Page<UserMessageVo> pageParam, @AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
||||
query.userId = userDetails.id;
|
||||
query.name = null;
|
||||
Page<UserMessageVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
return service.page(page, query);
|
||||
return service.page(pageParam, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,14 +80,13 @@ public class UserMessageController {
|
||||
/**
|
||||
* 管理查询消息详情
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param messageId 消息ID
|
||||
* @return 用户消息详情
|
||||
*/
|
||||
@GetMapping("/{userId}/{messageId}")
|
||||
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||
public UserMessageVo detail(@PathVariable("userId") Long userId, @PathVariable("messageId") Long messageId) {
|
||||
return service.detail(messageId, userId);
|
||||
return service.detail(userId, messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,9 +97,8 @@ public class UserMessageController {
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||
public IPage<UserMessageVo> page(UserMessageQuery query) {
|
||||
Page<UserMessageVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
return service.page(page, query);
|
||||
public IPage<AdminMessageVo> page(Page<UserMessageVo> page, AdminMessageQuery query) {
|
||||
return service.getAdminMessagePage(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,41 +112,4 @@ public class UserMessageController {
|
||||
public Boolean create(@RequestBody UserMessageDto 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;
|
||||
//
|
||||
// /**
|
||||
// * 附件ID集合
|
||||
// */
|
||||
// private List<String> attachmentIds;
|
||||
|
||||
/**
|
||||
* 附件ID集合
|
||||
*/
|
||||
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.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
import com.zsc.edu.gateway.framework.common.enums.IState;
|
||||
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import lombok.*;
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_bulletin_user")
|
||||
public class BulletinUser {
|
||||
|
||||
/**
|
||||
* 公告ID
|
||||
*/
|
||||
public Long bulletinId;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
public Long userId;
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
public Boolean isRead = true;
|
||||
}
|
@ -30,7 +30,7 @@ public class Message extends BaseEntity {
|
||||
/**
|
||||
* 是否系统生成
|
||||
*/
|
||||
public Boolean system;
|
||||
public Boolean system = false;
|
||||
|
||||
/**
|
||||
* 是否需要发送邮件
|
||||
@ -57,9 +57,4 @@ public class Message extends BaseEntity {
|
||||
*/
|
||||
public String content;
|
||||
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
public List<Attachment> attachments;
|
||||
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
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;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
import com.zsc.edu.gateway.framework.common.enums.IState;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -0,0 +1,14 @@
|
||||
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> {
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
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,16 +57,13 @@ public class UserMessageQuery {
|
||||
/**
|
||||
* 消息创建时间区间起始
|
||||
*/
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
public LocalDateTime createAtBegin;
|
||||
|
||||
/**
|
||||
* 消息创建时间区间终止
|
||||
*/
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
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> {
|
||||
|
||||
|
||||
List<BulletinVo> selectByBulletinId(@Param("bulletinId") Long bulletinId);
|
||||
BulletinVo selectByBulletinId(@Param("bulletinId") Long bulletinId);
|
||||
|
||||
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, @Param("query") BulletinQuery query);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.zsc.edu.gateway.modules.notice.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface BulletinUserRepository extends BaseMapper<BulletinUser> {
|
||||
|
||||
// @Select("select * from sys_bulletin_user sbu where sbu.bulletin_id=#{bulletinId} and sbu.user_id=#{userId}")
|
||||
// Boolean selectByBulletinIdAndUserId(@Param("bulletinId") Long bulletinId, @Param("userId") Long userId);
|
||||
}
|
@ -1,18 +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.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.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
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.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@ -16,7 +16,10 @@ import org.apache.ibatis.annotations.Param;
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface UserMessageRepository extends BaseMapper<UserMessage> {
|
||||
|
||||
UserMessageVo selectByMessageIdAndUserId(@Param("messageId") Long messageId, @Param("userId") Long userId);
|
||||
|
||||
IPage<UserMessageVo> query(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
||||
|
||||
IPage<AdminMessageVo> pageAdmin(Page<UserMessageVo> page, @Param("query") AdminMessageQuery query);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
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.PageDto;
|
||||
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.vo.BulletinVo;
|
||||
@ -21,7 +20,7 @@ import java.util.Set;
|
||||
|
||||
public interface BulletinService extends IService<Bulletin> {
|
||||
|
||||
List<BulletinVo> detail(UserDetailsImpl userDetails, Long id, Bulletin.State state);
|
||||
BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state);
|
||||
|
||||
Bulletin create(UserDetailsImpl userDetails, BulletinDto dto);
|
||||
|
||||
@ -33,7 +32,7 @@ public interface BulletinService extends IService<Bulletin> {
|
||||
|
||||
Boolean close(UserDetailsImpl userDetails,Long id);
|
||||
|
||||
Boolean insertInto(Long bulletinId, Set<String> attachmentIds);
|
||||
|
||||
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query);
|
||||
|
||||
Boolean delete(Long id);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
public interface BulletinUserService extends IService<BulletinUser> {
|
||||
|
||||
Boolean isRead(UserDetailsImpl userDetails, Long id);
|
||||
|
||||
void toggleIsRead(Long id);
|
||||
}
|
@ -5,18 +5,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessagePayload;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
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.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
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.Set;
|
||||
|
||||
/**
|
||||
* 用户消息Service
|
||||
@ -29,17 +24,12 @@ public interface UserMessageService extends IService<UserMessage> {
|
||||
|
||||
UserMessageVo detail(Long messageId, Long userId);
|
||||
|
||||
Boolean insertInto(Long messageId, List<String> attachmentIds);
|
||||
|
||||
List<MessageSetting> getSetting();
|
||||
|
||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query);
|
||||
|
||||
Integer countUnread(UserDetailsImpl userDetails);
|
||||
|
||||
Integer markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||
|
||||
@Transactional
|
||||
List<MessageSetting> saveSetting(List<MessageSetting> settings);
|
||||
|
||||
IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinAttachmentRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinAttachmentService;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
@ -39,6 +40,7 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
private final BulletinRepository repo;
|
||||
private final BulletinAttachmentService bulletinAttachmentService;
|
||||
private final UserRepository userRepository;
|
||||
private final BulletinAttachmentRepository bulletinAttachmentRepository;
|
||||
/**
|
||||
* 查询公告详情
|
||||
*
|
||||
@ -47,21 +49,15 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
* @return 公告详情
|
||||
*/
|
||||
@Override
|
||||
public List<BulletinVo> detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) {
|
||||
List<BulletinVo> bulletins = repo.selectByBulletinId(id);
|
||||
if (bulletins.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
public BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) {
|
||||
BulletinVo bulletinVo = repo.selectByBulletinId(id);
|
||||
if (state != null) {
|
||||
bulletinVo.getState().checkStatus(state);
|
||||
}
|
||||
for (BulletinVo bulletin : bulletins) {
|
||||
if (state != null) {
|
||||
bulletin.getState().checkStatus(state);
|
||||
}
|
||||
bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId()));
|
||||
bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId()));
|
||||
bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId()));
|
||||
}
|
||||
|
||||
return bulletins;
|
||||
bulletinVo.setEditUsername(userRepository.selectNameById(bulletinVo.getEditUserId()));
|
||||
bulletinVo.setPublishUsername(userRepository.selectNameById(bulletinVo.getPublishUserId()));
|
||||
bulletinVo.setCloseUsername(userRepository.selectNameById(bulletinVo.getCloseUserId()));
|
||||
return bulletinVo;
|
||||
}
|
||||
/**
|
||||
* 新建公告
|
||||
@ -82,6 +78,9 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
bulletin.setCreateBy(userDetails.getName());
|
||||
bulletin.setEditUserId(userDetails.getId());
|
||||
save(bulletin);
|
||||
if (dto.getAttachmentIds() != null) {
|
||||
insertInto(bulletin.getId(), dto.getAttachmentIds());
|
||||
}
|
||||
return bulletin;
|
||||
}
|
||||
/**
|
||||
@ -183,15 +182,13 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
* @param attachmentIds attachments
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertInto(Long bulletinId, Set<String> attachmentIds) {
|
||||
public Boolean insertInto(Long bulletinId, List<String> attachmentIds) {
|
||||
List<BulletinAttachment> bulletinAttachments = attachmentIds.stream()
|
||||
.map(attachmentId -> new BulletinAttachment(bulletinId, attachmentId))
|
||||
.collect(Collectors.toList());
|
||||
return bulletinAttachmentService.saveBatch(bulletinAttachments);
|
||||
}
|
||||
|
||||
|
||||
private List<Bulletin> getBulletinsByIds(List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
@ -205,4 +202,15 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
public IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query) {
|
||||
return baseMapper.selectPageByConditions(page, query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(Long id) {
|
||||
LambdaQueryWrapper<BulletinAttachment> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(BulletinAttachment::getAttachmentId, id);
|
||||
List<BulletinAttachment> bulletinAttachments = bulletinAttachmentRepository.selectList(queryWrapper);
|
||||
if (!bulletinAttachments.isEmpty()) {
|
||||
bulletinAttachmentRepository.delete(queryWrapper);
|
||||
}
|
||||
return removeById(id);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinUser;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinUserRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinUserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class BulletinUserServiceImpl extends ServiceImpl<BulletinUserRepository, BulletinUser> implements BulletinUserService {
|
||||
|
||||
/**
|
||||
* 已读公告,每次已读自动获取用户id与公告id加入联表
|
||||
*
|
||||
* @param userDetails userDetails
|
||||
* @param id id
|
||||
* return true
|
||||
*/
|
||||
@Override
|
||||
public Boolean isRead(UserDetailsImpl userDetails, Long id) {
|
||||
if (id == null || userDetails.getId() == null) {
|
||||
throw new IllegalArgumentException("Bulletin ID and User ID cannot be null");
|
||||
}
|
||||
QueryWrapper<BulletinUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("bulletin_id", id)
|
||||
.eq("user_id", userDetails.getId());
|
||||
BulletinUser existingUser = getOne(queryWrapper);
|
||||
if (existingUser == null) {
|
||||
BulletinUser newUser = new BulletinUser();
|
||||
newUser.setBulletinId(id);
|
||||
newUser.setUserId(userDetails.getId());
|
||||
newUser.setIsRead(false);
|
||||
save(newUser);
|
||||
} else {
|
||||
UpdateWrapper<BulletinUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("bulletin_id", id).eq("user_id", userDetails.getId()).set("is_read", false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新公告后修改已读状态
|
||||
*
|
||||
* @param id id
|
||||
*/
|
||||
@Override
|
||||
public void toggleIsRead(Long id) {
|
||||
UpdateWrapper<BulletinUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("bulletin_id", id).set("is_read", true);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -9,18 +10,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.framework.message.email.EmailSender;
|
||||
import com.zsc.edu.gateway.framework.message.sms.SmsSender;
|
||||
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.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.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.service.MessageAttachmentService;
|
||||
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.system.entity.User;
|
||||
import com.zsc.edu.gateway.modules.system.service.UserService;
|
||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -42,14 +44,12 @@ import java.util.stream.Collectors;
|
||||
public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, UserMessage> implements UserMessageService {
|
||||
|
||||
private final MessageRepository messageRepo;
|
||||
private final MessageSettingRepository messageSettingRepo;
|
||||
private final UserService userService;
|
||||
private final AttachmentService attachmentService;
|
||||
private final EmailSender emailSender;
|
||||
private final SmsSender smsSender;
|
||||
private final UserMessageRepository userMessageRepository;
|
||||
private final MessageAttachmentService messageAttachmentService;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final MessageMapper messageMapper;
|
||||
/**
|
||||
* 查询消息详情
|
||||
*
|
||||
@ -60,6 +60,14 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
|
||||
@Override
|
||||
public UserMessageVo detail(Long messageId, Long userId) {
|
||||
if (userMessageRepository.selectByMessageIdAndUserId(messageId, userId) == null) {
|
||||
UserMessage userMessage = new UserMessage();
|
||||
userMessage.setUserId(userId);
|
||||
userMessage.setMessageId(messageId);
|
||||
userMessage.setIsRead(true);
|
||||
userMessage.setReadTime(LocalDateTime.now());
|
||||
save(userMessage);
|
||||
}
|
||||
return userMessageRepository.selectByMessageIdAndUserId(messageId, userId);
|
||||
}
|
||||
|
||||
@ -72,7 +80,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
*/
|
||||
@Override
|
||||
public IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query) {
|
||||
return userMessageRepository.query(page, query);
|
||||
return userMessageRepository.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,12 +110,23 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
}
|
||||
UpdateWrapper<UserMessage> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("user_id", userDetails.getId()).in("message_id", messageIds);
|
||||
updateWrapper.set("is_read", false);
|
||||
updateWrapper.set("is_read", true);
|
||||
updateWrapper.set("read_time", LocalDateTime.now());
|
||||
return userMessageRepository.update(updateWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员查询消息列表
|
||||
*
|
||||
* @return 消息设置列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query) {
|
||||
return userMessageRepository.pageAdmin(page, query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员手动创建用户消息并发送
|
||||
*
|
||||
@ -117,72 +136,17 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
@Transactional
|
||||
@Override
|
||||
public Boolean createByAdmin(UserMessageDto dto) {
|
||||
Set<User> users = dto.userIds.stream()
|
||||
.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);
|
||||
Set<User> users = new HashSet<>(userRepository.selectList(new LambdaQueryWrapper<User>().in(User::getId, dto.userIds)));
|
||||
Message message = messageMapper.toEntity(dto);
|
||||
messageRepo.insert(message);
|
||||
Set<UserMessage> userMessages = users.stream()
|
||||
.map(user -> new UserMessage(null, user.getId(), message.getId(), false, null))
|
||||
.map(user -> new UserMessage(null, user.getId(), message.getId(), true, null))
|
||||
.collect(Collectors.toSet());
|
||||
send(users, message);
|
||||
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格式的消息才能以短信方式发送
|
||||
*
|
||||
@ -210,15 +174,15 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
public Boolean createBySystem(Set<User> receivers, MessagePayload payload) {
|
||||
AtomicBoolean email = new AtomicBoolean(false);
|
||||
AtomicBoolean sms = new AtomicBoolean(false);
|
||||
Optional.of(messageSettingRepo.selectById(payload.type)).ifPresent(messageSetting -> {
|
||||
email.set(messageSetting.email);
|
||||
sms.set(messageSetting.sms);
|
||||
Optional.of(messageRepo.selectById(payload.type)).ifPresent(message -> {
|
||||
email.set(message.email);
|
||||
sms.set(message.sms);
|
||||
});
|
||||
Message message = new Message(payload.type, true, email.get(), sms.get(),
|
||||
payload.html, payload.type.name(), payload.content, null);
|
||||
payload.html, payload.type.name(), payload.content);
|
||||
messageRepo.insert(message);
|
||||
Set<UserMessage> userMessages = receivers.stream().map(user ->
|
||||
new UserMessage(null, user.getId(), message.getId(), false, null)).collect(Collectors.toSet());
|
||||
new UserMessage(null, user.getId(), message.getId(), true, null)).collect(Collectors.toSet());
|
||||
send(receivers, message);
|
||||
return saveBatch(userMessages);
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
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,6 +2,7 @@ package com.zsc.edu.gateway.modules.notice.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
@ -11,35 +12,93 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude
|
||||
public class BulletinVo {
|
||||
/**
|
||||
* 公告id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 公告标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 公告属性
|
||||
*/
|
||||
private Bulletin.State state = Bulletin.State.edit;
|
||||
/**
|
||||
* 公告置顶状态
|
||||
*/
|
||||
private Boolean top;
|
||||
/**
|
||||
* 公告编辑者ID
|
||||
*/
|
||||
private Long editUserId;
|
||||
/**
|
||||
* 公告编辑者名称
|
||||
*/
|
||||
private String editUsername;
|
||||
/**
|
||||
* 公告编辑时间
|
||||
*/
|
||||
private LocalDateTime editTime;
|
||||
/**
|
||||
* 公告发布者ID
|
||||
*/
|
||||
private Long publishUserId;
|
||||
/**
|
||||
* 公告发布者名称
|
||||
*/
|
||||
private String publishUsername;
|
||||
/**
|
||||
* 公告发布时间
|
||||
*/
|
||||
private LocalDateTime publishTime;
|
||||
/**
|
||||
* 公告关闭者ID
|
||||
*/
|
||||
private Long closeUserId;
|
||||
/**
|
||||
* 公告关闭者名称
|
||||
*/
|
||||
private String closeUsername;
|
||||
/**
|
||||
* 公告关闭时间
|
||||
*/
|
||||
private LocalDateTime closeTime;
|
||||
/**
|
||||
* 公告内容
|
||||
*/
|
||||
private String content;
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updateBy;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
List<AttachmentVo> attachmentVos;
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
@ -17,35 +18,71 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
public class UserMessageVo {
|
||||
private Long id;
|
||||
public Long userId;
|
||||
public User user;
|
||||
public Long messageId;
|
||||
public Message message;
|
||||
/**
|
||||
* 用户消息id
|
||||
*/
|
||||
private Long messageId;
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
public Boolean isRead;
|
||||
/**
|
||||
* 阅读时间
|
||||
*/
|
||||
public LocalDateTime readTime;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
public String username;
|
||||
public String name;
|
||||
public String avatar;
|
||||
public String address;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
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;
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
public List<Attachment> attachments;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RestController
|
||||
@RequestMapping("/api/rest/authority")
|
||||
public class AuthorityController {
|
||||
|
||||
//TODO 导入IOT
|
||||
private AuthorityService service;
|
||||
|
||||
/**
|
||||
|
@ -1,15 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.system.controller;
|
||||
|
||||
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.modules.system.dto.DeptDto;
|
||||
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.query.DeptQuery;
|
||||
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.vo.DeptTree;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -31,12 +28,12 @@ public class DeptController {
|
||||
|
||||
/**
|
||||
* 返回管理部门列表 hasAuthority('DEPT_QUERY')
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门列表
|
||||
*/
|
||||
@GetMapping()
|
||||
public List<DeptTree> getDeptTree() {
|
||||
return service.getDeptTree();
|
||||
@GetMapping("/{deptId}")
|
||||
public List<Dept> getDeptTree(@PathVariable Long deptId) {
|
||||
return service.getDeptTree(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package com.zsc.edu.gateway.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.modules.system.vo.UserVo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -47,9 +48,9 @@ public class Dept extends BaseEntity {
|
||||
private Boolean enabled = true;
|
||||
|
||||
@TableField(exist = false)
|
||||
public List<Dept> children = new ArrayList<>(0);
|
||||
public List<Dept> children = null;
|
||||
|
||||
@TableField(exist = false)
|
||||
public List<User> members = new ArrayList<>(0);
|
||||
public List<UserVo> members = null;
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.zsc.edu.gateway.modules.system.entity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.zsc.edu.gateway.common.enums.EnableState;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.RoleAuthority;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.RoleDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.system.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.framework.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.dto.UserCreateDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import org.mapstruct.Mapper;
|
||||
|
@ -2,11 +2,6 @@ package com.zsc.edu.gateway.modules.system.repo;
|
||||
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
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;
|
||||
|
||||
@ -19,6 +14,5 @@ import java.util.List;
|
||||
* @since 2023-04-06
|
||||
*/
|
||||
public interface DeptRepository extends BaseMapper<Dept> {
|
||||
@Select("SELECT d.*, u.* FROM sys_dept d LEFT JOIN sys_user u ON d.id = u.dept_id")
|
||||
List<Dept> selectAllWithMembers();
|
||||
List<Dept> selectDeptTree();
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.zsc.edu.gateway.modules.system.service;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -31,13 +30,11 @@ public interface DeptService extends IService<Dept> {
|
||||
Boolean edit(DeptDto dto, Long id);
|
||||
|
||||
Boolean toggle(Long id);
|
||||
//
|
||||
// /**
|
||||
// * 生成部门树结构
|
||||
// * @param id
|
||||
// * @return
|
||||
// */
|
||||
//// Dept listTree(Long id);
|
||||
|
||||
List<DeptTree> getDeptTree();
|
||||
/**
|
||||
* 生成部门树结构
|
||||
*
|
||||
* @return Dept
|
||||
*/
|
||||
List<Dept> getDeptTree(Long deptId);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
||||
//import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||
import com.zsc.edu.gateway.modules.system.mapper.AuthorityMapper;
|
||||
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
|
||||
import com.zsc.edu.gateway.modules.system.service.AuthorityService;
|
||||
|
@ -2,23 +2,19 @@ package com.zsc.edu.gateway.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.framework.DeptTreeUtil;
|
||||
import com.zsc.edu.gateway.framework.common.util.TreeUtil;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
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.UserRepository;
|
||||
import com.zsc.edu.gateway.modules.system.service.DeptService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -34,7 +30,6 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
||||
|
||||
private final DeptMapper mapper;
|
||||
private final DeptRepository repo;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public Dept create(DeptDto dto) {
|
||||
@ -64,14 +59,25 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptTree> getDeptTree() {
|
||||
List<Dept> depots = repo.selectList(null);
|
||||
List<User> users = userRepository.selectList(null);
|
||||
Map<Long, List<User>> userMap = new HashMap<>();
|
||||
for (User user : users) {
|
||||
userMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
||||
public List<Dept> getDeptTree(Long deptId) {
|
||||
List<Dept> deptTrees = repo.selectDeptTree();
|
||||
List<Dept> deptTree = TreeUtil.makeTree(
|
||||
deptTrees,
|
||||
department -> department.getPid() == null || department.getPid() == -1L,
|
||||
(parent, child) -> parent.getId().equals(child.getPid()),
|
||||
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 deptChildrenTree;
|
||||
}
|
||||
return DeptTreeUtil.buildDeptTree(depots, userMap);
|
||||
return deptTree;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,7 +102,6 @@ public class RoleServiceImpl extends ServiceImpl<RoleRepository, Role> implement
|
||||
@Override
|
||||
public RoleVo detail(Long id) {
|
||||
// Role role = getById(id);
|
||||
// // TODO 联表查询
|
||||
// // List<RoleAuthority> roleAuthorities = roleAuthService.list(new LambdaQueryWrapper<RoleAuthority>().eq(RoleAuthority::getRoleId, role.id));
|
||||
// role.authorities = authorityRepository.selectAuthoritiesByRoleId(role.id);
|
||||
return roleRepository.selectRoleById(id);
|
||||
|
@ -10,7 +10,6 @@ import java.util.List;
|
||||
/**
|
||||
* @author ftz
|
||||
* 创建时间:16/2/2024 下午6:20
|
||||
* 描述: TODO
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -1,18 +1,19 @@
|
||||
package com.zsc.edu.gateway.modules.system.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class UserVo {
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
public Long id;
|
||||
public Long userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
@ -291,24 +291,31 @@ comment on column sys_user.enabled_status is '状态';
|
||||
alter table sys_user
|
||||
owner to postgres;
|
||||
|
||||
create table sys_user_message
|
||||
CREATE TABLE sys_user_message
|
||||
(
|
||||
id bigint not null
|
||||
constraint sys_user_message_pk
|
||||
primary key,
|
||||
user_id bigint not null,
|
||||
message_id bigint not null,
|
||||
is_read boolean not null,
|
||||
id bigserial NOT NULL
|
||||
CONSTRAINT sys_user_message_pk
|
||||
PRIMARY KEY,
|
||||
user_id bigint NOT NULL,
|
||||
message_id bigint NOT NULL,
|
||||
is_read boolean NOT NULL,
|
||||
read_time timestamp
|
||||
);
|
||||
comment on table sys_user_message is '用户消息';
|
||||
comment on column sys_user_message.id is '主键';
|
||||
comment on column sys_user_message.user_id is '用户';
|
||||
comment on column sys_user_message.message_id is '消息';
|
||||
comment on column sys_user_message.is_read is '是否已读';
|
||||
comment on column sys_user_message.read_time is '阅读时间';
|
||||
alter table sys_user_message
|
||||
owner to postgres;
|
||||
|
||||
COMMENT ON TABLE sys_user_message IS '用户消息';
|
||||
COMMENT ON COLUMN sys_user_message.id IS '主键';
|
||||
COMMENT ON COLUMN sys_user_message.user_id IS '用户';
|
||||
COMMENT ON COLUMN sys_user_message.message_id IS '消息';
|
||||
COMMENT ON COLUMN sys_user_message.is_read IS '是否已读';
|
||||
COMMENT ON COLUMN sys_user_message.read_time IS '阅读时间';
|
||||
|
||||
ALTER TABLE sys_user_message
|
||||
OWNER TO postgres;
|
||||
|
||||
-- 确保序列从1开始
|
||||
SELECT setval('sys_user_message_id_seq', 1, false);
|
||||
|
||||
|
||||
|
||||
create table sys_users_roles
|
||||
(
|
||||
@ -457,20 +464,12 @@ VALUES (1, TRUE, FALSE),
|
||||
(10, FALSE, TRUE);
|
||||
|
||||
INSERT INTO attachment (id, file_name, mime_type, url, upload_time)
|
||||
VALUES ('8', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf',
|
||||
CURRENT_TIMESTAMP - INTERVAL '1 day'),
|
||||
('9', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '2 days'),
|
||||
('10', 'presentation.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'http://example.com/files/presentation.pptx', CURRENT_TIMESTAMP - INTERVAL '3 days'),
|
||||
('11', 'spreadsheet.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'http://example.com/files/spreadsheet.xlsx', CURRENT_TIMESTAMP - INTERVAL '4 days'),
|
||||
('12', 'audio1.mp3', 'audio/mpeg', 'http://example.com/files/audio1.mp3', CURRENT_TIMESTAMP - INTERVAL '5 days'),
|
||||
('13', 'video1.mp4', 'video/mp4', 'http://example.com/files/video1.mp4', CURRENT_TIMESTAMP - INTERVAL '6 days'),
|
||||
('14', 'archive.zip', 'application/zip', 'http://example.com/files/archive.zip',
|
||||
CURRENT_TIMESTAMP - INTERVAL '7 days'),
|
||||
('15', 'textfile.txt', 'text/plain', 'http://example.com/files/textfile.txt',
|
||||
CURRENT_TIMESTAMP - INTERVAL '8 days'),
|
||||
('16', 'image2.png', 'image/png', 'http://example.com/files/image2.png', CURRENT_TIMESTAMP - INTERVAL '9 days'),
|
||||
('17', 'document2.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'http://example.com/files/document2.docx', CURRENT_TIMESTAMP - INTERVAL '10 days');
|
||||
VALUES ('1', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf', CURRENT_TIMESTAMP),
|
||||
('2', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '1 day'),
|
||||
('3', 'presentation.pptx', 'application/pptx', 'http://example.com/files/presentation.pptx',
|
||||
CURRENT_TIMESTAMP - INTERVAL '2 days'),
|
||||
('4', 'spreadsheet.xlsx', 'application/xlsx', 'http://example.com/files/spreadsheet.xlsx',
|
||||
CURRENT_TIMESTAMP - INTERVAL '3 days'),
|
||||
('5', 'audio.mp3', 'audio/mpeg', 'http://example.com/files/audio.mp3', CURRENT_TIMESTAMP - INTERVAL '4 days');
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.BulletinRepository">
|
||||
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo" autoMapping="true">
|
||||
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="title" jdbcType="VARCHAR" property="title"/>
|
||||
<result column="state" jdbcType="INTEGER" property="state"/>
|
||||
@ -18,64 +18,38 @@
|
||||
<result column="edit_user_name" jdbcType="VARCHAR" property="editUsername"/>
|
||||
<result column="publish_user_name" jdbcType="VARCHAR" property="publishUsername"/>
|
||||
<result column="close_user_name" jdbcType="VARCHAR" property="closeUsername"/>
|
||||
<collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo">
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<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="file_ame" jdbcType="VARCHAR" property="fileName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="selectByBulletinId" resultMap="BulletinMap">
|
||||
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 sys_bulletin sb
|
||||
LEFT JOIN
|
||||
sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
LEFT JOIN
|
||||
attachment a ON a.id = sba.attachment_id
|
||||
WHERE sb.id = #{bulletinId}
|
||||
|
||||
</select>
|
||||
|
||||
<select id="selectPageByConditions" resultType="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
|
||||
SELECT
|
||||
sb.id AS id,
|
||||
sb.state AS state,
|
||||
sb.content AS content,
|
||||
sb.title AS title,
|
||||
sb.top AS top,
|
||||
sb.remark AS remark,
|
||||
sb.close_time AS close_time,
|
||||
sb.close_user_id AS close_user_id,
|
||||
sb.create_by AS create_by,
|
||||
sb.create_time AS create_time,
|
||||
sb.edit_user_id AS edit_user_id,
|
||||
sb.publish_time AS publish_time,
|
||||
sb.publish_user_id AS publish_user_id,
|
||||
sb.update_by AS update_by,
|
||||
sb.update_time AS update_time,
|
||||
a.file_name AS file_name,
|
||||
a.url AS url
|
||||
SELECT sb.*, a.id as attachment_id,a.url as attachment_url,a.file_name as attachment_file_name
|
||||
FROM
|
||||
sys_bulletin sb
|
||||
LEFT JOIN
|
||||
sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
LEFT JOIN
|
||||
attachment a ON a.id = sba.attachment_id
|
||||
where 1=1
|
||||
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
LEFT JOIN attachment a ON a.id = sba.attachment_id
|
||||
<where>
|
||||
<if test="bulletinId !=null">
|
||||
sb.id = #{bulletinId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectPageByConditions" resultMap="BulletinMap">
|
||||
SELECT sb.*, a.id as attachment_id,a.file_name as attachment_file_name,a.url as attachment_url
|
||||
FROM
|
||||
sys_bulletin sb
|
||||
LEFT JOIN sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
LEFT JOIN attachment a ON a.id = sba.attachment_id
|
||||
<where>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND sb.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
@ -85,6 +59,7 @@
|
||||
<if test="query.publishTimeBegin != null and query.publishTimeEnd != null">
|
||||
AND sb.publish_time BETWEEN #{query.publishTimeBegin} AND #{query.publishTimeEnd}
|
||||
</if>
|
||||
</where>
|
||||
order by sb.top DESC,sb.publish_time DESC,sb.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
@ -4,14 +4,10 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository">
|
||||
<resultMap id="userMessageMap" type="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<id column="message_id" jdbcType="BIGINT" property="messageId"/>
|
||||
<result column="is_read" jdbcType="BOOLEAN" property="isRead"/>
|
||||
<result column="read_time" jdbcType="TIMESTAMP" property="readTime"/>
|
||||
<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="system" jdbcType="BOOLEAN" property="system"/>
|
||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
||||
@ -24,64 +20,90 @@
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
<collection property="attachments" ofType="com.zsc.edu.gateway.modules.attachment.entity.Attachment">
|
||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||
<result column="mime_type" jdbcType="VARCHAR" property="mimeType"/>
|
||||
<result column="upload_time" jdbcType="TIMESTAMP" property="uploadTime"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="userMessageAdminMap" type="com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
||||
<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>
|
||||
<select id="selectByMessageIdAndUserId" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo"
|
||||
resultMap="userMessageMap">
|
||||
select sum.id as user_message_id,sum.user_id as user_message_user_id,sum.message_id as
|
||||
user_message_message_id,sum.is_read as user_message_is_read,sum.read_time as user_message_read_time,su.id as
|
||||
user_id,su.username as user_username,su.address as user_address,su.avatar as user_avatar,su.name as
|
||||
user_name,su.phone as user_phone,sm.*,sm.email as message_email,a.*
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name
|
||||
from sys_user_message sum
|
||||
left join sys_user su on sum.id=su.id
|
||||
left join sys_message sm on sm.id=sum.id
|
||||
left join sys_message_attachment sma on sm.id=sma.message_id
|
||||
left join attachment a on sma.attachment_id=a.id
|
||||
left join sys_user su on sum.user_id = su.id
|
||||
left join sys_message sm on sm.id = sum.message_id
|
||||
<where>
|
||||
sm.id=#{messageId}
|
||||
and su.id=#{userId}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="query" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
||||
select sum.id as user_message_id,sum.user_id as user_message_user_id,sum.message_id as
|
||||
user_message_message_id,sum.is_read as user_message_is_read,sum.read_time as user_message_read_time,su.id as
|
||||
user_id,su.username as user_username,su.address as user_address,su.avatar as user_avatar,su.name as
|
||||
user_name,su.email as user_email,su.phone as user_phone,sm.*,sm.email as message_email,a.*
|
||||
<select id="page" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name
|
||||
from sys_user_message sum
|
||||
left join sys_user su on sum.id=su.id
|
||||
left join sys_message sm on sm.id=sum.id
|
||||
left join sys_message_attachment sma on sm.id=sma.message_id
|
||||
left join attachment a on sma.attachment_id=a.id
|
||||
where 1=1
|
||||
<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.type != null">
|
||||
AND sm.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
AND su.username LIKE CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.system != null">
|
||||
AND sm.system = #{query.system}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND sum.is_read = #{query.isRead}
|
||||
</if>
|
||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
</if>
|
||||
left join sys_user su on sum.user_id = su.id
|
||||
left join sys_message sm on sm.id = sum.message_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.type != null">
|
||||
AND sm.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
AND su.username LIKE CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.system != null">
|
||||
AND sm.system = #{query.system}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND sum.is_read = #{query.isRead}
|
||||
</if>
|
||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY
|
||||
sm.create_time DESC
|
||||
</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>
|
@ -1,9 +1,33 @@
|
||||
<?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">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.system.repo.DeptRepository">
|
||||
<select id="selectAllWithMembers" resultType="com.zsc.edu.gateway.modules.system.entity.Dept">
|
||||
SELECT d.*, u.*
|
||||
FROM sys_dept d
|
||||
LEFT JOIN sys_user u ON d.id = u.dept_id
|
||||
|
||||
<resultMap id="deptMap" type="com.zsc.edu.gateway.modules.system.entity.Dept">
|
||||
<id column="id" property="id"/>
|
||||
<result column="sub_count" property="subCount"/>
|
||||
<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>
|
||||
</mapper>
|
||||
|
@ -28,7 +28,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
@WebMvcTest(RoleController.class)
|
||||
public class RoleControllerTest extends MockMvcConfigBase {
|
||||
|
||||
//TODO 公告部分测试
|
||||
private static Role role1;
|
||||
|
||||
private static Role role2;
|
||||
|
@ -1,89 +1,89 @@
|
||||
//package com.zsc.edu.gateway.service;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.zsc.edu.gateway.domain.BulletinBuilder;
|
||||
//import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
//import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
//import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
//import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
//import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
//import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.junit.jupiter.api.AfterEach;
|
||||
//import org.junit.jupiter.api.BeforeEach;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.jupiter.api.Assertions.*;
|
||||
//
|
||||
//public class BulletinServiceTest {
|
||||
// @Resource
|
||||
// private BulletinService service;
|
||||
// @Resource
|
||||
// private BulletinRepository repo;
|
||||
//
|
||||
// Bulletin bulletin1;
|
||||
// Bulletin bulletin2;
|
||||
//
|
||||
// @BeforeEach
|
||||
// void setUp() {
|
||||
// bulletin1 = BulletinBuilder.bBulletin().title("测试1").build();
|
||||
// repo.insert(bulletin1);
|
||||
// bulletin2 = BulletinBuilder.bBulletin().title("测试2").build();
|
||||
// repo.insert(bulletin2);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void list() {
|
||||
// LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
||||
// assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
||||
// assertEquals(2, service.list().size());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void createBulletin() {
|
||||
// BulletinDto dto = new BulletinDto();
|
||||
// dto.setTitle("测试");
|
||||
// dto.setTop(true);
|
||||
// dto.setContent("测试测试");
|
||||
// dto.setRemark("测试公告增加");
|
||||
// BulletinDto dto2 = new BulletinDto();
|
||||
// dto2.setTitle(bulletin2.getTitle());
|
||||
//// dto2.setTop(bulletin2.isTop());
|
||||
// dto2.setRemark(bulletin2.getRemark());
|
||||
// UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
// userDetails.setUsername("admin");
|
||||
// Bulletin bulletin=service.create(userDetails,dto);
|
||||
// assertNotNull(bulletin.getId());
|
||||
// List<Bulletin> list = service.list();
|
||||
// assertEquals(3, list.size());
|
||||
// // 不能创建其他已存在标题公告
|
||||
// assertThrows(ConstraintException.class, () -> service.create(userDetails,dto2));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void updateBulletin() {
|
||||
// BulletinDto dto = new BulletinDto();
|
||||
// dto.setTitle("测试3");
|
||||
// dto.setContent("测试测");
|
||||
// dto.setTop(true);
|
||||
// dto.setRemark("测试公告更新");
|
||||
// UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
// userDetails.setUsername("admin");
|
||||
// assertTrue(service.update(userDetails,dto, bulletin2.id));
|
||||
// Bulletin bulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
||||
// assertEquals(bulletin.getTitle(), dto.getTitle());
|
||||
// assertEquals(bulletin.getId(), bulletin2.id);
|
||||
// // 不能改为其他已存在的同名同代码部门
|
||||
package com.zsc.edu.gateway.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zsc.edu.gateway.domain.BulletinBuilder;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class BulletinServiceTest {
|
||||
@Resource
|
||||
private BulletinService service;
|
||||
@Resource
|
||||
private BulletinRepository repo;
|
||||
|
||||
Bulletin bulletin1;
|
||||
Bulletin bulletin2;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
bulletin1 = BulletinBuilder.bBulletin().title("测试1").build();
|
||||
repo.insert(bulletin1);
|
||||
bulletin2 = BulletinBuilder.bBulletin().title("测试2").build();
|
||||
repo.insert(bulletin2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() {
|
||||
LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||
assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
||||
assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
||||
assertEquals(2, service.list().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBulletin() {
|
||||
BulletinDto dto = new BulletinDto();
|
||||
dto.setTitle("测试");
|
||||
dto.setTop(true);
|
||||
dto.setContent("测试测试");
|
||||
dto.setRemark("测试公告增加");
|
||||
BulletinDto dto2 = new BulletinDto();
|
||||
dto2.setTitle(bulletin2.getTitle());
|
||||
// dto2.setTop(bulletin2.isTop());
|
||||
dto2.setRemark(bulletin2.getRemark());
|
||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
userDetails.setUsername("admin");
|
||||
Bulletin bulletin = service.create(userDetails, dto);
|
||||
assertNotNull(bulletin.getId());
|
||||
List<Bulletin> list = service.list();
|
||||
assertEquals(3, list.size());
|
||||
// 不能创建其他已存在标题公告
|
||||
assertThrows(ConstraintException.class, () -> service.create(userDetails, dto2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBulletin() {
|
||||
BulletinDto dto = new BulletinDto();
|
||||
dto.setTitle("测试3");
|
||||
dto.setContent("测试测");
|
||||
dto.setTop(true);
|
||||
dto.setRemark("测试公告更新");
|
||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
userDetails.setUsername("admin");
|
||||
assertTrue(service.update(userDetails, dto, bulletin2.id));
|
||||
Bulletin bulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
||||
assertEquals(bulletin.getTitle(), dto.getTitle());
|
||||
assertEquals(bulletin.getId(), bulletin2.id);
|
||||
// 不能改为其他已存在的同名同代码部门
|
||||
// assertThrows(ConstraintException.class,
|
||||
// () -> service.update(userDetails,new BulletinDto(bulletin1.getTitle(),true,null,null), bulletin2.id));
|
||||
// }
|
||||
//
|
||||
// @AfterEach
|
||||
// void tearDown() {
|
||||
// repo.delete(new QueryWrapper<>());
|
||||
// }
|
||||
//}
|
||||
// () -> service.update(userDetails, new BulletinDto(bulletin1.getTitle(), true, null, null), bulletin2.id));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
repo.delete(new QueryWrapper<>());
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import java.util.Set;
|
||||
/**
|
||||
* @author ftz
|
||||
* 创建时间:29/12/2023 上午11:21
|
||||
* 描述: TODO
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class UserServiceTest {
|
||||
|
Loading…
Reference in New Issue
Block a user