|
|
@@ -1,5 +1,6 @@
|
|
|
package com.cyksj.service.mange.form.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
@@ -20,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/*
|
|
|
*项目名: netflix
|
|
|
@@ -59,10 +62,10 @@ public class FormServiceImpl implements FormService {
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
response.setHeader("Content-disposition",
|
|
|
"attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
|
|
|
-
|
|
|
+ List<FormFields> formFields = formFieldsMapper.selectList(new LambdaQueryWrapper<FormFields>().eq(FormFields::getTemplateId, promotion.getTemplateId()).orderByAsc(FormFields::getSorted));
|
|
|
EasyExcel.write(response.getOutputStream())
|
|
|
// 这里放入动态头
|
|
|
- .head(head(promotionId)).sheet("问卷信息")
|
|
|
+ .head(head(formFields)).sheet("问卷信息")
|
|
|
// 当然这里数据也可以用 List<List<String>> 去传入
|
|
|
.doWrite(data(promotionId));
|
|
|
}
|
|
|
@@ -121,24 +124,29 @@ public class FormServiceImpl implements FormService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private List<List<String>> head(Long templateId) {
|
|
|
- List<FormFields> formFields = formFieldsMapper.selectList(new LambdaQueryWrapper<FormFields>().eq(FormFields::getTemplateId, templateId).orderByAsc(FormFields::getSorted));
|
|
|
+ private List<List<String>> head(List<FormFields> formFields) {
|
|
|
List<List<String>> headTitles = new ArrayList<>();
|
|
|
- String formInfo = "表单信息";
|
|
|
formFields.forEach((field) -> {
|
|
|
- headTitles.add(Lists.newArrayList(formInfo, formInfo, field.getFieldsName()));
|
|
|
+ headTitles.add(Lists.newArrayList(field.getFieldsName()));
|
|
|
});
|
|
|
+ headTitles.add(Lists.newArrayList("提交时间"));
|
|
|
return headTitles;
|
|
|
}
|
|
|
|
|
|
private List<List<String>> data(Long promotionId) {
|
|
|
- List<List<String>> contentList = Lists.newArrayList();
|
|
|
List<FormFieldsData> fieldsDataList = formFieldsDataMapper.selectList(new LambdaQueryWrapper<FormFieldsData>().eq(FormFieldsData::getPromotionId, promotionId).eq(FormFieldsData::getDeleted, true).orderByAsc(FormFieldsData::getSorted));
|
|
|
- fieldsDataList.forEach((formFieldsData) -> {
|
|
|
+ if (fieldsDataList.isEmpty()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("暂无数据");
|
|
|
+ }
|
|
|
+ List<List<String>> contentList = Lists.newArrayList();
|
|
|
+ Map<Long, List<FormFieldsData>> collect = fieldsDataList.stream().collect(Collectors.groupingBy(FormFieldsData::getGroupsId));
|
|
|
+ collect.forEach((groupsId, answers) -> {
|
|
|
ArrayList<String> dataList = new ArrayList<>();
|
|
|
- dataList.add(formFieldsData.getContent());
|
|
|
- contentList.add(Lists.newArrayList(formFieldsData.getContent()));
|
|
|
-
|
|
|
+ answers.forEach(answer -> {
|
|
|
+ dataList.add(answer.getContent());
|
|
|
+ });
|
|
|
+ dataList.add(DateUtil.format(answers.get(answers.size() - 1).getCreatedTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ contentList.add(dataList);
|
|
|
});
|
|
|
return contentList;
|
|
|
}
|