|
@@ -9,15 +9,14 @@ import com.google.gson.Gson;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.boot.tools.excel.ExcelWriter;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
+import com.qmth.boot.tools.excel.model.CellValue;
|
|
|
import com.qmth.distributed.print.business.bean.dto.*;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.pdf.ExamStudentInfo;
|
|
|
import com.qmth.distributed.print.business.bean.params.DownloadPaperFileParam;
|
|
|
import com.qmth.distributed.print.business.bean.query.BasicExamStudentPageQuery;
|
|
|
import com.qmth.distributed.print.business.bean.result.BasicExamStudentResult;
|
|
|
import com.qmth.distributed.print.business.bean.result.TSyncExamStudentScoreResult;
|
|
|
-import com.qmth.distributed.print.business.entity.ExamCard;
|
|
|
-import com.qmth.distributed.print.business.entity.ExamTaskDetail;
|
|
|
-import com.qmth.distributed.print.business.entity.TSyncExamStudentScore;
|
|
|
-import com.qmth.distributed.print.business.entity.TeachClazz;
|
|
|
+import com.qmth.distributed.print.business.entity.*;
|
|
|
import com.qmth.distributed.print.business.enums.ImageTrajectoryEnum;
|
|
|
import com.qmth.distributed.print.business.enums.PaperFileDownloadContentEnum;
|
|
|
import com.qmth.distributed.print.business.enums.PaperFileDownloadExposureStatusEnum;
|
|
@@ -26,6 +25,7 @@ import com.qmth.distributed.print.business.templete.service.DownloadLogicService
|
|
|
import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
import com.qmth.distributed.print.business.util.ExamTaskUtil;
|
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
|
+import com.qmth.teachcloud.common.bean.examRule.CodeNameEnableDisabledValue;
|
|
|
import com.qmth.teachcloud.common.bean.params.ArraysParams;
|
|
|
import com.qmth.teachcloud.common.bean.result.DictionaryResult;
|
|
|
import com.qmth.teachcloud.common.bean.vo.FilePathVo;
|
|
@@ -53,6 +53,7 @@ import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -101,6 +102,8 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
|
|
|
@Resource
|
|
|
private BasicExamStudentService basicExamStudentService;
|
|
|
@Resource
|
|
|
+ private BasicExamRuleService basicExamRuleService;
|
|
|
+ @Resource
|
|
|
DictionaryConfig dictionaryConfig;
|
|
|
@Resource
|
|
|
FileUploadService fileUploadService;
|
|
@@ -680,7 +683,7 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+
|
|
|
public void executeExportBasicExamStudentLogic(Map<String, Object> map) {
|
|
|
TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
SysUser sysUser = (SysUser) map.get(SystemConstant.USER);
|
|
@@ -736,6 +739,101 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }*/
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeExportBasicExamStudentLogic(Map<String, Object> map) {
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
+ SysUser sysUser = (SysUser) map.get(SystemConstant.USER);
|
|
|
+ Long privilegeId = (Long) map.get("privilegeId");
|
|
|
+ File file = null;
|
|
|
+ FileOutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId(sysUser.getSchoolId());
|
|
|
+ if (basicExamRule == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("通用规则未设置");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> columnNameList = new ArrayList<>();
|
|
|
+ List<EnumResult> requiredFieldList = basicExamRule.getRequiredFieldList().stream().filter(m -> m.getEnable()).collect(Collectors.toList());
|
|
|
+ requiredFieldList.forEach(m -> columnNameList.add(m.getName()));
|
|
|
+ List<EnumResult> extendFieldList = basicExamRule.getExtendFieldList().stream().filter(m -> m.getEnable()).collect(Collectors.toList());
|
|
|
+ extendFieldList.forEach(m -> columnNameList.add(m.getName()));
|
|
|
+
|
|
|
+ String[] columnNames = columnNameList.toArray(new String[0]);
|
|
|
+
|
|
|
+ BasicExamStudentPageQuery query = (BasicExamStudentPageQuery) map.get("query");
|
|
|
+ List<BasicExamStudent> list = basicExamStudentService.exportList(query, sysUser, privilegeId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ file = SystemConstant.getFileTempDirVar(SystemConstant.EXCEL_PREFIX);
|
|
|
+
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
|
|
|
+
|
|
|
+ List<CellValue[]> columnValues = new ArrayList<>();
|
|
|
+ int sheetCount = 1;
|
|
|
+ for (BasicExamStudent s : list) {
|
|
|
+ List<CellValue> valueList = new ArrayList<>();
|
|
|
+ Class<BasicExamStudentResult> aClass = (Class<BasicExamStudentResult>) s.getClass();
|
|
|
+ for (EnumResult enumResult : requiredFieldList) {
|
|
|
+ try {
|
|
|
+ Field declaredField = aClass.getDeclaredField(enumResult.getCode());
|
|
|
+ declaredField.setAccessible(true);
|
|
|
+
|
|
|
+ Object value = declaredField.get(s);
|
|
|
+ valueList.add(value != null ? CellValue.of(String.valueOf(value)) : CellValue.of(""));
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未获取到表头为[" + enumResult.getCode() + "]的属性值");
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("表头为[" + enumResult.getCode() + "]的值取值失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, String> extendMap = s.getExtendFieldList().stream().collect(Collectors.toMap(m -> m.getCode(), n -> n.getValue()));
|
|
|
+ for (EnumResult enumResult : extendFieldList) {
|
|
|
+ if (extendMap.containsKey(enumResult.getCode())) {
|
|
|
+ String extendValue = extendMap.get(enumResult.getCode());
|
|
|
+ valueList.add(StringUtils.isNotBlank(extendValue) ? CellValue.of(extendValue) : CellValue.of(""));
|
|
|
+ } else {
|
|
|
+ valueList.add(CellValue.of(""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ columnValues.add(valueList.toArray(new CellValue[0]));
|
|
|
+ if (columnValues.size() == ExcelUtil.DEFAULT_SHEET_COUNT) {
|
|
|
+ writer.writeDataArrays("sheet" + sheetCount, null, columnNames, columnValues.listIterator());
|
|
|
+ columnValues.clear();
|
|
|
+ sheetCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnValues.size() > 0) {
|
|
|
+ writer.writeDataArrays("sheet" + sheetCount, null, columnNames, columnValues.listIterator());
|
|
|
+ columnValues.clear();
|
|
|
+ }
|
|
|
+ writer.output(outputStream);
|
|
|
+
|
|
|
+ String fileName = SystemConstant.getNanoId() + SystemConstant.EXCEL_PREFIX;
|
|
|
+ FilePathVo filePathVo = fileUploadService.uploadFile(file, UploadFileEnum.FILE, fileName);
|
|
|
+ tbTask.setResultFilePath(JSON.toJSONString(filePathVo));
|
|
|
+ map.put(SystemConstant.DATA_COUNT, list.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(file)) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|