2023-08-27 09:47:36 优化完善能耗统计设备用能数据入库功能!

master
魔神煜修罗皇 2 years ago
parent 2c97d2043c
commit 75d8e2d255
  1. 4
      psdc-admin/src/main/resources/application-prod.yml
  2. 2
      psdc-admin/src/main/resources/application.yml
  3. 2
      psdc-business/src/main/java/com/psdc/mqtt/savedata/DataAndPowerSave.java
  4. 22
      psdc-business/src/main/java/com/psdc/service/impl/PsdcStrategyLogService.java

@ -54,9 +54,9 @@ spring:
# 数据库驱动 # 数据库驱动
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://127.0.0.1:3308/psdc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true url: jdbc:mysql://127.0.0.1:3306/psdc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&nullCatalogMeansCurrent=true
username: root username: root
password: root password: 123456
messages: messages:
# 国际化资源文件路径 # 国际化资源文件路径
basename: i18n/messages basename: i18n/messages

@ -1,3 +1,3 @@
spring: spring:
profiles: profiles:
active: prod active: dev

@ -177,7 +177,7 @@ public class DataAndPowerSave {
PsdcStrategyLog strategyLog = psdcStrategyLogMapper.selMyRunLog(2); PsdcStrategyLog strategyLog = psdcStrategyLogMapper.selMyRunLog(2);
if (null != strategyLog) { if (null != strategyLog) {
Boolean b2 = false; boolean b2 = false;
String[] runCodes = strategyLog.getRunSceneCodes().split(","); String[] runCodes = strategyLog.getRunSceneCodes().split(",");
String[] resList; String[] resList;
if (null != strategyLog.getStrategyRunRes()) { if (null != strategyLog.getStrategyRunRes()) {

@ -48,7 +48,8 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService {
public List<PsdcStrategyLog> selMyStrategyLog() { public List<PsdcStrategyLog> selMyStrategyLog() {
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
List<PsdcStrategyLog> logList = strategyLogMapper.selMyStrategyLog(userId); List<PsdcStrategyLog> logList = strategyLogMapper.selMyStrategyLog(userId);
for (PsdcStrategyLog psl : logList){ // 策略层 // 策略层
for (PsdcStrategyLog psl : logList) {
Long code = psl.getStrategyCode(); Long code = psl.getStrategyCode();
PsdcStrategy res; PsdcStrategy res;
Double strategyUseEnergy = 0.0; Double strategyUseEnergy = 0.0;
@ -56,7 +57,8 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService {
if (null != strategyList && strategyList.size() > 0) { if (null != strategyList && strategyList.size() > 0) {
res = strategyList.get(0); res = strategyList.get(0);
String[] split = res.getScenes().split(","); String[] split = res.getScenes().split(",");
for (String s : split){ // 步骤层【1个步骤1个设备】 // 步骤层【1个步骤1个设备】
for (String s : split) {
List<SceneVo> sceneVos = sceneMapper.findSceneByUserAndSceneCode(userId, Long.parseLong(s), null); List<SceneVo> sceneVos = sceneMapper.findSceneByUserAndSceneCode(userId, Long.parseLong(s), null);
// for (SceneVo sv : sceneVos) { // 设备层 // for (SceneVo sv : sceneVos) { // 设备层
// Integer deviceId = sv.getDeviceId(); // Integer deviceId = sv.getDeviceId();
@ -81,9 +83,9 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService {
psl.setSceneUseEnergy(strategyUseEnergy); psl.setSceneUseEnergy(strategyUseEnergy);
double v = 0.0; double v = 0.0;
if (jssc > 0.0) { if (jssc > 0.0) {
v = strategyUseEnergy / jssc; // 时长空判断处理 // 时长空判断处理
v = strategyUseEnergy / jssc;
} }
// System.out.println("触发 = " + v + "\n");
String s = df.format(v); String s = df.format(v);
if (".".equals(s.substring(0, 1))) { if (".".equals(s.substring(0, 1))) {
s = "0" + s; s = "0" + s;
@ -170,9 +172,15 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService {
public Double jssc(SimpleDateFormat dfs, String start, String end) { public Double jssc(SimpleDateFormat dfs, String start, String end) {
try { try {
Double d1 = Double.valueOf(dfs.parse(start).getTime()); double d1 = 0.0;
Double d2 = Double.valueOf(dfs.parse(end).getTime()); if (null != start && !"".equals(start)) {
Double between = (d2 - d1)/1000/3600; d1 = (double) dfs.parse(start).getTime();
}
double d2 = 0.0;
if (null != end && !"".equals(end)) {
d2 = (double) dfs.parse(end).getTime();
}
double between = (d2 - d1) / 1000 / 3600;
return between; return between;
} catch (ParseException pe) { } catch (ParseException pe) {
pe.printStackTrace(); pe.printStackTrace();

Loading…
Cancel
Save