|
|
|
@ -19,7 +19,6 @@ import cn.teammodel.service.EvaluationService;
|
|
|
|
|
import cn.teammodel.utils.RepositoryUtil;
|
|
|
|
|
import cn.teammodel.utils.SchoolDateUtil;
|
|
|
|
|
import com.azure.cosmos.models.CosmosPatchOperations;
|
|
|
|
|
import com.azure.spring.data.cosmos.core.CosmosTemplate;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
@ -31,6 +30,8 @@ import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author winter
|
|
|
|
@ -44,8 +45,6 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
private final static String TARGET_STUDENT = "student";
|
|
|
|
|
private final static String TARGET_CLASS = "class";
|
|
|
|
|
@Resource
|
|
|
|
|
CosmosTemplate cosmosTemplate;
|
|
|
|
|
@Resource
|
|
|
|
|
private SchoolRepository schoolRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
private AppraiseRecordRepository appraiseRecordRepository;
|
|
|
|
@ -72,11 +71,49 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Appraise getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
|
|
|
|
|
Appraise appraise = findAppraise(getEvaluateTreeDto.getPeriodId());
|
|
|
|
|
String periodId = getEvaluateTreeDto.getPeriodId();
|
|
|
|
|
// 默认学区为 default
|
|
|
|
|
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
|
|
|
|
|
User loginUser = SecurityUtil.getLoginUser();
|
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
|
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
|
|
|
|
|
|
|
|
|
|
// todo: 是否要对学段进行鉴权
|
|
|
|
|
if (appraise != null) {
|
|
|
|
|
return this.buildTree(appraise);
|
|
|
|
|
}
|
|
|
|
|
// 如果传参 period 所在没有 tree 的话,则复制一份模板 tree 给他 (处理节点 id)
|
|
|
|
|
appraise = RepositoryUtil.findOne(appraiseRepository.findTemplateTree(), "获取模板评价树失败");
|
|
|
|
|
if (appraise == null) {
|
|
|
|
|
throw new ServiceException();
|
|
|
|
|
}
|
|
|
|
|
refreshAppraiseTree(appraise.getNodes());
|
|
|
|
|
appraise.setPeriodId(periodId);
|
|
|
|
|
appraise.setSchoolId(schoolId);
|
|
|
|
|
appraise.setId(null);
|
|
|
|
|
appraise = appraiseRepository.save(appraise);
|
|
|
|
|
return this.buildTree(appraise);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将树的节点的 id 进行替换
|
|
|
|
|
*/
|
|
|
|
|
private void refreshAppraiseTree(List<AppraiseTreeNode> nodes) {
|
|
|
|
|
List<AppraiseTreeNode> children = nodes.stream().filter(item -> item.getPid() != null).collect(Collectors.toList());
|
|
|
|
|
// 将非 root 的 nodes 通过 pid 收集成 list, 再遍历 nodes, 将其每一个 id 对应 map 中的 list 的 pid修改成新的 id 即可
|
|
|
|
|
Map<String, List<AppraiseTreeNode>> pidNodeMap = children.stream().collect(Collectors.groupingBy(AppraiseTreeNode::getPid));
|
|
|
|
|
nodes.forEach(item -> {
|
|
|
|
|
String newId = UUID.randomUUID().toString();
|
|
|
|
|
String oldId = item.getId();
|
|
|
|
|
List<AppraiseTreeNode> appraiseTreeNodes = pidNodeMap.get(oldId);
|
|
|
|
|
if (appraiseTreeNodes != null) {
|
|
|
|
|
appraiseTreeNodes.forEach(node -> node.setPid(newId));
|
|
|
|
|
}
|
|
|
|
|
item.setId(newId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Appraise buildTree(Appraise appraise) {
|
|
|
|
|
if (appraise == null) {
|
|
|
|
@ -208,17 +245,17 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
|
|
|
|
|
// 获取评价项节点
|
|
|
|
|
List<AppraiseTreeNode> nodes = appraiseRepository.findNodeById(PK.PK_APPRAISE, appraiseId);
|
|
|
|
|
AppraiseTreeNode appraiseTreeNode = RepositoryUtil.findOne(nodes);
|
|
|
|
|
AppraiseTreeNode appraiseTreeNode = RepositoryUtil.findOne(nodes, "获取评价项失败");
|
|
|
|
|
|
|
|
|
|
// 通过 periodId 获取 semesters
|
|
|
|
|
List<School.Period> periodById = schoolRepository.findPeriodById(schoolId, periodId);
|
|
|
|
|
School.Period period = RepositoryUtil.findOne(periodById);
|
|
|
|
|
School.Period period = RepositoryUtil.findOne(periodById, "获取学段失败");
|
|
|
|
|
List<School.Semester> semesters = period.getSemesters();
|
|
|
|
|
|
|
|
|
|
// 获取当前学年学期组合 ID
|
|
|
|
|
String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now());
|
|
|
|
|
|
|
|
|
|
// 查询是否存在记录,不存在则创建一条新的,存在则处理一下分值后再向其 nodes 中插入一条 item
|
|
|
|
|
// 查询是否存在记录
|
|
|
|
|
AppraiseRecord record = appraiseRecordRepository.findAppraiseRecordByTargetIdAndAcademicYearIdAndCode(
|
|
|
|
|
targetId,
|
|
|
|
|
academicYearId,
|
|
|
|
@ -233,8 +270,8 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
item.setCreatorId(loginUser.getId());
|
|
|
|
|
item.setCreateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
// 不存在则创建一条新的,存在则处理一下分值后再向其 nodes 中插入一条 item
|
|
|
|
|
if (record == null) {
|
|
|
|
|
// 不存在, 创建新的 AppraiseRecord
|
|
|
|
|
List<AppraiseRecordItem> items = Collections.singletonList(item);
|
|
|
|
|
|
|
|
|
|
record = new AppraiseRecord();
|
|
|
|
@ -270,8 +307,26 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void findVoteRecord(FindVoteRecordDto findVoteRecordDto) {
|
|
|
|
|
public List<AppraiseRecordItem> findVoteRecord(FindVoteRecordDto findVoteRecordDto) {
|
|
|
|
|
String periodId = findVoteRecordDto.getTargetId();
|
|
|
|
|
String targetId = findVoteRecordDto.getTargetId();
|
|
|
|
|
String targetType = findVoteRecordDto.getTargetType();
|
|
|
|
|
String classId = findVoteRecordDto.getClassId();
|
|
|
|
|
User loginUser = SecurityUtil.getLoginUser();
|
|
|
|
|
String teacherId = loginUser.getId();
|
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
|
|
|
|
|
|
List<School.Semester> semesters = schoolRepository.findSemestersById(schoolId, periodId);
|
|
|
|
|
String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now());
|
|
|
|
|
List<AppraiseRecordItem> appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition(
|
|
|
|
|
targetId,
|
|
|
|
|
targetType,
|
|
|
|
|
classId,
|
|
|
|
|
teacherId,
|
|
|
|
|
academicYearId,
|
|
|
|
|
String.format(PK.PK_APPRAISE_RECORD, schoolId)
|
|
|
|
|
);
|
|
|
|
|
return appraiseRecordItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|