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