|
@@ -1,11 +1,14 @@
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.google.gson.Gson;
|
|
import com.qmth.distributed.print.business.bean.dto.*;
|
|
import com.qmth.distributed.print.business.bean.dto.*;
|
|
import com.qmth.distributed.print.business.bean.result.WorkResult;
|
|
import com.qmth.distributed.print.business.bean.result.WorkResult;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
@@ -13,18 +16,24 @@ import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.ReviewStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.ReviewStatusEnum;
|
|
import com.qmth.distributed.print.business.mapper.ExamTaskMapper;
|
|
import com.qmth.distributed.print.business.mapper.ExamTaskMapper;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
|
+import com.qmth.distributed.print.business.util.ExcelUtil;
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
|
|
+import com.qmth.distributed.print.business.util.excel.ExcelError;
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.distributed.print.common.util.ResultUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import javax.websocket.RemoteEndpoint;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -60,6 +69,12 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
@Resource
|
|
@Resource
|
|
ExamTaskMapper examTaskMapper;
|
|
ExamTaskMapper examTaskMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private BasicCourseService basicCourseService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysUserService sysUserService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<ExamTask> listByCourseCode(Long schoolId, String code) {
|
|
public List<ExamTask> listByCourseCode(Long schoolId, String code) {
|
|
QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
|
|
@@ -178,9 +193,101 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<ExamTaskImportDto> importFile(MultipartFile file, String md5) {
|
|
|
|
- // 导入文件
|
|
|
|
- return null;
|
|
|
|
|
|
+ public ExamTaskImportDto importFile(MultipartFile file) throws IOException, NoSuchFieldException {
|
|
|
|
+ // 学校ID
|
|
|
|
+ Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
|
+ // 用户
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+
|
|
|
|
+ List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(ExamTaskTemp.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
|
|
+ List<ExcelError> excelErrorTemp = new ArrayList<>();
|
|
|
|
+ // 只允许导入一个sheet
|
|
|
|
+ if(finalExcelList.size() > 1){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel中只允许有一个sheet");
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < finalExcelList.size(); i++) {
|
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
|
|
+ List<Object> examTaskTempList = excelMap.get(i);
|
|
|
|
+ for (int y = 0; y < examTaskTempList.size(); y++) {
|
|
|
|
+ ExamTaskTemp userImportDto = (ExamTaskTemp) examTaskTempList.get(y);
|
|
|
|
+ if (StringUtils.isBlank(userImportDto.getCourseCode())) {
|
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程代码]必填"));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(userImportDto.getCourseName())) {
|
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程名称]必填"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 课程是否存在并且与名称对应
|
|
|
|
+ QueryWrapper<BasicCourse> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(BasicCourse::getCode, userImportDto.getCourseCode());
|
|
|
|
+ BasicCourse course = basicCourseService.getOne(queryWrapper);
|
|
|
|
+ if (course == null) {
|
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程代码]在系统中不存在"));
|
|
|
|
+ } else if (!userImportDto.getCourseName().equals(course.getName())) {
|
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[课程名称]与系统中不匹配"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isBlank(userImportDto.getPaperNumber())) {
|
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[试卷编号]必填"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ userImportDto.setId(SystemConstant.getDbUuid());
|
|
|
|
+ userImportDto.setSchoolId(schoolId);
|
|
|
|
+ userImportDto.setCreateId(sysUser.getId());
|
|
|
|
+ userImportDto.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (excelErrorTemp.size() > 0) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(excelErrorTemp));
|
|
|
|
+ }
|
|
|
|
+ return finalExcelList;
|
|
|
|
+ });
|
|
|
|
+ return executeImportExamTaskBatch(finalList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ ExamTaskImportDto executeImportExamTaskBatch(List<LinkedMultiValueMap<Integer, Object>> finalList) {
|
|
|
|
+ // 批次号
|
|
|
|
+ String batchNo = String.valueOf(System.nanoTime());
|
|
|
|
+ ExamTaskImportDto examTaskImportDto = new ExamTaskImportDto();
|
|
|
|
+ examTaskImportDto.setBatchNo(batchNo);
|
|
|
|
+ List<ExamTaskDto> tasks = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
|
|
+ List<Object> examTaskTempList = excelMap.get(i);
|
|
|
|
+ for (int y = 0; y < examTaskTempList.size(); y++) {
|
|
|
|
+ ExamTaskTemp examTaskTemp = (ExamTaskTemp) examTaskTempList.get(y);
|
|
|
|
+ examTaskTemp.setBatchNo(batchNo);
|
|
|
|
+ //保存
|
|
|
|
+ examTaskTempService.save(examTaskTemp);
|
|
|
|
+
|
|
|
|
+ ExamTaskDto examTaskDto = new ExamTaskDto();
|
|
|
|
+ examTaskDto.setCourseCode(examTaskTemp.getCourseCode());
|
|
|
|
+ examTaskDto.setCourseName(examTaskTemp.getCourseName());
|
|
|
|
+ examTaskDto.setPaperNumber(examTaskTemp.getPaperNumber());
|
|
|
|
+ examTaskDto.setSpecialty(examTaskTemp.getSpecialty());
|
|
|
|
+ // 校验命题老师
|
|
|
|
+ if(StringUtils.isBlank(examTaskTemp.getUserAccount())){
|
|
|
|
+ examTaskDto.setUsers(listUsers(examTaskTemp.getCourseCode(), null));
|
|
|
|
+ } else {
|
|
|
|
+ QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(SysUser::getLoginName, examTaskTemp.getUserAccount());
|
|
|
|
+ SysUser sysUser = sysUserService.getOne(queryWrapper);
|
|
|
|
+ if(sysUser == null){
|
|
|
|
+ examTaskDto.setUsers( listUsers(examTaskTemp.getCourseCode(), null));
|
|
|
|
+ } else {
|
|
|
|
+ examTaskDto.setUsers(listUsers(examTaskTemp.getCourseCode(), String.valueOf(sysUser.getId())));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tasks.add(examTaskDto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ examTaskImportDto.setTasks(tasks);
|
|
|
|
+ return examTaskImportDto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<BlurryUserDto> listUsers(String courseCode, String userId){
|
|
|
|
+ return sysUserService.listUser(courseCode, userId);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -209,7 +316,6 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
examTask.setStartTime(task.getStartTime());
|
|
examTask.setStartTime(task.getStartTime());
|
|
examTask.setEndTime(task.getEndTime());
|
|
examTask.setEndTime(task.getEndTime());
|
|
examTask.setCardRuleId(task.getCardRuleId());
|
|
examTask.setCardRuleId(task.getCardRuleId());
|
|
- examTask.setStatus(ExamStatusEnum.NEW);
|
|
|
|
examTask.setBatchNo(task.getBatchNo());
|
|
examTask.setBatchNo(task.getBatchNo());
|
|
examTask.setCreateId(sysUser.getId());
|
|
examTask.setCreateId(sysUser.getId());
|
|
examTask.setCreateTime(System.currentTimeMillis());
|
|
examTask.setCreateTime(System.currentTimeMillis());
|
|
@@ -221,6 +327,9 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
}).findFirst().get();
|
|
}).findFirst().get();
|
|
if (StringUtils.isNotBlank(userId)) {
|
|
if (StringUtils.isNotBlank(userId)) {
|
|
examTask.setUserId(Long.valueOf(userId));
|
|
examTask.setUserId(Long.valueOf(userId));
|
|
|
|
+ examTask.setStatus(ExamStatusEnum.READY);
|
|
|
|
+ } else {
|
|
|
|
+ examTask.setStatus(ExamStatusEnum.NEW);
|
|
}
|
|
}
|
|
list.add(examTask);
|
|
list.add(examTask);
|
|
}
|
|
}
|
|
@@ -409,7 +518,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public IPage<WorkResult> queryByMyWork(IPage<Map> iPage, Long userId, Long schoolId, String...status) {
|
|
|
|
|
|
+ public IPage<WorkResult> queryByMyWork(IPage<Map> iPage, Long userId, Long schoolId, String... status) {
|
|
return examTaskMapper.queryByMyWork(iPage, userId, schoolId, status);
|
|
return examTaskMapper.queryByMyWork(iPage, userId, schoolId, status);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -433,19 +542,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, examTaskId);
|
|
queryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, examTaskId);
|
|
ExamTaskDetail examTaskDetail = examTaskDetailService.getOne(queryWrapper);
|
|
ExamTaskDetail examTaskDetail = examTaskDetailService.getOne(queryWrapper);
|
|
- if(examTaskDetail == null){
|
|
|
|
|
|
+ if (examTaskDetail == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("数据异常");
|
|
throw ExceptionResultEnum.ERROR.exception("数据异常");
|
|
}
|
|
}
|
|
String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
|
|
String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
|
|
List<JSONObject> jsonObjectList = JSONObject.parseArray(paperAttachmentIds, JSONObject.class);
|
|
List<JSONObject> jsonObjectList = JSONObject.parseArray(paperAttachmentIds, JSONObject.class);
|
|
// 本地保存目录
|
|
// 本地保存目录
|
|
- String rootPath = SystemConstant.DOWNLOAD_TEMP + File.separator + schoolId + File.separator+ examTaskDetail.getId();
|
|
|
|
|
|
+ String rootPath = SystemConstant.DOWNLOAD_TEMP + File.separator + schoolId + File.separator + examTaskDetail.getId();
|
|
List<File> fileList = new ArrayList<>();
|
|
List<File> fileList = new ArrayList<>();
|
|
// 试卷
|
|
// 试卷
|
|
for (JSONObject jsonObject : jsonObjectList) {
|
|
for (JSONObject jsonObject : jsonObjectList) {
|
|
Long id = jsonObject.getLongValue("attachmentId");
|
|
Long id = jsonObject.getLongValue("attachmentId");
|
|
BasicAttachment attachment = basicAttachmentService.getById(id);
|
|
BasicAttachment attachment = basicAttachmentService.getById(id);
|
|
- if(attachment == null){
|
|
|
|
|
|
+ if (attachment == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("附件数据异常");
|
|
throw ExceptionResultEnum.ERROR.exception("附件数据异常");
|
|
}
|
|
}
|
|
File file = commonService.copyFile(rootPath, attachment);
|
|
File file = commonService.copyFile(rootPath, attachment);
|
|
@@ -457,7 +566,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
// if (cardId != null){
|
|
// if (cardId != null){
|
|
//
|
|
//
|
|
// }
|
|
// }
|
|
- if(fileList.size() == 0){
|
|
|
|
|
|
+ if (fileList.size() == 0) {
|
|
throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
|
|
throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
|
|
}
|
|
}
|
|
|
|
|