添加总目标/思政目标内容逻辑优化(只能填一个内容)

修改知识点--关联目标内容接口
修改目标内容--知识点  数据统计接口,现在可以拿到知识点个数,总学时,占比,以及相关知识点的详细数据(id,name,学时)
master
Alan 3 months ago
parent c3bf152cb0
commit 5c9061d8df
  1. 2
      src/main/java/com/teaching/backend/common/ErrorCode.java
  2. 8
      src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java
  3. 8
      src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java
  4. 4
      src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
  5. 2
      src/main/java/com/teaching/backend/model/dto/courses/ObjectiveContentKnowDTO.java
  6. 6
      src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java
  7. 4
      src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContents.java
  8. 1
      src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java
  9. 23
      src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesVO.java
  10. 11
      src/main/java/com/teaching/backend/model/vo/courses/ObjectiveContentKnowVO.java
  11. 29
      src/main/java/com/teaching/backend/model/vo/knowtmp/KnowTmpVO.java
  12. 3
      src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java
  13. 2
      src/main/java/com/teaching/backend/service/courses/IObjectiveContentKnowService.java
  14. 2
      src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java
  15. 34
      src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
  16. 2
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  17. 166
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java
  18. 34
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java

@ -10,7 +10,7 @@ public enum ErrorCode {
SUCCESS(200, "ok"),
PARAMS_ERROR(40000, "请求参数错误"),
OBJECTIVE_OR_CONTENT_NOT_EXIT(40001, "目标内容id不存在"),
OBJECTIVE_CONTENT_NOT_EXIT(40001, "目标内容不存在"),
KONWID_NOT_EXIT(40002, "没有选择知识点"),
OBJECTIVE_OR_CONTENT_EXIT(40003, "该记录已存在"),
KNOW_NOT_EXIT(40004, "知识点不存在"),

@ -9,6 +9,7 @@ import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CourseObjectivesVO;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -76,5 +77,12 @@ public class CourseObjectivesController {
return ResultUtils.success(courseObjectivesTreeVO);
}
@ApiOperation("列表显示分项目标(用于添加目标内容时选择)")
@GetMapping("/objectiveslist/{courseId}")
public BaseResponse<List<CourseObjectivesVO>> queryCourseObjectivesForAdd(@PathVariable String courseId){
List<CourseObjectivesVO> courseObjectivesVOS = courseObjectivesService.queryCourseObjectivesForAdd(courseId);
return ResultUtils.success(courseObjectivesVOS);
}
}

