|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |