|
@@ -1,9 +1,14 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.excel.TeachCourseDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.excel.TeachStudentImportDto;
|
|
|
+import com.qmth.distributed.print.business.bean.params.TeachCourseParams;
|
|
|
import com.qmth.distributed.print.business.bean.result.DictionaryResult;
|
|
|
import com.qmth.distributed.print.business.bean.result.TeachCourseResult;
|
|
|
import com.qmth.distributed.print.business.entity.TeachClazz;
|
|
@@ -11,23 +16,31 @@ import com.qmth.distributed.print.business.entity.TeachCourse;
|
|
|
import com.qmth.distributed.print.business.mapper.TeachCourseMapper;
|
|
|
import com.qmth.distributed.print.business.service.TeachClazzService;
|
|
|
import com.qmth.distributed.print.business.service.TeachCourseService;
|
|
|
+import com.qmth.teachcloud.common.base.BaseEntity;
|
|
|
+import com.qmth.teachcloud.common.bean.params.BasicCourseParams;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.BasicCourse;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.service.BasicCourseService;
|
|
|
import com.qmth.teachcloud.common.service.SysOrgService;
|
|
|
+import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
* @Description: 教学课程服务实现类
|
|
@@ -53,15 +66,43 @@ public class TeachCourseServiceImpl extends ServiceImpl<TeachCourseMapper, Teach
|
|
|
return this.baseMapper.findTeachCoursePage(new Page<>(pageNumber, pageSize), courseName, userId, schoolId);
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public Boolean createTeachCourse(Long basicCourseId, SysUser requestUser) {
|
|
|
- BasicCourse basicCourse = basicCourseService.getById(basicCourseId);
|
|
|
- if (Objects.isNull(basicCourse)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("基础课程不存在");
|
|
|
- }
|
|
|
- Long schoolId = basicCourse.getSchoolId();
|
|
|
+ public Boolean manualCreate(TeachCourseParams teachCourseParams, SysUser requestUser) {
|
|
|
+ String courseCode = teachCourseParams.getCourseCode();
|
|
|
+ String courseName = teachCourseParams.getCourseName();
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
Long userId = requestUser.getId();
|
|
|
+ Long basicCourseId;
|
|
|
+
|
|
|
+
|
|
|
+ BasicCourse basicCourse = basicCourseService.getOne(new QueryWrapper<BasicCourse>()
|
|
|
+ .lambda()
|
|
|
+ .eq(BasicCourse::getSchoolId, schoolId)
|
|
|
+ .eq(BasicCourse::getCode, courseCode));
|
|
|
+ if (Objects.nonNull(basicCourse)) {
|
|
|
+
|
|
|
+ if (!courseName.equals(basicCourse.getName())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("课程编号为【" + courseCode + "】的课程名称错误");
|
|
|
+ } else {
|
|
|
+ basicCourseId = basicCourse.getId();
|
|
|
+
|
|
|
+ if (this.count(new QueryWrapper<TeachCourse>()
|
|
|
+ .lambda()
|
|
|
+ .eq(TeachCourse::getSchoolId, schoolId)
|
|
|
+ .eq(TeachCourse::getUserId, userId)
|
|
|
+ .eq(TeachCourse::getBasicCourseId, basicCourseId)) > 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("课程【" + courseName + "】已经创建");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ BasicCourseParams basicCourseParams = new BasicCourseParams();
|
|
|
+ basicCourseParams.setCourseCode(courseCode);
|
|
|
+ basicCourseParams.setCourseName(courseName);
|
|
|
+ basicCourseParams.setTeachingRoomId(requestUser.getOrgId());
|
|
|
+ basicCourseId = basicCourseService.saveBasicCourse(basicCourseParams, requestUser);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
TeachCourse checkUnique = this.getOne(new QueryWrapper<TeachCourse>()
|
|
@@ -83,13 +124,83 @@ public class TeachCourseServiceImpl extends ServiceImpl<TeachCourseMapper, Teach
|
|
|
return this.save(teachCourse);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void selectCreate(List<Long> basicCourseIdList, SysUser requestUser) {
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
+ Long userId = requestUser.getId();
|
|
|
+ if (CollectionUtils.isNotEmpty(basicCourseIdList)) {
|
|
|
+ basicCourseIdList = basicCourseService.listByIds(basicCourseIdList)
|
|
|
+ .stream()
|
|
|
+ .filter(BasicCourse::getEnable)
|
|
|
+ .map(BaseEntity::getId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(basicCourseIdList)) {
|
|
|
+ List<Long> alreadyCreated = this.list(new QueryWrapper<TeachCourse>().lambda()
|
|
|
+ .eq(TeachCourse::getUserId, userId)
|
|
|
+ .in(TeachCourse::getBasicCourseId, basicCourseIdList))
|
|
|
+ .stream()
|
|
|
+ .map(TeachCourse::getBasicCourseId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ basicCourseIdList.removeAll(alreadyCreated);
|
|
|
+
|
|
|
+ List<TeachCourse> teachCourseList = basicCourseIdList.stream().flatMap(e -> {
|
|
|
+ TeachCourse teachCourse = new TeachCourse();
|
|
|
+ teachCourse.setSchoolId(schoolId);
|
|
|
+ teachCourse.setBasicCourseId(e);
|
|
|
+ teachCourse.setUserId(userId);
|
|
|
+ teachCourse.setEnable(true);
|
|
|
+ teachCourse.insertInfo(userId);
|
|
|
+ return Stream.of(teachCourse);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ this.saveBatch(teachCourseList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void importTeachCourse(MultipartFile file, SysUser requestUser) throws IOException, NoSuchFieldException {
|
|
|
+ List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(TeachCourseDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
|
+ if (finalExcelErrorList.size() > 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(finalExcelErrorList));
|
|
|
+ }
|
|
|
+ return finalExcelList;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (Objects.nonNull(finalList) && finalList.size() > 0) {
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
+ LinkedMultiValueMap<Integer, Object> map = finalList.get(i);
|
|
|
+ List<Object> teachCourseImportDtoList = map.get(i);
|
|
|
+ for (int y = 0; y < Objects.requireNonNull(teachCourseImportDtoList).size(); y++) {
|
|
|
+ if (teachCourseImportDtoList.get(y) instanceof TeachCourseDto) {
|
|
|
+ TeachCourseDto teachCourseDto = (TeachCourseDto) teachCourseImportDtoList.get(y);
|
|
|
+ String courseCode = teachCourseDto.getCourseCode();
|
|
|
+ String courseName = teachCourseDto.getCourseName();
|
|
|
+ TeachCourseParams teachCourseParams = new TeachCourseParams();
|
|
|
+ teachCourseParams.setCourseCode(courseCode);
|
|
|
+ teachCourseParams.setCourseName(courseName);
|
|
|
+ this.manualCreate(teachCourseParams,requestUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<DictionaryResult> findBasicCourseByUser(SysUser requestUser) {
|
|
|
Long userId = requestUser.getId();
|
|
|
Set<Long> orgIdSet = sysOrgService.findDeepOrgIdListByUserId(userId);
|
|
|
QueryWrapper<BasicCourse> basicCourseQueryWrapper = new QueryWrapper<>();
|
|
|
basicCourseQueryWrapper.lambda().eq(BasicCourse::getEnable, true);
|
|
|
- if (orgIdSet.size() > 0){
|
|
|
+ if (orgIdSet.size() > 0) {
|
|
|
basicCourseQueryWrapper.lambda().in(BasicCourse::getTeachingRoomId, orgIdSet);
|
|
|
}
|
|
|
List<BasicCourse> basicCourseList = basicCourseService.list(basicCourseQueryWrapper);
|
|
@@ -105,24 +216,23 @@ public class TeachCourseServiceImpl extends ServiceImpl<TeachCourseMapper, Teach
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public Boolean deleteTeachCourseBatch(List<Long> idList) {
|
|
|
- List<TeachClazz> teachClazzList = teachClazzService.list(new QueryWrapper<TeachClazz>().lambda().in(TeachClazz::getTeachCourseId, idList));
|
|
|
- StringBuilder exception = new StringBuilder();
|
|
|
- Set<Long> teachCourseIdSet = teachClazzList.stream().map(TeachClazz::getTeachCourseId).collect(Collectors.toSet());
|
|
|
- for (Long teachCourseId : teachCourseIdSet) {
|
|
|
- String e = "";
|
|
|
- List<TeachClazz> cellList = teachClazzList.stream().filter(cell -> teachCourseId.equals(cell.getTeachCourseId())).collect(Collectors.toList());
|
|
|
- if (cellList.size() > 0) {
|
|
|
- String clazzNameStr = cellList.stream().map(TeachClazz::getTeachClazzName).collect(Collectors.joining(","));
|
|
|
- String courseName = basicCourseService.getById(this.getById(teachCourseId).getBasicCourseId()).getName();
|
|
|
- e = e + "【" + courseName + "】" + "已绑定教学班级【" + clazzNameStr + "】不能删除,请先删除被绑定的教学班级\n";
|
|
|
+ public void deleteTeachCourseBatch(List<Long> idList) {
|
|
|
+ List<Long> basicCourseIdList = this.listByIds(idList).stream().map(TeachCourse::getBasicCourseId).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(basicCourseIdList)){
|
|
|
+ List<TeachClazz> teachClazzList = teachClazzService.list(new QueryWrapper<TeachClazz>()
|
|
|
+ .lambda()
|
|
|
+ .in(TeachClazz::getBasicCourseId, basicCourseIdList));
|
|
|
+ if (CollectionUtils.isNotEmpty(teachClazzList)){
|
|
|
+
|
|
|
+ String msg = "";
|
|
|
+ List<Long> existCourseIdList = teachClazzList.stream().map(TeachClazz::getBasicCourseId).distinct().collect(Collectors.toList());
|
|
|
+ msg = basicCourseService.listByIds(existCourseIdList)
|
|
|
+ .stream()
|
|
|
+ .map(e -> e.getName() + "(" + e.getCode() + ")")
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("教学课程:【" + msg + "】下存在教学班级不能删除");
|
|
|
}
|
|
|
- exception.append(e);
|
|
|
- }
|
|
|
- if (teachClazzList.size() > 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(exception.toString());
|
|
|
+ this.removeByIds(idList);
|
|
|
}
|
|
|
- return this.removeByIds(idList);
|
|
|
}
|
|
|
-
|
|
|
}
|