|
@@ -3,21 +3,27 @@ package cn.com.qmth.print.manage.service.impl;
|
|
|
import cn.com.qmth.print.manage.dao.ExamDao;
|
|
|
import cn.com.qmth.print.manage.dao.ExamStudentDao;
|
|
|
import cn.com.qmth.print.manage.dto.StudentDTO;
|
|
|
+import cn.com.qmth.print.manage.entity.CheckRecordEntity;
|
|
|
import cn.com.qmth.print.manage.entity.ExamEntity;
|
|
|
import cn.com.qmth.print.manage.entity.ExamStudentEntity;
|
|
|
import cn.com.qmth.print.manage.enums.GroupType;
|
|
|
+import cn.com.qmth.print.manage.enums.RecordStatus;
|
|
|
+import cn.com.qmth.print.manage.service.BreakRecordService;
|
|
|
+import cn.com.qmth.print.manage.service.CheckRecordService;
|
|
|
import cn.com.qmth.print.manage.service.ExamStudentService;
|
|
|
import cn.com.qmth.print.manage.service.query.ExamStudentQuery;
|
|
|
import cn.com.qmth.print.manage.utils.excel.ExcelError;
|
|
|
import cn.com.qmth.print.manage.utils.excel.ExcelReader;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
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.core.exception.StatusException;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
@@ -30,11 +36,18 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.StringJoiner;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStudentEntity> implements
|
|
|
ExamStudentService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CheckRecordService checkRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BreakRecordService breakRecordService;
|
|
|
+
|
|
|
@Resource
|
|
|
private ExamDao examDao;
|
|
|
|
|
@@ -106,7 +119,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
return this.page(page, queryWrapper);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
@Override
|
|
|
public List<ExcelError> importStudents(Long examId, MultipartFile file) throws IOException {
|
|
|
ExamEntity examEntity = examDao.selectById(examId);
|
|
@@ -144,20 +156,66 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
}
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(studentList)) {
|
|
|
- List<ExamStudentEntity> data = new ArrayList<>();
|
|
|
- for (ExamStudentEntity stu : studentList) {
|
|
|
- if (data.size() == 2000) {
|
|
|
- this.saveBatch(data);
|
|
|
- data.clear();
|
|
|
- }
|
|
|
- data.add(stu);
|
|
|
- }
|
|
|
- // 将剩下的数据也导入
|
|
|
- if (!data.isEmpty()) {
|
|
|
+ insertData(examEntity, studentList);
|
|
|
+ }
|
|
|
+ return excelErrors;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteByExamId(Long examId) {
|
|
|
+ UpdateWrapper<ExamStudentEntity> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().eq(ExamStudentEntity::getExamId, examId);
|
|
|
+ this.remove(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void insertData(ExamEntity examEntity, List<ExamStudentEntity> studentList) {
|
|
|
+ // 删除考生表
|
|
|
+ this.deleteByExamId(examEntity.getId());
|
|
|
+ // 删除校验记录
|
|
|
+ checkRecordService.deleteByExamId(examEntity.getId());
|
|
|
+ // 删除中断记录
|
|
|
+ breakRecordService.deleteByExamId(examEntity.getId());
|
|
|
+
|
|
|
+ // 添加考生
|
|
|
+ List<ExamStudentEntity> data = new ArrayList<>();
|
|
|
+ for (ExamStudentEntity stu : studentList) {
|
|
|
+ if (data.size() == 2000) {
|
|
|
this.saveBatch(data);
|
|
|
+ data.clear();
|
|
|
}
|
|
|
+ data.add(stu);
|
|
|
+ }
|
|
|
+ // 将剩下的数据也导入
|
|
|
+ if (!data.isEmpty()) {
|
|
|
+ this.saveBatch(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加校验数据
|
|
|
+ List<CheckRecordEntity> checkRecordEntities = studentList.stream().map(m->{
|
|
|
+ CheckRecordEntity checkRecordEntity = new CheckRecordEntity();
|
|
|
+ checkRecordEntity.setOrgId(examEntity.getOrgId());
|
|
|
+ checkRecordEntity.setExamId(examEntity.getId());
|
|
|
+ checkRecordEntity.setGroupType(examEntity.getGroupType());
|
|
|
+ checkRecordEntity.setGroupName(examEntity.getGroupType().getName());
|
|
|
+ checkRecordEntity.setStatus(RecordStatus.NONE);
|
|
|
+ checkRecordEntity.setCreateTime(new Date());
|
|
|
+ checkRecordEntity.setUpdateTime(new Date());
|
|
|
+ return checkRecordEntity;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<CheckRecordEntity> data1 = new ArrayList<>();
|
|
|
+ for (CheckRecordEntity stu : checkRecordEntities) {
|
|
|
+ if (data1.size() == 2000) {
|
|
|
+ checkRecordService.saveBatch(data1);
|
|
|
+ data1.clear();
|
|
|
+ }
|
|
|
+ data1.add(stu);
|
|
|
+ }
|
|
|
+ // 将剩下的数据也导入
|
|
|
+ if (!data1.isEmpty()) {
|
|
|
+ checkRecordService.saveBatch(data1);
|
|
|
}
|
|
|
- return excelErrors;
|
|
|
}
|
|
|
|
|
|
/**
|