“djh”
2024-12-04 d1549b8445c65a6775cf1ba093f5040ace0f87e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.gkhy.huataiFourierSpecialGasMonitor.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;
    }
 
 
}