|
@@ -0,0 +1,101 @@
|
|
|
+package com.qmth.eds.service.impl;
|
|
|
+
|
|
|
+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.qmth.boot.tools.excel.ExcelReader;
|
|
|
+import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
+import com.qmth.eds.bean.dto.ExamCourseMappingDto;
|
|
|
+import com.qmth.eds.common.entity.ExamCourseMapping;
|
|
|
+import com.qmth.eds.common.entity.ExamSemester;
|
|
|
+import com.qmth.eds.common.entity.ExamType;
|
|
|
+import com.qmth.eds.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.eds.common.util.ServletUtil;
|
|
|
+import com.qmth.eds.mapper.ExamCourseMappingMapper;
|
|
|
+import com.qmth.eds.service.ExamCourseMappingService;
|
|
|
+import com.qmth.eds.service.ExamSemesterService;
|
|
|
+import com.qmth.eds.service.ExamTypeService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ExamCourseMappingServiceImpl extends ServiceImpl<ExamCourseMappingMapper, ExamCourseMapping> implements ExamCourseMappingService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ExamSemesterService examSemesterService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ExamTypeService examTypeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<ExamCourseMapping> pageData(Long semesterId, Long examTypeId, String syncCourseCode, String cloudMarkingCourseCode, Integer pageNumber, Integer pageSize) {
|
|
|
+ QueryWrapper<ExamCourseMapping> queryWrapper = new QueryWrapper<>();
|
|
|
+ if (semesterId != null) {
|
|
|
+ queryWrapper.lambda().eq(ExamCourseMapping::getSemesterId, semesterId);
|
|
|
+ }
|
|
|
+ if (examTypeId != null) {
|
|
|
+ queryWrapper.lambda().eq(ExamCourseMapping::getExamTypeId, examTypeId);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(syncCourseCode)) {
|
|
|
+ queryWrapper.lambda().likeRight(ExamCourseMapping::getSyncCourseCode, syncCourseCode);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(cloudMarkingCourseCode)) {
|
|
|
+ queryWrapper.lambda().likeRight(ExamCourseMapping::getCloudMarkingCourseCode, cloudMarkingCourseCode);
|
|
|
+ }
|
|
|
+ queryWrapper.lambda().orderByAsc(ExamCourseMapping::getSyncCourseCode);
|
|
|
+ Page<ExamCourseMapping> page = new Page<>(pageNumber, pageSize);
|
|
|
+ return this.page(page, queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void importData(Long semesterId, Long examTypeId, MultipartFile file) {
|
|
|
+ Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
+ try {
|
|
|
+ ExamSemester examSemester = examSemesterService.getById(semesterId);
|
|
|
+ ExamType examType = examTypeService.getById(examTypeId);
|
|
|
+
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ ExcelReader excelReader = ExcelReader.create(ExcelType.XLSX, inputStream, 1);
|
|
|
+ // 读取文件内容
|
|
|
+ List<ExamCourseMappingDto> examCourseMappingDtos = excelReader.getObjectList(ExamCourseMappingDto.class);
|
|
|
+ // 数据去重
|
|
|
+ Set<ExamCourseMappingDto> courseMappingDtoHashSet = new HashSet<>(examCourseMappingDtos);
|
|
|
+
|
|
|
+ // 查询学期+考试下所有对应关系
|
|
|
+ QueryWrapper<ExamCourseMapping> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamCourseMapping::getSchoolId, schoolId)
|
|
|
+ .eq(ExamCourseMapping::getSemesterId, semesterId)
|
|
|
+ .eq(ExamCourseMapping::getExamTypeId, examTypeId);
|
|
|
+ List<ExamCourseMapping> examCourseMappingList = this.list(queryWrapper);
|
|
|
+ List<ExamCourseMapping> examCourseMappings = new ArrayList<>();
|
|
|
+ for (ExamCourseMappingDto examCourseMappingDto : courseMappingDtoHashSet) {
|
|
|
+ ExamCourseMapping examCourseMapping = null;
|
|
|
+ Optional<ExamCourseMapping> optionalExamCourseMapping = examCourseMappingList.stream().filter(m -> examCourseMappingDto.getSyncCourseCode().equals(m.getSyncCourseCode())).findFirst();
|
|
|
+ if (optionalExamCourseMapping.isPresent()) {
|
|
|
+ examCourseMapping = optionalExamCourseMapping.get();
|
|
|
+ }
|
|
|
+ // 不存在,新增
|
|
|
+ if (examCourseMapping == null) {
|
|
|
+ examCourseMapping = new ExamCourseMapping(schoolId, semesterId, examSemester.getName(), examTypeId, examType.getName(), examCourseMappingDto.getSyncCourseCode(), examCourseMappingDto.getCloudMarkingCourseCode());
|
|
|
+ }
|
|
|
+ // 存在且云阅卷课程代码不一致,更新
|
|
|
+ else if (!examCourseMapping.getCloudMarkingCourseCode().equals(examCourseMappingDto.getCloudMarkingCourseCode())) {
|
|
|
+ examCourseMapping.setCloudMarkingCourseCode(examCourseMappingDto.getCloudMarkingCourseCode());
|
|
|
+ }
|
|
|
+ // 存在且云阅卷课程代码一致,不处理
|
|
|
+
|
|
|
+ examCourseMappings.add(examCourseMapping);
|
|
|
+ }
|
|
|
+ // 批量新增、修改
|
|
|
+ this.saveOrUpdateBatch(examCourseMappings);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("导入异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|