2021-05-18 12:23:21 +08:00
|
|
|
package io.dataease.service;
|
|
|
|
|
2021-06-07 16:11:06 +08:00
|
|
|
import io.dataease.commons.constants.AuthConstants;
|
2021-05-18 12:23:21 +08:00
|
|
|
import io.dataease.commons.license.DefaultLicenseService;
|
|
|
|
import io.dataease.commons.license.F2CLicenseResponse;
|
|
|
|
import io.dataease.commons.utils.CommonBeanFactory;
|
2021-06-11 16:06:15 +08:00
|
|
|
import io.dataease.commons.utils.DateUtils;
|
2021-05-18 12:23:21 +08:00
|
|
|
import io.dataease.commons.utils.LogUtil;
|
2021-06-07 16:11:06 +08:00
|
|
|
import io.dataease.listener.util.CacheUtils;
|
2021-05-18 12:23:21 +08:00
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.stereotype.Service;
|
2021-11-22 18:34:49 +08:00
|
|
|
|
2021-05-18 12:23:21 +08:00
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.File;
|
2021-06-07 16:11:06 +08:00
|
|
|
import java.util.Date;
|
2021-05-18 12:23:21 +08:00
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class AboutService {
|
2021-05-18 18:35:54 +08:00
|
|
|
private static final String BUILD_VERSION = "/opt/dataease/conf/version";
|
|
|
|
private static final String product = "DataEase";
|
2021-05-18 12:23:21 +08:00
|
|
|
|
|
|
|
@Resource
|
|
|
|
private DefaultLicenseService defaultLicenseService;
|
|
|
|
|
|
|
|
public F2CLicenseResponse updateLicense(String licenseKey) {
|
|
|
|
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.updateLicense(product, licenseKey);
|
2021-06-07 16:11:06 +08:00
|
|
|
Optional.ofNullable(f2CLicenseResponse).ifPresent(resp -> {
|
2021-11-22 18:34:49 +08:00
|
|
|
if (resp.getStatus() == F2CLicenseResponse.Status.valid) {
|
2021-06-11 16:06:15 +08:00
|
|
|
String dateStr = f2CLicenseResponse.getLicense().getExpired();
|
|
|
|
LogUtil.info("update valid lic, expired date is {}", dateStr);
|
|
|
|
try {
|
2021-11-22 18:34:49 +08:00
|
|
|
Date date = DateUtils.getDate(dateStr);
|
2021-06-11 16:06:15 +08:00
|
|
|
CacheUtils.updateLicCache(date);
|
|
|
|
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
|
|
|
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
|
|
|
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LogUtil.error(e);
|
|
|
|
}
|
2021-06-07 16:11:06 +08:00
|
|
|
}
|
|
|
|
});
|
2021-05-18 12:23:21 +08:00
|
|
|
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");
|
2021-11-22 18:34:49 +08:00
|
|
|
return Optional.ofNullable(property).orElse("V1.0");
|
2021-05-18 12:23:21 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
LogUtil.error("failed to get build version.", e);
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|