-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
3,489 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?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>base-module</artifactId> | ||
<groupId>cn.zm</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>common</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<hutool.version>5.3.10</hutool.version> | ||
<knife4j.version>2.0.8</knife4j.version> | ||
<mysql.version>8.0.27</mysql.version> | ||
<fastjson.version>1.2.58</fastjson.version> | ||
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cn.zm</groupId> | ||
<artifactId>knife4j</artifactId> | ||
</dependency> | ||
|
||
<!-- commons-lang3 --> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<!--<version>${commons-lang3.version}</version>--> | ||
</dependency> | ||
|
||
<!-- test --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
|
||
<!-- web --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- fastjson --> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<version>${fastjson.version}</version> | ||
</dependency> | ||
|
||
<!--Actuator:springboot程序监控器--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
|
||
<!-- hutool 工具 --> | ||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-all</artifactId> | ||
<version>${hutool.version}</version> | ||
</dependency> | ||
|
||
<!-- aop --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
|
||
|
||
<!-- SpringMVC校验 --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>${hibernate-validator.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
trip-web-server/base-module/common/src/main/java/cn/zm/common/annotation/SetNull.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cn.zm.common.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Mr_W | ||
* @date 2021/2/18 12:37 | ||
* @description: 当入参验证分组和该分组一致时设置为 null | ||
*/ | ||
@Documented | ||
@Target(FIELD) | ||
@Retention(RUNTIME) | ||
public @interface SetNull { | ||
|
||
Class<?> group(); | ||
|
||
} |
133 changes: 133 additions & 0 deletions
133
...server/base-module/common/src/main/java/cn/zm/common/aspect/DataTransferObjectAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package cn.zm.common.aspect; | ||
|
||
import cn.zm.common.annotation.SetNull; | ||
import cn.zm.common.base.ServiceException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
/** | ||
* @author Mr_W | ||
* @date 2021/2/18 9:22 | ||
* @description dto 参数切面 | ||
*/ | ||
@Aspect | ||
@Slf4j | ||
@Component | ||
public class DataTransferObjectAspect { | ||
@Pointcut("execution(public * com.*.*.*.web.*.*(..))") | ||
public void pointcut() {} | ||
|
||
@Around("pointcut()") | ||
public Object proceed(ProceedingJoinPoint p) throws Throwable { | ||
Instant now = Instant.now(); | ||
MethodSignature signature = (MethodSignature) p.getSignature(); | ||
Method method = signature.getMethod(); | ||
Annotation[][] methodAnnotations = method.getParameterAnnotations(); | ||
for (int i = 0; i < methodAnnotations.length; i++) { | ||
for (Annotation annotation : methodAnnotations[i]) { | ||
if (annotation instanceof Validated) { | ||
// 如果有分组 | ||
if (((Validated) annotation).value().length != 0) { | ||
p.getArgs()[i] = buildParams(p.getArgs()[i], ((Validated) annotation).value()[0]); | ||
} | ||
} | ||
} | ||
} | ||
log.debug("入参构建完毕, 用时: [{}] ms", Duration.between(now, Instant.now()).toMillis()); | ||
return p.proceed(); | ||
} | ||
|
||
/** | ||
* 构建入参 | ||
* @param obj 原始入参 | ||
* @return 构建后的入参 | ||
*/ | ||
private Object buildParams(Object obj, Class<?> type) { | ||
for (Field field : obj.getClass().getDeclaredFields()) { | ||
for (Annotation annotation : field.getAnnotations()) { | ||
if (annotation instanceof SetNull) { | ||
try { | ||
Method groupMethod = annotation.annotationType().getDeclaredMethod("group"); | ||
Class<?> group = (Class<?>) groupMethod.invoke(annotation); | ||
if (type.isAssignableFrom(group)) { | ||
field.setAccessible(true); | ||
field.set(obj, null); | ||
field.setAccessible(false); | ||
} | ||
} catch (NoSuchMethodException e) { | ||
log.error("没有 groups 方法", e); | ||
throw ServiceException.serviceException("服务器异常", e).build(); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
log.error("groups 方法执行失败", e); | ||
throw ServiceException.serviceException("服务器异常", e).build(); | ||
} | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
|
||
// @Around("pointcut()") | ||
// public Object proceed(ProceedingJoinPoint p) throws Throwable { | ||
// Instant now = Instant.now(); | ||
// MethodSignature signature = (MethodSignature) p.getSignature(); | ||
// Method method = signature.getMethod(); | ||
// Annotation[][] methodAnnotations = method.getParameterAnnotations(); | ||
// for (int i = 0; i < methodAnnotations.length; i++) { | ||
// for (Annotation annotation : methodAnnotations[i]) { | ||
// if (annotation instanceof Validated) { | ||
// // 如果有分组 | ||
// if (((Validated) annotation).value().length != 0) { | ||
// p.getArgs()[i] = buildParams(p.getArgs()[i], ((Validated) annotation).value()[0]); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// LOGGER.debug("入参构建完毕, 用时: [{}] ms", Duration.between(now, Instant.now()).toMillis()); | ||
// return proceed(p); | ||
// } | ||
// | ||
// /** | ||
// * 构建入参 | ||
// * @param obj 原始入参 | ||
// * @return 构建后的入参 | ||
// */ | ||
// private Object buildParams(Object obj, Class<?> type) { | ||
// for (Field field : obj.getClass().getDeclaredFields()) { | ||
// for (Annotation annotation : field.getAnnotations()) { | ||
// if (annotation.annotationType().getName().contains("javax.validation.constraints")) { | ||
// try { | ||
// Method groups = annotation.annotationType().getDeclaredMethod("groups"); | ||
// Class<?> group = ((Class<?>[]) groups.invoke(annotation))[0]; | ||
// if (!type.isAssignableFrom(group)) { | ||
// field.setAccessible(true); | ||
// field.set(obj, null); | ||
// field.setAccessible(false); | ||
// } | ||
// } catch (NoSuchMethodException e) { | ||
// LOGGER.error("没有 groups 方法", e); | ||
// throw new ServiceException("服务器异常"); | ||
// } catch (IllegalAccessException | InvocationTargetException e) { | ||
// LOGGER.error("groups 方法执行失败", e); | ||
// throw new ServiceException("服务器异常"); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// return obj; | ||
// } | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
trip-web-server/base-module/common/src/main/java/cn/zm/common/base/BaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cn.zm.common.base; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.*; | ||
|
||
@Data | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@ApiModel(value = "基础条件依赖", description = "基础条件依赖") | ||
public class BaseEntity { | ||
@ApiModelProperty(value = "页数") | ||
private String page; | ||
@ApiModelProperty(value="长度") | ||
private String size; | ||
@ApiModelProperty(value="排序资源") | ||
private String orderByColumn; | ||
@ApiModelProperty(value="正倒序") | ||
private boolean isDesc; | ||
} |
15 changes: 15 additions & 0 deletions
15
trip-web-server/base-module/common/src/main/java/cn/zm/common/base/Child.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.zm.common.base; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Child<T> { | ||
String id; | ||
List<T> child; | ||
} |
Oops, something went wrong.