🎨 调整代码结构
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.hccake.ballcat.admin.modules.log.handler;
|
||||
|
||||
import com.hccake.ballcat.common.conf.exception.handler.GlobalExceptionHandler;
|
||||
import com.hccake.ballcat.common.core.exception.handler.GlobalExceptionHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.hccake.ballcat.admin.modules.sys.model.vo.DictItemVO;
|
||||
import com.hccake.ballcat.admin.modules.sys.service.SysDictItemService;
|
||||
import com.hccake.ballcat.admin.modules.sys.service.SysDictService;
|
||||
import com.hccake.ballcat.common.core.constant.GlobalConstants;
|
||||
import com.hccake.ballcat.common.core.constant.enums.BooleanEm;
|
||||
import com.hccake.ballcat.common.core.constant.enums.BooleanEnum;
|
||||
import com.hccake.ballcat.common.core.exception.BusinessException;
|
||||
import com.hccake.ballcat.common.core.result.BaseResultCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -69,7 +69,7 @@ public class SysDictManager {
|
||||
public boolean updateDictById(SysDict sysDict) {
|
||||
// 查询现有数据
|
||||
SysDict dict = sysDictService.getById(sysDict.getId());
|
||||
if (BooleanEm.TRUE.getValue() != dict.getEditable()) {
|
||||
if (BooleanEnum.TRUE.getValue() != dict.getEditable()) {
|
||||
throw new BusinessException(
|
||||
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "该字典项目不能修改"
|
||||
);
|
||||
@@ -88,7 +88,7 @@ public class SysDictManager {
|
||||
public boolean removeDictById(Integer id) {
|
||||
// 查询现有数据
|
||||
SysDict dict = sysDictService.getById(id);
|
||||
if (BooleanEm.TRUE.getValue() != dict.getEditable()) {
|
||||
if (BooleanEnum.TRUE.getValue() != dict.getEditable()) {
|
||||
throw new BusinessException(
|
||||
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "该字典项目不能删除"
|
||||
);
|
||||
@@ -140,7 +140,7 @@ public class SysDictManager {
|
||||
// 根据ID查询字典
|
||||
SysDict dict = sysDictService.getByCode(sysDictItem.getDictCode());
|
||||
// 校验是否可编辑
|
||||
if (BooleanEm.TRUE.getValue() != dict.getEditable()) {
|
||||
if (BooleanEnum.TRUE.getValue() != dict.getEditable()) {
|
||||
throw new BusinessException(
|
||||
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "该字典项目不能修改"
|
||||
);
|
||||
@@ -165,7 +165,7 @@ public class SysDictManager {
|
||||
SysDictItem dictItem = sysDictItemService.getById(id);
|
||||
SysDict dict = sysDictService.getByCode(dictItem.getDictCode());
|
||||
// 校验是否系统内置
|
||||
if (BooleanEm.TRUE.getValue() != dict.getEditable()) {
|
||||
if (BooleanEnum.TRUE.getValue() != dict.getEditable()) {
|
||||
throw new BusinessException(
|
||||
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "该字典项目不能删除"
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.hccake.ballcat.admin.oauth.filter;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.hccake.ballcat.admin.constants.UrlMappingConst;
|
||||
import com.hccake.ballcat.common.core.filter.ModifyParamMapRequestWrapper;
|
||||
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;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.hccake.ballcat.common.conf.exception;
|
||||
|
||||
import com.hccake.ballcat.common.conf.exception.handler.DefaultGlobalExceptionHandler;
|
||||
import com.hccake.ballcat.common.conf.exception.handler.GlobalExceptionHandler;
|
||||
import com.hccake.ballcat.common.core.exception.handler.DefaultGlobalExceptionHandler;
|
||||
import com.hccake.ballcat.common.core.exception.handler.GlobalExceptionHandler;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hccake.ballcat.common.conf.exception;
|
||||
|
||||
import com.hccake.ballcat.common.conf.exception.handler.GlobalExceptionHandler;
|
||||
import com.hccake.ballcat.common.core.exception.handler.GlobalExceptionHandler;
|
||||
import com.hccake.ballcat.common.core.exception.BusinessException;
|
||||
import com.hccake.ballcat.common.core.result.R;
|
||||
import com.hccake.ballcat.common.core.result.SystemResultCode;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.hccake.ballcat.common.conf.web;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.hccake.ballcat.common.core.exception.SqlCheckedException;
|
||||
import com.hccake.ballcat.common.core.result.BaseResultCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -57,7 +58,7 @@ public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver
|
||||
String sortField = request.getParameter("sortField");
|
||||
String sortAsc = request.getParameter("sortAsc");
|
||||
|
||||
Page page = new Page();
|
||||
Page<?> page = new Page<>();
|
||||
if (StrUtil.isNotBlank(current)) {
|
||||
page.setCurrent(Long.parseLong(current));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BooleanEm {
|
||||
public enum BooleanEnum {
|
||||
|
||||
/**
|
||||
* 是
|
||||
@@ -10,8 +10,8 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public class BusinessException extends RuntimeException {
|
||||
|
||||
private String msg;
|
||||
private int code;
|
||||
private final String msg;
|
||||
private final int code;
|
||||
|
||||
public BusinessException(ResultCode resultCode) {
|
||||
super(resultCode.getMessage());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hccake.ballcat.common.conf.web;
|
||||
package com.hccake.ballcat.common.core.exception;
|
||||
|
||||
import com.hccake.ballcat.common.core.exception.BusinessException;
|
||||
import com.hccake.ballcat.common.core.result.SystemResultCode;
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.conf.exception.handler;
|
||||
package com.hccake.ballcat.common.core.exception.handler;
|
||||
|
||||
/**
|
||||
* @author Hccake
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.conf.exception.handler;
|
||||
package com.hccake.ballcat.common.core.exception.handler;
|
||||
|
||||
/**
|
||||
* @author Hccake
|
||||
@@ -17,16 +17,24 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The type Actuator filter.
|
||||
*
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/17 20:28
|
||||
* @date 2019 /10/17 20:28
|
||||
*/
|
||||
public class ActuatorFilter extends OncePerRequestFilter {
|
||||
|
||||
private String secretId;
|
||||
private String secretKey;
|
||||
private final String secretId;
|
||||
private final String secretKey;
|
||||
|
||||
public ActuatorFilter(String secretId, String secretKey){
|
||||
/**
|
||||
* Instantiates a new Actuator filter.
|
||||
*
|
||||
* @param secretId the secret id
|
||||
* @param secretKey the secret key
|
||||
*/
|
||||
public ActuatorFilter(String secretId, String secretKey){
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
@@ -38,9 +46,9 @@ public class ActuatorFilter extends OncePerRequestFilter {
|
||||
* <p>Provides HttpServletRequest and HttpServletResponse arguments instead of the
|
||||
* default ServletRequest and ServletResponse ones.
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param filterChain
|
||||
* @param request 请求信息
|
||||
* @param response 响应信息
|
||||
* @param filterChain 过滤器链
|
||||
*/
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||
@@ -58,13 +66,13 @@ public class ActuatorFilter extends OncePerRequestFilter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验sign
|
||||
* @param reqSecretId
|
||||
* @param sign
|
||||
* @param reqTime
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* 校验sign
|
||||
* @param reqSecretId secretId
|
||||
* @param sign 签名
|
||||
* @param reqTime 请求时间戳 ms
|
||||
* @return boolean 通过返回true
|
||||
*/
|
||||
private boolean verifySign(String reqSecretId, String sign, String reqTime) {
|
||||
if (StrUtil.isNotBlank(sign) && StrUtil.isNotBlank(reqTime) && StrUtil.isNotBlank(reqSecretId)) {
|
||||
if(!reqSecretId.equals(secretId)){
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hccake.ballcat.common.core.filter;
|
||||
|
||||
import com.hccake.ballcat.common.core.request.wrapper.XSSRequestWrapper;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
|
||||
@@ -16,32 +16,29 @@ import java.util.Map;
|
||||
* @date 2019/10/17 23:19
|
||||
*/
|
||||
public class ArraySerializerModifier extends BeanSerializerModifier {
|
||||
|
||||
private JsonSerializer<Object> nullArrayJsonSerializer = new NullArrayJsonSerializer();
|
||||
|
||||
private JsonSerializer<Object> nullMapJsonSerializer = new NullMapJsonSerializer();
|
||||
private final JsonSerializer<Object> nullArrayJsonSerializer = new NullArrayJsonSerializer();
|
||||
private final JsonSerializer<Object> nullMapJsonSerializer = new NullMapJsonSerializer();
|
||||
|
||||
|
||||
@Override
|
||||
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
|
||||
List<BeanPropertyWriter> beanProperties) {
|
||||
// 循环所有的beanPropertyWriter
|
||||
for (int i = 0; i < beanProperties.size(); i++) {
|
||||
BeanPropertyWriter writer = beanProperties.get(i);
|
||||
// 判断字段的类型,如果是array,list,set则注册nullSerializer
|
||||
if (isArrayType(writer)) {
|
||||
writer.assignNullSerializer(this.nullArrayJsonSerializer);
|
||||
}else if (isMapType(writer)){
|
||||
writer.assignNullSerializer(this.nullMapJsonSerializer);
|
||||
}
|
||||
}
|
||||
for (BeanPropertyWriter writer : beanProperties) {
|
||||
// 判断字段的类型,如果是array,list,set则注册nullSerializer
|
||||
if (isArrayType(writer)) {
|
||||
writer.assignNullSerializer(this.nullArrayJsonSerializer);
|
||||
} else if (isMapType(writer)) {
|
||||
writer.assignNullSerializer(this.nullMapJsonSerializer);
|
||||
}
|
||||
}
|
||||
return beanProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是Map类型
|
||||
* @param writer
|
||||
* @return
|
||||
* @param writer BeanPropertyWriter
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean isMapType(BeanPropertyWriter writer) {
|
||||
Class<?> clazz = writer.getType().getRawClass();
|
||||
@@ -50,8 +47,8 @@ public class ArraySerializerModifier extends BeanSerializerModifier {
|
||||
|
||||
/**
|
||||
* 是否是集合类型
|
||||
* @param writer
|
||||
* @return
|
||||
* @param writer BeanPropertyWriter
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean isArrayType(BeanPropertyWriter writer) {
|
||||
Class<?> clazz = writer.getType().getRawClass();
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.IOException;
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/17 23:17
|
||||
* 空数组序列化处理器
|
||||
* 如果 Array 为 null,则序列化为 []
|
||||
*/
|
||||
public class NullArrayJsonSerializer extends JsonSerializer<Object> {
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.IOException;
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/17 23:17
|
||||
* 空 Map 序列化处理器
|
||||
* Map 为 null,则序列化为 {}
|
||||
*/
|
||||
public class NullMapJsonSerializer extends JsonSerializer<Object> {
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.io.IOException;
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/17 22:19
|
||||
* jackson NULL值序列化为""
|
||||
* jackson NULL值序列化为 ""
|
||||
*/
|
||||
public class NullSerializer extends JsonSerializer<Object> {
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.filter;
|
||||
package com.hccake.ballcat.common.core.request.wrapper;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.filter;
|
||||
package com.hccake.ballcat.common.core.request.wrapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.core.filter;
|
||||
package com.hccake.ballcat.common.core.request.wrapper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.util.HtmlUtils;
|
||||
@@ -35,6 +35,6 @@ public enum SystemResultCode implements ResultCode {
|
||||
SERVER_ERROR(500, "Internal Server Error");
|
||||
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
private final Integer code;
|
||||
private final String message;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.hccake.ballcat.commom.log.access.filter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.hccake.ballcat.commom.log.access.handler.AccessLogHandler;
|
||||
import com.hccake.ballcat.commom.log.util.LogUtils;
|
||||
import com.hccake.ballcat.common.core.filter.RepeatBodyRequestWrapper;
|
||||
import com.hccake.ballcat.common.core.request.wrapper.RepeatBodyRequestWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user