|
@@ -1,10 +1,37 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.CourseDimensionDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.CourseWeightDetailDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.CourseWeightDto;
|
|
|
+import com.qmth.distributed.print.business.bean.params.CourseWeightParam;
|
|
|
+import com.qmth.distributed.print.business.bean.result.CourseEvaluationResult;
|
|
|
+import com.qmth.distributed.print.business.bean.result.CourseTargetResult;
|
|
|
+import com.qmth.distributed.print.business.entity.CourseTarget;
|
|
|
import com.qmth.distributed.print.business.entity.CourseWeight;
|
|
|
+import com.qmth.distributed.print.business.entity.TeachCourse;
|
|
|
+import com.qmth.distributed.print.business.enums.CourseSettingTypeEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.CourseWeightMapper;
|
|
|
+import com.qmth.distributed.print.business.service.CourseEvaluationService;
|
|
|
+import com.qmth.distributed.print.business.service.CourseTargetService;
|
|
|
import com.qmth.distributed.print.business.service.CourseWeightService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.distributed.print.business.service.TeachCourseService;
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +44,195 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class CourseWeightServiceImpl extends ServiceImpl<CourseWeightMapper, CourseWeight> implements CourseWeightService {
|
|
|
|
|
|
-}
|
|
|
+ @Resource
|
|
|
+ private TeachCourseService teachCourseService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CourseTargetService courseTargetService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CourseEvaluationService courseEvaluationService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CourseWeightDto> findCourseWeight(Long examId, String courseCode, Long userId) {
|
|
|
+ TeachCourse teachCourse = teachCourseService.findByExamIdCourseCodeAndUserId(examId, courseCode, userId);
|
|
|
+ Long teachCourseId = teachCourse.getId();
|
|
|
+
|
|
|
+ // 现有目标
|
|
|
+ List<CourseTargetResult> courseTargetList = courseTargetService.findCourseTargetList(examId, courseCode, userId);
|
|
|
+ // 现有评价方式
|
|
|
+ List<CourseEvaluationResult> courseEvaluationResultList = courseEvaluationService.findCourseEvaluationList(
|
|
|
+ examId, courseCode, userId);
|
|
|
+ // 现有权重
|
|
|
+ List<CourseWeight> courseWeightList = this.list(
|
|
|
+ new QueryWrapper<CourseWeight>().lambda().eq(CourseWeight::getTeachCourseId, teachCourseId));
|
|
|
+ // 权重map
|
|
|
+ Map<String, CourseWeight> courseWeightMap = courseWeightList.stream()
|
|
|
+ .collect(Collectors.toMap(k -> k.getTargetId() + SystemConstant.HYPHEN + k.getEvaluationId(), v -> v));
|
|
|
+
|
|
|
+ List<CourseWeightDto> result = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(courseTargetList)) {
|
|
|
+ for (CourseTargetResult courseTarget : courseTargetList) {
|
|
|
+ Long targetId = courseTarget.getId();
|
|
|
+ String targetName = courseTarget.getTargetName();
|
|
|
+ List<CourseDimensionDto> dimensionList = courseTarget.getDimensionList();
|
|
|
+ String degreeRequirement = courseTarget.getDegreeRequirement();
|
|
|
+ BigDecimal totalWeight = courseTarget.getTotalWeight();
|
|
|
+
|
|
|
+ List<CourseWeightDetailDto> courseWeightDetailDtoList = new ArrayList<>();
|
|
|
+ for (CourseEvaluationResult courseEvaluationResult : courseEvaluationResultList) {
|
|
|
+ Long evaluationId = courseEvaluationResult.getEvaluationId();
|
|
|
+ String evaluationName = courseEvaluationResult.getEvaluation();
|
|
|
+ String key = targetId + SystemConstant.HYPHEN + evaluationId;
|
|
|
+
|
|
|
+ Boolean enable = false;
|
|
|
+ BigDecimal weight = BigDecimal.ZERO;
|
|
|
+ BigDecimal targetScore = BigDecimal.ZERO;
|
|
|
+ if (courseWeightMap.containsKey(key)) {
|
|
|
+ // 权重表中包含该目标评价的设置 - 获取权重表的数据
|
|
|
+ CourseWeight courseWeight = courseWeightMap.get(key);
|
|
|
+ enable = courseWeight.getEnable();
|
|
|
+ weight = courseWeight.getWeight();
|
|
|
+ targetScore = courseWeight.getTargetScore();
|
|
|
+ }
|
|
|
+ CourseWeightDetailDto detail = new CourseWeightDetailDto();
|
|
|
+ detail.setEvaluationId(evaluationId);
|
|
|
+ detail.setEvaluationName(evaluationName);
|
|
|
+ detail.setEnable(enable);
|
|
|
+ detail.setWeight(weight);
|
|
|
+ detail.setTargetScore(targetScore);
|
|
|
+ courseWeightDetailDtoList.add(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ CourseWeightDto courseWeightDto = new CourseWeightDto();
|
|
|
+ courseWeightDto.setCourseTargetId(targetId);
|
|
|
+ courseWeightDto.setCourseTargetName(targetName);
|
|
|
+ courseWeightDto.setDimensionList(dimensionList);
|
|
|
+ courseWeightDto.setDegreeRequirement(degreeRequirement);
|
|
|
+ courseWeightDto.setTotalWeight(totalWeight);
|
|
|
+ courseWeightDto.setEvaluationList(courseWeightDetailDtoList);
|
|
|
+ result.add(courseWeightDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void saveCourseWeight(CourseWeightParam courseWeightParam, SysUser requestUser) {
|
|
|
+ Long requestUserId = requestUser.getId();
|
|
|
+ Long examId = courseWeightParam.getExamId();
|
|
|
+ String courseCode = courseWeightParam.getCourseCode();
|
|
|
+ List<CourseWeightDto> submitForm = courseWeightParam.getSubmitForm();
|
|
|
+
|
|
|
+ TeachCourse teachCourse = teachCourseService.findByExamIdCourseCodeAndUserId(examId, courseCode, requestUserId);
|
|
|
+ Long teachCourseId = teachCourse.getId();
|
|
|
+
|
|
|
+ teachCourseService.clearCourseSetting(teachCourseId, CourseSettingTypeEnum.COURSE_WEIGHT);
|
|
|
+
|
|
|
+ List<CourseTarget> courseTargetList = new ArrayList<>();
|
|
|
+ List<CourseWeight> courseWeightList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 目标分值检测
|
|
|
+ BigDecimal checkTotalScore = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 评价方式整体权重检测
|
|
|
+ BigDecimal checkEvaluationTotalWeight = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 课程目标整体权重检测
|
|
|
+ BigDecimal checkTargetTotalWeight = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (CourseWeightDto courseWeightDto : submitForm) {
|
|
|
+ Long courseTargetId = courseWeightDto.getCourseTargetId();
|
|
|
+ CourseTarget courseTarget = courseTargetService.getById(courseTargetId);
|
|
|
+ if (Objects.isNull(courseTarget)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("课程目标不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal totalWeight = courseWeightDto.getTotalWeight();
|
|
|
+ courseTarget.setTotalWeight(totalWeight);
|
|
|
+ courseTarget.updateInfo(requestUserId);
|
|
|
+ courseTargetList.add(courseTarget);
|
|
|
+ checkTargetTotalWeight = checkTargetTotalWeight.add(totalWeight);
|
|
|
+
|
|
|
+ List<CourseWeightDetailDto> detailDtoList = courseWeightDto.getEvaluationList();
|
|
|
+ for (CourseWeightDetailDto detail : detailDtoList) {
|
|
|
+ Long evaluationId = detail.getEvaluationId();
|
|
|
+ Boolean enable = detail.getEnable();
|
|
|
+ BigDecimal weight = detail.getWeight();
|
|
|
+ BigDecimal targetScore = detail.getTargetScore();
|
|
|
+
|
|
|
+ CourseWeight courseWeight = new CourseWeight();
|
|
|
+ courseWeight.setTeachCourseId(teachCourseId);
|
|
|
+ courseWeight.setSchoolId(requestUser.getSchoolId());
|
|
|
+ courseWeight.setExamId(examId);
|
|
|
+ courseWeight.setCourseCode(courseCode);
|
|
|
+ courseWeight.setUserId(requestUserId);
|
|
|
+ courseWeight.setTargetId(courseTargetId);
|
|
|
+ courseWeight.setEvaluationId(evaluationId);
|
|
|
+ courseWeight.setEnable(enable);
|
|
|
+ courseWeight.setWeight(weight);
|
|
|
+ courseWeight.setTargetScore(targetScore);
|
|
|
+ courseWeight.insertInfo(requestUserId);
|
|
|
+ courseWeightList.add(courseWeight);
|
|
|
+
|
|
|
+ if (enable) {
|
|
|
+ checkTotalScore = checkTotalScore.add(targetScore);
|
|
|
+ checkEvaluationTotalWeight = checkEvaluationTotalWeight.add(weight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> errorMsgList = new ArrayList<>();
|
|
|
+ // 数据校验1:所有课程目标的总目标分值等于100分;
|
|
|
+ int checkTotalScoreCompareResult = checkTotalScore.compareTo(new BigDecimal(100));
|
|
|
+ if (checkTotalScoreCompareResult > 0) {
|
|
|
+ errorMsgList.add(String.format("所有课程目标的总目标分值为[%s],超过100分", checkTotalScore));
|
|
|
+ } else if (checkTotalScoreCompareResult < 0) {
|
|
|
+ errorMsgList.add(String.format("所有课程目标的总目标分值为[%s],低于100分", checkTotalScore));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据校验2:各课程目标下评价方式的总权重应等于100%;
|
|
|
+ int checkEvaluationTotalWeightCompareResult = checkEvaluationTotalWeight.compareTo(new BigDecimal(100));
|
|
|
+ if (checkEvaluationTotalWeightCompareResult > 0) {
|
|
|
+ errorMsgList.add(
|
|
|
+ String.format("所有课程目标下评价方式的总权重为[%s],超过[%s]", String.valueOf(checkEvaluationTotalWeight) + '%',
|
|
|
+ "100%"));
|
|
|
+ } else if (checkEvaluationTotalWeightCompareResult < 0) {
|
|
|
+ errorMsgList.add(
|
|
|
+ String.format("所有课程目标下评价方式的总权重为[%s],低于[%s]", String.valueOf(checkEvaluationTotalWeight) + '%',
|
|
|
+ "100%"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据校验3:目标整体权重应等于100%,用于计算课程整体达成度。
|
|
|
+ int checkTargetTotalWeightCompareResult = checkTargetTotalWeight.compareTo(new BigDecimal(100));
|
|
|
+ if (checkTargetTotalWeightCompareResult > 0) {
|
|
|
+ errorMsgList.add(
|
|
|
+ String.format("所有课程目标整体权重为[%s],超过[%s]", String.valueOf(checkTargetTotalWeight) + '%', "100%"));
|
|
|
+ } else if (checkTargetTotalWeightCompareResult < 0) {
|
|
|
+ errorMsgList.add(
|
|
|
+ String.format("所有课程目标整体权重为[%s],低于[%s]", String.valueOf(checkTargetTotalWeight) + '%', "100%"));
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(errorMsgList)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorMsgList));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新目标整体权重
|
|
|
+ courseTargetService.updateBatchById(courseTargetList);
|
|
|
+ // 保存课程权重设置
|
|
|
+ this.saveBatch(courseWeightList);
|
|
|
+ // 更新课程权重设置状态
|
|
|
+ teachCourse.setWeightSetting(true);
|
|
|
+ teachCourseService.updateById(teachCourse);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void deleteCourseWeight(Long teachCourseId) {
|
|
|
+ this.remove(new QueryWrapper<CourseWeight>().lambda().eq(CourseWeight::getTeachCourseId, teachCourseId));
|
|
|
+ UpdateWrapper<CourseTarget> courseTargetUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ courseTargetUpdateWrapper.lambda().eq(CourseTarget::getTeachCourseId, teachCourseId)
|
|
|
+ .set(CourseTarget::getTotalWeight, null);
|
|
|
+ courseTargetService.update(courseTargetUpdateWrapper);
|
|
|
+ }
|
|
|
+}
|