|
|
|
@ -11,22 +11,26 @@ import com.teaching.backend.exception.BusinessException; |
|
|
|
|
import com.teaching.backend.mapper.courses.CourseObjectivesMapper; |
|
|
|
|
import com.teaching.backend.mapper.courses.CoursesMapper; |
|
|
|
|
import com.teaching.backend.mapper.courses.ObjectiveContentsMapper; |
|
|
|
|
import com.teaching.backend.mapper.courses.ObjectivesTypeMapper; |
|
|
|
|
import com.teaching.backend.model.dto.courses.CoursesDTO; |
|
|
|
|
import com.teaching.backend.model.dto.courses.PageDTO; |
|
|
|
|
import com.teaching.backend.model.entity.courses.CourseObjectives; |
|
|
|
|
import com.teaching.backend.model.entity.courses.Courses; |
|
|
|
|
import com.teaching.backend.model.entity.courses.ObjectiveContents; |
|
|
|
|
import com.teaching.backend.model.entity.courses.ObjectivesType; |
|
|
|
|
import com.teaching.backend.model.query.CourseQuery; |
|
|
|
|
import com.teaching.backend.model.vo.CourseObjectivesTreeVO; |
|
|
|
|
import com.teaching.backend.model.vo.CoursesVO; |
|
|
|
|
import com.teaching.backend.service.courses.ICoursesService; |
|
|
|
|
import com.teaching.backend.utils.CourseCode; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <p> |
|
|
|
@ -46,17 +50,16 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
CourseObjectivesMapper courseObjectivesMapper; |
|
|
|
|
@Autowired |
|
|
|
|
ObjectiveContentsMapper objectiveContentsMapper; |
|
|
|
|
@Autowired |
|
|
|
|
ObjectivesTypeMapper objectivesTypeMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public String saveCourseWithObjective(CoursesDTO coursesDTO, String teacherId) { |
|
|
|
|
public String saveCourseWithObjective(CoursesDTO coursesDTO) { |
|
|
|
|
Courses courses = new Courses(); |
|
|
|
|
CourseObjectives courseObjectives = new CourseObjectives(); |
|
|
|
|
BeanUtils.copyProperties(coursesDTO, courses); |
|
|
|
|
// List<String> teacherIds = new ArrayList<>();
|
|
|
|
|
// teacherIds.add(teacherId);
|
|
|
|
|
// courses.setTeacher(String.valueOf(teacherIds));
|
|
|
|
|
courses.setTeacher(teacherId); |
|
|
|
|
courses.setCreateTime(LocalDateTime.now()); |
|
|
|
|
String code = coursesDTO.getCode(); |
|
|
|
|
QueryWrapper<Courses> queryWrapper = new QueryWrapper<>(); |
|
|
|
@ -65,11 +68,28 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
if (count == 0) { |
|
|
|
|
int insert = coursesMapper.insert(courses); |
|
|
|
|
if (insert > 0) { |
|
|
|
|
Courses courses1 = coursesMapper.selectOne(queryWrapper); |
|
|
|
|
courseObjectives.setCourseId(courses1.getId()); |
|
|
|
|
courseObjectives.setCreateTime(courses1.getCreateTime()); |
|
|
|
|
courseObjectives.setName(courses1.getName() + "课程总体目标"); |
|
|
|
|
courseObjectivesMapper.insert(courseObjectives); |
|
|
|
|
Courses coursesNew = coursesMapper.selectOne(queryWrapper); |
|
|
|
|
courseObjectives.setCourseId(coursesNew.getId()); |
|
|
|
|
courseObjectives.setName(coursesNew.getName() + "课程总体目标"); |
|
|
|
|
// courseObjectives.setHasChild(1);
|
|
|
|
|
int insertTotal = courseObjectivesMapper.insert(courseObjectives); |
|
|
|
|
if (insertTotal>0){ |
|
|
|
|
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne |
|
|
|
|
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, coursesNew.getId())); |
|
|
|
|
String courseTotalObjectivesId = courseTotalObjectives.getId(); |
|
|
|
|
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<ObjectivesType>()); |
|
|
|
|
for (ObjectivesType objectivesType : objectivesTypes) { |
|
|
|
|
Integer typeId = objectivesType.getId(); |
|
|
|
|
String typeName = objectivesType.getTypeName(); |
|
|
|
|
CourseObjectives courseObjectivesF = new CourseObjectives(); |
|
|
|
|
courseObjectivesF.setType(typeId); |
|
|
|
|
courseObjectivesF.setName(typeName); |
|
|
|
|
courseObjectivesF.setPid(courseTotalObjectivesId); |
|
|
|
|
courseObjectivesMapper.insert(courseObjectivesF); |
|
|
|
|
} |
|
|
|
|
courseTotalObjectives.setHasChild(1); |
|
|
|
|
courseObjectivesMapper.updateById(courseTotalObjectives); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return "添加成功"; |
|
|
|
|
} else { |
|
|
|
@ -97,79 +117,54 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
// @Transactional
|
|
|
|
|
public void deleteBatchByIds(String id) { |
|
|
|
|
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, id); |
|
|
|
|
CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(queryWrapper); |
|
|
|
|
CourseObjectives courseObjectives= courseObjectivesMapper.selectOne |
|
|
|
|
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, id)); |
|
|
|
|
String objectivesId = courseObjectives.getId(); |
|
|
|
|
LambdaQueryWrapper<ObjectiveContents> queryWrapper2 = new LambdaQueryWrapper<ObjectiveContents>().eq(ObjectiveContents::getObjectiveId, objectivesId); |
|
|
|
|
Long count = objectiveContentsMapper.selectCount(queryWrapper2); |
|
|
|
|
if (courseObjectives.getHasChild().equals("1")) { |
|
|
|
|
throw new BusinessException(ErrorCode.CONTENT_EXISTS, "该课程已有分项目标,禁止删除"); |
|
|
|
|
} |
|
|
|
|
if (!count.equals(0)){ |
|
|
|
|
throw new BusinessException(ErrorCode.CONTENT_EXISTS, "总目标下面还有内容,禁止删除"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
List<CourseObjectivesTreeVO> courseObjectivesTreeVOList = courseObjectivesMapper.selectTreeNodes(objectivesId); |
|
|
|
|
int contents = 0; |
|
|
|
|
List<String> objectiveIds = new ArrayList<>(); |
|
|
|
|
for (CourseObjectivesTreeVO courseObjectivesTreeVO : courseObjectivesTreeVOList) { |
|
|
|
|
String objectiveId = courseObjectivesTreeVO.getId(); |
|
|
|
|
objectiveIds.add(objectiveId); |
|
|
|
|
Long content = objectiveContentsMapper |
|
|
|
|
.selectCount(new LambdaQueryWrapper<ObjectiveContents>().eq(ObjectiveContents::getObjectiveId, objectiveId)); |
|
|
|
|
contents+=content; |
|
|
|
|
} |
|
|
|
|
if (contents==0){ |
|
|
|
|
coursesMapper.deleteById(id); |
|
|
|
|
courseObjectivesMapper.deleteById(courseObjectives.getId()); |
|
|
|
|
courseObjectivesMapper.deleteBatchIds(objectiveIds); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
throw new BusinessException(ErrorCode.CONTENT_EXISTS, "该课程的目标下面还有内容,请把相关内容清空后再来删除课程"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<CoursesVO> getPagePageSize(int page, int pageSize) { |
|
|
|
|
int startIndex = (page-1) * pageSize; |
|
|
|
|
List<Courses> list = coursesMapper.getItemsByPage(startIndex, pageSize); |
|
|
|
|
// List<Courses> list = coursesMapper.selectList(null);
|
|
|
|
|
List<CoursesVO> coursesVo = BeanUtil.copyToList(list, CoursesVO.class); |
|
|
|
|
coursesVo = coursesVo.stream().map((item) -> { |
|
|
|
|
|
|
|
|
|
item.setTotalHours(countHours(item.getId())); |
|
|
|
|
item.setTotalchapter(100); |
|
|
|
|
item.setTotalKnow(100); |
|
|
|
|
// if (StringUtils.isBlank(item.getName()) ||
|
|
|
|
|
// StringUtils.isBlank(item.getDescription()) ){
|
|
|
|
|
// throw new BusinessException(ErrorCode.OPERATION_ERROR,"数据格式有问题,请修改");
|
|
|
|
|
// }
|
|
|
|
|
return item; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
return coursesVo; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int countHours(String id) { |
|
|
|
|
Courses courses = coursesMapper.selectById(id); |
|
|
|
|
|
|
|
|
|
Integer classhours = 0; |
|
|
|
|
Integer theoryhours = 0; |
|
|
|
|
Integer practicehours = 0; |
|
|
|
|
Integer experimenthours = 0; |
|
|
|
|
Integer otherhours = 0; |
|
|
|
|
if (courses.getClasshours() != null) { |
|
|
|
|
classhours = courses.getClasshours(); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (courses.getTheoryhours() != null) { |
|
|
|
|
theoryhours = courses.getTheoryhours(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (courses.getPracticehours() != null) { |
|
|
|
|
practicehours = courses.getPracticehours(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (courses.getExperimenthours() != null) { |
|
|
|
|
experimenthours = courses.getExperimenthours(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (courses.getOtherhours() != null) { |
|
|
|
|
otherhours = courses.getOtherhours(); |
|
|
|
|
@Override |
|
|
|
|
public List<CoursesVO> getPagePageSize(int page, int pageSize) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
int total = classhours + theoryhours + practicehours + experimenthours + otherhours; |
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改课程信息 |
|
|
|
|
* @param coursesDTO |
|
|
|
|
*/ |
|
|
|
|
public void updateCourse(CoursesDTO coursesDTO) { |
|
|
|
|
String courseId = coursesDTO.getId(); |
|
|
|
|
Courses course = coursesMapper.selectById(courseId); |
|
|
|
|
if (course.getStatus()==CourseCode.COURSE_UODATING.getValue()){ |
|
|
|
|
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"课程正在修改中,请等待修改完成后再进行操作"); |
|
|
|
|
} |
|
|
|
|
course.setStatus(CourseCode.COURSE_UODATING.getValue()); |
|
|
|
|
coursesMapper.updateById(course); |
|
|
|
|
BeanUtil.copyProperties(coursesDTO, course); |
|
|
|
|
course.setStatus(0); |
|
|
|
|
coursesMapper.updateById(course); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|