自动化立体仓库 - WMS系统
1
zhang
昨天 e01fce2ebdd2bdba72682aa314656b57e68f211c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.zy.system.controller;
 
import com.core.annotations.ManagerAuth;
import com.core.common.AesUtils;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.zy.common.properties.OSinfo;
import com.zy.common.properties.SystemProperties;
import com.zy.system.entity.license.*;
import de.schlichtherle.license.LicenseContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.prefs.Preferences;
 
/**
 *
 * 用于生成证书文件,不能放在给客户部署的代码里
 */
@RestController
@RequestMapping("/license")
public class LicenseCreatorController {
 
    @Value("${license.licensePath}")
    private String licensePath;
 
    @Autowired
    private LicenseCheckListener licenseCheckListener;
 
    /**
     * 获取服务器硬件信息
     * @param osName 操作系统类型,如果为空则自动判断
     */
    @RequestMapping(value = "/getServerInfos",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public LicenseCheck getServerInfos(@RequestParam(value = "osName",required = false) String osName) {
        //操作系统类型
        if(Cools.isEmpty(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 WindowsServerInfos();
        }
 
        return abstractServerInfos.getServerInfos();
    }
 
    /**
     * 获取许可证有效期天数
     */
    @RequestMapping(value = "/getLicenseDays")
    public R getLicenseDays() {
 
        // 获取激活码
        String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
        if (!Cools.isEmpty(activationCode)) {
            // 获取有效期
            String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
            if (null == timeStr) {
                return R.error();
            }
            Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
            if (new Date().getTime() < exprTime.getTime()) {
                Date start = new Date();
                Long starTime = start.getTime();
                Long endTime = exprTime.getTime();
                Long num = endTime - starTime;//时间戳相差的毫秒数
                int day = (int) (num / 24 / 60 / 60 / 1000);
                return R.ok().add(day);
            }
        }
        return R.error();
    }
 
    @RequestMapping(value = "/updateLicense")
    public R updateLicense(@RequestParam("file") MultipartFile[] files){
        MultipartFile file = files[0];
 
        String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath();
        File licensePathFile = new File(licensePathFileName);
        //服务器端保存的文件对象
        File serverFile = new File(licensePathFile.getPath());
        if (serverFile.exists()) {
            try {
                serverFile.delete();//存在文件,删除
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        try {
            //创建文件
            serverFile.createNewFile();
            //将上传的文件写入到服务器端文件内
            file.transferTo(serverFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        //重新加载许可证
        boolean loadedLicense = licenseCheckListener.loadLicense();
        if (loadedLicense) {
            return R.ok();
        }
        return R.error("许可证更新失败");
    }
 
}