|
@@ -3,6 +3,8 @@ package com.ruoyi.system.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.format.FastDateFormat;
|
|
|
import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
@@ -12,13 +14,11 @@ import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.common.exception.base.BaseException;
|
|
|
-import com.ruoyi.system.domain.TaskResult;
|
|
|
-import com.ruoyi.system.domain.WaterLevel;
|
|
|
+import com.ruoyi.system.domain.*;
|
|
|
import com.ruoyi.system.dto.PrintExcelDTO;
|
|
|
import com.ruoyi.system.dto.TaskResultSortDTO;
|
|
|
import com.ruoyi.system.dto.WaterLevelDTO;
|
|
|
-import com.ruoyi.system.mapper.TaskResultMapper;
|
|
|
-import com.ruoyi.system.mapper.WaterLevelMapper;
|
|
|
+import com.ruoyi.system.mapper.*;
|
|
|
import com.ruoyi.system.paramet.AchievementQuery;
|
|
|
import com.ruoyi.system.paramet.ScattperPlotQuery;
|
|
|
import com.ruoyi.system.paramet.WaterLevelQuery;
|
|
@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -48,6 +49,15 @@ public class AchievementServiceImpl implements AchievementService {
|
|
|
@Resource
|
|
|
private WaterLevelMapper waterLevelMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SiteInfoMapper siteInfoMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BerthingPointMapper berthingPointMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BerthingPointConfigMapper berthingPointConfigMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<TaskResult> queryAchievement(AchievementQuery achievementQuery){
|
|
|
if (achievementQuery.getPage() == null || achievementQuery.getSize() == null) {
|
|
@@ -78,84 +88,84 @@ public class AchievementServiceImpl implements AchievementService {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
- public boolean downAchievement(Long siteId, HttpServletResponse response) {
|
|
|
+ public boolean downAchievement(Long resultId, HttpServletResponse response) {
|
|
|
|
|
|
ExcelWriter excelWriter = null;
|
|
|
try {
|
|
|
+ //查询resultId结果
|
|
|
+ TaskResult taskResult = taskResultMapper.queryById(resultId);
|
|
|
+ if (taskResult == null){
|
|
|
+ throw new BaseException("该结果不存在");
|
|
|
+ }
|
|
|
+ if (taskResult.getStatus() != 2){
|
|
|
+ throw new BaseException("结果未完成,不支持导出");
|
|
|
+ }
|
|
|
+ //查询站点信息
|
|
|
+ SiteInfo siteInfo = siteInfoMapper.queryById(taskResult.getSiteId());
|
|
|
+ if (siteInfo == null){
|
|
|
+ throw new BaseException("该站点不存在");
|
|
|
+ }
|
|
|
+ //拿停泊点数据
|
|
|
+ BerthingPointConfig berthingPointConfig = berthingPointConfigMapper.queryByPlanid(taskResult.getSiteId(), taskResult.getPlanid());
|
|
|
+ if (berthingPointConfig == null){
|
|
|
+ throw new BaseException("停泊点配置不存在");
|
|
|
+ }
|
|
|
+ //拿断面数据
|
|
|
+ BerthingPoint berthingPoint = berthingPointMapper.queryById(berthingPointConfig.getBerthingId());
|
|
|
+ if (berthingPoint == null){
|
|
|
+ throw new BaseException("断面不存在");
|
|
|
+ }
|
|
|
+
|
|
|
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);
|
|
|
+ //先组装单数据
|
|
|
+ Map<String, Object> map = MapUtils.newHashMap();
|
|
|
+ map.put("stieName", siteInfo.getSiteName());
|
|
|
+ map.put("startTime", taskResult.getStarttime());
|
|
|
+ map.put("endTime", taskResult.getEndtime());
|
|
|
+ map.put("flowsum", taskResult.getFlowsum());
|
|
|
+ map.put("width", taskResult.getWidth());
|
|
|
+ map.put("waterlevel",taskResult.getWaterlevel());
|
|
|
+
|
|
|
+ List<Double> WspeedsList = JSONUtil.parseArray(taskResult.getWspeeds()).toList(Double.class);
|
|
|
+ double averageWspeed = WspeedsList.stream().mapToDouble(d -> d).average().orElse(Double.NaN);
|
|
|
+ Double maxWspeed = WspeedsList.stream().max(Double::compareTo).orElse(Double.NaN);
|
|
|
+
|
|
|
+ List<Double> waterlevelList = JSONUtil.parseArray(taskResult.getWaterlevels()).toList(Double.class);
|
|
|
+ double averageWaterlevel = waterlevelList.stream().mapToDouble(d -> d).average().orElse(Double.NaN);
|
|
|
+ Double maxWaterlevel = waterlevelList.stream().max(Double::compareTo).orElse(Double.NaN);
|
|
|
+
|
|
|
+ map.put("agWaterlevels",String.valueOf(averageWaterlevel));
|
|
|
+ map.put("maxWaterlevels",String.valueOf(maxWaterlevel));
|
|
|
+ map.put("agWspeeds",String.valueOf(averageWspeed));
|
|
|
+ map.put("maxWspeeds",String.valueOf(maxWspeed));
|
|
|
+
|
|
|
+
|
|
|
+// 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);
|
|
|
+// dataList.add(data);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// Map<String, Object> data = MapUtils.newHashMap();
|
|
|
+// 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");
|
|
@@ -165,7 +175,7 @@ public class AchievementServiceImpl implements AchievementService {
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
log.error("下载失败", e);
|
|
|
- return true;
|
|
|
+ throw new BaseException(e.getMessage());
|
|
|
} finally {
|
|
|
if (excelWriter != null) {
|
|
|
excelWriter.close();
|