refactor: 调整评价树的学段id,现摒弃default为默认,每个学段id都有自己的评价树

11111
winter 1 year ago
parent 646caaa926
commit d185a3ffe7

@ -29,26 +29,26 @@ public class AppraiseController {
@PostMapping("getTrees") @PostMapping("getTrees")
@ApiOperation(value = "获取评价树", notes = "获取评价树") @ApiOperation(value = "获取评价树", notes = "获取评价树")
public R<Appraise> getEvaluateTree(@RequestBody GetEvaluateTreeDto getEvaluateTreeDto) { public R<Appraise> getEvaluateTree(@RequestBody @Valid GetEvaluateTreeDto getEvaluateTreeDto) {
Appraise appraise = evaluationService.getTree(getEvaluateTreeDto); Appraise appraise = evaluationService.getTree(getEvaluateTreeDto);
return R.success(appraise); return R.success(appraise);
} }
@PostMapping("insertNode") @PostMapping("insertNode")
@ApiOperation(value = "新增评价树的节点") @ApiOperation(value = "新增评价树的节点")
public R<Appraise> insertNode(@RequestBody InsertNodeDto insertNodeDto) { public R<Appraise> insertNode(@RequestBody @Valid InsertNodeDto insertNodeDto) {
Appraise appraise = evaluationService.insertNode(insertNodeDto); Appraise appraise = evaluationService.insertNode(insertNodeDto);
return R.success(appraise); return R.success(appraise);
} }
@PostMapping("updateNode") @PostMapping("updateNode")
@ApiOperation(value = "更新评价树的节点", notes = "传递更新后的节点,而不是局部更新的值") @ApiOperation(value = "更新评价树的节点", notes = "传递更新后的节点,而不是局部更新的值")
public R<Appraise> updateTree(@RequestBody UpdateNodeDto updateNodeDto) { public R<Appraise> updateTree(@RequestBody @Valid UpdateNodeDto updateNodeDto) {
Appraise appraise = evaluationService.updateNode(updateNodeDto); Appraise appraise = evaluationService.updateNode(updateNodeDto);
return R.success(appraise); return R.success(appraise);
} }
@PostMapping("deleteNode") @PostMapping("deleteNode")
@ApiOperation(value = "删除评价树的节点") @ApiOperation(value = "删除评价树的节点")
public R<Appraise> deleteNode(@Valid @RequestBody DeleteNodeDto deleteNodeDto) { public R<Appraise> deleteNode(@RequestBody @Valid DeleteNodeDto deleteNodeDto) {
Appraise appraise = evaluationService.deleteNode(deleteNodeDto); Appraise appraise = evaluationService.deleteNode(deleteNodeDto);
return R.success(appraise); return R.success(appraise);
} }

@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
*/ */
@Data @Data
public class DeleteNodeDto { public class DeleteNodeDto {
// 检索需要,但是有 bug @NotNull(message = "学段 id 不能为空")
String periodId; String periodId;
@NotNull @NotNull
String id; String id;

@ -25,7 +25,7 @@ public class FindVoteRecordDto extends PageableRequest {
@ApiModelProperty(value = "评价对象类型:", allowableValues = "student ,class") @ApiModelProperty(value = "评价对象类型:", allowableValues = "student ,class")
private String targetType; private String targetType;
@ApiModelProperty(value = "按班级 id搜索") @ApiModelProperty(value = "按班级 id 搜索")
private String classId; private String classId;
@ApiModelProperty(value = "是否为表扬") @ApiModelProperty(value = "是否为表扬")
private Boolean isPraise; private Boolean isPraise;

@ -3,12 +3,15 @@ package cn.teammodel.model.dto.Appraise;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
/** /**
* @author winter * @author winter
* @create 2023-11-22 15:21 * @create 2023-11-22 15:21
*/ */
@Data @Data
public class GetEvaluateTreeDto { public class GetEvaluateTreeDto {
@ApiModelProperty("学段 id, 默认为 default") @ApiModelProperty(value = "学段 id", required = true)
@NotNull(message = "学段 id 不能为空")
String periodId; String periodId;
} }

@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** /**
* @author winter * @author winter
@ -11,7 +12,8 @@ import javax.validation.constraints.NotBlank;
*/ */
@Data @Data
public class InsertNodeDto { public class InsertNodeDto {
@ApiModelProperty(value = "不传则默认为 default 的树增加节点") @ApiModelProperty(value = "学段 id", required = true)
@NotNull(message = "学段 id 不能为空")
String periodId; String periodId;
@ApiModelProperty(value = "父亲节点,不传则为根节点") @ApiModelProperty(value = "父亲节点,不传则为根节点")
String pid; String pid;

@ -3,13 +3,16 @@ package cn.teammodel.model.dto.Appraise;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
/** /**
* @author winter * @author winter
* @create 2023-11-22 16:16 * @create 2023-11-22 16:16
*/ */
@Data @Data
public class UpdateNodeDto { public class UpdateNodeDto {
@ApiModelProperty(value = "不传则默认为 default 的树修改节点") @ApiModelProperty(value = "学段 id", required = true)
@NotNull(message = "学段 id 不能为空")
String periodId; String periodId;
@ApiModelProperty(value = "评价项节点的 id") @ApiModelProperty(value = "评价项节点的 id")
String id; String id;

@ -60,8 +60,6 @@ public class EvaluationServiceImpl implements EvaluationService {
* token schoolId * token schoolId
*/ */
private Appraise findAppraise(String periodId) { private Appraise findAppraise(String periodId) {
// 默认学区为 default
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
User loginUser = SecurityUtil.getLoginUser(); User loginUser = SecurityUtil.getLoginUser();
String schoolId = loginUser.getSchoolId(); String schoolId = loginUser.getSchoolId();
@ -76,8 +74,6 @@ public class EvaluationServiceImpl implements EvaluationService {
@Override @Override
public Appraise getTree(GetEvaluateTreeDto getEvaluateTreeDto) { public Appraise getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
String periodId = getEvaluateTreeDto.getPeriodId(); String periodId = getEvaluateTreeDto.getPeriodId();
// 默认学区为 default
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
User loginUser = SecurityUtil.getLoginUser(); User loginUser = SecurityUtil.getLoginUser();
String schoolId = loginUser.getSchoolId(); String schoolId = loginUser.getSchoolId();
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
@ -279,7 +275,10 @@ public class EvaluationServiceImpl implements EvaluationService {
// 获取评价项节点 // 获取评价项节点
List<AppraiseTreeNode> nodes = appraiseRepository.findNodeById(PK.PK_APPRAISE, appraiseId); List<AppraiseTreeNode> nodes = appraiseRepository.findNodeById(PK.PK_APPRAISE, appraiseId);
AppraiseTreeNode appraiseTreeNode = RepositoryUtil.findOne(nodes, "获取评价项失败"); AppraiseTreeNode appraiseTreeNode = RepositoryUtil.findOne(nodes, "该评价项不存在");
if (appraiseTreeNode.getPath() == null) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "仅能评价三级评价项");
}
// 通过 periodId 获取 semesters // 通过 periodId 获取 semesters
List<School.Period> periodById = schoolRepository.findPeriodById(schoolId, periodId); List<School.Period> periodById = schoolRepository.findPeriodById(schoolId, periodId);
@ -439,6 +438,10 @@ public class EvaluationServiceImpl implements EvaluationService {
for (AppraiseRecordItem record : records) { for (AppraiseRecordItem record : records) {
AppraiseTreeNode appraiseNode = record.getAppraiseNode(); AppraiseTreeNode appraiseNode = record.getAppraiseNode();
String[] path = appraiseNode.getPath(); String[] path = appraiseNode.getPath();
// 数据异常则跳过
if (path == null || path.length == 0){
continue;
}
String root = path[0]; String root = path[0];
if (appraiseNode.isPraise()) { if (appraiseNode.isPraise()) {
praiseDistribution.put(root, praiseDistribution.getOrDefault(root, 0) + 1); praiseDistribution.put(root, praiseDistribution.getOrDefault(root, 0) + 1);

@ -19,7 +19,7 @@ public class RepositoryUtil {
public static <T> T findOne(List<T> list, String errorMsg) { public static <T> T findOne(List<T> list, String errorMsg) {
if (ObjectUtils.isEmpty(list) || list.size() > 1) { if (ObjectUtils.isEmpty(list) || list.size() > 1) {
log.error("查询结果为空或数量 > 1"); log.error("查询结果为空或数量 > 1");
throw new ServiceException(ErrorCode.PARAMS_ERROR); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), errorMsg);
} }
return list.get(0); return list.get(0);
} }

Loading…
Cancel
Save