|
@@ -41,6 +41,7 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -53,6 +54,7 @@ import java.io.*;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -127,6 +129,15 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
@Resource
|
|
|
TeachcloudCommonService teachcloudCommonService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ ConvertUtil convertUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamDetailCourseService examDetailCourseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BasicStudentService basicStudentService;
|
|
|
+
|
|
|
/**
|
|
|
* 创建pdf前置条件
|
|
|
*
|
|
@@ -708,7 +719,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
}
|
|
|
|
|
|
// 删除印刷计划下的考务数据
|
|
|
- examDetailService.deleteExaminationData(printPlanId);
|
|
|
+ examDetailService.deleteExaminationData(printPlanId, ExamDataSourceEnum.FILE_IMPORT);
|
|
|
|
|
|
// 卷袋号生成规则
|
|
|
SerialNumberParams serialNumberParams = new SerialNumberParams("packageCode-" + schoolId, "1", 6);
|
|
@@ -1049,4 +1060,114 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
map.put("count", 1);
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> executeGenerateExamLogic(Map<String, Object> map) {
|
|
|
+ List<ExamTaskPrint> list = (List<ExamTaskPrint>) map.get("list");
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
+ Long printPlanId = list.stream().map(m -> m.getPrintPlanId()).findFirst().get();
|
|
|
+ Long schoolId = (Long) ServletUtil.getRequestHeaderSchoolId();
|
|
|
+ if (!tbTaskService.countByPrintPlanIdAndEntityId(schoolId, printPlanId, null)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("当前印刷计划正在生成pdf,无法导入考务数据");
|
|
|
+ }
|
|
|
+ ExamPrintPlan examPrintPlan = examPrintPlanService.getById(printPlanId);
|
|
|
+ if (examPrintPlan == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷计划不存在");
|
|
|
+ }
|
|
|
+ PrintPlanStatusEnum printPlanStatus = examPrintPlan.getStatus();
|
|
|
+ if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(printPlanStatus + "状态下的印刷计划不允许重新提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ String printPlanName = examPrintPlan.getName();
|
|
|
+ // 该学校有效考务数据
|
|
|
+ List<FieldsDto> fieldsDtoList = examDetailService.findExaminationFields(schoolId);
|
|
|
+ if (fieldsDtoList.size() == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该学校没有设置考务数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除印刷计划下的考务数据
|
|
|
+ examDetailService.deleteExaminationData(printPlanId, ExamDataSourceEnum.EXAM_TASK);
|
|
|
+
|
|
|
+ List<Long> examDetailIdList = new ArrayList<>();
|
|
|
+ for (ExamTaskPrint examTaskPrint : list) {
|
|
|
+ // 卷袋号生成规则
|
|
|
+ SerialNumberParams serialNumberParams = new SerialNumberParams("packageCode-" + schoolId, "1", 6);
|
|
|
+ String key = serialNumberParams.getModel() + serialNumberParams.getPrefix();
|
|
|
+ RedisAtomicLong counter = new RedisAtomicLong(key, Objects.requireNonNull(redisTemplate.getConnectionFactory()));
|
|
|
+ Long value = counter.get();
|
|
|
+ try {
|
|
|
+ ExamDetail examDetail = new ExamDetail();
|
|
|
+ examDetail.setId(SystemConstant.getDbUuid());
|
|
|
+ examDetail.setPackageCode(createTempNumber(serialNumberParams));
|
|
|
+ examDetail.setSchoolId(schoolId);
|
|
|
+ examDetail.setPrintPlanId(printPlanId);
|
|
|
+ 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());
|
|
|
+ examDetailService.save(examDetail);
|
|
|
+ examDetailIdList.add(examDetail.getId());
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ List<String> classIds = Arrays.asList(examTaskPrint.getClassId().split(","));
|
|
|
+ QueryWrapper<BasicStudent> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(BasicStudent::getSchoolId, schoolId).in(BasicStudent::getClazz, classIds);
|
|
|
+ List<BasicStudent> basicStudents = basicStudentService.list(queryWrapper);
|
|
|
+ AtomicInteger atomicInteger = new AtomicInteger(1);
|
|
|
+ List<ExamStudent> examStudents = new ArrayList<>();
|
|
|
+ SerialNumberParams ticketNumberParams = new SerialNumberParams("ticketNumber-" + schoolId, DateUtil.format(new Date(), "yyyyMM"), 6);
|
|
|
+ for (BasicStudent basicStudent : basicStudents) {
|
|
|
+ ExamStudent examStudent = new ExamStudent();
|
|
|
+ examStudent.setId(SystemConstant.getDbUuid());
|
|
|
+ examStudent.setSchoolId(schoolId);
|
|
|
+ examStudent.setExamDetailCourseId(examDetailCourse.getId());
|
|
|
+ examStudent.setStudentName(basicStudent.getStudentName());
|
|
|
+ examStudent.setStudentCode(basicStudent.getStudentCode());
|
|
|
+ // 准考证号(年月+000001)
|
|
|
+ examStudent.setTicketNumber(createTempNumber(ticketNumberParams));
|
|
|
+// examStudent.setExtendFields(JSON.toJSONString(extendFieldsDtoList));
|
|
|
+ examStudent.setSiteNumber(String.valueOf(atomicInteger.getAndIncrement()));
|
|
|
+ examStudent.setCreateId(examTaskPrint.getCreateId());
|
|
|
+ examStudent.setUpdateId(examTaskPrint.getCreateId());
|
|
|
+ examStudents.add(examStudent);
|
|
|
+ }
|
|
|
+ examStudentService.saveBatch(examStudents);
|
|
|
+ } catch (Exception e) {
|
|
|
+ redisTemplate.opsForValue().set(key, value);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更改印刷计划状态
|
|
|
+ examPrintPlan.setStatus(PrintPlanStatusEnum.READY);
|
|
|
+ examPrintPlanService.updateById(examPrintPlan);
|
|
|
+
|
|
|
+ map.put("examDetailIdList", examDetailIdList);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String createTempNumber(SerialNumberParams serialNumberParams){
|
|
|
+ return convertUtil.getIncre(serialNumberParams.getPrefix(), serialNumberParams.getModel(), serialNumberParams.getDigit());
|
|
|
+ }
|
|
|
}
|