趋势图后台接口提交

This commit is contained in:
zhanghan11 2024-04-09 14:18:18 +08:00
parent 076e8721e0
commit 6cdd1daecb
3 changed files with 26 additions and 8 deletions

View File

@ -76,7 +76,7 @@ public class IpcDataLogController extends BaseController {
*/
@PreAuthorize("@ss.hasPermi('ipc:dataShow:query')")
@GetMapping(value = "/getTendencyData")
public AjaxResult getTendencyData(@RequestBody IpcQueryParams ipcQueryParams) {
public AjaxResult getTendencyData(IpcQueryParams ipcQueryParams) {
return AjaxResult.success(iIpcDataLogService.getTendencyData(ipcQueryParams));
}
}

View File

@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
@ -71,19 +72,32 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService {
long intervalHours = ChronoUnit.HOURS.between(stime, etime);
List<Map<String, Object>> list = new ArrayList<>();
if (intervalHours <= 6) {//6小时内全查
list = selectDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime);
list = selectDataByParamNameandDate(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime);
} else if (intervalHours <= 7 * 24) {//7天内每30s一个
list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "30s");
list = selectLongTimeDataByParamNameandDate(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "30s");
} else if (intervalHours <= 30 * 24) {//30天内每2min一个
list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "2m");
list = selectLongTimeDataByParamNameandDate(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "2m");
} else if (intervalHours <= 90 * 24) {//90天以上每4h一个
list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "6m");
list = selectLongTimeDataByParamNameandDate(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "6m");
}
Map<String, Object> resMap = new HashMap<>();
if (list.size() == 0) {
return null;
}
List<Object> paramList = new ArrayList<>();
List<String> timelist = new ArrayList<>();
String param = ipcQueryParams.getParam();
if (intervalHours > 6) {
param = "mean";
}
for (Map<String, Object> data : list) {
paramList.add(data.get(param));
LocalDateTime time = InfluxdbTimeUtil.utcToCst(data.get("time").toString());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
timelist.add(time.format(formatter));
}
map.put("y", paramList);
map.put("x", timelist);
return map;
}
@ -98,7 +112,8 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService {
* @return 数据
*/
private List<Map<String, Object>> selectDataByParamNameandDate(String tableName, String part, String param, String startTime, String endTime) {
String sql = "select time," + param + " from " + tableName + " where part = '" + part + "' time >= '" + startTime + "' and time <= '" + endTime + "'";
String sql = "select time," + param + " from " + tableName + " where part = '" + part + "' and time >= '" + startTime + "' and time <= '" + endTime + "'";
System.out.println(sql);
return influxDBService.queryResultProcess(influxDBService.query(sql));
}
@ -108,7 +123,8 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService {
* @return
*/
private List<Map<String, Object>> selectLongTimeDataByParamNameandDate(String tableName, String part, String param, String startTime, String endTime, String interval) {
String sql = "select time, mean(" + param + ") from " + tableName + " where part = '" + part + "' time >= '" + startTime + "' and time <= '" + endTime + "' group by time(" + interval + ")";
String sql = "select time, mean(" + param + ") from " + tableName + " where part = '" + part + "' and time >= '" + startTime + "' and time <= '" + endTime + "' group by time(" + interval + ")";
System.out.println(sql);
return influxDBService.queryResultProcess(influxDBService.query(sql));
}

View File

@ -47,11 +47,13 @@
@click="handleQuery"
>搜索</el-button>
<el-button
type="primary"
icon="el-icon-refresh"
size="mini"
@click="resetQuery"
>重置</el-button>
<el-button
type="primary"
icon="el-icon-download"
size="mini"
@click="exportData"