feat:增加版本控制

This commit is contained in:
wangyu 2022-03-09 19:52:59 +08:00
parent 752a3837f1
commit 9a9318973f
5 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package com.flyfish.framework.backup.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
/**
* 版本配置
*
* @author wangyu
*/
@EnableConfigurationProperties(VersionProperties.class)
//@Configuration
public class VersionConfig {
}

View File

@ -0,0 +1,29 @@
package com.flyfish.framework.backup.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* 备份配置
*
* @author wangyu
*/
@ConfigurationProperties(prefix = "flyfish.version")
@Data
public class VersionProperties {
/**
* 服务器地址
*/
private String server = "http://version.flyfish.group";
/**
* 版本配置地址
*/
private String versionUri = "/doc-system/version.json";
/**
* 当前系统版本
*/
private String version = "v1.0";
}

View File

@ -0,0 +1,15 @@
package com.flyfish.framework.backup.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 版本控制服务
* @author wangyu
*/
@RestController
@RequestMapping("versions")
public class VersionController {
}

View File

@ -0,0 +1,26 @@
package com.flyfish.framework.backup.domain;
import com.flyfish.framework.annotations.Property;
import lombok.Data;
import java.util.Date;
/**
* 版本号实体
* @author wangyu
*/
@Data
public class Version {
@Property("版本号")
private String version;
@Property("下载地址")
private String payload;
@Property("安装脚本")
private String script;
@Property("创建时间")
private Date time;
}

View File

@ -0,0 +1,44 @@
package com.flyfish.framework.backup.service;
import com.flyfish.framework.backup.config.VersionProperties;
import com.flyfish.framework.backup.domain.Version;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
/**
* 版本服务
*
* @author wangyu
*/
@Service
public class VersionService {
private final VersionProperties versionProperties;
private final WebClient webClient;
public VersionService(VersionProperties versionProperties) {
this.versionProperties = versionProperties;
this.webClient = WebClient.create(versionProperties.getServer());
}
/**
* 拉取最新版本
*
* @return 结果
*/
public Mono<Version> fetch() {
return webClient.get().uri(versionProperties.getVersionUri())
.exchangeToMono(clientResponse -> clientResponse.bodyToMono(Version.class));
}
/**
* 检查新版
*
* @return 结果
*/
public Mono<Boolean> checkUpdate() {
return fetch().map(version -> !version.getVersion().equals(versionProperties.getVersion()));
}
}