feat: 新增撤回评价的接口

11111
winter 1 year ago
parent 6c47e0c59e
commit a3922d8c2d

@ -0,0 +1,15 @@
package cn.teammodel.common;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author winter
* @create 2023-12-04 9:55
*/
@Data
public class IdRequest {
@NotBlank(message = "id 不能为空")
private String id;
}

@ -57,6 +57,12 @@ public class AppraiseController {
evaluationService.vote(appraiseVoteDto); evaluationService.vote(appraiseVoteDto);
return R.success("评价成功"); return R.success("评价成功");
} }
@PostMapping("recallVote")
@ApiOperation(value = "撤回给某个学生评价(投票)")
public R<String> recallVote(@RequestBody @Valid RecallVoteDto recallVoteDto) {
evaluationService.recallVote(recallVoteDto);
return R.success("撤回评价成功");
}
@PostMapping("findVoteRecord") @PostMapping("findVoteRecord")
@ApiOperation(value = "多条件查询当前登录老师的学生评价(投票)") @ApiOperation(value = "多条件查询当前登录老师的学生评价(投票)")

@ -24,7 +24,7 @@ public interface AppraiseRecordRepository extends CosmosRepository<AppraiseRecor
/** /**
* *
*/ */
AppraiseRecord findAppraiseRecordByTargetIdAndClassIdAndAcademicYearIdAndCode(String targetId, String academicYearId, String classId , String code); AppraiseRecord findAppraiseRecordByTargetIdAndClassIdAndAcademicYearIdAndCode(String targetId, String classId, String academicYearId, String code);
@Query("select c.id, c.praiseCount, c.score from Student as c where c.targetId = @targetId and c.academicYearId = @academicYearId and c.code = @code") @Query("select c.id, c.praiseCount, c.score from Student as c where c.targetId = @targetId and c.academicYearId = @academicYearId and c.code = @code")
List<AppraiseRecord> findScoreAndPraise(String targetId,String academicYearId,String code); List<AppraiseRecord> findScoreAndPraise(String targetId,String academicYearId,String code);

@ -19,6 +19,7 @@ public class InsertNodeDto {
@NotBlank(message = "name 不能为空") @NotBlank(message = "name 不能为空")
String name; String name;
String logo; String logo;
Integer order; Integer order = 0;
Integer score = 0;
boolean isPraise; boolean isPraise;
} }

@ -0,0 +1,20 @@
package cn.teammodel.model.dto.Appraise;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author winter
* @create 2023-11-22 16:16
*/
@Data
public class RecallVoteDto {
@NotNull
@ApiModelProperty("学生评价记录的文档id")
String recordId;
@NotNull
@ApiModelProperty("学生评价记录的具体节点id")
String nodeId;
}

@ -50,4 +50,6 @@ public interface EvaluationService {
void vote(AppraiseVoteDto appraiseVoteDto); void vote(AppraiseVoteDto appraiseVoteDto);
List<AppraiseRecordItem> findVoteRecord(FindVoteRecordDto findVoteRecordDto); List<AppraiseRecordItem> findVoteRecord(FindVoteRecordDto findVoteRecordDto);
void recallVote(RecallVoteDto recallVoteDto);
} }

@ -27,10 +27,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -243,7 +240,7 @@ public class EvaluationServiceImpl implements EvaluationService {
String periodId; String periodId;
String name; String name;
String avatar = null; String avatar = null;
// 判断评价对象是否合法 // 分别对班级和学生的关键信息取值
if (targetType.equals(TARGET_STUDENT)) { if (targetType.equals(TARGET_STUDENT)) {
Student student = studentRepository.findStudentByIdAndCode(targetId, String.format(PK.STUDENT, schoolId)); Student student = studentRepository.findStudentByIdAndCode(targetId, String.format(PK.STUDENT, schoolId));
if (student == null) { if (student == null) {
@ -280,8 +277,8 @@ public class EvaluationServiceImpl implements EvaluationService {
// 查询是否存在记录 // 查询是否存在记录
AppraiseRecord record = appraiseRecordRepository.findAppraiseRecordByTargetIdAndClassIdAndAcademicYearIdAndCode( AppraiseRecord record = appraiseRecordRepository.findAppraiseRecordByTargetIdAndClassIdAndAcademicYearIdAndCode(
targetId, targetId,
academicYearId,
classId, classId,
academicYearId,
String.format(PK.PK_APPRAISE_RECORD,schoolId) String.format(PK.PK_APPRAISE_RECORD,schoolId)
); );
@ -350,6 +347,36 @@ public class EvaluationServiceImpl implements EvaluationService {
return appraiseRecordItems; return appraiseRecordItems;
} }
@Override
public void recallVote(RecallVoteDto recallVoteDto) {
String recordId = recallVoteDto.getRecordId();
String nodeId = recallVoteDto.getNodeId();
User loginUser = SecurityUtil.getLoginUser();
String schoolId = loginUser.getSchoolId();
String userId = loginUser.getId();
Optional<AppraiseRecord> optional = appraiseRecordRepository.findById(recordId, PK.buildOf(PK.PK_APPRAISE_RECORD, schoolId));
AppraiseRecord appraiseRecord = optional.orElseThrow(() -> new ServiceException("该记录不存在"));
AppraiseRecordItem record = appraiseRecord.getNodes()
.stream()
.filter(item -> nodeId.equals(item.getId()))
.findFirst().orElseThrow(() -> new ServiceException("该记录节点不存在"));
// 鉴权(不是创建老师不能撤回)
if (!userId.equals(record.getCreatorId())) {
throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您不是创建老师,不能撤回");
}
// 删除评价项并且恢复评分
appraiseRecord.getNodes().removeIf(item -> nodeId.equals(item.getId()));
boolean praise = record.getAppraiseNode().isPraise();
Integer newPraiseCount = appraiseRecord.getPraiseCount() + (praise ? -1 : 1);
appraiseRecord.setPraiseCount(newPraiseCount);
int score = record.getAppraiseNode().getScore() == null ? 0 : record.getAppraiseNode().getScore();
Integer newScore = appraiseRecord.getScore() - score;
appraiseRecord.setScore(newScore);
// 保存
appraiseRecordRepository.save(appraiseRecord);
}
/** /**
* id id () * id id ()
*/ */

Loading…
Cancel
Save