Pre Merge pull request !263 from 小诺/dev

pull/263/MERGE
小诺 2025-05-22 13:35:29 +00:00 committed by Gitee
commit 1e491f52ef
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 180 additions and 173 deletions

View File

@ -16,6 +16,9 @@ Snowy谐音“小诺”恰应小诺团队名称意思为”下雪的、纯
<p align="center">
<p align="center">
<a href="https://gitcode.com/xiaonuobase/Snowy">
<img src="https://gitcode.com/xiaonuobase/Snowy/star/badge.svg" alt="bootstrap">
</a>
<a href="https://gitee.com/xiaonuobase/snowy">
<img src="https://gitee.com/xiaonuobase/snowy/badge/star.svg?theme=dark" alt="Gitee star">
</a>

View File

@ -29,6 +29,9 @@ public enum AuthExceptionEnum {
/** 验证码请求号不能为空 */
VALID_CODE_REQ_NO_EMPTY("验证码请求号不能为空"),
/** 验证码过期 */
VALID_CODE_EXPIRED("验证码过期"),
/** 验证码错误 */
VALID_CODE_ERROR("验证码错误"),

View File

@ -327,11 +327,15 @@ public class AuthServiceImpl implements AuthService {
// 手机或者邮箱验证码
existValidCode = commonCacheOperator.get(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
}
// 为空则直接验证码错误
if(ObjectUtil.isEmpty(existValidCode)) {
// 缓存中不存在验证码则返回失效错误
if (ObjectUtil.isEmpty(existValidCode)){
throw new CommonException(AuthExceptionEnum.VALID_CODE_EXPIRED.getValue());
}
// 不一致则直接验证码错误
if (!validCode.equalsIgnoreCase(Convert.toStr(existValidCode))) {
throw new CommonException(AuthExceptionEnum.VALID_CODE_ERROR.getValue());
}
// 移除该验证码
// 验证成功,移除该验证码
if(ObjectUtil.isEmpty(phoneOrEmail)) {
// 图形验证码
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + validCodeReqNo);
@ -339,10 +343,6 @@ public class AuthServiceImpl implements AuthService {
// 手机或者邮箱验证码
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
}
// 不一致则直接验证码错误
if (!validCode.equalsIgnoreCase(Convert.toStr(existValidCode))) {
throw new CommonException("验证码错误");
}
}
/**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,165 +1,165 @@
package vip.xiaonuo.core.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* Jackson
* null
*/
@Configuration
public class JacksonConfig {
private static final ThreadLocal<Boolean> IS_APP_REQUEST = ThreadLocal.withInitial(() -> false);
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
// 若是APP端请求则处理响应结果字段默认值
if (IS_APP_REQUEST.get()) {
handleNullValue(gen);
} else {
gen.writeNull();
}
}
private void handleNullValue(JsonGenerator gen) throws IOException {
JsonStreamContext context = gen.getOutputContext();
if (context.inObject()) {
String fieldName = context.getCurrentName();
Object currentObj = context.getCurrentValue();
if (currentObj != null) {
Class<?> clazz = currentObj.getClass();
Field field = getField(clazz, fieldName);
if (field != null) {
setDefaultByType(field.getType(), gen);
return;
}
}
}
// 默认处理
gen.writeString("");
}
private Field getField(Class<?> clazz, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException e) {
// 查找父类字段
Class<?> superClass = clazz.getSuperclass();
while (superClass != null) {
try {
Field field = superClass.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
superClass = superClass.getSuperclass();
}
}
}
return null;
}
private void setDefaultByType(Class<?> type, JsonGenerator gen) throws IOException {
if (type.isPrimitive()) {
handlePrimitive(type, gen);
} else if (type == String.class) {
gen.writeString("");
} else if (Number.class.isAssignableFrom(type)) {
gen.writeNumber(0);
} else if (type == Boolean.class) {
gen.writeBoolean(false);
} else if (type == Date.class) {
gen.writeString("");
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
gen.writeStartArray();
gen.writeEndArray();
} else if (Map.class.isAssignableFrom(type)) {
gen.writeStartObject();
gen.writeEndObject();
} else {
gen.writeStartObject();
gen.writeEndObject();
}
}
private void handlePrimitive(Class<?> type, JsonGenerator gen) throws IOException {
if (type == int.class) {
gen.writeNumber(0);
} else if (type == long.class) {
gen.writeNumber(0L);
} else if (type == double.class) {
gen.writeNumber(0.0);
} else if (type == float.class) {
gen.writeNumber(0.0f);
} else if (type == boolean.class) {
gen.writeBoolean(false);
} else if (type == char.class) {
gen.writeString(String.valueOf('\0'));
} else {
gen.writeNull();
}
}
});
return objectMapper;
}
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
IS_APP_REQUEST.set(isAppRequest(request));
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
IS_APP_REQUEST.remove();
}
});
}
};
}
/**
*
* path
*/
private boolean isAppRequest(HttpServletRequest request) {
String path = request.getRequestURI();
String userAgent = request.getHeader("User-Agent");
return path.startsWith("/client/c/app/") || path.startsWith("/auth/c/");
}
}
package vip.xiaonuo.core.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* Jackson
* null
*/
@Configuration
public class JacksonConfigure {
private static final ThreadLocal<Boolean> IS_APP_REQUEST = ThreadLocal.withInitial(() -> false);
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
// 若是APP端请求则处理响应结果字段默认值
if (IS_APP_REQUEST.get()) {
handleNullValue(gen);
} else {
gen.writeNull();
}
}
private void handleNullValue(JsonGenerator gen) throws IOException {
JsonStreamContext context = gen.getOutputContext();
if (context.inObject()) {
String fieldName = context.getCurrentName();
Object currentObj = context.getCurrentValue();
if (currentObj != null) {
Class<?> clazz = currentObj.getClass();
Field field = getField(clazz, fieldName);
if (field != null) {
setDefaultByType(field.getType(), gen);
return;
}
}
}
// 默认处理
gen.writeString("");
}
private Field getField(Class<?> clazz, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException e) {
// 查找父类字段
Class<?> superClass = clazz.getSuperclass();
while (superClass != null) {
try {
Field field = superClass.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
superClass = superClass.getSuperclass();
}
}
}
return null;
}
private void setDefaultByType(Class<?> type, JsonGenerator gen) throws IOException {
if (type.isPrimitive()) {
handlePrimitive(type, gen);
} else if (type == String.class) {
gen.writeString("");
} else if (Number.class.isAssignableFrom(type)) {
gen.writeNumber(0);
} else if (type == Boolean.class) {
gen.writeBoolean(false);
} else if (type == Date.class) {
gen.writeString("");
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
gen.writeStartArray();
gen.writeEndArray();
} else if (Map.class.isAssignableFrom(type)) {
gen.writeStartObject();
gen.writeEndObject();
} else {
gen.writeStartObject();
gen.writeEndObject();
}
}
private void handlePrimitive(Class<?> type, JsonGenerator gen) throws IOException {
if (type == int.class) {
gen.writeNumber(0);
} else if (type == long.class) {
gen.writeNumber(0L);
} else if (type == double.class) {
gen.writeNumber(0.0);
} else if (type == float.class) {
gen.writeNumber(0.0f);
} else if (type == boolean.class) {
gen.writeBoolean(false);
} else if (type == char.class) {
gen.writeString(String.valueOf('\0'));
} else {
gen.writeNull();
}
}
});
return objectMapper;
}
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
IS_APP_REQUEST.set(isAppRequest(request));
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
IS_APP_REQUEST.remove();
}
});
}
};
}
/**
*
* path
*/
private boolean isAppRequest(HttpServletRequest request) {
String path = request.getRequestURI();
String userAgent = request.getHeader("User-Agent");
return path.startsWith("/client/c/app/") || path.startsWith("/auth/c/");
}
}

