From 02a2bb8536d13ed5aa6110ec63d39cab78314ea6 Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Mon, 15 Apr 2019 21:16:20 +0800
Subject: [PATCH 01/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=86=E5=AF=B9java-?=
=?UTF-8?q?mail=E7=9A=84=E5=B0=81=E8=A3=85=E3=80=82=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E4=BA=86=E6=B3=A8=E9=87=8A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../util/constant/common/ModifyEnum.java | 1 +
.../util/constant/common/OperationEnum.java | 1 +
.../java/frodez/util/error/ErrorCode.java | 5 +
.../java/frodez/util/http/ServletUtil.java | 2 +-
src/main/java/frodez/util/json/JSONUtil.java | 5 +-
src/main/java/frodez/util/mail/MailUtil.java | 175 ------------------
.../java/frodez/util/reflect/BeanUtil.java | 10 +-
7 files changed, 20 insertions(+), 179 deletions(-)
delete mode 100644 src/main/java/frodez/util/mail/MailUtil.java
diff --git a/src/main/java/frodez/util/constant/common/ModifyEnum.java b/src/main/java/frodez/util/constant/common/ModifyEnum.java
index 4b0e003..5f55d81 100644
--- a/src/main/java/frodez/util/constant/common/ModifyEnum.java
+++ b/src/main/java/frodez/util/constant/common/ModifyEnum.java
@@ -7,6 +7,7 @@
/**
* 修改操作类型枚举
+ * @see OperationEnum
* @author Frodez
* @date 2019-03-17
*/
diff --git a/src/main/java/frodez/util/constant/common/OperationEnum.java b/src/main/java/frodez/util/constant/common/OperationEnum.java
index 4e518b6..57500d8 100644
--- a/src/main/java/frodez/util/constant/common/OperationEnum.java
+++ b/src/main/java/frodez/util/constant/common/OperationEnum.java
@@ -7,6 +7,7 @@
/**
* 操作类型枚举
+ * @see ModifyEnum
* @author Frodez
* @date 2019-03-17
*/
diff --git a/src/main/java/frodez/util/error/ErrorCode.java b/src/main/java/frodez/util/error/ErrorCode.java
index 9b55f9c..7cfed4c 100644
--- a/src/main/java/frodez/util/error/ErrorCode.java
+++ b/src/main/java/frodez/util/error/ErrorCode.java
@@ -5,6 +5,11 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
+/**
+ * 异常相关枚举
+ * @author Frodez
+ * @date 2019-04-15
+ */
@Getter
@AllArgsConstructor
public enum ErrorCode {
diff --git a/src/main/java/frodez/util/http/ServletUtil.java b/src/main/java/frodez/util/http/ServletUtil.java
index c7cfc3a..acd6d1a 100644
--- a/src/main/java/frodez/util/http/ServletUtil.java
+++ b/src/main/java/frodez/util/http/ServletUtil.java
@@ -13,7 +13,7 @@
import org.springframework.util.Assert;
/**
- * HTTP工具类
+ * Servlet工具类
* @author Frodez
* @date 2018-12-21
*/
diff --git a/src/main/java/frodez/util/json/JSONUtil.java b/src/main/java/frodez/util/json/JSONUtil.java
index edd4cc6..2433d62 100644
--- a/src/main/java/frodez/util/json/JSONUtil.java
+++ b/src/main/java/frodez/util/json/JSONUtil.java
@@ -26,7 +26,10 @@
import org.springframework.util.Assert;
/**
- * json工具类
+ * json工具类
+ * 本工具类使用的ObjectMapper是jackson的springboot-starter所自动配置得到的,不会使得项目中引入两个不同的ObjectMapper。
+ * 本工具类对html字符的转义做了专门处理。
+ * 本工具类大量采用缓存,可较大程度上提高速度。
* @author Frodez
* @date 2018-11-27
*/
diff --git a/src/main/java/frodez/util/mail/MailUtil.java b/src/main/java/frodez/util/mail/MailUtil.java
deleted file mode 100644
index 27b5172..0000000
--- a/src/main/java/frodez/util/mail/MailUtil.java
+++ /dev/null
@@ -1,175 +0,0 @@
-package frodez.util.mail;
-
-import frodez.util.constant.setting.PropertyKey;
-import frodez.util.io.CircularByteBuffer;
-import frodez.util.spring.ContextUtil;
-import frodez.util.spring.PropertyUtil;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import javax.annotation.PostConstruct;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.mail.SimpleMailMessage;
-import org.springframework.mail.javamail.JavaMailSender;
-import org.springframework.mail.javamail.MimeMessageHelper;
-import org.springframework.stereotype.Component;
-import org.springframework.util.Assert;
-
-/**
- * 邮件工具类
- * 警告!!!如果要使用本类的方法,必须确保MailUtil已经被初始化!
- * 方式:在使用本方法的类上加入@DependsOn("mailUtil")注解。
- * @author Frodez
- * @date 2019-03-27
- */
-@Lazy
-@Component("mailUtil")
-public class MailUtil {
-
- private static JavaMailSender mailSender;
-
- @PostConstruct
- private void init() {
- mailSender = ContextUtil.get(JavaMailSender.class);
- Assert.notNull(mailSender, "mailSender must not be null");
- }
-
- /**
- * 获取mailSender
- * @author Frodez
- * @date 2019-03-27
- */
- public static JavaMailSender mailSender() {
- return mailSender;
- }
-
- /**
- * 获取设置的自己的邮箱
- * @author Frodez
- * @date 2019-03-27
- */
- public static String ownUser() {
- return PropertyUtil.get(PropertyKey.Mail.OWN_USER);
- }
-
- /**
- * 发送邮件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void send(String from, String to, String subject, String text) {
- Assert.notNull(from, "from must not be null");
- Assert.notNull(to, "to must not be null");
- Assert.notNull(subject, "subject must not be null");
- Assert.notNull(text, "text must not be null");
- SimpleMailMessage message = new SimpleMailMessage();
- message.setFrom(from);
- message.setTo(to);
- message.setSubject(subject);
- message.setText(text);
- mailSender.send(message);
- }
-
- /**
- * 发送邮件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void send(SimpleMailMessage message) {
- Assert.notNull(message, "message must not be null");
- mailSender.send(message);
- }
-
- /**
- * 发送邮件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void send(MimeMessage message) {
- Assert.notNull(message, "message must not be null");
- mailSender.send(message);
- }
-
- /**
- * 发送邮件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void send(MimeMessageHelper messageHelper) {
- Assert.notNull(messageHelper, "messageHelper must not be null");
- mailSender.send(messageHelper.getMimeMessage());
- }
-
- /**
- * 添加附件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void attach(MimeMessageHelper messageHelper, String attachmentName, byte[] attachment) {
- try {
- messageHelper.addAttachment(attachmentName, new ByteArrayResource(attachment));
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * 添加附件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void attach(MimeMessageHelper messageHelper, String attachmentName, CircularByteBuffer buffer) {
- try {
- messageHelper.addAttachment(attachmentName, new ByteArrayResource(buffer.getInputStream().readAllBytes()));
- } catch (MessagingException | IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * 添加附件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void attach(MimeMessageHelper messageHelper, String attachmentName, ByteArrayOutputStream stream) {
- try {
- messageHelper.addAttachment(attachmentName, new ByteArrayResource(stream.toByteArray()));
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * 发送邮件
- * @author Frodez
- * @date 2019-03-27
- */
- public static void sendWithAttachments(String from, String to, String subject, String text, String... filePaths) {
- Assert.notNull(from, "from must not be null");
- Assert.notNull(to, "to must not be null");
- Assert.notNull(subject, "subject must not be null");
- Assert.notNull(text, "text must not be null");
- Assert.notNull(filePaths, "filePaths must not be null");
- try {
- MimeMessage message = mailSender.createMimeMessage();
- MimeMessageHelper helper = new MimeMessageHelper(message, true);
- helper.setFrom(from);
- helper.setTo(to);
- helper.setSubject(subject);
- helper.setText(text);
- for (String filePath : filePaths) {
- FileSystemResource resource = new FileSystemResource(filePath);
- String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
- helper.addAttachment(fileName, resource);
- }
- mailSender.send(message);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/src/main/java/frodez/util/reflect/BeanUtil.java b/src/main/java/frodez/util/reflect/BeanUtil.java
index e6ab8ea..696b7c5 100644
--- a/src/main/java/frodez/util/reflect/BeanUtil.java
+++ b/src/main/java/frodez/util/reflect/BeanUtil.java
@@ -114,7 +114,10 @@ public static T as(Map map, Class klass) {
}
/**
- * 清空bean的默认值
+ * 清空bean的默认值
+ * 如果只需要一个全新的无默认值的对象,建议使用BeanUtil.clearInstance方法,
+ * 原因是本方法会对所有字段执行其setter方法(无法确保只有存在默认值的字段拥有值),开销更大。
+ * @see BeanUtil#clearInstance(Class)
* @author Frodez
* @param
* @date 2019-02-08
@@ -174,7 +177,10 @@ private static List getDefaultNotNullSetters(Object bean) {
}
/**
- * 获取无默认值的bean,推荐使用本方法,比新建一个对象然后使用BeanUtil.clear更快。
+ * 获取无默认值的bean。
+ * 推荐使用本方法,比新建一个对象然后使用BeanUtil.clear更快,
+ * 原因是本方法只会执行存在默认值的字段的setter方法,方法执行的开销减小。
+ * @see BeanUtil#clear(Object)
* @author Frodez
* @param
* @date 2019-02-08
From cc4fbff7c900ddc2ef7731a8d2d3e070a7602cd7 Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 00:37:07 +0800
Subject: [PATCH 02/11] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=BC=82=E6=AD=A5?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/frodez/config/async/AsyncConfig.java | 41 ++++++++
.../frodez/config/async/AsyncProperties.java | 44 +++++++++
.../controller/user/PermissionController.java | 18 +++-
.../controller/user/RoleController.java | 19 +++-
.../dao/mapper/user/RolePermissionMapper.xml | 18 ++--
.../user/facade/IAuthorityService.java | 17 ++--
.../service/user/impl/AuthorityService.java | 93 +++++++++++--------
.../java/frodez/util/beans/result/Result.java | 11 +++
.../resources/settings/dev/async.properties | 5 +
.../resources/settings/prod/async.properties | 5 +
.../settings/release/async.properties | 5 +
.../resources/settings/test/async.properties | 5 +
12 files changed, 219 insertions(+), 62 deletions(-)
create mode 100644 src/main/java/frodez/config/async/AsyncConfig.java
create mode 100644 src/main/java/frodez/config/async/AsyncProperties.java
create mode 100644 src/main/resources/settings/dev/async.properties
create mode 100644 src/main/resources/settings/prod/async.properties
create mode 100644 src/main/resources/settings/release/async.properties
create mode 100644 src/main/resources/settings/test/async.properties
diff --git a/src/main/java/frodez/config/async/AsyncConfig.java b/src/main/java/frodez/config/async/AsyncConfig.java
new file mode 100644
index 0000000..5325b93
--- /dev/null
+++ b/src/main/java/frodez/config/async/AsyncConfig.java
@@ -0,0 +1,41 @@
+package frodez.config.async;
+
+import frodez.util.spring.ContextUtil;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+/**
+ * 异步配置
+ * @author Frodez
+ * @date 2019-04-15
+ */
+@Slf4j
+@EnableAsync
+@Configuration
+public class AsyncConfig {
+
+ @Bean
+ public Executor getAsyncExecutor() {
+ AsyncProperties properties = ContextUtil.get(AsyncProperties.class);
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ int availableProcessors = Runtime.getRuntime().availableProcessors();
+ int corePoolSize = Math.round(availableProcessors * properties.getCoreThreadTimes());
+ int maxPoolSize = Math.round(availableProcessors * properties.getMaxThreadTimes());
+ int queueCapacity = Math.round(maxPoolSize * properties.getQueueFactors());
+ executor.setCorePoolSize(corePoolSize);
+ executor.setMaxPoolSize(maxPoolSize);
+ executor.setQueueCapacity(queueCapacity);
+ executor.setKeepAliveSeconds(properties.getKeepAliveSeconds());
+ executor.setThreadNamePrefix(properties.getThreadNamePrefix());
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+ executor.initialize();
+ log.info("async executor is running now!");
+ return executor;
+ }
+
+}
diff --git a/src/main/java/frodez/config/async/AsyncProperties.java b/src/main/java/frodez/config/async/AsyncProperties.java
new file mode 100644
index 0000000..4a20117
--- /dev/null
+++ b/src/main/java/frodez/config/async/AsyncProperties.java
@@ -0,0 +1,44 @@
+package frodez.config.async;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.stereotype.Component;
+
+/**
+ * 异步任务配置
+ * @author Frodez
+ * @date 2019-04-15
+ */
+@Data
+@Component
+@PropertySource(value = { "classpath:settings/${spring.profiles.active}/async.properties" })
+@ConfigurationProperties(prefix = "async")
+public class AsyncProperties {
+
+ /**
+ * 核心线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
+ */
+ private float coreThreadTimes = 0.5F;
+
+ /**
+ * 最大线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
+ */
+ private float maxThreadTimes = 1.0F;
+
+ /**
+ * 队列规模因子,队列最大长度等于计算出的最大线程数乘以规模因子并四舍五入。
+ */
+ private float queueFactors = 16.0F;
+
+ /**
+ * 线程最长活跃时间,单位为秒
+ */
+ private int keepAliveSeconds = 60;
+
+ /**
+ * 线程名前缀
+ */
+ private String threadNamePrefix = "async";
+
+}
diff --git a/src/main/java/frodez/controller/user/PermissionController.java b/src/main/java/frodez/controller/user/PermissionController.java
index d768216..e1365ae 100644
--- a/src/main/java/frodez/controller/user/PermissionController.java
+++ b/src/main/java/frodez/controller/user/PermissionController.java
@@ -63,19 +63,31 @@ public Result getRolePermissions(@RequestBody @ApiParam(value = "权限信息获
@DeleteMapping
@ApiOperation(value = "删除权限接口")
public Result removePermission(@RequestParam("id") @ApiParam(value = "权限ID", required = true) Long id) {
- return authorityService.removePermission(id);
+ try {
+ return authorityService.removePermission(id).get();
+ } catch (Exception e) {
+ return Result.errorService();
+ }
}
@PostMapping("/add")
@ApiOperation(value = "添加新权限接口")
public Result addPermission(@RequestBody @ApiParam(value = "新增权限请求参数", required = true) AddPermission param) {
- return authorityService.addPermission(param);
+ try {
+ return authorityService.addPermission(param).get();
+ } catch (Exception e) {
+ return Result.errorService();
+ }
}
@PostMapping("/update")
@ApiOperation(value = "修改权限接口")
public Result updatePermission(@RequestBody @ApiParam(value = "修改权限请求参数", required = true) UpdatePermission param) {
- return authorityService.updatePermission(param);
+ try {
+ return authorityService.updatePermission(param).get();
+ } catch (Exception e) {
+ return Result.errorService();
+ }
}
}
diff --git a/src/main/java/frodez/controller/user/RoleController.java b/src/main/java/frodez/controller/user/RoleController.java
index ded4ed1..e69efed 100644
--- a/src/main/java/frodez/controller/user/RoleController.java
+++ b/src/main/java/frodez/controller/user/RoleController.java
@@ -14,6 +14,7 @@
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import java.util.concurrent.ExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -46,13 +47,15 @@ public Result getRole(@RequestParam("id") @ApiParam(value = "角色ID", required
/**
* 分页查询角色信息
* @author Frodez
+ * @throws InterruptedException
+ * @throws ExecutionException
* @date 2019-03-06
*/
@GetMapping("/page")
@ApiOperation(value = "分页查询角色信息接口")
@ApiResponses(value = { @ApiResponse(code = 200, message = "成功", response = Role.class) })
- public Result getRoles(@RequestBody @ApiParam(value = DefDesc.Message.PAGE_QUERY,
- required = true) QueryPage param) {
+ public Result getRoles(@RequestBody @ApiParam(value = DefDesc.Message.PAGE_QUERY, required = true) QueryPage param)
+ throws InterruptedException, ExecutionException {
return authorityService.getRoles(param);
}
@@ -60,13 +63,21 @@ public Result getRoles(@RequestBody @ApiParam(value = DefDesc.Message.PAGE_QUERY
@ApiOperation(value = "修改角色权限接口")
public Result updateRolePermission(@RequestBody @ApiParam(value = "修改角色权限请求参数",
required = true) UpdateRolePermission param) {
- return authorityService.updateRolePermission(param);
+ try {
+ return authorityService.updateRolePermission(param).get();
+ } catch (Exception e) {
+ return Result.errorService();
+ }
}
@DeleteMapping
@ApiOperation(value = "删除角色接口")
public Result removeRole(@RequestParam("id") @ApiParam(value = "角色ID", required = true) Long id) {
- return authorityService.removeRole(id);
+ try {
+ return authorityService.removeRole(id).get();
+ } catch (Exception e) {
+ return Result.errorService();
+ }
}
@PostMapping("/add")
diff --git a/src/main/java/frodez/dao/mapper/user/RolePermissionMapper.xml b/src/main/java/frodez/dao/mapper/user/RolePermissionMapper.xml
index 963760a..2c4af7b 100644
--- a/src/main/java/frodez/dao/mapper/user/RolePermissionMapper.xml
+++ b/src/main/java/frodez/dao/mapper/user/RolePermissionMapper.xml
@@ -1,8 +1,8 @@
-
-
\ No newline at end of file
diff --git a/src/main/java/frodez/service/user/facade/IAuthorityService.java b/src/main/java/frodez/service/user/facade/IAuthorityService.java
index 369d83a..1a50427 100644
--- a/src/main/java/frodez/service/user/facade/IAuthorityService.java
+++ b/src/main/java/frodez/service/user/facade/IAuthorityService.java
@@ -10,6 +10,7 @@
import frodez.util.beans.result.Result;
import frodez.util.constant.annotation.ServiceOnly;
import java.util.List;
+import org.springframework.util.concurrent.ListenableFuture;
/**
* 权限信息服务
@@ -59,7 +60,7 @@ public interface IAuthorityService {
* @date 2019-03-16
*/
@ServiceOnly
- Result refreshUserInfoByIds(List userIds, boolean includeFobiddens);
+ ListenableFuture refreshUserInfoByIds(List userIds, boolean includeFobiddens);
/**
* 根据用户名更新用户基本信息
@@ -67,7 +68,7 @@ public interface IAuthorityService {
* @date 2019-03-16
*/
@ServiceOnly
- Result refreshUserInfoByNames(List userNames, boolean includeFobiddens);
+ ListenableFuture refreshUserInfoByNames(List userNames, boolean includeFobiddens);
/**
* 获取权限信息
@@ -123,41 +124,41 @@ public interface IAuthorityService {
* @author Frodez
* @date 2019-03-15
*/
- Result addPermission(AddPermission param);
+ ListenableFuture addPermission(AddPermission param);
/**
* 修改权限
* @author Frodez
* @date 2019-03-17
*/
- Result updatePermission(UpdatePermission param);
+ ListenableFuture updatePermission(UpdatePermission param);
/**
* 修改角色权限
* @author Frodez
* @date 2019-03-15
*/
- Result updateRolePermission(UpdateRolePermission param);
+ ListenableFuture updateRolePermission(UpdateRolePermission param);
/**
* 删除角色
* @author Frodez
* @date 2019-03-18
*/
- Result removeRole(Long roleId);
+ ListenableFuture removeRole(Long roleId);
/**
* 删除权限
* @author Frodez
* @date 2019-03-18
*/
- Result removePermission(Long permissionId);
+ ListenableFuture removePermission(Long permissionId);
/**
* 扫描系统中所有端点并添加权限
* @author Frodez
* @date 2019-03-18
*/
- Result scanAndCreatePermissions();
+ ListenableFuture scanAndCreatePermissions();
}
diff --git a/src/main/java/frodez/service/user/impl/AuthorityService.java b/src/main/java/frodez/service/user/impl/AuthorityService.java
index e3f3c62..30c5f62 100644
--- a/src/main/java/frodez/service/user/impl/AuthorityService.java
+++ b/src/main/java/frodez/service/user/impl/AuthorityService.java
@@ -59,8 +59,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@@ -227,8 +229,9 @@ public Result getUserInfosByNames(@NotEmpty List userNames, boolean incl
}
@Check
+ @Async
@Override
- public Result refreshUserInfoByIds(@NotEmpty List userIds, boolean includeFobiddens) {
+ public ListenableFuture refreshUserInfoByIds(@NotEmpty List userIds, boolean includeFobiddens) {
try {
Example example = new Example(User.class);
example.createCriteria().andIn("id", userIds);
@@ -237,19 +240,20 @@ public Result refreshUserInfoByIds(@NotEmpty List userIds, boolean include
}
List users = userMapper.selectByExample(example);
if (users.size() != userIds.size()) {
- return Result.fail("存在非法的用户ID!");
+ return Result.fail("存在非法的用户ID!").async();
}
refreshUserInfo(getUserInfos(users));
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[refreshUserInfoByIds]", e);
- return Result.errorService();
+ return Result.errorService().async();
}
}
@Check
+ @Async
@Override
- public Result refreshUserInfoByNames(@NotEmpty List userNames, boolean includeFobiddens) {
+ public ListenableFuture refreshUserInfoByNames(@NotEmpty List userNames, boolean includeFobiddens) {
try {
Example example = new Example(User.class);
example.createCriteria().andIn("name", userNames);
@@ -258,13 +262,13 @@ public Result refreshUserInfoByNames(@NotEmpty List userNames, boolean i
}
List users = userMapper.selectByExample(example);
if (users.size() != userNames.size()) {
- return Result.fail("存在非法的用户名!");
+ return Result.fail("存在非法的用户名!").async();
}
refreshUserInfo(getUserInfos(users));
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[refreshUserInfoByNames]", e);
- return Result.errorService();
+ return Result.errorService().async();
}
}
@@ -310,9 +314,12 @@ private void refreshUserInfo(List userInfos) {
stream.forEach((item) -> {
userIdCache.save(item.getId(), item);
nameCache.save(item.getName(), item);
- tokenCache.save(tokenCache.getTokenByCondition((iter) -> {
+ String token = tokenCache.getTokenByCondition((iter) -> {
return iter.getId().equals(item.getId());
- }), item);
+ });
+ if (token != null) {
+ tokenCache.save(token, item);
+ }
});
}
@@ -469,24 +476,25 @@ private boolean checkPermissionName(String name) {
}
@Check
+ @Async
@Transactional
@Override
- public Result addPermission(@Valid @NotNull AddPermission param) {
+ public ListenableFuture addPermission(@Valid @NotNull AddPermission param) {
try {
if (checkPermissionName(param.getName())) {
- return Result.fail("权限不能重名!");
+ return Result.fail("权限不能重名!").async();
}
if (URLMatcher.isPermitAllPath(param.getUrl())) {
- return Result.fail("免验证路径不能配备权限!");
+ return Result.fail("免验证路径不能配备权限!").async();
}
if (!checkPermissionUrl(PermissionTypeEnum.of(param.getType()), param.getUrl())) {
- return Result.fail("系统不存在与此匹配的url!");
+ return Result.fail("系统不存在与此匹配的url!").async();
}
Permission permission = new Permission();
BeanUtil.copy(param, permission);
permission.setCreateTime(new Date());
permissionMapper.insert(permission);
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[addPermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -497,29 +505,30 @@ public Result addPermission(@Valid @NotNull AddPermission param) {
}
@Check
+ @Async
@Transactional
@Override
- public Result updatePermission(@Valid @NotNull UpdatePermission param) {
+ public ListenableFuture updatePermission(@Valid @NotNull UpdatePermission param) {
try {
if (param.getType() == null && param.getUrl() != null || param.getType() != null && param
.getUrl() == null) {
- return Result.errorRequest("类型和url必须同时存在!");
+ return Result.errorRequest("类型和url必须同时存在!").async();
}
if (param.getUrl() != null && URLMatcher.isPermitAllPath(param.getUrl())) {
- return Result.fail("免验证路径不能配备权限!");
+ return Result.fail("免验证路径不能配备权限!").async();
}
if (!checkPermissionUrl(PermissionTypeEnum.of(param.getType()), param.getUrl())) {
- return Result.fail("系统不存在与此匹配的url!");
+ return Result.fail("系统不存在与此匹配的url!").async();
}
Permission permission = permissionMapper.selectByPrimaryKey(param.getId());
if (permission == null) {
- return Result.fail("找不到该权限!");
+ return Result.fail("找不到该权限!").async();
}
if (param.getName() != null && checkPermissionName(param.getName())) {
- return Result.fail("权限不能重名!");
+ return Result.fail("权限不能重名!").async();
}
permissionMapper.updateByPrimaryKeySelective(BeanUtil.initialize(param, Permission.class));
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[addPermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -568,16 +577,17 @@ private boolean checkPermissionUrl(PermissionTypeEnum type, String url) {
}
@Check
+ @Async
@Transactional
@Override
- public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
+ public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
try {
if (ModifyEnum.UPDATE.getVal() != param.getOperationType() && EmptyUtil.yes(param.getPermissionIds())) {
- return Result.errorRequest("不能对角色新增或者删除一个空的权限!");
+ return Result.errorRequest("不能对角色新增或者删除一个空的权限!").async();
}
Role role = roleMapper.selectByPrimaryKey(param.getRoleId());
if (role == null) {
- return Result.fail("找不到该角色!");
+ return Result.fail("找不到该角色!").async();
}
switch (ModifyEnum.of(param.getOperationType())) {
case INSERT : {
@@ -586,13 +596,13 @@ public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
List permissionIds = permissionMapper.selectByExample(example).stream().map(Permission::getId)
.collect(Collectors.toList());
if (permissionIds.size() != param.getPermissionIds().size()) {
- return Result.fail("存在错误的权限!");
+ return Result.fail("存在错误的权限!").async();
}
example = new Example(RolePermission.class);
example.createCriteria().andIn("permissionId", param.getPermissionIds()).andEqualTo("roleId", param
.getRoleId());
if (rolePermissionMapper.selectCountByExample(example) != 0) {
- return Result.fail("不能添加已拥有的权限!");
+ return Result.fail("不能添加已拥有的权限!").async();
}
Date date = new Date();
List rolePermissions = param.getPermissionIds().stream().map((iter) -> {
@@ -610,7 +620,7 @@ public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
example.createCriteria().andIn("permissionId", param.getPermissionIds()).andEqualTo("roleId", param
.getRoleId());
if (rolePermissionMapper.selectCountByExample(example) != param.getPermissionIds().size()) {
- return Result.fail("存在错误的权限!");
+ return Result.fail("存在错误的权限!").async();
}
rolePermissionMapper.deleteByExample(example);
break;
@@ -620,7 +630,7 @@ public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
Example example = new Example(Permission.class);
example.createCriteria().andIn("id", param.getPermissionIds());
if (permissionMapper.selectCountByExample(example) != param.getPermissionIds().size()) {
- return Result.fail("存在错误的权限!");
+ return Result.fail("存在错误的权限!").async();
}
}
Example example = new Example(RolePermission.class);
@@ -646,7 +656,7 @@ public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
Example example = new Example(User.class);
example.createCriteria().andEqualTo("roleId", param.getRoleId());
refreshUserInfo(getUserInfos(userMapper.selectByExample(example)));
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[setRolePermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -657,24 +667,25 @@ public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
}
@Check
+ @Async
@Transactional
@Override
- public Result removeRole(@NotNull Long roleId) {
+ public ListenableFuture removeRole(@NotNull Long roleId) {
try {
Role role = roleMapper.selectByPrimaryKey(roleId);
if (role == null) {
- return Result.fail("找不到该角色!");
+ return Result.fail("找不到该角色!").async();
}
Example example = new Example(User.class);
example.createCriteria().andEqualTo("roleId", roleId);
if (userMapper.selectCountByExample(example) != 0) {
- return Result.fail("仍存在使用该角色的用户,请更改该用户角色后再删除!");
+ return Result.fail("仍存在使用该角色的用户,请更改该用户角色后再删除!").async();
}
roleMapper.deleteByPrimaryKey(roleId);
example = new Example(RolePermission.class);
example.createCriteria().andEqualTo("roleId", roleId);
rolePermissionMapper.deleteByExample(example);
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[removeRole]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -685,22 +696,23 @@ public Result removeRole(@NotNull Long roleId) {
}
@Check
+ @Async
@Transactional
@Override
- public Result removePermission(@NotNull Long permissionId) {
+ public ListenableFuture removePermission(@NotNull Long permissionId) {
try {
Permission permission = permissionMapper.selectByPrimaryKey(permissionId);
if (permission == null) {
- return Result.fail("找不到该权限!");
+ return Result.fail("找不到该权限!").async();
}
Example example = new Example(RolePermission.class);
example.createCriteria().andEqualTo("permissionId", permissionId);
if (rolePermissionMapper.selectCountByExample(example) != 0) {
- return Result.fail("仍存在使用该权限的角色,请更改该角色权限后再删除!");
+ return Result.fail("仍存在使用该权限的角色,请更改该角色权限后再删除!").async();
}
rolePermissionMapper.deleteByExample(example);
permissionMapper.deleteByPrimaryKey(permissionId);
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[removePermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -710,9 +722,10 @@ public Result removePermission(@NotNull Long permissionId) {
}
}
+ @Async
@Transactional
@Override
- public Result scanAndCreatePermissions() {
+ public ListenableFuture scanAndCreatePermissions() {
try {
List permissionList = new ArrayList<>();
Date date = new Date();
@@ -750,7 +763,7 @@ public Result scanAndCreatePermissions() {
permissionList.add(permission);
});
permissionMapper.insertList(permissionList);
- return Result.success();
+ return Result.success().async();
} catch (Exception e) {
log.error("[scanAndCreatePermissions]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
diff --git a/src/main/java/frodez/util/beans/result/Result.java b/src/main/java/frodez/util/beans/result/Result.java
index c724a04..b9b32a0 100644
--- a/src/main/java/frodez/util/beans/result/Result.java
+++ b/src/main/java/frodez/util/beans/result/Result.java
@@ -20,7 +20,9 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.http.HttpStatus;
+import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.util.Assert;
+import org.springframework.util.concurrent.ListenableFuture;
/**
* 通用返回参数
@@ -434,6 +436,15 @@ public HttpStatus httpStatus() {
return ResultEnum.of(code).status;
}
+ /**
+ * 使用异步包装
+ * @author Frodez
+ * @date 2019-04-16
+ */
+ public ListenableFuture async() {
+ return new AsyncResult<>(this);
+ }
+
private void ableAndNotNull() {
if (code != ResultEnum.SUCCESS.val) {
throw new UnsupportedOperationException(message);
diff --git a/src/main/resources/settings/dev/async.properties b/src/main/resources/settings/dev/async.properties
new file mode 100644
index 0000000..348e3b5
--- /dev/null
+++ b/src/main/resources/settings/dev/async.properties
@@ -0,0 +1,5 @@
+async.core-thread-times=0.5
+async.max-thread-times=1.0
+async.queue-factors=20.0
+async.keep-alive-seconds=60
+async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/prod/async.properties b/src/main/resources/settings/prod/async.properties
new file mode 100644
index 0000000..db6d969
--- /dev/null
+++ b/src/main/resources/settings/prod/async.properties
@@ -0,0 +1,5 @@
+async.core-thread-times=0.5
+async.max-thread-times=1.0
+async.queue-factors=16.0
+async.keep-alive-seconds=60
+async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/release/async.properties b/src/main/resources/settings/release/async.properties
new file mode 100644
index 0000000..db6d969
--- /dev/null
+++ b/src/main/resources/settings/release/async.properties
@@ -0,0 +1,5 @@
+async.core-thread-times=0.5
+async.max-thread-times=1.0
+async.queue-factors=16.0
+async.keep-alive-seconds=60
+async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/test/async.properties b/src/main/resources/settings/test/async.properties
new file mode 100644
index 0000000..db6d969
--- /dev/null
+++ b/src/main/resources/settings/test/async.properties
@@ -0,0 +1,5 @@
+async.core-thread-times=0.5
+async.max-thread-times=1.0
+async.queue-factors=16.0
+async.keep-alive-seconds=60
+async.thread-name-prefix=async
\ No newline at end of file
From de522927ceea2c9f15703b0506c16e12d041e84d Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 01:01:17 +0800
Subject: [PATCH 03/11] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97?=
=?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81,=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A,=E5=88=A0=E9=99=A4https=E7=9B=B8=E5=85=B3?=
=?UTF-8?q?=E9=85=8D=E7=BD=AE(https=E5=BB=BA=E8=AE=AE=E7=94=B1nginx?=
=?UTF-8?q?=E4=B9=8B=E7=B1=BB=E5=8D=8F=E5=8A=A9=E5=AE=9E=E7=8E=B0)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../frodez/config/cache/CacheProperties.java | 33 ++++++++++++++++++
.../frodez/config/font/FontProperties.java | 3 ++
.../controller/user/PermissionController.java | 5 +++
.../controller/user/RoleController.java | 8 +++--
src/main/resources/application.yml | 13 +------
.../resources/settings/dev/async.properties | 7 +++-
src/main/resources/settings/dev/https.jks | Bin 2236 -> 0 bytes
.../resources/settings/prod/async.properties | 5 +++
src/main/resources/settings/prod/https.jks | Bin 2236 -> 0 bytes
.../settings/release/async.properties | 5 +++
src/main/resources/settings/release/https.jks | Bin 2236 -> 0 bytes
.../resources/settings/test/async.properties | 5 +++
src/main/resources/settings/test/https.jks | Bin 2236 -> 0 bytes
13 files changed, 69 insertions(+), 15 deletions(-)
delete mode 100644 src/main/resources/settings/dev/https.jks
delete mode 100644 src/main/resources/settings/prod/https.jks
delete mode 100644 src/main/resources/settings/release/https.jks
delete mode 100644 src/main/resources/settings/test/https.jks
diff --git a/src/main/java/frodez/config/cache/CacheProperties.java b/src/main/java/frodez/config/cache/CacheProperties.java
index 91b4e0d..1dc2bbc 100644
--- a/src/main/java/frodez/config/cache/CacheProperties.java
+++ b/src/main/java/frodez/config/cache/CacheProperties.java
@@ -16,19 +16,37 @@
@ConfigurationProperties(prefix = "cache")
public class CacheProperties {
+ /**
+ * 标准配置
+ */
private StandardProperties standard = new StandardProperties();
+ /**
+ * AutoGuavaChecker配置
+ */
private AutoGuavaCheckerProperties autoGuavaChecker = new AutoGuavaCheckerProperties();
+ /**
+ * ManualGuavaChecker配置
+ */
private ManualGuavaCheckerProperties manualGuavaChecker = new ManualGuavaCheckerProperties();
+ /**
+ * LimitUserGuavaChecker配置
+ */
private LimitUserGuavaCheckerProperties limitUserGuavaChecker = new LimitUserGuavaCheckerProperties();
+ /**
+ * URLMatcher配置
+ */
private URLMatcherProperties urlMatcher = new URLMatcherProperties();
@Data
public static class StandardProperties {
+ /**
+ * 超时时间,单位毫秒
+ */
private Integer timeout = 60000;
}
@@ -36,6 +54,9 @@ public static class StandardProperties {
@Data
public static class AutoGuavaCheckerProperties {
+ /**
+ * 超时时间,单位毫秒
+ */
private Integer timeout = 60000;
}
@@ -43,6 +64,9 @@ public static class AutoGuavaCheckerProperties {
@Data
public static class ManualGuavaCheckerProperties {
+ /**
+ * 超时时间,单位毫秒
+ */
private Integer timeout = 60000;
}
@@ -50,6 +74,9 @@ public static class ManualGuavaCheckerProperties {
@Data
public static class LimitUserGuavaCheckerProperties {
+ /**
+ * 超时时间,单位毫秒
+ */
private Integer timeout = 60000;
}
@@ -57,8 +84,14 @@ public static class LimitUserGuavaCheckerProperties {
@Data
public static class URLMatcherProperties {
+ /**
+ * 超时时间,单位毫秒
+ */
private Integer timeout = 3600000;
+ /**
+ * 缓存最大容量
+ */
private Integer maxSize = 65536;
}
diff --git a/src/main/java/frodez/config/font/FontProperties.java b/src/main/java/frodez/config/font/FontProperties.java
index 154850b..73a8a92 100644
--- a/src/main/java/frodez/config/font/FontProperties.java
+++ b/src/main/java/frodez/config/font/FontProperties.java
@@ -18,6 +18,9 @@
@ConfigurationProperties(prefix = "font")
public class FontProperties {
+ /**
+ * 字体存放路径
+ */
private String path = "";
/**
diff --git a/src/main/java/frodez/controller/user/PermissionController.java b/src/main/java/frodez/controller/user/PermissionController.java
index e1365ae..5c5345f 100644
--- a/src/main/java/frodez/controller/user/PermissionController.java
+++ b/src/main/java/frodez/controller/user/PermissionController.java
@@ -15,6 +15,7 @@
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -29,6 +30,7 @@
* @author Frodez
* @date 2018-12-01
*/
+@Slf4j
@RestController
@RequestMapping("/permission")
@Api(tags = "用户权限信息控制器")
@@ -66,6 +68,7 @@ public Result removePermission(@RequestParam("id") @ApiParam(value = "权限ID",
try {
return authorityService.removePermission(id).get();
} catch (Exception e) {
+ log.error("[removePermission]", e);
return Result.errorService();
}
}
@@ -76,6 +79,7 @@ public Result addPermission(@RequestBody @ApiParam(value = "新增权限请求
try {
return authorityService.addPermission(param).get();
} catch (Exception e) {
+ log.error("[addPermission]", e);
return Result.errorService();
}
}
@@ -86,6 +90,7 @@ public Result updatePermission(@RequestBody @ApiParam(value = "修改权限请
try {
return authorityService.updatePermission(param).get();
} catch (Exception e) {
+ log.error("[updatePermission]", e);
return Result.errorService();
}
}
diff --git a/src/main/java/frodez/controller/user/RoleController.java b/src/main/java/frodez/controller/user/RoleController.java
index e69efed..cdbefa2 100644
--- a/src/main/java/frodez/controller/user/RoleController.java
+++ b/src/main/java/frodez/controller/user/RoleController.java
@@ -15,6 +15,7 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.concurrent.ExecutionException;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -29,6 +30,7 @@
* @author Frodez
* @date 2018-12-01
*/
+@Slf4j
@RestController
@RequestMapping("/role")
@Api(tags = "用户角色信息控制器")
@@ -54,8 +56,8 @@ public Result getRole(@RequestParam("id") @ApiParam(value = "角色ID", required
@GetMapping("/page")
@ApiOperation(value = "分页查询角色信息接口")
@ApiResponses(value = { @ApiResponse(code = 200, message = "成功", response = Role.class) })
- public Result getRoles(@RequestBody @ApiParam(value = DefDesc.Message.PAGE_QUERY, required = true) QueryPage param)
- throws InterruptedException, ExecutionException {
+ public Result getRoles(@RequestBody @ApiParam(value = DefDesc.Message.PAGE_QUERY,
+ required = true) QueryPage param) {
return authorityService.getRoles(param);
}
@@ -66,6 +68,7 @@ public Result updateRolePermission(@RequestBody @ApiParam(value = "修改角色
try {
return authorityService.updateRolePermission(param).get();
} catch (Exception e) {
+ log.error("[updateRolePermission]", e);
return Result.errorService();
}
}
@@ -76,6 +79,7 @@ public Result removeRole(@RequestParam("id") @ApiParam(value = "角色ID", requi
try {
return authorityService.removeRole(id).get();
} catch (Exception e) {
+ log.error("[removeRole]", e);
return Result.errorService();
}
}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 4ae7a27..caf4dfc 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,14 +1,3 @@
spring:
profiles:
- active: dev
-
-#不在此处理https,建议使用nginx
- #ssl:
- #在jdk目录下使用keytool.命令如下:
- #.\keytool.exe -genkey -alias Frodez -keyalg RSA -keysize 2048 -keypass
- #Frodez -keystore https.keystore -storepass 123456 -validity 3650
- #-dname "cn=Frodez,ou=Frodez,o=beijing,l=beijing,st=beijing,c=cn"
- #enabled: true
- #key-store: classpath:settings/https.jks
- #key-store-password: 123456
- #key-password: 123456
\ No newline at end of file
+ active: dev
\ No newline at end of file
diff --git a/src/main/resources/settings/dev/async.properties b/src/main/resources/settings/dev/async.properties
index 348e3b5..fc3cf48 100644
--- a/src/main/resources/settings/dev/async.properties
+++ b/src/main/resources/settings/dev/async.properties
@@ -1,5 +1,10 @@
+#核心线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.core-thread-times=0.5
+#最大线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.max-thread-times=1.0
-async.queue-factors=20.0
+#队列规模因子,队列最大长度等于计算出的最大线程数乘以规模因子并四舍五入。
+async.queue-factors=16.0
+#线程最长活跃时间,单位为秒
async.keep-alive-seconds=60
+#线程名前缀
async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/dev/https.jks b/src/main/resources/settings/dev/https.jks
deleted file mode 100644
index dd5b2db45a22ec00a035bbb84e23574639d3c18c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 2236
zcmchYXHXN^9>vq?MG_#OR1rcE5~R6Ek&Ytj0@9QgLR(4F5trugMn(=^s>OG>l?2L{i^vZ@}B
zP;O1;GW71BKe~X+O<3x*ue}$tx)NP33(G?gGMIM807-Dx=p%Obw2tSk4K02Smh(?W
zY!(>EiqqAbO+d;t1SzM-xf_ukKDMYMGHX|`+IUAk{Ohj6_x>vd>Y;M)ZI)
z{X5z1z2e2NM5L2CC1XO*Gf<&HNb{J~pDw;|&1C&9)oqW95Hp)p)W6$6gDV!gVmh9H
z20jHv-MB800v>KQx(~I~O%n^=ip>p5KE4t`yZCL>w4&_c97&6Kvot_&cU4ODIF^dW`kQg~7aEeQ7{xR>cJqj|)mvFxe_nP}?s&N7q=y
zNmrduAX_pr4}nmP+2ER*raG~`Fv{;H~rVN>Y$%dhAq2t>68
z0jKJ$$>P5pApf?zmTSYeK=jCDu$Yq%)xtw_I$Odj81pcoH<6`R_?SDh%1PbcrQ9t<
zc8wm+;u~b07dw9MPEvUt&OUTTkm~Mg!znHe%nA_xo~+5|aBvuquWDK~k*Q1m6#oIhpJ5bINUgG=88)9{>r&w;I>X
z-iNl{dlT5=F6^}wa%9hen!~^8Dq<4mV~(8$pBOD^*Df;ec{=xOPvKJt*BPEm1gxEH
z=AGeD`(vmpz759o`yolb>X14iwwu;WKz2R(kUIV@rfiOvTBE{kK(aM^H_YMOT$w=j
zX-8a1Wpq!@EgP4%#S&yirQ0ju+)KHMH~-9m_K(5K?I5tm+86*Fq=;@oa8n
z`=nKrANOvzV+o+~IrXcj_yFQp<$l|}g!~XWtUHsGkv>WR9rZ0p#U)V%Zl!SPWXJ9J
zcqRKQm8ZE{4L8xjV}o*dH2PHiT2HeFAG?shTdjtzSyV{NGcWy~zR+mcyvnsn-k3m%
zF1(2mYaN-bTfyhUIdAI$n1SF6onW$d+sy++YpBizg|~aN;bPz~6cX>O{HshPzPq6b
zHK=$$k+eEG^s4XEGQE3JEP3+{v0Y+a-!$bm&vi%LR~B^^h;6Twi}hCdMh_6@2*x!P1XV|^!q|tu;j|kyxulk|C3%i-ps{ALQ^iF;Va7^
zOPl)`>LN;g_Ug0Gsp7Ujln~8q=L`BG(U(BNYa;lFXR+dz7E1Q)|#Z6!XYTZq3x8
zyOJ&HExwAS#fPY67ir2j2O6ohsS5hqqb_1h#;v~ZI5Dsa|NM*`Az3?2#wTJr;v{(4
zQ0j-Rv5-D-G_v22??bQVE^NV4HbQ?i<;B#~7aEW4vhFhL$2TSXY(}VstRng{008zz
z6Tx0+BFH=!3<82ckn2TLwP-dNlT?&J)Bzh1$N~kRT`=ruRv6d}0)s=bF0P*T7|zoQ
zJ@t%m1_zw0o2#euKZN0b2=jjl$LYnVr&!=Hy`Q~|`5S=$0cb&9Hq2$Tyu30-0dpCn
zY{kna{~xRHxBWl9ga{PG&w
zIzs-gCx1x&5a+8CCD~Z>7{kso!ScfJM|Ri5s(X@YczllswNPJjAZf;TWvh)mUuewx
zhLw{qb$VCXfCqV7PU(Rq+cZUVmLZ&m6jD`
z2#0FvuH$#MhaTqXci~G}UcP?k-RC!(tW6(E0D*x3V7>@i2rY0rQvr4e4+Ih6%{yDL
zyX*%28pKa471Wxjuuu4Rh^M=B8X^!NWkXML+;xerLtp=GUtD)bo7>Ux?bM@9tDu2;
z0Yc6qJEY@bW`b2%yXyDLabquUWZ|5M`K`YftLD#+orw^AnuA+PT@^R}
z;)&NjKTjxD{SuZuf_BpFJLg|tp^_KZ{&C!~tvP_fgwpC(a+Wh@m}9@}f_+7&F}CKW
zV787wrA)xqWrHz%sJ5ymjV7t*?yNMIJ8(O4n0?saPM?dsMc_h;?_;X)^9?g!os7kh
sAlt5n>aAE$ol@pT`Vm0ueW@N&`i4<{@Cox`VOdIeu##h1+U@ec0Io3Ou>b%7
diff --git a/src/main/resources/settings/prod/async.properties b/src/main/resources/settings/prod/async.properties
index db6d969..fc3cf48 100644
--- a/src/main/resources/settings/prod/async.properties
+++ b/src/main/resources/settings/prod/async.properties
@@ -1,5 +1,10 @@
+#核心线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.core-thread-times=0.5
+#最大线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.max-thread-times=1.0
+#队列规模因子,队列最大长度等于计算出的最大线程数乘以规模因子并四舍五入。
async.queue-factors=16.0
+#线程最长活跃时间,单位为秒
async.keep-alive-seconds=60
+#线程名前缀
async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/prod/https.jks b/src/main/resources/settings/prod/https.jks
deleted file mode 100644
index dd5b2db45a22ec00a035bbb84e23574639d3c18c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 2236
zcmchYXHXN^9>vq?MG_#OR1rcE5~R6Ek&Ytj0@9QgLR(4F5trugMn(=^s>OG>l?2L{i^vZ@}B
zP;O1;GW71BKe~X+O<3x*ue}$tx)NP33(G?gGMIM807-Dx=p%Obw2tSk4K02Smh(?W
zY!(>EiqqAbO+d;t1SzM-xf_ukKDMYMGHX|`+IUAk{Ohj6_x>vd>Y;M)ZI)
z{X5z1z2e2NM5L2CC1XO*Gf<&HNb{J~pDw;|&1C&9)oqW95Hp)p)W6$6gDV!gVmh9H
z20jHv-MB800v>KQx(~I~O%n^=ip>p5KE4t`yZCL>w4&_c97&6Kvot_&cU4ODIF^dW`kQg~7aEeQ7{xR>cJqj|)mvFxe_nP}?s&N7q=y
zNmrduAX_pr4}nmP+2ER*raG~`Fv{;H~rVN>Y$%dhAq2t>68
z0jKJ$$>P5pApf?zmTSYeK=jCDu$Yq%)xtw_I$Odj81pcoH<6`R_?SDh%1PbcrQ9t<
zc8wm+;u~b07dw9MPEvUt&OUTTkm~Mg!znHe%nA_xo~+5|aBvuquWDK~k*Q1m6#oIhpJ5bINUgG=88)9{>r&w;I>X
z-iNl{dlT5=F6^}wa%9hen!~^8Dq<4mV~(8$pBOD^*Df;ec{=xOPvKJt*BPEm1gxEH
z=AGeD`(vmpz759o`yolb>X14iwwu;WKz2R(kUIV@rfiOvTBE{kK(aM^H_YMOT$w=j
zX-8a1Wpq!@EgP4%#S&yirQ0ju+)KHMH~-9m_K(5K?I5tm+86*Fq=;@oa8n
z`=nKrANOvzV+o+~IrXcj_yFQp<$l|}g!~XWtUHsGkv>WR9rZ0p#U)V%Zl!SPWXJ9J
zcqRKQm8ZE{4L8xjV}o*dH2PHiT2HeFAG?shTdjtzSyV{NGcWy~zR+mcyvnsn-k3m%
zF1(2mYaN-bTfyhUIdAI$n1SF6onW$d+sy++YpBizg|~aN;bPz~6cX>O{HshPzPq6b
zHK=$$k+eEG^s4XEGQE3JEP3+{v0Y+a-!$bm&vi%LR~B^^h;6Twi}hCdMh_6@2*x!P1XV|^!q|tu;j|kyxulk|C3%i-ps{ALQ^iF;Va7^
zOPl)`>LN;g_Ug0Gsp7Ujln~8q=L`BG(U(BNYa;lFXR+dz7E1Q)|#Z6!XYTZq3x8
zyOJ&HExwAS#fPY67ir2j2O6ohsS5hqqb_1h#;v~ZI5Dsa|NM*`Az3?2#wTJr;v{(4
zQ0j-Rv5-D-G_v22??bQVE^NV4HbQ?i<;B#~7aEW4vhFhL$2TSXY(}VstRng{008zz
z6Tx0+BFH=!3<82ckn2TLwP-dNlT?&J)Bzh1$N~kRT`=ruRv6d}0)s=bF0P*T7|zoQ
zJ@t%m1_zw0o2#euKZN0b2=jjl$LYnVr&!=Hy`Q~|`5S=$0cb&9Hq2$Tyu30-0dpCn
zY{kna{~xRHxBWl9ga{PG&w
zIzs-gCx1x&5a+8CCD~Z>7{kso!ScfJM|Ri5s(X@YczllswNPJjAZf;TWvh)mUuewx
zhLw{qb$VCXfCqV7PU(Rq+cZUVmLZ&m6jD`
z2#0FvuH$#MhaTqXci~G}UcP?k-RC!(tW6(E0D*x3V7>@i2rY0rQvr4e4+Ih6%{yDL
zyX*%28pKa471Wxjuuu4Rh^M=B8X^!NWkXML+;xerLtp=GUtD)bo7>Ux?bM@9tDu2;
z0Yc6qJEY@bW`b2%yXyDLabquUWZ|5M`K`YftLD#+orw^AnuA+PT@^R}
z;)&NjKTjxD{SuZuf_BpFJLg|tp^_KZ{&C!~tvP_fgwpC(a+Wh@m}9@}f_+7&F}CKW
zV787wrA)xqWrHz%sJ5ymjV7t*?yNMIJ8(O4n0?saPM?dsMc_h;?_;X)^9?g!os7kh
sAlt5n>aAE$ol@pT`Vm0ueW@N&`i4<{@Cox`VOdIeu##h1+U@ec0Io3Ou>b%7
diff --git a/src/main/resources/settings/release/async.properties b/src/main/resources/settings/release/async.properties
index db6d969..fc3cf48 100644
--- a/src/main/resources/settings/release/async.properties
+++ b/src/main/resources/settings/release/async.properties
@@ -1,5 +1,10 @@
+#核心线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.core-thread-times=0.5
+#最大线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.max-thread-times=1.0
+#队列规模因子,队列最大长度等于计算出的最大线程数乘以规模因子并四舍五入。
async.queue-factors=16.0
+#线程最长活跃时间,单位为秒
async.keep-alive-seconds=60
+#线程名前缀
async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/release/https.jks b/src/main/resources/settings/release/https.jks
deleted file mode 100644
index dd5b2db45a22ec00a035bbb84e23574639d3c18c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 2236
zcmchYXHXN^9>vq?MG_#OR1rcE5~R6Ek&Ytj0@9QgLR(4F5trugMn(=^s>OG>l?2L{i^vZ@}B
zP;O1;GW71BKe~X+O<3x*ue}$tx)NP33(G?gGMIM807-Dx=p%Obw2tSk4K02Smh(?W
zY!(>EiqqAbO+d;t1SzM-xf_ukKDMYMGHX|`+IUAk{Ohj6_x>vd>Y;M)ZI)
z{X5z1z2e2NM5L2CC1XO*Gf<&HNb{J~pDw;|&1C&9)oqW95Hp)p)W6$6gDV!gVmh9H
z20jHv-MB800v>KQx(~I~O%n^=ip>p5KE4t`yZCL>w4&_c97&6Kvot_&cU4ODIF^dW`kQg~7aEeQ7{xR>cJqj|)mvFxe_nP}?s&N7q=y
zNmrduAX_pr4}nmP+2ER*raG~`Fv{;H~rVN>Y$%dhAq2t>68
z0jKJ$$>P5pApf?zmTSYeK=jCDu$Yq%)xtw_I$Odj81pcoH<6`R_?SDh%1PbcrQ9t<
zc8wm+;u~b07dw9MPEvUt&OUTTkm~Mg!znHe%nA_xo~+5|aBvuquWDK~k*Q1m6#oIhpJ5bINUgG=88)9{>r&w;I>X
z-iNl{dlT5=F6^}wa%9hen!~^8Dq<4mV~(8$pBOD^*Df;ec{=xOPvKJt*BPEm1gxEH
z=AGeD`(vmpz759o`yolb>X14iwwu;WKz2R(kUIV@rfiOvTBE{kK(aM^H_YMOT$w=j
zX-8a1Wpq!@EgP4%#S&yirQ0ju+)KHMH~-9m_K(5K?I5tm+86*Fq=;@oa8n
z`=nKrANOvzV+o+~IrXcj_yFQp<$l|}g!~XWtUHsGkv>WR9rZ0p#U)V%Zl!SPWXJ9J
zcqRKQm8ZE{4L8xjV}o*dH2PHiT2HeFAG?shTdjtzSyV{NGcWy~zR+mcyvnsn-k3m%
zF1(2mYaN-bTfyhUIdAI$n1SF6onW$d+sy++YpBizg|~aN;bPz~6cX>O{HshPzPq6b
zHK=$$k+eEG^s4XEGQE3JEP3+{v0Y+a-!$bm&vi%LR~B^^h;6Twi}hCdMh_6@2*x!P1XV|^!q|tu;j|kyxulk|C3%i-ps{ALQ^iF;Va7^
zOPl)`>LN;g_Ug0Gsp7Ujln~8q=L`BG(U(BNYa;lFXR+dz7E1Q)|#Z6!XYTZq3x8
zyOJ&HExwAS#fPY67ir2j2O6ohsS5hqqb_1h#;v~ZI5Dsa|NM*`Az3?2#wTJr;v{(4
zQ0j-Rv5-D-G_v22??bQVE^NV4HbQ?i<;B#~7aEW4vhFhL$2TSXY(}VstRng{008zz
z6Tx0+BFH=!3<82ckn2TLwP-dNlT?&J)Bzh1$N~kRT`=ruRv6d}0)s=bF0P*T7|zoQ
zJ@t%m1_zw0o2#euKZN0b2=jjl$LYnVr&!=Hy`Q~|`5S=$0cb&9Hq2$Tyu30-0dpCn
zY{kna{~xRHxBWl9ga{PG&w
zIzs-gCx1x&5a+8CCD~Z>7{kso!ScfJM|Ri5s(X@YczllswNPJjAZf;TWvh)mUuewx
zhLw{qb$VCXfCqV7PU(Rq+cZUVmLZ&m6jD`
z2#0FvuH$#MhaTqXci~G}UcP?k-RC!(tW6(E0D*x3V7>@i2rY0rQvr4e4+Ih6%{yDL
zyX*%28pKa471Wxjuuu4Rh^M=B8X^!NWkXML+;xerLtp=GUtD)bo7>Ux?bM@9tDu2;
z0Yc6qJEY@bW`b2%yXyDLabquUWZ|5M`K`YftLD#+orw^AnuA+PT@^R}
z;)&NjKTjxD{SuZuf_BpFJLg|tp^_KZ{&C!~tvP_fgwpC(a+Wh@m}9@}f_+7&F}CKW
zV787wrA)xqWrHz%sJ5ymjV7t*?yNMIJ8(O4n0?saPM?dsMc_h;?_;X)^9?g!os7kh
sAlt5n>aAE$ol@pT`Vm0ueW@N&`i4<{@Cox`VOdIeu##h1+U@ec0Io3Ou>b%7
diff --git a/src/main/resources/settings/test/async.properties b/src/main/resources/settings/test/async.properties
index db6d969..fc3cf48 100644
--- a/src/main/resources/settings/test/async.properties
+++ b/src/main/resources/settings/test/async.properties
@@ -1,5 +1,10 @@
+#核心线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.core-thread-times=0.5
+#最大线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。
async.max-thread-times=1.0
+#队列规模因子,队列最大长度等于计算出的最大线程数乘以规模因子并四舍五入。
async.queue-factors=16.0
+#线程最长活跃时间,单位为秒
async.keep-alive-seconds=60
+#线程名前缀
async.thread-name-prefix=async
\ No newline at end of file
diff --git a/src/main/resources/settings/test/https.jks b/src/main/resources/settings/test/https.jks
deleted file mode 100644
index dd5b2db45a22ec00a035bbb84e23574639d3c18c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 2236
zcmchYXHXN^9>vq?MG_#OR1rcE5~R6Ek&Ytj0@9QgLR(4F5trugMn(=^s>OG>l?2L{i^vZ@}B
zP;O1;GW71BKe~X+O<3x*ue}$tx)NP33(G?gGMIM807-Dx=p%Obw2tSk4K02Smh(?W
zY!(>EiqqAbO+d;t1SzM-xf_ukKDMYMGHX|`+IUAk{Ohj6_x>vd>Y;M)ZI)
z{X5z1z2e2NM5L2CC1XO*Gf<&HNb{J~pDw;|&1C&9)oqW95Hp)p)W6$6gDV!gVmh9H
z20jHv-MB800v>KQx(~I~O%n^=ip>p5KE4t`yZCL>w4&_c97&6Kvot_&cU4ODIF^dW`kQg~7aEeQ7{xR>cJqj|)mvFxe_nP}?s&N7q=y
zNmrduAX_pr4}nmP+2ER*raG~`Fv{;H~rVN>Y$%dhAq2t>68
z0jKJ$$>P5pApf?zmTSYeK=jCDu$Yq%)xtw_I$Odj81pcoH<6`R_?SDh%1PbcrQ9t<
zc8wm+;u~b07dw9MPEvUt&OUTTkm~Mg!znHe%nA_xo~+5|aBvuquWDK~k*Q1m6#oIhpJ5bINUgG=88)9{>r&w;I>X
z-iNl{dlT5=F6^}wa%9hen!~^8Dq<4mV~(8$pBOD^*Df;ec{=xOPvKJt*BPEm1gxEH
z=AGeD`(vmpz759o`yolb>X14iwwu;WKz2R(kUIV@rfiOvTBE{kK(aM^H_YMOT$w=j
zX-8a1Wpq!@EgP4%#S&yirQ0ju+)KHMH~-9m_K(5K?I5tm+86*Fq=;@oa8n
z`=nKrANOvzV+o+~IrXcj_yFQp<$l|}g!~XWtUHsGkv>WR9rZ0p#U)V%Zl!SPWXJ9J
zcqRKQm8ZE{4L8xjV}o*dH2PHiT2HeFAG?shTdjtzSyV{NGcWy~zR+mcyvnsn-k3m%
zF1(2mYaN-bTfyhUIdAI$n1SF6onW$d+sy++YpBizg|~aN;bPz~6cX>O{HshPzPq6b
zHK=$$k+eEG^s4XEGQE3JEP3+{v0Y+a-!$bm&vi%LR~B^^h;6Twi}hCdMh_6@2*x!P1XV|^!q|tu;j|kyxulk|C3%i-ps{ALQ^iF;Va7^
zOPl)`>LN;g_Ug0Gsp7Ujln~8q=L`BG(U(BNYa;lFXR+dz7E1Q)|#Z6!XYTZq3x8
zyOJ&HExwAS#fPY67ir2j2O6ohsS5hqqb_1h#;v~ZI5Dsa|NM*`Az3?2#wTJr;v{(4
zQ0j-Rv5-D-G_v22??bQVE^NV4HbQ?i<;B#~7aEW4vhFhL$2TSXY(}VstRng{008zz
z6Tx0+BFH=!3<82ckn2TLwP-dNlT?&J)Bzh1$N~kRT`=ruRv6d}0)s=bF0P*T7|zoQ
zJ@t%m1_zw0o2#euKZN0b2=jjl$LYnVr&!=Hy`Q~|`5S=$0cb&9Hq2$Tyu30-0dpCn
zY{kna{~xRHxBWl9ga{PG&w
zIzs-gCx1x&5a+8CCD~Z>7{kso!ScfJM|Ri5s(X@YczllswNPJjAZf;TWvh)mUuewx
zhLw{qb$VCXfCqV7PU(Rq+cZUVmLZ&m6jD`
z2#0FvuH$#MhaTqXci~G}UcP?k-RC!(tW6(E0D*x3V7>@i2rY0rQvr4e4+Ih6%{yDL
zyX*%28pKa471Wxjuuu4Rh^M=B8X^!NWkXML+;xerLtp=GUtD)bo7>Ux?bM@9tDu2;
z0Yc6qJEY@bW`b2%yXyDLabquUWZ|5M`K`YftLD#+orw^AnuA+PT@^R}
z;)&NjKTjxD{SuZuf_BpFJLg|tp^_KZ{&C!~tvP_fgwpC(a+Wh@m}9@}f_+7&F}CKW
zV787wrA)xqWrHz%sJ5ymjV7t*?yNMIJ8(O4n0?saPM?dsMc_h;?_;X)^9?g!os7kh
sAlt5n>aAE$ol@pT`Vm0ueW@N&`i4<{@Cox`VOdIeu##h1+U@ec0Io3Ou>b%7
From e4e45af9b0bd256d7980638e1b684b00ac46d4c1 Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 08:49:43 +0800
Subject: [PATCH 04/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/user/LoginController.java | 4 +-
.../controller/user/PermissionController.java | 23 +-----
.../controller/user/RoleController.java | 16 +---
.../user/facade/IAuthorityService.java | 17 ++--
.../service/user/impl/AuthorityService.java | 77 +++++++++----------
5 files changed, 53 insertions(+), 84 deletions(-)
diff --git a/src/main/java/frodez/controller/user/LoginController.java b/src/main/java/frodez/controller/user/LoginController.java
index 3f38b50..04bab40 100644
--- a/src/main/java/frodez/controller/user/LoginController.java
+++ b/src/main/java/frodez/controller/user/LoginController.java
@@ -74,8 +74,8 @@ public Result out() {
* @author Frodez
* @date 2019-02-27
*/
- @GetMapping("/userInfo")
- public Result getUserInfo(@RequestParam("userName") String userName) {
+ @GetMapping("/test")
+ public Result test(@RequestParam("userName") String userName) {
return authorityService.getUserInfo(userName);
}
diff --git a/src/main/java/frodez/controller/user/PermissionController.java b/src/main/java/frodez/controller/user/PermissionController.java
index 5c5345f..d768216 100644
--- a/src/main/java/frodez/controller/user/PermissionController.java
+++ b/src/main/java/frodez/controller/user/PermissionController.java
@@ -15,7 +15,6 @@
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -30,7 +29,6 @@
* @author Frodez
* @date 2018-12-01
*/
-@Slf4j
@RestController
@RequestMapping("/permission")
@Api(tags = "用户权限信息控制器")
@@ -65,34 +63,19 @@ public Result getRolePermissions(@RequestBody @ApiParam(value = "权限信息获
@DeleteMapping
@ApiOperation(value = "删除权限接口")
public Result removePermission(@RequestParam("id") @ApiParam(value = "权限ID", required = true) Long id) {
- try {
- return authorityService.removePermission(id).get();
- } catch (Exception e) {
- log.error("[removePermission]", e);
- return Result.errorService();
- }
+ return authorityService.removePermission(id);
}
@PostMapping("/add")
@ApiOperation(value = "添加新权限接口")
public Result addPermission(@RequestBody @ApiParam(value = "新增权限请求参数", required = true) AddPermission param) {
- try {
- return authorityService.addPermission(param).get();
- } catch (Exception e) {
- log.error("[addPermission]", e);
- return Result.errorService();
- }
+ return authorityService.addPermission(param);
}
@PostMapping("/update")
@ApiOperation(value = "修改权限接口")
public Result updatePermission(@RequestBody @ApiParam(value = "修改权限请求参数", required = true) UpdatePermission param) {
- try {
- return authorityService.updatePermission(param).get();
- } catch (Exception e) {
- log.error("[updatePermission]", e);
- return Result.errorService();
- }
+ return authorityService.updatePermission(param);
}
}
diff --git a/src/main/java/frodez/controller/user/RoleController.java b/src/main/java/frodez/controller/user/RoleController.java
index cdbefa2..4bb6ebf 100644
--- a/src/main/java/frodez/controller/user/RoleController.java
+++ b/src/main/java/frodez/controller/user/RoleController.java
@@ -15,7 +15,6 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.concurrent.ExecutionException;
-import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -30,7 +29,6 @@
* @author Frodez
* @date 2018-12-01
*/
-@Slf4j
@RestController
@RequestMapping("/role")
@Api(tags = "用户角色信息控制器")
@@ -65,23 +63,13 @@ public Result getRoles(@RequestBody @ApiParam(value = DefDesc.Message.PAGE_QUERY
@ApiOperation(value = "修改角色权限接口")
public Result updateRolePermission(@RequestBody @ApiParam(value = "修改角色权限请求参数",
required = true) UpdateRolePermission param) {
- try {
- return authorityService.updateRolePermission(param).get();
- } catch (Exception e) {
- log.error("[updateRolePermission]", e);
- return Result.errorService();
- }
+ return authorityService.updateRolePermission(param);
}
@DeleteMapping
@ApiOperation(value = "删除角色接口")
public Result removeRole(@RequestParam("id") @ApiParam(value = "角色ID", required = true) Long id) {
- try {
- return authorityService.removeRole(id).get();
- } catch (Exception e) {
- log.error("[removeRole]", e);
- return Result.errorService();
- }
+ return authorityService.removeRole(id);
}
@PostMapping("/add")
diff --git a/src/main/java/frodez/service/user/facade/IAuthorityService.java b/src/main/java/frodez/service/user/facade/IAuthorityService.java
index 1a50427..369d83a 100644
--- a/src/main/java/frodez/service/user/facade/IAuthorityService.java
+++ b/src/main/java/frodez/service/user/facade/IAuthorityService.java
@@ -10,7 +10,6 @@
import frodez.util.beans.result.Result;
import frodez.util.constant.annotation.ServiceOnly;
import java.util.List;
-import org.springframework.util.concurrent.ListenableFuture;
/**
* 权限信息服务
@@ -60,7 +59,7 @@ public interface IAuthorityService {
* @date 2019-03-16
*/
@ServiceOnly
- ListenableFuture refreshUserInfoByIds(List userIds, boolean includeFobiddens);
+ Result refreshUserInfoByIds(List userIds, boolean includeFobiddens);
/**
* 根据用户名更新用户基本信息
@@ -68,7 +67,7 @@ public interface IAuthorityService {
* @date 2019-03-16
*/
@ServiceOnly
- ListenableFuture refreshUserInfoByNames(List userNames, boolean includeFobiddens);
+ Result refreshUserInfoByNames(List userNames, boolean includeFobiddens);
/**
* 获取权限信息
@@ -124,41 +123,41 @@ public interface IAuthorityService {
* @author Frodez
* @date 2019-03-15
*/
- ListenableFuture addPermission(AddPermission param);
+ Result addPermission(AddPermission param);
/**
* 修改权限
* @author Frodez
* @date 2019-03-17
*/
- ListenableFuture updatePermission(UpdatePermission param);
+ Result updatePermission(UpdatePermission param);
/**
* 修改角色权限
* @author Frodez
* @date 2019-03-15
*/
- ListenableFuture updateRolePermission(UpdateRolePermission param);
+ Result updateRolePermission(UpdateRolePermission param);
/**
* 删除角色
* @author Frodez
* @date 2019-03-18
*/
- ListenableFuture removeRole(Long roleId);
+ Result removeRole(Long roleId);
/**
* 删除权限
* @author Frodez
* @date 2019-03-18
*/
- ListenableFuture removePermission(Long permissionId);
+ Result removePermission(Long permissionId);
/**
* 扫描系统中所有端点并添加权限
* @author Frodez
* @date 2019-03-18
*/
- ListenableFuture scanAndCreatePermissions();
+ Result scanAndCreatePermissions();
}
diff --git a/src/main/java/frodez/service/user/impl/AuthorityService.java b/src/main/java/frodez/service/user/impl/AuthorityService.java
index 30c5f62..5a2ed14 100644
--- a/src/main/java/frodez/service/user/impl/AuthorityService.java
+++ b/src/main/java/frodez/service/user/impl/AuthorityService.java
@@ -62,7 +62,6 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@@ -231,7 +230,7 @@ public Result getUserInfosByNames(@NotEmpty List userNames, boolean incl
@Check
@Async
@Override
- public ListenableFuture refreshUserInfoByIds(@NotEmpty List userIds, boolean includeFobiddens) {
+ public Result refreshUserInfoByIds(@NotEmpty List userIds, boolean includeFobiddens) {
try {
Example example = new Example(User.class);
example.createCriteria().andIn("id", userIds);
@@ -240,20 +239,20 @@ public ListenableFuture refreshUserInfoByIds(@NotEmpty List userId
}
List users = userMapper.selectByExample(example);
if (users.size() != userIds.size()) {
- return Result.fail("存在非法的用户ID!").async();
+ return Result.fail("存在非法的用户ID!");
}
refreshUserInfo(getUserInfos(users));
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[refreshUserInfoByIds]", e);
- return Result.errorService().async();
+ return Result.errorService();
}
}
@Check
@Async
@Override
- public ListenableFuture refreshUserInfoByNames(@NotEmpty List userNames, boolean includeFobiddens) {
+ public Result refreshUserInfoByNames(@NotEmpty List userNames, boolean includeFobiddens) {
try {
Example example = new Example(User.class);
example.createCriteria().andIn("name", userNames);
@@ -262,13 +261,13 @@ public ListenableFuture refreshUserInfoByNames(@NotEmpty List us
}
List users = userMapper.selectByExample(example);
if (users.size() != userNames.size()) {
- return Result.fail("存在非法的用户名!").async();
+ return Result.fail("存在非法的用户名!");
}
refreshUserInfo(getUserInfos(users));
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[refreshUserInfoByNames]", e);
- return Result.errorService().async();
+ return Result.errorService();
}
}
@@ -479,22 +478,22 @@ private boolean checkPermissionName(String name) {
@Async
@Transactional
@Override
- public ListenableFuture addPermission(@Valid @NotNull AddPermission param) {
+ public Result addPermission(@Valid @NotNull AddPermission param) {
try {
if (checkPermissionName(param.getName())) {
- return Result.fail("权限不能重名!").async();
+ return Result.fail("权限不能重名!");
}
if (URLMatcher.isPermitAllPath(param.getUrl())) {
- return Result.fail("免验证路径不能配备权限!").async();
+ return Result.fail("免验证路径不能配备权限!");
}
if (!checkPermissionUrl(PermissionTypeEnum.of(param.getType()), param.getUrl())) {
- return Result.fail("系统不存在与此匹配的url!").async();
+ return Result.fail("系统不存在与此匹配的url!");
}
Permission permission = new Permission();
BeanUtil.copy(param, permission);
permission.setCreateTime(new Date());
permissionMapper.insert(permission);
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[addPermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -508,27 +507,27 @@ public ListenableFuture addPermission(@Valid @NotNull AddPermission para
@Async
@Transactional
@Override
- public ListenableFuture updatePermission(@Valid @NotNull UpdatePermission param) {
+ public Result updatePermission(@Valid @NotNull UpdatePermission param) {
try {
if (param.getType() == null && param.getUrl() != null || param.getType() != null && param
.getUrl() == null) {
- return Result.errorRequest("类型和url必须同时存在!").async();
+ return Result.errorRequest("类型和url必须同时存在!");
}
if (param.getUrl() != null && URLMatcher.isPermitAllPath(param.getUrl())) {
- return Result.fail("免验证路径不能配备权限!").async();
+ return Result.fail("免验证路径不能配备权限!");
}
if (!checkPermissionUrl(PermissionTypeEnum.of(param.getType()), param.getUrl())) {
- return Result.fail("系统不存在与此匹配的url!").async();
+ return Result.fail("系统不存在与此匹配的url!");
}
Permission permission = permissionMapper.selectByPrimaryKey(param.getId());
if (permission == null) {
- return Result.fail("找不到该权限!").async();
+ return Result.fail("找不到该权限!");
}
if (param.getName() != null && checkPermissionName(param.getName())) {
- return Result.fail("权限不能重名!").async();
+ return Result.fail("权限不能重名!");
}
permissionMapper.updateByPrimaryKeySelective(BeanUtil.initialize(param, Permission.class));
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[addPermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -580,14 +579,14 @@ private boolean checkPermissionUrl(PermissionTypeEnum type, String url) {
@Async
@Transactional
@Override
- public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
+ public Result updateRolePermission(@Valid @NotNull UpdateRolePermission param) {
try {
if (ModifyEnum.UPDATE.getVal() != param.getOperationType() && EmptyUtil.yes(param.getPermissionIds())) {
- return Result.errorRequest("不能对角色新增或者删除一个空的权限!").async();
+ return Result.errorRequest("不能对角色新增或者删除一个空的权限!");
}
Role role = roleMapper.selectByPrimaryKey(param.getRoleId());
if (role == null) {
- return Result.fail("找不到该角色!").async();
+ return Result.fail("找不到该角色!");
}
switch (ModifyEnum.of(param.getOperationType())) {
case INSERT : {
@@ -596,13 +595,13 @@ public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRoleP
List permissionIds = permissionMapper.selectByExample(example).stream().map(Permission::getId)
.collect(Collectors.toList());
if (permissionIds.size() != param.getPermissionIds().size()) {
- return Result.fail("存在错误的权限!").async();
+ return Result.fail("存在错误的权限!");
}
example = new Example(RolePermission.class);
example.createCriteria().andIn("permissionId", param.getPermissionIds()).andEqualTo("roleId", param
.getRoleId());
if (rolePermissionMapper.selectCountByExample(example) != 0) {
- return Result.fail("不能添加已拥有的权限!").async();
+ return Result.fail("不能添加已拥有的权限!");
}
Date date = new Date();
List rolePermissions = param.getPermissionIds().stream().map((iter) -> {
@@ -620,7 +619,7 @@ public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRoleP
example.createCriteria().andIn("permissionId", param.getPermissionIds()).andEqualTo("roleId", param
.getRoleId());
if (rolePermissionMapper.selectCountByExample(example) != param.getPermissionIds().size()) {
- return Result.fail("存在错误的权限!").async();
+ return Result.fail("存在错误的权限!");
}
rolePermissionMapper.deleteByExample(example);
break;
@@ -630,7 +629,7 @@ public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRoleP
Example example = new Example(Permission.class);
example.createCriteria().andIn("id", param.getPermissionIds());
if (permissionMapper.selectCountByExample(example) != param.getPermissionIds().size()) {
- return Result.fail("存在错误的权限!").async();
+ return Result.fail("存在错误的权限!");
}
}
Example example = new Example(RolePermission.class);
@@ -656,7 +655,7 @@ public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRoleP
Example example = new Example(User.class);
example.createCriteria().andEqualTo("roleId", param.getRoleId());
refreshUserInfo(getUserInfos(userMapper.selectByExample(example)));
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[setRolePermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -670,22 +669,22 @@ public ListenableFuture updateRolePermission(@Valid @NotNull UpdateRoleP
@Async
@Transactional
@Override
- public ListenableFuture removeRole(@NotNull Long roleId) {
+ public Result removeRole(@NotNull Long roleId) {
try {
Role role = roleMapper.selectByPrimaryKey(roleId);
if (role == null) {
- return Result.fail("找不到该角色!").async();
+ return Result.fail("找不到该角色!");
}
Example example = new Example(User.class);
example.createCriteria().andEqualTo("roleId", roleId);
if (userMapper.selectCountByExample(example) != 0) {
- return Result.fail("仍存在使用该角色的用户,请更改该用户角色后再删除!").async();
+ return Result.fail("仍存在使用该角色的用户,请更改该用户角色后再删除!");
}
roleMapper.deleteByPrimaryKey(roleId);
example = new Example(RolePermission.class);
example.createCriteria().andEqualTo("roleId", roleId);
rolePermissionMapper.deleteByExample(example);
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[removeRole]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -699,20 +698,20 @@ public ListenableFuture removeRole(@NotNull Long roleId) {
@Async
@Transactional
@Override
- public ListenableFuture removePermission(@NotNull Long permissionId) {
+ public Result removePermission(@NotNull Long permissionId) {
try {
Permission permission = permissionMapper.selectByPrimaryKey(permissionId);
if (permission == null) {
- return Result.fail("找不到该权限!").async();
+ return Result.fail("找不到该权限!");
}
Example example = new Example(RolePermission.class);
example.createCriteria().andEqualTo("permissionId", permissionId);
if (rolePermissionMapper.selectCountByExample(example) != 0) {
- return Result.fail("仍存在使用该权限的角色,请更改该角色权限后再删除!").async();
+ return Result.fail("仍存在使用该权限的角色,请更改该角色权限后再删除!");
}
rolePermissionMapper.deleteByExample(example);
permissionMapper.deleteByPrimaryKey(permissionId);
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[removePermission]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
@@ -725,7 +724,7 @@ public ListenableFuture removePermission(@NotNull Long permissionId) {
@Async
@Transactional
@Override
- public ListenableFuture scanAndCreatePermissions() {
+ public Result scanAndCreatePermissions() {
try {
List permissionList = new ArrayList<>();
Date date = new Date();
@@ -763,7 +762,7 @@ public ListenableFuture scanAndCreatePermissions() {
permissionList.add(permission);
});
permissionMapper.insertList(permissionList);
- return Result.success().async();
+ return Result.success();
} catch (Exception e) {
log.error("[scanAndCreatePermissions]", e);
throw new ServiceException(ErrorCode.AUTHORITY_SERVICE_ERROR);
From 4e576d46c6e90dc01073fb64031e99a63db87bc3 Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 09:36:21 +0800
Subject: [PATCH 05/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/frodez/util/pdf/PDFConverter.java | 12 +++++++-----
.../{RenderUtil.java => FreemarkerRender.java} | 2 +-
.../frodez/util/renderer/reverter/CSSReverter.java | 4 ++--
3 files changed, 10 insertions(+), 8 deletions(-)
rename src/main/java/frodez/util/renderer/{RenderUtil.java => FreemarkerRender.java} (95%)
diff --git a/src/main/java/frodez/util/pdf/PDFConverter.java b/src/main/java/frodez/util/pdf/PDFConverter.java
index 8287f65..06e58f2 100644
--- a/src/main/java/frodez/util/pdf/PDFConverter.java
+++ b/src/main/java/frodez/util/pdf/PDFConverter.java
@@ -20,19 +20,20 @@
import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
+import org.springframework.util.concurrent.ListenableFuture;
/**
* PDF生成工具类
- * 警告!!!如果要使用本类的方法,必须确保PDFConverter已经被初始化!
- * 方式:在使用本方法的类上加入@DependsOn("PDFConverter")注解。
* @author Frodez
* @date 2019-03-27
*/
@Lazy
@Slf4j
-@Component("PDFConverter")
+@Component
public class PDFConverter {
private static Map fontCache = new HashMap<>();
@@ -64,7 +65,8 @@ public static Map fonts() {
* @author Frodez
* @date 2019-03-21
*/
- public static ByteArrayOutputStream convert(String html) throws IOException {
+ @Async
+ public ListenableFuture convert(String html) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ConverterProperties properties = new ConverterProperties();
DefaultFontProvider defaultFontProvider = new DefaultFontProvider(false, false, false);
@@ -75,7 +77,7 @@ public static ByteArrayOutputStream convert(String html) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(stream));
Document document = HtmlConverter.convertToDocument(html, pdf, properties);
document.close();
- return stream;
+ return new AsyncResult<>(stream);
}
}
diff --git a/src/main/java/frodez/util/renderer/RenderUtil.java b/src/main/java/frodez/util/renderer/FreemarkerRender.java
similarity index 95%
rename from src/main/java/frodez/util/renderer/RenderUtil.java
rename to src/main/java/frodez/util/renderer/FreemarkerRender.java
index 7fdd249..faf8a6d 100644
--- a/src/main/java/frodez/util/renderer/RenderUtil.java
+++ b/src/main/java/frodez/util/renderer/FreemarkerRender.java
@@ -26,7 +26,7 @@
*/
@Lazy
@Component("renderUtil")
-public class RenderUtil {
+public class FreemarkerRender {
private static Configuration configuration;
diff --git a/src/main/java/frodez/util/renderer/reverter/CSSReverter.java b/src/main/java/frodez/util/renderer/reverter/CSSReverter.java
index 31cae5a..d3d49e2 100644
--- a/src/main/java/frodez/util/renderer/reverter/CSSReverter.java
+++ b/src/main/java/frodez/util/renderer/reverter/CSSReverter.java
@@ -2,7 +2,7 @@
import frodez.util.common.StrUtil;
import frodez.util.io.FileUtil;
-import frodez.util.renderer.RenderUtil;
+import frodez.util.renderer.FreemarkerRender;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@@ -38,7 +38,7 @@ public String revert(String html) {
continue;
}
htmlElement.prepend(StrUtil.concat(""));
+ .getFile(StrUtil.concat(FreemarkerRender.getLoaderPath(), path))), ""));
}
links.remove();
return document.html();
From c4b4125ffd571acef0836861bd79c42bca3d0fe4 Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 09:53:17 +0800
Subject: [PATCH 06/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81,=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6?=
=?UTF-8?q?=E4=BB=BB=E5=8A=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../service/task/base/BaseTaskService.java | 1 -
.../util/renderer/FreemarkerRender.java | 4 +--
src/test/java/frodez/RenderTest.java | 25 +++++++++++++++++++
3 files changed, 26 insertions(+), 4 deletions(-)
create mode 100644 src/test/java/frodez/RenderTest.java
diff --git a/src/main/java/frodez/service/task/base/BaseTaskService.java b/src/main/java/frodez/service/task/base/BaseTaskService.java
index e467a21..6d07e7c 100644
--- a/src/main/java/frodez/service/task/base/BaseTaskService.java
+++ b/src/main/java/frodez/service/task/base/BaseTaskService.java
@@ -74,7 +74,6 @@ public class BaseTaskService {
@PostConstruct
private void init() {
try {
- scheduler.setWaitForTasksToCompleteOnShutdown(true);
taskServiceInfos = ContextUtil.gets(ITask.class).entrySet().stream().map((entry) -> {
AvailableTaskInfo info = new AvailableTaskInfo();
info.setName(entry.getKey());
diff --git a/src/main/java/frodez/util/renderer/FreemarkerRender.java b/src/main/java/frodez/util/renderer/FreemarkerRender.java
index faf8a6d..36109a3 100644
--- a/src/main/java/frodez/util/renderer/FreemarkerRender.java
+++ b/src/main/java/frodez/util/renderer/FreemarkerRender.java
@@ -13,7 +13,6 @@
import javax.annotation.PostConstruct;
import lombok.Getter;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerProperties;
-import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@@ -24,8 +23,7 @@
* @author Frodez
* @date 2019-03-27
*/
-@Lazy
-@Component("renderUtil")
+@Component
public class FreemarkerRender {
private static Configuration configuration;
diff --git a/src/test/java/frodez/RenderTest.java b/src/test/java/frodez/RenderTest.java
new file mode 100644
index 0000000..662e8ce
--- /dev/null
+++ b/src/test/java/frodez/RenderTest.java
@@ -0,0 +1,25 @@
+package frodez;
+
+import frodez.util.renderer.FreemarkerRender;
+import frodez.util.spring.ContextUtil;
+import org.springframework.boot.SpringApplication;
+
+public class RenderTest {
+
+ public static void main(String[] args) {
+ SpringApplication.run(BlogManagePlatformApplication.class, args);
+ int totalTimes = 100000;
+ int testTimes = 3;
+ for (int i = 1; i <= testTimes; i++) {
+ System.out.println("第" + i + "次测试开始!");
+ long start = System.currentTimeMillis();
+ for (int j = 0; j < totalTimes; j++) {
+ FreemarkerRender.render("test");
+ }
+ start = System.currentTimeMillis() - start;
+ System.out.println("第" + i + "次测试结束,测试次数" + totalTimes + "次,耗时" + start + "毫秒");
+ }
+ SpringApplication.exit(ContextUtil.context(), () -> 1);
+ }
+
+}
From f2a7c94645092ec9a4b5d4ae98bb85d825d7ae3a Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 10:25:53 +0800
Subject: [PATCH 07/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/frodez/util/common/StrUtil.java | 26 ++++++++++++-------
src/test/java/frodez/StringTest.java | 4 +--
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/main/java/frodez/util/common/StrUtil.java b/src/main/java/frodez/util/common/StrUtil.java
index c3a74f3..ff3de27 100644
--- a/src/main/java/frodez/util/common/StrUtil.java
+++ b/src/main/java/frodez/util/common/StrUtil.java
@@ -37,12 +37,12 @@ public static String get(@Nullable Object object) {
* @author Frodez
* @date 2019-04-01
*/
- public static String get(@Nullable Object object, CharSequence defaultStr) {
+ public static String get(@Nullable Object object, String defaultStr) {
if (object == null) {
if (defaultStr == null) {
throw new IllegalArgumentException();
}
- return defaultStr.toString();
+ return defaultStr;
}
if (object.getClass() == BigDecimal.class) {
return ((BigDecimal) object).setScale(DefDecimal.PRECISION, DefDecimal.ROUND_MODE).toString();
@@ -52,36 +52,40 @@ public static String get(@Nullable Object object, CharSequence defaultStr) {
/**
* 批量拼接字符串,对null会当作空字符串处理。
+ * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入)。这种情况可以极大地加快速度。
+ * 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
* 经测试,在绝大多数场景下相对jdk的实现更快(平均30%左右),在最坏情况下也与其相当。
* @see java.lang.String#concat(String)
* @author Frodez
* @date 2019-04-01
*/
- public static String concat(CharSequence... strings) {
+ public static String concat(String... strings) {
return concatWithDefault("", strings);
}
/**
* 批量拼接字符串,将null处理为默认字符串。默认字符串可以为空字符串,但不能为null。
+ * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入)。这种情况可以极大地加快速度。
+ * 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
* 经测试,在绝大多数场景下相对jdk的实现更快(平均30%左右),在最坏情况下也与其相当。
* @param defaultStr 为null时的默认字符串
* @see java.lang.String#concat(String)
* @author Frodez
* @date 2019-04-01
*/
- public static String concatWithDefault(CharSequence defaultStr, CharSequence... strings) {
+ public static String concatWithDefault(String defaultStr, String... strings) {
if (defaultStr == null || EmptyUtil.yes(strings)) {
throw new IllegalArgumentException();
}
if (strings.length == 1) {
- return strings[0] == null ? defaultStr.toString() : new String(strings[0].toString());
+ return strings[0] == null ? defaultStr : strings[0];
}
int size = 0;
- for (CharSequence string : strings) {
+ for (String string : strings) {
size = size + (string == null ? defaultStr.length() : string.length());
}
StringBuilder builder = new StringBuilder(size);
- for (CharSequence string : strings) {
+ for (String string : strings) {
if (string == null) {
builder.append(defaultStr);
} else {
@@ -93,6 +97,8 @@ public static String concatWithDefault(CharSequence defaultStr, CharSequence...
/**
* 批量连接字符串,中间有分隔符,可自定义字符串为null时的替代字符串。
+ * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入)。这种情况可以极大地加快速度。
+ * 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
* 不需要自定义null的替代字符串时,建议使用String.join方法。
* 测试表明,大部分情况下String.join的性能略强于本方法(15%以内),少数情况下本方法性能强于String.join。
* 替代字符串可以为空字符串,但不能为null。但是分隔符不能为null或者空字符串!!!
@@ -103,15 +109,15 @@ public static String concatWithDefault(CharSequence defaultStr, CharSequence...
* @author Frodez
* @date 2019-04-02
*/
- public static String join(CharSequence defaultStr, CharSequence delimiter, CharSequence... strings) {
+ public static String join(String defaultStr, String delimiter, String... strings) {
if (defaultStr == null || EmptyUtil.yes(delimiter) || EmptyUtil.yes(strings)) {
throw new IllegalArgumentException();
}
if (strings.length == 1) {
- return strings[0] == null ? defaultStr.toString() : new String(strings[0].toString());
+ return strings[0] == null ? defaultStr : strings[0];
}
int size = (strings.length - 1) * delimiter.length();
- for (CharSequence string : strings) {
+ for (String string : strings) {
size = size + (string == null ? defaultStr.length() : string.length());
}
StringBuilder builder = new StringBuilder(size);
diff --git a/src/test/java/frodez/StringTest.java b/src/test/java/frodez/StringTest.java
index c6796af..262077a 100644
--- a/src/test/java/frodez/StringTest.java
+++ b/src/test/java/frodez/StringTest.java
@@ -8,8 +8,8 @@ public class StringTest {
@SuppressWarnings("unused")
public static void main(String[] args) {
- int testTimes = 1000000;
- int arrayLength = 15;
+ int testTimes = 1000000000;
+ int arrayLength = 1;
int testRounds = 3;
String[] arr = new String[arrayLength];
for (int i = 0; i < arrayLength; i++) {
From 7b0fbeaa32754ea85162c3deef18bf6b48b7eeda Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 13:11:16 +0800
Subject: [PATCH 08/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7?=
=?UTF-8?q?=E7=B1=BB=E5=8A=9F=E8=83=BD=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/frodez/util/common/StrUtil.java | 41 +++++++++++++++++--
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/main/java/frodez/util/common/StrUtil.java b/src/main/java/frodez/util/common/StrUtil.java
index ff3de27..4d72373 100644
--- a/src/main/java/frodez/util/common/StrUtil.java
+++ b/src/main/java/frodez/util/common/StrUtil.java
@@ -52,7 +52,7 @@ public static String get(@Nullable Object object, String defaultStr) {
/**
* 批量拼接字符串,对null会当作空字符串处理。
- * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入)。这种情况可以极大地加快速度。
+ * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入且该字符串不为null)。这种情况可以极大地加快速度。
* 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
* 经测试,在绝大多数场景下相对jdk的实现更快(平均30%左右),在最坏情况下也与其相当。
* @see java.lang.String#concat(String)
@@ -65,7 +65,7 @@ public static String concat(String... strings) {
/**
* 批量拼接字符串,将null处理为默认字符串。默认字符串可以为空字符串,但不能为null。
- * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入)。这种情况可以极大地加快速度。
+ * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入且该字符串不为null)。这种情况可以极大地加快速度。
* 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
* 经测试,在绝大多数场景下相对jdk的实现更快(平均30%左右),在最坏情况下也与其相当。
* @param defaultStr 为null时的默认字符串
@@ -97,7 +97,7 @@ public static String concatWithDefault(String defaultStr, String... strings) {
/**
* 批量连接字符串,中间有分隔符,可自定义字符串为null时的替代字符串。
- * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入)。这种情况可以极大地加快速度。
+ * 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入且该字符串不为null)。这种情况可以极大地加快速度。
* 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
* 不需要自定义null的替代字符串时,建议使用String.join方法。
* 测试表明,大部分情况下String.join的性能略强于本方法(15%以内),少数情况下本方法性能强于String.join。
@@ -159,4 +159,39 @@ public static String lowerFirst(String string) {
.substring(1)).toString();
}
+ /**
+ * 转换为驼峰命名法
+ * @author Frodez
+ * @date 2019-04-17
+ */
+ public static String toCamelCase(String string) {
+ return toCamelCase("-", string);
+ }
+
+ /**
+ * 转换为驼峰命名法
+ * @author Frodez
+ * @date 2019-04-17
+ */
+ public static String toCamelCase(String delimiter, String string) {
+ if (string == null || EmptyUtil.yes(delimiter)) {
+ throw new IllegalArgumentException();
+ }
+ String[] tokens = string.split(delimiter);
+ if (tokens.length <= 1) {
+ return string;
+ }
+ char[] upperStarters = new char[tokens.length - 1];
+ for (int i = 1; i < tokens.length; i++) {
+ upperStarters[i - 1] = Character.toUpperCase(tokens[i].charAt(0));
+ tokens[i] = tokens[i].substring(1);
+ }
+ StringBuilder builder = new StringBuilder(string.length());
+ builder.append(tokens[0]);
+ for (int i = 1; i < tokens.length; i++) {
+ builder.append(upperStarters[i]).append(tokens[i]);
+ }
+ return builder.toString();
+ }
+
}
From 513b0cefe547a7223e114431a1a66aa152114afd Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Wed, 17 Apr 2019 15:24:05 +0800
Subject: [PATCH 09/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E5=92=8C=E6=B3=A8=E9=87=8A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/frodez/util/common/StrUtil.java | 23 +++++++++++--------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/main/java/frodez/util/common/StrUtil.java b/src/main/java/frodez/util/common/StrUtil.java
index 4d72373..a084738 100644
--- a/src/main/java/frodez/util/common/StrUtil.java
+++ b/src/main/java/frodez/util/common/StrUtil.java
@@ -24,7 +24,7 @@ public class StrUtil {
* @date 2019-04-01
*/
public static String get(@Nullable Object object) {
- return get(object, "");
+ return get("", object);
}
/**
@@ -37,7 +37,7 @@ public static String get(@Nullable Object object) {
* @author Frodez
* @date 2019-04-01
*/
- public static String get(@Nullable Object object, String defaultStr) {
+ public static String get(String defaultStr, @Nullable Object object) {
if (object == null) {
if (defaultStr == null) {
throw new IllegalArgumentException();
@@ -53,7 +53,8 @@ public static String get(@Nullable Object object, String defaultStr) {
/**
* 批量拼接字符串,对null会当作空字符串处理。
* 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入且该字符串不为null)。这种情况可以极大地加快速度。
- * 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
+ * 当然,如果只有一个字符串且该字符串为null,则会直接返回默认字符串,同样可以极大地加快速度。
+ * 另外由于String类型是inmutable的,故只要不涉及对其内存地址的操作,则不会出现bug。
* 经测试,在绝大多数场景下相对jdk的实现更快(平均30%左右),在最坏情况下也与其相当。
* @see java.lang.String#concat(String)
* @author Frodez
@@ -66,7 +67,8 @@ public static String concat(String... strings) {
/**
* 批量拼接字符串,将null处理为默认字符串。默认字符串可以为空字符串,但不能为null。
* 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入且该字符串不为null)。这种情况可以极大地加快速度。
- * 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
+ * 当然,如果只有一个字符串且该字符串为null,则会直接返回默认字符串,同样可以极大地加快速度。
+ * 另外由于String类型是inmutable的,故只要不涉及对其内存地址的操作,则不会出现bug。
* 经测试,在绝大多数场景下相对jdk的实现更快(平均30%左右),在最坏情况下也与其相当。
* @param defaultStr 为null时的默认字符串
* @see java.lang.String#concat(String)
@@ -98,7 +100,8 @@ public static String concatWithDefault(String defaultStr, String... strings) {
/**
* 批量连接字符串,中间有分隔符,可自定义字符串为null时的替代字符串。
* 在极端的情况下,会直接返回原字符串(例如只有一个字符串传入且该字符串不为null)。这种情况可以极大地加快速度。
- * 另外由于String类型是inmutable的,故此情况不会导致某些场景下bug的出现。
+ * 当然,如果只有一个字符串且该字符串为null,则会直接返回默认字符串,同样可以极大地加快速度。
+ * 另外由于String类型是inmutable的,故只要不涉及对其内存地址的操作,则不会出现bug。
* 不需要自定义null的替代字符串时,建议使用String.join方法。
* 测试表明,大部分情况下String.join的性能略强于本方法(15%以内),少数情况下本方法性能强于String.join。
* 替代字符串可以为空字符串,但不能为null。但是分隔符不能为null或者空字符串!!!
@@ -160,7 +163,8 @@ public static String lowerFirst(String string) {
}
/**
- * 转换为驼峰命名法
+ * 转换为驼峰命名法
+ * 默认以"-"为分隔符,将首字母变为小写,将之后的每个分词的首字母变为大写。如果分隔符无效,则会将首字母变为小写。
* @author Frodez
* @date 2019-04-17
*/
@@ -169,7 +173,8 @@ public static String toCamelCase(String string) {
}
/**
- * 转换为驼峰命名法
+ * 转换为驼峰命名法
+ * 以设定的分隔符作为标准,将首字母变为小写,将之后的每个分词的首字母变为大写。如果分隔符无效,则会将首字母变为小写。
* @author Frodez
* @date 2019-04-17
*/
@@ -179,7 +184,7 @@ public static String toCamelCase(String delimiter, String string) {
}
String[] tokens = string.split(delimiter);
if (tokens.length <= 1) {
- return string;
+ return lowerFirst(string);
}
char[] upperStarters = new char[tokens.length - 1];
for (int i = 1; i < tokens.length; i++) {
@@ -187,7 +192,7 @@ public static String toCamelCase(String delimiter, String string) {
tokens[i] = tokens[i].substring(1);
}
StringBuilder builder = new StringBuilder(string.length());
- builder.append(tokens[0]);
+ builder.append(lowerFirst(tokens[0]));
for (int i = 1; i < tokens.length; i++) {
builder.append(upperStarters[i]).append(tokens[i]);
}
From 5859fd7b4b1596a2f7c94f898f0576f0dde7844c Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Thu, 18 Apr 2019 22:59:57 +0800
Subject: [PATCH 10/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E5=92=8C=E6=B3=A8=E9=87=8A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../config/aop/log/annotation/DurationLog.java | 2 ++
.../java/frodez/config/aop/request/TimeoutAOP.java | 3 ---
.../frodez/config/aop/request/annotation/Limit.java | 3 +++
.../config/aop/request/annotation/TimeoutLock.java | 2 ++
.../frodez/config/aop/validation/ValidationAOP.java | 3 +--
.../aop/validation/annotation/common/LegalStr.java | 10 ++++++++++
.../frodez/config/aop/validation/package-info.java | 1 +
src/main/java/frodez/config/async/AsyncConfig.java | 3 +++
.../frodez/config/mvc/JsonHttpMessageConverer.java | 13 ++++++++-----
src/main/java/frodez/util/beans/result/Result.java | 11 ++++++++++-
10 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/src/main/java/frodez/config/aop/log/annotation/DurationLog.java b/src/main/java/frodez/config/aop/log/annotation/DurationLog.java
index f2552fc..30c4eea 100644
--- a/src/main/java/frodez/config/aop/log/annotation/DurationLog.java
+++ b/src/main/java/frodez/config/aop/log/annotation/DurationLog.java
@@ -5,6 +5,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import javax.validation.constraints.Positive;
/**
* 方法耗时监控注解
@@ -21,6 +22,7 @@
* @author Frodez
* @date 2019-04-13
*/
+ @Positive
long threshold() default 3000;
}
diff --git a/src/main/java/frodez/config/aop/request/TimeoutAOP.java b/src/main/java/frodez/config/aop/request/TimeoutAOP.java
index 5e8efae..d2a5549 100644
--- a/src/main/java/frodez/config/aop/request/TimeoutAOP.java
+++ b/src/main/java/frodez/config/aop/request/TimeoutAOP.java
@@ -49,9 +49,6 @@ public class TimeoutAOP {
public Object process(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request = MVCUtil.request();
TimeoutLock timeoutLock = AspectUtil.annotation(point, TimeoutLock.class);
- if (timeoutLock.value() < 0) {
- throw new IllegalArgumentException("the timeout can't be negative!");
- }
String key = KeyGenerator.servletKey(AspectUtil.fullMethodName(point), request);
if (checker.check(key)) {
log.info("重复请求:IP地址{}", ServletUtil.getAddr(request));
diff --git a/src/main/java/frodez/config/aop/request/annotation/Limit.java b/src/main/java/frodez/config/aop/request/annotation/Limit.java
index 4c223f2..ca0e591 100644
--- a/src/main/java/frodez/config/aop/request/annotation/Limit.java
+++ b/src/main/java/frodez/config/aop/request/annotation/Limit.java
@@ -5,6 +5,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import javax.validation.constraints.Positive;
/**
* 请求限流注解,只用于controller中的端点
@@ -21,6 +22,7 @@
* @author Frodez
* @date 2019-04-13
*/
+ @Positive
double value() default 100.0;
/**
@@ -28,6 +30,7 @@
* @author Frodez
* @date 2019-04-13
*/
+ @Positive
long timeout() default 3000;
}
diff --git a/src/main/java/frodez/config/aop/request/annotation/TimeoutLock.java b/src/main/java/frodez/config/aop/request/annotation/TimeoutLock.java
index 121b1f4..a3bde10 100644
--- a/src/main/java/frodez/config/aop/request/annotation/TimeoutLock.java
+++ b/src/main/java/frodez/config/aop/request/annotation/TimeoutLock.java
@@ -5,6 +5,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import javax.validation.constraints.Positive;
/**
* 控制重复请求注解(带过期时间),只用于controller中的端点
@@ -21,6 +22,7 @@
* @author Frodez
* @date 2019-04-13
*/
+ @Positive
long value() default 500;
}
diff --git a/src/main/java/frodez/config/aop/validation/ValidationAOP.java b/src/main/java/frodez/config/aop/validation/ValidationAOP.java
index 5dd5116..34140ca 100644
--- a/src/main/java/frodez/config/aop/validation/ValidationAOP.java
+++ b/src/main/java/frodez/config/aop/validation/ValidationAOP.java
@@ -2,7 +2,6 @@
import frodez.util.aop.AspectUtil;
import frodez.util.beans.result.Result;
-import frodez.util.common.EmptyUtil;
import frodez.util.common.ValidationUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -28,7 +27,7 @@ public class ValidationAOP {
@Around("@annotation(frodez.config.aop.validation.annotation.Check)")
public Object validate(ProceedingJoinPoint p) throws Throwable {
String msg = ValidationUtil.validateParam(p.getTarget(), AspectUtil.method(p), p.getArgs());
- return EmptyUtil.yes(msg) ? p.proceed() : Result.errorRequest(msg);
+ return msg == null ? p.proceed() : Result.errorRequest(msg);
}
}
diff --git a/src/main/java/frodez/config/aop/validation/annotation/common/LegalStr.java b/src/main/java/frodez/config/aop/validation/annotation/common/LegalStr.java
index 947cbba..fbbc754 100644
--- a/src/main/java/frodez/config/aop/validation/annotation/common/LegalStr.java
+++ b/src/main/java/frodez/config/aop/validation/annotation/common/LegalStr.java
@@ -36,6 +36,13 @@
*/
String regex();
+ /**
+ * 正则表达式的模式
+ * @see java.util.regex.Pattern
+ * @see javax.validation.constraints.Pattern.Flag
+ * @author Frodez
+ * @date 2019-04-18
+ */
Flag[] flags() default {};
/**
@@ -57,6 +64,9 @@ class Validator implements ConstraintValidator {
*/
private String regex;
+ /**
+ * 正则表达式的模式
+ */
private int flag;
/**
diff --git a/src/main/java/frodez/config/aop/validation/package-info.java b/src/main/java/frodez/config/aop/validation/package-info.java
index c74ce08..97da290 100644
--- a/src/main/java/frodez/config/aop/validation/package-info.java
+++ b/src/main/java/frodez/config/aop/validation/package-info.java
@@ -1,6 +1,7 @@
/**
* 本包用于配置方法参数自动验证。
* 使用hibernate-validation框架进行验证。
+ * 本包中的自定义注解使用后,相当于默认添加了@NotNull注解。如果需要关闭此功能,请在自定义注解的属性中设定nullable为true。
* @author Frodez
* @date 2019-03-11
*/
diff --git a/src/main/java/frodez/config/async/AsyncConfig.java b/src/main/java/frodez/config/async/AsyncConfig.java
index 5325b93..64fabdd 100644
--- a/src/main/java/frodez/config/async/AsyncConfig.java
+++ b/src/main/java/frodez/config/async/AsyncConfig.java
@@ -35,6 +35,9 @@ public Executor getAsyncExecutor() {
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
log.info("async executor is running now!");
+ log.info("async config:{}corePoolSize, {}maxPoolSize, {}queueCapacity, {}keepAliveSeconds, {}threadNamePrefix",
+ corePoolSize, maxPoolSize, queueCapacity, properties.getKeepAliveSeconds(), properties
+ .getThreadNamePrefix());
return executor;
}
diff --git a/src/main/java/frodez/config/mvc/JsonHttpMessageConverer.java b/src/main/java/frodez/config/mvc/JsonHttpMessageConverer.java
index 3ec3aa7..4035282 100644
--- a/src/main/java/frodez/config/mvc/JsonHttpMessageConverer.java
+++ b/src/main/java/frodez/config/mvc/JsonHttpMessageConverer.java
@@ -10,6 +10,7 @@
import frodez.util.constant.setting.DefCharset;
import frodez.util.json.JSONUtil;
import java.io.IOException;
+import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Map;
@@ -134,12 +135,14 @@ public Object read(Type type, @Nullable Class> contextClass, HttpInputMessage
protected void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
try {
- if (object instanceof Result) {
- outputMessage.getBody().write(object.toString().getBytes());
- outputMessage.getBody().flush();
+ OutputStream outputStream = outputMessage.getBody();
+ if (object.getClass() == Result.class) {
+ //对通用Result采用特殊的优化过的方式
+ outputStream.write(object.toString().getBytes());
+ outputStream.flush();
} else {
- outputMessage.getBody().write(JSONUtil.string(object).getBytes());
- outputMessage.getBody().flush();
+ outputStream.write(JSONUtil.string(object).getBytes());
+ outputStream.flush();
}
} catch (InvalidDefinitionException ex) {
throw new HttpMessageConversionException(StrUtil.concat("Type definition error: ", ex.getType().toString()),
diff --git a/src/main/java/frodez/util/beans/result/Result.java b/src/main/java/frodez/util/beans/result/Result.java
index b9b32a0..de2ae40 100644
--- a/src/main/java/frodez/util/beans/result/Result.java
+++ b/src/main/java/frodez/util/beans/result/Result.java
@@ -436,6 +436,15 @@ public HttpStatus httpStatus() {
return ResultEnum.of(code).status;
}
+ /**
+ * 获取对应的状态枚举
+ * @author Frodez
+ * @date 2019-04-17
+ */
+ public ResultEnum resultEnum() {
+ return ResultEnum.of(code);
+ }
+
/**
* 使用异步包装
* @author Frodez
@@ -461,7 +470,7 @@ private void ableAndNotNull() {
*/
@Getter
@AllArgsConstructor
- public enum ResultEnum implements Serializable {
+ public enum ResultEnum {
/**
* 操作成功,与预期相符
From 83e45d416dbf3980b8c6fcbc07afb24d26ae8465 Mon Sep 17 00:00:00 2001
From: Frodez <463082995@qq.com>
Date: Fri, 19 Apr 2019 12:49:42 +0800
Subject: [PATCH 11/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=E7=B1=BB=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/test/java/frodez/ResultTest.java | 32 ++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 src/test/java/frodez/ResultTest.java
diff --git a/src/test/java/frodez/ResultTest.java b/src/test/java/frodez/ResultTest.java
new file mode 100644
index 0000000..1497858
--- /dev/null
+++ b/src/test/java/frodez/ResultTest.java
@@ -0,0 +1,32 @@
+package frodez;
+
+import frodez.dao.model.user.Role;
+import frodez.util.beans.result.Result;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+import org.springframework.boot.SpringApplication;
+
+public class ResultTest {
+
+ @SuppressWarnings({ "resource" })
+ public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
+ SpringApplication.run(BlogManagePlatformApplication.class, args);
+ Role role = new Role();
+ role.setCreateTime(new Date());
+ role.setDescription("test123");
+ role.setId(123L);
+ role.setLevel((byte) 1);
+ role.setName("wqwq");
+ ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("D:/test.txt"));
+ outputStream.writeObject(Result.success(role));
+ ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("D:/test.txt"));
+ Result object = (Result) inputStream.readObject();
+ object.getClass();
+ }
+
+}