|
@@ -27,7 +27,9 @@ import com.qmth.teachcloud.common.base.BaseEntity;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.*;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.export.BasicStudentErrorExportDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.export.SysUserErrorExportDto;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.mark.MarkUser;
|
|
|
import com.qmth.teachcloud.common.bean.params.ArraysParams;
|
|
|
+import com.qmth.teachcloud.common.bean.params.UserSaveParams;
|
|
|
import com.qmth.teachcloud.common.bean.result.ExcelResult;
|
|
|
import com.qmth.teachcloud.common.bean.vo.PaperInfoVo;
|
|
|
import com.qmth.teachcloud.common.bean.vo.PrintPathVo;
|
|
@@ -39,7 +41,7 @@ import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import com.qmth.teachcloud.common.util.excel.ExcelError;
|
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
|
-import com.qmth.teachcloud.mark.params.MarkQuestionParams;
|
|
|
+import com.qmth.teachcloud.mark.service.MarkGroupService;
|
|
|
import com.qmth.teachcloud.mark.service.MarkPaperService;
|
|
|
import com.qmth.teachcloud.mark.service.MarkQuestionService;
|
|
|
import com.qmth.teachcloud.mark.service.MarkStudentService;
|
|
@@ -71,6 +73,7 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @Description: 任务处理逻辑impl
|
|
@@ -107,11 +110,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
TBTaskPdfService tbTaskPdfService;
|
|
|
@Resource
|
|
|
BasicCardRuleService basicCardRuleService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
ExamDetailCourseService examDetailCourseService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
BasicStudentService basicStudentService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
ExamTaskPrintService examTaskPrintService;
|
|
|
@Resource
|
|
|
BasicExamService basicExamService;
|
|
@@ -133,9 +136,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
@Lazy
|
|
|
PrintCommonService printCommonService;
|
|
|
@Resource
|
|
|
- private DownloadService downloadService;
|
|
|
+ DownloadService downloadService;
|
|
|
@Resource
|
|
|
- private TeachClazzService teachClazzService;
|
|
|
+ TeachClazzService teachClazzService;
|
|
|
@Resource
|
|
|
DictionaryConfig dictionaryConfig;
|
|
|
@Resource
|
|
@@ -152,6 +155,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
MarkStudentService markStudentService;
|
|
|
@Resource
|
|
|
MarkQuestionService markQuestionService;
|
|
|
+ @Resource
|
|
|
+ MarkGroupService markGroupService;
|
|
|
+ @Resource
|
|
|
+ SysRoleService sysRoleService;
|
|
|
|
|
|
/**
|
|
|
* 创建pdf前置条件
|
|
@@ -2355,7 +2362,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
// 公共异常提示
|
|
|
String logicErrorCommonNotice = "";
|
|
|
|
|
|
- // 行索引
|
|
|
String courseCode = objectiveStructDto.getCourseCode();
|
|
|
String courseName = objectiveStructDto.getCourseName();
|
|
|
String paperNumber = objectiveStructDto.getPaperNumber();
|
|
@@ -2367,7 +2373,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
Integer questionType = objectiveStructDto.getQuestionType();
|
|
|
String errorMsg = objectiveStructDto.getErrorMsg();
|
|
|
|
|
|
- // 1.判断题号重复
|
|
|
+ // 1.题号重复校验
|
|
|
if (SystemConstant.strNotNull(paperNumber) && mainNumber != null && subNumber != null) {
|
|
|
logicErrorCommonNotice = String.format("试卷编号为[%s],大题号为[%s],小题号为[%s]的数据异常 : ", paperNumber, mainNumber,
|
|
|
subNumber);
|
|
@@ -2467,6 +2473,254 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> executeImportSubjectiveStructLogic(Map<String, Object> map) throws Exception {
|
|
|
+ SysUser requestUser = (SysUser) map.get(SystemConstant.USER);
|
|
|
+ InputStream inputStream = (InputStream) map.get("inputStream");
|
|
|
+ Long examId = SystemConstant.convertIdToLong(String.valueOf(map.get("examId")));
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
+ BasicExam basicExam = basicExamService.getById(examId);
|
|
|
+ if (Objects.isNull(basicExam)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考试不存在");
|
|
|
+ }
|
|
|
+ if (!ExamModelEnum.MODEL4.equals(basicExam.getExamModel())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("仅针对模式4的考试可以导入");
|
|
|
+ }
|
|
|
+ SysRole markerRole = sysRoleService.getOne(
|
|
|
+ new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.MARKER));
|
|
|
+ if (Objects.isNull(markerRole)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("缺少评卷员角色");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 课程编号名称校验
|
|
|
+ Map<String, String> courseCheckMap = basicCourseService.list(
|
|
|
+ new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId, schoolId)).stream()
|
|
|
+ .collect(Collectors.toMap(BasicCourse::getCode, BasicCourse::getName));
|
|
|
+ List<MarkPaper> markPaperList = markPaperService.list(
|
|
|
+ new QueryWrapper<MarkPaper>().lambda().eq(MarkPaper::getExamId, examId));
|
|
|
+ // 题号重复校验
|
|
|
+ // 导入的客观题题号集合
|
|
|
+ Set<String> questionNumberCheckSet = new HashSet<>();
|
|
|
+ // 该试卷已存在的客观题题号集合
|
|
|
+ Set<String> dbObjectiveQuestionNumberSet = markQuestionService.list(
|
|
|
+ new QueryWrapper<MarkQuestion>().lambda().eq(MarkQuestion::getExamId, examId)
|
|
|
+ .eq(MarkQuestion::getObjective, true)).stream()
|
|
|
+ .map(e -> e.getPaperNumber() + SystemConstant.HYPHEN + e.getMainNumber() + SystemConstant.HYPHEN + e.getSubNumber()).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ ExcelResult<SubjectiveStructDto> excelResult = ConvertUtil.analyzeExcel(inputStream, SubjectiveStructDto.class,
|
|
|
+ true, 0);
|
|
|
+ List<SubjectiveStructDto> subjectiveStructDtoList = excelResult.getDatasource();
|
|
|
+ for (SubjectiveStructDto subjectiveStructDto : subjectiveStructDtoList) {
|
|
|
+ List<String> excelErrorList = new ArrayList<>();
|
|
|
+ // 公共异常提示
|
|
|
+ String excelErrorCommonNotice = "";
|
|
|
+
|
|
|
+ String courseCode = subjectiveStructDto.getCourseCode();
|
|
|
+ String courseName = subjectiveStructDto.getCourseName();
|
|
|
+ String paperNumber = subjectiveStructDto.getPaperNumber();
|
|
|
+ String mainTitle = subjectiveStructDto.getMainTitle();
|
|
|
+ Integer mainNumber = subjectiveStructDto.getMainNumber();
|
|
|
+ Integer subNumber = subjectiveStructDto.getSubNumber();
|
|
|
+ Double totalScore = subjectiveStructDto.getTotalScore();
|
|
|
+ Double intervalScore = subjectiveStructDto.getIntervalScore();
|
|
|
+ Integer groupNumber = subjectiveStructDto.getGroupNumber();
|
|
|
+ Integer markerCount = subjectiveStructDto.getMarkerCount();
|
|
|
+ String markerCodes = subjectiveStructDto.getMarkerCodes();
|
|
|
+ String errorMsg = subjectiveStructDto.getErrorMsg();
|
|
|
+
|
|
|
+ // 1.题号重复校验
|
|
|
+ if (SystemConstant.strNotNull(paperNumber) && mainNumber != null && subNumber != null) {
|
|
|
+ excelErrorCommonNotice = String.format("试卷编号为[%s],大题号为[%s],小题号为[%s]的数据异常 : ", paperNumber, mainNumber,
|
|
|
+ subNumber);
|
|
|
+ String questionNumberKey = paperNumber + SystemConstant.HYPHEN + mainNumber + SystemConstant.HYPHEN + subNumber;
|
|
|
+ if (questionNumberCheckSet.contains(questionNumberKey)) {
|
|
|
+ excelErrorList.add("excel中题号重复");
|
|
|
+ } else {
|
|
|
+ questionNumberCheckSet.add(questionNumberKey);
|
|
|
+ }
|
|
|
+ if (dbObjectiveQuestionNumberSet.contains(questionNumberKey)) {
|
|
|
+ excelErrorList.add("该题号已存在客观题中");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2.校验课程代码,课程名称,试卷在考试下是否存在
|
|
|
+ if (SystemConstant.strNotNull(courseCode) && SystemConstant.strNotNull(courseName) && SystemConstant.strNotNull(paperNumber)) {
|
|
|
+ if (!courseCheckMap.containsKey(courseCode)) {
|
|
|
+ excelErrorList.add("课程代码不存在");
|
|
|
+ } else if (!courseCheckMap.get(courseCode).equals(courseName)) {
|
|
|
+ excelErrorList.add("课程代码名称不匹配");
|
|
|
+ }
|
|
|
+ if (markPaperList.stream().noneMatch(m -> m.getPaperNumber().equals(paperNumber) && m.getCourseCode().equals(courseCode))) {
|
|
|
+ excelErrorList.add("试卷不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3.评卷员校验
|
|
|
+ if (Objects.isNull(markerCount) && Objects.isNull(markerCodes)){
|
|
|
+ excelErrorList.add("[评卷员数量(系统生成)]和[绑定工号(英文逗号分隔)]不能同时为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 整理异常信息
|
|
|
+ if (CollectionUtils.isNotEmpty(excelErrorList)) {
|
|
|
+ if (SystemConstant.strNotNull(errorMsg)) {
|
|
|
+ errorMsg = errorMsg + "、" + excelErrorCommonNotice + String.join("、", excelErrorList);
|
|
|
+ } else {
|
|
|
+ errorMsg = excelErrorCommonNotice + String.join("、", excelErrorList);
|
|
|
+ }
|
|
|
+ subjectiveStructDto.setErrorMsg(errorMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (subjectiveStructDtoList.stream().anyMatch(e -> SystemConstant.strNotNull(e.getErrorMsg()))) {
|
|
|
+ // 抛出excel解析异常
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(
|
|
|
+ subjectiveStructDtoList.stream().map(SubjectiveStructDto::getErrorMsg).filter(SystemConstant::strNotNull).collect(Collectors.joining(System.lineSeparator())));
|
|
|
+ } else {
|
|
|
+ List<String> logicErrorList = new ArrayList<>();
|
|
|
+ // 试卷编号-> 题目集合 Map
|
|
|
+ Map<String, List<SubjectiveStructDto>> paperQuestionsMap = subjectiveStructDtoList.stream().collect(Collectors.groupingBy(SubjectiveStructDto::getPaperNumber));
|
|
|
+ paperQuestionsMap.forEach((paperNumber, paperQuestionList) -> {
|
|
|
+ if (markGroupService.countByExamIdAndPaperNumber(examId,paperNumber) > 0){
|
|
|
+ logicErrorList.add(String.format("[试卷编号]%s,已存在分组,请先删除该试卷的所有分组再导入试题", paperNumber));
|
|
|
+ }
|
|
|
+ // 创建评卷试题
|
|
|
+ List<MarkQuestion> markQuestionList = paperQuestionList.stream().flatMap(e -> {
|
|
|
+ MarkQuestion markQuestion = new MarkQuestion();
|
|
|
+ markQuestion.setExamId(examId);
|
|
|
+ markQuestion.setPaperNumber(paperNumber);
|
|
|
+ markQuestion.setPaperType(OptionsEnum.A.getCode());
|
|
|
+ markQuestion.setObjective(false);
|
|
|
+ markQuestion.setMainNumber(e.getMainNumber());
|
|
|
+ markQuestion.setSubNumber(e.getSubNumber());
|
|
|
+ markQuestion.setMainTitle(e.getMainTitle());
|
|
|
+ markQuestion.setTotalScore(e.getTotalScore());
|
|
|
+ markQuestion.setIntervalScore(e.getIntervalScore());
|
|
|
+ return Stream.of(markQuestion);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ // 试卷下分组集合
|
|
|
+ List<Integer> groupNumberList = paperQuestionList.stream()
|
|
|
+ .map(SubjectiveStructDto::getGroupNumber)
|
|
|
+ .distinct().sorted()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 评卷员序号
|
|
|
+ AtomicInteger markerNumber = new AtomicInteger(0);
|
|
|
+ for (Integer groupNumber : groupNumberList) {
|
|
|
+ // 分组下题目集合
|
|
|
+ List<SubjectiveStructDto> groupQuestionList = paperQuestionList.stream()
|
|
|
+ .filter(e -> e.getGroupNumber().equals(groupNumber))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ String paperNumberGroupNumberNotice = String.format("[试卷编号]%s,[评卷分组(只能用小写数字)]%s",paperNumber, groupNumber);
|
|
|
+
|
|
|
+ String orgName = null;
|
|
|
+ Long orgId = null;
|
|
|
+ BasicCourse basicCourse = basicCourseService.getOne(new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId,schoolId).eq(BasicCourse::getCode,groupQuestionList.get(0).getCourseCode()));
|
|
|
+ if (Objects.isNull(basicCourse)){
|
|
|
+ logicErrorList.add(paperNumberGroupNumberNotice + "的[课程代码]不存在");
|
|
|
+ } else {
|
|
|
+ Long teachingRoomId = basicCourse.getTeachingRoomId();
|
|
|
+ SysOrg sysOrg = sysOrgService.getById(teachingRoomId);
|
|
|
+ if (Objects.isNull(sysOrg)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("无法找到机构");
|
|
|
+ }
|
|
|
+ orgName = sysOrg.getName();
|
|
|
+ orgId = sysOrg.getId();
|
|
|
+ }
|
|
|
+ Integer markerCount = null;
|
|
|
+ String markerCodes = null;
|
|
|
+ List<Integer> markerCountList = groupQuestionList.stream().map(SubjectiveStructDto::getMarkerCount).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(markerCountList)){
|
|
|
+ if (markerCountList.size() > 1){
|
|
|
+ logicErrorList.add(paperNumberGroupNumberNotice + "的[评卷员数量(系统生成)]不一致");
|
|
|
+ } else if (markerCountList.size() == 1){
|
|
|
+ markerCount = markerCountList.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<String> markerCodesList= groupQuestionList.stream().map(SubjectiveStructDto::getMarkerCodes).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(markerCodesList)){
|
|
|
+ if (markerCodesList.size() > 1){
|
|
|
+ logicErrorList.add(paperNumberGroupNumberNotice + "的[绑定工号(英文逗号分隔)]不一致");
|
|
|
+ } else if (markerCodesList.size() == 1){
|
|
|
+ markerCodes = markerCodesList.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装评卷员信息
|
|
|
+ List<MarkUser> markUsers = new ArrayList<>();
|
|
|
+ if (SystemConstant.strNotNull(markerCodes)) {
|
|
|
+ // 优先以绑定工号为准
|
|
|
+ String[] markerCodeArray = markerCodes.split(SystemConstant.COMMA);
|
|
|
+ for (String markerCode : markerCodeArray) {
|
|
|
+ SysUser sysUser = sysUserService.getOne(
|
|
|
+ new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getLoginName, markerCode).last(SystemConstant.LIMIT1));
|
|
|
+ if (Objects.isNull(sysUser)) {
|
|
|
+ logicErrorList.add(String.format("[试卷编号]%s,[评卷分组(只能用小写数字)]%s,[绑定工号(英文逗号分隔)]%s不存在", paperNumber, groupNumber, markerCode));
|
|
|
+ } else {
|
|
|
+ // 添加评卷员信息
|
|
|
+ MarkUser markUser = new MarkUser();
|
|
|
+ markUser.setUserId(sysUser.getId());
|
|
|
+ markUser.setLoginName(sysUser.getLoginName());
|
|
|
+ markUser.setName(sysUser.getRealName());
|
|
|
+ markUser.setOrgName(orgName);
|
|
|
+ markUsers.add(markUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (Objects.nonNull(markerCount) && markerCount > 0) {
|
|
|
+ // 没有绑定工号且评卷员生成数量大于0,生成评卷员(或使用之前工号相同的评卷员)
|
|
|
+ for (int i = 0; i < markerCount; i++) {
|
|
|
+ int num = markerNumber.incrementAndGet();
|
|
|
+ if (num > 99){
|
|
|
+ logicErrorList.add("[试卷编号]%s的[评卷员数量(系统生成)]总有效数量不能超过99");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String markerCode = String.format("%02d",num);
|
|
|
+
|
|
|
+ SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().lambda()
|
|
|
+ .eq(SysUser::getSchoolId, schoolId)
|
|
|
+ .eq(SysUser::getLoginName, markerCode)
|
|
|
+ .last(SystemConstant.LIMIT1));
|
|
|
+
|
|
|
+ MarkUser markUser = new MarkUser();
|
|
|
+ markUser.setLoginName(markerCode);
|
|
|
+ markUser.setOrgName(orgName);
|
|
|
+ markUsers.add(markUser);
|
|
|
+ if (Objects.nonNull(sysUser)){
|
|
|
+ markUser.setUserId(sysUser.getId());
|
|
|
+ markUser.setName(sysUser.getRealName());
|
|
|
+ } else {
|
|
|
+ // 创建用户
|
|
|
+ UserSaveParams userSaveParams = new UserSaveParams();
|
|
|
+ userSaveParams.setSchoolId(schoolId);
|
|
|
+ userSaveParams.setLoginName(markerCode);
|
|
|
+ userSaveParams.setRealName(markerCode);
|
|
|
+ userSaveParams.setCode(markerCode);
|
|
|
+ userSaveParams.setPassword(SystemConstant.DEFAULT_PASSWORD);
|
|
|
+ userSaveParams.setOrgId(orgId);
|
|
|
+ userSaveParams.setEnable(true);
|
|
|
+ userSaveParams.setRoleIds(new Long[] { markerRole.getId() });
|
|
|
+ try {
|
|
|
+ markUser.setUserId(sysUserService.saveUser(userSaveParams));
|
|
|
+ markUser.setName(markerCode);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 验证机构是否存在
|
|
|
*
|