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

11111
winter 1 year ago
parent 646caaa926
commit d185a3ffe7

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

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

@ -3,12 +3,15 @@ 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 15:21
*/
@Data
public class GetEvaluateTreeDto {
@ApiModelProperty("学段 id, 默认为 default")
@ApiModelProperty(value = "学段 id", required = true)
@NotNull(message = "学段 id 不能为空")
String periodId;
}

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

@ -3,13 +3,16 @@ 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 UpdateNodeDto {
@ApiModelProperty(value = "不传则默认为 default 的树修改节点")
@ApiModelProperty(value = "学段 id", required = true)
@NotNull(message = "学段 id 不能为空")
String periodId;
@ApiModelProperty(value = "评价项节点的 id")
String id;

@ -60,8 +60,6 @@ public class EvaluationServiceImpl implements EvaluationService {
* token schoolId
*/
private Appraise findAppraise(String periodId) {
// 默认学区为 default
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
User loginUser = SecurityUtil.getLoginUser();
String schoolId = loginUser.getSchoolId();
@ -76,8 +74,6 @@ public class EvaluationServiceImpl implements EvaluationService {
@Override
public Appraise getTree(GetEvaluateTreeDto getEvaluateTreeDto) {
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);
@ -279,7 +275,10 @@ public class EvaluationServiceImpl implements EvaluationService {
// 获取评价项节点
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
List<School.Period> periodById = schoolRepository.findPeriodById(schoolId, periodId);
@ -439,6 +438,10 @@ public class EvaluationServiceImpl implements EvaluationService {
for (AppraiseRecordItem record : records) {
AppraiseTreeNode appraiseNode = record.getAppraiseNode();
String[] path = appraiseNode.getPath();
// 数据异常则跳过
if (path == null || path.length == 0){
continue;
}
String root = path[0];
if (appraiseNode.isPraise()) {
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) {
if (ObjectUtils.isEmpty(list) || list.size() > 1) {
log.error("查询结果为空或数量 > 1");
throw new ServiceException(ErrorCode.PARAMS_ERROR);
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), errorMsg);
}
return list.get(0);
}

Loading…
Cancel
Save