Lius
2024-11-04 d603739c0320f355cfc3152865918729fea790de
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package org.jeecg.modules.base.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.config.license.*;
import org.jeecg.config.license.entity.LicenseCheckModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Author: lius
 * @ClassName LicenseController
 * @date 2024/11/2 17:35
 */
@Slf4j
@Api(tags = "license证书")
@RestController
@RequestMapping("/base/license")
public class LicenseController {
 
    /**
     * 证书生成路径
     */
    @Value("${license.licensePath}")
    private String licensePath;
 
    /**
    * @Author: lius
    * @Description: 获取服务器硬件信息
    * @DateTime: 17:35 2024/11/2
    * @Params:  osName 系统类型 windows或linux
    * @Return
    */
    @AutoLog(value = "获取服务器硬件信息")
    @ApiOperation("获取服务器硬件信息")
    @GetMapping("/getServerInfos/{osName}")
    public LicenseCheckModel getServerInfos(@PathVariable String osName) {
        //操作系统类型
        if (StringUtils.isBlank(osName)) {
            osName = System.getProperty("os.name");
        }
        osName = osName.toLowerCase();
 
        AbstractServerInfos abstractServerInfos = null;
 
        //根据不同操作系统类型选择不同的数据获取方法
        if (osName.startsWith("windows")) {
            abstractServerInfos = new WindowsServerInfos();
        } else if (osName.startsWith("linux")) {
            abstractServerInfos = new LinuxServerInfos();
        } else {//其他服务器类型
            abstractServerInfos = new LinuxServerInfos();
        }
 
        return abstractServerInfos.getServerInfos();
    }
 
    /**
    * @Author: lius
    * @Description: 生成证书
    * @DateTime: 17:35 2024/11/2
    */
    @AutoLog(value = "生成证书")
    @ApiOperation("生成证书")
    @PostMapping("/generateLicense")
    public Map<String, Object> generateLicense(@RequestBody LicenseCreatorParam param) {
        Map<String, Object> resultMap = new HashMap<>(2);
 
        if (StringUtils.isBlank(param.getLicensePath())) {
            param.setLicensePath(licensePath);
        }
 
        LicenseCreator licenseCreator = new LicenseCreator(param);
        boolean result = licenseCreator.generateLicense();
 
        if (result) {
            resultMap.put("result", "ok");
            resultMap.put("msg", param);
        } else {
            resultMap.put("result", "error");
            resultMap.put("msg", "证书文件生成失败!");
        }
 
        return resultMap;
    }
 
 
 
 
}