feat: 把采集到的数据保存或更新到data表

dev
huangfeng 8 months ago
parent cb4d2fc1e8
commit 87f544707a

@ -21,4 +21,6 @@ public interface DataService {
List<Map<String, Object>> getLatestData(NSensor sensor, List<ModevTypePoint> points, Date start) throws Exception;
Map<String, Object> getLastOneData(NSensor sensor, ModevTypePoint point) throws Exception;
void insertData(String tableName, Integer eqmid, String time, String colname, String value);
}

@ -272,5 +272,24 @@ public class DataServiceImpl implements DataService {
}
}
@Override
public void insertData(String tableName, Integer eqmid, String time, String colname, String value) {
String devField = DataTable.getDevidField(tableName);
String timeField = this.getTimeField(tableName);
String sqlFrom = " FROM " + tableName;
String sqlWhere = " WHERE " + devField + "=" + eqmid + " AND " + timeField + " = '" + time + "'";
String sqlCount = "SELECT count(*)" + sqlFrom + sqlWhere;
Long count = jdbcTemplate.queryForObject(sqlCount, Long.class);
if (count > 0) {
String sql = "UPDATE " + tableName + " set " + colname + "=" + value
+ sqlWhere;
jdbcTemplate.execute(sql);
} else {
String sql = "INSERT INTO " + tableName + " (" + devField + ", " + timeField + "," + colname
+ ") VALUES (" + eqmid + ", '" + time + "', " + value + ")";
jdbcTemplate.execute(sql);
}
}
}

@ -3,6 +3,7 @@ package com.xydl.cac.task;
import com.xydl.cac.entity.*;
import com.xydl.cac.iec.IecClient;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.DataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@ -27,6 +28,8 @@ public class Client61850Task {
IcdConfigTypeInstRepository instRepository;
@Resource
RptparamindexRepository rptparamindexRepository;
@Resource
DataService dataService;
@Scheduled(cron = "0 30 * * * ?")
public void collectAll() {
@ -90,12 +93,10 @@ public class Client61850Task {
}
private void getOneValue(String paramindexNew, String paramindexT, String fc, Rptparamindex rpt, IecClient iecClient) throws Exception {
String value = iecClient.getValue(paramindexNew, fc);
log.info(paramindexNew + "=" + value);
String time = iecClient.getValue(paramindexT, fc);
log.info(paramindexT + "=" + time);
time = time.replace("T", " ").replace("Z", "").replace("z", "");
dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value);
}
}

Loading…
Cancel
Save