feat(消息模块与部门模块): 修改了消息模块的bug并从新建消息接口中独立出添加附件接口,部门模块新添加了部门树返回接口
This commit is contained in:
parent
e894b5aa00
commit
5b6a97b668
@ -0,0 +1,66 @@
|
|||||||
|
package com.zsc.edu.gateway.framework;
|
||||||
|
|
||||||
|
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||||
|
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||||
|
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||||
|
import com.zsc.edu.gateway.modules.system.vo.UserTree;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DeptTreeUtil {
|
||||||
|
|
||||||
|
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
|
||||||
|
return list.stream()
|
||||||
|
.filter(rootCheck)
|
||||||
|
.peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <E> List<E> makeChildren(E parent, List<E> allData, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
|
||||||
|
return allData.stream()
|
||||||
|
.filter(x -> parentCheck.apply(parent, x))
|
||||||
|
.peek(x -> setSubChildren.accept(x, makeChildren(x, allData, parentCheck, setSubChildren)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DeptTree> buildDeptTree(List<Dept> depots, Map<Long, List<User>> userMap) {
|
||||||
|
List<DeptTree> deptTrees = depots.stream()
|
||||||
|
.map(DeptTreeUtil::convertToDeptTree)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
deptTrees.forEach(deptTree -> {
|
||||||
|
List<User> users = userMap.getOrDefault(deptTree.getId(), Collections.emptyList());
|
||||||
|
deptTree.setMembers(users.stream()
|
||||||
|
.map(DeptTreeUtil::convertToUserTree)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
});
|
||||||
|
|
||||||
|
return makeTree(
|
||||||
|
deptTrees,
|
||||||
|
deptTree -> deptTree.getPid() == null || deptTree.getPid() == 0L,
|
||||||
|
(parent, child) -> parent.getId().equals(child.getPid()),
|
||||||
|
DeptTree::setChildren
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeptTree convertToDeptTree(Dept dept) {
|
||||||
|
DeptTree deptTree = new DeptTree();
|
||||||
|
deptTree.setId(dept.getId());
|
||||||
|
deptTree.setPid(dept.getPid());
|
||||||
|
deptTree.setName(dept.getName());
|
||||||
|
return deptTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UserTree convertToUserTree(User user) {
|
||||||
|
UserTree userTree = new UserTree();
|
||||||
|
userTree.setId(user.getId());
|
||||||
|
userTree.setName(user.getName());
|
||||||
|
return userTree;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.attachment.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhuang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AttachmentVo {
|
||||||
|
public String fileName;
|
||||||
|
public String url;
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.notice.repo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageAttachment;
|
||||||
|
|
||||||
|
public interface MessageAttachmentRepository extends BaseMapper<MessageAttachment> {
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.notice.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageAttachment;
|
||||||
|
|
||||||
|
public interface MessageAttachmentService extends IService<MessageAttachment> {
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageAttachment;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.repo.MessageAttachmentRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.service.MessageAttachmentService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhuang
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MessageAttachmentServiceImpl extends ServiceImpl<MessageAttachmentRepository, MessageAttachment> implements MessageAttachmentService {
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.system.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhuang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class DeptTree {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
@JsonIgnore
|
||||||
|
private Long pid;
|
||||||
|
private String name;
|
||||||
|
List<DeptTree> children = new ArrayList<>();
|
||||||
|
List<UserTree> members = new ArrayList<>();
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.zsc.edu.gateway.modules.system.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhuang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserTree {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user