2023-07-26 10:37:06 优化完善能耗统计设备用能数据入库功能!

master
魔神煜修罗皇 2 years ago
parent fd57e46546
commit abd93e0e29
  1. 2
      psdc-admin/src/main/resources/application-dev.yml
  2. 6
      psdc-admin/src/main/resources/application-prod.yml
  3. 5
      psdc-business/src/main/java/com/psdc/mapper/PsdcStatisticsDayMapper.java
  4. 18
      psdc-business/src/main/java/com/psdc/mqtt/savedata/DataAndPowerSave.java
  5. 4
      psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java
  6. 7
      psdc-business/src/main/java/com/psdc/service/impl/PsdcElectricHtdataServiceImpl.java
  7. 1
      psdc-business/src/main/java/com/psdc/service/impl/PsdcThermometerHtdataServiceImpl.java
  8. 6
      psdc-business/src/main/resources/mapper/business/PsdcStatisticsDayMapper.xml

@ -138,7 +138,7 @@ mqtt:
#QOS等级 0, 1, 2 #QOS等级 0, 1, 2
qos: 1 qos: 1
#客户端id 必须唯一 #客户端id 必须唯一
clientId: psdcDev12356EVQ clientId: psdcDev12356HDFS
#连接超时,默认30000 #连接超时,默认30000
timeOut: 10 timeOut: 10
#心跳间隔时间,默认3000 #心跳间隔时间,默认3000

@ -54,7 +54,7 @@ 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:3306/psdc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=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: 123456 password: 123456
messages: messages:
@ -130,7 +130,7 @@ xss:
#MQTT配置 #MQTT配置
mqtt: mqtt:
#MQTT服务端地址,端口默认为1883,如果有多个,用逗号隔开,如tcp://127.0.0.1:1883,tcp://192.168.60.133:1883 #MQTT服务端地址,端口默认为1883,如果有多个,用逗号隔开,如tcp://127.0.0.1:1883, tcp://192.168.60.133:1883, tcp://39.105.213.67:1883
url: tcp://127.0.0.1:1883 url: tcp://127.0.0.1:1883
#用户名 密码 #用户名 密码
username: 1669792462840@UserName username: 1669792462840@UserName
@ -138,7 +138,7 @@ mqtt:
#QOS等级 0, 1, 2 #QOS等级 0, 1, 2
qos: 1 qos: 1
#客户端id 必须唯一 #客户端id 必须唯一
clientId: psdc@System2 clientId: psdc@System
#连接超时,默认30000 #连接超时,默认30000
timeOut: 10 timeOut: 10
#心跳间隔时间,默认3000 #心跳间隔时间,默认3000

