Browse Source

1、优化能耗处理:时间匹配函数不对等问题;

dev
mh 2 weeks ago
parent
commit
225d2bb291
  1. 24
      mh-admin/src/test/java/com/mh/MHApplicationTest.java
  2. 3
      mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java
  3. 1
      mh-quartz/src/main/java/com/mh/quartz/task/DealDataTask.java
  4. 18
      mh-system/src/main/java/com/mh/system/mapper/device/DataProcessMapper.java

24
mh-admin/src/test/java/com/mh/MHApplicationTest.java

@ -2,6 +2,7 @@ package com.mh;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.mh.common.core.domain.entity.DeviceReport;
import com.mh.common.core.domain.entity.SysParams;
import com.mh.common.core.domain.entity.SysUser;
import com.mh.common.core.domain.entity.WeatherData;
@ -9,6 +10,7 @@ import com.mh.common.utils.DateUtils;
import com.mh.common.utils.StringUtils;
import com.mh.quartz.task.DealDataTask;
import com.mh.quartz.task.GetWeatherDataTask;
import com.mh.system.mapper.device.DataProcessMapper;
import com.mh.system.service.ISysParamsService;
import com.mh.system.service.ISysUserService;
import com.mh.system.service.device.IDeviceQrManageService;
@ -92,4 +94,26 @@ public class MHApplicationTest {
// }
// }
}
@Autowired
private DataProcessMapper dataProcessMapper;
@Test
public void insertDataHour() {
DeviceReport data = new DeviceReport();
data.setId(315286L);
data.setDeviceNum("39001260");
data.setDeviceCode("39001260");
data.setDeviceType("5");
data.setLastValue("388063.97");
data.setLastTime(DateUtils.stringToDate("2025-04-19 10:00:00", "yyyy-MM-dd HH:mm:ss"));
data.setCurTime(DateUtils.stringToDate("2025-04-19 10:00:00", "yyyy-MM-dd HH:mm:ss"));
data.setCurValue("388063.99");
data.setUsedValue("0.02");
data.setCalcValue("0.02");
data.setRatio(1);
data.setGrade(0);
System.out.println(data);
dataProcessMapper.insertTable(data, "data_hour2025");
}
}

3
mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java

