diff --git a/src/main/java/com/sztzjy/fund_investment/controller/UserController.java b/src/main/java/com/sztzjy/fund_investment/controller/UserController.java index 0bf4024..b4a8669 100644 --- a/src/main/java/com/sztzjy/fund_investment/controller/UserController.java +++ b/src/main/java/com/sztzjy/fund_investment/controller/UserController.java @@ -6,8 +6,11 @@ import com.sztzjy.fund_investment.annotation.OperateLog; import com.sztzjy.fund_investment.config.security.JwtUser; import com.sztzjy.fund_investment.config.security.TokenProvider; import com.sztzjy.fund_investment.entity.Flow; +import com.sztzjy.fund_investment.entity.PerformanceScore; +import com.sztzjy.fund_investment.entity.PerformanceScoreExample; import com.sztzjy.fund_investment.entity.User; import com.sztzjy.fund_investment.mapper.FlowMapper; +import com.sztzjy.fund_investment.mapper.PerformanceScoreMapper; import com.sztzjy.fund_investment.service.IUserService; import com.sztzjy.fund_investment.util.ResultEntity; import com.sztzjy.fund_investment.util.RsaUtil; @@ -27,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -41,16 +45,19 @@ public class UserController { private AuthenticationManagerBuilder authenticationManagerBuilder; @Autowired private FlowMapper flowMapper; + @Autowired + private PerformanceScoreMapper performanceScoreMapper; + - @ApiOperation(value = "用户登录",httpMethod = "POST") + @ApiOperation(value = "用户登录", httpMethod = "POST") @OperateLog(recordParameters = false) @PostMapping("login") @AnonymousAccess public ResultEntity login(@RequestParam String username, @RequestParam String passwordEncode) { String password; - try{ + try { password = RsaUtil.decryptByPrivateKey(passwordEncode); - }catch (Exception e){ + } catch (Exception e) { return new ResultEntity(HttpStatus.BAD_REQUEST, "密码错误"); } UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); @@ -68,17 +75,17 @@ public class UserController { map.put("schoolId", user.getSchoolId()); Flow flow = flowMapper.selectByPrimaryKey(jwtUser.getUserId()); - if(flow==null){ + if (flow == null) { String uuid = String.valueOf(UUID.randomUUID()); Flow flow1 = new Flow(); flow1.setUserid(jwtUser.getUserId()); flow1.setFlowId(uuid); flowMapper.insert(flow1); - map.put("flowId",uuid); - }else { - map.put("flowId",flow.getFlowId()); + map.put("flowId", uuid); + } else { + map.put("flowId", flow.getFlowId()); } - return new ResultEntity(HttpStatus.OK, map); + return new ResultEntity(HttpStatus.OK, map); } @@ -93,13 +100,20 @@ public class UserController { System.out.println(new BCryptPasswordEncoder().encode(password)); } - @ApiOperation(value = "重新实训",httpMethod = "POST") + @ApiOperation(value = "重新实训", httpMethod = "POST") @PostMapping("reTraining") @AnonymousAccess public ResultEntity reTraining(@RequestParam String userId) { Flow flow = flowMapper.selectByPrimaryKey(userId); flow.setFlowId(IdUtil.simpleUUID()); flowMapper.updateByPrimaryKey(flow); - return new ResultEntity(HttpStatus.OK,"已重新实训!"); + PerformanceScoreExample example = new PerformanceScoreExample(); + example.createCriteria().andFlowIdEqualTo(flow.getFlowId()); + List performanceScores = performanceScoreMapper.selectByExample(example); + if (performanceScores.isEmpty()) { + return null; + } + performanceScoreMapper.deleteByExample(example); + return new ResultEntity(HttpStatus.OK, "已重新实训!"); } } diff --git a/src/main/java/com/sztzjy/fund_investment/controller/tea/ClassScoreController.java b/src/main/java/com/sztzjy/fund_investment/controller/tea/ClassScoreController.java index ed52d64..410e7b3 100644 --- a/src/main/java/com/sztzjy/fund_investment/controller/tea/ClassScoreController.java +++ b/src/main/java/com/sztzjy/fund_investment/controller/tea/ClassScoreController.java @@ -52,7 +52,7 @@ public class ClassScoreController { @AnonymousAccess @GetMapping("/getClassAVGScore") @ApiOperation("成绩管理/班级平均成绩折线图") - public ResultEntity> getClassAVGScore(@RequestParam String schoolId) { + public ResultEntity> getClassAVGScore(@RequestParam String schoolId) { return new ResultEntity<>(classScoreService.getClassAVGScore(schoolId)); } diff --git a/src/main/java/com/sztzjy/fund_investment/entity/dto/ClassAVGScoreVo.java b/src/main/java/com/sztzjy/fund_investment/entity/dto/ClassAVGScoreVo.java new file mode 100644 index 0000000..c415a9e --- /dev/null +++ b/src/main/java/com/sztzjy/fund_investment/entity/dto/ClassAVGScoreVo.java @@ -0,0 +1,54 @@ +package com.sztzjy.fund_investment.entity.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * @Author xcj + * @Date 2023/12/14 + */ +@Data +public class ClassAVGScoreVo { +// private String id; + +// @ApiModelProperty("学校ID") +// private String schoolId; + +// @ApiModelProperty("班级ID") +// private String classId; + + @ApiModelProperty("班级名称") + private String className; + +// @ApiModelProperty("优秀人数") +// private Integer excellentCount; +// +// @ApiModelProperty("良好人数") +// private Integer goodCount; +// +// @ApiModelProperty("一般人数") +// private Integer generalCount; +// +// @ApiModelProperty("不及格人数") +// private Integer failCount; + +// @ApiModelProperty("班级最高分") +// private BigDecimal classMaxScore; +// +// @ApiModelProperty("班级最低分") +// private BigDecimal classMinScore; + + @ApiModelProperty("班级平均分") + private List classAverageScore; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") + @ApiModelProperty("最早得分日期") + private Date startTime; +} diff --git a/src/main/java/com/sztzjy/fund_investment/mapper/TeaClassScoreMapper.java b/src/main/java/com/sztzjy/fund_investment/mapper/TeaClassScoreMapper.java index 708588e..5803207 100644 --- a/src/main/java/com/sztzjy/fund_investment/mapper/TeaClassScoreMapper.java +++ b/src/main/java/com/sztzjy/fund_investment/mapper/TeaClassScoreMapper.java @@ -6,6 +6,8 @@ import java.util.List; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + @Mapper public interface TeaClassScoreMapper { long countByExample(TeaClassScoreExample example); @@ -30,5 +32,8 @@ public interface TeaClassScoreMapper { int updateByPrimaryKey(TeaClassScore record); - List selectAndOrderByTime(@Param("schoolId")String schoolId); + List selectAndOrderByTime(@Param("schoolId")String schoolId,@Param("className")String className); + + @Select("select class_name from tea_class_score where school_id = #{schoolId} group by class_name") + List selectClassNameBySchool(@Param("schoolId")String schoolId); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/tea/ClassScoreServiceImpl.java b/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/tea/ClassScoreServiceImpl.java index f7961ae..6f79328 100644 --- a/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/tea/ClassScoreServiceImpl.java +++ b/src/main/java/com/sztzjy/fund_investment/service/serviceImpl/tea/ClassScoreServiceImpl.java @@ -50,13 +50,31 @@ public class ClassScoreServiceImpl implements ClassScoreService { private IFileUtil fileUtil; - /* + /* 班级平均成绩走势图 * @author xcj * @Date 2023/11/24 */ @Override - public List getClassAVGScore(String schoolId) { - return teaClassScoreMapper.selectAndOrderByTime(schoolId); + public List getClassAVGScore(String schoolId) { + List classNameList = teaClassScoreMapper.selectClassNameBySchool(schoolId); + List voList = new ArrayList<>(); + for (String className : classNameList) { + ClassAVGScoreVo vo = new ClassAVGScoreVo(); + vo.setClassName(className); + List list = teaClassScoreMapper.selectAndOrderByTime(schoolId, className); + if (list.isEmpty()) { + continue; + } + TeaClassScore teaClassScore = list.get(0); + vo.setStartTime(teaClassScore.getStartTime()); + List scoreList = new ArrayList(); + for (TeaClassScore classScore : list) { + scoreList.add(classScore.getClassAverageScore()); + } + vo.setClassAverageScore(scoreList); + voList.add(vo); + } + return voList; } diff --git a/src/main/java/com/sztzjy/fund_investment/service/tea/ClassScoreService.java b/src/main/java/com/sztzjy/fund_investment/service/tea/ClassScoreService.java index 4f0ac8d..4686e10 100644 --- a/src/main/java/com/sztzjy/fund_investment/service/tea/ClassScoreService.java +++ b/src/main/java/com/sztzjy/fund_investment/service/tea/ClassScoreService.java @@ -17,7 +17,7 @@ import java.util.Map; * @Date 2023/11/24 */ public interface ClassScoreService { - List getClassAVGScore(String schoolId); + List getClassAVGScore(String schoolId); TeaClassScoreDto getClassScoreCount(String schoolId, String classId, Date time); diff --git a/src/main/resources/mappers/TeaClassScoreMapper.xml b/src/main/resources/mappers/TeaClassScoreMapper.xml index d6448e0..0c51bef 100644 --- a/src/main/resources/mappers/TeaClassScoreMapper.xml +++ b/src/main/resources/mappers/TeaClassScoreMapper.xml @@ -97,7 +97,8 @@ from tea_class_score where school_id = #{schoolId,jdbcType=VARCHAR} - and start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH) + AND class_name = #{className} + AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH) order by start_time