From 9e16f14a6de9066a596952c9b6d0dd97e02ea6f9 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Sat, 8 Jun 2024 17:05:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:100:=20=E7=AC=AC=E4=B8=80=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gasweb/controller/ChartController.java | 48 ++++ .../gasweb/repository/GasRepository.java | 6 + src/main/resources/application.yml | 3 + src/main/resources/templates/index.ftl | 260 ++++++++++++++---- 4 files changed, 268 insertions(+), 49 deletions(-) diff --git a/src/main/java/cc/niushuai/gasweb/controller/ChartController.java b/src/main/java/cc/niushuai/gasweb/controller/ChartController.java index e5e3687..8eb4f7b 100644 --- a/src/main/java/cc/niushuai/gasweb/controller/ChartController.java +++ b/src/main/java/cc/niushuai/gasweb/controller/ChartController.java @@ -16,16 +16,24 @@ package cc.niushuai.gasweb.controller; +import cc.niushuai.gasweb.entity.ChartResp; +import cc.niushuai.gasweb.entity.Gas; import cc.niushuai.gasweb.repository.GasRepository; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 图表请求入口 @@ -50,4 +58,44 @@ public class ChartController { return "hello test"; } + + @Operation(summary = "根据类型获取不同表的数据") + @PostMapping("/fetch") + @ResponseBody + public Map fetch(String startDateTime, String endDateTime) { + + Map map = new HashMap<>(); + List allList = gasRepository.findAllByTimeBetweenOrderByIdAsc(DateUtil.parseDateTime(startDateTime), DateUtil.parseDateTime(endDateTime)); + + if (CollUtil.isNotEmpty(allList)) { + + ChartResp co = new ChartResp("CO浓度"); + ChartResp co2 = new ChartResp("CO2浓度"); + ChartResp ch4 = new ChartResp("CH4浓度"); + ChartResp temperature = new ChartResp("环境温度"); + ChartResp rp2024_temperature = new ChartResp("rp2024温度"); + + + for (Gas gas : allList) { + + String dateTime = DateUtil.formatDateTime(gas.getTime()); + + co.getData().add(new ChartResp.Data(dateTime, gas.getCo())); + co2.getData().add(new ChartResp.Data(dateTime, gas.getCo2())); + ch4.getData().add(new ChartResp.Data(dateTime, gas.getCh4())); + temperature.getData().add(new ChartResp.Data(dateTime, gas.getTemperature())); + rp2024_temperature.getData().add(new ChartResp.Data(dateTime, gas.getRp2040Temperature())); + } + + map.put("co", co); + map.put("co2", co2); + map.put("ch4", ch4); + map.put("temperature", temperature); + map.put("rp2024_temperature", rp2024_temperature); + } + + return map; + } + + } diff --git a/src/main/java/cc/niushuai/gasweb/repository/GasRepository.java b/src/main/java/cc/niushuai/gasweb/repository/GasRepository.java index 8a315d9..0d6894c 100644 --- a/src/main/java/cc/niushuai/gasweb/repository/GasRepository.java +++ b/src/main/java/cc/niushuai/gasweb/repository/GasRepository.java @@ -20,6 +20,9 @@ import cc.niushuai.gasweb.entity.Gas; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Date; +import java.util.List; + /** * gas sql repository * @@ -29,4 +32,7 @@ import org.springframework.stereotype.Repository; */ @Repository public interface GasRepository extends JpaRepository { + + List findAllByTimeBetweenOrderByIdAsc(Date startDateTime, Date endDateTime); + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6bf0489..6c35757 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -48,6 +48,9 @@ spring: username: ${MYSQL_USERNAME} password: ${MYSQL_PASSWORD} + jpa: + open-in-view: false + logging: file: name: logs/gas-web.log diff --git a/src/main/resources/templates/index.ftl b/src/main/resources/templates/index.ftl index d3a26cf..20ca337 100644 --- a/src/main/resources/templates/index.ftl +++ b/src/main/resources/templates/index.ftl @@ -5,14 +5,12 @@ + <#--bootstrap--> - - + <#--datepicker--> + - - - @@ -29,78 +31,238 @@

Gas监控

+
+ + + - + +



-
+
-
+
-
+
-
+
-
+
+<#--jq--> + +<#--bootstrap--> + +<#--datepicker--> + + + +<#--echarts--> + + + +