🎨 工具类移动到 common-util模块. (#65)
🎨 工具类移动到 common-util 模块. ✨ 新增自动配置的JsonUtil ✨ 添加 RedisHelper 工具类
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
- 更新了 Service 层的父类,现在无法直接使用 service 对象,进行 Wrapper 条件构造
|
||||
- 更新了分页查询的排序参数,前端需要对应升级
|
||||
- 工具类移动到 common-util 模块, 相应包名已更改,请注意
|
||||
|
||||
### Added
|
||||
|
||||
@@ -27,6 +28,8 @@
|
||||
- feat: 分页查询出入参封装,提供 PageParam 作为入参,PageResult 作为出参,不再用 Page 贯穿
|
||||
- feat: 密码在日志中的存储脱敏
|
||||
- feat: 数据权限注解提供对于指定 Mapper类,或指定方法的数据权限关闭功能
|
||||
- feat: 添加 JsonUtils 根据依赖执行对应的json处理方法
|
||||
- feat: 添加 RedisHelper 提供对redis的常用方法支持
|
||||
- test: 对 client test 跳过登陆验证和密码解密,便于测试,注意生产环境不要开启 test client
|
||||
|
||||
### Changed
|
||||
@@ -58,6 +61,7 @@
|
||||
- 移除 mybatis-plus-extend-mysql 扩展包,相关方法移入 mybatis-plus-extend 扩展中
|
||||
- 移除 model 的 AR 模式支持
|
||||
- 移除 hibernate-validator 的版本指定,改为跟随 spring-boot 的依赖版本
|
||||
- 移除 JacksonUtils
|
||||
|
||||
### Dependency
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.hccake.ballcat.commom.log.constant.LogConstant;
|
||||
import com.hccake.ballcat.commom.log.util.LogUtils;
|
||||
import com.hccake.ballcat.common.desensitize.enums.RegexDesensitizationTypeEnum;
|
||||
import com.hccake.ballcat.common.desensitize.handler.RegexDesensitizationHandler;
|
||||
import com.hccake.ballcat.common.core.util.IPUtil;
|
||||
import com.hccake.ballcat.common.util.IpUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
@@ -73,7 +73,7 @@ public class AdminAccessLogHandler implements AccessLogHandler<AdminAccessLog> {
|
||||
.setTraceId(MDC.get(LogConstant.TRACE_ID))
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
.setTime(time)
|
||||
.setIp(IPUtil.getIpAddr(request))
|
||||
.setIp(IpUtils.getIpAddr(request))
|
||||
.setMethod(request.getMethod())
|
||||
.setUserAgent(request.getHeader("user-agent"))
|
||||
.setUri(uri)
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.hccake.ballcat.admin.modules.lov.typehandler;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.hccake.ballcat.admin.modules.lov.model.entity.LovSelectOptions;
|
||||
import com.hccake.ballcat.common.core.util.SpringUtil;
|
||||
import com.hccake.ballcat.common.conf.util.SpringUtils;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ListLovSelectOptionTypeHandler implements TypeHandler<List<LovSelec
|
||||
|
||||
public ObjectMapper getOm() {
|
||||
if (om == null) {
|
||||
om = SpringUtil.getBean(ObjectMapper.class);
|
||||
om = SpringUtils.getBean(ObjectMapper.class);
|
||||
}
|
||||
return om;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.hccake.ballcat.admin.constants.NotifyChannel;
|
||||
import com.hccake.ballcat.admin.modules.notify.model.domain.NotifyInfo;
|
||||
import com.hccake.ballcat.admin.modules.sys.model.entity.SysUser;
|
||||
import com.hccake.ballcat.common.core.util.HtmlUtil;
|
||||
import com.hccake.ballcat.common.util.HtmlUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@@ -34,7 +34,7 @@ public class SmsNotifyPusher implements NotifyPusher {
|
||||
List<String> phoneList = userList.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toList());
|
||||
// 短信文本去除 html 标签
|
||||
String content = HtmlUtil.toText(notifyInfo.getContent());
|
||||
String content = HtmlUtils.toText(notifyInfo.getContent());
|
||||
// TODO 对接短信发送平台
|
||||
System.out.println("短信推送");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.hccake.ballcat.common.core.domain.SelectData;
|
||||
import com.hccake.ballcat.common.core.result.BaseResultCode;
|
||||
import com.hccake.ballcat.common.core.result.R;
|
||||
import com.hccake.ballcat.common.core.result.SystemResultCode;
|
||||
import com.hccake.ballcat.common.core.util.PasswordUtil;
|
||||
import com.hccake.ballcat.common.util.PasswordUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -99,7 +99,7 @@ public class SysUserController {
|
||||
return R.failed(BaseResultCode.LOGIC_CHECK_ERROR, "用户名已存在");
|
||||
}
|
||||
// 明文密码
|
||||
String password = PasswordUtil.decodeAES(sysUserDTO.getPass(), passwordSecretKey);
|
||||
String password = PasswordUtils.decodeAES(sysUserDTO.getPass(), passwordSecretKey);
|
||||
sysUserDTO.setPassword(password);
|
||||
return sysUserService.addSysUser(sysUserDTO) ? R.ok()
|
||||
: R.failed(BaseResultCode.UPDATE_DATABASE_ERROR, "新增系统用户失败");
|
||||
@@ -180,7 +180,7 @@ public class SysUserController {
|
||||
}
|
||||
|
||||
// 明文密码
|
||||
String password = PasswordUtil.decodeAES(pass, passwordSecretKey);
|
||||
String password = PasswordUtils.decodeAES(pass, passwordSecretKey);
|
||||
return sysUserService.updatePassword(userId, password) ? R.ok()
|
||||
: R.failed(BaseResultCode.UPDATE_DATABASE_ERROR, "修改用户密码失败!");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.hccake.ballcat.admin.modules.sys.model.entity.SysOrganization;
|
||||
import com.hccake.ballcat.admin.modules.sys.model.vo.SysOrganizationTree;
|
||||
import com.hccake.ballcat.admin.modules.sys.service.SysOrganizationService;
|
||||
import com.hccake.ballcat.common.core.constant.GlobalConstants;
|
||||
import com.hccake.ballcat.common.core.util.TreeUtil;
|
||||
import com.hccake.ballcat.common.util.TreeUtils;
|
||||
import com.hccake.extend.mybatis.plus.service.impl.ExtendServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SysOrganizationServiceImpl extends ExtendServiceImpl<SysOrganizatio
|
||||
@Override
|
||||
public List<SysOrganizationTree> listTree() {
|
||||
List<SysOrganization> list = baseMapper.selectList(null);
|
||||
return TreeUtil.buildTree(list, 0, SysOrganizationConverter.INSTANCE::poToTree);
|
||||
return TreeUtils.buildTree(list, 0, SysOrganizationConverter.INSTANCE::poToTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.hccake.ballcat.admin.modules.sys.service.*;
|
||||
import com.hccake.ballcat.common.core.domain.PageParam;
|
||||
import com.hccake.ballcat.common.core.domain.PageResult;
|
||||
import com.hccake.ballcat.common.core.domain.SelectData;
|
||||
import com.hccake.ballcat.common.core.util.PasswordUtil;
|
||||
import com.hccake.ballcat.common.util.PasswordUtils;
|
||||
import com.hccake.extend.mybatis.plus.service.impl.ExtendServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -133,7 +133,7 @@ public class SysUserServiceImpl extends ExtendServiceImpl<SysUserMapper, SysUser
|
||||
sysUser.setType(SysUserConst.Type.SYSTEM.getValue());
|
||||
// 对密码进行 BCrypt 加密
|
||||
String password = sysUserDto.getPassword();
|
||||
String bCryptPassword = PasswordUtil.encodeBCrypt(password);
|
||||
String bCryptPassword = PasswordUtils.encodeBCrypt(password);
|
||||
sysUser.setPassword(bCryptPassword);
|
||||
boolean result = SqlHelper.retBool(baseMapper.insert(sysUser));
|
||||
if (result) {
|
||||
@@ -191,7 +191,7 @@ public class SysUserServiceImpl extends ExtendServiceImpl<SysUserMapper, SysUser
|
||||
public boolean updatePassword(Integer userId, String password) {
|
||||
Assert.isTrue(adminUserChecker.hasModifyPermission(getById(userId)), "当前用户不允许修改!");
|
||||
// BCrypt 加密
|
||||
String bCryptPassword = PasswordUtil.encodeBCrypt(password);
|
||||
String bCryptPassword = PasswordUtils.encodeBCrypt(password);
|
||||
return baseMapper.updatePassword(userId, bCryptPassword);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.hccake.ballcat.admin.oauth.config;
|
||||
|
||||
import com.hccake.ballcat.admin.oauth.CustomAuthenticationEntryPoint;
|
||||
import com.hccake.ballcat.admin.oauth.mobile.MobileAuthenticationProvider;
|
||||
import com.hccake.ballcat.common.core.util.PasswordUtil;
|
||||
import com.hccake.ballcat.common.util.PasswordUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,7 +31,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
*/
|
||||
@Bean
|
||||
protected PasswordEncoder passwordEncoder() {
|
||||
return PasswordUtil.ENCODER;
|
||||
return PasswordUtils.ENCODER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.hccake.ballcat.admin.oauth.util.SecurityUtils;
|
||||
import com.hccake.ballcat.common.core.request.wrapper.ModifyParamMapRequestWrapper;
|
||||
import com.hccake.ballcat.common.core.result.R;
|
||||
import com.hccake.ballcat.common.core.result.SystemResultCode;
|
||||
import com.hccake.ballcat.common.core.util.PasswordUtil;
|
||||
import com.hccake.ballcat.common.util.PasswordUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -58,7 +58,7 @@ public class LoginPasswordDecoderFilter extends OncePerRequestFilter {
|
||||
Map<String, String[]> parameterMap = new HashMap<>(request.getParameterMap());
|
||||
try {
|
||||
if (request.getParameter(GRANT_TYPE).equals(PASSWORD)) {
|
||||
String password = PasswordUtil.decodeAES(request.getParameter(PASSWORD), secretKey);
|
||||
String password = PasswordUtils.decodeAES(request.getParameter(PASSWORD), secretKey);
|
||||
parameterMap.put(PASSWORD, new String[] { password });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.hccake.ballcat.admin.modules.log.service.AdminLoginLogService;
|
||||
import com.hccake.ballcat.commom.log.constant.LogConstant;
|
||||
import com.hccake.ballcat.commom.log.operation.enums.LogStatusEnum;
|
||||
import com.hccake.ballcat.commom.log.util.LogUtils;
|
||||
import com.hccake.ballcat.common.core.util.IPUtil;
|
||||
import com.hccake.ballcat.common.util.IpUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -89,7 +89,7 @@ public class LoginEventListener {
|
||||
// 获取 Request
|
||||
HttpServletRequest request = LogUtils.getHttpServletRequest();
|
||||
AdminLoginLog adminLoginLog = new AdminLoginLog().setLoginTime(LocalDateTime.now())
|
||||
.setIp(IPUtil.getIpAddr(request)).setStatus(LogStatusEnum.SUCCESS.getValue())
|
||||
.setIp(IpUtils.getIpAddr(request)).setStatus(LogStatusEnum.SUCCESS.getValue())
|
||||
.setTraceId(MDC.get(LogConstant.TRACE_ID)).setUsername(source.getName());
|
||||
// 根据 ua 获取浏览器和操作系统
|
||||
UserAgent ua = UserAgentUtil.parse(request.getHeader("user-agent"));
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.hccake.ballcat.admin.modules.sys.model.entity.SysUser;
|
||||
import com.hccake.ballcat.admin.websocket.message.AnnouncementCloseMessage;
|
||||
import com.hccake.ballcat.admin.websocket.message.AnnouncementPushMessage;
|
||||
import com.hccake.ballcat.admin.websocket.message.DictChangeMessage;
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -44,7 +44,7 @@ public class PushEventListener {
|
||||
// 构建字典修改的消息体
|
||||
DictChangeMessage dictChangeMessage = new DictChangeMessage();
|
||||
dictChangeMessage.setDictCode(event.getDictCode());
|
||||
String msg = JacksonUtils.toJson(dictChangeMessage);
|
||||
String msg = JsonUtils.toJson(dictChangeMessage);
|
||||
|
||||
// 广播修改信息
|
||||
MessageDO messageDO = new MessageDO().setMessageText(msg).setNeedBroadcast(true);
|
||||
@@ -61,7 +61,7 @@ public class PushEventListener {
|
||||
// 构建字典修改的消息体
|
||||
AnnouncementCloseMessage message = new AnnouncementCloseMessage();
|
||||
message.setId(event.getId());
|
||||
String msg = JacksonUtils.toJson(message);
|
||||
String msg = JsonUtils.toJson(message);
|
||||
|
||||
// 广播修改信息
|
||||
MessageDO messageDO = new MessageDO().setMessageText(msg).setNeedBroadcast(true);
|
||||
@@ -88,7 +88,7 @@ public class PushEventListener {
|
||||
message.setContent(announcementNotifyInfo.getContent());
|
||||
message.setImmortal(announcementNotifyInfo.getImmortal());
|
||||
message.setDeadline(announcementNotifyInfo.getDeadline());
|
||||
String msg = JacksonUtils.toJson(message);
|
||||
String msg = JsonUtils.toJson(message);
|
||||
|
||||
List<UserAnnouncement> userAnnouncements = new ArrayList<>();
|
||||
List<Object> sessionKeys = new ArrayList<>();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class RedisMessageDistributor implements MessageDistributor {
|
||||
*/
|
||||
@Override
|
||||
public void distribute(MessageDO messageDO) {
|
||||
String str = JacksonUtils.toJson(messageDO);
|
||||
String str = JsonUtils.toJson(messageDO);
|
||||
stringRedisTemplate.convertAndSend(RedisWebsocketMessageListener.CHANNEL, str);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
@@ -30,7 +30,7 @@ public class RedisWebsocketMessageListener implements MessageListener, MessageSe
|
||||
if (CHANNEL.equals(channel)) {
|
||||
byte[] bodyBytes = message.getBody();
|
||||
String body = stringSerializer.deserialize(bodyBytes);
|
||||
MessageDO messageDO = JacksonUtils.toObj(body, MessageDO.class);
|
||||
MessageDO messageDO = JsonUtils.toObj(body, MessageDO.class);
|
||||
doSend(messageDO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.hccake.ballcat.codegen.service.TemplateInfoService;
|
||||
import com.hccake.ballcat.common.core.constant.GlobalConstants;
|
||||
import com.hccake.ballcat.common.core.exception.BusinessException;
|
||||
import com.hccake.ballcat.common.core.result.BaseResultCode;
|
||||
import com.hccake.ballcat.common.core.util.TreeUtil;
|
||||
import com.hccake.ballcat.common.util.TreeUtils;
|
||||
import com.hccake.extend.mybatis.plus.service.impl.ExtendServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -150,10 +150,10 @@ public class TemplateDirectoryEntryServiceImpl
|
||||
// 1. 获取所有目录项(目录项不会太多,一次查询比较方便)
|
||||
List<TemplateDirectoryEntry> entryList = baseMapper.selectList(null);
|
||||
// 2. 获取当前删除目录项的孩子节点列表
|
||||
List<TemplateDirectory> treeList = TreeUtil.buildTree(entryList, entryId,
|
||||
List<TemplateDirectory> treeList = TreeUtils.buildTree(entryList, entryId,
|
||||
TemplateModelConverter.INSTANCE::entryPoToTree);
|
||||
// 3. 获取当前删除目录项的孩子节点Id
|
||||
List<Integer> treeNodeIds = TreeUtil.getTreeNodeIds(treeList);
|
||||
List<Integer> treeNodeIds = TreeUtils.getTreeNodeIds(treeList);
|
||||
// 4. 删除所有孩子节点
|
||||
if (CollectionUtil.isNotEmpty(treeNodeIds)) {
|
||||
baseMapper.deleteBatchIds(treeNodeIds);
|
||||
@@ -243,7 +243,7 @@ public class TemplateDirectoryEntryServiceImpl
|
||||
}
|
||||
|
||||
// 转树形目录结构
|
||||
List<TemplateDirectory> treeList = TreeUtil.buildTree(list, GlobalConstants.TREE_ROOT_ID,
|
||||
List<TemplateDirectory> treeList = TreeUtils.buildTree(list, GlobalConstants.TREE_ROOT_ID,
|
||||
TemplateModelConverter.INSTANCE::entryPoToTree);
|
||||
|
||||
// 填充模板文件
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
|
||||
@@ -3,7 +3,8 @@ package com.hccake.ballcat.common.conf.config;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.hccake.ballcat.common.core.jackson.JavaTimeModule;
|
||||
import com.hccake.ballcat.common.core.jackson.NullSerializerModifier;
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.common.util.json.JacksonAdapter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -15,24 +16,25 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @date 2019/10/17 22:14
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(ObjectMapper.class)
|
||||
public class JacksonConfig {
|
||||
public class JsonConfig {
|
||||
|
||||
/**
|
||||
* 自定义objectMapper
|
||||
* @return ObjectMapper
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnClass(ObjectMapper.class)
|
||||
@ConditionalOnMissingBean(ObjectMapper.class)
|
||||
public ObjectMapper objectMapper() {
|
||||
JacksonUtils.config(mapper -> {
|
||||
JacksonAdapter adapter = (JacksonAdapter) JsonUtils.getAdapter();
|
||||
adapter.config(mapper -> {
|
||||
// NULL值修改
|
||||
mapper.setSerializerFactory(
|
||||
mapper.getSerializerFactory().withSerializerModifier(new NullSerializerModifier()));
|
||||
// 时间解析器
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
});
|
||||
return JacksonUtils.getMapper();
|
||||
return JacksonAdapter.getMapper();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.util;
|
||||
package com.hccake.ballcat.common.conf.util;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -12,13 +12,13 @@ import java.util.Map;
|
||||
* @author lingting 2020/6/12 16:36
|
||||
*/
|
||||
@Component
|
||||
public class SpringUtil implements ApplicationContextAware {
|
||||
public class SpringUtils implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext context;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
context = applicationContext;
|
||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||
SpringUtils.context = context;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -1,8 +1,9 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.hccake.ballcat.common.conf.web.FilterConfig,\
|
||||
com.hccake.ballcat.common.conf.config.JacksonConfig,\
|
||||
com.hccake.ballcat.common.conf.config.JsonConfig,\
|
||||
com.hccake.ballcat.common.conf.exception.ExceptionHandleAutoConfiguration,\
|
||||
com.hccake.ballcat.common.conf.mybatis.MybatisPlusConfig,\
|
||||
com.hccake.ballcat.common.conf.web.WebMvcConfig,\
|
||||
com.hccake.ballcat.common.conf.config.ExceptionHandleConfig
|
||||
com.hccake.ballcat.common.conf.config.ExceptionHandleConfig,\
|
||||
com.hccake.ballcat.common.conf.util.SpringUtils
|
||||
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
package com.hccake.ballcat.common.core.util;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
/**
|
||||
* @author lingting 2020-12-02 20:06
|
||||
*/
|
||||
public class JacksonUtils {
|
||||
|
||||
@Getter
|
||||
static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
static {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 mapper 进行配置
|
||||
* @author lingting 2020-12-02 20:24
|
||||
*/
|
||||
public static void config(Consumer<ObjectMapper> consumer) {
|
||||
consumer.accept(mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转 json string
|
||||
* @author lingting 2020-12-02 20:08
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static String toJson(Object o) {
|
||||
return mapper.writeValueAsString(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param json json string
|
||||
* @param <T> 目标类型
|
||||
* @author lingting 2020-12-02 20:12
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(String json, Class<T> t) {
|
||||
return mapper.readValue(json, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param json json string
|
||||
* @param type 目标类型
|
||||
* @author lingting 2020-12-02 20:12
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(String json, Type type) {
|
||||
return mapper.readValue(json, mapper.constructType(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param json json string
|
||||
* @param ref 目标类型
|
||||
* @author lingting 2020-12-02 20:12
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(String json, TypeReference<T> ref) {
|
||||
return mapper.readValue(json, ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputStream json string 输入流
|
||||
* @param <T> 目标类型
|
||||
* @author lingting 2020-12-02 20:12
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(InputStream inputStream, Class<T> t) {
|
||||
return mapper.readValue(inputStream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputStream json string 输入流
|
||||
* @param type 目标类型
|
||||
* @author lingting 2020-12-02 20:12
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(InputStream inputStream, Type type) {
|
||||
return mapper.readValue(inputStream, mapper.constructType(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputStream json string 输入流
|
||||
* @param ref 目标类型
|
||||
* @author lingting 2020-12-02 20:12
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(InputStream inputStream, TypeReference<T> ref) {
|
||||
return mapper.readValue(inputStream, ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param json json string
|
||||
* @return {@link JsonNode}
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static JsonNode toJsonNode(String json) {
|
||||
return mapper.readTree(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lingting 2020-12-02 20:18
|
||||
*/
|
||||
public static void registerSubtype(Class<?> clz, String type) {
|
||||
mapper.registerSubtypes(new NamedType(clz, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lingting 2020-12-02 20:18
|
||||
*/
|
||||
public static ObjectNode createEmptyJsonNode() {
|
||||
return new ObjectNode(mapper.getNodeFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lingting 2020-12-02 20:18
|
||||
*/
|
||||
public static ArrayNode createEmptyArrayNode() {
|
||||
return new ArrayNode(mapper.getNodeFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lingting 2020-12-02 20:18
|
||||
*/
|
||||
public static JsonNode transferToJsonNode(Object obj) {
|
||||
return mapper.valueToTree(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lingting 2020-12-02 20:18
|
||||
*/
|
||||
public static JavaType constructJavaType(Type type) {
|
||||
return mapper.constructType(type);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hccake.ballcat.common.core.util.SpringUtil
|
||||
42
ballcat-common/ballcat-common-util/pom.xml
Normal file
42
ballcat-common/ballcat-common-util/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ballcat-common</artifactId>
|
||||
<groupId>com.hccake</groupId>
|
||||
<version>0.0.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-json</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.hccake.ballcat.common.util;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/25 21:17
|
||||
*/
|
||||
public class ClassUtils extends ClassUtil {
|
||||
|
||||
/**
|
||||
*
|
||||
* 确定class是否可以被加载
|
||||
* @param className 完整类名
|
||||
* @param classLoader 类加载
|
||||
* @author lingting 2021-02-25 21:17
|
||||
*/
|
||||
public static boolean isPresent(String className, ClassLoader classLoader) {
|
||||
try {
|
||||
Class.forName(className, true, classLoader);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.util;
|
||||
package com.hccake.ballcat.common.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.jsoup.Jsoup;
|
||||
@@ -9,7 +9,7 @@ import org.jsoup.safety.Whitelist;
|
||||
* @author Hccake 2020/12/21
|
||||
* @version 1.0
|
||||
*/
|
||||
public class HtmlUtil {
|
||||
public class HtmlUtils {
|
||||
|
||||
/**
|
||||
* html 转字符串,保留换行样式
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.util;
|
||||
package com.hccake.ballcat.common.util;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
@@ -10,7 +10,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
*
|
||||
* @author Hccake
|
||||
*/
|
||||
public class IPUtil {
|
||||
public class IpUtils {
|
||||
|
||||
/**
|
||||
* 如果在前端和服务端中间还有一层Node服务 在Node对前端数据进行处理并发起新请求时,需携带此头部信息 便于获取真实IP
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.hccake.ballcat.common.util;
|
||||
|
||||
import com.hccake.ballcat.common.util.json.FastjsonAdapter;
|
||||
import com.hccake.ballcat.common.util.json.GsonAdapter;
|
||||
import com.hccake.ballcat.common.util.json.HuToolJsonAdapter;
|
||||
import com.hccake.ballcat.common.util.json.JacksonAdapter;
|
||||
import com.hccake.ballcat.common.util.json.JsonAdapter;
|
||||
import com.hccake.ballcat.common.util.json.TypeReference;
|
||||
import java.lang.reflect.Type;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/25 20:38
|
||||
*/
|
||||
public class JsonUtils {
|
||||
|
||||
|
||||
@Getter
|
||||
private static JsonAdapter adapter;
|
||||
|
||||
static {
|
||||
ClassLoader classLoader = JsonUtils.class.getClassLoader();
|
||||
if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader)) {
|
||||
adapter = new JacksonAdapter();
|
||||
} else if (ClassUtils.isPresent("com.google.gson.Gson", classLoader)) {
|
||||
adapter = new GsonAdapter();
|
||||
} else if (ClassUtils.isPresent("cn.hutool.json.JSONConfig", classLoader)) {
|
||||
adapter = new HuToolJsonAdapter();
|
||||
} else if (ClassUtils.isPresent("com.alibaba.fastjson.JSON", classLoader)) {
|
||||
adapter = new FastjsonAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换适配器. 请注意 本方法全局生效
|
||||
*
|
||||
* @author lingting 2021-02-26 11:18
|
||||
*/
|
||||
public static void switchAdapter(JsonAdapter adapter) {
|
||||
JsonUtils.adapter = adapter;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String toJson(Object obj) {
|
||||
return adapter.toJson(obj);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(String json, Class<T> r) {
|
||||
return adapter.toObj(json, r);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(String json, Type t) {
|
||||
return adapter.toObj(json, t);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static <T> T toObj(String json, TypeReference<T> t) {
|
||||
return adapter.toObj(json, t);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.util;
|
||||
package com.hccake.ballcat.common.util;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.crypto.Mode;
|
||||
@@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
|
||||
* @version 1.0
|
||||
* @date 2019/9/25 15:14
|
||||
*/
|
||||
public class PasswordUtil {
|
||||
public class PasswordUtils {
|
||||
|
||||
public static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.util;
|
||||
package com.hccake.ballcat.common.util;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.hccake.ballcat.common.core.tree.TreeNode;
|
||||
@@ -16,7 +16,7 @@ import java.util.stream.Collectors;
|
||||
* @version 1.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class TreeUtil {
|
||||
public class TreeUtils {
|
||||
|
||||
/**
|
||||
* 根据一个TreeNode集合,返回构建好的树列表
|
||||
@@ -27,7 +27,7 @@ public class TreeUtil {
|
||||
* @return 树列表
|
||||
*/
|
||||
public <T extends TreeNode<I>, I> List<T> buildTree(List<T> nodes, I rootId) {
|
||||
return TreeUtil.buildTree(nodes, rootId, Function.identity());
|
||||
return TreeUtils.buildTree(nodes, rootId, Function.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ public class TreeUtil {
|
||||
// 根据根节点ID拿到一级节点
|
||||
List<T> treeList = childrenMap.get(rootId);
|
||||
// 遍历所有一级节点,赋值其子节点
|
||||
treeList.forEach(node -> TreeUtil.setChildren(node, childrenMap));
|
||||
treeList.forEach(node -> TreeUtils.setChildren(node, childrenMap));
|
||||
return treeList;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TreeUtil {
|
||||
// 如果有孩子节点则赋值,且给孩子节点的孩子节点赋值
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
parent.setChildren(children);
|
||||
children.forEach(node -> TreeUtil.setChildren(node, childrenMap));
|
||||
children.forEach(node -> TreeUtils.setChildren(node, childrenMap));
|
||||
}
|
||||
else {
|
||||
parent.setChildren(new ArrayList<>());
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.hccake.ballcat.common.util.json;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/26 10:32
|
||||
*/
|
||||
public class FastjsonAdapter implements JsonAdapter {
|
||||
|
||||
/**
|
||||
* json str -> obj 时
|
||||
*/
|
||||
static final List<Feature> FEATURES = new ArrayList<>(Feature.values().length);
|
||||
|
||||
/**
|
||||
* obj -> json str
|
||||
*/
|
||||
static final List<SerializerFeature> SERIALIZER_FEATURES = new ArrayList<>(SerializerFeature.values().length);
|
||||
|
||||
private static Feature[] features = new Feature[0];
|
||||
|
||||
private static SerializerFeature[] serializerFeatures = new SerializerFeature[0];
|
||||
|
||||
/**
|
||||
* 不要使用 config 以外的形式更新配置
|
||||
*/
|
||||
public void config(BiConsumer<List<Feature>, List<SerializerFeature>> consumer) {
|
||||
consumer.accept(FEATURES, SERIALIZER_FEATURES);
|
||||
features = FEATURES.toArray(new Feature[0]);
|
||||
serializerFeatures = SERIALIZER_FEATURES.toArray(new SerializerFeature[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(Object obj) {
|
||||
return JSON.toJSONString(obj, serializerFeatures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, Class<T> r) {
|
||||
return JSON.parseObject(json, r, features);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, Type t) {
|
||||
return JSON.parseObject(json, t, features);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, TypeReference<T> t) {
|
||||
/*
|
||||
由于 fastjson 下面这个方法
|
||||
com.alibaba.fastjson.JSON.parseObject(java.lang.String, com.alibaba.fastjson.TypeReference<T>, com.alibaba
|
||||
.fastjson.parser.Feature...)
|
||||
直接调用了 type.type, 而不是使用的 getType()方法. 所以使用 com.debug.json.FastjsonAdapter.toObj(java.lang.String, java.lang
|
||||
.reflect.Type) 方法
|
||||
*/
|
||||
|
||||
return toObj(json, t.getType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.hccake.ballcat.common.util.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/26 10:22
|
||||
*/
|
||||
public class GsonAdapter implements JsonAdapter {
|
||||
|
||||
@Getter
|
||||
static Gson gson = new GsonBuilder().create();
|
||||
|
||||
static {
|
||||
// 初始化gson配置
|
||||
}
|
||||
|
||||
/**
|
||||
* 由于 gson 实例不能更新. 需要 create 之后生成新的实例. 请避免在运行中更新配置.
|
||||
*
|
||||
* @author lingting 2021-02-26 10:29
|
||||
*/
|
||||
public void config(Consumer<GsonBuilder> consumer) {
|
||||
GsonBuilder builder = gson.newBuilder();
|
||||
consumer.accept(builder);
|
||||
// 更新 gson
|
||||
gson = builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(Object obj) {
|
||||
return gson.toJson(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, Class<T> r) {
|
||||
return gson.fromJson(json,r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, Type t) {
|
||||
return gson.fromJson(json,t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, TypeReference<T> t) {
|
||||
return gson.fromJson(json, t.getType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.hccake.ballcat.common.util.json;
|
||||
|
||||
import cn.hutool.json.JSONConfig;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/26 10:00
|
||||
*/
|
||||
public class HuToolJsonAdapter implements JsonAdapter {
|
||||
|
||||
@Getter
|
||||
static JSONConfig jsonConfig = JSONConfig.create();
|
||||
|
||||
static {
|
||||
|
||||
}
|
||||
|
||||
public void config(Consumer<JSONConfig> consumer) {
|
||||
consumer.accept(jsonConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(Object obj) {
|
||||
return JSONUtil.parse(obj, jsonConfig).toJSONString(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, Class<T> r) {
|
||||
return JSONUtil.parse(json, jsonConfig).toBean(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, Type t) {
|
||||
return JSONUtil.parse(json, jsonConfig).toBean(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObj(String json, TypeReference<T> t) {
|
||||
return JSONUtil.parse(json, jsonConfig).toBean(new cn.hutool.core.lang.TypeReference<T>() {
|
||||
@Override
|
||||
public Type getType() {
|
||||
return t.getType();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.hccake.ballcat.common.util.json;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/25 21:04
|
||||
*/
|
||||
public class JacksonAdapter implements JsonAdapter {
|
||||
|
||||
@Getter
|
||||
static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
static {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
}
|
||||
|
||||
public void config(Consumer<ObjectMapper> consumer) {
|
||||
consumer.accept(mapper);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toJson(Object obj) {
|
||||
return mapper.writeValueAsString(obj);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public <T> T toObj(String json, Class<T> r) {
|
||||
return mapper.readValue(json, r);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public <T> T toObj(String json, Type t) {
|
||||
return mapper.readValue(json, mapper.constructType(t));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public <T> T toObj(String json, TypeReference<T> t) {
|
||||
return mapper.readValue(json, new com.fasterxml.jackson.core.type.TypeReference<T>() {
|
||||
@Override
|
||||
public Type getType() {
|
||||
return t.getType();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.hccake.ballcat.common.util.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* json 相关 util类需实现本类
|
||||
*
|
||||
* @author lingting 2021/2/25 20:43
|
||||
*/
|
||||
public interface JsonAdapter {
|
||||
|
||||
/**
|
||||
* obj -> jsonStr
|
||||
* @param obj obj
|
||||
* @return java.lang.String
|
||||
* @author lingting 2021-02-25 21:00
|
||||
*/
|
||||
String toJson(Object obj);
|
||||
|
||||
/**
|
||||
* jsonStr -> obj
|
||||
* @param json json str
|
||||
* @param r obj.class
|
||||
* @return T
|
||||
* @author lingting 2021-02-25 21:02
|
||||
*/
|
||||
<T> T toObj(String json, Class<T> r);
|
||||
|
||||
/**
|
||||
* jsonStr -> obj
|
||||
* @param json json str
|
||||
* @param t (obj.class)type
|
||||
* @return T
|
||||
* @author lingting 2021-02-25 21:02
|
||||
*/
|
||||
<T> T toObj(String json, Type t);
|
||||
|
||||
/**
|
||||
*
|
||||
* jsonStr -> obj
|
||||
* @param json json str
|
||||
* @param t TypeReference
|
||||
* @return T
|
||||
* @author lingting 2021-02-25 21:49
|
||||
*/
|
||||
<T> T toObj(String json, TypeReference<T> t);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.hccake.ballcat.common.util.json;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/2/25 21:46
|
||||
*/
|
||||
public abstract class TypeReference<T> implements Comparable<TypeReference<T>> {
|
||||
|
||||
protected final Type type;
|
||||
|
||||
protected TypeReference() {
|
||||
Type superClass = getClass().getGenericSuperclass();
|
||||
if (superClass instanceof Class<?>) {
|
||||
throw new IllegalArgumentException(
|
||||
"Internal error: TypeReference constructed without actual type information");
|
||||
}
|
||||
type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TypeReference<T> o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,8 @@
|
||||
<module>ballcat-common-core</module>
|
||||
<module>ballcat-common-conf</module>
|
||||
<module>ballcat-common-desensitize</module>
|
||||
</modules>
|
||||
<module>ballcat-common-util</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<knife4j.version>2.0.8</knife4j.version>
|
||||
<kafka.version>2.5.0</kafka.version>
|
||||
<hutool.version>5.5.8</hutool.version>
|
||||
<fastjson.version>1.2.9</fastjson.version>
|
||||
<mybatis-plus.version>3.4.2</mybatis-plus.version>
|
||||
<dynamic-datasource.version>3.3.1</dynamic-datasource.version>
|
||||
<xxl-job.version>2.3.0</xxl-job.version>
|
||||
@@ -133,6 +134,11 @@
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-desensitize</artifactId>
|
||||
@@ -354,6 +360,19 @@
|
||||
<artifactId>hutool-extra</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-json</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<!-- fastjson -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!--配置文件加密-->
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.hccake.starte.pay.ali.domain;
|
||||
|
||||
import static com.hccake.ballcat.common.core.util.JacksonUtils.toJson;
|
||||
import static com.hccake.ballcat.common.core.util.JacksonUtils.toObj;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.starte.pay.ali.enums.TradeStatus;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
@@ -28,10 +26,10 @@ public class AliPayCallback {
|
||||
public static AliPayCallback of(Map<String, String> callbackParams) {
|
||||
Map<String, Object> map = new HashMap<>(callbackParams);
|
||||
String fundBillListStr = callbackParams.get("fund_bill_list").replaceAll(""", "\"");
|
||||
map.put("fund_bill_list", toObj(fundBillListStr, List.class));
|
||||
map.put("fund_bill_list", JsonUtils.toObj(fundBillListStr, List.class));
|
||||
// 覆盖原值
|
||||
callbackParams.put("fund_bill_list", fundBillListStr);
|
||||
return toObj(toJson(map), AliPayCallback.class);
|
||||
return JsonUtils.toObj(JsonUtils.toJson(map), AliPayCallback.class);
|
||||
}
|
||||
|
||||
@JsonProperty("gmt_create")
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -19,7 +19,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.hccake.starte.pay.wx.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.starte.pay.wx.WxPay;
|
||||
import com.hccake.starte.pay.wx.enums.ResponseCode;
|
||||
import com.hccake.starte.pay.wx.enums.TradeType;
|
||||
@@ -68,7 +68,7 @@ public class WxPayCallback {
|
||||
private ResponseCode returnCode;
|
||||
|
||||
public static WxPayCallback of(Map<String, String> res) {
|
||||
return JacksonUtils.toObj(JacksonUtils.toJson(res), WxPayCallback.class).setRaw(res);
|
||||
return JsonUtils.toObj(JsonUtils.toJson(res), WxPayCallback.class).setRaw(res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.hccake.starte.pay.wx.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.starte.pay.wx.enums.ResponseCode;
|
||||
import com.hccake.starte.pay.wx.enums.TradeState;
|
||||
import com.hccake.starte.pay.wx.enums.TradeType;
|
||||
@@ -83,7 +83,7 @@ public class WxPayOrderQueryResponse {
|
||||
private ResponseCode returnCode;
|
||||
|
||||
public static WxPayOrderQueryResponse of(Map<String, String> res) {
|
||||
return JacksonUtils.toObj(JacksonUtils.toJson(res), WxPayOrderQueryResponse.class).setRaw(res);
|
||||
return JsonUtils.toObj(JsonUtils.toJson(res), WxPayOrderQueryResponse.class).setRaw(res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package com.hccake.starte.pay.wx.response;
|
||||
|
||||
import static com.hccake.starte.pay.wx.enums.ResponseCode.SUCCESS;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.starte.pay.wx.enums.ResponseCode;
|
||||
import com.hccake.starte.pay.wx.enums.TradeType;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
@@ -20,7 +16,7 @@ import lombok.experimental.Accessors;
|
||||
public class WxPayResponse {
|
||||
|
||||
public static WxPayResponse of(Map<String, String> res) {
|
||||
return JacksonUtils.toObj(JacksonUtils.toJson(res), WxPayResponse.class).setRaw(res);
|
||||
return JsonUtils.toObj(JsonUtils.toJson(res), WxPayResponse.class).setRaw(res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<!-- ballcat-common-core -->
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.sample.pay.virtual.thread;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.sample.pay.virtual.domain.Result;
|
||||
import com.hccake.sample.pay.virtual.entity.Order;
|
||||
import com.hccake.starter.pay.viratual.AbstractVerifyThread;
|
||||
@@ -31,7 +31,7 @@ public abstract class AbstractThread extends AbstractVerifyThread<Order, Result>
|
||||
@Override
|
||||
public void errorLog(Throwable e, List<Order> list) {
|
||||
// 读取缓存 和 接收数据时出现异常执行此方法
|
||||
log.error("读取缓存 和 接收数据时出现异常执行此方法, 数据: " + JacksonUtils.toJson(list), e);
|
||||
log.error("读取缓存 和 接收数据时出现异常执行此方法, 数据: " + JsonUtils.toJson(list), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +91,7 @@ public abstract class AbstractThread extends AbstractVerifyThread<Order, Result>
|
||||
@Override
|
||||
public void error(Order obj, Throwable e) {
|
||||
// 校验订单 和 获取交易数据时出现异常执行此方法
|
||||
log.error("校验订单 和 获取交易数据时出现异常执行此方法, 出错订单: " + JacksonUtils.toJson(obj), e);
|
||||
log.error("校验订单 和 获取交易数据时出现异常执行此方法, 出错订单: " + JsonUtils.toJson(obj), e);
|
||||
|
||||
// 可根据业务需求在此进行其他处理.
|
||||
|
||||
@@ -107,16 +107,16 @@ public abstract class AbstractThread extends AbstractVerifyThread<Order, Result>
|
||||
|
||||
@Override
|
||||
public void success(Order obj, Optional<Transaction> optional, Result verifyResult) {
|
||||
log.info("交易成功, 订单数据: {}, 交易信息: {}, 结果: {}", JacksonUtils.toJson(obj),
|
||||
!optional.isPresent() ? "null" : JacksonUtils.toJson(optional.get()),
|
||||
JacksonUtils.toJson(verifyResult));
|
||||
log.info("交易成功, 订单数据: {}, 交易信息: {}, 结果: {}", JsonUtils.toJson(obj),
|
||||
!optional.isPresent() ? "null" : JsonUtils.toJson(optional.get()),
|
||||
JsonUtils.toJson(verifyResult));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Order obj, Optional<Transaction> optional, Result verifyResult) {
|
||||
log.info("交易失败, 订单数据: {}, 交易信息: {}, 结果: {}", JacksonUtils.toJson(obj),
|
||||
!optional.isPresent() ? "null" : JacksonUtils.toJson(optional.get()),
|
||||
JacksonUtils.toJson(verifyResult));
|
||||
log.info("交易失败, 订单数据: {}, 交易信息: {}, 结果: {}", JsonUtils.toJson(obj),
|
||||
!optional.isPresent() ? "null" : JsonUtils.toJson(optional.get()),
|
||||
JsonUtils.toJson(verifyResult));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.sample.pay.virtual.thread;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.sample.pay.virtual.entity.Order;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -30,7 +30,7 @@ public class EtherscanThread extends AbstractThread {
|
||||
return service.getTransactionByHash(obj.getHash());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("查询订单出错, 订单: " + JacksonUtils.toJson(obj), e);
|
||||
log.error("查询订单出错, 订单: " + JsonUtils.toJson(obj), e);
|
||||
// 查询出错, 返回 empty
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.sample.pay.virtual.thread;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.sample.pay.virtual.entity.Order;
|
||||
import live.lingting.virtual.currency.Transaction;
|
||||
import live.lingting.virtual.currency.service.impl.BtcOmniServiceImpl;
|
||||
@@ -31,7 +31,7 @@ public class OmniThread extends AbstractThread {
|
||||
return service.getTransactionByHash(obj.getHash());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("查询订单出错, 订单: " + JacksonUtils.toJson(obj), e);
|
||||
log.error("查询订单出错, 订单: " + JsonUtils.toJson(obj), e);
|
||||
// 查询出错, 返回 empty
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.sample.pay.virtual.thread;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.sample.pay.virtual.entity.Order;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -30,7 +30,7 @@ public class TronscanThread extends AbstractThread {
|
||||
return service.getTransactionByHash(obj.getHash());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("查询订单出错, 订单: " + JacksonUtils.toJson(obj), e);
|
||||
log.error("查询订单出错, 订单: " + JsonUtils.toJson(obj), e);
|
||||
// 查询出错, 返回 empty
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.hccake.ballcat.commom.log.operation.enums.LogStatusEnum;
|
||||
import com.hccake.ballcat.commom.log.operation.event.OperationLogEvent;
|
||||
import com.hccake.ballcat.commom.log.operation.model.OperationLogDTO;
|
||||
import com.hccake.ballcat.commom.log.util.LogUtils;
|
||||
import com.hccake.ballcat.common.core.util.IPUtil;
|
||||
import com.hccake.ballcat.common.util.IpUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@@ -102,7 +102,7 @@ public class OperationLogAspect {
|
||||
// @formatter:off
|
||||
return new OperationLogDTO()
|
||||
.setCreateTime(LocalDateTime.now())
|
||||
.setIp(IPUtil.getIpAddr(request))
|
||||
.setIp(IpUtils.getIpAddr(request))
|
||||
.setMethod(request.getMethod())
|
||||
.setOperator(Objects.requireNonNull(LogUtils.getUsername()))
|
||||
.setStatus(LogStatusEnum.SUCCESS.getValue())
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- spring boot 配置所需依赖 -->
|
||||
|
||||
@@ -0,0 +1,423 @@
|
||||
package com.hccake.ballcat.common.redis;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.ListOperations;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.SessionCallback;
|
||||
import org.springframework.data.redis.core.SetOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.data.redis.core.script.RedisScript;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author lingting 2020/4/17 11:49
|
||||
*/
|
||||
@Slf4j
|
||||
public class RedisHelper {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
static StringRedisTemplate template;
|
||||
|
||||
/*
|
||||
* common ----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author lingting 2020-04-29 15:04:39
|
||||
*/
|
||||
public static HashOperations<String, Object, Object> getHash() {
|
||||
return template.opsForHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lingting 2020-04-29 15:04:40
|
||||
*/
|
||||
public static ValueOperations<String, String> getValue() {
|
||||
return template.opsForValue();
|
||||
}
|
||||
|
||||
public static ListOperations<String, String> getList() {
|
||||
return template.opsForList();
|
||||
}
|
||||
|
||||
public static SetOperations<String, String> getSet() {
|
||||
return template.opsForSet();
|
||||
}
|
||||
|
||||
public static boolean hasKey(String key) {
|
||||
Boolean b = template.hasKey(key);
|
||||
return b != null && b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置过期时间
|
||||
* @param time 时间,单位 秒
|
||||
* @author lingting 2020-07-28 13:28:41
|
||||
*/
|
||||
public static boolean expire(String key, long time) {
|
||||
Boolean b = template.expire(key, time, TimeUnit.SECONDS);
|
||||
return b != null && b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有符合指定表达式的 key
|
||||
* @param pattern 表达式
|
||||
* @return java.util.Set<java.lang.String>
|
||||
* @author lingting 2020-04-27 15:44:09
|
||||
*/
|
||||
public static Set<String> keys(String pattern) {
|
||||
return template.keys(pattern);
|
||||
}
|
||||
|
||||
/*
|
||||
* lua 脚本 ----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* 执行 lua脚本
|
||||
* @param action
|
||||
* @return T
|
||||
* @author lingting 2021-02-26 15:22
|
||||
*/
|
||||
public static <T> T execute(RedisCallback<T> action) {
|
||||
return template.execute(action);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T execute(RedisCallback<T> action, boolean exposeConnection) {
|
||||
return execute(action, exposeConnection, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T execute(RedisCallback<T> action, boolean exposeConnection, boolean pipeline) {
|
||||
return template.execute(action, exposeConnection, pipeline);
|
||||
}
|
||||
|
||||
public static <T> T execute(SessionCallback<T> session) {
|
||||
return template.execute(session);
|
||||
}
|
||||
|
||||
public static <T> T execute(RedisScript<T> script, List<String> keys, Object... args) {
|
||||
return template.execute(script, keys, args);
|
||||
}
|
||||
|
||||
public static <T> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer,
|
||||
RedisSerializer<T> resultSerializer, List<String> keys, Object... args) {
|
||||
return template.execute(script, argsSerializer, resultSerializer, keys, args);
|
||||
}
|
||||
|
||||
/*
|
||||
* pipelined 操作 ----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* 操作 pipelined
|
||||
* @author lingting 2021-02-26 15:23
|
||||
*/
|
||||
public static List<Object> executePipelined(SessionCallback<?> session) {
|
||||
return template.executePipelined(session);
|
||||
}
|
||||
|
||||
public static List<Object> executePipelined(SessionCallback<?> session,
|
||||
@Nullable RedisSerializer<?> resultSerializer) {
|
||||
return template.executePipelined(session, resultSerializer);
|
||||
}
|
||||
|
||||
public static List<Object> executePipelined(RedisCallback<?> action) {
|
||||
return template.executePipelined(action);
|
||||
}
|
||||
|
||||
public static List<Object> executePipelined(RedisCallback<?> action,
|
||||
@Nullable RedisSerializer<?> resultSerializer) {
|
||||
return template.executePipelined(action, resultSerializer);
|
||||
}
|
||||
|
||||
/*
|
||||
* string ----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author lingting 2020-04-29 15:04:48
|
||||
*/
|
||||
public static String get(String key) {
|
||||
return getValue().get(key);
|
||||
}
|
||||
|
||||
public static void set(String key, String val) {
|
||||
getValue().set(key, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存数据
|
||||
* @param key key
|
||||
* @param val val
|
||||
* @param second 过期时间 单位:秒
|
||||
* @author lingting 2020-04-22 11:38:13
|
||||
*/
|
||||
public static void set(String key, String val, long second) {
|
||||
if (second > 0) {
|
||||
getValue().set(key, val, second, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存数据
|
||||
* @param key key
|
||||
* @param val val
|
||||
* @param instant 在指定时间过期
|
||||
* @author lingting 2021-02-02 10:31
|
||||
*/
|
||||
public static void set(String key, String val, Instant instant) {
|
||||
getValue().set(key, val);
|
||||
getTemplate().expireAt(key, instant);
|
||||
}
|
||||
|
||||
public static boolean delete(String key) {
|
||||
Boolean b = template.delete(key);
|
||||
return b != null && b;
|
||||
}
|
||||
|
||||
public static long delete(Collection<String> keys) {
|
||||
Long l = template.delete(keys);
|
||||
return l == null ? 0 : l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果 key 不存在,则设置 key为 val 并设置过期时间
|
||||
* @param key key
|
||||
* @param value val
|
||||
* @return boolean
|
||||
* @author lingting 2020-04-29 15:56:51
|
||||
*/
|
||||
public static boolean setIfAbsent(String key, String value) {
|
||||
Boolean b = getValue().setIfAbsent(key, value);
|
||||
return b != null && b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果key存在则设置
|
||||
* @param key key
|
||||
* @param value 值
|
||||
* @param time 过期时间, 单位 秒
|
||||
* @return boolean
|
||||
* @author lingting 2021-01-18 14:59
|
||||
*/
|
||||
public static boolean setIfAbsent(String key, String value, long time) {
|
||||
Boolean b = getValue().setIfAbsent(key, value, Duration.ofSeconds(time));
|
||||
return b != null && b;
|
||||
}
|
||||
|
||||
public static List<String> multiGet(Collection<String> keys) {
|
||||
List<String> list = getValue().multiGet(keys);
|
||||
return list == null ? new ArrayList<>() : new ArrayList<>(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给 key +1
|
||||
*
|
||||
* @author lingting 2020-05-13 11:04:17
|
||||
*/
|
||||
public static Long increment(String key) {
|
||||
return getValue().increment(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给 key 增加 指定数值
|
||||
*
|
||||
* @author lingting 2020-05-13 11:04:17
|
||||
*/
|
||||
public static Long increment(String key, long delta) {
|
||||
return getValue().increment(key, delta);
|
||||
}
|
||||
|
||||
public static Long incrementAndExpire(String key, long time) {
|
||||
return incrementAndExpire(key, 1, time);
|
||||
}
|
||||
|
||||
public static Long incrementAndExpire(String key, long delta, long time) {
|
||||
Long increment = getValue().increment(key, delta);
|
||||
expire(key, time);
|
||||
return increment;
|
||||
}
|
||||
|
||||
/*
|
||||
* list ----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author lingting 2020-04-29 15:04:52
|
||||
*/
|
||||
public static List<String> listGet(String key) {
|
||||
return getList().range(key, 0, listSize(key) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定值在指定key中的索引
|
||||
* @author lingting 2020-12-17 11:06
|
||||
*/
|
||||
public static Long listIndexOf(String key, String val) {
|
||||
return getList().indexOf(key, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获知指定key中指定索引的值
|
||||
* @author lingting 2020-12-17 11:07
|
||||
*/
|
||||
public static String listIndex(String key, long index) {
|
||||
return getList().index(key, index);
|
||||
}
|
||||
|
||||
public static Long listRemove(String key, String val) {
|
||||
return listRemove(key, 1, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param count 删除多少个
|
||||
* @author lingting 2020-12-16 19:13
|
||||
*/
|
||||
public static Long listRemove(String key, long count, String val) {
|
||||
return getList().remove(key, count, val);
|
||||
}
|
||||
|
||||
public static long listSize(String key) {
|
||||
Long size = getList().size(key);
|
||||
return size == null ? 0 : size;
|
||||
}
|
||||
|
||||
private static long listSet(String key, List<String> list) {
|
||||
long l = 0;
|
||||
for (String str : list) {
|
||||
l += listLeftPush(key, str);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入list 并设置过期时间
|
||||
* @param key key
|
||||
* @param list list 值
|
||||
* @param time 过期时间
|
||||
* @return long
|
||||
* @author lingting 2020-04-22 15:22:02
|
||||
*/
|
||||
public static long listSet(String key, List<String> list, long time) {
|
||||
long l = listSet(key, list);
|
||||
expire(key, time);
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入列表
|
||||
* @param key key
|
||||
* @param val val
|
||||
* @author lingting 2020-04-22 15:18:07
|
||||
*/
|
||||
public static Long listLeftPush(String key, String val) {
|
||||
return getList().leftPush(key, val);
|
||||
}
|
||||
|
||||
public static String listPop(String key) {
|
||||
return getList().rightPop(key);
|
||||
}
|
||||
|
||||
/*
|
||||
* hash ----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author lingting 2020-04-29 15:05:41
|
||||
*/
|
||||
public static void hashSet(String key, String field, String value) {
|
||||
getHash().put(key, field, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 指定 key 中 指定 field 的值
|
||||
* @param key key
|
||||
* @param field field
|
||||
* @return java.lang.Object
|
||||
* @author lingting 2020-04-22 17:17:33
|
||||
*/
|
||||
public static String hashGet(String key, String field) {
|
||||
Object o = getHash().get(key, field);
|
||||
return o == null ? null : o.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定 key中的 字段
|
||||
* @param key key
|
||||
* @param fields 字段
|
||||
* @return java.lang.Long
|
||||
* @author lingting 2020-12-21 10:16
|
||||
*/
|
||||
public static Long hashDelete(String key, String... fields) {
|
||||
return getHash().delete(key, (Object[]) fields);
|
||||
}
|
||||
|
||||
/*
|
||||
* set -----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* set中添加数据
|
||||
*
|
||||
* @author lingting 2020-12-17 10:50
|
||||
*/
|
||||
public static Long setAdd(String key, String... values) {
|
||||
return getSet().add(key, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取集合中元素数量
|
||||
* @author lingting 2020-12-17 10:51
|
||||
*/
|
||||
public static Long setSize(String key) {
|
||||
return getSet().size(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机弹出一个元素
|
||||
* @author lingting 2020-12-17 10:52
|
||||
*/
|
||||
public static String setPop(String key) {
|
||||
return getSet().pop(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除集合中的元素
|
||||
* @author lingting 2020-12-17 10:55
|
||||
*/
|
||||
public static Long setRemove(String key, String... values) {
|
||||
return getSet().remove(key, (Object[]) values);
|
||||
}
|
||||
|
||||
public static Object evalLua(String lua, List<String> key, Object... argv) {
|
||||
String[] arg = Arrays.stream(argv).map(String::valueOf).toArray(String[]::new);
|
||||
|
||||
try {
|
||||
DefaultRedisScript<String> redisScript = new DefaultRedisScript<>(lua, String.class);
|
||||
return template.execute(redisScript, new StringRedisSerializer(), new StringRedisSerializer(), key, arg);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("redis evalLua execute fail:lua[{}]", lua, e);
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.hccake.ballcat.common.redis.serialize.CacheSerializer;
|
||||
import com.hccake.ballcat.common.redis.serialize.JacksonSerializer;
|
||||
import com.hccake.ballcat.common.redis.serialize.PrefixJdkRedisSerializer;
|
||||
import com.hccake.ballcat.common.redis.serialize.PrefixStringRedisSerializer;
|
||||
import com.hccake.ballcat.common.redis.RedisHelper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -97,4 +98,11 @@ public class RedisAutoConfiguration {
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean(name = "com.hccake.ballcat.common.redis.RedisHelpers")
|
||||
@ConditionalOnMissingBean(RedisHelper.class)
|
||||
public RedisHelper redis(StringRedisTemplate template) {
|
||||
RedisHelper.setTemplate(template);
|
||||
return new RedisHelper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<!-- spring boot 配置所需依赖 -->
|
||||
<dependency>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.hccake.starter.sms;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.hccake.ballcat.common.core.util.SpringUtil;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.common.util.json.TypeReference;
|
||||
import com.hccake.starter.sms.enums.TypeEnum;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -20,10 +19,6 @@ import lombok.experimental.Accessors;
|
||||
@Accessors(chain = true)
|
||||
public class SmsSenderResult {
|
||||
|
||||
public static ObjectMapper getObjectMapper() {
|
||||
return SpringUtil.getBean(ObjectMapper.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态字段名
|
||||
*/
|
||||
@@ -85,7 +80,7 @@ public class SmsSenderResult {
|
||||
SmsSenderResult result = new SmsSenderResult();
|
||||
result.success = false;
|
||||
result.msg = "短信发送失败,出现异常:" + e.getMessage() + "," + id;
|
||||
result.target = getObjectMapper().writeValueAsString(phoneNumbers);
|
||||
result.target = JsonUtils.toJson(phoneNumbers);
|
||||
result.platform = platform.name();
|
||||
return result;
|
||||
}
|
||||
@@ -102,7 +97,7 @@ public class SmsSenderResult {
|
||||
// 没有异常就是成功!
|
||||
result.success = true;
|
||||
result.platform = TypeEnum.TENCENT.name();
|
||||
result.target = getObjectMapper().writeValueAsString(phoneNumbers);
|
||||
result.target = JsonUtils.toJson(phoneNumbers);
|
||||
result.req = req;
|
||||
return result;
|
||||
}
|
||||
@@ -114,10 +109,10 @@ public class SmsSenderResult {
|
||||
// 没有异常就是成功!
|
||||
result.success = true;
|
||||
result.platform = TypeEnum.TIAN_YI_HONG.name();
|
||||
result.target = getObjectMapper().writeValueAsString(phoneNumbers);
|
||||
result.target = JsonUtils.toJson(phoneNumbers);
|
||||
result.req = req;
|
||||
|
||||
Map<String, Object> map = getObjectMapper().readValue(resp, new TypeReference<Map<String, Object>>() {
|
||||
Map<String, Object> map = JsonUtils.toObj(resp, new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (Convert.toInt(map.get(TIAN_YI_HONG_STATUS), -1) < 0) {
|
||||
result.success = false;
|
||||
@@ -129,7 +124,7 @@ public class SmsSenderResult {
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toString() {
|
||||
return getObjectMapper().writeValueAsString(this);
|
||||
return JsonUtils.toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-core</artifactId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.ballcat.common.websocket;
|
||||
|
||||
import com.hccake.ballcat.common.core.util.JacksonUtils;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.common.websocket.holder.WebSocketSessionHolder;
|
||||
import com.hccake.ballcat.common.websocket.message.JsonWebSocketMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -36,7 +36,7 @@ public class WebSocketMessageSender {
|
||||
}
|
||||
|
||||
public static void send(WebSocketSession session, JsonWebSocketMessage message) {
|
||||
send(session, JacksonUtils.toJson(message));
|
||||
send(session, JsonUtils.toJson(message));
|
||||
}
|
||||
|
||||
public static boolean send(WebSocketSession session, String message) {
|
||||
|
||||
Reference in New Issue
Block a user