commit 8888e7981f78c95e3f03c70b149bf1e683ea0771
Author: 刘泽璋 <2833784085@qq.com@user.noreply.gitee.com>
Date: Wed Jun 19 17:04:09 2024 +0800
第一次
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..7909b96
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..7ffa493
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..5a2f139
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..325840e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml
new file mode 100644
index 0000000..9a7566c
--- /dev/null
+++ b/.idea/qaplug_profiles.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..43d5b7f
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "customColor": "",
+ "associatedIndex": 3
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1718786660406
+
+
+ 1718786660406
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etl-common/pom.xml b/etl-common/pom.xml
new file mode 100644
index 0000000..412ed7b
--- /dev/null
+++ b/etl-common/pom.xml
@@ -0,0 +1,137 @@
+
+
+ 4.0.0
+
+ com.bwie
+ etl-cloud
+ 1.0-SNAPSHOT
+
+ etl-common
+ etl-common
+
+ 1.8
+ UTF-8
+ UTF-8
+ 2.6.13
+
+
+
+ net.sourceforge.tess4j
+ tess4j
+ 4.5.5
+
+
+ commons-codec
+ commons-codec
+ 1.15
+
+
+
+ com.github.xiaoymin
+ knife4j-openapi2-spring-boot-starter
+ 4.4.0
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.apache.commons
+ commons-lang3
+
+
+ cn.hutool
+ hutool-all
+ 5.8.3
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.26
+
+
+
+ io.jsonwebtoken
+ jjwt
+ 0.9.1
+
+
+ org.projectlombok
+ lombok
+ 1.18.22
+
+
+ org.springframework
+ spring-web
+ 5.3.31
+
+
+ org.apache.tomcat.embed
+ tomcat-embed-core
+ 9.0.83
+
+
+ io.swagger
+ swagger-annotations
+ 1.6.6
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+ 3.1.8
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ ${spring-boot.version}
+ pom
+ import
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring-boot.version}
+
+ com.health.cloud.common.HealthCloudCommonApplication
+ true
+
+
+
+ repackage
+
+ repackage
+
+
+
+
+
+
+
+
+
diff --git a/etl-common/src/main/java/com/etl/common/BaseEntity.java b/etl-common/src/main/java/com/etl/common/BaseEntity.java
new file mode 100644
index 0000000..7dc1ced
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/BaseEntity.java
@@ -0,0 +1,43 @@
+package com.etl.common;
+/**
+ * @Author:fzx
+ * @Package:com.health.cloud.common
+ * @Project:health-cloud
+ * @name:BaseEntity
+ * @Date:2024/5/23 21:36
+ */
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ *@name:BaseEntity
+ *@Author:fzx
+ *@Description: 描述
+ *@Project:health-cloud
+ *@Date:2024/5/23 21:36
+ */
+@Data
+public class BaseEntity {
+ /**
+ * 创建时间
+ */
+ private Date createTime;
+ /**
+ * 创建人
+ */
+ private Integer createBy;
+ /**
+ * 修改时间
+ */
+ private Date updateTime;
+ /**
+ * 修改人
+ */
+ private Integer updateBy;
+ /**
+ * 是否删除(0-否 1-是)
+ */
+ private Integer isDelete;
+}
diff --git a/etl-common/src/main/java/com/etl/common/Entity.java b/etl-common/src/main/java/com/etl/common/Entity.java
new file mode 100644
index 0000000..bc797d2
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/Entity.java
@@ -0,0 +1,27 @@
+package com.etl.common;
+
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+@Data
+@ApiModel("实体类公共字段")
+public class Entity {
+
+ @ApiModelProperty("创建时间")
+ private Date createTime;
+ @ApiModelProperty("修改时间")
+ private Date updateTime;
+ @ApiModelProperty("创建人")
+ private Long createBy;
+ @ApiModelProperty("修改人")
+ private Long updateBy;
+ @ApiModelProperty("/是否删除")
+ private Long isDeleted;
+
+
+
+
+}
diff --git a/etl-common/src/main/java/com/etl/common/constants/Constants.java b/etl-common/src/main/java/com/etl/common/constants/Constants.java
new file mode 100644
index 0000000..55813c8
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/constants/Constants.java
@@ -0,0 +1,18 @@
+package com.etl.common.constants;
+
+/**
+ * @description: 系统常量
+ * @author dongyan Ma
+ */
+public class Constants {
+ /**
+ * 成功标记
+ */
+ public static final Integer SUCCESS = 200;
+ public static final String SUCCESS_MSG = "操作成功";
+ /**
+ * 失败标记
+ */
+ public static final Integer ERROR = 500;
+ public static final String ERROR_MSG = "操作异常";
+}
diff --git a/etl-common/src/main/java/com/etl/common/constants/JwtConstants.java b/etl-common/src/main/java/com/etl/common/constants/JwtConstants.java
new file mode 100644
index 0000000..48ac386
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/constants/JwtConstants.java
@@ -0,0 +1,29 @@
+package com.etl.common.constants;
+
+/**
+ * @author dongyan Ma
+ * @description: Jwt常量
+ */
+public class JwtConstants {
+
+ /**
+ * 用户ID字段
+ */
+ public static final String DETAILS_USER_ID = "user_id";
+
+ /**
+ * 用户名字段
+ */
+ public static final String DETAILS_USERNAME = "username";
+
+ /**
+ * 用户标识
+ */
+ public static final String USER_KEY = "user_key";
+
+ /**
+ * 令牌秘钥
+ */
+ public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
+
+}
diff --git a/etl-common/src/main/java/com/etl/common/constants/TokenConstants.java b/etl-common/src/main/java/com/etl/common/constants/TokenConstants.java
new file mode 100644
index 0000000..ad6bbce
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/constants/TokenConstants.java
@@ -0,0 +1,24 @@
+package com.etl.common.constants;
+
+/**
+ * @author dongyan Ma
+ * @description: 令牌常量
+ */
+public class TokenConstants {
+ /**
+ * 缓存有效期,默认720(分钟)
+ */
+ public final static long EXPIRATION = 720;
+ /**
+ * 缓存刷新时间,默认120(分钟)
+ */
+ public final static long REFRESH_TIME = 120;
+ /**
+ * 权限缓存前缀
+ */
+ public final static String LOGIN_TOKEN_KEY = "login_tokens:";
+ /**
+ * token标识
+ */
+ public static final String TOKEN = "token";
+}
diff --git a/etl-common/src/main/java/com/etl/common/exception/AllException.java b/etl-common/src/main/java/com/etl/common/exception/AllException.java
new file mode 100644
index 0000000..8398af4
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/exception/AllException.java
@@ -0,0 +1,38 @@
+package com.etl.common.exception;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author:ZiJian.Zhang
+ * @Project:day01_homework
+ * @Package:com.bwie.common.exception
+ * @name:AllException
+ * @Description:请输入
+ * @Date:2024/3/21 14:59
+ */
+@Component
+@Getter
+public class AllException extends RuntimeException {
+
+ @Setter
+ private Integer code;
+
+
+ private String msg;
+
+ public AllException setMsg(String msg) {
+ this.msg = msg;
+ return this;
+ }
+
+ public AllException(Integer code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+
+ public AllException(String msg) {
+ this.msg = msg;
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/exception/GlobalException.java b/etl-common/src/main/java/com/etl/common/exception/GlobalException.java
new file mode 100644
index 0000000..bd5784f
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/exception/GlobalException.java
@@ -0,0 +1,33 @@
+package com.etl.common.exception;
+
+import com.etl.common.result.Result;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import javax.validation.ValidationException;
+
+
+/**
+ *@name:GlobalException
+ *@Author:fzx
+ *@Description: 描述
+ *@Project:health-cloud
+ *@Date:2024/5/30 13:02
+ */
+@RestControllerAdvice
+public class GlobalException {
+ @ExceptionHandler(Exception.class)
+ public Result exception(Exception e){
+ return Result.error(e.getMessage());
+ }
+
+ @ExceptionHandler(ValidationException.class)
+ public Result validation(Exception e){
+ return Result.error(e.getMessage());
+ }
+
+ @ExceptionHandler(RuntimeException.class)
+ public Result runtimeException(Exception e){
+ return Result.error(e.getMessage());
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/exception/ServiceException.java b/etl-common/src/main/java/com/etl/common/exception/ServiceException.java
new file mode 100644
index 0000000..89cea7e
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/exception/ServiceException.java
@@ -0,0 +1,60 @@
+package com.etl.common.exception;
+/**
+ * @Author:mdy
+ * @Package:com.bwie.common.exception
+ * @Project:zg4_es
+ * @name:ServiceException
+ * @Date:2024/3/12 19:11
+ */
+
+import lombok.Getter;
+
+/**
+ *@ClassName ServiceException
+ *@Description 描述
+ *@Author YuWei.Cai
+ *@Date 2024/3/12 19:11
+ */
+public class ServiceException extends RuntimeException{
+ @Getter
+ private Integer code;
+
+ private String message;
+
+ public ServiceException(){
+
+ }
+
+ public ServiceException( Integer code,String message){
+ this.message=message;
+ this.code=code;
+ }
+
+ public ServiceException(String message){
+ this.message=message;
+
+ }
+
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public ServiceException setCode(Integer code){
+ this.code=code;
+ return this;
+ }
+
+ public ServiceException setMessage(String message){
+ this.message=message;
+ return this;
+ }
+
+}
diff --git a/etl-common/src/main/java/com/etl/common/handler/ExceptionHandlers.java b/etl-common/src/main/java/com/etl/common/handler/ExceptionHandlers.java
new file mode 100644
index 0000000..794ee96
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/handler/ExceptionHandlers.java
@@ -0,0 +1,75 @@
+package com.etl.common.handler;
+
+import com.etl.common.exception.AllException;
+import com.etl.common.result.Result;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.BindException;
+import org.springframework.validation.ObjectError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+import java.util.stream.Collectors;
+
+/**
+ * @Author:ZiJian.Zhang
+ * @Project:day01_homework
+ * @Package:com.bwie.common.handler
+ * @name:ExceptionHandler
+ * @Description:异常处理器
+ * @Date:2024/3/21 15:03
+ */
+@RestControllerAdvice
+public class ExceptionHandlers {
+
+ /**
+ * 自定义异常处理
+ * @param allException 自定义异常
+ * @return 返回统一结果集
+ */
+ @ExceptionHandler(AllException.class)
+ public Result result(AllException allException){
+ return Result.error(allException.getMsg());
+ }
+
+
+ /**
+ * 参数校验的拦截
+ */
+ @ExceptionHandler(value = {BindException.class, ValidationException.class, MethodArgumentNotValidException.class})
+ public ResponseEntity> handleValidatedException(Exception e) {
+ Result result = null;
+ if (e instanceof MethodArgumentNotValidException) {
+ MethodArgumentNotValidException ex = (MethodArgumentNotValidException) e;
+ String errorMessages = ex.getBindingResult().getAllErrors().stream()
+ .map(ObjectError::getDefaultMessage)
+ .collect(Collectors.joining(";"));
+ result = Result.error(HttpStatus.BAD_REQUEST.value(), errorMessages);
+ } else if (e instanceof ConstraintViolationException) {
+ ConstraintViolationException ex = (ConstraintViolationException) e;
+ String errorMessages = ex.getConstraintViolations().stream()
+ .map(ConstraintViolation::getMessage)
+ .collect(Collectors.joining(";"));
+ result = Result.error(HttpStatus.BAD_REQUEST.value(), errorMessages);
+ } else if (e instanceof BindException) {
+ BindException ex = (BindException) e;
+ String errorMessages = ex.getAllErrors().stream()
+ .map(ObjectError::getDefaultMessage)
+ .collect(Collectors.joining(";"));
+ result = Result.error(HttpStatus.BAD_REQUEST.value(), errorMessages);
+ }
+ return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST);
+ }
+
+ /**
+ * 处理 form data方式调用接口校验失败抛出的异常 (对象参数)
+ */
+ @ExceptionHandler(Exception.class)
+ public Result error(Exception e) {
+ return Result.error(e.getMessage());
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/result/PageResult.java b/etl-common/src/main/java/com/etl/common/result/PageResult.java
new file mode 100644
index 0000000..e61f931
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/result/PageResult.java
@@ -0,0 +1,34 @@
+package com.etl.common.result;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author dongyan Ma
+ * @description: 列表返回结果集
+ */
+@Data
+public class PageResult implements Serializable {
+ /**
+ * 总条数
+ */
+ private long total;
+ /**
+ * 结果集合
+ */
+ private List list;
+ public PageResult() {
+ }
+ public PageResult(long total, List list) {
+ this.total = total;
+ this.list = list;
+ }
+ public static PageResult toPageResult(long total, List list){
+ return new PageResult(total , list);
+ }
+ public static Result> toResult(long total, List list){
+ return Result.success(PageResult.toPageResult(total,list));
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/result/Result.java b/etl-common/src/main/java/com/etl/common/result/Result.java
new file mode 100644
index 0000000..ee12c23
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/result/Result.java
@@ -0,0 +1,79 @@
+package com.etl.common.result;
+
+
+
+import com.etl.common.constants.Constants;
+import lombok.Data;
+
+
+import java.io.Serializable;
+
+/**
+ * @author dongyan Ma
+ * @description: 响应信息主体
+ */
+@Data
+public class Result implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ /**
+ * 成功
+ */
+ public static final int SUCCESS = Constants.SUCCESS;
+ /**
+ * 失败
+ */
+ public static final int FAIL = Constants.ERROR;
+ /**
+ * 返回状态码
+ */
+ private int code;
+ /**
+ * 响应信息
+ */
+ private String msg;
+ /**
+ * 响应数据
+ */
+ private T data;
+
+ public static Result success() {
+ return restResult(null, SUCCESS, Constants.SUCCESS_MSG);
+ }
+
+ public static Result success(T data) {
+ return restResult(data, SUCCESS, Constants.SUCCESS_MSG);
+ }
+
+ public static Result success(T data, String msg) {
+ return restResult(data, SUCCESS, msg);
+ }
+
+ public static Result error() {
+ return restResult(null, FAIL, Constants.ERROR_MSG);
+ }
+
+ public static Result error(String msg) {
+ return restResult(null, FAIL, msg);
+ }
+
+ public static Result error(T data) {
+ return restResult(data, FAIL, Constants.ERROR_MSG);
+ }
+
+ public static Result error(T data, String msg) {
+ return restResult(data, FAIL, msg);
+ }
+
+ public static Result error(int code, String msg) {
+ return restResult(null, code, msg);
+ }
+
+ private static Result restResult(T data, int code, String msg) {
+ Result apiResult = new Result<>();
+ apiResult.setCode(code);
+ apiResult.setData(data);
+ apiResult.setMsg(msg);
+ return apiResult;
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/result/ResultBody.java b/etl-common/src/main/java/com/etl/common/result/ResultBody.java
new file mode 100644
index 0000000..064687d
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/result/ResultBody.java
@@ -0,0 +1,57 @@
+package com.etl.common.result;/**
+ * @Author:fzx
+ * @Package:com.health.cloud.common.result
+ * @Project:health-cloud
+ * @name:ResultBoby
+ * @Date:2024/5/30 12:57
+ */
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+ /**
+ *@name:ResultBoby
+ *@Author:fzx
+ *@Description: 描述
+ *@Project:health-cloud
+ *@Date:2024/5/30 12:57
+ */
+@Data
+@NoArgsConstructor
+public class ResultBody {
+ private Integer code;
+ private String msg;
+ private Object data;
+
+ /**
+ * 操作成功
+ * @param data
+ * @return
+ */
+ public static ResultBody success(Object data){
+ ResultBody resultBody = new ResultBody();
+ resultBody.setCode(200);
+ resultBody.setMsg("操作成功");
+ resultBody.setData(data);
+ return resultBody;
+ }
+
+ public static ResultBody success(){
+ ResultBody resultBody = new ResultBody();
+ resultBody.setCode(200);
+ resultBody.setMsg("操作成功");
+ return resultBody;
+ }
+
+ /**
+ * 操作失败
+ * @param message
+ * @return
+ */
+ public static ResultBody fail(String message){
+ ResultBody resultBody = new ResultBody();
+ resultBody.setCode(500);
+ resultBody.setMsg(message);
+ return resultBody;
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/util/JwtUtils.java b/etl-common/src/main/java/com/etl/common/util/JwtUtils.java
new file mode 100644
index 0000000..416a030
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/util/JwtUtils.java
@@ -0,0 +1,110 @@
+package com.etl.common.util;
+
+
+import com.etl.common.constants.JwtConstants;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+
+import java.util.Map;
+
+/**
+ * @description: Jwt工具类
+ * @author dongyan Ma
+ */
+public class JwtUtils {
+
+ /**
+ * 秘钥
+ */
+ public static String secret = JwtConstants.SECRET;
+
+ /**
+ * 从数据声明生成令牌
+ *
+ * @param claims 数据声明
+ * @return 令牌
+ */
+ public static String createToken(Map claims){
+ String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
+ return token;
+ }
+
+ /**
+ * 从令牌中获取数据声明
+ *
+ * @param token 令牌
+ * @return 数据声明
+ */
+ public static Claims parseToken(String token){
+ return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
+ }
+ /**
+ * 根据令牌获取用户标识
+ *
+ * @param token 令牌
+ * @return 用户ID
+ */
+ public static String getUserKey(String token){
+ Claims claims = parseToken(token);
+ return getValue(claims, JwtConstants.USER_KEY);
+ }
+ /**
+ * 根据令牌获取用户标识
+ *
+ * @param claims 身份信息
+ * @return 用户ID
+ */
+ public static String getUserKey(Claims claims){
+ return getValue(claims, JwtConstants.USER_KEY);
+ }
+ /**
+ * 根据令牌获取用户ID
+ *
+ * @param token 令牌
+ * @return 用户ID
+ */
+ public static String getUserId(String token){
+ Claims claims = parseToken(token);
+ return getValue(claims, JwtConstants.DETAILS_USER_ID);
+ }
+ /**
+ * 根据身份信息获取用户ID
+ *
+ * @param claims 身份信息
+ * @return 用户ID
+ */
+ public static String getUserId(Claims claims){
+ return getValue(claims, JwtConstants.DETAILS_USER_ID);
+ }
+ /**
+ * 根据令牌获取用户名
+ *
+ * @param token 令牌
+ * @return 用户名
+ */
+ public static String getUserName(String token){
+ Claims claims = parseToken(token);
+ return getValue(claims, JwtConstants.DETAILS_USERNAME);
+ }
+ /**
+ * 根据身份信息获取用户名
+ *
+ * @param claims 身份信息
+ * @return 用户名
+ */
+ public static String getUserName(Claims claims){
+ return getValue(claims, JwtConstants.DETAILS_USERNAME);
+ }
+ /**
+ * 根据身份信息获取键值
+ *
+ * @param claims 身份信息
+ * @param key 键
+ * @return 值
+ */
+ public static String getValue(Claims claims, String key){
+ Object obj = claims.get(key);
+ return obj == null ? "" : obj.toString();
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/util/RequestUtil.java b/etl-common/src/main/java/com/etl/common/util/RequestUtil.java
new file mode 100644
index 0000000..def007f
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/util/RequestUtil.java
@@ -0,0 +1,47 @@
+package com.etl.common.util;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * 请求工具类
+ * Created by macro on 2020/10/8.
+ */
+public class RequestUtil {
+
+ /**
+ * 获取请求真实IP地址
+ */
+ public static String getRequestIp(HttpServletRequest request) {
+ //通过HTTP代理服务器转发时添加
+ String ipAddress = request.getHeader("x-forwarded-for");
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+ ipAddress = request.getHeader("Proxy-Client-IP");
+ }
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+ ipAddress = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+ ipAddress = request.getRemoteAddr();
+ // 从本地访问时根据网卡取本机配置的IP
+ if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) {
+ InetAddress inetAddress = null;
+ try {
+ inetAddress = InetAddress.getLocalHost();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ ipAddress = inetAddress.getHostAddress();
+ }
+ }
+ // 通过多个代理转发的情况,第一个IP为客户端真实IP,多个IP会按照','分割
+ if (ipAddress != null && ipAddress.length() > 15) {
+ if (ipAddress.indexOf(",") > 0) {
+ ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
+ }
+ }
+ return ipAddress;
+ }
+
+}
diff --git a/etl-common/src/main/java/com/etl/common/util/RestTemplateConfig.java b/etl-common/src/main/java/com/etl/common/util/RestTemplateConfig.java
new file mode 100644
index 0000000..0cf30e2
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/util/RestTemplateConfig.java
@@ -0,0 +1,13 @@
+package com.etl.common.util;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+public class RestTemplateConfig {
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/util/RestTemplateUtil.java b/etl-common/src/main/java/com/etl/common/util/RestTemplateUtil.java
new file mode 100644
index 0000000..2aae86b
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/util/RestTemplateUtil.java
@@ -0,0 +1,83 @@
+package com.etl.common.util;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import com.alibaba.fastjson2.JSONObject;
+import org.springframework.http.*;
+import org.springframework.stereotype.Component;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class RestTemplateUtil {
+ @Autowired
+ private RestTemplate restTemplate;
+ public JSONObject get(String url, Map queryParams) throws IOException {
+ return get(url, queryParams, new HashMap<>(1));
+ }
+ public JSONObject get(String url, Map queryParams, Map headerParams) throws IOException {
+ String tempUrl = setParamsByAppendUrl(queryParams, url);
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ HttpEntity> httpEntity = new HttpEntity<>(null, headers);
+ ResponseEntity response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class);
+ return JSONObject.parseObject(response.getBody());
+ }
+ public JSONObject get2(String url, Map queryParams, Map headerParams) throws IOException {
+ String tempUrl = setParamsByPath(queryParams, url);
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ HttpEntity> httpEntity = new HttpEntity<>(null, headers);
+ ResponseEntity response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class, queryParams);
+ return JSONObject.parseObject(response.getBody());
+ }
+ public JSONObject post(String url, String json, Map headerParams) {
+ HttpHeaders headers = new HttpHeaders();
+ headerParams.forEach(headers::add);
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ headers.add("Accept", MediaType.APPLICATION_JSON.toString());
+ HttpEntity httpEntity = new HttpEntity<>(json, headers);
+ ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+ return JSONObject.parseObject(response.getBody());
+ }
+ private String setParamsByPath(Map queryParams, String url) {
+ // url?id={id}&name={name}
+ if (queryParams == null || queryParams.isEmpty()) {
+ return url;
+ }
+ StringBuilder sb = new StringBuilder();
+ try {
+ for (Map.Entry entry : queryParams.entrySet()) {
+ sb.append("&").append(entry.getKey()).append("=").append("{").append(entry.getKey()).append("}");
+ }
+ if (!url.contains("?")) {
+ sb.deleteCharAt(0).insert(0, "?");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return url + sb;
+ }
+ private String setParamsByAppendUrl(Map queryParams, String url) {
+ // url?id=1&name=zzc
+ if (queryParams == null || queryParams.isEmpty()) {
+ return url;
+ }
+ StringBuilder sb = new StringBuilder();
+ try {
+ for (Map.Entry entry : queryParams.entrySet()) {
+ sb.append("&").append(entry.getKey()).append("=");
+ sb.append(entry.getValue());
+ }
+ if (!url.contains("?")) {
+ sb.deleteCharAt(0).insert(0, "?");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return url + sb;
+ }
+}
diff --git a/etl-common/src/main/java/com/etl/common/util/StringUtils.java b/etl-common/src/main/java/com/etl/common/util/StringUtils.java
new file mode 100644
index 0000000..0e7ce2e
--- /dev/null
+++ b/etl-common/src/main/java/com/etl/common/util/StringUtils.java
@@ -0,0 +1,70 @@
+package com.etl.common.util;
+
+
+import cn.hutool.core.text.AntPathMatcher;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author dongyan Ma
+ * @description: 字符串处理工具类
+ */
+
+public class StringUtils extends org.apache.commons.lang3.StringUtils {
+
+ /**
+ * * 判断一个对象是否为空
+ *
+ * @param object Object
+ * @return true:为空 false:非空
+ */
+ public static boolean isNull(Object object) {
+ return object == null;
+ }
+
+ /**
+ * * 判断一个Collection是否为空, 包含List,Set,Queue
+ *
+ * @param coll 要判断的Collection
+ * @return true:为空 false:非空
+ */
+ public static boolean isEmpty(Collection> coll) {
+ return isNull(coll) || coll.isEmpty();
+ }
+
+ /**
+ * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
+ *
+ * @param str 指定字符串
+ * @param strs 需要检查的字符串数组
+ * @return 是否匹配
+ */
+ public static boolean matches(String str, List strs) {
+ if (isEmpty(str) || isEmpty(strs)) {
+ return false;
+ }
+ for (String pattern : strs) {
+ if (isMatch(pattern, str))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 判断url是否与规则配置:
+ * ? 表示单个字符;
+ * * 表示一层路径内的任意字符串,不可跨层级;
+ * ** 表示任意层路径;
+ *
+ * @param pattern 匹配规则
+ * @param url 需要匹配的url
+ * @return
+ */
+ public static boolean isMatch(String pattern, String url) {
+ AntPathMatcher matcher = new AntPathMatcher();
+ return matcher.match(pattern, url);
+ }
+}
diff --git a/etl-common/target/classes/com/etl/common/BaseEntity.class b/etl-common/target/classes/com/etl/common/BaseEntity.class
new file mode 100644
index 0000000..20a0dd4
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/BaseEntity.class differ
diff --git a/etl-common/target/classes/com/etl/common/Entity.class b/etl-common/target/classes/com/etl/common/Entity.class
new file mode 100644
index 0000000..b847381
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/Entity.class differ
diff --git a/etl-common/target/classes/com/etl/common/constants/Constants.class b/etl-common/target/classes/com/etl/common/constants/Constants.class
new file mode 100644
index 0000000..642f300
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/constants/Constants.class differ
diff --git a/etl-common/target/classes/com/etl/common/constants/JwtConstants.class b/etl-common/target/classes/com/etl/common/constants/JwtConstants.class
new file mode 100644
index 0000000..214584d
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/constants/JwtConstants.class differ
diff --git a/etl-common/target/classes/com/etl/common/constants/TokenConstants.class b/etl-common/target/classes/com/etl/common/constants/TokenConstants.class
new file mode 100644
index 0000000..a4da1a3
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/constants/TokenConstants.class differ
diff --git a/etl-common/target/classes/com/etl/common/exception/AllException.class b/etl-common/target/classes/com/etl/common/exception/AllException.class
new file mode 100644
index 0000000..75ca5e9
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/exception/AllException.class differ
diff --git a/etl-common/target/classes/com/etl/common/exception/GlobalException.class b/etl-common/target/classes/com/etl/common/exception/GlobalException.class
new file mode 100644
index 0000000..7ef6eb4
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/exception/GlobalException.class differ
diff --git a/etl-common/target/classes/com/etl/common/exception/ServiceException.class b/etl-common/target/classes/com/etl/common/exception/ServiceException.class
new file mode 100644
index 0000000..9e4e551
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/exception/ServiceException.class differ
diff --git a/etl-common/target/classes/com/etl/common/handler/ExceptionHandlers.class b/etl-common/target/classes/com/etl/common/handler/ExceptionHandlers.class
new file mode 100644
index 0000000..abc6feb
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/handler/ExceptionHandlers.class differ
diff --git a/etl-common/target/classes/com/etl/common/result/PageResult.class b/etl-common/target/classes/com/etl/common/result/PageResult.class
new file mode 100644
index 0000000..d765cf8
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/result/PageResult.class differ
diff --git a/etl-common/target/classes/com/etl/common/result/Result.class b/etl-common/target/classes/com/etl/common/result/Result.class
new file mode 100644
index 0000000..cc583af
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/result/Result.class differ
diff --git a/etl-common/target/classes/com/etl/common/result/ResultBody.class b/etl-common/target/classes/com/etl/common/result/ResultBody.class
new file mode 100644
index 0000000..15a7bf8
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/result/ResultBody.class differ
diff --git a/etl-common/target/classes/com/etl/common/util/JwtUtils.class b/etl-common/target/classes/com/etl/common/util/JwtUtils.class
new file mode 100644
index 0000000..84690fd
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/util/JwtUtils.class differ
diff --git a/etl-common/target/classes/com/etl/common/util/RequestUtil.class b/etl-common/target/classes/com/etl/common/util/RequestUtil.class
new file mode 100644
index 0000000..d723dbf
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/util/RequestUtil.class differ
diff --git a/etl-common/target/classes/com/etl/common/util/RestTemplateConfig.class b/etl-common/target/classes/com/etl/common/util/RestTemplateConfig.class
new file mode 100644
index 0000000..5c71b7c
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/util/RestTemplateConfig.class differ
diff --git a/etl-common/target/classes/com/etl/common/util/RestTemplateUtil.class b/etl-common/target/classes/com/etl/common/util/RestTemplateUtil.class
new file mode 100644
index 0000000..00ed40b
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/util/RestTemplateUtil.class differ
diff --git a/etl-common/target/classes/com/etl/common/util/StringUtils.class b/etl-common/target/classes/com/etl/common/util/StringUtils.class
new file mode 100644
index 0000000..9e7f326
Binary files /dev/null and b/etl-common/target/classes/com/etl/common/util/StringUtils.class differ
diff --git a/etl-common/target/maven-archiver/pom.properties b/etl-common/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..72f02fc
--- /dev/null
+++ b/etl-common/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Tue Jun 18 19:06:20 CST 2024
+version=1.0-SNAPSHOT
+groupId=com.bwie
+artifactId=etl-common
diff --git a/etl-gateway/.gitignore b/etl-gateway/.gitignore
new file mode 100644
index 0000000..549e00a
--- /dev/null
+++ b/etl-gateway/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/etl-gateway/pom.xml b/etl-gateway/pom.xml
new file mode 100644
index 0000000..d0fa0ed
--- /dev/null
+++ b/etl-gateway/pom.xml
@@ -0,0 +1,72 @@
+
+
+ 4.0.0
+
+ com.bwie
+ etl-cloud
+ 1.0-SNAPSHOT
+
+ etl-gateway
+ etl-gateway
+
+ 1.8
+ UTF-8
+ UTF-8
+ 2.6.13
+ 2021.0.5.0
+ 2021.0.5
+
+
+
+ com.bwie
+ etl-common
+ 1.0-SNAPSHOT
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+ 3.1.3
+
+
+ javax.servlet
+ javax.servlet-api
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+ 3.1.3
+
+
+
+ com.alibaba.csp
+ sentinel-spring-cloud-gateway-adapter
+ 1.8.4
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+ 2.4.0
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+ org.springframework.cloud
+ spring-cloud-starter-gateway
+ 3.1.3
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
diff --git a/etl-gateway/src/main/java/com/etl/gateway/EtlGatewayApplication.java b/etl-gateway/src/main/java/com/etl/gateway/EtlGatewayApplication.java
new file mode 100644
index 0000000..62b9dd9
--- /dev/null
+++ b/etl-gateway/src/main/java/com/etl/gateway/EtlGatewayApplication.java
@@ -0,0 +1,13 @@
+package com.etl.gateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class EtlGatewayApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(EtlGatewayApplication.class, args);
+ }
+
+}
diff --git a/etl-gateway/src/main/java/com/etl/gateway/config/IgnoreWhiteConfig.java b/etl-gateway/src/main/java/com/etl/gateway/config/IgnoreWhiteConfig.java
new file mode 100644
index 0000000..f01f313
--- /dev/null
+++ b/etl-gateway/src/main/java/com/etl/gateway/config/IgnoreWhiteConfig.java
@@ -0,0 +1,32 @@
+package com.etl.gateway.config;
+
+import com.alibaba.fastjson2.JSONObject;
+import lombok.Data;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @description: 放行白名单配置
+ * @author dongyan Ma
+ */
+@Configuration
+@RefreshScope
+@ConfigurationProperties(prefix = "ignore")
+@Data
+@Log4j2
+public class IgnoreWhiteConfig {
+ /**
+ * 放行白名单配置,网关不校验此处的白名单
+ */
+ private List whites = new ArrayList<>();
+
+ public void setWhites(List whites) {
+ log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites));
+ this.whites = whites;
+ }
+}
diff --git a/etl-gateway/src/main/java/com/etl/gateway/filters/AuthFilter.java b/etl-gateway/src/main/java/com/etl/gateway/filters/AuthFilter.java
new file mode 100644
index 0000000..52441d0
--- /dev/null
+++ b/etl-gateway/src/main/java/com/etl/gateway/filters/AuthFilter.java
@@ -0,0 +1,95 @@
+package com.etl.gateway.filters;//package com.health.cloud.gateway.filters;
+//
+//
+//import com.health.cloud.common.constants.TokenConstants;
+//import com.health.cloud.common.util.JwtUtils;
+//import com.health.cloud.common.util.StringUtils;
+//import com.health.cloud.gateway.config.IgnoreWhiteConfig;
+//import com.health.cloud.gateway.utils.GatewayUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
+//import org.springframework.cloud.gateway.filter.GlobalFilter;
+//import org.springframework.core.Ordered;
+//import org.springframework.data.redis.core.RedisTemplate;
+//import org.springframework.http.server.reactive.ServerHttpRequest;
+//import org.springframework.stereotype.Component;
+//import org.springframework.web.server.ServerWebExchange;
+//import reactor.core.publisher.Mono;
+//
+//import java.util.List;
+//import java.util.concurrent.TimeUnit;
+//
+///**
+// * @ClassName:
+// * @Description: 过滤请求,验证 token
+// * @Author: dongyan Ma
+// * @Date: 2024/2/28
+// */
+//@Component
+//public class AuthFilter implements GlobalFilter, Ordered {
+//
+// @Autowired
+// private IgnoreWhiteConfig ignoreWhitesConfig;
+//
+// @Autowired
+// private RedisTemplate redisTemplate;
+//
+// /**
+// * 过滤请求方法
+// * @param exchange 请求的上下文, 通过这个对象可以获取请求对象以及响应对象
+// * @param chain 过滤器链 使用他进行 过滤 或者 放行
+// * @return
+// */
+// @Override
+// public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+// // 判断这次请求是否需要验证 token 白名单【直接放行的请求】
+// // 获取系统白名单
+// List whites = ignoreWhitesConfig.getWhites();
+// // 获取当前请求的 URI
+// ServerHttpRequest request = exchange.getRequest();
+// String path = request.getURI().getPath();
+// boolean matches = StringUtils.matches(path, whites);
+// if (matches) {
+// // 白名单请求
+// return chain.filter(exchange);
+// }
+//// boolean anyMatch = whites.stream().anyMatch(white -> white.equals(path));
+//// if (anyMatch) {
+// // 白名单请求
+//// return chain.filter(exchange);
+//// }
+// // 验证 token
+// String token = request.getHeaders().getFirst(TokenConstants.TOKEN);
+// // 非空验证
+// if (StringUtils.isBlank(token)) {
+// // 空的
+// return GatewayUtils.errorResponse(exchange, "token不能为空!");
+// }
+// // 是否合法
+// try {
+// JwtUtils.parseToken(token);
+// } catch (Exception e) {
+// return GatewayUtils.errorResponse(exchange, "token不合法!");
+// }
+// // 是否有效
+// String userKey = JwtUtils.getUserKey(token);
+// if (!redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey)) {
+// return GatewayUtils.errorResponse(exchange, "token过期!");
+// } else {
+// // 重新设置 redis中的用户有效时间
+// redisTemplate.expire(TokenConstants.LOGIN_TOKEN_KEY + userKey, 30, TimeUnit.MINUTES);
+// }
+// // 放行
+// return chain.filter(exchange);
+// }
+//
+// /**
+// * 规定过滤器执行的顺序
+// * @return 方法的返回值越小 执行顺序越高
+// */
+// @Override
+// public int getOrder() {
+// return 0;
+// }
+//
+//}
diff --git a/etl-gateway/src/main/java/com/etl/gateway/filters/LogFilter.java b/etl-gateway/src/main/java/com/etl/gateway/filters/LogFilter.java
new file mode 100644
index 0000000..6fd69cd
--- /dev/null
+++ b/etl-gateway/src/main/java/com/etl/gateway/filters/LogFilter.java
@@ -0,0 +1,25 @@
+package com.etl.gateway.filters;
+
+import org.springframework.cloud.gateway.filter.GatewayFilterChain;
+import org.springframework.cloud.gateway.filter.GlobalFilter;
+import org.springframework.core.Ordered;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+/**
+ * @ClassName:
+ * @Description:
+ * @Author: dongyan Ma
+ * @Date: 2024/2/28
+ */
+public class LogFilter implements GlobalFilter, Ordered {
+ @Override
+ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+ return null;
+ }
+
+ @Override
+ public int getOrder() {
+ return 1;
+ }
+}
diff --git a/etl-gateway/src/main/java/com/etl/gateway/utils/GatewayUtils.java b/etl-gateway/src/main/java/com/etl/gateway/utils/GatewayUtils.java
new file mode 100644
index 0000000..e65bd84
--- /dev/null
+++ b/etl-gateway/src/main/java/com/etl/gateway/utils/GatewayUtils.java
@@ -0,0 +1,98 @@
+package com.etl.gateway.utils;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.etl.common.result.Result;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.util.StringUtils;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+/**
+ * @author dongyan Ma
+ * @description: 网关处理工具类
+ */
+@Log4j2
+public class GatewayUtils {
+ /**
+ * 添加请求头参数
+ * @param mutate 修改对象
+ * @param key 键
+ * @param value 值
+ */
+ public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
+ if (StringUtils.isEmpty(key)){
+ log.warn("添加请求头参数键不可以为空");
+ return;
+ }
+ if (value == null) {
+ log.warn("添加请求头参数:[{}]值为空",key);
+ return;
+ }
+ String valueStr = value.toString();
+ mutate.header(key, valueStr);
+ log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
+ }
+
+ /**
+ * 删除请求头参数
+ * @param mutate 修改对象
+ * @param key 键
+ */
+ public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
+ if (StringUtils.isEmpty(key)){
+ log.warn("删除请求头参数键不可以为空");
+ return;
+ }
+ mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
+ log.info("删除请求头参数 - 键:[{}]",key);
+ }
+
+ /**
+ * 错误结果响应
+ * @param exchange 响应上下文
+ * @param msg 响应消息
+ * @return
+ */
+ public static Mono errorResponse(ServerWebExchange exchange, String msg, HttpStatus httpStatus) {
+ ServerHttpResponse response = exchange.getResponse();
+ //设置HTTP响应头状态
+ response.setStatusCode(httpStatus);
+ //设置HTTP响应头文本格式
+ response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
+ //定义响应内容
+ Result> result = Result.error(msg);
+ String resultJson = JSONObject.toJSONString(result);
+ log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
+ DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
+ //进行响应
+ return response.writeWith(Mono.just(dataBuffer));
+ }
+
+ /**
+ * 错误结果响应
+ * @param exchange 响应上下文
+ * @param msg 响应消息
+ * @return
+ */
+ public static Mono errorResponse(ServerWebExchange exchange, String msg) {
+ ServerHttpResponse response = exchange.getResponse();
+ //设置HTTP响应头状态
+ response.setStatusCode(HttpStatus.OK);
+ //设置HTTP响应头文本格式
+ response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
+ //定义响应内容
+ Result> result = Result.error(msg);
+ String resultJson = JSONObject.toJSONString(result);
+ log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
+ DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
+ //进行响应
+ return response.writeWith(Mono.just(dataBuffer));
+ }
+
+
+}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..ce08678
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,132 @@
+
+
+ 4.0.0
+
+ com.bwie
+ etl-cloud
+ 1.0-SNAPSHOT
+ pom
+
+ etl-common
+ etl-gateway
+
+
+
+ 1.8
+ UTF-8
+ UTF-8
+ 2.6.13
+ 2021.0.5.0
+ 3.1.3
+ 3.5.1
+
+
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ ${mybits-plus-version}
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jdbc
+
+
+
+ com.mysql
+ mysql-connector-j
+ 8.0.33
+ runtime
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+ ${spring-cloud-bootstrap}
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+ ${spring-cloud-alibaba.version}
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+ ${spring-cloud-alibaba.version}
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ ${spring-boot.version}
+ runtime
+ true
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.43
+
+
+ org.projectlombok
+ lombok
+ 1.18.22
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter
+ ${spring-boot.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot.version}
+ test
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ ${spring-boot.version}
+ pom
+ import
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring-boot.version}
+
+ com.health.cloud.HealthCloudApplication
+ true
+
+
+
+ repackage
+
+ repackage
+
+
+
+
+
+
+
+
+