Browse Source

1、美的泵读取设置问题修复;

dev
mh 4 months ago
parent
commit
b298be7fd9
  1. 17
      user-service/pom.xml
  2. 6
      user-service/src/main/java/com/mh/user/job/DealDataJob.java
  3. 21
      user-service/src/main/java/com/mh/user/service/impl/HistoryDataPreServiceImpl.java
  4. 1
      user-service/src/main/java/com/mh/user/strategy/HeatPumpStrategy.java
  5. 17
      user-service/src/test/java/com/mh/user/DealDataTest.java

17
user-service/pom.xml

@ -35,6 +35,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-config -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-config</artifactId>-->
<!-- <version>2.2.2.RELEASE</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- mybatis配置-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>

6
user-service/src/main/java/com/mh/user/job/DealDataJob.java

@ -50,7 +50,7 @@ public class DealDataJob {
/**
* 定时处理汇总数据每15分钟处理一次,十分钟(0 0/10 * * * ?)
*/
// @Scheduled(cron = "0 0/15 * * * ?")
@Scheduled(cron = "0 0/15 * * * ?")
public void ProEnergy() {
try {
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
@ -73,7 +73,7 @@ public class DealDataJob {
/**
* 采集
*/
// @Scheduled(cron = "35 0/2 * * * ?")
@Scheduled(cron = "35 0/2 * * * ?")
// @Scheduled(cron = "0/10 * * * * ?") 0 0/5 * * * ?
// @Scheduled(cron = "0 0/5 * * * ?") //5分钟
public void collect() {
@ -148,7 +148,7 @@ public class DealDataJob {
/**
* 定时处理数据每十五分钟处理一次
*/
// @Scheduled(cron = "0 0/15 * * * ?")
@Scheduled(cron = "0 0/15 * * * ?")
public void dealData() {
try {
StopWatch stopWatch = new StopWatch();

21
user-service/src/main/java/com/mh/user/service/impl/HistoryDataPreServiceImpl.java

@ -17,6 +17,7 @@ import com.mh.user.dto.EnergyPreEchartDataDTO;
import com.mh.user.dto.EnergyPreTopDataDTO;
import com.mh.user.entity.HistoryDataPre;
import com.mh.user.entity.SysParamEntity;
import com.mh.user.job.GetWeatherInfoJob;
import com.mh.user.mapper.HistoryDataPreMapper;
import com.mh.user.service.HistoryDataPreService;
import com.mh.user.service.SysParamService;
@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@ -54,6 +56,10 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
@Resource
private SysParamService sysParamService;
@Resource
private GetWeatherInfoJob getWeatherInfoJob;
public static String[] convert(HistoryDataPre dataPre) {
// 假设HistoryDataPre有字段如field1, field2, field3等,根据需要进行转换
return new String[] {
@ -98,15 +104,16 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
@Override
public void startPredictData(String buildingId, String curDate) throws Exception {
// 判断是否存在天气温度数据以及现在的用水量用电量等
int isPre = historyDataPreMapper.selectIsPre(buildingId, curDate);
if (isPre > 0) {
return;
}
// int isPre = historyDataPreMapper.selectIsPre(buildingId, curDate);
// if (isPre > 0) {
// return;
// }
// 获取当前天气数据
SysParamEntity sysParam = sysParamService.selectSysParam();
Object weather = caffeineCache.getIfPresent(sysParam.getProArea());
if (weather == null) {
return;
getWeatherInfoJob.getWeatherInfo();
weather = caffeineCache.getIfPresent(sysParam.getProArea());
}
String weatherStr = (String) weather;
JSONObject jsonObject = JSON.parseObject(weatherStr);
@ -154,7 +161,7 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
for (int i = 0; i < result.getMatrixRowCount(); i++) {
String[] record = new String[result.getMatrixColCount()];
for (int j = 0; j < result.getMatrixColCount(); j++) {
record[j] = result.getValOfIdx(i, j)+"";
record[j] = String.valueOf(result.getValOfIdx(i, j));
}
// 拼接预测值
preHistoryData.setWaterValuePre(evaluateAndReturnBigDecimal(record[0]));
@ -178,7 +185,7 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
public static BigDecimal evaluateAndReturnBigDecimal(String recordValue) {
BigDecimal value = new BigDecimal(recordValue);
if (value.compareTo(BigDecimal.ZERO) >= 0) {
return value;
return value.setScale(2, RoundingMode.HALF_UP);
} else {
return BigDecimal.ZERO;
}

1
user-service/src/main/java/com/mh/user/strategy/HeatPumpStrategy.java

@ -243,6 +243,7 @@ public class HeatPumpStrategy implements DeviceStrategy {
String closetTime = checkStr.substring(16, 18) + checkStr.substring(20, 22);
sValue = startTime + closetTime;
}
rtData = sValue;
} else if (checkStr.substring(2, 4).equalsIgnoreCase("10")) {
log.info("时间: " + dateStr + ",热泵ID: " + addr + ",操作成功! ");
return Constant.SUCCESS;

17
user-service/src/test/java/com/mh/user/DealDataTest.java

@ -3,6 +3,7 @@ package com.mh.user;
import com.mh.user.entity.EnergyEntity;
import com.mh.user.mapper.EnergyMapper;
import com.mh.user.mapper.DealDataMapper;
import com.mh.user.service.HistoryDataPreService;
import com.mh.user.service.NowDataService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -41,4 +42,20 @@ public class DealDataTest extends UserServiceApplicationTests {
List<EnergyEntity> list = energyMapper.queryEnergyMonth("2-3", "2023-03", "2023-03", 1, 10);
System.out.println(list);
}
@Autowired
private HistoryDataPreService historyDataPreService;
@Test
public void testPre() {
try {
// 训练数据
historyDataPreService.startTrainData("21");
// 预测数据
historyDataPreService.startPredictData("21", "2024-05-15");
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}

Loading…
Cancel
Save