From 48c1de18235020edff108339ed1d12bade8a2b90 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期一, 08 十二月 2025 16:37:02 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/system/controller/LicenseCreatorController.java |  105 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/system/controller/LicenseCreatorController.java b/src/main/java/com/zy/system/controller/LicenseCreatorController.java
new file mode 100644
index 0000000..13e2b1c
--- /dev/null
+++ b/src/main/java/com/zy/system/controller/LicenseCreatorController.java
@@ -0,0 +1,105 @@
+package com.zy.system.controller;
+
+import com.core.common.Cools;
+import com.core.common.R;
+import com.zy.system.entity.license.*;
+import com.zy.system.timer.LicenseTimer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.MediaType;
+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;
+
+/**
+ *
+ * 鐢ㄤ簬鐢熸垚璇佷功鏂囦欢锛屼笉鑳芥斁鍦ㄧ粰瀹㈡埛閮ㄧ讲鐨勪唬鐮侀噷
+ */
+@RestController
+@RequestMapping("/license")
+public class LicenseCreatorController {
+
+    @Value("${license.licensePath}")
+    private String licensePath;
+    @Autowired
+    private LicenseCheckListener licenseCheckListener;
+    @Autowired
+    private LicenseTimer licenseTimer;
+    /**
+     * 鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭�
+     * @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() {
+        return R.ok(licenseTimer.getLicenseDays());
+    }
+
+    @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("璁稿彲璇佹洿鏂板け璐�");
+    }
+
+    @RequestMapping(value = "/activate")
+    public R activate() {
+        licenseTimer.timer();
+        return R.ok();
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.1