feat: 新增关于页面 以及 lic更新功能

This commit is contained in:
fit2cloud-chenyw
2021-05-18 12:23:21 +08:00
parent 120dd256aa
commit 5fc32d6bba
8 changed files with 337 additions and 9 deletions

View File

@@ -0,0 +1,32 @@
package io.dataease.controller;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.service.AboutService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
@RequestMapping("/about")
@RestController
public class AboutController {
@Resource
private AboutService aboutService;
@PostMapping("/license/update")
public F2CLicenseResponse updateLicense(@RequestBody Map<String, String> map) {
return aboutService.updateLicense(map.get("license"));
}
@PostMapping("/license/validate")
public F2CLicenseResponse validateLicense(@RequestBody Map<String, String> map) {
return aboutService.validateLicense(map.get("license"));
}
@GetMapping("/build/version")
public Object getBuildVersion() {
return aboutService.getBuildVersion();
}
}

View File

@@ -0,0 +1,54 @@
package io.dataease.service;
import io.dataease.commons.license.DefaultLicenseService;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.LogUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.util.Optional;
@Service
public class AboutService {
private static final String BUILD_VERSION = "/opt/fit2cloud/conf/version";
private static final String product = "dataease";
@Resource
private DefaultLicenseService defaultLicenseService;
public F2CLicenseResponse updateLicense(String licenseKey) {
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.updateLicense(product, licenseKey);
return f2CLicenseResponse;
}
public F2CLicenseResponse validateLicense(String licenseKey) {
if (StringUtils.isNotBlank(licenseKey)) {
return defaultLicenseService.validateLicense(product, licenseKey);
} else {
return defaultLicenseService.validateLicense();
}
}
public String getBuildVersion() {
try {
File file = new File(BUILD_VERSION);
if (file.exists()) {
String version = FileUtils.readFileToString(file, "UTF-8");
if (StringUtils.isNotBlank(version)) {
return version;
}
}
String property = CommonBeanFactory.getBean(Environment.class).getProperty("cmp.version");
String result = Optional.ofNullable(property).orElse("V1.0");
return result;
} catch (Exception e) {
LogUtil.error("failed to get build version.", e);
}
return "unknown";
}
}