fix: 修复成就的 by zero 错误和增强参数校验

11111
winter 1 year ago
parent 6cf0ebaef3
commit cec0a7e58d

@ -49,7 +49,7 @@ public class SparkGptClient implements InitializingBean {
this.okHttpClient = new OkHttpClient() this.okHttpClient = new OkHttpClient()
.newBuilder() .newBuilder()
.connectTimeout(90, TimeUnit.SECONDS) .connectTimeout(90, TimeUnit.SECONDS)
.readTimeout(90, TimeUnit.SECONDS) .readTimeout(90, TimeUnit.SECONDS) // sse 接口的 readTimeout 不能设置小了
.writeTimeout(90, TimeUnit.SECONDS) .writeTimeout(90, TimeUnit.SECONDS)
.build(); .build();
} }

@ -1,13 +1,50 @@
package cn.teammodel.common; package cn.teammodel.common;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
*
* @author winter * @author winter
* @create 2023-12-14 12:19 * @create 2023-12-14 12:19
*/ */
public interface FiveEducations { public enum FiveEducations {
String MORAL = "美德"; VIRTUE("virtue", "德育"),
String INTELLECTUAL = "美智"; INTELLIGENCE("intelligence","智育"),
String PHYSICAL = "体育"; SPORTS("sports", "体育"),
String AESTHETIC = "美艺"; ART("art", "美育"),
String LABOUR = "劳动"; LABOUR("labour", "劳育");
private final String code;
private final String name;
public static List<String> codes() {
return Arrays.stream(values()).map(FiveEducations::getCode).collect(Collectors.toList());
}
/**
* name code
*/
public static String getCodeByName(String name) {
FiveEducations fiveEducation = Arrays.stream(values()).filter(item -> item.getName().equals(name)).findFirst().orElse(null);
String res = null;
if (fiveEducation != null) {
res = fiveEducation.getCode();
}
return res;
}
FiveEducations(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
} }

@ -5,12 +5,10 @@ import cn.teammodel.controller.admin.service.AdminAppraiseService;
import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto; import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto;
import cn.teammodel.model.entity.appraise.AchievementRule; import cn.teammodel.model.entity.appraise.AchievementRule;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List; import java.util.List;
/** /**
@ -25,8 +23,15 @@ public class AdminAppraiseController {
@PostMapping("updateAchieveRule") @PostMapping("updateAchieveRule")
@ApiOperation("更新的 rule 节点将会直接覆盖老节点") @ApiOperation("更新的 rule 节点将会直接覆盖老节点")
public R<List<AchievementRule>> updateAchieveRule(@RequestBody UpdateAchievementRuleDto ruleDto) { public R<List<AchievementRule>> updateAchieveRule(@RequestBody @Valid UpdateAchievementRuleDto ruleDto) {
List<AchievementRule> res = adminAppraiseService.updateAchieveRule(ruleDto); List<AchievementRule> res = adminAppraiseService.updateAchieveRule(ruleDto);
return R.success(res); return R.success(res);
} }
@GetMapping("getAchieveRules/{periodId}")
@ApiOperation("获取当前学段下的成就规则")
public R<List<AchievementRule>> getAchieveRules(@PathVariable String periodId){
List<AchievementRule> res = adminAppraiseService.getAchieveRules(periodId);
return R.success(res);
}
} }

@ -32,4 +32,6 @@ public interface AdminAppraiseService {
List<StudentRankVo> studentRank(TimeRangeDto timeRangeDto); List<StudentRankVo> studentRank(TimeRangeDto timeRangeDto);
List<AchievementRule> updateAchieveRule(UpdateAchievementRuleDto ruleDto); List<AchievementRule> updateAchieveRule(UpdateAchievementRuleDto ruleDto);
List<AchievementRule> getAchieveRules(String periodId);
} }

@ -61,7 +61,7 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
@Override @Override
public IndexData getIndexData(String periodId) { public IndexData getIndexData(String periodId) {
final int SLICE_SIZE = 10; final int SLICE_SIZE = 100;
if (StringUtils.isBlank(periodId)) { if (StringUtils.isBlank(periodId)) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空");
} }
@ -322,13 +322,15 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
public List<AchievementRule> updateAchieveRule(UpdateAchievementRuleDto ruleDto) { public List<AchievementRule> updateAchieveRule(UpdateAchievementRuleDto ruleDto) {
String periodId = ruleDto.getPeriodId(); String periodId = ruleDto.getPeriodId();
UpdateAchievementRuleDto.UpdateRule updateRule = ruleDto.getUpdateRule(); UpdateAchievementRuleDto.UpdateRule updateRule = ruleDto.getUpdateRule();
// fixme: 判断 参数
if (ObjectUtils.isEmpty(updateRule) || StringUtils.isBlank(updateRule.getId())) { if (ObjectUtils.isEmpty(updateRule) || StringUtils.isBlank(updateRule.getId()) || ObjectUtils.isEmpty(updateRule.getName())) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "rule id 不能为空"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "rule id/name 不能为空");
}
if (updateRule.getLevelCount() == null || updateRule.getLevelCount() <= 0 || updateRule.getPromotionLevel() == null || updateRule.getPromotionLevel() <= 0) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "规则不能为空或小于等于0");
} }
User user = SecurityUtil.getLoginUser(); User user = SecurityUtil.getLoginUser();
String schoolId = user.getSchoolId(); String schoolId = user.getSchoolId();
// String schoolId = "template";
Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "参数错误,找不到该学段下的评价规则"); Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "参数错误,找不到该学段下的评价规则");
List<AchievementRule> rules = appraise.getAchievementRules(); List<AchievementRule> rules = appraise.getAchievementRules();
@ -360,4 +362,17 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
return saved.getAchievementRules(); return saved.getAchievementRules();
} }
@Override
public List<AchievementRule> getAchieveRules(String periodId) {
User user = SecurityUtil.getLoginUser();
String schoolId = user.getSchoolId();
Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "还未创建该学段下的评价规则");
List<AchievementRule> rules = appraise.getAchievementRules();
if (ObjectUtils.isEmpty(rules)) {
rules = Collections.emptyList();
}
return rules;
}
} }

@ -12,6 +12,6 @@ import javax.validation.constraints.NotNull;
public class DeleteNodeDto { public class DeleteNodeDto {
@NotNull(message = "学段 id 不能为空") @NotNull(message = "学段 id 不能为空")
String periodId; String periodId;
@NotNull @NotNull(message = "评价项节点 id 不能为空")
String id; String id;
} }

@ -19,27 +19,16 @@ public class UpdateAchievementRuleDto {
@Data @Data
public static class UpdateRule { public static class UpdateRule {
@NotNull
private String id; private String id;
/** /**
* *
*/ */
@NotNull private String name = "";
private String name; @ApiModelProperty("等级 logo")
/** private String logo = "";
* logo @ApiModelProperty("每次所需表扬数")
*/ private Integer levelCount = 0;
@NotNull @ApiModelProperty("晋级所需下一等级所需当前等级次数")
private String logo; private Integer promotionLevel = 0;
/**
*
*/
@NotNull
private Integer levelCount;
/**
*
*/
@NotNull
private Integer promotionLevel;
} }
} }

