|
|
@ -4,16 +4,16 @@ import cn.hutool.core.lang.UUID;
|
|
|
|
import cn.teammodel.common.ErrorCode;
|
|
|
|
import cn.teammodel.common.ErrorCode;
|
|
|
|
import cn.teammodel.common.PK;
|
|
|
|
import cn.teammodel.common.PK;
|
|
|
|
import cn.teammodel.config.exception.ServiceException;
|
|
|
|
import cn.teammodel.config.exception.ServiceException;
|
|
|
|
import cn.teammodel.dao.AppraiseRecordRepository;
|
|
|
|
import cn.teammodel.dao.*;
|
|
|
|
import cn.teammodel.dao.AppraiseRepository;
|
|
|
|
|
|
|
|
import cn.teammodel.dao.SchoolRepository;
|
|
|
|
|
|
|
|
import cn.teammodel.model.dto.Appraise.*;
|
|
|
|
import cn.teammodel.model.dto.Appraise.*;
|
|
|
|
import cn.teammodel.model.entity.User;
|
|
|
|
import cn.teammodel.model.entity.User;
|
|
|
|
import cn.teammodel.model.entity.appraise.Appraise;
|
|
|
|
import cn.teammodel.model.entity.appraise.Appraise;
|
|
|
|
import cn.teammodel.model.entity.appraise.AppraiseRecord;
|
|
|
|
import cn.teammodel.model.entity.appraise.AppraiseRecord;
|
|
|
|
import cn.teammodel.model.entity.appraise.AppraiseRecordItem;
|
|
|
|
import cn.teammodel.model.entity.appraise.AppraiseRecordItem;
|
|
|
|
import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
|
|
|
|
import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
|
|
|
|
|
|
|
|
import cn.teammodel.model.entity.school.ClassInfo;
|
|
|
|
import cn.teammodel.model.entity.school.School;
|
|
|
|
import cn.teammodel.model.entity.school.School;
|
|
|
|
|
|
|
|
import cn.teammodel.model.entity.school.Student;
|
|
|
|
import cn.teammodel.security.utils.SecurityUtil;
|
|
|
|
import cn.teammodel.security.utils.SecurityUtil;
|
|
|
|
import cn.teammodel.service.EvaluationService;
|
|
|
|
import cn.teammodel.service.EvaluationService;
|
|
|
|
import cn.teammodel.utils.RepositoryUtil;
|
|
|
|
import cn.teammodel.utils.RepositoryUtil;
|
|
|
@ -45,6 +45,10 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
private final static String TARGET_STUDENT = "student";
|
|
|
|
private final static String TARGET_STUDENT = "student";
|
|
|
|
private final static String TARGET_CLASS = "class";
|
|
|
|
private final static String TARGET_CLASS = "class";
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private ClassRepository classRepository;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private StudentRepository studentRepository;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private SchoolRepository schoolRepository;
|
|
|
|
private SchoolRepository schoolRepository;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private AppraiseRecordRepository appraiseRecordRepository;
|
|
|
|
private AppraiseRecordRepository appraiseRecordRepository;
|
|
|
@ -109,7 +113,9 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
if (appraiseTreeNodes != null) {
|
|
|
|
if (appraiseTreeNodes != null) {
|
|
|
|
appraiseTreeNodes.forEach(node -> node.setPid(newId));
|
|
|
|
appraiseTreeNodes.forEach(node -> node.setPid(newId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理每个节点属性
|
|
|
|
item.setId(newId);
|
|
|
|
item.setId(newId);
|
|
|
|
|
|
|
|
item.setCreator("template");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -228,17 +234,34 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void vote(AppraiseVoteDto appraiseVoteDto) {
|
|
|
|
public void vote(AppraiseVoteDto appraiseVoteDto) {
|
|
|
|
String targetId = appraiseVoteDto.getTargetId();
|
|
|
|
String targetId = appraiseVoteDto.getTargetId();
|
|
|
|
String classId = appraiseVoteDto.getClassId();
|
|
|
|
|
|
|
|
boolean spread = appraiseVoteDto.isSpread();
|
|
|
|
boolean spread = appraiseVoteDto.isSpread();
|
|
|
|
String targetType = appraiseVoteDto.getTargetType();
|
|
|
|
String targetType = appraiseVoteDto.getTargetType();
|
|
|
|
String appraiseId = appraiseVoteDto.getAppraiseId();
|
|
|
|
String appraiseId = appraiseVoteDto.getAppraiseId();
|
|
|
|
// 获取 school 中的 semesters
|
|
|
|
|
|
|
|
String periodId = appraiseVoteDto.getPeriodId();
|
|
|
|
|
|
|
|
User loginUser = SecurityUtil.getLoginUser();
|
|
|
|
User loginUser = SecurityUtil.getLoginUser();
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
String schoolId = loginUser.getSchoolId();
|
|
|
|
|
|
|
|
String classId;
|
|
|
|
|
|
|
|
String periodId;
|
|
|
|
|
|
|
|
String name;
|
|
|
|
|
|
|
|
String avatar = null;
|
|
|
|
// 判断评价对象是否合法
|
|
|
|
// 判断评价对象是否合法
|
|
|
|
if (!targetType.equals(TARGET_STUDENT) && !targetType.equals(TARGET_CLASS)) {
|
|
|
|
if (targetType.equals(TARGET_STUDENT)) {
|
|
|
|
|
|
|
|
Student student = studentRepository.findStudentByIdAndCode(targetId, String.format(PK.STUDENT, schoolId));
|
|
|
|
|
|
|
|
if (student == null) {
|
|
|
|
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该学生不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
classId = student.getClassId();
|
|
|
|
|
|
|
|
periodId = student.getPeriodId();
|
|
|
|
|
|
|
|
name = student.getName();
|
|
|
|
|
|
|
|
avatar = student.getPicture();
|
|
|
|
|
|
|
|
} else if (targetType.equals(TARGET_CLASS)){
|
|
|
|
|
|
|
|
ClassInfo classInfo = classRepository.findClassByIdAndCode(targetId, String.format(PK.CLASS, schoolId));
|
|
|
|
|
|
|
|
if (classInfo == null) {
|
|
|
|
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "班级不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
classId = targetId;
|
|
|
|
|
|
|
|
periodId = classInfo.getPeriodId();
|
|
|
|
|
|
|
|
name = classInfo.getName();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不受支持的评价对象");
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不受支持的评价对象");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -255,9 +278,10 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now());
|
|
|
|
String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now());
|
|
|
|
|
|
|
|
|
|
|
|
// 查询是否存在记录
|
|
|
|
// 查询是否存在记录
|
|
|
|
AppraiseRecord record = appraiseRecordRepository.findAppraiseRecordByTargetIdAndAcademicYearIdAndCode(
|
|
|
|
AppraiseRecord record = appraiseRecordRepository.findAppraiseRecordByTargetIdAndClassIdAndAcademicYearIdAndCode(
|
|
|
|
targetId,
|
|
|
|
targetId,
|
|
|
|
academicYearId,
|
|
|
|
academicYearId,
|
|
|
|
|
|
|
|
classId,
|
|
|
|
String.format(PK.PK_APPRAISE_RECORD,schoolId)
|
|
|
|
String.format(PK.PK_APPRAISE_RECORD,schoolId)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -269,18 +293,16 @@ public class EvaluationServiceImpl implements EvaluationService {
|
|
|
|
item.setCreatorId(loginUser.getId());
|
|
|
|
item.setCreatorId(loginUser.getId());
|
|
|
|
item.setCreateTime(LocalDateTime.now());
|
|
|
|
item.setCreateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
|
|
// 不存在则创建一条新的,存在则处理一下分值后再向其 nodes 中插入一条 item
|
|
|
|
// 不存在或者学生的班级不一样则创建一条新的,存在则处理一下分值后再向其 nodes 中插入一条 item
|
|
|
|
if (record == null) {
|
|
|
|
if (record == null || !classId.equals(record.getClassId())) {
|
|
|
|
List<AppraiseRecordItem> items = Collections.singletonList(item);
|
|
|
|
List<AppraiseRecordItem> items = Collections.singletonList(item);
|
|
|
|
|
|
|
|
|
|
|
|
record = new AppraiseRecord();
|
|
|
|
record = new AppraiseRecord();
|
|
|
|
if (targetType.equals(TARGET_STUDENT)) {
|
|
|
|
|
|
|
|
record.setTargetType(TARGET_STUDENT);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
record.setTargetType(TARGET_CLASS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
record.setTargetId(targetId);
|
|
|
|
record.setTargetId(targetId);
|
|
|
|
|
|
|
|
record.setTargetType(targetType);
|
|
|
|
record.setClassId(classId);
|
|
|
|
record.setClassId(classId);
|
|
|
|
|
|
|
|
record.setName(name);
|
|
|
|
|
|
|
|
record.setAvatar(avatar);
|
|
|
|
record.setAcademicYearId(academicYearId);
|
|
|
|
record.setAcademicYearId(academicYearId);
|
|
|
|
record.setPraiseCount(appraiseTreeNode.isPraise() ? 1 : -1);
|
|
|
|
record.setPraiseCount(appraiseTreeNode.isPraise() ? 1 : -1);
|
|
|
|
record.setScore(ObjectUtils.isEmpty(appraiseTreeNode.getScore()) ? 0 : appraiseTreeNode.getScore());
|
|
|
|
record.setScore(ObjectUtils.isEmpty(appraiseTreeNode.getScore()) ? 0 : appraiseTreeNode.getScore());
|
|
|
|