feat(ems): 添加查询指定表最新N条记录功能并优化数据字典查询

- 在 RecordIotenvInstantMapper 中添加 selectLatestRecordsFromTable 方法
- 在 RecordIotenvInstantMapper.xml 中实现该方法的 SQL 语句
- 在 RuoYiApplication 中启用定时任务调度
- 优化 SysDictTypeMapper.xml 中的字典类型查询 SQL,top(1)是SQL server独有的,现在是TiDB(兼容MySQL)
boardTest
zch 1 month ago
parent b799cd5a7c
commit 359f7a1eb3

@ -3,6 +3,7 @@ package com.os;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
* *
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
* @author ruoyi * @author ruoyi
*/ */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableScheduling
public class RuoYiApplication public class RuoYiApplication
{ {
public static void main(String[] args) public static void main(String[] args)

@ -115,4 +115,13 @@ public interface RecordIotenvInstantMapper
*/ */
int countFromTables(@Param("tableNames") List<String> tableNames, @Param("recordIotenvInstant") RecordIotenvInstant recordIotenvInstant); int countFromTables(@Param("tableNames") List<String> tableNames, @Param("recordIotenvInstant") RecordIotenvInstant recordIotenvInstant);
/**
* N
*
* @param tableName
* @param limit
* @return
*/
public List<RecordIotenvInstant> selectLatestRecordsFromTable(@Param("tableName") String tableName,
@Param("limit") int limit);
} }

@ -296,4 +296,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) AS total_count ) AS total_count
</select> </select>
<!-- 从指定表查询最新的N条记录 -->
<select id="selectLatestRecordsFromTable" resultMap="RecordIotenvInstantResult">
SELECT objid, monitorId, temperature, humidity, illuminance, noise, concentration,
vibration_speed, vibration_displacement, vibration_acceleration, vibration_temp,
collectTime, recodeTime
FROM ${tableName}
ORDER BY objid DESC
LIMIT #{limit}
</select>
</mapper> </mapper>

@ -58,9 +58,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult"> <select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult">
select top(1) dict_id, dict_name, dict_type, status, create_by, create_time, remark select dict_id, dict_name, dict_type, status, create_by, create_time, remark
from sys_dict_type from sys_dict_type
where dict_type = #{dictType} where dict_type = #{dictType}
LIMIT 1
</select> </select>
<delete id="deleteDictTypeById" parameterType="Long"> <delete id="deleteDictTypeById" parameterType="Long">

Loading…
Cancel
Save