View File

@ -895,7 +895,7 @@ CREATE TABLE `MOBILE_RESOURCE` (
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380023993298945', NULL, '业务', '217gcp9ifi', 'MODULE', NULL, NULL, NULL, 'container-outlined', '#1890ff', NULL, NULL, 1, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380258656219138', '0', '机构管理', 'UJ3Iwy3jsW', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/org/index', 'apartment-outlined', '#1890ff', 'YES', 'ENABLE', 0, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380614295449601', '0', '岗位管理', 'sjIY9oGYir', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/position/index', 'robot-outlined', '#9c28b1', 'YES', 'ENABLE', 2, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380765202313218', '0', '人员管理', 'sjIY9oGYir', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/user/index', 'team-outlined', '#fed835', 'YES', 'ENABLE', 4, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380765202313218', '0', '人员管理', '2ppITl9dMw', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/user/index', 'team-outlined', '#fed835', 'YES', 'ENABLE', 4, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381127095250946', '0', '更多', 'mFVJNzE7gx', 'MENU', '1623380023993298945', 'CATALOG', '7029146815941316608', 'small-dash-outlined', '#f1627e', 'YES', 'ENABLE', 7, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381298801668098', '1623380258656219138', '新增机构', 'mobileBizOrgAdd', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381632131395586', '1623380258656219138', '编辑机构', 'mobileBizOrgEdit', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);

View File

@ -84,6 +84,7 @@ spring.datasource.dynamic.druid.validation-query-timeout=2000
spring.datasource.dynamic.druid.test-on-borrow=false
spring.datasource.dynamic.druid.test-on-return=false
spring.datasource.dynamic.druid.test-while-idle=true
spring.datasource.dynamic.druid.validation-query=SELECT 1
spring.datasource.dynamic.druid.time-between-eviction-runs-millis=6000
spring.datasource.dynamic.druid.min-evictable-idle-time-millis=300000
spring.datasource.dynamic.druid.filters=stat