|
@@ -1,12 +1,13 @@
|
|
|
package com.rongwei.trainingcommon.sys.service.impl;
|
|
|
|
|
|
+import com.aspose.words.Document;
|
|
|
+import com.aspose.words.SaveFormat;
|
|
|
import com.aspose.words.net.System.Data.DataRow;
|
|
|
import com.aspose.words.net.System.Data.DataTable;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
|
-import com.rongwei.rwadmincommon.system.vo.SysUserOrgVo;
|
|
|
-import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import com.rongwei.training.domain.DemandSurveyUserAnswerDo;
|
|
|
import com.rongwei.training.domain.TrainingDemandSurveyBackupsDo;
|
|
|
import com.rongwei.training.domain.TrainingDemandSurveyDo;
|
|
|
import com.rongwei.training.vo.DemandUserVo;
|
|
@@ -25,6 +26,8 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
/**
|
|
|
* ExportTrainingDemandService class
|
|
@@ -46,6 +49,8 @@ public class ExportTrainingDemandServiceImpl implements ExportTrainingDemandServ
|
|
|
private DemandSurveyContentDao demandSurveyContentDao;
|
|
|
@Autowired
|
|
|
private TraningCommonDao traningCommonDao;
|
|
|
+ @Autowired
|
|
|
+ private DemandSurveyUserAnswerServiceImpl demandSurveyUserAnswerService;
|
|
|
// 单选 多选
|
|
|
public static final String RADIO = "1";
|
|
|
// 单选 多选
|
|
@@ -97,8 +102,9 @@ public class ExportTrainingDemandServiceImpl implements ExportTrainingDemandServ
|
|
|
// 获取问卷调查试卷
|
|
|
List<TrainingDemandVo> surveyContent = demandSurveyContentDao.getSurveyContent(trainingDemandSurveyBackupsDos.get(0).getId(), "");
|
|
|
DataTable dataTable = createDataTable(surveyContent, false);
|
|
|
+ Document document = wordDrawing(WORD_KEY, createWordValue(trainingDemandSurveyDo, null, ""), dataTable, DOCX_FILE_PATH);
|
|
|
// 文件导出
|
|
|
- exportSingleWord(WORD_KEY, createWordValue(trainingDemandSurveyDo, null, ""), dataTable, response, DOCX_FILE_PATH);
|
|
|
+ exportSingleWord(document, response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -113,18 +119,84 @@ public class ExportTrainingDemandServiceImpl implements ExportTrainingDemandServ
|
|
|
throw new RuntimeException("参数异常");
|
|
|
}
|
|
|
TrainingDemandSurveyBackupsDo trainingDemandSurveyBackupsDo = trainingDemandSurveyBackupsDao.selectById(surveyId);
|
|
|
- if(trainingDemandSurveyBackupsDo==null){
|
|
|
+ if (trainingDemandSurveyBackupsDo == null) {
|
|
|
throw new RuntimeException("当前计划已删除");
|
|
|
}
|
|
|
TrainingDemandSurveyDo trainingDemandSurveyDo = trainingDemandSurveyDao.selectById(trainingDemandSurveyBackupsDo.getOldSurveyId());
|
|
|
- if(trainingDemandSurveyDo==null){
|
|
|
+ if (trainingDemandSurveyDo == null) {
|
|
|
throw new RuntimeException("当前计划已删除");
|
|
|
}
|
|
|
List<TrainingDemandVo> surveyContent = demandSurveyContentDao.getSurveyContent(surveyId, userId);
|
|
|
List<DemandUserVo> demandUserInfo = traningCommonDao.getDemandUserInfo(Arrays.asList(userId));
|
|
|
DataTable dataTable = createDataTable(surveyContent, true);
|
|
|
+ // 绘制word
|
|
|
+ Document document = wordDrawing(WORD_KEY, createWordValue(trainingDemandSurveyDo, demandUserInfo, userId), dataTable, DOCX_FILE_PATH);
|
|
|
// 文件导出
|
|
|
- exportSingleWord(WORD_KEY, createWordValue(trainingDemandSurveyDo, demandUserInfo, userId), dataTable, response, DOCX_FILE_PATH);
|
|
|
+ exportSingleWord(document, response);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成所有已填写问卷调查记录的数据
|
|
|
+ *
|
|
|
+ * @param surveyId
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void generateRecord(String surveyId, HttpServletResponse response) {
|
|
|
+ log.info("开始生成问卷调查试卷");
|
|
|
+ if (StringUtils.isBlank(surveyId)) {
|
|
|
+ log.error("参数异常");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断问卷调查是否生成
|
|
|
+ TrainingDemandSurveyDo trainingDemandSurveyDo = trainingDemandSurveyDao.selectById(surveyId);
|
|
|
+ if (trainingDemandSurveyDo == null) {
|
|
|
+ log.error("问卷调查已删除");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<TrainingDemandSurveyBackupsDo> trainingDemandSurveyBackupsDos = trainingDemandSurveyBackupsDao.selectList(new LambdaQueryWrapper<TrainingDemandSurveyBackupsDo>()
|
|
|
+ .eq(TrainingDemandSurveyBackupsDo::getOldSurveyId, surveyId));
|
|
|
+ if (trainingDemandSurveyBackupsDos.isEmpty()) {
|
|
|
+ log.error("问卷调查暂未发布");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String backupId = trainingDemandSurveyBackupsDos.get(0).getId();
|
|
|
+ // 获取问卷调查题目信息
|
|
|
+ List<TrainingDemandVo> surveyContent = demandSurveyContentDao.getSurveyContent(backupId, "");
|
|
|
+ // 获取用户填报记录
|
|
|
+ List<DemandSurveyUserAnswerDo> userAnswer = demandSurveyUserAnswerService.list(new LambdaQueryWrapper<DemandSurveyUserAnswerDo>().eq(DemandSurveyUserAnswerDo::getSurverid, backupId));
|
|
|
+ if (userAnswer.isEmpty()) {
|
|
|
+ log.error("参数异常");
|
|
|
+ throw new RuntimeException("当前调查暂无人填写问卷信息");
|
|
|
+ }
|
|
|
+ // 对问卷答案按照填写人进行分组
|
|
|
+ Map<String, List<DemandSurveyUserAnswerDo>> collect = userAnswer.stream().collect(Collectors.groupingBy(BaseDo::getCreateuserid));
|
|
|
+
|
|
|
+ List<String> userIds = userAnswer.stream().map(BaseDo::getCreateuserid).distinct().collect(Collectors.toList());
|
|
|
+ List<DemandUserVo> demandUserInfo = traningCommonDao.getDemandUserInfo(userIds);
|
|
|
+
|
|
|
+ Map<String, Document> documentMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, List<DemandSurveyUserAnswerDo>> entry : collect.entrySet()) {
|
|
|
+ List<DemandSurveyUserAnswerDo> userAnswerList = entry.getValue();
|
|
|
+ surveyContent.forEach(info -> {
|
|
|
+ Optional<DemandSurveyUserAnswerDo> first = userAnswerList.stream().filter(answer -> answer.getSurvercontentid().equals(info.getContentid())).findFirst();
|
|
|
+ info.setUserAnswer(first.isPresent() ? first.get().getAnswer() : "");
|
|
|
+ });
|
|
|
+ DataTable dataTable = createDataTable(surveyContent, true);
|
|
|
+ // 绘制word
|
|
|
+ Document document = wordDrawing(WORD_KEY, createWordValue(trainingDemandSurveyDo, demandUserInfo, entry.getKey()), dataTable, DOCX_FILE_PATH);
|
|
|
+ documentMap.put(userAnswerList.get(0).getCreateusername(), document);
|
|
|
+ }
|
|
|
+ try (ZipOutputStream outputStream = new ZipOutputStream(response.getOutputStream());) {
|
|
|
+ for (Map.Entry<String, Document> entry : documentMap.entrySet()) {
|
|
|
+ ZipEntry zipEntry = new ZipEntry(entry.getKey() + ".docx");
|
|
|
+ outputStream.putNextEntry(zipEntry);
|
|
|
+ entry.getValue().save(outputStream, SaveFormat.DOCX);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("压缩包生成异常");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|