|
|
@ -11,6 +11,8 @@ 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.Evaluation;
|
|
|
|
import cn.teammodel.model.entity.EvaluationTreeNode;
|
|
|
|
import cn.teammodel.model.entity.EvaluationTreeNode;
|
|
|
|
|
|
|
|
import cn.teammodel.model.entity.User;
|
|
|
|
|
|
|
|
import cn.teammodel.security.utils.SecurityUtils;
|
|
|
|
import cn.teammodel.service.EvaluationService;
|
|
|
|
import cn.teammodel.service.EvaluationService;
|
|
|
|
import com.azure.spring.data.cosmos.core.CosmosTemplate;
|
|
|
|
import com.azure.spring.data.cosmos.core.CosmosTemplate;
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
@ -33,13 +35,27 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private EvaluationRepository evaluationRepository;
|
|
|
|
private EvaluationRepository evaluationRepository;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
/**
|
|
|
|
public Evaluation getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
|
|
|
|
* 通用的获取 evaluation 的方法: 判断参数,判断数据是否为空 <br/>
|
|
|
|
String schoolId = getEvaluateTreeDto.getSchoolId();
|
|
|
|
* 从 token 中获取 schoolId
|
|
|
|
String periodId = getEvaluateTreeDto.getPeriodId();
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Evaluation findEvaluation(String periodId) {
|
|
|
|
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
|
|
|
|
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
|
|
|
|
|
|
|
|
User loginUser = SecurityUtils.getLoginUser();
|
|
|
|
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 拿到要新增节点的原始数据
|
|
|
|
Evaluation evaluation = evaluationRepository.findBySchoolIdAndPeriodId(schoolId, periodId, PK.PK_EVALUATION);
|
|
|
|
Evaluation evaluation = evaluationRepository.findBySchoolIdAndPeriodId(schoolId, periodId, PK.PK_EVALUATION);
|
|
|
|
|
|
|
|
if (evaluation == null) {
|
|
|
|
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return evaluation;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Evaluation getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
|
|
|
|
|
|
|
|
Evaluation evaluation = findEvaluation(getEvaluateTreeDto.getPeriodId());
|
|
|
|
|
|
|
|
|
|
|
|
return this.buildTree(evaluation);
|
|
|
|
return this.buildTree(evaluation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +99,7 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation insertNode(InsertNodeDto insertNodeDto) {
|
|
|
|
public Evaluation insertNode(InsertNodeDto insertNodeDto) {
|
|
|
|
Evaluation evaluation = findEvaluation(insertNodeDto.getSchoolId(), insertNodeDto.getPeriodId());
|
|
|
|
Evaluation evaluation = findEvaluation(insertNodeDto.getPeriodId());
|
|
|
|
|
|
|
|
|
|
|
|
List<EvaluationTreeNode> originNodes = evaluation.getNodes();
|
|
|
|
List<EvaluationTreeNode> originNodes = evaluation.getNodes();
|
|
|
|
// 拷贝数据到新节点
|
|
|
|
// 拷贝数据到新节点
|
|
|
@ -109,7 +125,7 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
public Evaluation updateNode(UpdateNodeDto updateNodeDto) {
|
|
|
|
public Evaluation updateNode(UpdateNodeDto updateNodeDto) {
|
|
|
|
String updateNodeId = updateNodeDto.getId();
|
|
|
|
String updateNodeId = updateNodeDto.getId();
|
|
|
|
|
|
|
|
|
|
|
|
Evaluation evaluation = findEvaluation(updateNodeDto.getSchoolId(), updateNodeDto.getPeriodId());
|
|
|
|
Evaluation evaluation = findEvaluation(updateNodeDto.getPeriodId());
|
|
|
|
List<EvaluationTreeNode> originNodes = evaluation.getNodes();
|
|
|
|
List<EvaluationTreeNode> originNodes = evaluation.getNodes();
|
|
|
|
// 每个节点都有 id, 直接校验是否合法
|
|
|
|
// 每个节点都有 id, 直接校验是否合法
|
|
|
|
EvaluationTreeNode updateNode = originNodes.stream()
|
|
|
|
EvaluationTreeNode updateNode = originNodes.stream()
|
|
|
@ -129,7 +145,7 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Evaluation deleteNode(DeleteNodeDto deleteNodeDto) {
|
|
|
|
public Evaluation deleteNode(DeleteNodeDto deleteNodeDto) {
|
|
|
|
// 删除指定节点,可能是(一级,二级,三级),设计一个通用的
|
|
|
|
// 删除指定节点,可能是(一级,二级,三级),设计一个通用的
|
|
|
|
Evaluation evaluation = findEvaluation(deleteNodeDto.getSchoolId(), deleteNodeDto.getPeriodId());
|
|
|
|
Evaluation evaluation = findEvaluation(deleteNodeDto.getPeriodId());
|
|
|
|
List<EvaluationTreeNode> nodes = evaluation.getNodes();
|
|
|
|
List<EvaluationTreeNode> nodes = evaluation.getNodes();
|
|
|
|
List<EvaluationTreeNode> nodesToDelete = new ArrayList<>();
|
|
|
|
List<EvaluationTreeNode> nodesToDelete = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
@ -162,20 +178,6 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 通用的获取 evaluation 的方法: 判断参数,判断数据是否为空
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Evaluation findEvaluation(String schoolId,String periodId) {
|
|
|
|
|
|
|
|
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 拿到要新增节点的原始数据
|
|
|
|
|
|
|
|
Evaluation evaluation = evaluationRepository.findBySchoolIdAndPeriodId(schoolId, periodId, PK.PK_EVALUATION);
|
|
|
|
|
|
|
|
if (evaluation == null) {
|
|
|
|
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return evaluation;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 递归的构建父亲节点的孩子,以及孩子的孩子 (理论支持无极树,但应该考虑是否增加递归深度)
|
|
|
|
* 递归的构建父亲节点的孩子,以及孩子的孩子 (理论支持无极树,但应该考虑是否增加递归深度)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|