@ -1,5 +1,6 @@
package cn.teammodel.model.vo.admin; package cn.teammodel.model.vo.admin;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.Map; import java.util.Map;
@ -10,10 +11,16 @@ import java.util.Map;
*/ */
@Data @Data
public class IndexData { public class IndexData {
@ApiModelProperty("评价数据的总数")
private Integer totalCount = 0; private Integer totalCount = 0;
@ApiModelProperty("表扬总数")
private Integer praiseCount = 0; private Integer praiseCount = 0;
@ApiModelProperty("批评总数")
private Integer criticalCount = 0; private Integer criticalCount = 0;
@ApiModelProperty("使用老师的总数")
private Integer teacherCount = 0; private Integer teacherCount = 0;
@ApiModelProperty("被评价学生的总数")
private Integer studentCount = 0; private Integer studentCount = 0;
@ApiModelProperty("学期中按周分布的评级数据")
private Map<Long, Integer> countByWeek; private Map<Long, Integer> countByWeek;
} }

@ -1,9 +1,11 @@
package cn.teammodel.model.vo.appraise; package cn.teammodel.model.vo.appraise;
import cn.teammodel.common.FiveEducations;
import cn.teammodel.model.entity.appraise.AchievementRule; import cn.teammodel.model.entity.appraise.AchievementRule;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -23,4 +25,13 @@ public class StudentReportVo {
private Map<String, Integer> criticalDistribution; private Map<String, Integer> criticalDistribution;
@ApiModelProperty("学生当前成就") @ApiModelProperty("学生当前成就")
private AchievementRule curAchievement; private AchievementRule curAchievement;
public static Map<String, Integer> ofFiveEducation() {
Map<String, Integer> initialMap = new HashMap<>();
FiveEducations.codes().forEach(item -> {
initialMap.put(item, 0);
});
return initialMap;
}
} }