@ -31,11 +31,11 @@ public class ObjectiveContentKnowController {
IObjectiveContentKnowService objectiveContentKnowService;
@ApiOperation("给分项目标或者是内容添加知识点")
// @ValidateParams({"objectiveId","know"})
@ApiOperation("给知识点关联--目标内容")
@ValidateParams({"objectiveContentId","knowId"})
@PostMapping("/addknows")
public BaseResponse<String> saveKnowsWithObjectiveOrContent(@RequestBody ObjectiveContentKnowDTO objectiveContentKnowDTO){
String data = objectiveContentKnowService.saveKnowsWithObjectiveOrContent(objectiveContentKnowDTO);
public BaseResponse<String> saveKnowsWithObjectiveContent(@RequestBody ObjectiveContentKnowDTO objectiveContentKnowDTO){
String data = objectiveContentKnowService.saveKnowsWithObjectiveContent(objectiveContentKnowDTO);
return ResultUtils.success(data);
}

@ -31,8 +31,8 @@ public class ObjectiveContentsController {
@ValidateParams({"objectiveId"})
@PostMapping("/addcontent")
public BaseResponse<String> saveContent(@RequestBody ObjectiveContents objectiveContents){
objectiveContentsService.save(objectiveContents);
return ResultUtils.success("添加成功");
String data = objectiveContentsService.saveWithCheck(objectiveContents);
return ResultUtils.success(data);
}
@ApiOperation("删除目标内容")

@ -20,7 +20,7 @@ import java.io.Serializable;
* @since 2024-06-13
*/
@Data
@ApiModel(description = "分项目标内容添加知识点")
@ApiModel(description = "目标内容添加知识点")
public class ObjectiveContentKnowDTO extends ObjectiveContentKnow {
}

@ -38,12 +38,14 @@ public class ObjectiveContentKnow implements Serializable {
/**
* 分项目标或内容 id
*/
private String objectiveOrContent;
// private String objectiveOrContent;
private String objectiveContentId;
/**
* 关联的知识点
*/
private String know;
// private String know;
private Integer knowId;
}

@ -36,8 +36,6 @@ public class ObjectiveContents implements Serializable {
@ApiModelProperty(value = "内容",required = true)
private String content;
@ApiModelProperty(value = "排序字段",required = true)
@ApiModelProperty(value = "排序字段")
private Float orderNum;
}

@ -36,5 +36,4 @@ public class Knowtmp implements Serializable {
private double hour;
}

@ -0,0 +1,23 @@
package com.teaching.backend.model.vo.courses;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@ApiModel(description = "课程目标详情(简略)")
public class CourseObjectivesVO implements Serializable {
@ApiModelProperty(value = "目标id")
private String id;
@ApiModelProperty(value = "目标名称")
private String name;
}

@ -1,5 +1,6 @@
package com.teaching.backend.model.vo.courses;
import com.teaching.backend.model.vo.knowtmp.KnowTmpVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -12,7 +13,7 @@ import java.util.List;
public class ObjectiveContentKnowVO {
/**
* 分项目标内容 id
* 目标内容 id
*/
private String objectiveOrContent;
@ -26,17 +27,17 @@ public class ObjectiveContentKnowVO {
* 关联的知识点学时合计
*/
@ApiModelProperty(value = "关联的知识点学时合计")
private BigDecimal knowsTime;
private Double knowsTime;
/**
* 关联的知识点学时占比
*/
@ApiModelProperty(value = "关联的知识点学时占比")
private String persent;
private Double persent;
/**
* 分项目标下面的内容对应的知识点数据
* 知识点的展示数据
*/
List<ObjectiveContentKnowVO> contentKnowsData;
List<KnowTmpVO> knowTmpVOList;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.vo.knowtmp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-05-31
*/
@Data
@TableName(value = "knowtmp")
public class KnowTmpVO implements Serializable {
private Long id;
private String name;
private double hour;
}

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CourseObjectivesVO;
import java.util.List;
@ -37,4 +38,6 @@ public interface ICourseObjectivesService extends IService<CourseObjectives> {
* @return
*/
List<CourseObjectivesTreeVO> queryCourseObjectivesTree(String id);
List<CourseObjectivesVO> queryCourseObjectivesForAdd(String courseId);
}

@ -15,7 +15,7 @@ import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO;
*/
public interface IObjectiveContentKnowService extends IService<ObjectiveContentKnow> {
String saveKnowsWithObjectiveOrContent(ObjectiveContentKnowDTO objectiveContentKnowDTO);
String saveKnowsWithObjectiveContent(ObjectiveContentKnowDTO objectiveContentKnowDTO);
ObjectiveContentKnowVO getCountData(String objectiveId);
}

@ -16,4 +16,6 @@ public interface IObjectiveContentsService extends IService<ObjectiveContents> {
String deleteById(String id);
String saveWithCheck(ObjectiveContents objectiveContents);
}

@ -14,8 +14,10 @@ import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.model.vo.courses.CourseObjectivesVO;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import com.teaching.backend.utils.CourseCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -26,6 +28,7 @@ import java.util.List;
import java.util.Map;
import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD;
import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_TYPE;
/**
* <p>
@ -36,6 +39,7 @@ import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD
* @since 2024-05-31
*/
@Service
@Slf4j
public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMapper, CourseObjectives> implements ICourseObjectivesService {
@ -109,12 +113,12 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
Integer type = courseObjectives.getType();
if (type == CourseCode.TOTAL_OBJECTIVE_TYPE.getValue()){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"课程总目标只需清除所列内容即可!");
if (type == TOTAL_OBJECTIVE_TYPE.getValue()){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"课程总目标禁止删除!");
}
//等到删完内容后判断还是上来就判断?
Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, id));
.eq(ObjectiveContentKnow::getObjectiveContentId, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
throw new BusinessException(ErrorCode.KNOWS_EXIT);
}
@ -204,6 +208,30 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
return roots;
}
@Override
public List<CourseObjectivesVO> queryCourseObjectivesForAdd(String courseId) {
CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<>(CourseObjectives.class)
.eq(CourseObjectives::getCourseId, courseId));
if (courseObjectives == null){
log.error("课程相关数据不存在:{}",courseId);
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
String courseTotalObjectiveId = courseObjectives.getId();
List<CourseObjectives> objectivesLists = courseObjectivesMapper.selectList(new LambdaQueryWrapper<>(CourseObjectives.class)
.eq(CourseObjectives::getPid, courseTotalObjectiveId)
.select(CourseObjectives::getId,CourseObjectives::getType)
.orderByAsc(CourseObjectives::getType)
);
List<CourseObjectivesVO> courseObjectivesVOS = new ArrayList<>(objectivesLists.size());
for (CourseObjectives objectives : objectivesLists) {
CourseObjectivesVO courseObjectivesVO = new CourseObjectivesVO();
courseObjectivesVO.setId(objectives.getId());
courseObjectivesVO.setName(objectivesTypeMapper.selectById(objectives.getType()).getTypeName());
courseObjectivesVOS.add(courseObjectivesVO);
}
return courseObjectivesVOS;
}
// 获取目标的内容列表
private List<ObjectiveContents> fetchContentsForObjective(String objectiveId) {
LambdaQueryWrapper<ObjectiveContents> queryWrapper = new LambdaQueryWrapper<>();

@ -283,7 +283,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
contents+=content;
Long know = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveId));
.eq(ObjectiveContentKnow::getObjectiveContentId, objectiveId));
knows+=know;
}
if(contents > 0){

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
@ -13,7 +14,9 @@ import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.model.entity.knowtmp.Knowtmp;
import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO;
import com.teaching.backend.model.vo.knowtmp.KnowTmpVO;
import com.teaching.backend.service.courses.IObjectiveContentKnowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -40,8 +43,8 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
@Autowired
ObjectiveContentKnowMapper objectiveContentKnowMapper;
// @Autowired
// KnowMapper knowMapper;
@Autowired
KnowtmpMapper knowtmpMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Autowired
@ -53,114 +56,109 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
@Override
@Transactional
public String saveKnowsWithObjectiveOrContent(ObjectiveContentKnowDTO objectiveContentKnowDTO) {
String objectiveOrContent = objectiveContentKnowDTO.getObjectiveOrContent();
if (objectiveOrContent == null || objectiveOrContent.equals("")){
throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_NOT_EXIT);
}
public String saveKnowsWithObjectiveContent(ObjectiveContentKnowDTO objectiveContentKnowDTO) {
//暂时约定前端传过来的的knows是“1,2,3” 用 , 隔开的
String knows = objectiveContentKnowDTO.getKnow();
if (knows == null || knows.equals("")){
throw new BusinessException(ErrorCode.KONWID_NOT_EXIT);
}
List<String> knowIds = new ArrayList<>(Arrays.asList(knows.split(",")));
List<ObjectiveContentKnow> objectiveContentKnowList = new ArrayList<>();
for (String knowId : knowIds) {
ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow();
// objectiveContentKnow.setId(snowflakeGenerator.next());
objectiveContentKnow.setObjectiveOrContent(objectiveOrContent);
objectiveContentKnow.setKnow(knowId);
objectiveContentKnowList.add(objectiveContentKnow);
}
try {
objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList);
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT);
// String knows = objectiveContentKnowDTO.getKnow();
// if (knows == null || knows.equals("")){
// throw new BusinessException(ErrorCode.KONWID_NOT_EXIT);
// }
// List<String> knowIds = new ArrayList<>(Arrays.asList(knows.split(",")));
// List<ObjectiveContentKnow> objectiveContentKnowList = new ArrayList<>();
// for (String knowId : knowIds) {
// ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow();
//// objectiveContentKnow.setId(snowflakeGenerator.next());
// objectiveContentKnow.setObjectiveOrContent(objectiveOrContent);
// objectiveContentKnow.setKnow(knowId);
// objectiveContentKnowList.add(objectiveContentKnow);
// }
// try {
// objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList);
// } catch (Exception e) {
// e.printStackTrace();
// throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT);
// }
//添加逻辑变了 变成了给知识点添加关联的--课程目标
ObjectiveContents objectiveContents = objectiveContentsMapper.selectById(objectiveContentKnowDTO.getObjectiveContentId());
if (objectiveContents == null) {
throw new BusinessException(ErrorCode.OBJECTIVE_CONTENT_NOT_EXIT);
}
int insert = objectiveContentKnowMapper.insert(objectiveContentKnowDTO);
return "添加成功";
return insert > 0 ? "添加成功" : "添加失败";
}
@Override
public ObjectiveContentKnowVO getCountData(String objectiveOrContentId) {
// 查询分项目标或者是下面的内容关联的知识点数据(按设计要求,这个传的就是分项目标的id)
List<ObjectiveContentKnow> objectiveContentKnows = objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveOrContentId));
public ObjectiveContentKnowVO getCountData(String objectiveContentId) {
// 创建ObjectiveContentKnowVO对象,用于存储和返回计算结果
ObjectiveContentKnowVO objectiveContentKnowVO = new ObjectiveContentKnowVO();
// 创建ObjectiveContentKnowVO对象,并计算相关数据
ObjectiveContentKnowVO objectiveContentKnowVO = createObjectiveContentKnowVO(objectiveOrContentId, objectiveContentKnows);
// 根据分项目标找到课程id
// 根据传入的目标内容ID找到课程ID和总学时
String objectiveID = objectiveContentsMapper.selectOne(new LambdaQueryWrapper<ObjectiveContents>()
.eq(ObjectiveContents::getId, objectiveContentId)).getObjectiveId();
String pid = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<CourseObjectives>()
.eq(CourseObjectives::getId, objectiveOrContentId)).getPid();
.eq(CourseObjectives::getId, objectiveID)).getPid();
String courseId = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<CourseObjectives>()
.eq(CourseObjectives::getId, pid)).getCourseId();
.eq(CourseObjectives::getId, pid)).getCourseId();
Integer classhours = coursesMapper.selectById(courseId).getClasshours();
// 计算并设置比例(百分比)
// BigDecimal percentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours);
// objectiveContentKnowVO.setPersent(percentage + "%");
// 查找分项目标下的内容
List<ObjectiveContents> objectiveContents = objectiveContentsMapper.selectList(new LambdaQueryWrapper<ObjectiveContents>()
.eq(ObjectiveContents::getObjectiveId, objectiveOrContentId));
// 获取当前目标内容下关联的知识点数据
List<ObjectiveContentKnow> objectiveContentKnows = objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveContentId, objectiveContentId)
);
// 如果存在分项目标内容,处理并计算每个内容的相关数据
if (!CollectionUtils.isEmpty(objectiveContents)) {
List<ObjectiveContentKnowVO> contentKnowVOs = objectiveContents.stream()
.map(content -> createObjectiveContentKnowVO(content.getId(), objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, content.getId())
)))
.collect(Collectors.toList());
// 创建并设置ObjectiveContentKnowVO对象的属性
objectiveContentKnowVO = createObjectiveContentKnowVO(objectiveContentId, objectiveContentKnows);
// 计算每个内容的知识点总学时的比例(百分比)
// contentKnowVOs.forEach(contentKnowVO -> {
// BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
// contentKnowVO.setPersent(contentPercentage + "%");
// });
// 计算并设置该内容的知识点总学时的比例(百分比)
Double contentPercentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours);
objectiveContentKnowVO.setPersent(contentPercentage);
// 设置内容的知识点数据
objectiveContentKnowVO.setContentKnowsData(contentKnowVOs);
}
// 返回计算结果
// 返回最终结果
return objectiveContentKnowVO;
}
// 创建ObjectiveContentKnowVO对象,并计算知识点数量和总时间
// 创建ObjectiveContentKnowVO对象,并计算知识点数量、总时间和关联的知识点部分数据
private ObjectiveContentKnowVO createObjectiveContentKnowVO(String objectiveOrContentId, List<ObjectiveContentKnow> objectiveContentKnows) {
ObjectiveContentKnowVO vo = new ObjectiveContentKnowVO();
vo.setObjectiveOrContent(objectiveOrContentId);
vo.setKnowsNumber(objectiveContentKnows.size());
// 计算知识点的总时间
// BigDecimal knowsTime = objectiveContentKnows.stream()
// .map(contentKnow -> {
// Know know = knowMapper.selectOne(new LambdaQueryWrapper<Know>()
// .eq(Know::getId, contentKnow.getKnow()));
// if (know == null) {
// throw new BusinessException(ErrorCode.KNOW_NOT_EXIT);
// }
// return know.getHour();
// })
// .reduce(BigDecimal.ZERO, BigDecimal::add);
// vo.setKnowsTime(knowsTime);
// 计算知识点的总时间,并收集关联的知识点部分数据
Double knowsTime = 0.0;
List<KnowTmpVO> knowTmpVOList = new ArrayList<>();
for (ObjectiveContentKnow contentKnow : objectiveContentKnows) {
Knowtmp know = knowtmpMapper.selectOne(new LambdaQueryWrapper<Knowtmp>()
.eq(Knowtmp::getId, contentKnow.getKnowId()));
if (know == null) {
throw new BusinessException(ErrorCode.KNOW_NOT_EXIT);
}
knowsTime += know.getHour();
// 将当前知识点数据添加到knowTmpVOList中
KnowTmpVO knowTmpVO = new KnowTmpVO();
knowTmpVO.setId(know.getId());
knowTmpVO.setName(know.getName());
knowTmpVO.setHour(know.getHour());
knowTmpVOList.add(knowTmpVO);
}
vo.setKnowsTime(knowsTime);
vo.setKnowTmpVOList(knowTmpVOList); // 设置知识点的部分数据列表
return vo;
}
// 计算知识点时间占总学时的比例,并转换为百分比
private BigDecimal calculatePercentage(BigDecimal knowsTime, Integer classhours) {
// 计算知识点学时占总学时的比例,并返回百分比形式的结果
private Double calculatePercentage(Double knowsTime, Integer classhours) {
if (classhours == null || classhours == 0) {
return BigDecimal.ZERO;
return 0.0;
}
// 将classhours转换为BigDecimal类型,以便进行精确计算
BigDecimal classHoursBigDecimal = new BigDecimal(classhours);
// 计算knowsTime占classhours的比例,先除以classhours再乘以100,保留两位小数,并四舍五入
return knowsTime.divide(classHoursBigDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
return new BigDecimal(knowsTime)
.divide(new BigDecimal(classhours), 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100))
.setScale(2, RoundingMode.HALF_UP)
.doubleValue();
}
}

