diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/ThreadPoolAdapterScheduler.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/ThreadPoolAdapterScheduler.java
index 41f5db22..d71cf267 100644
--- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/ThreadPoolAdapterScheduler.java
+++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/ThreadPoolAdapterScheduler.java
@@ -17,7 +17,7 @@
package cn.hippo4j.adapter.hystrix;
-import cn.hutool.core.thread.ThreadFactoryBuilder;
+import cn.hippo4j.common.design.builder.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ScheduledExecutorService;
@@ -36,8 +36,8 @@ public class ThreadPoolAdapterScheduler {
public ThreadPoolAdapterScheduler() {
scheduler = new ScheduledThreadPoolExecutor(2,
new ThreadFactoryBuilder()
- .setNamePrefix("threadPoolAdapter")
- .setDaemon(true)
+ .prefix("threadPoolAdapter")
+ .daemon(true)
.build());
}
diff --git a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/TomcatWebThreadPoolHandler.java b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/TomcatWebThreadPoolHandler.java
index 70057a9d..c15cf7a6 100644
--- a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/TomcatWebThreadPoolHandler.java
+++ b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/TomcatWebThreadPoolHandler.java
@@ -24,12 +24,13 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.CalculateUtil;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
-import cn.hutool.core.date.DateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.boot.web.server.WebServer;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
@@ -138,7 +139,7 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
runStateInfo.setQueueRemainingCapacity(remainingCapacity);
runStateInfo.setLargestPoolSize(largestPoolSize);
runStateInfo.setCompletedTaskCount(completedTaskCount);
- runStateInfo.setClientLastRefreshTime(DateUtil.formatDateTime(new Date()));
+ runStateInfo.setClientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
runStateInfo.setTimestamp(System.currentTimeMillis());
String rejectedExecutionHandlerName = executor instanceof ThreadPoolExecutor ? ((ThreadPoolExecutor) executor).getRejectedExecutionHandler().getClass().getSimpleName()
: tomcatThreadPoolExecutor.getRejectedExecutionHandler().getClass().getSimpleName();
diff --git a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/UndertowWebThreadPoolHandler.java b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/UndertowWebThreadPoolHandler.java
index 13038842..731b094a 100644
--- a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/UndertowWebThreadPoolHandler.java
+++ b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/UndertowWebThreadPoolHandler.java
@@ -24,7 +24,6 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.CalculateUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
-import cn.hutool.core.date.DateUtil;
import io.undertow.Undertow;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServer;
@@ -35,6 +34,8 @@ import org.xnio.XnioWorker;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.Executor;
@@ -128,7 +129,7 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
? ((DynamicThreadPoolExecutor) fieldObject).getRejectCountNum()
: -1L;
stateInfo.setRejectCount(rejectCount);
- stateInfo.setClientLastRefreshTime(DateUtil.formatDateTime(new Date()));
+ stateInfo.setClientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
stateInfo.setTimestamp(System.currentTimeMillis());
return stateInfo;
}
diff --git a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java
index b5442300..2cee24ef 100644
--- a/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java
+++ b/hippo4j-adapter/hippo4j-adapter-web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java
@@ -20,10 +20,12 @@ package cn.hippo4j.adapter.web;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.ByteConvertUtil;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.system.RuntimeInfo;
import lombok.extern.slf4j.Slf4j;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
/**
* Web thread pool run state handler.
*/
@@ -32,16 +34,20 @@ public class WebThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
@Override
public ThreadPoolRunStateInfo supplement(ThreadPoolRunStateInfo poolRunStateInfo) {
- RuntimeInfo runtimeInfo = new RuntimeInfo();
- String memoryProportion = StrUtil.builder(
- "已分配: ",
- ByteConvertUtil.getPrintSize(runtimeInfo.getTotalMemory()),
- " / 最大可用: ",
- ByteConvertUtil.getPrintSize(runtimeInfo.getMaxMemory())).toString();
+ MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
+ MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
+ long used = heapMemoryUsage.getUsed();
+ long max = heapMemoryUsage.getMax();
+ String memoryProportion = new StringBuilder()
+ .append("已分配: ")
+ .append(ByteConvertUtil.getPrintSize(used))
+ .append(" / 最大可用: ")
+ .append(ByteConvertUtil.getPrintSize(max))
+ .toString();
poolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad() + "%");
poolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad() + "%");
poolRunStateInfo.setMemoryProportion(memoryProportion);
- poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(runtimeInfo.getFreeMemory()));
+ poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(Math.subtractExact(max, used)));
return poolRunStateInfo;
}
}
diff --git a/hippo4j-auth/pom.xml b/hippo4j-auth/pom.xml
index c44bcffb..9a2d1212 100644
--- a/hippo4j-auth/pom.xml
+++ b/hippo4j-auth/pom.xml
@@ -46,11 +46,6 @@
spring-boot-starter-web
-
- cn.hutool
- hutool-all
-
-
org.springframework.boot
spring-boot-starter-security
diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java
index f6456ba8..0f93e918 100644
--- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java
+++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java
@@ -21,8 +21,8 @@ import cn.hippo4j.auth.model.biz.user.JwtUser;
import cn.hippo4j.auth.model.biz.user.LoginUser;
import cn.hippo4j.auth.toolkit.JwtTokenUtil;
import cn.hippo4j.auth.toolkit.ReturnT;
+import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.web.base.Results;
-import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationManager;
@@ -34,7 +34,6 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -100,7 +99,7 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
Map maps = new HashMap(MAP_INITIAL_CAPACITY);
maps.put("data", JwtTokenUtil.TOKEN_PREFIX + token);
maps.put("roles", role.split(SPLIT_COMMA));
- response.getWriter().write(JSONUtil.toJsonStr(Results.success(maps)));
+ response.getWriter().write(JSONUtil.toJSONString(Results.success(maps)));
} finally {
rememberMe.remove();
}
@@ -109,6 +108,6 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
@Override
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
response.setCharacterEncoding("UTF-8");
- response.getWriter().write(JSONUtil.toJsonStr(new ReturnT(-1, "Server Error")));
+ response.getWriter().write(JSONUtil.toJSONString(new ReturnT(-1, "Server Error")));
}
}
diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java
index 7ec3c66b..3b6cf69e 100644
--- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java
+++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java
@@ -20,10 +20,10 @@ package cn.hippo4j.auth.filter;
import cn.hippo4j.auth.security.JwtTokenManager;
import cn.hippo4j.auth.toolkit.JwtTokenUtil;
import cn.hippo4j.common.toolkit.JSONUtil;
+import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.UserContext;
import cn.hippo4j.common.web.base.Results;
import cn.hippo4j.common.web.exception.ServiceException;
-import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -61,7 +61,7 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
FilterChain chain) throws IOException, ServletException {
// Token when verifying client interaction.
String accessToken = request.getParameter(ACCESS_TOKEN);
- if (StrUtil.isNotBlank(accessToken)) {
+ if (StringUtil.isNotBlank(accessToken)) {
tokenManager.validateToken(accessToken);
Authentication authentication = this.tokenManager.getAuthentication(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/security/JwtTokenManager.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/security/JwtTokenManager.java
index 84160cc9..17f52aaa 100644
--- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/security/JwtTokenManager.java
+++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/security/JwtTokenManager.java
@@ -17,7 +17,7 @@
package cn.hippo4j.auth.security;
-import cn.hutool.core.util.StrUtil;
+import cn.hippo4j.common.toolkit.StringUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
@@ -64,7 +64,7 @@ public class JwtTokenManager {
Claims claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
List authorities = AuthorityUtils
.commaSeparatedStringToAuthorityList((String) claims.get(AUTHORITIES_KEY));
- User principal = new User(claims.getSubject(), StrUtil.EMPTY, authorities);
- return new UsernamePasswordAuthenticationToken(principal, StrUtil.EMPTY, authorities);
+ User principal = new User(claims.getSubject(), StringUtil.EMPTY, authorities);
+ return new UsernamePasswordAuthenticationToken(principal, StringUtil.EMPTY, authorities);
}
}
diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/PermissionServiceImpl.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/PermissionServiceImpl.java
index b53b1c6a..83787200 100644
--- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/PermissionServiceImpl.java
+++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/PermissionServiceImpl.java
@@ -21,8 +21,8 @@ import cn.hippo4j.auth.mapper.PermissionMapper;
import cn.hippo4j.auth.model.biz.permission.PermissionQueryPageReqDTO;
import cn.hippo4j.auth.model.biz.permission.PermissionRespDTO;
import cn.hippo4j.auth.service.PermissionService;
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.util.StrUtil;
+import cn.hippo4j.common.toolkit.BeanUtil;
+import cn.hippo4j.common.toolkit.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -44,8 +44,7 @@ public class PermissionServiceImpl implements PermissionService {
public IPage listPermission(int pageNo, int pageSize) {
PermissionQueryPageReqDTO queryPage = new PermissionQueryPageReqDTO(pageNo, pageSize);
IPage selectPage = permissionMapper.selectPage(queryPage, null);
-
- return selectPage.convert(each -> BeanUtil.toBean(each, PermissionRespDTO.class));
+ return selectPage.convert(each -> BeanUtil.convert(each, PermissionRespDTO.class));
}
@Override
@@ -68,9 +67,9 @@ public class PermissionServiceImpl implements PermissionService {
@Override
public void deletePermission(String role, String resource, String action) {
LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(PermissionInfo.class)
- .eq(StrUtil.isNotBlank(role), PermissionInfo::getRole, role)
- .eq(StrUtil.isNotBlank(resource), PermissionInfo::getResource, resource)
- .eq(StrUtil.isNotBlank(action), PermissionInfo::getAction, action);
+ .eq(StringUtil.isNotBlank(role), PermissionInfo::getRole, role)
+ .eq(StringUtil.isNotBlank(resource), PermissionInfo::getResource, resource)
+ .eq(StringUtil.isNotBlank(action), PermissionInfo::getAction, action);
permissionMapper.delete(updateWrapper);
}
}
diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/RoleServiceImpl.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/RoleServiceImpl.java
index dd45b56c..b298bb70 100644
--- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/RoleServiceImpl.java
+++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/RoleServiceImpl.java
@@ -22,9 +22,9 @@ import cn.hippo4j.auth.model.biz.role.RoleQueryPageReqDTO;
import cn.hippo4j.auth.model.biz.role.RoleRespDTO;
import cn.hippo4j.auth.service.PermissionService;
import cn.hippo4j.auth.service.RoleService;
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.StrUtil;
+import cn.hippo4j.common.toolkit.BeanUtil;
+import cn.hippo4j.common.toolkit.CollectionUtil;
+import cn.hippo4j.common.toolkit.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -51,7 +51,7 @@ public class RoleServiceImpl implements RoleService {
public IPage listRole(int pageNo, int pageSize) {
RoleQueryPageReqDTO queryPage = new RoleQueryPageReqDTO(pageNo, pageSize);
IPage selectPage = roleMapper.selectPage(queryPage, null);
- return selectPage.convert(each -> BeanUtil.toBean(each, RoleRespDTO.class));
+ return selectPage.convert(each -> BeanUtil.convert(each, RoleRespDTO.class));
}
@Override
@@ -70,14 +70,14 @@ public class RoleServiceImpl implements RoleService {
@Override
public void deleteRole(String role, String userName) {
- List roleStrList = CollUtil.toList(role);
- if (StrUtil.isBlank(role)) {
+ List roleStrList = CollectionUtil.toList(role);
+ if (StringUtil.isBlank(role)) {
LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(RoleInfo.class).eq(RoleInfo::getUserName, userName);
roleStrList = roleMapper.selectList(queryWrapper).stream().map(RoleInfo::getRole).collect(Collectors.toList());
}
LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(RoleInfo.class)
- .eq(StrUtil.isNotBlank(role), RoleInfo::getRole, role)
- .eq(StrUtil.isNotBlank(userName), RoleInfo::getUserName, userName);
+ .eq(StringUtil.isNotBlank(role), RoleInfo::getRole, role)
+ .eq(StringUtil.isNotBlank(userName), RoleInfo::getUserName, userName);
roleMapper.delete(updateWrapper);
roleStrList.forEach(each -> permissionService.deletePermission(each, "", ""));
}
diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java
index f94df6a2..b500fa06 100644
--- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java
+++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java
@@ -24,10 +24,9 @@ import cn.hippo4j.auth.model.biz.user.UserReqDTO;
import cn.hippo4j.auth.model.biz.user.UserRespDTO;
import cn.hippo4j.auth.service.RoleService;
import cn.hippo4j.auth.service.UserService;
+import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.web.exception.ServiceException;
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -59,7 +58,7 @@ public class UserServiceImpl implements UserService {
LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(UserInfo.class)
.eq(StringUtil.isNotBlank(reqDTO.getUserName()), UserInfo::getUserName, reqDTO.getUserName());
IPage selectPage = userMapper.selectPage(reqDTO, queryWrapper);
- return selectPage.convert(each -> BeanUtil.toBean(each, UserRespDTO.class));
+ return selectPage.convert(each -> BeanUtil.convert(each, UserRespDTO.class));
}
@Override
@@ -71,16 +70,16 @@ public class UserServiceImpl implements UserService {
throw new RuntimeException("用户名重复");
}
reqDTO.setPassword(bCryptPasswordEncoder.encode(reqDTO.getPassword()));
- UserInfo insertUser = BeanUtil.toBean(reqDTO, UserInfo.class);
+ UserInfo insertUser = BeanUtil.convert(reqDTO, UserInfo.class);
userMapper.insert(insertUser);
}
@Override
public void updateUser(UserReqDTO reqDTO) {
- if (StrUtil.isNotBlank(reqDTO.getPassword())) {
+ if (StringUtil.isNotBlank(reqDTO.getPassword())) {
reqDTO.setPassword(bCryptPasswordEncoder.encode(reqDTO.getPassword()));
}
- UserInfo updateUser = BeanUtil.toBean(reqDTO, UserInfo.class);
+ UserInfo updateUser = BeanUtil.convert(reqDTO, UserInfo.class);
LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(UserInfo.class)
.eq(UserInfo::getUserName, reqDTO.getUserName());
userMapper.update(updateUser, updateWrapper);
@@ -108,7 +107,7 @@ public class UserServiceImpl implements UserService {
Wrapper queryWrapper = Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserName, reqDTO.getUserName());
UserInfo userInfo = userMapper.selectOne(queryWrapper);
UserRespDTO respUser = Optional.ofNullable(userInfo)
- .map(each -> BeanUtil.toBean(each, UserRespDTO.class))
+ .map(each -> BeanUtil.convert(each, UserRespDTO.class))
.orElseThrow(() -> new ServiceException("查询无此用户, 可以尝试清空缓存或退出登录."));
return respUser;
}
diff --git a/hippo4j-common/pom.xml b/hippo4j-common/pom.xml
index 44b46e4d..320c0fba 100644
--- a/hippo4j-common/pom.xml
+++ b/hippo4j-common/pom.xml
@@ -61,11 +61,6 @@
spring-boot-starter-json
-
- cn.hutool
- hutool-all
-
-
org.springframework.boot
spring-boot-starter-test
@@ -76,6 +71,11 @@
com.github.ben-manes.caffeine
caffeine
+
+
+ com.github.dozermapper
+ dozer-core
+
diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadFactoryBuilder.java b/hippo4j-common/src/main/java/cn/hippo4j/common/design/builder/ThreadFactoryBuilder.java
similarity index 97%
rename from hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadFactoryBuilder.java
rename to hippo4j-common/src/main/java/cn/hippo4j/common/design/builder/ThreadFactoryBuilder.java
index ff78da04..6a9323fb 100644
--- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadFactoryBuilder.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/design/builder/ThreadFactoryBuilder.java
@@ -15,9 +15,7 @@
* limitations under the License.
*/
-package cn.hippo4j.core.executor.support;
-
-import cn.hippo4j.common.design.builder.Builder;
+package cn.hippo4j.common.design.builder;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Assert.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Assert.java
index 1bff8abf..327152a0 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Assert.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Assert.java
@@ -91,6 +91,16 @@ public class Assert {
}
}
+ public static void notBlank(String str, String message) {
+ if (StringUtil.isBlank(str)) {
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ public static void notBlank(String str) {
+ notBlank(str, "[Assertion failed] - this string must not be blank");
+ }
+
public static void hasText(String text, String message) {
if (!StringUtils.hasText(text)) {
throw new IllegalArgumentException(message);
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BeanUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BeanUtil.java
new file mode 100644
index 00000000..523f56a9
--- /dev/null
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BeanUtil.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.common.toolkit;
+
+import cn.hippo4j.common.web.exception.IllegalException;
+import com.github.dozermapper.core.DozerBeanMapperBuilder;
+import com.github.dozermapper.core.Mapper;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.springframework.beans.BeanUtils;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * Bean util.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class BeanUtil {
+
+ protected static Mapper BEAN_MAPPER_BUILDER;
+
+ static {
+ BEAN_MAPPER_BUILDER = DozerBeanMapperBuilder.buildDefault();
+ }
+
+ public static T convert(S source, Class clazz) {
+ return Optional.ofNullable(source)
+ .map(each -> BEAN_MAPPER_BUILDER.map(each, clazz))
+ .orElse(null);
+ }
+
+ public static T convert(S source, T target) {
+ Optional.ofNullable(source)
+ .ifPresent(each -> BEAN_MAPPER_BUILDER.map(each, target));
+ return target;
+ }
+
+ public static List convert(List sources, Class clazz) {
+ return Optional.ofNullable(sources)
+ .map(each -> {
+ List targetList = new ArrayList(each.size());
+ each.forEach(item -> targetList.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
+ return targetList;
+ })
+ .orElse(null);
+ }
+
+ public static Set convert(Set sources, Class clazz) {
+ return Optional.ofNullable(sources)
+ .map(each -> {
+ Set targetSize = new HashSet(each.size());
+ each.forEach(item -> targetSize.add(BEAN_MAPPER_BUILDER.map(item, clazz)));
+ return targetSize;
+ })
+ .orElse(null);
+ }
+
+ public static T mapToBean(Map map, Class clazz, boolean toCamelCase) {
+ if (clazz == null) {
+ return null;
+ }
+ try {
+ T newInstance = clazz.newInstance();
+ return mapToBean(map, newInstance, toCamelCase);
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new IllegalException("do not create instance for " + clazz.getName(), e);
+ }
+ }
+
+ /**
+ * map to bean
+ *
+ * @param map map
+ * @param bean obj bean
+ * @param toCamelCase format to camel case
+ * @param bean type
+ * @return T
+ */
+ public static T mapToBean(Map map, T bean, boolean toCamelCase) {
+ if (bean == null) {
+ return null;
+ }
+ if (map.isEmpty()) {
+ return bean;
+ }
+ Class> clazz = bean.getClass();
+ map.forEach((s, o) -> {
+ String name = toCamelCase ? StringUtil.toCamelCase(s, StringUtil.UNDERLINE) : s;
+ Method method = setter(clazz, name);
+ if (method != null) {
+ ReflectUtil.invoke(bean, method, o);
+ }
+ });
+ return bean;
+ }
+
+ /**
+ * getter for properties
+ *
+ * @param o obj
+ * @param propertiesName name
+ * @return Method for get
+ */
+ public static Method getter(Class> o, String propertiesName) {
+ if (o == null) {
+ return null;
+ }
+ try {
+ PropertyDescriptor descriptor = new PropertyDescriptor(propertiesName, o);
+ return descriptor.getReadMethod();
+ } catch (IntrospectionException e) {
+ throw new IllegalException("not find getter for" + propertiesName + "in" + o.getName(), e);
+ }
+ }
+
+ /**
+ * setter for properties
+ *
+ * @param o obj
+ * @param propertiesName name
+ * @return Method for set
+ */
+ public static Method setter(Class> o, String propertiesName) {
+ if (o == null) {
+ return null;
+ }
+ try {
+ PropertyDescriptor descriptor = new PropertyDescriptor(propertiesName, o);
+ return descriptor.getWriteMethod();
+ } catch (IntrospectionException e) {
+ throw new IllegalException("not find setter for" + propertiesName + "in" + o.getName(), e);
+ }
+ }
+}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BooleanUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BooleanUtil.java
index 7d98a0fa..8885aab5 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BooleanUtil.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/BooleanUtil.java
@@ -17,8 +17,6 @@
package cn.hippo4j.common.toolkit;
-import cn.hutool.core.util.StrUtil;
-
import java.util.HashSet;
import java.util.Set;
@@ -42,7 +40,7 @@ public class BooleanUtil {
* @return
*/
public static boolean toBoolean(String valueStr) {
- if (StrUtil.isNotBlank(valueStr)) {
+ if (StringUtil.isNotBlank(valueStr)) {
valueStr = valueStr.trim().toLowerCase();
return TREE_SET.contains(valueStr);
}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/CollectionUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/CollectionUtil.java
index 0177dca4..baa5a02f 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/CollectionUtil.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/CollectionUtil.java
@@ -18,6 +18,7 @@
package cn.hippo4j.common.toolkit;
import java.util.*;
+import java.util.stream.Collectors;
/**
* Collection util.
@@ -121,6 +122,21 @@ public class CollectionUtil {
return !isEmpty(collection);
}
+ /**
+ * to list
+ *
+ * @param ts elements
+ * @param type
+ * @return List
+ */
+ public static List toList(T... ts) {
+ if (ts == null || ts.length == 0) {
+ return new ArrayList<>();
+ }
+ return Arrays.stream(ts)
+ .collect(Collectors.toList());
+ }
+
/**
* reference google guava
*
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/DateUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/DateUtil.java
new file mode 100644
index 00000000..7db6d7c5
--- /dev/null
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/DateUtil.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.common.toolkit;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.util.Date;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+/**
+ * date and time util
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class DateUtil {
+
+ /**
+ * get time zone for this JVM
+ */
+ private static final TimeZone TIME_ZONE = TimeZone.getDefault();
+
+ public static final String NORM_DATE_PATTERN = "yyyy-MM-dd";
+
+ public static final String NORM_TIME_PATTERN = "HH:mm:ss";
+
+ public static final String NORM_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ /**
+ * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
+ * represented by this Date object.
+ *
+ * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
+ * represented by this date.
+ */
+ public static long getTime(LocalDateTime date) {
+ return getTime(date, TIME_ZONE.toZoneId());
+ }
+
+ public static long getTime(LocalDateTime date, ZoneId zoneId) {
+ return date.atZone(zoneId).toInstant().toEpochMilli();
+
+ }
+
+ /**
+ * modify format to date
+ *
+ * @param date date
+ * @param normTimePattern PATTERN
+ * @return String
+ */
+ public static String format(Date date, String normTimePattern) {
+ SimpleDateFormat zoneFormat = new SimpleDateFormat(normTimePattern);
+ return zoneFormat.format(date);
+
+ }
+}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/FileUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/FileUtil.java
index 6361c767..1e7d971f 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/FileUtil.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/FileUtil.java
@@ -17,12 +17,15 @@
package cn.hippo4j.common.toolkit;
+import cn.hippo4j.common.web.exception.IllegalException;
import lombok.SneakyThrows;
import org.springframework.core.io.ClassPathResource;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
/**
* File util;
@@ -48,4 +51,38 @@ public class FileUtil {
}
return resultReadStr;
}
+
+ public static List readLines(String path, Charset charset) {
+ List strList = new ArrayList<>();
+ InputStreamReader inputStreamReader = null;
+ BufferedReader bufferedReader = null;
+ ClassPathResource classPathResource = new ClassPathResource(path);
+ try {
+ inputStreamReader = new InputStreamReader(classPathResource.getInputStream(), charset);
+ bufferedReader = new BufferedReader(inputStreamReader);
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ strList.add(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new IllegalException("file read error");
+ } finally {
+ if (inputStreamReader != null) {
+ try {
+ inputStreamReader.close();
+ } catch (IOException e) {
+ throw new IllegalException("file read error");
+ }
+ }
+ if (bufferedReader != null) {
+ try {
+ bufferedReader.close();
+ } catch (IOException e) {
+ throw new IllegalException("file read error");
+ }
+ }
+ }
+ return strList;
+ }
}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/IdUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/IdUtil.java
new file mode 100644
index 00000000..e9bf9a50
--- /dev/null
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/IdUtil.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.common.toolkit;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.UUID;
+
+/**
+ * id and uuid util,{@link UUID}
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class IdUtil {
+
+ /**
+ * get a random UUID
+ *
+ * @return UUID
+ */
+ public static String randomUUID() {
+ return toString(UUID.randomUUID(), false);
+ }
+
+ /**
+ * get a simple random UUID
+ *
+ * @return a simple UUID
+ */
+ public static String simpleUUID() {
+ return toString(UUID.randomUUID(), true);
+ }
+
+ /**
+ * toString
+ *
+ * @param uuid UUID
+ * @return UUID String
+ */
+ public static String toString(UUID uuid, boolean isSimple) {
+ long mostSigBits = uuid.getMostSignificantBits();
+ long leastSigBits = uuid.getLeastSignificantBits();
+ if (isSimple) {
+ return (digits(mostSigBits >> 32, 8) +
+ digits(mostSigBits >> 16, 4) +
+ digits(mostSigBits, 4) +
+ digits(leastSigBits >> 48, 4) +
+ digits(leastSigBits, 12));
+ } else {
+ return (digits(mostSigBits >> 32, 8) + "-" +
+ digits(mostSigBits >> 16, 4) + "-" +
+ digits(mostSigBits, 4) + "-" +
+ digits(leastSigBits >> 48, 4) + "-" +
+ digits(leastSigBits, 12));
+ }
+ }
+
+ /**
+ * Returns val represented by the specified number of hex digits.
+ * {@link UUID#digits(long, int)}
+ *
+ * @param val value
+ * @param digits position
+ * @return hex value
+ */
+ private static String digits(long val, int digits) {
+ long hi = 1L << (digits * 4);
+ return Long.toHexString(hi | (val & (hi - 1))).substring(1);
+ }
+}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MessageConvert.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MessageConvert.java
index fdf529f9..3be85745 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MessageConvert.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MessageConvert.java
@@ -41,7 +41,7 @@ public class MessageConvert {
MessageWrapper wrapper = new MessageWrapper();
wrapper.setResponseClass(message.getClass());
wrapper.setMessageType(message.getMessageType());
- List