refactor(iot): 优化 OTA 升级记录查询方法
- 重写 getOtaUpgradeRecordCount 和 getOtaUpgradeRecordStatistics 方法,使用 MyBatis-Plus 的 LambdaQueryWrapperX -移除 XML 中对应的 SQL 查询语句 - 提高代码可维护性和数据库兼容性
This commit is contained in:
parent
6e1ec8b3eb
commit
0302ebee99
|
@ -13,6 +13,7 @@ import org.apache.ibatis.annotations.Param;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// TODO @li:这里的注释,可以去掉哈,多了点点
|
// TODO @li:这里的注释,可以去掉哈,多了点点
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OTA 升级记录 Mapper 接口
|
* OTA 升级记录 Mapper 接口
|
||||||
*/
|
*/
|
||||||
|
@ -43,9 +44,14 @@ public interface IotOtaUpgradeRecordMapper extends BaseMapperX<IotOtaUpgradeReco
|
||||||
* @param status 状态,用于筛选特定状态的升级记录
|
* @param status 状态,用于筛选特定状态的升级记录
|
||||||
* @return 返回符合条件的OTA升级记录的数量
|
* @return 返回符合条件的OTA升级记录的数量
|
||||||
*/
|
*/
|
||||||
Long getOtaUpgradeRecordCount(@Param("taskId") Long taskId,
|
default Long getOtaUpgradeRecordCount(@Param("taskId") Long taskId,
|
||||||
@Param("deviceName") String deviceName,
|
@Param("deviceName") String deviceName,
|
||||||
@Param("status") Integer status);
|
@Param("status") Integer status) {
|
||||||
|
return selectCount(new LambdaQueryWrapperX<IotOtaUpgradeRecordDO>()
|
||||||
|
.eqIfPresent(IotOtaUpgradeRecordDO::getTaskId, taskId)
|
||||||
|
.likeIfPresent(IotOtaUpgradeRecordDO::getDeviceId, deviceName)
|
||||||
|
.eqIfPresent(IotOtaUpgradeRecordDO::getStatus, status));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取OTA升级记录的统计信息
|
* 获取OTA升级记录的统计信息
|
||||||
|
@ -54,8 +60,12 @@ public interface IotOtaUpgradeRecordMapper extends BaseMapperX<IotOtaUpgradeReco
|
||||||
* @param status 状态,用于筛选特定状态的升级记录
|
* @param status 状态,用于筛选特定状态的升级记录
|
||||||
* @return 返回符合条件的OTA升级记录的统计信息
|
* @return 返回符合条件的OTA升级记录的统计信息
|
||||||
*/
|
*/
|
||||||
Long getOtaUpgradeRecordStatistics(@Param("firmwareId") Long firmwareId,
|
default Long getOtaUpgradeRecordStatistics(@Param("firmwareId") Long firmwareId,
|
||||||
@Param("status") Integer status);
|
@Param("status") Integer status) {
|
||||||
|
return selectCount(new LambdaQueryWrapperX<IotOtaUpgradeRecordDO>()
|
||||||
|
.eqIfPresent(IotOtaUpgradeRecordDO::getFirmwareId, firmwareId)
|
||||||
|
.eqIfPresent(IotOtaUpgradeRecordDO::getStatus, status));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,21 +4,4 @@
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaUpgradeRecordMapper">
|
<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaUpgradeRecordMapper">
|
||||||
|
|
||||||
<!-- TODO @li:看看是不是可以通过 mybatis plus 写哈,更好适配多 db -->
|
|
||||||
<select id="getOtaUpgradeRecordCount" resultType="java.lang.Long">
|
|
||||||
select count(*)
|
|
||||||
from iot_ota_upgrade_record
|
|
||||||
where task_id = #{taskId}
|
|
||||||
and device_name like concat('%', #{deviceName}, '%')
|
|
||||||
and status = #{status}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- TODO @li:看看是不是可以通过 mybatis plus 写哈,更好适配多 db -->
|
|
||||||
<select id="getOtaUpgradeRecordStatistics" resultType="java.lang.Long">
|
|
||||||
select count(*)
|
|
||||||
from iot_ota_upgrade_record
|
|
||||||
where firmware_id = #{firmwareId}
|
|
||||||
and status = #{status}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue