master
小萌新 3 months ago
parent 3f63df9f86
commit 40a04bf19d
  1. 5
      pom.xml
  2. 2
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  3. 14
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java

@ -35,7 +35,10 @@
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<version>5.1.5.RELEASE</version> <version>5.1.5.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId> <artifactId>poi</artifactId>

@ -71,9 +71,7 @@ public class Chapter implements Serializable {
private String courseObjectivesId; private String courseObjectivesId;
@ApiModelProperty(value = "总学时") @ApiModelProperty(value = "总学时")
//使用参数合法性校验
@Digits(integer = 10, fraction = 1, message = "总学时只能保留一位小数") @Digits(integer = 10, fraction = 1, message = "总学时只能保留一位小数")
// package com.teaching.backend.exception;需要在这个里面添加异常处理
private double totalClassHours; private double totalClassHours;
@ApiModelProperty(value = "要求") @ApiModelProperty(value = "要求")

@ -244,8 +244,9 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
BigDecimal remainingHours = BigDecimal.ZERO; // 初始化剩余学时 BigDecimal remainingHours = BigDecimal.ZERO; // 初始化剩余学时
if (pid == null) { if (pid == null||pid.equals(0L)) {
BigDecimal classHours = coursesMapper.getClassHoursById(chapterDTO.getCourseId()); BigDecimal classHours = coursesMapper.getClassHoursById(chapterDTO.getCourseId());
LambdaQueryWrapper<Chapter> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Chapter::getPid, 0) lambdaQueryWrapper.eq(Chapter::getPid, 0)
.eq(Chapter::getCourseId, chapterDTO.getCourseId()); .eq(Chapter::getCourseId, chapterDTO.getCourseId());
@ -258,10 +259,10 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
remainingHours = classHours.subtract(totalChapterHours).setScale(1, RoundingMode.HALF_UP); remainingHours = classHours.subtract(totalChapterHours).setScale(1, RoundingMode.HALF_UP);
BigDecimal newChapterHours = BigDecimal.valueOf(chapter.getTotalClassHours()); // 根据实际返回类型调整
if (newChapterHours.compareTo(remainingHours) <= 0) {
if (totalChapterHours.compareTo(classHours) < 0) {
chapter.setPid(0L); chapter.setPid(0L);
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>();
maxSortWrapper.eq(Chapter::getPid, 0).orderByDesc(Chapter::getOrderNum).last("limit 1"); maxSortWrapper.eq(Chapter::getPid, 0).orderByDesc(Chapter::getOrderNum).last("limit 1");
@ -274,10 +275,12 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
chapter.setCreateTime(LocalDateTime.now()); chapter.setCreateTime(LocalDateTime.now());
chapter.setUpdateTime(LocalDateTime.now()); chapter.setUpdateTime(LocalDateTime.now());
this.save(chapter); this.save(chapter);
remainingHours = remainingHours.subtract(newChapterHours).setScale(1, RoundingMode.HALF_UP);
} else { } else {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前课程的总学时已经分配完成,请先修改章节学时,或者课程总学时"); throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前添加的学时为:"+newChapterHours+"当前剩余学时为:"+remainingHours);
} }
} else { }
else {
BigDecimal chapterHours = chapterMapper.getChapterHours(pid); BigDecimal chapterHours = chapterMapper.getChapterHours(pid);
@ -297,7 +300,6 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
remainingHours = chapterHours.subtract(hours).setScale(1, RoundingMode.HALF_UP); remainingHours = chapterHours.subtract(hours).setScale(1, RoundingMode.HALF_UP);

Loading…
Cancel
Save