From 1d9c00b1fb1a8e6473fc8625470c7616866bb803 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期四, 23 十月 2025 10:52:45 +0800
Subject: [PATCH] 13
---
/dev/null | 42 --------
src/main/java/com/zy/system/service/impl/ConfigServiceImpl.java | 43 ++++++++
src/main/java/com/zy/common/web/AuthController.java | 104 ++++++++++----------
src/main/java/com/zy/common/config/AdminInterceptor.java | 11 +
src/main/java/com/zy/system/service/ConfigService.java | 3
src/main/java/com/zy/system/timer/LoadingConfigTimer.java | 39 +++++++
src/main/java/com/zy/system/timer/TokenTimer.java | 50 ++++++++++
7 files changed, 196 insertions(+), 96 deletions(-)
diff --git a/src/main/java/com/zy/common/config/AdminInterceptor.java b/src/main/java/com/zy/common/config/AdminInterceptor.java
index 90f1f5b..3d0f696 100644
--- a/src/main/java/com/zy/common/config/AdminInterceptor.java
+++ b/src/main/java/com/zy/common/config/AdminInterceptor.java
@@ -5,10 +5,11 @@
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
-import com.zy.common.properties.SystemProperties;
import com.zy.common.utils.Http;
import com.zy.system.entity.*;
import com.zy.system.service.*;
+import com.zy.system.timer.LicenseTimer;
+import com.zy.system.timer.LoadingConfigTimer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.Nullable;
@@ -40,6 +41,10 @@
private PermissionService permissionService;
@Autowired
private RolePermissionService rolePermissionService;
+ @Autowired
+ private LicenseTimer licenseTimer;
+ @Autowired
+ private LoadingConfigTimer loadingConfigTimer;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@@ -54,7 +59,7 @@
if (deToken != null) {
long timestamp = Long.parseLong(deToken.substring(0, 13));
// 鍗婂皬鏃跺悗杩囨湡
- if (System.currentTimeMillis() - timestamp > 1000 * 60 * 30) {
+ if (System.currentTimeMillis() - timestamp > loadingConfigTimer.getTokenExpire()) {
Http.response(response, BaseRes.DENIED);
return false;
}
@@ -136,7 +141,7 @@
// 鎿嶄綔鏃ュ織
if (!Cools.isEmpty(memo)) {
// 杩涜婵�娲诲垽鏂�
- if (!SystemProperties.SYSTEM_ACTIVATION) {
+ if (!licenseTimer.getSystemSupport()) {
Http.response(response, BaseRes.NO_ACTIVATION);
return false;
}
diff --git a/src/main/java/com/zy/common/properties/SystemProperties.java b/src/main/java/com/zy/common/properties/SystemProperties.java
deleted file mode 100644
index bd926c4..0000000
--- a/src/main/java/com/zy/common/properties/SystemProperties.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.zy.common.properties;
-
-import com.core.common.AesUtils;
-import com.core.common.DateUtils;
-
-import java.io.*;
-import java.util.Date;
-
-/**
- * Created by vincent on 2020/8/1
- */
-public class SystemProperties {
-
- // 婵�娲荤爜鍔犲瘑鐩� -- 16浣�
- public static final String SALT = "123456789qwertyu";
-
- // 绯荤粺婵�娲荤姸鎬� (榛樿鏈縺娲�)
-// public static boolean SYSTEM_ACTIVATION = Boolean.FALSE;
- public static boolean SYSTEM_ACTIVATION = Boolean.TRUE;
-
- public static String getActivationCode(String fileName) {
- StringBuilder activationCode = new StringBuilder();
- try {
- FileReader f = new FileReader(fileName);
- BufferedReader buf = new BufferedReader(f);
- String s;
- while ((s = buf.readLine()) != null) {
- activationCode.append(s);
- }
- f.close();
- buf.close();
- } catch (FileNotFoundException ignore) {
-
- } catch (IOException e) {
- e.printStackTrace();
- throw new RuntimeException("璇诲彇WMS绯荤粺婵�娲荤爜澶辫触锛侊紒锛乗n璇诲彇璺緞 " + fileName);
- }
- return activationCode.toString();
- }
-
- public static boolean saveActivationCode(String filePath, String code) {
- try {
- // 闃叉鏂囦欢寤虹珛鎴栬鍙栧け璐ワ紝鐢╟atch鎹曟崏閿欒骞舵墦鍗帮紝涔熷彲浠hrow
- File file = new File(filePath);// 鐩稿璺緞锛屽鏋滄病鏈夊垯瑕佸缓绔嬩竴涓柊鐨刼utput銆倀xt鏂囦欢
- if (file.exists()) {
- file.delete();
- }
- boolean newFile = file.createNewFile();// 鍒涘缓鏂版枃浠�
- if (newFile) {
- String sets = "attrib +H \"" + file.getAbsolutePath() + "\"";
- Runtime.getRuntime().exec(sets);
- BufferedWriter out = new BufferedWriter(new FileWriter(file, true));
- out.write(code); // \r\n鍗充负鎹㈣
- out.flush(); // 鎶婄紦瀛樺尯鍐呭鍘嬪叆鏂囦欢
- out.close(); // 鏈�鍚庤寰楀叧闂枃浠�
- }
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("鍐欏叆WMS绯荤粺婵�娲荤爜澶辫触锛侊紒锛乗n璺緞 " + filePath);
- }
- return true;
- }
-
-
- // 鐢熸垚婵�娲荤爜
- public static void main(String[] args) {
- String timeStr = "2021-08-01 17:48:35";
- Date exprTime = DateUtils.convert(timeStr);
- String code = AesUtils.encrypt(DateUtils.convert(exprTime, DateUtils.yyyyMMddHHmmss), SystemProperties.SALT);
- System.out.println("婵�娲荤爜锛�" + code);
- System.out.println("鏈夋晥鏈熻嚦锛�" + timeStr);
-// saveActivationCode(SysOsType.Windows.getActivationCodePath(), code);
-// String activationCode = getActivationCode(OSinfo.getOSname().getActivationCodePath());
-// String decrypt = AesUtils.decrypt(activationCode, "123456789qwertyu");
-// Date convert = DateUtils.convert(decrypt, DateUtils.yyyyMMddHHmmss);
-// System.out.println(DateUtils.convert(convert));
- }
-
-}
diff --git a/src/main/java/com/zy/common/task/ActivateScheduler.java b/src/main/java/com/zy/common/task/ActivateScheduler.java
deleted file mode 100644
index 32ec715..0000000
--- a/src/main/java/com/zy/common/task/ActivateScheduler.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.zy.common.task;
-
-import com.core.common.AesUtils;
-import com.core.common.Cools;
-import com.core.common.DateUtils;
-import com.zy.common.properties.OSinfo;
-import com.zy.common.properties.SystemProperties;
-import org.springframework.stereotype.Component;
-
-import java.util.Date;
-
-/**
- * 绯荤粺婵�娲讳换鍔�
- */
-@Component
-public class ActivateScheduler {
-
- // @Scheduled(cron = "0/1 * 8 * * ? ") // 姣忓ぉ8鐐�
-// @Scheduled(cron = "* 0/1 * * * ? ") // 姣忓垎閽�
-// @PostConstruct
- private void execute() {
- // 鑾峰彇婵�娲荤爜
- String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
- if (!Cools.isEmpty(activationCode)) {
- // 鑾峰彇鏈夋晥鏈�
- String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
- if (null == timeStr) {
- SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
- return;
- }
- Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
- if (new Date().getTime() < exprTime.getTime()) {
- SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE;
- } else {
- SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
- }
- } else {
- SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
- }
- }
-
-}
diff --git a/src/main/java/com/zy/common/web/AuthController.java b/src/main/java/com/zy/common/web/AuthController.java
index a0e6146..640a452 100644
--- a/src/main/java/com/zy/common/web/AuthController.java
+++ b/src/main/java/com/zy/common/web/AuthController.java
@@ -4,25 +4,25 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
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.core.exception.CoolException;
import com.zy.common.CodeRes;
import com.zy.common.entity.Parameter;
import com.zy.common.model.PowerDto;
import com.zy.common.model.enums.HtmlNavIconType;
-import com.zy.common.properties.OSinfo;
-import com.zy.common.properties.SystemProperties;
import com.zy.common.utils.RandomValidateCodeUtil;
import com.zy.system.entity.*;
import com.zy.system.service.*;
import com.zy.system.timer.LicenseTimer;
+import com.zy.system.timer.LoadingConfigTimer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
@@ -51,6 +51,8 @@
private RolePermissionService rolePermissionService;
@Autowired
private LicenseTimer licenseTimer;
+ @Autowired
+ private LoadingConfigTimer loadingConfigTimer;
@RequestMapping("/login.action")
@ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "鐧诲綍")
@@ -78,7 +80,9 @@
return R.parse(CodeRes.USER_10003);
}
String token = Cools.enToken(System.currentTimeMillis() + username, user.getPassword());
- userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId()));
+ if (loadingConfigTimer.getTokenNumber() == 1) {
+ userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId()).eq("system", "WMS"));
+ }
UserLogin userLogin = new UserLogin();
userLogin.setUserId(user.getId());
userLogin.setToken(token);
@@ -136,7 +140,7 @@
resourceWrapper = new EntityWrapper<Resource>().eq("level", 2).eq("status", 1).orderBy("sort");
} else {
// 婵�娲荤爜楠岃瘉
- if (!SystemProperties.SYSTEM_ACTIVATION) {
+ if (!licenseTimer.getSystemSupport()) {
return R.ok();
}
oneLevel = resourceService.selectList(new EntityWrapper<Resource>().eq("level", 1).eq("status", 1).orderBy("sort"));
@@ -342,48 +346,48 @@
return R.ok(resources);
}
- @GetMapping(value = "/system/activation/auth")
- public R activation() {
- if (SystemProperties.SYSTEM_ACTIVATION) {
- String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
- String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
- if (null == timeStr) {
- SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
- return R.error();
- }
- Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
- if (new Date().getTime() < exprTime.getTime()) {
- return R.ok().add(DateUtils.convert(exprTime));
- } else {
- SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
- return R.error();
- }
- } else {
- return R.error();
- }
- }
-
- @PostMapping(value = "/system/secret/auth")
- @ManagerAuth
- public R systemSecret(@RequestParam(value = "secret") String secret) {
- if (Cools.isEmpty(secret)) {
- return R.error("璇疯緭鍏ユ縺娲荤爜");
- }
- // 楠岃瘉婵�娲荤爜
- String timeStr = AesUtils.decrypt(secret, SystemProperties.SALT);
- if (null == timeStr) {
- return R.error("婵�娲荤爜閿欒");
- }
- Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
- if (new Date().getTime() >= exprTime.getTime()) {
- return R.error("婵�娲荤爜宸插け鏁�");
- }
- boolean result = SystemProperties.saveActivationCode(OSinfo.getOSname().getActivationCodePath(), secret);
- if (!result) {
- return R.error("婵�娲诲け璐�");
- }
- SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE;
- return R.ok("婵�娲绘垚鍔燂紝鏈夋晥鏈熻嚦" + DateUtils.convert(exprTime));
- }
+// @GetMapping(value = "/system/activation/auth")
+// public R activation() {
+// if (SystemProperties.SYSTEM_ACTIVATION) {
+// String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
+// String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
+// if (null == timeStr) {
+// SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+// return R.error();
+// }
+// Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+// if (new Date().getTime() < exprTime.getTime()) {
+// return R.ok().add(DateUtils.convert(exprTime));
+// } else {
+// SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+// return R.error();
+// }
+// } else {
+// return R.error();
+// }
+// }
+//
+// @PostMapping(value = "/system/secret/auth")
+// @ManagerAuth
+// public R systemSecret(@RequestParam(value = "secret") String secret) {
+// if (Cools.isEmpty(secret)) {
+// return R.error("璇疯緭鍏ユ縺娲荤爜");
+// }
+// // 楠岃瘉婵�娲荤爜
+// String timeStr = AesUtils.decrypt(secret, SystemProperties.SALT);
+// if (null == timeStr) {
+// return R.error("婵�娲荤爜閿欒");
+// }
+// Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+// if (new Date().getTime() >= exprTime.getTime()) {
+// return R.error("婵�娲荤爜宸插け鏁�");
+// }
+// boolean result = SystemProperties.saveActivationCode(OSinfo.getOSname().getActivationCodePath(), secret);
+// if (!result) {
+// return R.error("婵�娲诲け璐�");
+// }
+// SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE;
+// return R.ok("婵�娲绘垚鍔燂紝鏈夋晥鏈熻嚦" + DateUtils.convert(exprTime));
+// }
}
diff --git a/src/main/java/com/zy/system/service/ConfigService.java b/src/main/java/com/zy/system/service/ConfigService.java
index 6100b23..87e9627 100644
--- a/src/main/java/com/zy/system/service/ConfigService.java
+++ b/src/main/java/com/zy/system/service/ConfigService.java
@@ -6,4 +6,7 @@
public interface ConfigService extends IService<Config> {
Config selectConfigByCode(String code);
+
+ <T> T getVal(String key, Class<T> clazz, T t);
+
}
diff --git a/src/main/java/com/zy/system/service/impl/ConfigServiceImpl.java b/src/main/java/com/zy/system/service/impl/ConfigServiceImpl.java
index 749de96..4ab9ef4 100644
--- a/src/main/java/com/zy/system/service/impl/ConfigServiceImpl.java
+++ b/src/main/java/com/zy/system/service/impl/ConfigServiceImpl.java
@@ -1,12 +1,15 @@
package com.zy.system.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.core.common.Cools;
import com.zy.system.entity.Config;
import com.zy.system.mapper.ConfigMapper;
import com.zy.system.service.ConfigService;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service("configService")
+@Slf4j
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {
@Override
@@ -14,6 +17,44 @@
return this.baseMapper.selectConfigByCode(code);
}
- ;
+ /**
+ * 鑾峰彇閰嶇疆淇℃伅
+ *
+ * @param key 閿��
+ * @param clazz 绫诲瀷
+ * @param t 榛樿鍊�
+ * @param <T>
+ * @return
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getVal(String key, Class<T> clazz, T t) {
+ try {
+ Config config = this.baseMapper.selectConfigByCode(key);
+ if (config == null || config.getStatus() != 1 || Cools.isEmpty(config.getValue())) {
+ return t;
+ }
+ String val = config.getValue();
+ if (clazz.equals(Boolean.class)) {
+ if (val.equals("1") || val.trim().equalsIgnoreCase("TRUE")) {
+ return (T) Boolean.TRUE;
+ }
+ return (T) Boolean.FALSE;
+ } else if (clazz.equals(Integer.class)) {
+ return (T) Integer.valueOf(val);
+ } else if (clazz.equals(String.class)) {
+ return (T) val;
+ } else if (clazz.equals(Short.class)) {
+ return (T) Short.valueOf(val);
+ } else if (clazz.equals(Long.class)) {
+ return (T) Long.valueOf(val);
+ } else if (clazz.equals(Double.class)) {
+ return (T) Double.valueOf(val);
+ }
+ } catch (Exception e) {
+ log.error("鍙傛暟鍔犺浇寮傚父,閰嶇疆鍙傛暟={}", key);
+ }
+ return t;
+ }
}
diff --git a/src/main/java/com/zy/system/timer/LoadingConfigTimer.java b/src/main/java/com/zy/system/timer/LoadingConfigTimer.java
new file mode 100644
index 0000000..c5f5a02
--- /dev/null
+++ b/src/main/java/com/zy/system/timer/LoadingConfigTimer.java
@@ -0,0 +1,39 @@
+package com.zy.system.timer;
+
+import com.zy.system.service.ConfigService;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * 瀹氭椂浠诲姟璇诲彇閰嶇疆淇℃伅
+ */
+@Component
+@Slf4j
+@Data
+public class LoadingConfigTimer {
+
+ /**
+ * token鏈夋晥鏈熸椂闂�
+ */
+ private Integer tokenExpire = 1000 * 30 * 60;
+ /**
+ * token鏁伴噺闄愬埗
+ */
+ private Integer tokenNumber = 1;
+
+
+
+ @Autowired
+ private ConfigService configService;
+
+ @Scheduled(cron = "0/2 * * * * ? ")
+ public void timer() {
+ tokenExpire = configService.getVal("tokenExpire", Integer.class, tokenExpire);
+ tokenNumber = configService.getVal("tokenNumber", Integer.class, tokenNumber);
+
+ }
+
+}
diff --git a/src/main/java/com/zy/system/timer/TokenTimer.java b/src/main/java/com/zy/system/timer/TokenTimer.java
new file mode 100644
index 0000000..b44ad2a
--- /dev/null
+++ b/src/main/java/com/zy/system/timer/TokenTimer.java
@@ -0,0 +1,50 @@
+package com.zy.system.timer;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.Cools;
+import com.zy.system.entity.UserLogin;
+import com.zy.system.service.UserLoginService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * token瀹氭椂浠诲姟,鍒犻櫎杩囨湡鐨則oken
+ */
+@Component
+@Slf4j
+public class TokenTimer {
+
+ @Autowired
+ private UserLoginService userLoginService;
+
+ @Autowired
+ private LoadingConfigTimer loadingConfigTimer;
+
+ @Value("${super.pwd}")
+ private String superPwd;
+
+ @Scheduled(cron = "0/30 * * * * ? ")
+ public void timer() {
+ if (loadingConfigTimer.getTokenNumber() == 1) {
+ return;
+ }
+ List<UserLogin> userLogins = userLoginService.selectList(new EntityWrapper<>());
+ for (UserLogin userLogin : userLogins) {
+ String deToken = Cools.deTokn(userLogin.getToken(), superPwd);
+ if (deToken != null) {
+ long timestamp = Long.parseLong(deToken.substring(0, 13));
+ // 鍗婂皬鏃跺悗杩囨湡
+ if (System.currentTimeMillis() - timestamp > loadingConfigTimer.getTokenExpire()) {
+ userLoginService.deleteById(userLogin.getId());
+ }
+
+ }
+ }
+ }
+
+}
--
Gitblit v1.9.1