|
@@ -1,24 +1,38 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
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.distributed.print.business.bean.dto.ExamTaskPrintDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.TaskPrintClassDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.TaskPrintHouseDto;
|
|
|
+import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
|
|
|
import com.qmth.distributed.print.business.bean.params.TaskPrintParams;
|
|
|
-import com.qmth.distributed.print.business.entity.BasicStudent;
|
|
|
-import com.qmth.distributed.print.business.entity.ExamDetailCourse;
|
|
|
-import com.qmth.distributed.print.business.entity.ExamStudent;
|
|
|
-import com.qmth.distributed.print.business.entity.ExamTaskPrint;
|
|
|
+import com.qmth.distributed.print.business.entity.*;
|
|
|
+import com.qmth.distributed.print.business.enums.ExamDataSourceEnum;
|
|
|
+import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
|
|
|
+import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.ExamTaskPrintMapper;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
+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.util.ConvertUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -39,6 +53,18 @@ public class ExamTaskPrintServiceImpl extends ServiceImpl<ExamTaskPrintMapper, E
|
|
|
@Autowired
|
|
|
private ExamStudentService examStudentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamPrintPlanService examPrintPlanService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BasicExamRuleService basicExamRuleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BasicCourseService basicCourseService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ConvertUtil convertUtil;
|
|
|
+
|
|
|
@Override
|
|
|
public List<ExamTaskPrint> createTaskPrint(TaskPrintParams taskPrintParams) {
|
|
|
Long schoolId = (Long) ServletUtil.getRequestHeaderSchoolId();
|
|
@@ -93,4 +119,211 @@ public class ExamTaskPrintServiceImpl extends ServiceImpl<ExamTaskPrintMapper, E
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExamTaskPrintDto listTaskPrint(Long printPlanId, String courseCode, Long paperNumber, Integer pageNumber, Integer pageSize) {
|
|
|
+ QueryWrapper<ExamTaskPrint> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamTaskPrint::getPrintPlanId, printPlanId)
|
|
|
+ .eq(ExamTaskPrint::getCourseCode, courseCode)
|
|
|
+ .eq(ExamTaskPrint::getPaperNumber, paperNumber);
|
|
|
+ Page<ExamTaskPrint> page = new Page<>(pageNumber, pageSize);
|
|
|
+ IPage<ExamTaskPrint> examTaskPrintIPage = this.baseMapper.selectPage(page, queryWrapper);
|
|
|
+ ExamTaskPrintDto examTaskPrintDto = new ExamTaskPrintDto();
|
|
|
+ if (examTaskPrintIPage.getRecords().size() > 0) {
|
|
|
+ examTaskPrintDto.setiPage(examTaskPrintIPage);
|
|
|
+ List<Long> startTimes = examTaskPrintIPage.getRecords().stream().map(m -> m.getExamStartTime()).distinct().collect(Collectors.toList());
|
|
|
+ List<Long> endTimes = examTaskPrintIPage.getRecords().stream().map(m -> m.getExamEndTime()).distinct().collect(Collectors.toList());
|
|
|
+ if (startTimes.size() != 1 || endTimes.size() != 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考试时间有误");
|
|
|
+ }
|
|
|
+ examTaskPrintDto.setExamStartTime(startTimes.get(0));
|
|
|
+ examTaskPrintDto.setExamEndTime(endTimes.get(0));
|
|
|
+ }
|
|
|
+ return examTaskPrintDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void createTaskPrint(ExamTaskPrint examTaskPrint) {
|
|
|
+ Long schoolId = (Long) ServletUtil.getRequestHeaderSchoolId();
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+
|
|
|
+ ExamPrintPlan examPrintPlan = examPrintPlanService.getById(examTaskPrint.getPrintPlanId());
|
|
|
+ if (examPrintPlan == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷计划不存在");
|
|
|
+ }
|
|
|
+ PrintPlanStatusEnum printPlanStatus = examPrintPlan.getStatus();
|
|
|
+ if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(printPlanStatus.getDesc() + "状态下的印刷计划不允许生成考务数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId(schoolId);
|
|
|
+ if (Objects.isNull(basicExamRule)) {
|
|
|
+ throw ExceptionResultEnum.EXAM_RULE_IS_NULL.exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> classIds = Arrays.asList(examTaskPrint.getClassId().split(","));
|
|
|
+ if (examTaskPrint.getId() == null) {
|
|
|
+ // 校验班级
|
|
|
+ QueryWrapper<ExamTaskPrint> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamTaskPrint::getPrintPlanId, examTaskPrint);
|
|
|
+ List<ExamTaskPrint> examTaskPrints = this.list(queryWrapper);
|
|
|
+ validateClass(examTaskPrints, classIds);
|
|
|
+
|
|
|
+ examTaskPrint.setSchoolId(schoolId);
|
|
|
+ examTaskPrint.setOrgId(sysUser.getOrgId());
|
|
|
+ examTaskPrint.setCreateId(sysUser.getId());
|
|
|
+ examTaskPrint.setCreateTime(System.currentTimeMillis());
|
|
|
+
|
|
|
+ // 卷袋号生成规则
|
|
|
+ SerialNumberParams serialNumberParams = new SerialNumberParams("packageCode-" + schoolId, "1", 6);
|
|
|
+ ExamDetail examDetail = new ExamDetail();
|
|
|
+ examDetail.setId(SystemConstant.getDbUuid());
|
|
|
+ examDetail.setPackageCode(createTempNumber(serialNumberParams));
|
|
|
+ examDetail.setSchoolId(schoolId);
|
|
|
+ examDetail.setPrintPlanId(examTaskPrint.getPrintPlanId());
|
|
|
+ examDetail.setPrintPlanName(examPrintPlan.getName());
|
|
|
+ examDetail.setExamPlace(examTaskPrint.getExamPlace());
|
|
|
+ examDetail.setExamRoom(examTaskPrint.getExamRoom());
|
|
|
+ examDetail.setStatus(ExamDetailStatusEnum.NEW);
|
|
|
+ examDetail.setTotalSubjects(examTaskPrint.getStudentCount());
|
|
|
+ examDetail.setExamStartTime(examTaskPrint.getExamStartTime());
|
|
|
+ examDetail.setExamEndTime(examTaskPrint.getExamEndTime());
|
|
|
+ examDetail.setExamDataSource(ExamDataSourceEnum.EXAM_TASK);
|
|
|
+ examDetail.setCreateId(examTaskPrint.getCreateId());
|
|
|
+ examDetail.setCreateTime(System.currentTimeMillis());
|
|
|
+ examDetailService.save(examDetail);
|
|
|
+
|
|
|
+ examTaskPrint.setExamDetailId(examDetail.getId());
|
|
|
+ this.save(examTaskPrint);
|
|
|
+
|
|
|
+ ExamDetailCourse examDetailCourse = new ExamDetailCourse();
|
|
|
+ examDetailCourse.setId(SystemConstant.getDbUuid());
|
|
|
+ examDetailCourse.setSchoolId(schoolId);
|
|
|
+ examDetailCourse.setExamDetailId(examDetail.getId());
|
|
|
+ examDetailCourse.setCourseCode(examTaskPrint.getCourseCode());
|
|
|
+ examDetailCourse.setCourseName(examTaskPrint.getCourseName());
|
|
|
+ examDetailCourse.setPaperNumber(examTaskPrint.getPaperNumber());
|
|
|
+ examDetailCourse.setTotalSubjects(examTaskPrint.getStudentCount());
|
|
|
+ examDetailCourse.setCreateId(examTaskPrint.getCreateId());
|
|
|
+ examDetailCourseService.save(examDetailCourse);
|
|
|
+
|
|
|
+ saveBatchStudent(examTaskPrint, classIds, examDetailCourse.getId());
|
|
|
+
|
|
|
+ // 更改印刷计划状态
|
|
|
+ examPrintPlan.setStatus(PrintPlanStatusEnum.READY);
|
|
|
+ examPrintPlanService.updateById(examPrintPlan);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 校验班级
|
|
|
+ QueryWrapper<ExamTaskPrint> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamTaskPrint::getPrintPlanId, examTaskPrint).ne(ExamTaskPrint::getId, examTaskPrint.getId());
|
|
|
+ List<ExamTaskPrint> examTaskPrints = this.list(queryWrapper);
|
|
|
+ // 校验班级
|
|
|
+ validateClass(examTaskPrints, classIds);
|
|
|
+
|
|
|
+ ExamTaskPrint taskPrint = this.getById(examTaskPrint.getId());
|
|
|
+ taskPrint.setExamPlace(examTaskPrint.getExamPlace());
|
|
|
+ taskPrint.setExamRoom(examTaskPrint.getExamRoom());
|
|
|
+ taskPrint.setInvigilatorTeacher(examTaskPrint.getInvigilatorTeacher());
|
|
|
+ taskPrint.setClassId(examTaskPrint.getClassId());
|
|
|
+ taskPrint.setClassName(examTaskPrint.getClassName());
|
|
|
+ taskPrint.setStudentCount(examTaskPrint.getStudentCount());
|
|
|
+ taskPrint.setPrintHouseId(examTaskPrint.getPrintHouseId());
|
|
|
+ taskPrint.setUpdateId(sysUser.getId());
|
|
|
+ taskPrint.setUpdateTime(System.currentTimeMillis());
|
|
|
+ this.updateById(taskPrint);
|
|
|
+
|
|
|
+ ExamDetail examDetail = examDetailService.getById(taskPrint.getExamDetailId());
|
|
|
+ examDetail.setExamPlace(examTaskPrint.getExamPlace());
|
|
|
+ examDetail.setExamRoom(examTaskPrint.getExamRoom());
|
|
|
+ examDetail.setTotalSubjects(examTaskPrint.getStudentCount());
|
|
|
+ examDetail.setUpdateId(sysUser.getId());
|
|
|
+ examDetail.setUpdateTime(System.currentTimeMillis());
|
|
|
+ examDetailService.updateById(examDetail);
|
|
|
+
|
|
|
+ QueryWrapper<ExamDetailCourse> examDetailCourseQueryWrapper = new QueryWrapper<>();
|
|
|
+ examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, taskPrint.getExamDetailId());
|
|
|
+ ExamDetailCourse examDetailCourse = examDetailCourseService.getOne(examDetailCourseQueryWrapper);
|
|
|
+
|
|
|
+ UpdateWrapper<ExamStudent> examStudentUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ examStudentUpdateWrapper.lambda().eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
|
|
|
+ examStudentService.remove(examStudentUpdateWrapper);
|
|
|
+
|
|
|
+ saveBatchStudent(taskPrint, classIds, examDetailCourse.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TaskPrintClassDto> listClass(String printPlanId, String courseCode, String paperNumber) {
|
|
|
+ Long schoolId = (Long) ServletUtil.getRequestHeaderSchoolId();
|
|
|
+ QueryWrapper<BasicCourse> courseQueryWrapper = new QueryWrapper<>();
|
|
|
+ courseQueryWrapper.lambda().eq(BasicCourse::getSchoolId, schoolId).eq(BasicCourse::getCode, courseCode);
|
|
|
+ List<BasicCourse> courseList = basicCourseService.list(courseQueryWrapper);
|
|
|
+ List<String> stringList = courseList.stream().map(m -> m.getClazz()).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(!CollectionUtils.isEmpty(stringList)) {
|
|
|
+ QueryWrapper<ExamTaskPrint> examTaskPrintQueryWrapper = new QueryWrapper<>();
|
|
|
+ examTaskPrintQueryWrapper.lambda().eq(ExamTaskPrint::getPrintPlanId, printPlanId).eq(ExamTaskPrint::getCourseCode, courseCode).eq(ExamTaskPrint::getPaperNumber, paperNumber);
|
|
|
+ List<ExamTaskPrint> examTaskPrints = this.list(examTaskPrintQueryWrapper);
|
|
|
+ for (ExamTaskPrint examTaskPrint : examTaskPrints) {
|
|
|
+ List<String> classIds = Arrays.asList(examTaskPrint.getClassId().split(","));
|
|
|
+ for (String classId : classIds) {
|
|
|
+ if(stringList.contains(classId)){
|
|
|
+ stringList.remove(classId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TaskPrintClassDto> taskPrintClassDtos = basicStudentService.listByClass(schoolId, stringList);
|
|
|
+ return taskPrintClassDtos;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TaskPrintHouseDto> listHouse() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveBatchStudent(ExamTaskPrint examTaskPrint, List<String> classIds, Long examDetailCourseId) {
|
|
|
+ QueryWrapper<BasicStudent> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.lambda().eq(BasicStudent::getSchoolId, examTaskPrint.getSchoolId()).in(BasicStudent::getClazz, classIds);
|
|
|
+ List<BasicStudent> basicStudents = basicStudentService.list(queryWrapper1);
|
|
|
+ AtomicInteger atomicInteger = new AtomicInteger(1);
|
|
|
+ List<ExamStudent> examStudents = new ArrayList<>();
|
|
|
+ SerialNumberParams ticketNumberParams = new SerialNumberParams("ticketNumber-" + examTaskPrint.getSchoolId(), DateUtil.format(new Date(), "yyyyMM"), 6);
|
|
|
+ for (BasicStudent basicStudent : basicStudents) {
|
|
|
+ ExamStudent examStudent = new ExamStudent();
|
|
|
+ examStudent.setId(SystemConstant.getDbUuid());
|
|
|
+ examStudent.setSchoolId(examTaskPrint.getSchoolId());
|
|
|
+ examStudent.setExamDetailCourseId(examDetailCourseId);
|
|
|
+ examStudent.setStudentName(basicStudent.getStudentName());
|
|
|
+ examStudent.setStudentCode(basicStudent.getStudentCode());
|
|
|
+ // 准考证号(年月+000001)
|
|
|
+ examStudent.setTicketNumber(createTempNumber(ticketNumberParams));
|
|
|
+ examStudent.setExtendFields(JSON.toJSONString(examTaskPrint.getExtendFields()));
|
|
|
+ examStudent.setSiteNumber(String.valueOf(atomicInteger.getAndIncrement()));
|
|
|
+ examStudent.setCreateId(examTaskPrint.getCreateId());
|
|
|
+ examStudents.add(examStudent);
|
|
|
+ }
|
|
|
+ examStudentService.saveBatch(examStudents);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateClass(List<ExamTaskPrint> examTaskPrints, List<String> classIds) {
|
|
|
+ if (!CollectionUtils.isEmpty(examTaskPrints)) {
|
|
|
+ for (ExamTaskPrint taskPrint : examTaskPrints) {
|
|
|
+ List<String> hisClassIds = Arrays.asList(taskPrint.getClassId().split(","));
|
|
|
+ for (String classId : classIds) {
|
|
|
+ if (hisClassIds.contains(classId)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(classId + "已分配考场");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String createTempNumber(SerialNumberParams serialNumberParams) {
|
|
|
+ return convertUtil.getIncre(serialNumberParams.getPrefix(), serialNumberParams.getModel(), serialNumberParams.getDigit());
|
|
|
+ }
|
|
|
}
|