@ -422,6 +422,9 @@ public class DataProcessServiceImpl implements DataProcessService {
case "hour":
tableName = tableName + DateUtils.dateToString(data.getCurTime(), "yyyy");
num = dataProcessMapper.selectDataByHH(tableName, data.getCurTime(), data.getDeviceNum());
if (num == 0) {
log.info("插入小时数据:{}", data.toString());
}
break;
}
if (num == 0) {

1
mh-quartz/src/main/java/com/mh/quartz/task/DealDataTask.java

@ -272,6 +272,7 @@ public class DealDataTask {
.sorted(Comparator.comparing(temMap -> temMap.keySet().iterator().next()))
.collect(Collectors.toList());
//计算上次值,当前值
log.info("计算小时表数据:{}", sortedList);
hourList = calcListData(hourList, key, "hour", sortedList);
}
//批量插入小时报表

18
mh-system/src/main/java/com/mh/system/mapper/device/DataProcessMapper.java

@ -104,16 +104,16 @@ public interface DataProcessMapper {
@Select("select * from ${tableName} where grade = 0 order by cur_time desc")
List<DeviceReport> queryUntreatedData(String tableName);
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and EXTRACT(YEAR FROM AGE(cur_time, #{curTime})) = 0;")
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and EXTRACT(YEAR FROM cur_time) = EXTRACT(YEAR FROM #{curTime}::timestamp);")
Integer selectDataByYY(@Param("tableName") String tableName,@Param("curTime") Date curTime,@Param("deviceNum")String deviceNum);
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and EXTRACT(MONTH FROM AGE(cur_time, #{curTime})) = 0;")
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and DATE_TRUNC('month', cur_time) = DATE_TRUNC('month', #{curTime}::timestamp);")
Integer selectDataByMM(@Param("tableName") String tableName,@Param("curTime") Date curTime,@Param("deviceNum")String deviceNum);
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and EXTRACT(DAY FROM AGE(cur_time, #{curTime})) = 0;")
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and DATE(cur_time) = DATE(#{curTime}::timestamp)")
Integer selectDataByDD(@Param("tableName") String tableName,@Param("curTime") Date curTime,@Param("deviceNum")String deviceNum);
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and EXTRACT(HOUR FROM AGE(cur_time, #{curTime})) = 0; ")
@Select("select count(1) from ${tableName} where device_num = #{deviceNum} and DATE_TRUNC('hour', cur_time) = DATE_TRUNC('hour', #{curTime}::timestamp); ")
Integer selectDataByHH(@Param("tableName") String tableName,@Param("curTime") Date curTime,@Param("deviceNum")String deviceNum);
@Insert("insert into ${tableName}(device_num, device_code, device_type, last_value, last_time, cur_value,cur_time,calc_value,used_value,ratio,grade) " +
@ -132,19 +132,19 @@ public interface DataProcessMapper {
void insertTable(@Param("data") DeviceReport data, @Param("tableName") String tableName);
@Update("update ${tableName} set cur_time = #{data.curTime},cur_value = #{data.curValue}::numeric,calc_value = (#{data.curValue}::numeric - last_value)*ratio,used_value = #{data.curValue}::numeric - last_value " +
"where device_num = #{data.deviceNum} and EXTRACT(MONTH FROM AGE(cur_time, #{data.curTime})) = 0 ")
"where device_num = #{data.deviceNum} and DATE_TRUNC('month', cur_time) = DATE_TRUNC('month', #{data.curTime}::timestamp); ")
void updateTableMM(@Param("data") DeviceReport data, @Param("tableName") String tableName);
@Update("update ${tableName} set cur_time = #{data.curTime},cur_value = #{data.curValue}::numeric,calc_value = (#{data.curValue}::numeric - last_value)*ratio,used_value = #{data.curValue}::numeric - last_value " +
"where device_num = #{data.deviceNum} and EXTRACT(YEAR FROM AGE(cur_time, #{data.curTime})) = 0 ")
"where device_num = #{data.deviceNum} and EXTRACT(YEAR FROM cur_time) = EXTRACT(YEAR FROM #{data.curTime}::timestamp); ")
void updateTableYY(@Param("data") DeviceReport data, @Param("tableName") String tableName);
@Update("update ${tableName} set cur_time = #{data.curTime},cur_value = #{data.curValue}::numeric,calc_value = (#{data.curValue}::numeric - last_value)*ratio,used_value = #{data.curValue}::numeric - last_value " +
"where device_num = #{data.deviceNum} and EXTRACT(DAY FROM AGE(cur_time, #{data.curTime})) = 0 ")
"where device_num = #{data.deviceNum} and DATE(cur_time) = DATE(#{data.curTime}::timestamp) ")
void updateTableDD(@Param("data") DeviceReport data, @Param("tableName") String tableName);
@Update("update ${tableName} set cur_time = #{data.curTime},cur_value = #{data.curValue}::numeric,calc_value = (#{data.curValue}::numeric - last_value)*ratio,used_value = #{data.curValue}::numeric - last_value " +
"where device_num = #{data.deviceNum} and EXTRACT(HOUR FROM AGE(cur_time, #{data.curTime})) = 0 ")
"where device_num = #{data.deviceNum} and DATE_TRUNC('hour', cur_time) = DATE_TRUNC('hour', #{data.curTime}::timestamp); ")
void updateTableHH(@Param("data") DeviceReport data, @Param("tableName") String tableName);
/**
@ -155,7 +155,7 @@ public interface DataProcessMapper {
* @param grade
*/
@Update("<script>" +
"update ${tableName} set grade = #{grade} where Id in(" +
"update ${tableName} set grade = #{grade} where id in(" +
"<foreach collection ='ids' item='id' index = 'index' separator=','>" +
"#{id}" +
"</foreach>" +

Loading…
Cancel
Save