|
@@ -2,21 +2,16 @@ package com.jiayue.biz.service.impl;
|
|
|
|
|
|
import cn.hutool.db.Entity;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
-import com.alibaba.excel.converters.AutoConverter;
|
|
|
-import com.alibaba.excel.converters.Converter;
|
|
|
-import com.alibaba.excel.enums.CellDataTypeEnum;
|
|
|
-import com.alibaba.excel.metadata.GlobalConfiguration;
|
|
|
-import com.alibaba.excel.metadata.data.CellData;
|
|
|
-import com.alibaba.excel.metadata.data.WriteCellData;
|
|
|
-import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
|
|
-import com.alibaba.excel.util.DateUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jiayue.biz.domain.CustomStringStringConverter;
|
|
|
import com.jiayue.biz.domain.EnvironmentalData;
|
|
|
+import com.jiayue.biz.domain.WeatherLook;
|
|
|
import com.jiayue.biz.mapper.EnvironmentalDataMapper;
|
|
|
import com.jiayue.biz.service.EnvironmentalDataService;
|
|
|
+import com.jiayue.biz.service.WeatherLookService;
|
|
|
import com.jiayue.biz.util.FileUtil;
|
|
|
import com.jiayue.common.utils.DateUtil;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -25,18 +20,14 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class EnvironmentalDataServiceImpl extends ServiceImpl<EnvironmentalDataMapper, EnvironmentalData> implements EnvironmentalDataService {
|
|
|
|
|
|
- @Value("${elf.profile}")
|
|
|
- private String profile;
|
|
|
-
|
|
|
+ private final WeatherLookService weatherLookService;
|
|
|
|
|
|
public void insertOne(EnvironmentalData environmentalData) {
|
|
|
baseMapper.insertOne(environmentalData);
|
|
@@ -131,13 +122,11 @@ public class EnvironmentalDataServiceImpl extends ServiceImpl<EnvironmentalDataM
|
|
|
HashMap<String, Object> dataMap = new HashMap<>();
|
|
|
ArrayList<String> wsList = new ArrayList<>();
|
|
|
ArrayList<String> wdList = new ArrayList<>();
|
|
|
- ArrayList<String> timeList = new ArrayList<>();
|
|
|
for (long i = startTime; i < endTime; i = i + 600000) {
|
|
|
String ws = "0";
|
|
|
String wd = "0";
|
|
|
long finalI = i;
|
|
|
List<EnvironmentalData> environmentalDataList = environmentalData.stream().filter(e -> e.getTs().getTime() >= finalI && e.getTs().getTime() < finalI + 600000).collect(Collectors.toList());
|
|
|
- timeList.add(DateUtil.format(new Date(i), "yyyy-MM-dd HH:mm"));
|
|
|
if (environmentalDataList.size() != 0) {
|
|
|
ws = environmentalDataList.get(0).getWs().toString();
|
|
|
wd = environmentalDataList.get(0).getWd().toString();
|
|
@@ -146,34 +135,52 @@ public class EnvironmentalDataServiceImpl extends ServiceImpl<EnvironmentalDataM
|
|
|
wdList.add(wd);
|
|
|
|
|
|
}
|
|
|
- //获取最后一条的时间
|
|
|
- List<Entity> lastData = baseMapper.getLastData(weatherLookNo);
|
|
|
- Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)");
|
|
|
- List<EnvironmentalData> environmentalDataList = environmentalData.stream().filter(e -> e.getTs().getTime() == timeEnd.getTime()).collect(Collectors.toList());
|
|
|
- if (environmentalDataList.size() != 0) {
|
|
|
- dataMap.put("t", environmentalDataList.get(0).getT());
|
|
|
- dataMap.put("rh", environmentalDataList.get(0).getRh());
|
|
|
- dataMap.put("pa", environmentalDataList.get(0).getPa());
|
|
|
- }
|
|
|
dataMap.put("wsList", wsList);
|
|
|
dataMap.put("wdList", wdList);
|
|
|
- dataMap.put("timeList", timeList);
|
|
|
return dataMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @return 首页温湿压
|
|
|
+ */
|
|
|
+ public ArrayList<HashMap<String, Object>> getTAndPaAndRh() {
|
|
|
+ List<WeatherLook> weatherLookList = weatherLookService.list();
|
|
|
+ weatherLookList = weatherLookList.stream().filter(w -> w.getWeatherLookNo().equals("1001")).collect(Collectors.toList());
|
|
|
+ ArrayList<HashMap<String, Object>> list = new ArrayList<>();
|
|
|
+ for (WeatherLook weatherLook : weatherLookList) {
|
|
|
+ HashMap<String, Object> weatherMap = new HashMap<>();
|
|
|
+ //获取最后一条的时间
|
|
|
+ EnvironmentalData environmentalData = baseMapper.selectLastTimeData(weatherLook.getWeatherLookNo());
|
|
|
+ if (environmentalData != null) {
|
|
|
+ weatherMap.put("t", environmentalData.getT());
|
|
|
+ weatherMap.put("rh", environmentalData.getRh());
|
|
|
+ weatherMap.put("pa", environmentalData.getPa());
|
|
|
+ weatherMap.put("weatherLook", weatherLook.getWeatherLookNo());
|
|
|
+ }
|
|
|
+ list.add(weatherMap);
|
|
|
+
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void exportExcel(HttpServletResponse response, String weatherLookNo, long startTime, long endTime) {
|
|
|
List<EnvironmentalData> environmentalDataList = this.selectAllData(weatherLookNo, startTime, endTime);
|
|
|
// List<EnvironmentalData> environmentalDataList = baseMapper.selectAll(weatherLookNo);
|
|
|
File file = new File("D:\\weatherLookNoExcel");
|
|
|
- if(!file.exists()){
|
|
|
+ if (!file.exists()) {
|
|
|
file.mkdirs();
|
|
|
}
|
|
|
- String fileName = file.getPath() + File.separator + weatherLookNo + "-" + DateUtil.format(new Date(startTime),"yyyy-MM-dd") + "-" + DateUtil.format(new Date(endTime),"yyyy-MM-dd") + ".xlsx";
|
|
|
+ String fileName = file.getPath() + File.separator + weatherLookNo + "-" + DateUtil.format(new Date(startTime), "yyyy-MM-dd") + "-" + DateUtil.format(new Date(endTime), "yyyy-MM-dd") + ".xlsx";
|
|
|
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
|
|
// 如果这里想使用03 则 传入excelType参数即可
|
|
|
EasyExcel.write(fileName, EnvironmentalData.class).sheet().registerConverter(new CustomStringStringConverter()).doWrite(environmentalDataList);
|
|
|
- FileUtil.downloadFile(new File(fileName),response);
|
|
|
+ FileUtil.downloadFile(new File(fileName), response);
|
|
|
+
|
|
|
+ cn.hutool.core.io.FileUtil.del(fileName);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|