diff --git a/src/main/java/com/corewing/app/modules/app/AppFirmwareController.java b/src/main/java/com/corewing/app/modules/app/AppFirmwareController.java index 638a455..4aad458 100644 --- a/src/main/java/com/corewing/app/modules/app/AppFirmwareController.java +++ b/src/main/java/com/corewing/app/modules/app/AppFirmwareController.java @@ -1,12 +1,15 @@ package com.corewing.app.modules.app; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.corewing.app.common.Result; import com.corewing.app.common.annotation.CommonLog; import com.corewing.app.dto.FirmwareVersionRequest; +import com.corewing.app.entity.BizDeviceCategory; import com.corewing.app.entity.Firmware; +import com.corewing.app.service.BizDeviceCategoryService; import com.corewing.app.service.FirmwareService; import com.corewing.app.util.I18nUtil; import io.swagger.annotations.Api; @@ -15,6 +18,7 @@ import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; @@ -27,11 +31,11 @@ import java.util.List; @Validated public class AppFirmwareController { - private final FirmwareService firmwareService; + @Resource + private FirmwareService firmwareService; - public AppFirmwareController(FirmwareService firmwareService) { - this.firmwareService = firmwareService; - } + @Resource + private BizDeviceCategoryService bizDeviceCategoryService; /** * 根据ID查询固件 @@ -96,7 +100,7 @@ public class AppFirmwareController { } /** - * 根据类型查询固件版本 + * 根据类型查询固件版本 【兼容旧版APP】 * * @param firmwareType 固件类型 */ @@ -117,6 +121,35 @@ public class AppFirmwareController { return Result.success(list); } + /** + * 根据类型查询固件版本 【兼容新版APP】 + * + * @param firmwareType 固件类型 + */ + @CommonLog("根据类型,型号查询固件版本") + @ApiOperation("根据类型,型号查询固件版本") + @GetMapping("/type/{firmwareType}/{modelId}") + public Result> listByType(@PathVariable Integer firmwareType, @PathVariable Integer modelId) { + if (firmwareType == null && modelId == null) { + return Result.error(I18nUtil.getMessage("firmware.type.or.model.required")); + } + + LambdaQueryWrapper categoryQueryWrapper = new LambdaQueryWrapper<>(); + categoryQueryWrapper.eq(BizDeviceCategory::getModelId, modelId); + BizDeviceCategory bizDeviceCategory = bizDeviceCategoryService.getOne(categoryQueryWrapper); + if(bizDeviceCategory == null) { + return Result.error(I18nUtil.getMessage("firmware.device.not.found")); + } + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Firmware::getFirmwareType, firmwareType); + wrapper.eq(Firmware::getModelId, bizDeviceCategory.getId()); + // 按版本号或创建时间倒序排列,最新版本在前 + wrapper.orderByDesc(Firmware::getCreateTime); + + List list = firmwareService.list(wrapper); + return Result.success(list); + } /** * 校验是否存在新固件 diff --git a/src/main/resources/i18n/messages_en_US.properties b/src/main/resources/i18n/messages_en_US.properties index 55ec8c1..13c1821 100644 --- a/src/main/resources/i18n/messages_en_US.properties +++ b/src/main/resources/i18n/messages_en_US.properties @@ -144,3 +144,5 @@ firmware.update.success=Firmware updated successfully firmware.update.failed=Failed to update firmware firmware.not.found=Firmware not found firmware.type.required=Firmware type is required +firmware.type.or.model.required=Firmware type or model is required +firmware.device.not.found=Device not found diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index ff4bab7..16f2ef2 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -144,3 +144,5 @@ firmware.update.success=固件更新成功 firmware.update.failed=固件更新失败 firmware.not.found=固件不存在 firmware.type.required=固件类型不能为空 +firmware.type.or.model.required=固件类型或型号不能为空 +firmware.device.not.found=设备不存在