|
@@ -1,24 +1,32 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.alibaba.excel.util.MapUtils;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.ruoyi.common.exception.base.BaseException;
|
|
|
-import com.ruoyi.system.domain.SiteInfo;
|
|
|
import com.ruoyi.system.domain.TaskResult;
|
|
|
import com.ruoyi.system.domain.WaterLevel;
|
|
|
-import com.ruoyi.system.dto.ManualMeasureDTO;
|
|
|
-import com.ruoyi.system.mapper.SiteInfoMapper;
|
|
|
import com.ruoyi.system.mapper.TaskResultMapper;
|
|
|
import com.ruoyi.system.mapper.WaterLevelMapper;
|
|
|
import com.ruoyi.system.paramet.AchievementQuery;
|
|
|
import com.ruoyi.system.paramet.WaterLevelQuery;
|
|
|
import com.ruoyi.system.service.AchievementService;
|
|
|
-import com.ruoyi.system.service.DirectiveService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* classname: 站点信息
|
|
@@ -60,6 +68,114 @@ public class AchievementServiceImpl implements AchievementService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean downAchievement(Long siteId, HttpServletResponse response) {
|
|
|
+
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
+ // 模版文件
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("excel/test.xlsx");
|
|
|
+ String templateFileName = classPathResource.getFile().getPath();
|
|
|
+ excelWriter = EasyExcel.write(outputStream).withTemplate(templateFileName).excelType(ExcelTypeEnum.XLSX).autoCloseStream(Boolean.FALSE).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
+ //新插入行
|
|
|
+ //FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
+ //单数据
|
|
|
+ Map<String, Object> map = MapUtils.newHashMap();
|
|
|
+ map.put("stieName", "水文站");
|
|
|
+ excelWriter.fill(map, writeSheet);
|
|
|
+ //列表
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+
|
|
|
+ //列表
|
|
|
+ List<Map<String, Object>> pgList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ Map<String, Object> data = MapUtils.newHashMap();
|
|
|
+ data.put("index", i);
|
|
|
+ data.put("a", "a" + i);
|
|
|
+ data.put("b", "b" + i);
|
|
|
+ data.put("c", "c" + i);
|
|
|
+ data.put("d", "d" + i);
|
|
|
+ data.put("e", "e" + i);
|
|
|
+ data.put("f", "f" + i);
|
|
|
+ data.put("g", "g" + i);
|
|
|
+ data.put("h", "h" + i);
|
|
|
+ data.put("i", "i" + i);
|
|
|
+ data.put("j", "j" + i);
|
|
|
+ data.put("k", "k" + i);
|
|
|
+ data.put("l", "l" + i);
|
|
|
+ data.put("m", "m" + i);
|
|
|
+ data.put("n", "n" + i);
|
|
|
+ data.put("o", "o" + i);
|
|
|
+ dataList.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < 2; i++) {
|
|
|
+ Map<String, Object> data = MapUtils.newHashMap();
|
|
|
+ data.put("a", "a" + i);
|
|
|
+ data.put("b", "b" + i);
|
|
|
+ data.put("c", "c" + i);
|
|
|
+ data.put("d", "d" + i);
|
|
|
+ data.put("e", "e" + i);
|
|
|
+ data.put("f", "f" + i);
|
|
|
+ pgList.add(data);
|
|
|
+
|
|
|
+ }
|
|
|
+ Map<String, Object> data = MapUtils.newHashMap();
|
|
|
+ data.put("index", "index");
|
|
|
+ data.put("a", "a");
|
|
|
+ data.put("b", "b");
|
|
|
+ data.put("c", "c");
|
|
|
+ data.put("d", "d");
|
|
|
+ data.put("e", "e");
|
|
|
+ data.put("f", "f");
|
|
|
+ data.put("g", "g");
|
|
|
+ data.put("h", "h");
|
|
|
+ data.put("i", "i");
|
|
|
+ data.put("j", "j");
|
|
|
+ data.put("k", "k");
|
|
|
+ data.put("l", "l");
|
|
|
+ data.put("m", "m");
|
|
|
+ data.put("n", "n");
|
|
|
+ data.put("o", "o");
|
|
|
+ dataList = insertEmptyDataOnEvenRows(dataList, data);
|
|
|
+ pgList = insertEmptyDataOnEvenRows(pgList, data);
|
|
|
+
|
|
|
+ excelWriter.fill(new FillWrapper("details", dataList), writeSheet);
|
|
|
+ excelWriter.fill(new FillWrapper("pg", pgList), writeSheet);
|
|
|
+
|
|
|
+ // 设置输出流格式以及文件名:
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = URLEncoder.encode("质检任务", StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("下载失败", e);
|
|
|
+ return true;
|
|
|
+ } finally {
|
|
|
+ if (excelWriter != null) {
|
|
|
+ excelWriter.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static <T> List<T> insertEmptyDataOnEvenRows(List<T> list, T emptyValue) {
|
|
|
+ List<T> modifiedList = new ArrayList<>(list.size() * 2 - 1); // 预估新列表的大小
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ modifiedList.add(list.get(i)); // 添加原始元素
|
|
|
+ if (i < list.size() - 1) { // 避免在最后一个元素后插入
|
|
|
+ modifiedList.add(emptyValue); // 在每个元素后插入空白数据
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return modifiedList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|