|
|
@@ -2,7 +2,10 @@ package com.xjrsoft.module.dataexpert.controller;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.xjrsoft.common.model.result.RT;
|
|
|
@@ -35,6 +38,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -117,12 +122,14 @@ public class DataExpertTemplateController {
|
|
|
@GetMapping("/export")
|
|
|
@ApiOperation(value = "导出")
|
|
|
public ResponseEntity<byte[]> exportData(@Valid DataExpertDto dto) {
|
|
|
+ //查出想要的数据
|
|
|
DataExpertTemplate template = dataExpertTemplateService.getById(dto.getDataExpertTemplateId());
|
|
|
DataExpertSource expertSource = dataExpertSourceService.getById(template.getDataExpertSourceId());
|
|
|
|
|
|
+ //拼接字段
|
|
|
String fields = "";
|
|
|
Map<Integer, String> showNameMap = new HashMap<>();
|
|
|
-
|
|
|
+ List<String> titleList = new ArrayList<>();
|
|
|
List<DataExpertTemplateFieldVo> fieldList = dto.getFieldList();
|
|
|
for (int i = 0; i < fieldList.size(); i ++){
|
|
|
DataExpertTemplateFieldVo fieldVo = fieldList.get(i);
|
|
|
@@ -131,13 +138,27 @@ public class DataExpertTemplateController {
|
|
|
fields += ",";
|
|
|
}
|
|
|
fields += fieldVo.getFieldName();
|
|
|
+ titleList.add(fieldVo.getShowName());
|
|
|
}
|
|
|
- for (DataExpertTemplateFieldVo dataExpertTemplateFieldVo : dto.getFieldList()) {
|
|
|
+ //查出导出的数据并进行组装
|
|
|
+ List<String[]> dataList = dataExpertTemplateService.getDataList(fields, expertSource.getViewName());
|
|
|
|
|
|
- }
|
|
|
+ List<String[]> allDataList = new ArrayList<>();
|
|
|
+ allDataList.add(titleList.toArray(new String[titleList.size()]));
|
|
|
+ allDataList.addAll(dataList);
|
|
|
+
|
|
|
+ String sheetName = "数据";
|
|
|
+ String fileName = template.getName() + ExcelTypeEnum.XLSX.getValue();
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(bot).excelType(ExcelTypeEnum.XLSX).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet(sheetName).needHead(Boolean.FALSE).build();
|
|
|
+
|
|
|
+ excelWriter.write(allDataList, writeSheet);
|
|
|
|
|
|
+ excelWriter.finish();
|
|
|
|
|
|
- return RT.fileStream(null, "WeeklyDutySchedule" + ExcelTypeEnum.XLSX.getValue());
|
|
|
+ return RT.fileStream(bot.toByteArray(), fileName);
|
|
|
}
|
|
|
|
|
|
}
|