修改固件类型字段
This commit is contained in:
@@ -23,68 +23,6 @@ public class FirmwareController {
|
|||||||
this.firmwareService = firmwareService;
|
this.firmwareService = firmwareService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增固件
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public Result<String> add(@RequestBody Firmware firmware) {
|
|
||||||
try {
|
|
||||||
// 检查固件名称是否已存在
|
|
||||||
Firmware existFirmware = firmwareService.getByFirmwareName(firmware.getFirmwareName());
|
|
||||||
if (existFirmware != null) {
|
|
||||||
return Result.error(I18nUtil.getMessage("firmware.name.exists"));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean success = firmwareService.save(firmware);
|
|
||||||
if (success) {
|
|
||||||
return Result.success(I18nUtil.getMessage("firmware.add.success"));
|
|
||||||
}
|
|
||||||
return Result.error(I18nUtil.getMessage("firmware.add.failed"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除固件
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public Result<String> delete(@PathVariable Long id) {
|
|
||||||
try {
|
|
||||||
boolean success = firmwareService.removeById(id);
|
|
||||||
if (success) {
|
|
||||||
return Result.success(I18nUtil.getMessage("firmware.delete.success"));
|
|
||||||
}
|
|
||||||
return Result.error(I18nUtil.getMessage("firmware.delete.failed"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新固件
|
|
||||||
*/
|
|
||||||
@PutMapping
|
|
||||||
public Result<String> update(@RequestBody Firmware firmware) {
|
|
||||||
try {
|
|
||||||
// 检查固件名称是否与其他固件重复
|
|
||||||
if (StringUtils.hasText(firmware.getFirmwareName())) {
|
|
||||||
Firmware existFirmware = firmwareService.getByFirmwareName(firmware.getFirmwareName());
|
|
||||||
if (existFirmware != null && !existFirmware.getId().equals(firmware.getId())) {
|
|
||||||
return Result.error(I18nUtil.getMessage("firmware.name.exists"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean success = firmwareService.updateById(firmware);
|
|
||||||
if (success) {
|
|
||||||
return Result.success(I18nUtil.getMessage("firmware.update.success"));
|
|
||||||
}
|
|
||||||
return Result.error(I18nUtil.getMessage("firmware.update.failed"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询固件
|
* 根据ID查询固件
|
||||||
*/
|
*/
|
||||||
@@ -140,4 +78,24 @@ public class FirmwareController {
|
|||||||
java.util.List<Firmware> list = firmwareService.list();
|
java.util.List<Firmware> list = firmwareService.list();
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型查询固件版本
|
||||||
|
*
|
||||||
|
* @param firmwareType 固件类型
|
||||||
|
*/
|
||||||
|
@GetMapping("/type/{firmwareType}")
|
||||||
|
public Result<java.util.List<Firmware>> listByType(@PathVariable Integer firmwareType) {
|
||||||
|
if (firmwareType == null) {
|
||||||
|
return Result.error(I18nUtil.getMessage("firmware.type.required"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryWrapper<Firmware> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("firmware_type", firmwareType);
|
||||||
|
// 按版本号或创建时间倒序排列,最新版本在前
|
||||||
|
wrapper.orderByDesc("create_time");
|
||||||
|
|
||||||
|
java.util.List<Firmware> list = firmwareService.list(wrapper);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Firmware implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 固件类型
|
* 固件类型
|
||||||
*/
|
*/
|
||||||
private String firmwareType;
|
private Integer firmwareType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 固件下载地址
|
* 固件下载地址
|
||||||
|
|||||||
@@ -140,3 +140,4 @@ firmware.delete.failed=Failed to delete firmware
|
|||||||
firmware.update.success=Firmware updated successfully
|
firmware.update.success=Firmware updated successfully
|
||||||
firmware.update.failed=Failed to update firmware
|
firmware.update.failed=Failed to update firmware
|
||||||
firmware.not.found=Firmware not found
|
firmware.not.found=Firmware not found
|
||||||
|
firmware.type.required=Firmware type is required
|
||||||
|
|||||||
@@ -140,3 +140,4 @@ firmware.delete.failed=固件删除失败
|
|||||||
firmware.update.success=固件更新成功
|
firmware.update.success=固件更新成功
|
||||||
firmware.update.failed=固件更新失败
|
firmware.update.failed=固件更新失败
|
||||||
firmware.not.found=固件不存在
|
firmware.not.found=固件不存在
|
||||||
|
firmware.type.required=固件类型不能为空
|
||||||
|
|||||||
Reference in New Issue
Block a user