@ -5,16 +5,21 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.service.courses.IObjectiveContentsService;
import com.teaching.backend.utils.CourseCode;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.teaching.backend.utils.CourseCode.*;
/**
* <p>
* 服务实现类
@ -24,23 +29,50 @@ import org.springframework.stereotype.Service;
* @since 2024-06-05
*/
@Service
@Slf4j
public class ObjectiveContentsServiceImpl extends ServiceImpl<ObjectiveContentsMapper, ObjectiveContents> implements IObjectiveContentsService {
@Autowired
ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Autowired
ObjectiveContentsMapper objectiveContentsMapper;
@Autowired
CourseObjectivesMapper courseObjectivesMapper;
@Override
public String deleteById(String id) {
if (id == null){
throw new BusinessException(ErrorCode.CONTENT_NOT_EXIT);
}
Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, id));
.eq(ObjectiveContentKnow::getObjectiveContentId, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
throw new BusinessException(ErrorCode.KNOWS_EXIT);
}
int delete = objectiveContentsMapper.deleteById(id);
return delete > 0 ? "删除成功!" : "删除失败!";
}
/**
* 在添加内容的时候需要校验总目标和思政目标只有一个内容
* @param objectiveContents
* @return
*/
@Override
public String saveWithCheck(ObjectiveContents objectiveContents) {
CourseObjectives courseObjective = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<>(CourseObjectives.class)
.eq(CourseObjectives::getId, objectiveContents.getObjectiveId()));
if (courseObjective == null){
log.error("课程目标数据不存在:{}",objectiveContents.getObjectiveId());
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
}
if (courseObjective.getType() == SI_ZHENG_TYPE.getValue() || courseObjective.getType() == TOTAL_OBJECTIVE_TYPE.getValue()){
Long count = objectiveContentsMapper.selectCount(new LambdaQueryWrapper<>(ObjectiveContents.class)
.eq(ObjectiveContents::getObjectiveId, objectiveContents.getObjectiveId()));
if (count>CONTENT_EXIT.getValue()){
throw new BusinessException(ErrorCode.CONTENT_EXISTS,"该目标下面已存在一条内容,无需再次添加");
}
}
int insert = objectiveContentsMapper.insert(objectiveContents);
return insert > 0 ? "添加内容成功" : "添加内容失败";
}
}

Loading…
Cancel
Save