场景化配置:根据配置动态获取设备数据TDengine增加接口
master
xs 2 weeks ago
parent e0d09a4685
commit afddf2994e

@ -529,4 +529,43 @@ public class TdEngineController {
return R.fail(message);
}
}
/**
* @param tdGroupSelectDto
* @return R<?>
* @MethodDescription 1s,1m,1d,1w,30d
* SELECT _WSTART as time, _WEND,max(value1) as maxValue,min(value1) as minValue,avg(value1) as avgValue,sum(value1) as sumValue from db_hwsaas.t_device_260
* where ts>=now-10d and ts<now interval(1d) order by time
*/
@InnerAuth
@PostMapping("/getGroupDeviceData")
public R<?> getGroupDeviceData(@Validated @RequestBody TdGroupSelectDto tdGroupSelectDto) {
try {
// if (selectVisualDto.getType() == 0) {//查询历史
// return R.ok(this.tdEngineService.getHistoryData(selectVisualDto));
// }else if(selectVisualDto.getType() == 1) {//查询实时
// return R.ok(this.tdEngineService.getRealtimeData(selectVisualDto));
// }else {//查询聚合
// return R.ok(this.tdEngineService.getAggregateData(selectVisualDto));
// }
TdReturnDataVo returnDataVo = new TdReturnDataVo();
returnDataVo.setDataList(this.tdEngineService.getGroupDeviceData(tdGroupSelectDto));
return R.ok(returnDataVo);
} catch (UncategorizedSQLException e) {
String message = e.getCause().getMessage();
try {
message = message.substring(message.lastIndexOf("invalid operation"));
} catch (Exception ex) {
}
log.error(message);
return R.fail(message);
} catch (Exception e) {
log.error(e.getMessage());
return R.fail(e.getMessage());
}
}
}

@ -165,6 +165,17 @@ public interface TdEngineMapper {
Map<String, Object> getDeviceLocation(TdSelectDto tdSelectDto);
/**
* @return List<Map < Object>>
* @param: tdGroupSelectDto
* @description
* @author xins
* @date 2024-12-31 16:11
*/
List<Map<String, Object>> getGroupDeviceData(TdGroupSelectDto tdGroupSelectDto);
// /**
// * 检查表是否存在
// * @param dataBaseName

@ -142,6 +142,16 @@ public interface ITdEngineService {
*/
public void dropTable(String databaseName, String tableName) throws Exception;
/**
* @return List<Map < Object>>
* @param: tdGroupSelectDto
* @description
* @author xins
* @date 2023-08-29 15:52
*/
public List<Map<String, Object>> getGroupDeviceData(TdGroupSelectDto tdGroupSelectDto);
Map<String,Object> getDeviceLocation(TdSelectDto tdSelectDto);
// void initSTableFrame(String msg) throws Exception;

@ -261,6 +261,28 @@ public class TdEngineServiceImpl implements ITdEngineService {
}
/**
* @return List<Map < Object>>
* @param: tdGroupSelectDto
* @description
* @author xins
* @date 2023-08-29 15:52
*/
@Override
public List<Map<String, Object>> getGroupDeviceData(TdGroupSelectDto tdGroupSelectDto) {
// if (StringUtils.isBlank(tdHistorySelectDto.getOrderByFieldName())) {
// tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
// }
// if (StringUtils.isBlank(tdHistorySelectDto.getOrderByMode())) {
// tdHistorySelectDto.setOrderByMode(TdEngineConstants.DEFAULT_ORDER_BY_MODE);
// }
List<Map<String, Object>> groupDataMaps = this.tdEngineMapper.getGroupDeviceData(tdGroupSelectDto);
return groupDataMaps;
}
//
// /**
// * 检查数据库表是否存在

@ -319,6 +319,19 @@
drop table #{databaseName}.#{tableName}
</update>
<select id="getGroupDeviceData" parameterType="com.ruoyi.tdengine.api.domain.TdHistorySelectDto" resultType="java.util.Map" >
SELECT _WSTART as time, _WEND,max(${functionIdentifier}) as maxValue,min(${functionIdentifier}) as minValue,avg(${functionIdentifier}) as avgValue,sum(${functionIdentifier}) as sumValue
FROM #{databaseName}.#{tableName}
where ${firstFieldName} &gt;= #{startTime}
and ${firstFieldName} &lt;= #{endTime}
interval(#{interval}) order by time
<if test="offset != null and limit != 0 ">
LIMIT #{offset},#{limit}
</if>
</select>
<!--
<select id="checkTableExists" resultType="java.lang.Integer">
SELECT COUNT(0) FROM #{dataBaseName}.#{tableName}

Loading…
Cancel
Save