From 680a1708befd66bd135d62435bbc01dabf49ce7f Mon Sep 17 00:00:00 2001
From: DYL0109 <1332079466@qq.com>
Date: 星期六, 08 二月 2025 18:04:16 +0800
Subject: [PATCH] !52 组态图配置,历史数据查询 Merge pull request !52 from DYL0109/dyl_dev
---
zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataExcel.java | 70 ++++
zhitan-system/src/main/java/com/zhitan/realtimedata/service/impl/RealtimeDatabaseServiceImpl.java | 12
zhitan-system/src/main/java/com/zhitan/history/domain/dto/HistoricalDataDTO.java | 63 ++++
zhitan-system/src/main/java/com/zhitan/basicSetup/service/impl/SysEquipmentfileServiceImpl.java | 49 +++
zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataVO.java | 77 +++++
zhitan-system/src/main/java/com/zhitan/basicSetup/service/ISysEquipmentfileService.java | 33 ++
zhitan-admin/src/main/java/com/zhitan/web/controller/history/HistoryDataTrendController.java | 224 ++++++++++++++
zhitan-system/src/main/resources/mapper/basicSetup/SysEquipmentfileMapper.xml | 50 +++
zhitan-common/src/main/java/com/zhitan/common/config/BaseConfig.java | 4
zhitan-system/src/main/java/com/zhitan/realtimedata/service/RealtimeDatabaseService.java | 14
zhitan-admin/src/main/java/com/zhitan/web/controller/basicSetup/SysEquipmentfileController.java | 88 +++++
zhitan-system/src/main/java/com/zhitan/basicSetup/mapper/SysEquipmentfileMapper.java | 24 +
zhitan-system/src/main/java/com/zhitan/realtimedata/data/RealtimeDatabaseManager.java | 163 ++++++++++
13 files changed, 870 insertions(+), 1 deletions(-)
diff --git a/zhitan-admin/src/main/java/com/zhitan/web/controller/basicSetup/SysEquipmentfileController.java b/zhitan-admin/src/main/java/com/zhitan/web/controller/basicSetup/SysEquipmentfileController.java
new file mode 100644
index 0000000..8fa8bb2
--- /dev/null
+++ b/zhitan-admin/src/main/java/com/zhitan/web/controller/basicSetup/SysEquipmentfileController.java
@@ -0,0 +1,88 @@
+package com.zhitan.web.controller.basicSetup;
+
+import com.zhitan.basicSetup.service.ISysEquipmentfileService;
+import com.zhitan.common.annotation.Log;
+import com.zhitan.common.config.BaseConfig;
+import com.zhitan.common.core.controller.BaseController;
+import com.zhitan.common.core.domain.AjaxResult;
+import com.zhitan.common.enums.BusinessType;
+import com.zhitan.common.utils.file.FileUploadUtils;
+import com.zhitan.common.utils.uuid.UUID;
+import com.zhitan.realtimedata.domain.SysEquipmentFile;
+import com.zhitan.realtimedata.domain.SysSvgInfo;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+
+
+/**
+ * 缁勬�佸浘Controller
+ *
+ * @author sys
+ * @date 2020-02-24
+ */
+@RestController
+@RequestMapping("/basicSetup/equipmentfile")
+public class SysEquipmentfileController extends BaseController {
+
+ private final ISysEquipmentfileService sysEquipmentfileService;
+
+ public SysEquipmentfileController(
+ ISysEquipmentfileService sysEquipmentfileService) {
+ this.sysEquipmentfileService = sysEquipmentfileService;
+ }
+
+ @PostMapping(value = "/upload")
+ @Log(title = "绯荤粺鍥�", businessType = BusinessType.IMPORT)
+ public AjaxResult upload(MultipartFile file) throws IOException {
+ if (!file.isEmpty()) {
+ String fileSuffix = FileUploadUtils.getExtension(file);
+ if (StringUtils.containsIgnoreCase(".svg,.jpg,.png,.gif", fileSuffix)) {
+ //鏂囦欢鏈�缁堜繚瀛樼殑缁濆璺緞
+ String filePath = FileUploadUtils.upload(BaseConfig.getConfigurePath(), file);
+ return AjaxResult.success(filePath);
+ }
+ return AjaxResult.error("鏂囦欢鏍煎紡閿欒");
+ }
+ return AjaxResult.error("绯荤粺鍥句笂浼犲け璐�");
+ }
+
+ /**
+ * 淇敼缁勬�佸浘
+ */
+ @Log(title = "绯荤粺鍥�", businessType = BusinessType.UPDATE)
+ @PutMapping
+ public AjaxResult edit(@RequestBody SysEquipmentFile sysEquipmentfile) {
+ try {
+ sysEquipmentfileService.saveEquipmentFile(sysEquipmentfile);
+ return AjaxResult.success();
+ } catch (Exception ex) {
+ return AjaxResult.error();
+ }
+ }
+
+ @PutMapping("/setting/{nodeId}")
+ public AjaxResult saveSetting(@PathVariable("nodeId") String nodeId,
+ @RequestBody List<SysSvgInfo> svgInfo) {
+ try {
+ svgInfo.forEach(info -> info.setId(UUID.fastUUID().toString()));
+ sysEquipmentfileService.saveSettingInfo(nodeId, svgInfo);
+ return AjaxResult.success("淇濆瓨鎴愬姛锛�");
+ } catch (Exception ex) {
+ return AjaxResult.error("淇濆瓨澶辫触锛�");
+ }
+ }
+
+ @GetMapping("/configure/{nodeId}")
+ public AjaxResult getConfigure(@PathVariable("nodeId") String nodeId) {
+ try {
+ SysEquipmentFile sysEquipmentfile = sysEquipmentfileService.getConfigure(nodeId);
+ return AjaxResult.success(sysEquipmentfile);
+ } catch (Exception ex) {
+ return AjaxResult.error("淇濆瓨澶辫触锛�");
+ }
+ }
+}
diff --git a/zhitan-admin/src/main/java/com/zhitan/web/controller/history/HistoryDataTrendController.java b/zhitan-admin/src/main/java/com/zhitan/web/controller/history/HistoryDataTrendController.java
new file mode 100644
index 0000000..e1f067b
--- /dev/null
+++ b/zhitan-admin/src/main/java/com/zhitan/web/controller/history/HistoryDataTrendController.java
@@ -0,0 +1,224 @@
+package com.zhitan.web.controller.history;
+
+import cn.hutool.core.date.DateUtil;
+import com.zhitan.basicdata.domain.MeterImplement;
+import com.zhitan.basicdata.services.IMeterImplementService;
+import com.zhitan.common.annotation.Log;
+import com.zhitan.common.core.controller.BaseController;
+import com.zhitan.common.core.domain.AjaxResult;
+import com.zhitan.common.enums.BusinessType;
+import com.zhitan.common.enums.RetrievalModes;
+import com.zhitan.common.utils.poi.ExcelUtil;
+import com.zhitan.history.domain.dto.HistoricalDataDTO;
+import com.zhitan.history.domain.vo.HistoricalDataExcel;
+import com.zhitan.history.domain.vo.HistoricalDataVO;
+import com.zhitan.model.domain.EnergyIndex;
+import com.zhitan.model.service.IEnergyIndexService;
+import com.zhitan.realtimedata.domain.TagValue;
+import com.zhitan.realtimedata.service.RealtimeDatabaseService;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 璁惧鍚仠瀹炴椂鐩戞祴Controller
+ *
+ * @author sys
+ * @date 2020-03-30
+ */
+@RestController
+@RequestMapping("/dataMonitoring/historyDataTrend")
+public class HistoryDataTrendController extends BaseController {
+ @Autowired
+ private final IEnergyIndexService energyIndexService;
+
+ @Autowired
+ private final IMeterImplementService meterImplementService;
+
+ @Autowired
+ private final RealtimeDatabaseService realtimeDatabaseService;
+
+
+ public HistoryDataTrendController(IEnergyIndexService energyIndexService,
+ IMeterImplementService meterImplementService,
+ RealtimeDatabaseService realtimeDatabaseService) {
+ this.energyIndexService = energyIndexService;
+ this.meterImplementService = meterImplementService;
+ this.realtimeDatabaseService = realtimeDatabaseService;
+ }
+
+
+ @Log(title = "鑾峰彇妯″瀷鑺傜偣鍏宠仈閲囬泦鎸囨爣", businessType = BusinessType.UPDATE)
+ @GetMapping("/energyIndex/list")
+ public AjaxResult getSettingIndex(EnergyIndex energyIndex) {
+ try {
+ List<EnergyIndex> infoList = energyIndexService.selectEnergyIndexList(energyIndex);
+// List<String> codeList= infoList.stream().map(EnergyIndex::getCode).collect(Collectors.toList());
+// List<TagValue> valList = realtimeDatabaseService.retrieve(codeList);
+// List resultList = new ArrayList();
+ return AjaxResult.success(infoList);
+ } catch (Exception ex) {
+ logger.error("鑾峰彇鍏宠仈閲囬泦鎸囨爣鍑洪敊锛�", ex);
+ return AjaxResult.error("鑾峰彇鍏宠仈鎸囨爣鍑洪敊!");
+ }
+ }
+
+ @Log(title = "鏍规嵁鏃堕棿涓庣偣浣嶆煡璇㈠巻鍙茬洃娴嬫暟鎹�", businessType = BusinessType.UPDATE)
+ @GetMapping("/getHistoricalDataByIndexId")
+ public AjaxResult getHistoricalDataByIndexId(HistoricalDataDTO dto) {
+ try {
+ // 鑾峰彇鐐逛綅淇℃伅
+ EnergyIndex energyIndex = energyIndexService.selectEnergyIndexById(dto.getIndexId());
+ if (ObjectUtils.isEmpty(energyIndex)) {
+ return AjaxResult.error("鏈壘鍒扮偣浣嶄俊鎭�");
+ }
+ Date beginTime = dto.getDataTime();
+ Date endTime;
+ // 鏌ヨ鏉℃暟
+ int count = 1440;
+ if ("DAY".equals(dto.getTimeType())) {
+ endTime = DateUtil.endOfDay(beginTime);
+ } else {
+ count = 3600;
+ endTime = DateUtil.offsetSecond(DateUtil.offsetHour(beginTime, 1), -1);
+ }
+ // 鏌ヨ璁¢噺鍣ㄥ叿
+ MeterImplement info = meterImplementService.selectMeterImplementById(energyIndex.getMeterId());
+ List<TagValue> tagValueList = realtimeDatabaseService.retrieve(energyIndex.getCode(), beginTime, endTime,
+ RetrievalModes.BestFit, count);
+ List<HistoricalDataVO> voList = new ArrayList<>();
+ Date date = DateUtil.date();
+ for (int i = 0; i < count + 1; i++) {
+ HistoricalDataVO vo = new HistoricalDataVO();
+ vo.setIndexId(energyIndex.getIndexId());
+ String indexName = energyIndex.getName();
+ if (ObjectUtils.isNotEmpty(info)) {
+ indexName = info.getInstallactionLocation() + "_" + info.getMeterName() + "_" + indexName;
+ }
+ vo.setIndexName(indexName);
+ // 鍙栧��
+ String value = "--";
+ String usedValue = "--";
+ if (beginTime.getTime() <= date.getTime()) {
+ try {
+ TagValue tagValue = tagValueList.get(i);
+ BigDecimal cumulative = BigDecimal.valueOf(tagValue.getValue());
+
+ if ("SWWSDJ_SD".equals(energyIndex.getCode()) || "SWWSDJ_WD".equals(energyIndex.getCode())) {
+ cumulative = cumulative.multiply(BigDecimal.valueOf(0.1));
+ }
+ if (i > 0) {
+ TagValue previousTagValue = tagValueList.get(i - 1);
+ BigDecimal previousValue = BigDecimal.ZERO;
+ if (ObjectUtils.isNotEmpty(previousTagValue.getValue())) {
+ previousValue = BigDecimal.valueOf(previousTagValue.getValue());
+ }
+ if ("SWWSDJ_SD".equals(energyIndex.getCode()) || "SWWSDJ_WD".equals(energyIndex.getCode())) {
+ previousValue = previousValue.multiply(BigDecimal.valueOf(0.1));
+
+ }
+ usedValue = String.valueOf(cumulative.subtract(previousValue).setScale(2, RoundingMode.HALF_UP));
+ }
+
+ value = String.valueOf(cumulative.setScale(2, RoundingMode.HALF_UP));
+ } catch (Exception ignored) {
+ }
+ }
+ // 鏃堕棿
+ String timeName = DateUtil.formatDateTime(beginTime);
+ vo.setDataTime(timeName);
+ if ("DAY".equals(dto.getTimeType())) {
+ beginTime = DateUtil.offsetMinute(beginTime, 1);
+ } else {
+ beginTime = DateUtil.offsetSecond(beginTime, 1);
+ }
+ vo.setUsedValue(String.valueOf(usedValue));
+ vo.setValue(String.valueOf(value));
+ voList.add(vo);
+ }
+ return AjaxResult.success(voList);
+ } catch (Exception ex) {
+ logger.error("鏌ヨ鍘嗗彶鐩戞祴鏁版嵁鍑洪敊锛�", ex);
+ return AjaxResult.error("鏌ヨ鍘嗗彶鐩戞祴鏁版嵁鍑洪敊!");
+ }
+ }
+
+ @Log(title = "瀵煎嚭Excel", businessType = BusinessType.UPDATE)
+ @GetMapping("/export")
+ public AjaxResult export(HistoricalDataDTO dto) {
+ try {
+ // 鑾峰彇鐐逛綅淇℃伅
+ EnergyIndex energyIndex = energyIndexService.selectEnergyIndexById(dto.getIndexId());
+ if (ObjectUtils.isEmpty(energyIndex)) {
+ return AjaxResult.success("鏈壘鍒扮偣浣嶄俊鎭�");
+ }
+ Date beginTime = dto.getDataTime();
+ Date endTime;
+ // 鏌ヨ鏉℃暟
+ int count = 23;
+ if ("DAY".equals(dto.getTimeType())) {
+ endTime = DateUtil.endOfDay(beginTime);
+ } else {
+ count = 19;
+ endTime = DateUtil.offsetSecond(DateUtil.offsetHour(beginTime, 1), -1);
+ }
+ // 鏌ヨ璁¢噺鍣ㄥ叿
+ MeterImplement infor = meterImplementService.selectMeterImplementById(energyIndex.getMeterId());
+ List<TagValue> tagValueList = realtimeDatabaseService.retrieve(energyIndex.getCode(), beginTime, endTime,
+ RetrievalModes.BestFit, count);
+ List<HistoricalDataExcel> excelList = new ArrayList<>();
+ Date date = DateUtil.date();
+ for (int i = 0; i < count + 1; i++) {
+ HistoricalDataExcel vo = new HistoricalDataExcel();
+ String indexName = energyIndex.getName();
+ if (ObjectUtils.isNotEmpty(infor)) {
+ indexName = infor.getInstallactionLocation() + "_" + infor.getMeterName() + "_" + indexName;
+ }
+ vo.setIndexName(indexName);
+ // 鍙栧��
+ String value = "--";
+ String usedValue = "--";
+ if (beginTime.getTime() <= date.getTime()) {
+ try {
+ TagValue tagValue = tagValueList.get(i);
+ BigDecimal cumulative = BigDecimal.valueOf(tagValue.getValue());
+ if (i > 0) {
+ TagValue previousTagValue = tagValueList.get(i - 1);
+ BigDecimal previousValue = BigDecimal.valueOf(previousTagValue.getValue());
+ usedValue = String.valueOf(cumulative.subtract(previousValue).setScale(2, RoundingMode.HALF_UP));
+ }
+ value = String.valueOf(cumulative.setScale(2, RoundingMode.HALF_UP));
+ } catch (Exception ignored) {
+ }
+ }
+ // 鏃堕棿
+ String timeName = DateUtil.formatDateTime(beginTime);
+ vo.setDataTime(timeName);
+ if ("DAY".equals(dto.getTimeType())) {
+ beginTime = DateUtil.offsetHour(beginTime, 1);
+ } else {
+ beginTime = DateUtil.offsetMinute(beginTime, 3);
+ }
+ vo.setValue(String.valueOf(value));
+ vo.setUsedValue(String.valueOf(usedValue));
+ excelList.add(vo);
+ }
+ ExcelUtil<HistoricalDataExcel> util = new ExcelUtil<>(HistoricalDataExcel.class);
+ String sheetName = "鍘嗗彶鏁版嵁缁熻" + DateUtil.formatDate(dto.getDataTime());
+// return util.exportRealTimeDataExcel(excelList, sheetName);
+ return util.exportExcel(excelList, sheetName);
+ } catch (Exception ex) {
+ logger.error("瀵煎嚭Excel鏁版嵁鍑洪敊锛�", ex);
+ return AjaxResult.error("瀵煎嚭Excel鏁版嵁鍑洪敊!");
+ }
+ }
+
+}
diff --git a/zhitan-common/src/main/java/com/zhitan/common/config/BaseConfig.java b/zhitan-common/src/main/java/com/zhitan/common/config/BaseConfig.java
index edd535b..c9096ba 100644
--- a/zhitan-common/src/main/java/com/zhitan/common/config/BaseConfig.java
+++ b/zhitan-common/src/main/java/com/zhitan/common/config/BaseConfig.java
@@ -119,4 +119,8 @@
{
return getProfile() + "/upload";
}
+
+ public static String getConfigurePath() {
+ return getProfile() + "/configure";
+ }
}
diff --git a/zhitan-system/src/main/java/com/zhitan/basicSetup/mapper/SysEquipmentfileMapper.java b/zhitan-system/src/main/java/com/zhitan/basicSetup/mapper/SysEquipmentfileMapper.java
new file mode 100644
index 0000000..dae8e52
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/basicSetup/mapper/SysEquipmentfileMapper.java
@@ -0,0 +1,24 @@
+package com.zhitan.basicSetup.mapper;
+
+import com.zhitan.realtimedata.domain.SysEquipmentFile;
+import com.zhitan.realtimedata.domain.SysSvgInfo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 缁勬�佸浘Mapper鎺ュ彛
+ *
+ * @author sys
+ * @date 2020-02-24
+ */
+public interface SysEquipmentfileMapper {
+
+ void saveEquipmentFile(SysEquipmentFile sysEquipmentfile);
+
+ void saveSettingInfo(@Param("nodeId") String nodeId, @Param("svgInfo") List<SysSvgInfo> svgInfo);
+
+ SysEquipmentFile getConfigure(String nodeId);
+
+ List<SysSvgInfo> getConfigureTag(String nodeId);
+}
diff --git a/zhitan-system/src/main/java/com/zhitan/basicSetup/service/ISysEquipmentfileService.java b/zhitan-system/src/main/java/com/zhitan/basicSetup/service/ISysEquipmentfileService.java
new file mode 100644
index 0000000..f62ca2a
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/basicSetup/service/ISysEquipmentfileService.java
@@ -0,0 +1,33 @@
+package com.zhitan.basicSetup.service;
+
+import com.zhitan.realtimedata.domain.SysEquipmentFile;
+import com.zhitan.realtimedata.domain.SysSvgInfo;
+
+import java.util.List;
+
+/**
+ * 缁勬�佸浘Service鎺ュ彛
+ *
+ * @author sys
+ * @date 2020-02-24
+ */
+public interface ISysEquipmentfileService {
+
+ void saveEquipmentFile(SysEquipmentFile sysEquipmentfile);
+
+ void saveSettingInfo(String nodeId, List<SysSvgInfo> svgInfo);
+
+ /**
+ * 鑾峰彇缁勬�佸浘閰嶇疆淇℃伅
+ * @param nodeId 妯″瀷鑺傜偣 id
+ * @return
+ */
+ SysEquipmentFile getConfigure(String nodeId);
+
+ /**
+ * 鑾峰彇缁勬�佸浘閰嶇疆鐨勭偣浣嶅彿
+ * @param nodeId 妯″瀷鑺傜偣 id
+ * @return
+ */
+ List<SysSvgInfo> getConfigureTag(String nodeId);
+}
diff --git a/zhitan-system/src/main/java/com/zhitan/basicSetup/service/impl/SysEquipmentfileServiceImpl.java b/zhitan-system/src/main/java/com/zhitan/basicSetup/service/impl/SysEquipmentfileServiceImpl.java
new file mode 100644
index 0000000..bad69ef
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/basicSetup/service/impl/SysEquipmentfileServiceImpl.java
@@ -0,0 +1,49 @@
+package com.zhitan.basicSetup.service.impl;
+
+import com.zhitan.basicSetup.mapper.SysEquipmentfileMapper;
+import com.zhitan.basicSetup.service.ISysEquipmentfileService;
+import com.zhitan.realtimedata.domain.SysEquipmentFile;
+import com.zhitan.realtimedata.domain.SysSvgInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 缁勬�佸浘Service涓氬姟灞傚鐞�
+ *
+ * @author sys
+ * @date 2020-02-24
+ */
+@Service
+public class SysEquipmentfileServiceImpl implements ISysEquipmentfileService {
+
+ @Autowired
+ private SysEquipmentfileMapper equipmentfileMapper;
+
+ @Override
+ public void saveEquipmentFile(SysEquipmentFile sysEquipmentfile) {
+ equipmentfileMapper.saveEquipmentFile(sysEquipmentfile);
+ }
+
+ @Override
+ public void saveSettingInfo(String nodeId, List<SysSvgInfo> svgInfo) {
+ equipmentfileMapper.saveSettingInfo(nodeId, svgInfo);
+ }
+
+ @Override
+ public SysEquipmentFile getConfigure(String nodeId) {
+ SysEquipmentFile sysEquipmentfile = equipmentfileMapper.getConfigure(nodeId);
+ List<SysSvgInfo> infos = getConfigureTag(nodeId);
+ if (sysEquipmentfile != null) {
+ sysEquipmentfile.setInfoList(infos);
+ }
+
+ return sysEquipmentfile;
+ }
+
+ @Override
+ public List<SysSvgInfo> getConfigureTag(String nodeId) {
+ return equipmentfileMapper.getConfigureTag(nodeId);
+ }
+}
diff --git a/zhitan-system/src/main/java/com/zhitan/history/domain/dto/HistoricalDataDTO.java b/zhitan-system/src/main/java/com/zhitan/history/domain/dto/HistoricalDataDTO.java
new file mode 100644
index 0000000..347976b
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/history/domain/dto/HistoricalDataDTO.java
@@ -0,0 +1,63 @@
+package com.zhitan.history.domain.dto;
+
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+
+/**
+ * 鍘嗗彶鐩戞祴鏁版嵁璇锋眰 DTO
+ *
+ * @Author: Zhujw
+ * @Date: 2023/3/7
+ */
+public class HistoricalDataDTO {
+
+ /**
+ * 鐐逛綅id
+ */
+ @NotBlank(message = "鏈壘鍒扮偣浣嶄俊鎭�")
+ private String indexId;
+
+ /**
+ * 鏃堕棿绫诲瀷
+ */
+ @NotBlank(message = "鏈壘鍒版椂闂寸被鍨�")
+ private String timeType;
+
+ /**
+ * 鏌ヨ鏃堕棿
+ */
+ @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+ @NotNull(message = "鏈壘鍒版椂闂翠俊鎭�")
+ private Date dataTime;
+
+ public String getIndexId() {
+ return indexId;
+ }
+
+ public void setIndexId(String indexId) {
+ this.indexId = indexId;
+ }
+
+ public String getTimeType() {
+ return timeType;
+ }
+
+ public void setTimeType(String timeType) {
+ this.timeType = timeType;
+ }
+
+ public Date getDataTime() {
+ return dataTime;
+ }
+
+ public void setDataTime(Date dataTime) {
+ this.dataTime = dataTime;
+ }
+
+}
\ No newline at end of file
diff --git a/zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataExcel.java b/zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataExcel.java
new file mode 100644
index 0000000..ca0b653
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataExcel.java
@@ -0,0 +1,70 @@
+package com.zhitan.history.domain.vo;
+
+
+import com.zhitan.common.annotation.Excel;
+
+/**
+ * 鍘嗗彶鐩戞祴鏁版嵁杩斿洖 Excel
+ *
+ * @Author: Zhujw
+ * @Date: 2023/3/7
+ */
+public class HistoricalDataExcel {
+
+ /**
+ * 鐐逛綅鍚嶇О
+ */
+ @Excel(name = "鐐逛綅鍚嶇О")
+ private String indexName;
+
+ /**
+ * 鍊�
+ */
+ @Excel(name = "鍊�")
+ private String value;
+
+ /**
+ * 浣跨敤閲�
+ */
+ @Excel(name = "浣跨敤閲�")
+ private String usedValue;
+
+ /**
+ * 鏃堕棿
+ */
+ @Excel(name = "鏃堕棿")
+ private String dataTime;
+
+
+ public String getIndexName() {
+ return indexName;
+ }
+
+ public void setIndexName(String indexName) {
+ this.indexName = indexName;
+ }
+
+ public String getDataTime() {
+ return dataTime;
+ }
+
+ public void setDataTime(String dataTime) {
+ this.dataTime = dataTime;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getUsedValue() {
+ return usedValue;
+ }
+
+ public void setUsedValue(String usedValue) {
+ this.usedValue = usedValue;
+ }
+}
\ No newline at end of file
diff --git a/zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataVO.java b/zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataVO.java
new file mode 100644
index 0000000..b03f10b
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/history/domain/vo/HistoricalDataVO.java
@@ -0,0 +1,77 @@
+package com.zhitan.history.domain.vo;
+
+
+/**
+ * 鍘嗗彶鐩戞祴鏁版嵁杩斿洖 VO
+ *
+ * @Author: Zhujw
+ * @Date: 2023/3/7
+ */
+public class HistoricalDataVO {
+
+ /**
+ * 鐐逛綅id
+ */
+ private String indexId;
+
+ /**
+ * 鐐逛綅鍚嶇О
+ */
+ private String indexName;
+
+ /**
+ * 鏃堕棿
+ */
+ private String dataTime;
+
+ /**
+ * 鍊�
+ */
+ private String value;
+
+ /**
+ * 浣跨敤閲�
+ */
+ private String usedValue;
+
+
+ public String getIndexId() {
+ return indexId;
+ }
+
+ public void setIndexId(String indexId) {
+ this.indexId = indexId;
+ }
+
+ public String getIndexName() {
+ return indexName;
+ }
+
+ public void setIndexName(String indexName) {
+ this.indexName = indexName;
+ }
+
+ public String getDataTime() {
+ return dataTime;
+ }
+
+ public void setDataTime(String dataTime) {
+ this.dataTime = dataTime;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getUsedValue() {
+ return usedValue;
+ }
+
+ public void setUsedValue(String usedValue) {
+ this.usedValue = usedValue;
+ }
+}
\ No newline at end of file
diff --git a/zhitan-system/src/main/java/com/zhitan/realtimedata/data/RealtimeDatabaseManager.java b/zhitan-system/src/main/java/com/zhitan/realtimedata/data/RealtimeDatabaseManager.java
new file mode 100644
index 0000000..f3914ff
--- /dev/null
+++ b/zhitan-system/src/main/java/com/zhitan/realtimedata/data/RealtimeDatabaseManager.java
@@ -0,0 +1,163 @@
+package com.zhitan.realtimedata.data;
+
+import com.influxdb.client.InfluxDBClient;
+import com.influxdb.client.InfluxDBClientFactory;
+import com.influxdb.client.domain.HealthCheck;
+import com.zhitan.common.enums.CollectionModes;
+import com.zhitan.common.enums.RetrievalModes;
+import com.zhitan.realtimedata.config.RtdbConfig;
+import com.zhitan.realtimedata.domain.TagValue;
+import com.zhitan.realtimedata.service.RealtimeDatabase;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * @author 鑼冩柊瀵� 瀹炴椂鏁版嵁搴撹闂鐞�.
+ */
+@Component
+public class RealtimeDatabaseManager {
+
+ private final RealtimeDatabase connection;
+
+ private final Logger logger = LogManager.getLogger(RealtimeDatabaseManager.class);
+
+ public RealtimeDatabaseManager(RtdbConfig config) {
+ connection = new VirtualRtdb();
+ try {
+ InfluxDBClient influxDBClient = InfluxDBClientFactory.create(config.getHost(),
+ config.getToken().toCharArray(), config.getOrg(), config.getBucket());
+
+ logger.error("--------------------瀹炴椂搴撹繛鎺ユ垚鍔�--------------------");
+ HealthCheck health = influxDBClient.health();
+ if (health.getStatus() == HealthCheck.StatusEnum.FAIL) {
+ influxDBClient.close();
+ }
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ public TagValue retrieve(String tagCode) {
+ List<String> tagCodes = new ArrayList<>();
+ tagCodes.add(tagCode);
+ List<TagValue> tagValues = retrieve(tagCodes);
+ if (!tagValues.isEmpty()) {
+ return tagValues.get(0);
+ }
+
+ return null;
+ }
+
+ public List<TagValue> retrieve(List<String> tagCodes) {
+ List<TagValue> tagValues = new ArrayList<>();
+ try {
+ tagValues = connection.retrieve(tagCodes);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+
+ return tagValues;
+ }
+
+ public TagValue retrieve(String tagCode, Date dataTime, String timeCode) {
+ List<String> tagCodes = new ArrayList<>();
+ tagCodes.add(tagCode);
+ List<TagValue> tagValues = retrieve(tagCodes, dataTime, timeCode);
+ if (!tagValues.isEmpty()) {
+ return tagValues.get(0);
+ }
+
+ return null;
+ }
+
+ public List<TagValue> retrieve(List<String> tagCodes, Date dataTime, String timeCode) {
+ List<TagValue> tagValues = new ArrayList<>();
+ try {
+ List<TagValue> tmp = connection.retrieve(tagCodes, dataTime, timeCode);
+ for (String tagCode : tagCodes) {
+ Optional<TagValue> tagValue = tmp.stream()
+ .filter(f -> StringUtils.equalsIgnoreCase(f.getTagCode(), tagCode)).findAny();
+ TagValue value;
+ if (!tagValue.isPresent()) {
+ value = new TagValue();
+ value.setTagCode(tagCode);
+ value.setDataTime(dataTime);
+ } else {
+ value = tagValue.get();
+ }
+
+ tagValues.add(value);
+ }
+ } catch (Exception e1) {
+ logger.error(e1);
+ }
+
+ return tagValues;
+ }
+
+ public List<TagValue> retrieve(String tagCode, Date beginTime, Date endTime,
+ RetrievalModes retrievalModes, int pointCount) {
+ List<String> tagCodes = new ArrayList<>();
+ tagCodes.add(tagCode);
+ return retrieve(tagCodes, beginTime, endTime, retrievalModes, pointCount);
+ }
+
+ public List<TagValue> retrieve(List<String> tagCodes, Date beginTime, Date endTime,
+ RetrievalModes retrievalModes, int pointCount) {
+ List<TagValue> tagValues = new ArrayList<>();
+ try {
+ tagValues = connection.retrieve(tagCodes, beginTime, endTime, retrievalModes, pointCount);
+ } catch (Exception e1) {
+ logger.error(e1);
+ }
+
+ return tagValues;
+ }
+
+ public TagValue statistics(String tagCode, Date beginTime, Date endTime,
+ CollectionModes collectionModes) {
+ List<String> tagCodes = new ArrayList<>();
+ tagCodes.add(tagCode);
+ List<TagValue> tagValues = statistics(tagCodes, beginTime, endTime, collectionModes);
+ if (!tagValues.isEmpty()) {
+ return tagValues.get(0);
+ }
+
+ return null;
+ }
+
+ public List<TagValue> statistics(List<String> tagCodes, Date beginTime, Date endTime,
+ CollectionModes collectionModes) {
+ List<TagValue> tagValues = new ArrayList<>();
+ try {
+ tagValues = connection.statistics(tagCodes, beginTime, endTime, collectionModes);
+ } catch (Exception e1) {
+ logger.error(e1);
+ }
+
+ return tagValues;
+ }
+
+ public void storeData(List<TagValue> tagValues) {
+ try {
+ connection.storeData(tagValues);
+ } catch (Exception e1) {
+ logger.error(e1);
+ }
+ }
+
+ public void insertData(List<TagValue> tagValues) {
+ try {
+ connection.insertData(tagValues);
+ } catch (Exception e1) {
+ logger.error(e1);
+ }
+ }
+}
diff --git a/zhitan-system/src/main/java/com/zhitan/realtimedata/service/RealtimeDatabaseService.java b/zhitan-system/src/main/java/com/zhitan/realtimedata/service/RealtimeDatabaseService.java
index 956a5cd..dc45bc7 100644
--- a/zhitan-system/src/main/java/com/zhitan/realtimedata/service/RealtimeDatabaseService.java
+++ b/zhitan-system/src/main/java/com/zhitan/realtimedata/service/RealtimeDatabaseService.java
@@ -2,6 +2,7 @@
import com.zhitan.common.enums.CollectionModes;
+import com.zhitan.common.enums.RetrievalModes;
import com.zhitan.realtimedata.domain.TagValue;
import java.util.Date;
@@ -105,4 +106,17 @@
* @param tagValues 娴嬬偣鍘嗗彶鏃跺埢鏁版嵁
*/
void insertData(List<TagValue> tagValues);
+
+ /**
+ * 鑾峰彇涓�娈垫椂闂村唴娴嬬偣鐨勫巻鍙叉暟鎹�.
+ *
+ * @param tagCode 娴嬬偣缂栧彿
+ * @param beginTime 寮�濮嬫椂闂�
+ * @param endTime 缁撴潫鏃堕棿
+ * @param retrievalModes 鏌ヨ鏁版嵁鏂瑰紡
+ * @param pointCount 娴嬬偣寰楀埌鐨勬暟鎹釜鏁�
+ * @return 娴嬬偣鍘嗗彶鏁版嵁
+ */
+ List<TagValue> retrieve(String tagCode, Date beginTime, Date endTime,
+ RetrievalModes retrievalModes, int pointCount);
}
diff --git a/zhitan-system/src/main/java/com/zhitan/realtimedata/service/impl/RealtimeDatabaseServiceImpl.java b/zhitan-system/src/main/java/com/zhitan/realtimedata/service/impl/RealtimeDatabaseServiceImpl.java
index bb8b97b..7128652 100644
--- a/zhitan-system/src/main/java/com/zhitan/realtimedata/service/impl/RealtimeDatabaseServiceImpl.java
+++ b/zhitan-system/src/main/java/com/zhitan/realtimedata/service/impl/RealtimeDatabaseServiceImpl.java
@@ -2,6 +2,8 @@
import com.google.common.collect.Lists;
import com.zhitan.common.enums.CollectionModes;
+import com.zhitan.common.enums.RetrievalModes;
+import com.zhitan.realtimedata.data.RealtimeDatabaseManager;
import com.zhitan.realtimedata.data.influxdb.InfluxDBRepository;
import com.zhitan.realtimedata.domain.TagValue;
import com.zhitan.realtimedata.service.RealtimeDatabaseService;
@@ -20,8 +22,11 @@
private final InfluxDBRepository repository;
- public RealtimeDatabaseServiceImpl(InfluxDBRepository repository) {
+ private final RealtimeDatabaseManager realtimeDatabaseManager;
+
+ public RealtimeDatabaseServiceImpl(InfluxDBRepository repository, RealtimeDatabaseManager realtimeDatabaseManager) {
this.repository = repository;
+ this.realtimeDatabaseManager = realtimeDatabaseManager;
}
/**
@@ -146,4 +151,9 @@
repository.store(tagValues);
}
+ @Override
+ public List<TagValue> retrieve(String tagCode, Date beginTime, Date endTime,
+ RetrievalModes retrievalModes, int pointCount) {
+ return realtimeDatabaseManager.retrieve(tagCode, beginTime, endTime, retrievalModes, pointCount);
+ }
}
diff --git a/zhitan-system/src/main/resources/mapper/basicSetup/SysEquipmentfileMapper.xml b/zhitan-system/src/main/resources/mapper/basicSetup/SysEquipmentfileMapper.xml
new file mode 100644
index 0000000..379a291
--- /dev/null
+++ b/zhitan-system/src/main/resources/mapper/basicSetup/SysEquipmentfileMapper.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhitan.basicSetup.mapper.SysEquipmentfileMapper">
+ <resultMap id="SysEquipmentFile"
+ type="com.zhitan.realtimedata.domain.SysEquipmentFile">
+ <result property="nodeId" column="node_id"/>
+ <result property="filePath" column="filepath"/>
+ </resultMap>
+ <resultMap id="SysSvgInfo"
+ type="com.zhitan.realtimedata.domain.SysSvgInfo">
+ <result property="id" column="id"/>
+ <result property="param" column="param"/>
+ <result property="tag" column="tag"/>
+ </resultMap>
+
+ <insert id="saveSettingInfo">
+ delete
+ from sys_svg_info
+ where node_id = #{nodeId};
+
+ <foreach collection="svgInfo" item="info" separator=";">
+ insert into sys_svg_info (id, node_id, param, tag)
+ values (#{info.id}, #{nodeId}, #{info.param}, #{info.tag});
+ </foreach>
+ </insert>
+
+ <update id="saveEquipmentFile">
+ insert into sys_equipmentfile (node_id, filepath)
+ select #{nodeId}, #{filePath}
+ on conflict
+ (node_id)
+ do update
+ set filepath = #{filePath}
+ </update>
+
+ <select id="getConfigure" resultMap="SysEquipmentFile">
+ select node_id, filepath
+ from sys_equipmentfile
+ where node_id = #{nodeId};
+ </select>
+
+ <select id="getConfigureTag" resultMap="SysSvgInfo">
+ select id, param, tag
+ from sys_svg_info
+ where node_id = #{nodeId}
+ </select>
+
+</mapper>
--
Gitblit v1.9.3