@ -3,6 +3,7 @@ package cn.teammodel.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.UUID; import cn.hutool.core.lang.UUID;
import cn.teammodel.common.ErrorCode; import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.FiveEducations;
import cn.teammodel.common.IdRequest; import cn.teammodel.common.IdRequest;
import cn.teammodel.common.PK; import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException; import cn.teammodel.config.exception.ServiceException;
@ -67,7 +68,7 @@ public class EvaluationServiceImpl implements EvaluationService {
// 拿到要新增节点的原始数据 // 拿到要新增节点的原始数据
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
if (appraise == null) { if (appraise == null) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该学段下评价项数据不存在");
} }
return appraise; return appraise;
} }
@ -437,8 +438,8 @@ public class EvaluationServiceImpl implements EvaluationService {
} }
StudentReportVo reportVo = new StudentReportVo(); StudentReportVo reportVo = new StudentReportVo();
// 计算雷达图 // 计算雷达图
Map<String, Integer> praiseDistribution = new HashMap<>(); Map<String, Integer> praiseDistribution = StudentReportVo.ofFiveEducation();
Map<String, Integer> criticalDistribution = new HashMap<>(); Map<String, Integer> criticalDistribution = StudentReportVo.ofFiveEducation();
for (AppraiseRecordItem record : records) { for (AppraiseRecordItem record : records) {
AppraiseTreeNode appraiseNode = record.getAppraiseNode(); AppraiseTreeNode appraiseNode = record.getAppraiseNode();
String[] path = appraiseNode.getPath(); String[] path = appraiseNode.getPath();
@ -447,10 +448,16 @@ public class EvaluationServiceImpl implements EvaluationService {
continue; continue;
} }
String root = path[0]; String root = path[0];
// 一级评价项不在预期中
String key = FiveEducations.getCodeByName(root);
if (key == null) {
// todo: 这里的数据异常情况是否需要上报一下
continue;
}
if (appraiseNode.isPraise()) { if (appraiseNode.isPraise()) {
praiseDistribution.put(root, praiseDistribution.getOrDefault(root, 0) + 1); praiseDistribution.put(key, praiseDistribution.getOrDefault(key, 0) + 1);
} else { } else {
criticalDistribution.put(root, criticalDistribution.getOrDefault(root, 0) + 1); criticalDistribution.put(key, criticalDistribution.getOrDefault(key, 0) + 1);
} }
} }
// 计算成就项 (排序 // 计算成就项 (排序

@ -1,5 +1,6 @@
package cn.teammodel; package cn.teammodel;
import cn.teammodel.common.FiveEducations;
import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.School;
@ -178,6 +179,8 @@ public class TestWithoutSpring {
Integer a = 1000; Integer a = 1000;
int b = 1000; int b = 1000;
// 包装类碰到基本类型,会自动拆箱,这时候用 == 没事 // 包装类碰到基本类型,会自动拆箱,这时候用 == 没事
System.out.println(a == b); // System.out.println(a == b);
System.out.println(FiveEducations.codes());
} }
} }

Loading…
Cancel
Save