diff --git a/src/main/java/cn/teammodel/ai/SparkGptClient.java b/src/main/java/cn/teammodel/ai/SparkGptClient.java index af75b02..fd008df 100644 --- a/src/main/java/cn/teammodel/ai/SparkGptClient.java +++ b/src/main/java/cn/teammodel/ai/SparkGptClient.java @@ -49,7 +49,7 @@ public class SparkGptClient implements InitializingBean { this.okHttpClient = new OkHttpClient() .newBuilder() .connectTimeout(90, TimeUnit.SECONDS) - .readTimeout(90, TimeUnit.SECONDS) + .readTimeout(90, TimeUnit.SECONDS) // sse 接口的 readTimeout 不能设置小了 .writeTimeout(90, TimeUnit.SECONDS) .build(); } diff --git a/src/main/java/cn/teammodel/common/FiveEducations.java b/src/main/java/cn/teammodel/common/FiveEducations.java index 2efd603..e286993 100644 --- a/src/main/java/cn/teammodel/common/FiveEducations.java +++ b/src/main/java/cn/teammodel/common/FiveEducations.java @@ -1,13 +1,50 @@ package cn.teammodel.common; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + /** + * 五育枚举 * @author winter * @create 2023-12-14 12:19 */ -public interface FiveEducations { - String MORAL = "美德"; - String INTELLECTUAL = "美智"; - String PHYSICAL = "体育"; - String AESTHETIC = "美艺"; - String LABOUR = "劳动"; +public enum FiveEducations { + VIRTUE("virtue", "德育"), + INTELLIGENCE("intelligence","智育"), + SPORTS("sports", "体育"), + ART("art", "美育"), + LABOUR("labour", "劳育"); + + private final String code; + private final String name; + + public static List 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; + } } diff --git a/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java b/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java index e8803d8..f3373c8 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java @@ -5,12 +5,10 @@ import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto; import cn.teammodel.model.entity.appraise.AchievementRule; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.validation.Valid; import java.util.List; /** @@ -25,8 +23,15 @@ public class AdminAppraiseController { @PostMapping("updateAchieveRule") @ApiOperation("更新的 rule 节点将会直接覆盖老节点") - public R> updateAchieveRule(@RequestBody UpdateAchievementRuleDto ruleDto) { + public R> updateAchieveRule(@RequestBody @Valid UpdateAchievementRuleDto ruleDto) { List res = adminAppraiseService.updateAchieveRule(ruleDto); return R.success(res); } + + @GetMapping("getAchieveRules/{periodId}") + @ApiOperation("获取当前学段下的成就规则") + public R> getAchieveRules(@PathVariable String periodId){ + List res = adminAppraiseService.getAchieveRules(periodId); + return R.success(res); + } } diff --git a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java index e5862b9..acf64ac 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java @@ -32,4 +32,6 @@ public interface AdminAppraiseService { List studentRank(TimeRangeDto timeRangeDto); List updateAchieveRule(UpdateAchievementRuleDto ruleDto); + + List getAchieveRules(String periodId); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java index 8e881ff..e8f043d 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java @@ -61,7 +61,7 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { @Override public IndexData getIndexData(String periodId) { - final int SLICE_SIZE = 10; + final int SLICE_SIZE = 100; if (StringUtils.isBlank(periodId)) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空"); } @@ -322,13 +322,15 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { public List updateAchieveRule(UpdateAchievementRuleDto ruleDto) { String periodId = ruleDto.getPeriodId(); UpdateAchievementRuleDto.UpdateRule updateRule = ruleDto.getUpdateRule(); - // fixme: 判断 参数 - if (ObjectUtils.isEmpty(updateRule) || StringUtils.isBlank(updateRule.getId())) { - throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "rule id 不能为空"); + + if (ObjectUtils.isEmpty(updateRule) || StringUtils.isBlank(updateRule.getId()) || ObjectUtils.isEmpty(updateRule.getName())) { + 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(); String schoolId = user.getSchoolId(); -// String schoolId = "template"; Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "参数错误,找不到该学段下的评价规则"); List rules = appraise.getAchievementRules(); @@ -360,4 +362,17 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { return saved.getAchievementRules(); } + @Override + public List getAchieveRules(String periodId) { + User user = SecurityUtil.getLoginUser(); + String schoolId = user.getSchoolId(); + + Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "还未创建该学段下的评价规则"); + List rules = appraise.getAchievementRules(); + if (ObjectUtils.isEmpty(rules)) { + rules = Collections.emptyList(); + } + return rules; + } + } diff --git a/src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java index e5476a3..faca0fc 100644 --- a/src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java @@ -12,6 +12,6 @@ import javax.validation.constraints.NotNull; public class DeleteNodeDto { @NotNull(message = "学段 id 不能为空") String periodId; - @NotNull + @NotNull(message = "评价项节点 id 不能为空") String id; } diff --git a/src/main/java/cn/teammodel/model/dto/admin/UpdateAchievementRuleDto.java b/src/main/java/cn/teammodel/model/dto/admin/UpdateAchievementRuleDto.java index fc78663..e6e2beb 100644 --- a/src/main/java/cn/teammodel/model/dto/admin/UpdateAchievementRuleDto.java +++ b/src/main/java/cn/teammodel/model/dto/admin/UpdateAchievementRuleDto.java @@ -19,27 +19,16 @@ public class UpdateAchievementRuleDto { @Data public static class UpdateRule { - @NotNull private String id; /** * 等级名称 */ - @NotNull - private String name; - /** - * 等级 logo - */ - @NotNull - private String logo; - /** - * 每次所需表扬数 - */ - @NotNull - private Integer levelCount; - /** - * 晋级所需下一等级所需当前等级次数 - */ - @NotNull - private Integer promotionLevel; + private String name = ""; + @ApiModelProperty("等级 logo") + private String logo = ""; + @ApiModelProperty("每次所需表扬数") + private Integer levelCount = 0; + @ApiModelProperty("晋级所需下一等级所需当前等级次数") + private Integer promotionLevel = 0; } } diff --git a/src/main/java/cn/teammodel/model/vo/admin/IndexData.java b/src/main/java/cn/teammodel/model/vo/admin/IndexData.java index dc167a0..f1c0d47 100644 --- a/src/main/java/cn/teammodel/model/vo/admin/IndexData.java +++ b/src/main/java/cn/teammodel/model/vo/admin/IndexData.java @@ -1,5 +1,6 @@ package cn.teammodel.model.vo.admin; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Map; @@ -10,10 +11,16 @@ import java.util.Map; */ @Data public class IndexData { + @ApiModelProperty("评价数据的总数") private Integer totalCount = 0; + @ApiModelProperty("表扬总数") private Integer praiseCount = 0; + @ApiModelProperty("批评总数") private Integer criticalCount = 0; + @ApiModelProperty("使用老师的总数") private Integer teacherCount = 0; + @ApiModelProperty("被评价学生的总数") private Integer studentCount = 0; + @ApiModelProperty("学期中按周分布的评级数据") private Map countByWeek; } diff --git a/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java b/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java index 04ede5f..aeeeb48 100644 --- a/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java +++ b/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java @@ -1,9 +1,11 @@ package cn.teammodel.model.vo.appraise; +import cn.teammodel.common.FiveEducations; import cn.teammodel.model.entity.appraise.AchievementRule; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.HashMap; import java.util.Map; /** @@ -23,4 +25,13 @@ public class StudentReportVo { private Map criticalDistribution; @ApiModelProperty("学生当前成就") private AchievementRule curAchievement; + + public static Map ofFiveEducation() { + Map initialMap = new HashMap<>(); + FiveEducations.codes().forEach(item -> { + initialMap.put(item, 0); + }); + + return initialMap; + } } diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index b0ed0de..3b7e71c 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -3,6 +3,7 @@ package cn.teammodel.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.UUID; import cn.teammodel.common.ErrorCode; +import cn.teammodel.common.FiveEducations; import cn.teammodel.common.IdRequest; import cn.teammodel.common.PK; import cn.teammodel.config.exception.ServiceException; @@ -67,7 +68,7 @@ public class EvaluationServiceImpl implements EvaluationService { // 拿到要新增节点的原始数据 Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); if (appraise == null) { - throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在"); + throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该学段下评价项数据不存在"); } return appraise; } @@ -437,8 +438,8 @@ public class EvaluationServiceImpl implements EvaluationService { } StudentReportVo reportVo = new StudentReportVo(); // 计算雷达图 - Map praiseDistribution = new HashMap<>(); - Map criticalDistribution = new HashMap<>(); + Map praiseDistribution = StudentReportVo.ofFiveEducation(); + Map criticalDistribution = StudentReportVo.ofFiveEducation(); for (AppraiseRecordItem record : records) { AppraiseTreeNode appraiseNode = record.getAppraiseNode(); String[] path = appraiseNode.getPath(); @@ -447,10 +448,16 @@ public class EvaluationServiceImpl implements EvaluationService { continue; } String root = path[0]; + // 一级评价项不在预期中 + String key = FiveEducations.getCodeByName(root); + if (key == null) { + // todo: 这里的数据异常情况是否需要上报一下 + continue; + } if (appraiseNode.isPraise()) { - praiseDistribution.put(root, praiseDistribution.getOrDefault(root, 0) + 1); + praiseDistribution.put(key, praiseDistribution.getOrDefault(key, 0) + 1); } else { - criticalDistribution.put(root, criticalDistribution.getOrDefault(root, 0) + 1); + criticalDistribution.put(key, criticalDistribution.getOrDefault(key, 0) + 1); } } // 计算成就项 (排序 diff --git a/src/test/java/cn/teammodel/TestWithoutSpring.java b/src/test/java/cn/teammodel/TestWithoutSpring.java index 66f31e6..489b835 100644 --- a/src/test/java/cn/teammodel/TestWithoutSpring.java +++ b/src/test/java/cn/teammodel/TestWithoutSpring.java @@ -1,5 +1,6 @@ package cn.teammodel; +import cn.teammodel.common.FiveEducations; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.school.School; @@ -178,6 +179,8 @@ public class TestWithoutSpring { Integer a = 1000; int b = 1000; // 包装类碰到基本类型,会自动拆箱,这时候用 == 没事 - System.out.println(a == b); +// System.out.println(a == b); + + System.out.println(FiveEducations.codes()); } }