From 27f37577f698c3cccefa117cee74c0713b36b0b0 Mon Sep 17 00:00:00 2001 From: jiangc <12345678> Date: Tue, 1 Apr 2025 17:21:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E6=97=A5=E7=94=B5=E5=8A=9B=E8=B4=9F?= =?UTF-8?q?=E8=8D=B7=202025=E5=B9=B44=E6=9C=881=E6=97=A517:21:45?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BoardNewServiceImpl.java | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java index 50df38d..51c16b1 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java @@ -3,6 +3,7 @@ package com.thing.qingyuan.board.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; +import com.thing.common.core.exception.SysException; import com.thing.common.core.utils.DateTimeUtils; import com.thing.common.data.tskv.TsKvDTO; import com.thing.common.tskv.service.TsKvService; @@ -49,14 +50,43 @@ public class BoardNewServiceImpl implements BoardNewService { Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); //当月结束时间 Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); + //获取租户编码 + Long realTenantCode = UserContext.getRealTenantCode(); + List attr = tsKvService.findTsKvByCodeAndAttr("CO_" + realTenantCode, "A16", dayStartTimeStamp, dayEndTimeStamp, true); + // 检查数据是否为空 + if (CollectionUtil.isEmpty(attr)) { + // 如果没有数据,返回错误 + throw new SysException("没有找到电力负荷数据"); + } + for (TsKvDTO kv : attr) { + // 获取时间戳 + Long timestamp = kv.getTs(); + // 电力负荷值 + String value = kv.getVal(); + // 将时间戳转换为日期格式 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String timestampStr = sdf.format(new Date(timestamp)); + // 填充电力负荷数据 + EnergyDataAnalyseDetailDTO detailDTO = new EnergyDataAnalyseDetailDTO(); + // 设置时间 + detailDTO.setDate(timestampStr); + // 设置电力负荷值 + detailDTO.setValue(new BigDecimal(value)); + currentMonthData.add(detailDTO); + } + result.setCurrentMonthData(currentMonthData); + return result; + } - /** - * 参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} - */ - String cqStr = sysParamsService.getValue("BOARD_TOTAL_ENERGY"); - Map codeMap = JSONObject.parseObject(cqStr, Map.class); - List keys = new ArrayList<>(); - keys.add("A16"); + + +// /** +// * 参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} +// */ +// String cqStr = sysParamsService.getValue("BOARD_TOTAL_ENERGY"); +// Map codeMap = JSONObject.parseObject(cqStr, Map.class); +// List keys = new ArrayList<>(); +// keys.add("A16"); //注释说明:获取电表在所传时间内A16属性的数据,该接口传的是天的时间,A16表示电负荷, todo // ThingsDTO thingsDTO = thingsService.getThingsByCode(codeMap.get("总用电")); // if(thingsDTO==null && StringUtils.isBlank(thingsDTO.getEntityId())){ @@ -73,9 +103,7 @@ public class BoardNewServiceImpl implements BoardNewService { // currentMonthData.add(energyDataAnalyseDetailDTO); // } // } - result.setCurrentMonthData(currentMonthData); - return result; - } + @Override