From 40a04bf19d9bdd8d3209116a0ea0aab434aa22db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=90=8C=E6=96=B0?=
<13658798+jjhyyds@user.noreply.gitee.com>
Date: Mon, 26 Aug 2024 02:16:05 +0800
Subject: [PATCH] 8.26
---
pom.xml | 5 ++++-
.../backend/model/entity/chapter/Chapter.java | 2 --
.../service/impl/chapter/ChapterServiceImpl.java | 14 ++++++++------
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index 1f52a11..1ac3f4e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,10 @@
spring-test
5.1.5.RELEASE
-
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.apache.poi
poi
diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
index 9a2f6f6..7e80163 100644
--- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
+++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
@@ -71,9 +71,7 @@ public class Chapter implements Serializable {
private String courseObjectivesId;
@ApiModelProperty(value = "总学时")
- //使用参数合法性校验
@Digits(integer = 10, fraction = 1, message = "总学时只能保留一位小数")
-// package com.teaching.backend.exception;需要在这个里面添加异常处理
private double totalClassHours;
@ApiModelProperty(value = "要求")
diff --git a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
index 8ce1301..db393d3 100644
--- a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
+++ b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
@@ -244,8 +244,9 @@ public class ChapterServiceImpl extends ServiceImpl impl
BigDecimal remainingHours = BigDecimal.ZERO; // 初始化剩余学时
- if (pid == null) {
+ if (pid == null||pid.equals(0L)) {
BigDecimal classHours = coursesMapper.getClassHoursById(chapterDTO.getCourseId());
+
LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Chapter::getPid, 0)
.eq(Chapter::getCourseId, chapterDTO.getCourseId());
@@ -258,10 +259,10 @@ public class ChapterServiceImpl extends ServiceImpl impl
.reduce(BigDecimal.ZERO, BigDecimal::add);
remainingHours = classHours.subtract(totalChapterHours).setScale(1, RoundingMode.HALF_UP);
+ BigDecimal newChapterHours = BigDecimal.valueOf(chapter.getTotalClassHours()); // 根据实际返回类型调整
-
- if (totalChapterHours.compareTo(classHours) < 0) {
+ if (newChapterHours.compareTo(remainingHours) <= 0) {
chapter.setPid(0L);
LambdaQueryWrapper maxSortWrapper = new LambdaQueryWrapper<>();
maxSortWrapper.eq(Chapter::getPid, 0).orderByDesc(Chapter::getOrderNum).last("limit 1");
@@ -274,10 +275,12 @@ public class ChapterServiceImpl extends ServiceImpl impl
chapter.setCreateTime(LocalDateTime.now());
chapter.setUpdateTime(LocalDateTime.now());
this.save(chapter);
+ remainingHours = remainingHours.subtract(newChapterHours).setScale(1, RoundingMode.HALF_UP);
} else {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前课程的总学时已经分配完成,请先修改章节学时,或者课程总学时");
+ throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前添加的学时为:"+newChapterHours+"当前剩余学时为:"+remainingHours);
}
- } else {
+ }
+ else {
BigDecimal chapterHours = chapterMapper.getChapterHours(pid);
@@ -297,7 +300,6 @@ public class ChapterServiceImpl extends ServiceImpl impl
-
remainingHours = chapterHours.subtract(hours).setScale(1, RoundingMode.HALF_UP);