From 057f3ddb9ffd4684a10427eb9e3f7d7b764049ca Mon Sep 17 00:00:00 2001 From: wangbing Date: Wed, 22 Jan 2020 23:21:10 +0800 Subject: [PATCH] Task Former-commit-id: f44fa1b74559ddf8b6aa4445c078921209cf2aa0 --- .../manger/callable/SpringBootCallable.java | 30 ++++++++++++- .../module/system/mgr/TokensManagerImpl.java | 2 +- .../SpringBoot/java/task/TokenTask.java | 44 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/modules/SpringBoot/java/task/TokenTask.java diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 532d7d41..f2e9a201 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -112,10 +112,14 @@ public class SpringBootCallable implements Callable { } } - // base 和 frame等内容 + // frame等内容 System.out.println("生成模块:frame"); generateFrame(Tool.createPath(domainDir.getAbsolutePath(), "frame"), project, dataBase, option); + // Task + System.out.println("生成模块:task"); + generateTask(Tool.createPath(domainDir.getAbsolutePath(), "task"), project, dataBase, option); + // Application System.out.println("生成模块:Application"); generateApplication(Tool.createPath(domainDir.getAbsolutePath()), project, dataBase, option); @@ -565,6 +569,30 @@ public class SpringBootCallable implements Callable { } } + + /** + * 生成frame类 + * + * @param root + * @param project + */ + public void generateTask(File root, Project project, DataBase dataBase, String option) { + if (!root.exists()) { + root.mkdirs(); + } else { + Tool.clear(root); + } + HashMap ctx = new HashMap(); + ctx.put("basePackage", project.getProjectBasePackage()); + ctx.put("moduleName", project.getProjectName()); + ctx.put("timestamp", new Date().getTime()); + + //task + for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/task/")) { + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), name), option + "/java/task/" + name, ctx); + } + } + /** * 生成base类 * diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/TokensManagerImpl.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/TokensManagerImpl.java index dfa58e68..2b7a0ab0 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/TokensManagerImpl.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/TokensManagerImpl.java @@ -278,7 +278,7 @@ public class TokensManagerImpl implements xyz.wbsite.module.system.mgr.TokensMan return response; } - if (request.getToken().equals(LocalData.getToken().getToken())) { + if (request.getToken().equals(token.getToken())) { response.addError(ErrorType.BUSINESS_ERROR, "无法注销当前登录用户!"); return response; } diff --git a/src/main/resources/modules/SpringBoot/java/task/TokenTask.java b/src/main/resources/modules/SpringBoot/java/task/TokenTask.java new file mode 100644 index 00000000..ad31ba92 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/task/TokenTask.java @@ -0,0 +1,44 @@ +package ${basePackage}.task; + +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.schedule.RunDelayRepeatTask; +import ${basePackage}.module.system.ent.Tokens; +import ${basePackage}.module.system.mgr.TokensManager; +import ${basePackage}.module.system.req.TokensFindRequest; +import ${basePackage}.module.system.req.TokensLogoutRequest; +import ${basePackage}.module.system.rsp.TokensFindResponse; +import ${basePackage}.module.system.rsp.TokensLogoutResponse; + +import java.time.Duration; +import java.util.Date; + +public class TokenTask extends RunDelayRepeatTask { + + @Override + public String taskId() { + return "task1"; + } + + @Override + public Duration interval() { + return Duration.ofMinutes(1); + } + + @Override + public void run() { + TokensManager tokensManager = LocalData.getBean(TokensManager.class); + TokensFindRequest tokensFindRequest = new TokensFindRequest(); + tokensFindRequest.setPageSize(0); + tokensFindRequest.setValid(true); + TokensFindResponse tokensFindResponse = tokensManager.find(tokensFindRequest, LocalData.getSysToken()); + + Date current = new Date(); + for (Tokens tokens : tokensFindResponse.getResult()) { + if (tokens.getValidTime().before(current)) { + TokensLogoutRequest tokensLogoutRequest = new TokensLogoutRequest(); + tokensLogoutRequest.setToken(tokens.getToken()); + TokensLogoutResponse tokensLogoutResponse = tokensManager.logout(tokensLogoutRequest, LocalData.getSysToken()); + } + } + } +}