|
|
@ -9,8 +9,8 @@ import cn.teammodel.model.dto.DeleteNodeDto;
|
|
|
|
import cn.teammodel.model.dto.GetEvaluateTreeDto;
|
|
|
|
import cn.teammodel.model.dto.GetEvaluateTreeDto;
|
|
|
|
import cn.teammodel.model.dto.InsertNodeDto;
|
|
|
|
import cn.teammodel.model.dto.InsertNodeDto;
|
|
|
|
import cn.teammodel.model.dto.UpdateNodeDto;
|
|
|
|
import cn.teammodel.model.dto.UpdateNodeDto;
|
|
|
|
import cn.teammodel.model.entity.Evaluation;
|
|
|
|
import cn.teammodel.model.entity.Appraise;
|
|
|
|
import cn.teammodel.model.entity.EvaluationTreeNode;
|
|
|
|
import cn.teammodel.model.entity.AppraiseTreeNode;
|
|
|
|
import cn.teammodel.model.entity.User;
|
|
|
|
import cn.teammodel.model.entity.User;
|
|
|
|
import cn.teammodel.security.utils.SecurityUtils;
|
|
|
|
import cn.teammodel.security.utils.SecurityUtils;
|
|
|
|
import cn.teammodel.service.EvaluationService;
|
|
|
|
import cn.teammodel.service.EvaluationService;
|
|
|
@ -40,56 +40,56 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
* 通用的获取 evaluation 的方法: 判断参数,判断数据是否为空 <br/>
|
|
|
|
* 通用的获取 evaluation 的方法: 判断参数,判断数据是否为空 <br/>
|
|
|
|
* 从 token 中获取 schoolId
|
|
|
|
* 从 token 中获取 schoolId
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Evaluation findEvaluation(String periodId) {
|
|
|
|
private Appraise findEvaluation(String periodId) {
|
|
|
|
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
|
|
|
|
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
|
|
|
|
User loginUser = SecurityUtils.getLoginUser();
|
|
|
|
User loginUser = SecurityUtils.getLoginUser();
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
|
|
|
|
|
|
|
|
// 拿到要新增节点的原始数据
|
|
|
|
// 拿到要新增节点的原始数据
|
|
|
|
Evaluation evaluation = evaluationRepository.findBySchoolIdAndPeriodId(schoolId, periodId, PK.PK_EVALUATION);
|
|
|
|
Appraise appraise = evaluationRepository.findBySchoolIdAndPeriodId(schoolId, periodId, PK.PK_EVALUATION);
|
|
|
|
if (evaluation == null) {
|
|
|
|
if (appraise == null) {
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在");
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return evaluation;
|
|
|
|
return appraise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
|
|
|
|
public Appraise getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
|
|
|
|
Evaluation evaluation = findEvaluation(getEvaluateTreeDto.getPeriodId());
|
|
|
|
Appraise appraise = findEvaluation(getEvaluateTreeDto.getPeriodId());
|
|
|
|
|
|
|
|
|
|
|
|
return this.buildTree(evaluation);
|
|
|
|
return this.buildTree(appraise);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation buildTree(Evaluation evaluation) {
|
|
|
|
public Appraise buildTree(Appraise appraise) {
|
|
|
|
if (evaluation == null) {
|
|
|
|
if (appraise == null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<EvaluationTreeNode> nodes = evaluation.getNodes();
|
|
|
|
List<AppraiseTreeNode> nodes = appraise.getNodes();
|
|
|
|
List<EvaluationTreeNode> parents = new ArrayList<>();
|
|
|
|
List<AppraiseTreeNode> parents = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
// pid 为 null 或者 "" 则为 parents
|
|
|
|
// pid 为 null 或者 "" 则为 parents
|
|
|
|
for (EvaluationTreeNode node : nodes) {
|
|
|
|
for (AppraiseTreeNode node : nodes) {
|
|
|
|
if (StringUtils.isBlank(node.getPid())) {
|
|
|
|
if (StringUtils.isBlank(node.getPid())) {
|
|
|
|
parents.add(node);
|
|
|
|
parents.add(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 迭代构建孩子节点
|
|
|
|
// 迭代构建孩子节点
|
|
|
|
for (EvaluationTreeNode parent : parents) {
|
|
|
|
for (AppraiseTreeNode parent : parents) {
|
|
|
|
buildChildren(parent, nodes);
|
|
|
|
buildChildren(parent, nodes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
evaluation.setNodes(parents);
|
|
|
|
appraise.setNodes(parents);
|
|
|
|
return evaluation;
|
|
|
|
return appraise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void flattenTree(List<EvaluationTreeNode> trees, List<EvaluationTreeNode> nodes) {
|
|
|
|
public void flattenTree(List<AppraiseTreeNode> trees, List<AppraiseTreeNode> nodes) {
|
|
|
|
// 递归结束条件
|
|
|
|
// 递归结束条件
|
|
|
|
if (ObjectUtils.isEmpty(trees)) return;
|
|
|
|
if (ObjectUtils.isEmpty(trees)) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 这里的每个 tree 都是组装好的树,区别于单个节点
|
|
|
|
// 这里的每个 tree 都是组装好的树,区别于单个节点
|
|
|
|
for (EvaluationTreeNode tree : trees) {
|
|
|
|
for (AppraiseTreeNode tree : trees) {
|
|
|
|
// 递归
|
|
|
|
// 递归
|
|
|
|
flattenTree(tree.getChildren(), nodes);
|
|
|
|
flattenTree(tree.getChildren(), nodes);
|
|
|
|
// 回溯时删除 children,添加进列表
|
|
|
|
// 回溯时删除 children,添加进列表
|
|
|
@ -99,13 +99,13 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation insertNode(InsertNodeDto insertNodeDto) {
|
|
|
|
public Appraise insertNode(InsertNodeDto insertNodeDto) {
|
|
|
|
Evaluation evaluation = findEvaluation(insertNodeDto.getPeriodId());
|
|
|
|
Appraise appraise = findEvaluation(insertNodeDto.getPeriodId());
|
|
|
|
User loginUser = SecurityUtils.getLoginUser();
|
|
|
|
User loginUser = SecurityUtils.getLoginUser();
|
|
|
|
|
|
|
|
|
|
|
|
List<EvaluationTreeNode> originNodes = evaluation.getNodes();
|
|
|
|
List<AppraiseTreeNode> originNodes = appraise.getNodes();
|
|
|
|
// 拷贝数据到新节点
|
|
|
|
// 拷贝数据到新节点
|
|
|
|
EvaluationTreeNode newNode = new EvaluationTreeNode();
|
|
|
|
AppraiseTreeNode newNode = new AppraiseTreeNode();
|
|
|
|
BeanUtils.copyProperties(insertNodeDto, newNode);
|
|
|
|
BeanUtils.copyProperties(insertNodeDto, newNode);
|
|
|
|
|
|
|
|
|
|
|
|
String newNodePid = newNode.getPid();
|
|
|
|
String newNodePid = newNode.getPid();
|
|
|
@ -123,17 +123,17 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
newNode.setCreateTime(LocalDateTime.now());
|
|
|
|
newNode.setCreateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
|
|
originNodes.add(newNode);
|
|
|
|
originNodes.add(newNode);
|
|
|
|
return buildTree(evaluationRepository.save(evaluation));
|
|
|
|
return buildTree(evaluationRepository.save(appraise));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation updateNode(UpdateNodeDto updateNodeDto) {
|
|
|
|
public Appraise updateNode(UpdateNodeDto updateNodeDto) {
|
|
|
|
String updateNodeId = updateNodeDto.getId();
|
|
|
|
String updateNodeId = updateNodeDto.getId();
|
|
|
|
|
|
|
|
|
|
|
|
Evaluation evaluation = findEvaluation(updateNodeDto.getPeriodId());
|
|
|
|
Appraise appraise = findEvaluation(updateNodeDto.getPeriodId());
|
|
|
|
List<EvaluationTreeNode> originNodes = evaluation.getNodes();
|
|
|
|
List<AppraiseTreeNode> originNodes = appraise.getNodes();
|
|
|
|
// 每个节点都有 id, 直接校验是否合法
|
|
|
|
// 每个节点都有 id, 直接校验是否合法
|
|
|
|
EvaluationTreeNode updateNode = originNodes.stream()
|
|
|
|
AppraiseTreeNode updateNode = originNodes.stream()
|
|
|
|
.filter(item -> updateNodeId.equals(item.getId()))
|
|
|
|
.filter(item -> updateNodeId.equals(item.getId()))
|
|
|
|
.findFirst()
|
|
|
|
.findFirst()
|
|
|
|
.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "更新节点不存在"));
|
|
|
|
.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "更新节点不存在"));
|
|
|
@ -144,18 +144,18 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
updateNode.setPraise(updateNodeDto.isPraise());
|
|
|
|
updateNode.setPraise(updateNodeDto.isPraise());
|
|
|
|
// todo: 为新节点赋值必须参数 (id, creator), 可不可以添加默认值 order ?
|
|
|
|
// todo: 为新节点赋值必须参数 (id, creator), 可不可以添加默认值 order ?
|
|
|
|
|
|
|
|
|
|
|
|
return buildTree(evaluationRepository.save(evaluation));
|
|
|
|
return buildTree(evaluationRepository.save(appraise));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation deleteNode(DeleteNodeDto deleteNodeDto) {
|
|
|
|
public Appraise deleteNode(DeleteNodeDto deleteNodeDto) {
|
|
|
|
// 删除指定节点,可能是(一级,二级,三级),设计一个通用的
|
|
|
|
// 删除指定节点,可能是(一级,二级,三级),设计一个通用的
|
|
|
|
Evaluation evaluation = findEvaluation(deleteNodeDto.getPeriodId());
|
|
|
|
Appraise appraise = findEvaluation(deleteNodeDto.getPeriodId());
|
|
|
|
List<EvaluationTreeNode> nodes = evaluation.getNodes();
|
|
|
|
List<AppraiseTreeNode> nodes = appraise.getNodes();
|
|
|
|
List<EvaluationTreeNode> nodesToDelete = new ArrayList<>();
|
|
|
|
List<AppraiseTreeNode> nodesToDelete = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
// 迭代器安全删除
|
|
|
|
// 迭代器安全删除
|
|
|
|
for (EvaluationTreeNode node : nodes) {
|
|
|
|
for (AppraiseTreeNode node : nodes) {
|
|
|
|
if (node.getId().equals(deleteNodeDto.getId())) {
|
|
|
|
if (node.getId().equals(deleteNodeDto.getId())) {
|
|
|
|
// 删除当前节点
|
|
|
|
// 删除当前节点
|
|
|
|
nodesToDelete.add(node);
|
|
|
|
nodesToDelete.add(node);
|
|
|
@ -165,14 +165,14 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nodes.removeAll(nodesToDelete);
|
|
|
|
nodes.removeAll(nodesToDelete);
|
|
|
|
|
|
|
|
|
|
|
|
return buildTree(evaluationRepository.save(evaluation));
|
|
|
|
return buildTree(evaluationRepository.save(appraise));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 递归收集 id 的节点及 id 节点的孩子节点 (迭代器删除居然也报错)
|
|
|
|
* 递归收集 id 的节点及 id 节点的孩子节点 (迭代器删除居然也报错)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void collectNodesToDelete(String id, List<EvaluationTreeNode> nodes, List<EvaluationTreeNode> nodesToDelete) {
|
|
|
|
private void collectNodesToDelete(String id, List<AppraiseTreeNode> nodes, List<AppraiseTreeNode> nodesToDelete) {
|
|
|
|
for (EvaluationTreeNode node : nodes) {
|
|
|
|
for (AppraiseTreeNode node : nodes) {
|
|
|
|
if (id.equals(node.getPid())) {
|
|
|
|
if (id.equals(node.getPid())) {
|
|
|
|
// 收集
|
|
|
|
// 收集
|
|
|
|
nodesToDelete.add(node);
|
|
|
|
nodesToDelete.add(node);
|
|
|
@ -186,12 +186,12 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 递归的构建父亲节点的孩子,以及孩子的孩子 (理论支持无极树,但应该考虑是否增加递归深度)
|
|
|
|
* 递归的构建父亲节点的孩子,以及孩子的孩子 (理论支持无极树,但应该考虑是否增加递归深度)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void buildChildren(EvaluationTreeNode parent, List<EvaluationTreeNode> nodes) {
|
|
|
|
private void buildChildren(AppraiseTreeNode parent, List<AppraiseTreeNode> nodes) {
|
|
|
|
List<EvaluationTreeNode> children = getChildren(parent, nodes);
|
|
|
|
List<AppraiseTreeNode> children = getChildren(parent, nodes);
|
|
|
|
if (children.size() == 0) return;
|
|
|
|
if (children.size() == 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
parent.setChildren(children);
|
|
|
|
parent.setChildren(children);
|
|
|
|
for (EvaluationTreeNode child : children) {
|
|
|
|
for (AppraiseTreeNode child : children) {
|
|
|
|
// 如果子节点还有孩子的话,就继续递归构建
|
|
|
|
// 如果子节点还有孩子的话,就继续递归构建
|
|
|
|
if (getChildren(child, nodes).size() > 0) {
|
|
|
|
if (getChildren(child, nodes).size() > 0) {
|
|
|
|
buildChildren(child, nodes);
|
|
|
|
buildChildren(child, nodes);
|
|
|
@ -204,9 +204,9 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取节点的孩子节点列表
|
|
|
|
* 获取节点的孩子节点列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private List<EvaluationTreeNode> getChildren(EvaluationTreeNode parent, List<EvaluationTreeNode> nodes) {
|
|
|
|
private List<AppraiseTreeNode> getChildren(AppraiseTreeNode parent, List<AppraiseTreeNode> nodes) {
|
|
|
|
List<EvaluationTreeNode> children = new ArrayList<>();
|
|
|
|
List<AppraiseTreeNode> children = new ArrayList<>();
|
|
|
|
for (EvaluationTreeNode node : nodes) {
|
|
|
|
for (AppraiseTreeNode node : nodes) {
|
|
|
|
if (StringUtils.isNotBlank(node.getPid()) && node.getPid().equals(parent.getId())) {
|
|
|
|
if (StringUtils.isNotBlank(node.getPid()) && node.getPid().equals(parent.getId())) {
|
|
|
|
children.add(node);
|
|
|
|
children.add(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|