Commit 0302ebee9915bc6abb3435c11df47dff57b9bbc9
1 parent
6e1ec8b3
refactor(iot): 优化 OTA 升级记录查询方法
- 重写 getOtaUpgradeRecordCount 和 getOtaUpgradeRecordStatistics 方法,使用 MyBatis-Plus 的 LambdaQueryWrapperX -移除 XML 中对应的 SQL 查询语句 - 提高代码可维护性和数据库兼容性
Showing
2 changed files
with
15 additions
and
22 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeRecordMapper.java
| @@ -13,6 +13,7 @@ import org.apache.ibatis.annotations.Param; | @@ -13,6 +13,7 @@ import org.apache.ibatis.annotations.Param; | ||
| 13 | import java.util.List; | 13 | import java.util.List; |
| 14 | 14 | ||
| 15 | // TODO @li:这里的注释,可以去掉哈,多了点点 | 15 | // TODO @li:这里的注释,可以去掉哈,多了点点 |
| 16 | + | ||
| 16 | /** | 17 | /** |
| 17 | * OTA 升级记录 Mapper 接口 | 18 | * OTA 升级记录 Mapper 接口 |
| 18 | */ | 19 | */ |
| @@ -43,9 +44,14 @@ public interface IotOtaUpgradeRecordMapper extends BaseMapperX<IotOtaUpgradeReco | @@ -43,9 +44,14 @@ public interface IotOtaUpgradeRecordMapper extends BaseMapperX<IotOtaUpgradeReco | ||
| 43 | * @param status 状态,用于筛选特定状态的升级记录 | 44 | * @param status 状态,用于筛选特定状态的升级记录 |
| 44 | * @return 返回符合条件的OTA升级记录的数量 | 45 | * @return 返回符合条件的OTA升级记录的数量 |
| 45 | */ | 46 | */ |
| 46 | - Long getOtaUpgradeRecordCount(@Param("taskId") Long taskId, | ||
| 47 | - @Param("deviceName") String deviceName, | ||
| 48 | - @Param("status") Integer status); | 47 | + default Long getOtaUpgradeRecordCount(@Param("taskId") Long taskId, |
| 48 | + @Param("deviceName") String deviceName, | ||
| 49 | + @Param("status") Integer status) { | ||
| 50 | + return selectCount(new LambdaQueryWrapperX<IotOtaUpgradeRecordDO>() | ||
| 51 | + .eqIfPresent(IotOtaUpgradeRecordDO::getTaskId, taskId) | ||
| 52 | + .likeIfPresent(IotOtaUpgradeRecordDO::getDeviceId, deviceName) | ||
| 53 | + .eqIfPresent(IotOtaUpgradeRecordDO::getStatus, status)); | ||
| 54 | + } | ||
| 49 | 55 | ||
| 50 | /** | 56 | /** |
| 51 | * 获取OTA升级记录的统计信息 | 57 | * 获取OTA升级记录的统计信息 |
| @@ -54,8 +60,12 @@ public interface IotOtaUpgradeRecordMapper extends BaseMapperX<IotOtaUpgradeReco | @@ -54,8 +60,12 @@ public interface IotOtaUpgradeRecordMapper extends BaseMapperX<IotOtaUpgradeReco | ||
| 54 | * @param status 状态,用于筛选特定状态的升级记录 | 60 | * @param status 状态,用于筛选特定状态的升级记录 |
| 55 | * @return 返回符合条件的OTA升级记录的统计信息 | 61 | * @return 返回符合条件的OTA升级记录的统计信息 |
| 56 | */ | 62 | */ |
| 57 | - Long getOtaUpgradeRecordStatistics(@Param("firmwareId") Long firmwareId, | ||
| 58 | - @Param("status") Integer status); | 63 | + default Long getOtaUpgradeRecordStatistics(@Param("firmwareId") Long firmwareId, |
| 64 | + @Param("status") Integer status) { | ||
| 65 | + return selectCount(new LambdaQueryWrapperX<IotOtaUpgradeRecordDO>() | ||
| 66 | + .eqIfPresent(IotOtaUpgradeRecordDO::getFirmwareId, firmwareId) | ||
| 67 | + .eqIfPresent(IotOtaUpgradeRecordDO::getStatus, status)); | ||
| 68 | + } | ||
| 59 | 69 | ||
| 60 | 70 | ||
| 61 | /** | 71 | /** |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/ota/IotOtaUpgradeRecordMapper.xml
| @@ -4,21 +4,4 @@ | @@ -4,21 +4,4 @@ | ||
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 5 | <mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaUpgradeRecordMapper"> | 5 | <mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaUpgradeRecordMapper"> |
| 6 | 6 | ||
| 7 | - <!-- TODO @li:看看是不是可以通过 mybatis plus 写哈,更好适配多 db --> | ||
| 8 | - <select id="getOtaUpgradeRecordCount" resultType="java.lang.Long"> | ||
| 9 | - select count(*) | ||
| 10 | - from iot_ota_upgrade_record | ||
| 11 | - where task_id = #{taskId} | ||
| 12 | - and device_name like concat('%', #{deviceName}, '%') | ||
| 13 | - and status = #{status} | ||
| 14 | - </select> | ||
| 15 | - | ||
| 16 | - <!-- TODO @li:看看是不是可以通过 mybatis plus 写哈,更好适配多 db --> | ||
| 17 | - <select id="getOtaUpgradeRecordStatistics" resultType="java.lang.Long"> | ||
| 18 | - select count(*) | ||
| 19 | - from iot_ota_upgrade_record | ||
| 20 | - where firmware_id = #{firmwareId} | ||
| 21 | - and status = #{status} | ||
| 22 | - </select> | ||
| 23 | - | ||
| 24 | </mapper> | 7 | </mapper> |
| 25 | \ No newline at end of file | 8 | \ No newline at end of file |