package com.gkhy.labRiskManage.config.license; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @Service public class LicenseManageService { @Value("${system.deployMode}") private String deployMode; @Autowired private CompanyLicenseDataCache companyLicenseDataCache; /** * 检查license有效性 * @return */ public boolean isActiveLicense(){ LicenseInfo licenseInfo = companyLicenseDataCache.getLicenseInfo(); if(licenseInfo == null){ return false; } if(licenseInfo.getLicenseType().equals(LicenseTypeEnum.INVALID.getType())){ //无效授权 return false; } LocalDateTime nowTime = LocalDateTime.now(); if(licenseInfo.getLicenseType().equals(LicenseTypeEnum.TRAIL.getType())){ //试用授权 if(licenseInfo.getBeginTime() == null || licenseInfo.getEndTime() == null){ return false; } if(licenseInfo.getBeginTime().isAfter(nowTime) || licenseInfo.getEndTime().isBefore(nowTime)){ return false; }else { return true; } } if(licenseInfo.getLicenseType().equals(LicenseTypeEnum.LIMIT.getType())){ //有限期授权 if(licenseInfo.getBeginTime() == null || licenseInfo.getEndTime() == null){ return false; } if(licenseInfo.getBeginTime().isAfter(nowTime) || licenseInfo.getEndTime().isBefore(nowTime)){ return false; }else { return true; } } if(licenseInfo.getLicenseType().equals(LicenseTypeEnum.LONG_TIME.getType())){ //长期授权 return true; } //证书类型不支持,默认无效 return false; } }