From f3f1f118e1ff589bb41b9e8bea5aa8d466bec670 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期二, 30 十二月 2025 12:03:16 +0800
Subject: [PATCH] 1

---
 src/main/java/com/zy/system/controller/LicenseCreatorController.java |  262 ++++++++++++++++----------------
 src/main/java/com/zy/system/entity/license/LicenseCheckListener.java |  190 +++++++++++-----------
 src/main/resources/application.yml                                   |    8 
 3 files changed, 227 insertions(+), 233 deletions(-)

diff --git a/src/main/java/com/zy/system/controller/LicenseCreatorController.java b/src/main/java/com/zy/system/controller/LicenseCreatorController.java
index 6b4d644..ca8b634 100644
--- a/src/main/java/com/zy/system/controller/LicenseCreatorController.java
+++ b/src/main/java/com/zy/system/controller/LicenseCreatorController.java
@@ -1,131 +1,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("璁稿彲璇佹洿鏂板け璐�");
-    }
-
-}
\ No newline at end of file
+//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("璁稿彲璇佹洿鏂板け璐�");
+//    }
+//
+//}
\ No newline at end of file
diff --git a/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java b/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
index 75f1104..3c79915 100644
--- a/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
+++ b/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
@@ -1,95 +1,95 @@
-package com.zy.system.entity.license;
-
-import com.core.common.Cools;
-import de.schlichtherle.license.LicenseContent;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.event.ContextRefreshedEvent;
-import org.springframework.stereotype.Component;
-
-import java.io.File;
-
-/**
- * 鍦ㄩ」鐩惎鍔ㄦ椂瀹夎璇佷功
- */
-@Component
-public class LicenseCheckListener implements ApplicationListener<ContextRefreshedEvent> {
-    private static Logger logger = LogManager.getLogger(LicenseCheckListener.class);
-
-    /**
-     * 璇佷功subject
-     */
-    @Value("${license.subject}")
-    private String subject;
-
-    /**
-     * 鍏挜鍒О
-     */
-    @Value("${license.publicAlias}")
-    private String publicAlias;
-
-    /**
-     * 璁块棶鍏挜搴撶殑瀵嗙爜
-     */
-    @Value("${license.storePass}")
-    private String storePass;
-
-    /**
-     * 璇佷功鐢熸垚璺緞
-     */
-    @Value("${license.licensePath}")
-    private String licensePath;
-
-    /**
-     * 瀵嗛挜搴撳瓨鍌ㄨ矾寰�
-     */
-    @Value("${license.publicKeysStorePath}")
-    private String publicKeysStorePath;
-
-    @Override
-    public void onApplicationEvent(ContextRefreshedEvent event) {
-        //root application context 娌℃湁parent
-        ApplicationContext context = event.getApplicationContext().getParent();
-        if(context == null){
-            loadLicense();
-        }
-    }
-
-    //鍔犺浇璇佷功
-    public boolean loadLicense() {
-        if(!Cools.isEmpty(licensePath)){
-            logger.info("++++++++ 寮�濮嬪姞杞借鍙瘉 ++++++++");
-
-            try {
-                String publicKeysStoreFileName = this.getClass().getClassLoader().getResource(publicKeysStorePath).getPath();
-                File publicKeysStoreFile = new File(publicKeysStoreFileName);
-
-                String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath();
-                File licensePathFile = new File(licensePathFileName);
-
-                LicenseVerifyParam param = new LicenseVerifyParam();
-                param.setSubject(subject);
-                param.setPublicAlias(publicAlias);
-                param.setStorePass(storePass);
-                param.setLicensePath(licensePathFile.getPath());
-                param.setPublicKeysStorePath(publicKeysStoreFile.getPath());
-
-                LicenseVerify licenseVerify = new LicenseVerify();
-                //瀹夎璇佷功
-                LicenseContent install = licenseVerify.install(param);
-
-                logger.info("++++++++ 璁稿彲璇佸姞杞界粨鏉� ++++++++");
-
-//                return install != null;
-                return true;
-            } catch (Exception e) {
-                return false;
-            }
-        }
-
-        return false;
-    }
-}
\ No newline at end of file
+//package com.zy.system.entity.license;
+//
+//import com.core.common.Cools;
+//import de.schlichtherle.license.LicenseContent;
+//import org.apache.logging.log4j.LogManager;
+//import org.apache.logging.log4j.Logger;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.ApplicationContext;
+//import org.springframework.context.ApplicationListener;
+//import org.springframework.context.event.ContextRefreshedEvent;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.File;
+//
+///**
+// * 鍦ㄩ」鐩惎鍔ㄦ椂瀹夎璇佷功
+// */
+//@Component
+//public class LicenseCheckListener implements ApplicationListener<ContextRefreshedEvent> {
+//    private static Logger logger = LogManager.getLogger(LicenseCheckListener.class);
+//
+//    /**
+//     * 璇佷功subject
+//     */
+//    @Value("${license.subject}")
+//    private String subject;
+//
+//    /**
+//     * 鍏挜鍒О
+//     */
+//    @Value("${license.publicAlias}")
+//    private String publicAlias;
+//
+//    /**
+//     * 璁块棶鍏挜搴撶殑瀵嗙爜
+//     */
+//    @Value("${license.storePass}")
+//    private String storePass;
+//
+//    /**
+//     * 璇佷功鐢熸垚璺緞
+//     */
+//    @Value("${license.licensePath}")
+//    private String licensePath;
+//
+//    /**
+//     * 瀵嗛挜搴撳瓨鍌ㄨ矾寰�
+//     */
+//    @Value("${license.publicKeysStorePath}")
+//    private String publicKeysStorePath;
+//
+//    @Override
+//    public void onApplicationEvent(ContextRefreshedEvent event) {
+//        //root application context 娌℃湁parent
+//        ApplicationContext context = event.getApplicationContext().getParent();
+//        if(context == null){
+//            loadLicense();
+//        }
+//    }
+//
+//    //鍔犺浇璇佷功
+//    public boolean loadLicense() {
+//        if(!Cools.isEmpty(licensePath)){
+//            logger.info("++++++++ 寮�濮嬪姞杞借鍙瘉 ++++++++");
+//
+//            try {
+//                String publicKeysStoreFileName = this.getClass().getClassLoader().getResource(publicKeysStorePath).getPath();
+//                File publicKeysStoreFile = new File(publicKeysStoreFileName);
+//
+//                String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath();
+//                File licensePathFile = new File(licensePathFileName);
+//
+//                LicenseVerifyParam param = new LicenseVerifyParam();
+//                param.setSubject(subject);
+//                param.setPublicAlias(publicAlias);
+//                param.setStorePass(storePass);
+//                param.setLicensePath(licensePathFile.getPath());
+//                param.setPublicKeysStorePath(publicKeysStoreFile.getPath());
+//
+//                LicenseVerify licenseVerify = new LicenseVerify();
+//                //瀹夎璇佷功
+//                LicenseContent install = licenseVerify.install(param);
+//
+//                logger.info("++++++++ 璁稿彲璇佸姞杞界粨鏉� ++++++++");
+//
+////                return install != null;
+//                return true;
+//            } catch (Exception e) {
+//                return false;
+//            }
+//        }
+//
+//        return false;
+//    }
+//}
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index c4a5ea9..e04c860 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -42,13 +42,7 @@
 swagger:
   enable: false
 
-#License鐩稿叧閰嶇疆
-license:
-  subject: ghjtasrs
-  publicAlias: publicCert
-  storePass: public_zhongyang_123456789
-  licensePath: license.lic
-  publicKeysStorePath: publicCerts.keystore
+
 
 # 涓嬩綅鏈洪厤缃�
 wcs-slave:

--
Gitblit v1.9.1