【新增】固件版本升级校验
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
package com.corewing.app.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FirmwareVersionRequest {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "型号id", required = true)
|
||||||
|
@NotNull(message = "型号不能为空")
|
||||||
|
private Integer modelId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "版本号", required = true)
|
||||||
|
@NotNull(message = "版本号不能为空")
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "固件类型", required = true)
|
||||||
|
@NotNull(message = "固件类型不能为空")
|
||||||
|
private Integer firmwareType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -45,6 +45,21 @@ public class Firmware implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer firmwareType;
|
private Integer firmwareType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型id
|
||||||
|
*/
|
||||||
|
private String modelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本校验id
|
||||||
|
*/
|
||||||
|
private Integer versionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本号
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 固件下载地址
|
* 固件下载地址
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,20 +5,26 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.corewing.app.common.Result;
|
import com.corewing.app.common.Result;
|
||||||
import com.corewing.app.common.annotation.CommonLog;
|
import com.corewing.app.common.annotation.CommonLog;
|
||||||
|
import com.corewing.app.dto.FirmwareVersionRequest;
|
||||||
import com.corewing.app.entity.Firmware;
|
import com.corewing.app.entity.Firmware;
|
||||||
import com.corewing.app.service.FirmwareService;
|
import com.corewing.app.service.FirmwareService;
|
||||||
import com.corewing.app.util.I18nUtil;
|
import com.corewing.app.util.I18nUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 固件 Controller
|
* 固件 Controller
|
||||||
*/
|
*/
|
||||||
@Api(tags = "固件接口")
|
@Api(tags = "固件接口")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/firmware")
|
@RequestMapping("/firmware")
|
||||||
|
@Validated
|
||||||
public class AppFirmwareController {
|
public class AppFirmwareController {
|
||||||
|
|
||||||
private final FirmwareService firmwareService;
|
private final FirmwareService firmwareService;
|
||||||
@@ -84,8 +90,8 @@ public class AppFirmwareController {
|
|||||||
@CommonLog("查询所有固件集合")
|
@CommonLog("查询所有固件集合")
|
||||||
@ApiOperation("查询所有固件集合")
|
@ApiOperation("查询所有固件集合")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Result<java.util.List<Firmware>> list() {
|
public Result<List<Firmware>> list() {
|
||||||
java.util.List<Firmware> list = firmwareService.list();
|
List<Firmware> list = firmwareService.list();
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +103,7 @@ public class AppFirmwareController {
|
|||||||
@CommonLog("根据类型查询固件版本")
|
@CommonLog("根据类型查询固件版本")
|
||||||
@ApiOperation("根据类型查询固件版本")
|
@ApiOperation("根据类型查询固件版本")
|
||||||
@GetMapping("/type/{firmwareType}")
|
@GetMapping("/type/{firmwareType}")
|
||||||
public Result<java.util.List<Firmware>> listByType(@PathVariable Integer firmwareType) {
|
public Result<List<Firmware>> listByType(@PathVariable Integer firmwareType) {
|
||||||
if (firmwareType == null) {
|
if (firmwareType == null) {
|
||||||
return Result.error(I18nUtil.getMessage("firmware.type.required"));
|
return Result.error(I18nUtil.getMessage("firmware.type.required"));
|
||||||
}
|
}
|
||||||
@@ -107,7 +113,19 @@ public class AppFirmwareController {
|
|||||||
// 按版本号或创建时间倒序排列,最新版本在前
|
// 按版本号或创建时间倒序排列,最新版本在前
|
||||||
wrapper.orderByDesc("create_time");
|
wrapper.orderByDesc("create_time");
|
||||||
|
|
||||||
java.util.List<Firmware> list = firmwareService.list(wrapper);
|
List<Firmware> list = firmwareService.list(wrapper);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验是否存在新固件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@CommonLog("校验是否存在新固件")
|
||||||
|
@ApiOperation("校验是否存在新固件")
|
||||||
|
@PostMapping("/checkVersion")
|
||||||
|
public Result<Firmware> checkVersion(@RequestBody @Valid FirmwareVersionRequest firmwareVersionRequest) {
|
||||||
|
return Result.success(firmwareService.checkVersion(firmwareVersionRequest));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.corewing.app.service;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.corewing.app.common.Result;
|
import com.corewing.app.common.Result;
|
||||||
|
import com.corewing.app.dto.FirmwareVersionRequest;
|
||||||
import com.corewing.app.entity.Firmware;
|
import com.corewing.app.entity.Firmware;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -40,4 +41,11 @@ public interface FirmwareService extends IService<Firmware> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean removeData(Long id);
|
boolean removeData(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验固件是否有新固件
|
||||||
|
* @param firmwareVersionRequest
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Firmware checkVersion(FirmwareVersionRequest firmwareVersionRequest);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.corewing.app.common.page.PageContext;
|
import com.corewing.app.common.page.PageContext;
|
||||||
|
import com.corewing.app.dto.FirmwareVersionRequest;
|
||||||
|
import com.corewing.app.entity.BizDeviceCategory;
|
||||||
import com.corewing.app.entity.Firmware;
|
import com.corewing.app.entity.Firmware;
|
||||||
import com.corewing.app.mapper.FirmwareMapper;
|
import com.corewing.app.mapper.FirmwareMapper;
|
||||||
|
import com.corewing.app.service.BizDeviceCategoryService;
|
||||||
import com.corewing.app.service.FirmwareService;
|
import com.corewing.app.service.FirmwareService;
|
||||||
import com.corewing.app.util.OSSUploadUtil;
|
import com.corewing.app.util.OSSUploadUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -13,7 +16,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 固件 Service 实现类
|
* 固件 Service 实现类
|
||||||
@@ -21,6 +26,9 @@ import java.io.IOException;
|
|||||||
@Service
|
@Service
|
||||||
public class FirmwareServiceImpl extends ServiceImpl<FirmwareMapper, Firmware> implements FirmwareService {
|
public class FirmwareServiceImpl extends ServiceImpl<FirmwareMapper, Firmware> implements FirmwareService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BizDeviceCategoryService bizDeviceCategoryService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<Firmware> page(Firmware firmware) {
|
public Page<Firmware> page(Firmware firmware) {
|
||||||
Page<Firmware> page = PageContext.getDefaultPage(Firmware.class);
|
Page<Firmware> page = PageContext.getDefaultPage(Firmware.class);
|
||||||
@@ -63,6 +71,30 @@ public class FirmwareServiceImpl extends ServiceImpl<FirmwareMapper, Firmware> i
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Firmware checkVersion(FirmwareVersionRequest firmwareVersionRequest) {
|
||||||
|
|
||||||
|
// 根据型号id搜索到设备分类id
|
||||||
|
LambdaQueryWrapper<BizDeviceCategory> categoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
categoryLambdaQueryWrapper.eq(BizDeviceCategory::getModelId, firmwareVersionRequest.getModelId());
|
||||||
|
BizDeviceCategory deviceCategory = bizDeviceCategoryService.getOne(categoryLambdaQueryWrapper);
|
||||||
|
if(Objects.isNull(deviceCategory)){
|
||||||
|
throw new RuntimeException("该设备型号不存在设备");
|
||||||
|
}
|
||||||
|
|
||||||
|
LambdaQueryWrapper<Firmware> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.ge(Firmware::getVersionId, firmwareVersionRequest.getVersion());
|
||||||
|
wrapper.eq(Firmware::getModelId, deviceCategory.getId());
|
||||||
|
wrapper.eq(Firmware::getFirmwareType, firmwareVersionRequest.getFirmwareType());
|
||||||
|
wrapper.orderByDesc(Firmware::getVersionId);
|
||||||
|
wrapper.last("LIMIT 1");
|
||||||
|
Firmware firmware = this.getOne(wrapper);
|
||||||
|
if (firmware == null) {
|
||||||
|
throw new RuntimeException("未找到匹配的固件版本");
|
||||||
|
}
|
||||||
|
return firmware;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 URL 路径的最后一节(忽略查询参数 ? 和锚点 #)
|
* 获取 URL 路径的最后一节(忽略查询参数 ? 和锚点 #)
|
||||||
* @param urlStr URL字符串
|
* @param urlStr URL字符串
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
# spring profiles configuration
|
# spring profiles configuration
|
||||||
#########################################
|
#########################################
|
||||||
#spring.profiles.active=local
|
spring.profiles.active=local
|
||||||
#spring.profiles.active=test
|
#spring.profiles.active=test
|
||||||
spring.profiles.active=prod
|
#spring.profiles.active=prod
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
# 应用服务 WEB 访问端口
|
# 应用服务 WEB 访问端口
|
||||||
|
|||||||
Reference in New Issue
Block a user