@ -54,6 +54,11 @@ public interface PsdcStatisticsDayMapper{
*/ */
int update(PsdcStatisticsDay psdcStatisticsDay); int update(PsdcStatisticsDay psdcStatisticsDay);
Integer updateTodayDevEnergy(@Param(value = "valNo") String valNo,
@Param(value = "powerValue") Double powerValue,
@Param(value = "devId") Integer devId,
@Param(value = "samDate") String samDate);
Integer updateDay(@Param(value = "valNo") String valNo, Integer updateDay(@Param(value = "valNo") String valNo,
@Param(value = "powerValue") Double powerValue, @Param(value = "powerValue") Double powerValue,
@Param(value = "devId") Integer devId, @Param(value = "devId") Integer devId,

@ -44,10 +44,6 @@ public class DataAndPowerSave {
PsdcThermometerHtdataMapper thermometerHtDataMapper; PsdcThermometerHtdataMapper thermometerHtDataMapper;
@Resource @Resource
PsdcStatisticsDayMapper statisticsDayMapper; PsdcStatisticsDayMapper statisticsDayMapper;
@Resource
PsdcStatisticsMonthMapper statisticsMonthMapper;
@Resource
PsdcStatisticsYearMapper statisticsYearMapper;
public Boolean saveDevRtData(JSONObject jsonObject) { public Boolean saveDevRtData(JSONObject jsonObject) {
Integer deviceId = jsonObject.getInteger("deviceId"); Integer deviceId = jsonObject.getInteger("deviceId");
@ -87,7 +83,7 @@ public class DataAndPowerSave {
String valNo = "val" + countNo; String valNo = "val" + countNo;
if (deviceStatusVo != null) { if (deviceStatusVo != null) {
if (null != params.getFloat("P")) { if (null != params.getFloat("TotWh")) {
double P = params.getFloat("P"); double P = params.getFloat("P");
double TotWh = params.getFloat("TotWh"); double TotWh = params.getFloat("TotWh");
PsdcElectricRtdata pert = new PsdcElectricRtdata(); PsdcElectricRtdata pert = new PsdcElectricRtdata();
@ -120,6 +116,18 @@ public class DataAndPowerSave {
electricHtDataMapper.insert(peht); electricHtDataMapper.insert(peht);
} }
Long devCountDay = statisticsDayMapper.count(deviceId, date1);
if (devCountDay < 1){
PsdcStatisticsDay statisticsDay = new PsdcStatisticsDay();
statisticsDay.setDayDate(date1);
statisticsDay.setDeviceId(deviceId);
statisticsDay.setDeviceName(deviceStatusVo.getDeviceName());
statisticsDayMapper.insertDay(statisticsDay);
}
Double hourUse = electricHtDataMapper.selTodayUseEnergy(deviceId, begin, end);
String hourNo = "hour_" + hour;
statisticsDayMapper.updateTodayDevEnergy(hourNo, hourUse, deviceId, date1);
// 根据设备id查询设备功率表中该设备的条数 // 根据设备id查询设备功率表中该设备的条数
int count3 = devicePowerHtData96Mapper.todayPowerCount(deviceId, samDate); int count3 = devicePowerHtData96Mapper.todayPowerCount(deviceId, samDate);
// 设备有功功率入库 // 设备有功功率入库

@ -470,11 +470,11 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
i = setTemperature(deviceId, sceneCode, data, userName, 1); i = setTemperature(deviceId, sceneCode, data, userName, 1);
System.out.println("你好 (2) 世界: " + sceneCode); System.out.println("你好 (2) 世界: " + sceneCode);
String sCode = newLog.getRunSceneCodes() + sceneCode + ","; String sCode = newLog.getRunSceneCodes() + sceneCode + ",";
if (sCode.indexOf("null") >= 0){ if (sCode.contains("null")){
sCode = sCode.substring(4); sCode = sCode.substring(4);
} }
String res = newLog.getStrategyRunRes() + "2"; String res = newLog.getStrategyRunRes() + "2";
if (res.indexOf("null") >= 0){ if (res.contains("null")){
res = res.substring(4); res = res.substring(4);
} }

@ -150,19 +150,22 @@ public class PsdcElectricHtdataServiceImpl implements IPsdcElectricHtdataService
/** /**
* 每日统计定时任务 * 每日统计定时任务
*/ */
@Scheduled(cron = "0 10 0 * * ? ") @Scheduled(cron = "0 0 0 1/1 * ?") // 每天凌晨零点执行一次
@Override @Override
public void statisticalTask(){ public void statisticalTask(){
System.out.println("李雷:How are you?Jerry: I am fine and you!\n");
// 获取昨日用电量总和 // 获取昨日用电量总和
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dayDateFormat = new SimpleDateFormat("dd"); SimpleDateFormat dayDateFormat = new SimpleDateFormat("dd");
SimpleDateFormat yearMonthDateFormat = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat yearMonthDateFormat = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat monthDateFormat = new SimpleDateFormat("MM"); SimpleDateFormat monthDateFormat = new SimpleDateFormat("MM");
SimpleDateFormat yearDateFormat = new SimpleDateFormat("yyyy");
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1); calendar.add(Calendar.DATE, -1);
Date yesterday = calendar.getTime(); Date yesterday = calendar.getTime();
List<PsdcElectricHtdata> psdcElectricHtdatas = electricHtdataMapper.statisticalGroupByTime(simpleDateFormat.format(yesterday)); List<PsdcElectricHtdata> psdcElectricHtdatas = electricHtdataMapper.statisticalGroupByTime(simpleDateFormat.format(yesterday));
// 月点位 // 月点位
String monthPoint = "day_" + dayDateFormat.format(yesterday); String monthPoint = "day_" + dayDateFormat.format(yesterday);
String yearPoint = "month_" + monthDateFormat.format(yesterday); String yearPoint = "month_" + monthDateFormat.format(yesterday);
@ -187,7 +190,7 @@ public class PsdcElectricHtdataServiceImpl implements IPsdcElectricHtdataService
// 每月数据 // 每月数据
// 先查询该id今年每月数据 // 先查询该id今年每月数据
PsdcStatisticsYear psdcStatisticsYear = psdcStatisticsYearMapper.queryByDeviceIdAndDate(deviceId, yearMonthDateFormat.format(yesterday)); PsdcStatisticsYear psdcStatisticsYear = psdcStatisticsYearMapper.queryByDeviceIdAndDate(deviceId, yearDateFormat.format(yesterday));
Double aDouble = psdcStatisticsMonthMapper.queryOneLineSum(deviceId, yearMonthDateFormat.format(yesterday)); Double aDouble = psdcStatisticsMonthMapper.queryOneLineSum(deviceId, yearMonthDateFormat.format(yesterday));
if (psdcStatisticsYear == null){ if (psdcStatisticsYear == null){
// 插入 // 插入

@ -188,6 +188,7 @@ public class PsdcThermometerHtdataServiceImpl implements IPsdcThermometerHtdataS
long time1 = 0; long time1 = 0;
for (int i = 0; i < tempList.size(); i++) { for (int i = 0; i < tempList.size(); i++) {
PsdcThermometerHtdata scr1 = tempList.get(i); PsdcThermometerHtdata scr1 = tempList.get(i);
SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
long time2 = sdf4.parse(scr1.getUpdateTime()).getTime(); long time2 = sdf4.parse(scr1.getUpdateTime()).getTime();
long time3 = time2 - time1; long time3 = time2 - time1;
if(time3 >= 900000){ if(time3 >= 900000){

@ -66,6 +66,12 @@
</insert> </insert>
<update id="updateTodayDevEnergy">
Update psdc_statistics_day Set ${valNo} = #{powerValue}
Where device_id = #{devId} And day_date = #{samDate}
</update>
<insert id="insertDay" > <insert id="insertDay" >
Insert into psdc_statistics_day( Insert into psdc_statistics_day(
day_date, day_date,

Loading…
Cancel
Save