From d25e5be42648af3a9229c2b8efedc7ece026de30 Mon Sep 17 00:00:00 2001 From: TanYibin <5491541@qq.com> Date: Wed, 15 Mar 2023 16:40:56 +0800 Subject: [PATCH] 统一aspect工具类路径到 org.jeecg.utils.aspect --- huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/CommonController.java | 33 +++++++++++++++++++++------------ huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java | 8 ++++++-- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/erp/controller/ErpController.java | 14 +++++++++++--- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mes/controller/MesController.java | 8 ++++++-- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ReceiptController.java | 12 ------------ huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ShipmentController.java | 12 ------------ huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java | 15 ++++++++++++--- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java | 2 +- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java | 122 -------------------------------------------------------------------------------------------------------------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLoggerAspect.java | 558 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/LogRecordAspect.java | 46 ---------------------------------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/PassApiAuthentication.java | 17 ----------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java | 106 ---------------------------------------------------------------------------------------------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/RSA256Key.java | 29 ----------------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/annotation/ApiLogger.java | 22 ---------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessStatus.java | 16 ---------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessType.java | 26 -------------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/DataSourceName.java | 16 ---------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/OperatorType.java | 19 ------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/ProcessCode.java | 38 -------------------------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/receipt/receiptHeader/controller/ReceiptHeaderController.java | 13 +++++++++++-- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentHeader/controller/ShipmentHeaderController.java | 13 +++++++++++-- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/controller/TaskHeaderController.java | 13 +++++++++++-- huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java | 4 ++-- huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java | 37 +++++++++++++++++++------------------ huaheng-wms-core/src/main/java/org/jeecg/utils/SecretKeyUtils.java | 2 +- huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiAuthenticationAspect.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiLoggerAspect.java | 556 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/LogRecordAspect.java | 43 +++++++++++++++++++++++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiAuthentication.java | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiLogger.java | 22 ++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessStatus.java | 16 ++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessType.java | 26 ++++++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/DataSourceName.java | 16 ++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/OperatorType.java | 19 +++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/PassApiAuthentication.java | 17 +++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/ProcessCode.java | 38 ++++++++++++++++++++++++++++++++++++++ huaheng-wms-core/src/main/java/org/jeecg/utils/support/RSA256Key.java | 29 +++++++++++++++++++++++++++++ 38 files changed, 1117 insertions(+), 1089 deletions(-) delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLoggerAspect.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/LogRecordAspect.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/PassApiAuthentication.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/RSA256Key.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/annotation/ApiLogger.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessStatus.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessType.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/DataSourceName.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/OperatorType.java delete mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/ProcessCode.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiAuthenticationAspect.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiLoggerAspect.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/LogRecordAspect.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiAuthentication.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiLogger.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessStatus.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessType.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/DataSourceName.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/OperatorType.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/PassApiAuthentication.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/ProcessCode.java create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/utils/support/RSA256Key.java diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/CommonController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/CommonController.java index 98adea7..e120e59 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/CommonController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/CommonController.java @@ -1,10 +1,17 @@ package org.jeecg.modules.system.controller; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLDecoder; +import java.util.Arrays; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.exception.JeecgBootException; @@ -13,7 +20,7 @@ import org.jeecg.common.util.CommonUtils; import org.jeecg.common.util.RestUtil; import org.jeecg.common.util.TokenUtils; import org.jeecg.common.util.oConvertUtils; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; +import org.jeecg.utils.support.ApiLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; @@ -22,18 +29,20 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.util.AntPathMatcher; import org.springframework.util.FileCopyUtils; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.ModelAndView; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.net.URLDecoder; -import java.util.Arrays; -import java.util.Collections; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import lombok.extern.slf4j.Slf4j; /** * <p> diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java index d770398..02ddaa7 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java @@ -9,12 +9,16 @@ import org.jeecg.common.api.vo.Result; import org.jeecg.modules.wms.api.acs.entity.AcsStatus; import org.jeecg.modules.wms.api.acs.service.IAcsService; import org.jeecg.modules.wms.config.address.service.IAddressService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; import org.jeecg.utils.StringUtils; import org.jeecg.utils.constant.QuantityConstant; -import org.springframework.web.bind.annotation.*; +import org.jeecg.utils.support.ApiLogger; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import cn.monitor4all.logRecord.annotation.OperationLog; import io.swagger.annotations.Api; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/erp/controller/ErpController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/erp/controller/ErpController.java index 2b388f9..2fb2d0f 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/erp/controller/ErpController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/erp/controller/ErpController.java @@ -4,11 +4,19 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.jeecg.common.api.vo.Result; -import org.jeecg.modules.wms.api.erp.entity.*; +import org.jeecg.modules.wms.api.erp.entity.ErpCancel; +import org.jeecg.modules.wms.api.erp.entity.ErpMaterial; +import org.jeecg.modules.wms.api.erp.entity.ErpReceipt; +import org.jeecg.modules.wms.api.erp.entity.ErpShipment; +import org.jeecg.modules.wms.api.erp.entity.InventoryQueryParam; import org.jeecg.modules.wms.api.erp.service.IErpService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; -import org.springframework.web.bind.annotation.*; +import org.jeecg.utils.support.ApiLogger; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mes/controller/MesController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mes/controller/MesController.java index 480779b..1ad9427 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mes/controller/MesController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mes/controller/MesController.java @@ -12,9 +12,13 @@ import org.jeecg.modules.wms.api.erp.service.IErpService; import org.jeecg.modules.wms.api.mes.entity.MesReceiptMaterial; import org.jeecg.modules.wms.api.mes.entity.MesShipmentMaterial; import org.jeecg.modules.wms.api.mes.servuce.IMesService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; -import org.springframework.web.bind.annotation.*; +import org.jeecg.utils.support.ApiLogger; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ReceiptController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ReceiptController.java index d389bb0..b2283a7 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ReceiptController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ReceiptController.java @@ -1,25 +1,13 @@ package org.jeecg.modules.wms.api.mobile.controller; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import org.jeecg.common.api.vo.Result; -import org.jeecg.common.aspect.annotation.AutoLog; -import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; -import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; import org.jeecg.modules.wms.api.mobile.service.IMobileService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; -import org.jeecg.utils.HuahengJwtUtil; -import org.jeecg.utils.constant.QuantityConstant; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; /** * PDA入库接口,整合复用PC端service层接口 diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ShipmentController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ShipmentController.java index 38a22d6..49b7759 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ShipmentController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/mobile/controller/ShipmentController.java @@ -1,25 +1,13 @@ package org.jeecg.modules.wms.api.mobile.controller; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import org.jeecg.common.api.vo.Result; -import org.jeecg.common.aspect.annotation.AutoLog; -import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; import org.jeecg.modules.wms.api.mobile.service.IMobileService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; -import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; -import org.jeecg.utils.HuahengJwtUtil; -import org.jeecg.utils.constant.QuantityConstant; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; /** * * PDA出库接口,整合复用PC端service层接口 diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java index 8499b85..1457086 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java @@ -5,13 +5,22 @@ import javax.servlet.http.HttpServletRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; -import org.jeecg.modules.wms.api.wcs.entity.*; +import org.jeecg.modules.wms.api.wcs.entity.ArriveEntity; +import org.jeecg.modules.wms.api.wcs.entity.ManyEmptyDomain; +import org.jeecg.modules.wms.api.wcs.entity.ManyEmptyOutDomain; +import org.jeecg.modules.wms.api.wcs.entity.MaterialInfoEntity; +import org.jeecg.modules.wms.api.wcs.entity.TaskEntity; +import org.jeecg.modules.wms.api.wcs.entity.WarecellDomain; import org.jeecg.modules.wms.api.wcs.service.WcsService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; import org.jeecg.utils.StringUtils; -import org.springframework.web.bind.annotation.*; +import org.jeecg.utils.support.ApiLogger; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java index 7b71b87..b9a6cf3 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java @@ -27,7 +27,6 @@ import org.jeecg.modules.wms.config.material.service.IMaterialService; import org.jeecg.modules.wms.config.parameterConfiguration.service.IParameterConfigurationService; import org.jeecg.modules.wms.config.zone.entity.Zone; import org.jeecg.modules.wms.config.zone.service.IZoneService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.receipt.receiptContainerHeader.entity.ReceiptContainerDetail; import org.jeecg.modules.wms.receipt.receiptContainerHeader.entity.ReceiptContainerHeader; import org.jeecg.modules.wms.receipt.receiptContainerHeader.service.IReceiptContainerDetailService; @@ -39,6 +38,7 @@ import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; import org.jeecg.utils.OkHttpUtils; import org.jeecg.utils.StringUtils; import org.jeecg.utils.constant.QuantityConstant; +import org.jeecg.utils.support.ApiLogger; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java deleted file mode 100644 index e06a286..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj; - -import java.lang.reflect.Method; -import java.util.Arrays; - -import javax.servlet.http.HttpServletRequest; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.aspectj.lang.reflect.MethodSignature; -import org.bouncycastle.crypto.RuntimeCryptoException; -import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication; -import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; -import org.jeecg.utils.HuahengJwtUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import com.auth0.jwt.JWT; -import com.auth0.jwt.JWTVerifier; -import com.auth0.jwt.algorithms.Algorithm; -import com.auth0.jwt.exceptions.JWTVerificationException; -import com.auth0.jwt.interfaces.DecodedJWT; -import com.baomidou.mybatisplus.extension.service.IService; - -import cn.hutool.core.date.DatePattern; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; - -/** - * 第三方系统调用接口身份认证Aspect - * @author TanYibin - * @createDate 2023年2月14日 - */ -@Slf4j -@Aspect -@Component -@EnableAsync -public class ApiAuthenticationAspect { - - @Autowired - private RSA256Key rsa256Key; - - @Pointcut("execution(* org.jeecg.modules.wms.api..*.*(..)) " + "&& (@annotation(org.springframework.web.bind.annotation.RequestMapping) " - + "|| @annotation(org.springframework.web.bind.annotation.GetMapping) " + "|| @annotation(org.springframework.web.bind.annotation.PostMapping))") - public void executeController() {} - - /** - * API Token 验证 - * @author TanYibin - * @createDate 2023年2月14日 - * @param joinPoint - * @throws NoSuchMethodException - * @throws Throwable - */ - @Before("executeController()") - public void doBefore(JoinPoint joinPoint) throws NoSuchMethodException, Throwable { - Method method = this.getTargetMethod(joinPoint); - // 检查是否有passtoken注释,有则跳过认证 - if (method.isAnnotationPresent(PassApiAuthentication.class)) { - PassApiAuthentication passApiAuthentication = method.getAnnotation(PassApiAuthentication.class); - if (passApiAuthentication.required()) { - return; - } - } - // 获取request对象 - ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - String token = request.getHeader("token"); - if (token == null) { - log.error("Authentication token is null"); - throw new RuntimeException("Authentication token is null"); - } - try { - Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey()); - JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); - DecodedJWT jwt = verifier.verify(token); - new ApiAuthentication.ApiAuthenticationBuild().operator(jwt.getClaim("operator").asString()).audience(jwt.getAudience().get(0)).issuer(jwt.getIssuer()) - .issuedAt(jwt.getIssuedAt()).expireDateTime(jwt.getExpiresAt()).bulid(); - } catch (JWTVerificationException e) { - log.error(e.getMessage()); - throw e; - } - } - - /** - * 基于连接点信息获取目标方法对象 - * @author TanYibin - * @createDate 2023年2月14日 - * @param joinPoint - * @return - * @throws NoSuchMethodException - */ - private Method getTargetMethod(JoinPoint joinPoint) throws NoSuchMethodException { - // 获取目标类对象 - Class<?> clazz = joinPoint.getTarget().getClass(); - // 获取方法签名信息,方法名和参数列表 - MethodSignature signature = (MethodSignature)joinPoint.getSignature(); - // 获取目标方法对象 - return clazz.getDeclaredMethod(signature.getName(), signature.getParameterTypes()); - } - - /** - * 获取方法类全名+方法名 - * @author TanYibin - * @createDate 2023年2月14日 - * @param method - * @return - */ - private String getClassAndMethodName(Method method) { - // 获取类全名 - String className = method.getDeclaringClass().getName(); - // 获取方法名 - String methodName = method.getName(); - return new StringBuffer(className).append(".").append(methodName).toString(); - } -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLoggerAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLoggerAspect.java deleted file mode 100644 index 7178bc2..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiLoggerAspect.java +++ /dev/null @@ -1,558 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj; - -import java.net.InetAddress; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang.exception.ExceptionUtils; -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.jeecg.JeecgSystemApplication; -import org.jeecg.common.api.vo.Result; -import org.jeecg.modules.wms.config.address.entity.Address; -import org.jeecg.modules.wms.config.address.service.IAddressService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; -import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; -import org.jeecg.modules.wms.monitor.apiLog.service.IApiLogService; -import org.jeecg.utils.HuahengJwtUtil; -import org.jeecg.utils.ServletUtils; -import org.jeecg.utils.SpringUtils; -import org.jeecg.utils.StringUtils; -import org.jeecg.utils.constant.QuantityConstant; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.stereotype.Component; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; - -import okhttp3.Request; -import okhttp3.Response; - -/** - * API调用日志记录处理 - * @author huaheng - */ -@Aspect -@Component -@EnableAsync -public class ApiLoggerAspect { - private static final Logger log = LoggerFactory.getLogger(ApiLoggerAspect.class); - - private static IApiLogService apiLogService; - - private static IAddressService addressService; - - @Autowired - public void setApiLogService(IApiLogService apiLogService) { - ApiLoggerAspect.apiLogService = apiLogService; - } - - @Autowired - public void setAddressService(IAddressService addressService) { - ApiLoggerAspect.addressService = addressService; - } - - // 配置织入点 - @Pointcut("@annotation(org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger)") - public void logPointCut() {} - - @Around("logPointCut() && @annotation(apiLogger)") - public Object around(ProceedingJoinPoint point, ApiLogger apiLogger) throws Throwable { - return aroundXXX2Wms(point, apiLogger); - } - - /** 记录第三方系统调用WMS接口的日志 **/ - private Object aroundXXX2Wms(ProceedingJoinPoint point, ApiLogger apiLogger) { - Object ret = null; - ApiLog apiLog = initApiLog(apiLogger, point); - try { - ret = point.proceed(); - } catch (Throwable e) { - setApiLogThrowable(apiLog, e); - ret = Result.error(e.getMessage()); - return ret; - } finally { - if (ret != null) { - finishApiLog(apiLog, ret); - } - } - return ret; - } - -// /** 记录WMS调用第三方接口的日志 **/ -// private Object aroundWms2XXX(ProceedingJoinPoint point, ApiLogger apiLogger) { -// Object ret = null; -// ApiLog log = new ApiLog(); -// -// HttpURLConnection connection = null; -// String body = null; -// -// try { -// connection = (HttpURLConnection)point.getArgs()[0]; -// body = (String)point.getArgs()[1]; -// initApiLog(connection, body); -// ret = point.proceed(); -// } catch (Throwable e) { -// setApiLogThrowable(log, e); -// ret = Result.error(e.getMessage()); -// } finally { -// if (ret != null) { -// finishApiLog(log, connection, ret.toString()); -// } -// } -// return ret; -// } - -// /** -// * 记录响应头信息,保存日志到数据库 -// */ -// public static void finishApiLog(ApiLog log, HttpURLConnection connection, String body) { -// try { -// log.setResponseBody(body); -// log.setResponseTime(new Date()); -// Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); -// log.setDuration(duration.intValue()); -// log.setHttpCode(connection.getResponseCode()); -// -// // 响应头 -// Set<String> keyset = connection.getHeaderFields().keySet(); -// ArrayList<String> headerList = new ArrayList<>(); -// Iterator<String> it = keyset.iterator(); -// while (it.hasNext()) { -// String name = it.next(); -// String header = connection.getHeaderField(name); -// if (name == null || "".equals(name)) { -// // 第一行没有name -// // HTTP/1.1 200 OK -// headerList.add(header); -// } else { -// headerList.add(name + ": " + header); -// } -// } -// log.setResponseHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); -// Result json = JSON.parseObject(body, Result.class); -// log.setRetCode(json.getCode()); -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// SpringUtils.getBean(ApiLogAspect.class).saveApiLog(log); -// } -// } - -// /** -// * 根据url,从address表中判断调用的去向 -// */ -// public static void parseUrl(ApiLog log, URL url, String warehouseCode) { -// try { -// String[] spList = url.toString().split("/"); -// String apiName = spList[spList.length - 1]; -// String ip = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); -// Address address = addressService.getAddressByUrl(url.toString(), warehouseCode); -// log.setApiName(apiName); -// log.setRequestFrom("WMS"); -// log.setIp(ip); -// log.setResponseBy(address.getParam().toUpperCase()); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } - -// /** -// * 记录WMS调用第三方系统接口的请求信息 -// * 在HttpUtils.body POST方法中直接调用本类static方法 -// **/ -// public static ApiLog initApiLog(String Method, String urlStr, String body, HttpHeaders headers, String warehouseCode) { -// ApiLog log = new ApiLog(); -// try { -// URL url = new URL(urlStr); -// log.setApiMethod(Method); -// log.setUrl(urlStr); -// log.setRequestTime(new Date()); -// parseUrl(log, url, warehouseCode); -// -// // 请求头 -// Set<String> keySet = headers.keySet(); -// ArrayList<String> headerList = new ArrayList<>(); -// Iterator<String> it = keySet.iterator(); -// while (it.hasNext()) { -// String name = it.next(); -// String header = String.valueOf(headers.getContentType()); -// headerList.add(name + ": " + header); -// } -// -// log.setRequestHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); -// log.setRequestBody(body); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// return log; -// } - -// /** -// * 记录WMS调用第三方系统接口的请求信息 -// * 在HttpUtils.body POST方法中直接调用本类static方法 -// **/ -// public static ApiLog initApiLog(HttpURLConnection connection, String body) { -// ApiLog log = new ApiLog(); -// try { -// log.setApiMethod(connection.getRequestMethod()); -// log.setUrl(connection.getURL().toString()); -// log.setRequestTime(new Date()); -// parseUrl(log, connection.getURL()); -// -// // 请求头 -// Set<String> keySet = connection.getRequestProperties().keySet(); -// ArrayList<String> headerList = new ArrayList<>(); -// Iterator<String> it = keySet.iterator(); -// while (it.hasNext()) { -// String name = it.next(); -// String header = connection.getRequestProperty(name); -// headerList.add(name + ":" + header); -// } -// -// log.setRequestHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); -// log.setRequestBody(body); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// return log; -// } - - /** - * 记录WMS调用第三方系统接口的请求信息 - * 在OKHttpUtils.bodypost方法中直接调用本类static方法 - * @param apiLog - **/ - public static void initApiLog(ApiLog apiLog, Request request, String body) { - try { - apiLog.setApiMethod(request.method()); - apiLog.setUrl(request.url().toString()); - apiLog.setRequestTime(new Date()); - parseUrl(apiLog, request.url().url()); - apiLog.setRequestHeader(request.headers().toString()); - apiLog.setRequestBody(body); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** 记录响应头信息 **/ - public static void finishApiLog(ApiLog log, Response response, String responseBody) { - try { - log.setResponseTime(new Date()); - Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); - log.setDuration(duration.intValue()); - if (response == null) { - return; - } - log.setHttpCode(response.code()); - log.setResponseHeader(response.headers().toString()); - log.setResponseBody(responseBody); - Result result = null; - try { - result = JSON.parseObject(responseBody, Result.class); - } catch (Exception ex) { - responseBody = JSON.parse(responseBody).toString(); - result = JSON.parseObject(responseBody, Result.class); - } - log.setRetCode(result.getCode()); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (StringUtils.isNotEmpty(log.getResponseBody()) && log.getResponseBody().length() > 2001) { - log.setResponseBody(log.getResponseBody().substring(0, 2000) + "...\n"); - } - } catch (Exception e) { - e.printStackTrace(); - } - SpringUtils.getBean(ApiLoggerAspect.class).saveApiLog(log); - } - } - - /** 根据url,从address表中判断调用的去向 **/ - public static void parseUrl(ApiLog apiLog, URL url) { - try { - String[] spList = url.toString().split("/"); - String apiName = spList[spList.length - 1]; - String ip = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); - apiLog.setApiName(apiName); - apiLog.setRequestFrom(HuahengJwtUtil.HUAHENG_SYSTEM_ID); - apiLog.setIp(ip); -// Address address = addressService.getAddressByUrl(url.toString(), QuantityConstant.DEFAULT_WAREHOUSE); -// apiLog.setResponseBy(address.getParam().toUpperCase()); - } catch (Exception e) { - e.printStackTrace(); - } - } - -// /** -// * 记录响应头信息 -// **/ -// public static void finishApiLog(ApiLog log, HttpHeaders headers, String body) { -// try { -// log.setResponseBody(body); -// log.setResponseTime(new Date()); -// Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); -// log.setDuration(duration.intValue()); -// log.setHttpCode(200); -// -// // 响应头 -// Set<String> keyset = headers.keySet(); -// ArrayList<String> headerList = new ArrayList<>(); -// Iterator<String> it = keyset.iterator(); -// while (it.hasNext()) { -// String name = it.next(); -// String header = String.valueOf(headers.getContentType()); -// if (name == null || "".equals(name)) -// // 第一行没有name -// // HTTP/1.1 200 OK -// headerList.add(header); -// else -// headerList.add(name + ": " + header); -// } -// log.setResponseHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); -// Result json = JSON.parseObject(body, Result.class); -// log.setRetCode(json.getCode()); -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// SpringUtils.getBean(ApiLogAspect.class).saveApiLog(log); -// } -// } - - private ApiLog initApiLog(ApiLogger apiLogger, ProceedingJoinPoint point) { - ApiLog log = new ApiLog(); - try { - log.setRequestTime(new Date()); - log.setRequestFrom(apiLogger.from()); - log.setResponseBy(apiLogger.to()); - log.setApiName(apiLogger.apiName()); - - HttpServletRequest request = ServletUtils.getRequest(); - String qryStr = request.getQueryString(); - String url = request.getRequestURL().toString(); - if (StringUtils.isNotEmpty(qryStr)) { - url = url + "?" + qryStr; - } - log.setUrl(url); - log.setApiMethod(request.getMethod()); - log.setIp(ApiLoggerAspect.getIpAddr(request)); - - rebuildRequestHeader(log); - rebuildRequestBody(log, request); - - // 如果reqeust中取不到post参数,就从接口方法参数中取json对象 - if (StringUtils.isEmpty(log.getRequestBody())) { - rebuildRequestBody(log, point); - } - - } catch (Exception e) { - e.printStackTrace(); - } - - return log; - } - - private void finishApiLog(ApiLog log, Object ret) { - try { - rebuildResponseHeader(log); - rebuildResponseBody(log, ret); - - log.setResponseTime(new Date()); - Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); - log.setDuration(duration.intValue()); - - HttpServletResponse resp = ServletUtils.getResponse(); - log.setHttpCode(resp.getStatus()); - - if (ret instanceof Result) { - int retCode = ((Result)ret).getCode(); - log.setRetCode(retCode); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - saveApiLog(log); - } - } - - public static void setApiLogException(ApiLog log, Exception e) { - try { - String exception = ExceptionUtils.getFullStackTrace(e); - String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 2000) + "..."; - log.setException(shortExpInfo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public static void setApiLogThrowable(ApiLog log, Throwable e) { - try { - String exception = ExceptionUtils.getFullStackTrace(e); - String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 2000) + "..."; - log.setException(shortExpInfo); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - private void rebuildRequestHeader(ApiLog log) { - try { - HttpServletRequest req = ServletUtils.getRequest(); - Enumeration names = req.getHeaderNames(); - ArrayList<String> headerList = new ArrayList<>(); - while (names.hasMoreElements()) { - String name = (String)names.nextElement(); - String header = req.getHeader(name); - headerList.add(name + ":" + header); - } - String headers = org.apache.commons.lang3.StringUtils.join(headerList, "\n"); - log.setRequestHeader(headers); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** 先从post参数中构造request body */ - private void rebuildRequestBody(ApiLog log, HttpServletRequest request) { - try { - Set<String> keySet = request.getParameterMap().keySet(); - Iterator<String> it = keySet.iterator(); - StringBuffer sbf = new StringBuffer(); - while (it.hasNext()) { - String key = it.next(); - String value = request.getParameter(key); - sbf.append(key).append("=").append(value); - if (it.hasNext()) { - sbf.append("&"); - } - } - log.setRequestBody(sbf.toString()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * 根据接口中的参数构造request body - */ - private void rebuildRequestBody(ApiLog log, ProceedingJoinPoint point) { - try { - if (point.getArgs().length == 1) { - log.setRequestBody(JSONObject.toJSONString(point.getArgs()[0])); - return; - } - - MethodSignature m = (MethodSignature)point.getSignature(); - HashMap<String, Object> map = new HashMap<>(); - Object[] args = point.getArgs(); - for (int i = 0; i < m.getParameterNames().length; i++) { - String name = m.getParameterNames()[i]; -// Class type = m.getParameterTypes()[i]; - if (args[i] instanceof HttpServletRequest) { - continue; - } - if (args[i] instanceof HttpServletResponse) { - continue; - } - map.put(name, args[i]); - } - - if (!map.isEmpty()) { - if (map.keySet().size() == 1) { - log.setRequestBody(JSONObject.toJSONString(map.values().iterator().next())); - } else { - log.setRequestBody(JSONObject.toJSONString(map)); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void rebuildResponseHeader(ApiLog log) { - try { - HttpServletResponse resp = ServletUtils.getResponse(); - Collection<String> names = resp.getHeaderNames(); - ArrayList<String> headerList = new ArrayList<>(); - Iterator<String> it = names.iterator(); - while (it.hasNext()) { - String name = it.next(); - String header = resp.getHeader(name); - headerList.add(name + ": " + header); - } - String headers = org.apache.commons.lang3.StringUtils.join(headerList, "\n"); - log.setResponseHeader(headers); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void rebuildResponseBody(ApiLog log, Object ret) { - try { - log.setResponseBody(JSONObject.toJSON(ret).toString()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Async - public void saveApiLog(ApiLog log) { - try { - apiLogService.saveOrUpdate(log); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static String getIpAddr(HttpServletRequest request) { - 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(); - if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) { - // 根据网卡取本机配置的IP - InetAddress inet = null; - try { - inet = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - ipAddress = inet.getHostAddress(); - } - } - // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 - // "***.***.***.***".length() = 15 - if (ipAddress != null && ipAddress.length() > 15) { - if (ipAddress.indexOf(",") > 0) { - ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); - } - } - return ipAddress; - } -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/LogRecordAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/LogRecordAspect.java deleted file mode 100644 index e4eea93..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/LogRecordAspect.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj; - -import javax.servlet.http.HttpServletRequest; - -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.jeecg.modules.wms.framework.aspectj.ApiLoggerAspect; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import com.alibaba.druid.util.StringUtils; - -import lombok.extern.slf4j.Slf4j; - -// 暂时注释掉,提高系统性能 -@Slf4j -@Aspect // 定义一个切面 -@Configuration -public class LogRecordAspect { - - // 定义切点Pointcut - @Pointcut("execution(public * org.jeecg.modules.wms..*.controller..*.*(..))" + "&& (@annotation(org.springframework.web.bind.annotation.RequestMapping) " - + "|| @annotation(org.springframework.web.bind.annotation.GetMapping) " + "|| @annotation(org.springframework.web.bind.annotation.PostMapping))") - public void excudeService() {} - - @Around("excudeService()") - public Object doAround(ProceedingJoinPoint point) throws Throwable { - long startTime = System.currentTimeMillis(); - // 接收到请求,记录请求内容 - ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); - // 获取请求的request - HttpServletRequest request = attributes.getRequest(); - String url = request.getRequestURL().toString(); - String className = point.getTarget().getClass().getSimpleName(); - String methodName = point.getSignature().getName(); - log.info("[{}] {} [{}.{}] [{}]", request.getMethod(), url, className, methodName, ApiLoggerAspect.getIpAddr(request)); - // result的值就是被拦截方法的返回值 - Object result = point.proceed(); - long callTime = System.currentTimeMillis() - startTime; - log.info("[{}] {} [{}.{}] [{}ms]", request.getMethod(), url, className, methodName, callTime); - return result; - } -} \ No newline at end of file diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/PassApiAuthentication.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/PassApiAuthentication.java deleted file mode 100644 index 604da8a..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/PassApiAuthentication.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 跳过API身份验证注解 - * @author TanYibin - * @createDate 2023年2月13日 - */ -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -public @interface PassApiAuthentication { - boolean required() default true; -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java deleted file mode 100644 index 5aa6397..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.dto; - -import java.util.Date; - -import org.jeecg.utils.HuahengJwtUtil; - -import cn.hutool.core.date.DatePattern; -import cn.hutool.core.date.DateUtil; -import lombok.Data; - -/** - * 接口认证Token对象 - * @author TanYibin - * @createDate 2023年2月14日 - */ -@Data -public class ApiAuthentication { - - private static final ThreadLocal<ApiAuthentication> REQUEST_HEADER_CONTEXT_THREAD_LOCAL = new ThreadLocal<>(); - - /** Token提供方 */ - private String operator; - - /** Token使用方 */ - private String audience = "Unknown"; // 观众,相当于接受者 - - /** Token签发方(WMS) */ - private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; - - /** Token签发时间 */ - private Date issuedAt; - - /** Token失效时间 */ - private Date expireDateTime; - - public ApiAuthentication() {} - - public static ApiAuthentication getInstance() { - return REQUEST_HEADER_CONTEXT_THREAD_LOCAL.get(); - } - - public void setContext(ApiAuthentication context) { - REQUEST_HEADER_CONTEXT_THREAD_LOCAL.set(context); - } - - public static void clean() { - REQUEST_HEADER_CONTEXT_THREAD_LOCAL.remove(); - } - - private ApiAuthentication(ApiAuthenticationBuild apiAuthenticationBuild) { - this.operator = apiAuthenticationBuild.operator; - this.audience = apiAuthenticationBuild.audience; - this.issuer = apiAuthenticationBuild.issuer; - this.issuedAt = apiAuthenticationBuild.issuedAt; - this.expireDateTime = apiAuthenticationBuild.expireDateTime; - setContext(this); - } - - public static class ApiAuthenticationBuild { - - /** Token提供方 */ - private String operator; - - /** Token使用方 */ - private String audience; // 观众,相当于接受者 - - /** Token签发方(WMS) */ - private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; - - /** Token签发时间 */ - private Date issuedAt; - - /** Token失效时间 */ - private Date expireDateTime; - - public ApiAuthenticationBuild operator(String operator) { - this.operator = operator; - return this; - } - - public ApiAuthenticationBuild audience(String audience) { - this.audience = audience; - return this; - } - - public ApiAuthenticationBuild issuer(String issuer) { - this.issuer = issuer; - return this; - } - - public ApiAuthenticationBuild issuedAt(Date issuedAt) { - this.issuedAt = issuedAt; - return this; - } - - public ApiAuthenticationBuild expireDateTime(Date expireDateTime) { - this.expireDateTime = expireDateTime; - return this; - } - - public ApiAuthentication bulid() { - return new ApiAuthentication(this); - } - } - -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/RSA256Key.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/RSA256Key.java deleted file mode 100644 index 943a5e2..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/RSA256Key.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.dto; - -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - -import org.jeecg.utils.SecretKeyUtils; -import org.springframework.stereotype.Component; - -import lombok.Data; - -@Data -@Component -public class RSA256Key { - - /** 第三方HTTP访问 公钥 */ - private RSAPublicKey publicKey = - (RSAPublicKey)SecretKeyUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmYcmhWzpgLgWVD0j+uTyFvQW0BBktYVJmTRQvLlrKt4CHnkfQ4Dn" - + "SLaRXCcJK/TGgAY0BtnaKUgFBqqmTI9l82tpxEWqYRzp4KGRLnVA6/igidYib0JeBWroI6Bs0wR43fkSXA8XG+n32bVbmMTKNa9IFUJCzICVTEjQzMQrSAwIDAQAB"); - - /** 第三方HTTP访问 私钥 */ - private RSAPrivateKey privateKey = - (RSAPrivateKey)SecretKeyUtils.getPrivateKey("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKZhyaFbOmAuBZUPSP65PIW9BbQEGS1hUmZNFC8uWsq" - + "3gIeeR9DgOdItpFcJwkr9MaABjQG2dopSAUGqqZMj2Xza2nERaphHOngoZEudUDr+KCJ1iJvQl4FaugjoGzTBHjd+RJcDxcb6ffZtVuYxMo1r0gVQkLMgJVMSNDMxCtID" - + "AgMBAAECgYBhxluIMCVI+iKbqyTZVB/l8+PTGwl0qpmStr8iztnaASZODEzlya8Q/XNzFrAQA2TTQ7YKiKB2vqQwY8tNRab7jpR4t5WPApDVrMvjPfvqVvBsPzTYr2c08" - + "xMfqcj5HNzPLisb7Wvi7URSL4jIY/106lXN+9cJuMV0oDZzcAhaYQJBANdNMlSnzTDF8VQ7ETpzZQrF0UzlqKeKG0Pz/YeTXT4IjyBhzvaSOF3+hi1cWucrSU0xMUAR9F" - + "av+K1BlPTYW/MCQQDF1UqEAY7YGzpUZK311ECO12ysb0oMt2jTYMwmgPnfPZfctD6SlV3u/JtsgE+bN5dXwV0ktyfP/3vl395zGoWxAkEAt/bQMKGIpEoeILivyd/b0E6" - + "ivi/l4fIRxghu8y8plt29Xg/0xZ6+5yGaCJxHWAsWgQytZm9w9bk6pN/KpUNRnQJAbQS72oDNSdO/UhBlOOntZYnbTi7J3LYZoxpdhf5fNCFKFYqSTM7ZA8DamXEf7UY2" - + "NVrOTFROMTX1/dhfSojcEQJBALNxIrEP97uszxIc8oH2r7DfXzmhRMKuIvnBfmNe1TR" + "VLvh1G1SKIyCYUTStaQCFN0FcH//Fab+zPiAgDmXApWs="); -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/annotation/ApiLogger.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/annotation/ApiLogger.java deleted file mode 100644 index cec5e37..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/annotation/ApiLogger.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.lang.annotation; - -import java.lang.annotation.*; - -/** - * 第三方系统API请求调用日志注解 - * @author huaheng - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface ApiLogger { - /** 接口名称 */ - String apiName() default ""; - - /** 接口调用方 */ - String from() default ""; - - /** 接口提供方 */ - String to() default "WMS"; - -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessStatus.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessStatus.java deleted file mode 100644 index 7254a9d..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessStatus.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.lang.constant; - -/** - * 操作状态 - * @author huaheng - */ -public class BusinessStatus { - /** 其它 */ - public static final String OTHER = "-1"; - - /** 成功 */ - public static final String SUCCESS = "0"; - - /** 失败 */ - public static final String FAIL = "1"; -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessType.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessType.java deleted file mode 100644 index 7a1142b..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/BusinessType.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.lang.constant; - -/** - * 业务操作类型 - * @author huaheng - */ -public class BusinessType { - /** 其它 */ - public static final String OTHER = "0"; - /** 新增 */ - public static final String INSERT = "1"; - /** 修改 */ - public static final String UPDATE = "2"; - /** 删除 */ - public static final String DELETE = "3"; - /** 授权 */ - public static final String GRANT = "4"; - /** 导出 */ - public static final String EXPORT = "5"; - /** 导入 */ - public static final String IMPORT = "6"; - /** 强退 */ - public static final String FORCE = "7"; - /** 生成代码 */ - public static final String GENCODE = "8"; -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/DataSourceName.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/DataSourceName.java deleted file mode 100644 index 2b09798..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/DataSourceName.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.lang.constant; - -/** - * 多数据源别名 - * @author huaheng - */ -public class DataSourceName { - /** 主库 */ - public static final String MASTER = "master"; - - /** 从库 */ - public static final String SLAVE = "slave"; - - /** wcs库 */ - public static final String WCS = "wcs"; -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/OperatorType.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/OperatorType.java deleted file mode 100644 index 3b98973..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/OperatorType.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.lang.constant; - -/** - * 操作人类别 - * @author huaheng - */ -public class OperatorType { - /** 其它 */ - public static final String OTHER = "0"; - - /** 后台用户 */ - public static final String MANAGE = "1"; - - /** 渠道用户 */ - public static final String CHANNEL = "2"; - - /** 手机端用户 */ - public static final String MOBILE = "3"; -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/ProcessCode.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/ProcessCode.java deleted file mode 100644 index 54d48e4..0000000 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/lang/constant/ProcessCode.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jeecg.modules.wms.framework.aspectj.lang.constant; - -/** - * 任务流程编码 - * @author xcq - */ -public class ProcessCode { - /** 入库任务 */ - public static final String RECEIPT_TASK_CODE = "receipt_task"; - /** 出库任务 */ - public static final String SHIPMENT_TASK_CODE = "shipment_task"; - /** 入库单据 */ - public static final String RECEIPT_BILL_CODE = "receipt_bill"; - /** 出库单据 */ - public static final String SHIPMENT_BILL_CODE = "shipment_bill"; - /** 其他任务 */ - public static final String OTHER_TASK_CODE = "other_task"; - - /** 从头部取值 */ - public static final String METHOD_HEAD = "head"; - /** 从返回结果取值 */ - public static final String METHOD_RESULT = "result"; - /** 通过表查询取值 */ - public static final String METHOD_SELECT = "SELECT"; - - /** 出库单据预约 */ - public static final String MODIFICATION_EDIT = "modificationEdit"; - - /** 出库单据审核 */ - public static final String REVIEW = "review"; - /** 出库单据销售单回传 */ - public static final String PUSH_SALES_DELIVERY = "pushSalesDelivery"; - - /** 入库单据创建 */ - public static final String CREATE_RECEIPT_TASK = "createReceiptTask"; - /** 入库单据回传 */ - public static final String RECEIPT_METHOD = "receiptMethod"; -} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/receipt/receiptHeader/controller/ReceiptHeaderController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/receipt/receiptHeader/controller/ReceiptHeaderController.java index 5826839..80f807a 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/receipt/receiptHeader/controller/ReceiptHeaderController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/receipt/receiptHeader/controller/ReceiptHeaderController.java @@ -24,7 +24,6 @@ import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; import org.jeecg.modules.wms.api.mobile.entity.QuickReceiptBean; import org.jeecg.modules.wms.api.mobile.service.IMobileService; import org.jeecg.modules.wms.config.material.service.IMaterialService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.receipt.receiptHeader.entity.ReceiptDetail; import org.jeecg.modules.wms.receipt.receiptHeader.entity.ReceiptHeader; import org.jeecg.modules.wms.receipt.receiptHeader.service.IReceiptDetailService; @@ -32,13 +31,23 @@ import org.jeecg.modules.wms.receipt.receiptHeader.service.IReceiptHeaderService import org.jeecg.utils.HuahengJwtUtil; import org.jeecg.utils.StringUtils; import org.jeecg.utils.constant.QuantityConstant; +import org.jeecg.utils.support.ApiLogger; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentHeader/controller/ShipmentHeaderController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentHeader/controller/ShipmentHeaderController.java index 19db219..f13b87c 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentHeader/controller/ShipmentHeaderController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentHeader/controller/ShipmentHeaderController.java @@ -24,7 +24,6 @@ import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.wms.api.erp.service.IErpService; import org.jeecg.modules.wms.api.mobile.entity.CallBoxBean; import org.jeecg.modules.wms.api.mobile.service.IMobileService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryDetail; import org.jeecg.modules.wms.inventory.inventoryHeader.service.IInventoryDetailService; import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentDetail; @@ -34,13 +33,23 @@ import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentHeaderServ import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; import org.jeecg.utils.HuahengJwtUtil; import org.jeecg.utils.constant.QuantityConstant; +import org.jeecg.utils.support.ApiLogger; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/controller/TaskHeaderController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/controller/TaskHeaderController.java index 385592a..5e7cc97 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/controller/TaskHeaderController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/controller/TaskHeaderController.java @@ -25,7 +25,6 @@ import org.jeecg.modules.wms.config.port.entity.Port; import org.jeecg.modules.wms.config.port.service.IPortService; import org.jeecg.modules.wms.config.zone.entity.Zone; import org.jeecg.modules.wms.config.zone.service.IZoneService; -import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; import org.jeecg.modules.wms.framework.service.IHuahengMultiHandlerService; import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; @@ -36,13 +35,23 @@ import org.jeecg.utils.ConvertUtils; import org.jeecg.utils.HuahengJwtUtil; import org.jeecg.utils.StringUtils; import org.jeecg.utils.constant.QuantityConstant; +import org.jeecg.utils.support.ApiLogger; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java index 8e14594..04ab8d0 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java @@ -12,8 +12,8 @@ import org.apache.shiro.SecurityUtils; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.oConvertUtils; -import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication; -import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; +import org.jeecg.utils.support.ApiAuthentication; +import org.jeecg.utils.support.RSA256Key; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java index bb589ef..efb5e35 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java @@ -1,31 +1,32 @@ package org.jeecg.utils; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.TypeReference; -import com.alibaba.fastjson.parser.Feature; -import org.jeecg.common.exception.JeecgBootException; -import com.xkcoding.http.util.StringUtil; - -import antlr.StringUtils; -import cn.hutool.core.util.StrUtil; -import net.bytebuddy.asm.Advice.This; -import okhttp3.*; -import org.jeecg.modules.wms.framework.aspectj.ApiLoggerAspect; -import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.messaging.support.ErrorMessage; - import java.io.IOException; -import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import javax.validation.constraints.NotNull; +import org.jeecg.common.exception.JeecgBootException; +import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; +import org.jeecg.utils.aspect.ApiLoggerAspect; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; + +import cn.hutool.core.util.StrUtil; +import okhttp3.ConnectionPool; +import okhttp3.FormBody; +import okhttp3.Interceptor; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + /** * OkHttp发送请求 * @author huaheng diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/SecretKeyUtils.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/SecretKeyUtils.java index 5aab3b7..364f5e7 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/utils/SecretKeyUtils.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/SecretKeyUtils.java @@ -14,7 +14,7 @@ import java.util.Base64; import java.util.HashMap; import java.util.Map; -import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; +import org.jeecg.utils.support.RSA256Key; /** * KeyPairGenerator https://www.jianshu.com/p/4de1ee0e7206 key的生成使用方法 diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiAuthenticationAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiAuthenticationAspect.java new file mode 100644 index 0000000..a7d34d6 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiAuthenticationAspect.java @@ -0,0 +1,117 @@ +package org.jeecg.utils.aspect; + +import java.lang.reflect.Method; + +import javax.servlet.http.HttpServletRequest; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.jeecg.utils.HuahengJwtUtil; +import org.jeecg.utils.support.ApiAuthentication; +import org.jeecg.utils.support.PassApiAuthentication; +import org.jeecg.utils.support.RSA256Key; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import com.auth0.jwt.JWT; +import com.auth0.jwt.JWTVerifier; +import com.auth0.jwt.algorithms.Algorithm; +import com.auth0.jwt.exceptions.JWTVerificationException; +import com.auth0.jwt.interfaces.DecodedJWT; + +import lombok.extern.slf4j.Slf4j; + +/** + * 第三方系统调用接口身份认证Aspect + * @author TanYibin + * @createDate 2023年2月14日 + */ +@Slf4j +@Aspect +@Component +@EnableAsync +public class ApiAuthenticationAspect { + + @Autowired + private RSA256Key rsa256Key; + + @Pointcut("execution(* org.jeecg.modules.wms.api..*.*(..)) " + "&& (@annotation(org.springframework.web.bind.annotation.RequestMapping) " + + "|| @annotation(org.springframework.web.bind.annotation.GetMapping) " + "|| @annotation(org.springframework.web.bind.annotation.PostMapping))") + public void executeController() {} + + /** + * API Token 验证 + * @author TanYibin + * @createDate 2023年2月14日 + * @param joinPoint + * @throws NoSuchMethodException + * @throws Throwable + */ + @Before("executeController()") + public void doBefore(JoinPoint joinPoint) throws NoSuchMethodException, Throwable { + Method method = this.getTargetMethod(joinPoint); + // 检查是否有passtoken注释,有则跳过认证 + if (method.isAnnotationPresent(PassApiAuthentication.class)) { + PassApiAuthentication passApiAuthentication = method.getAnnotation(PassApiAuthentication.class); + if (passApiAuthentication.required()) { + return; + } + } + // 获取request对象 + ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + String token = request.getHeader("token"); + if (token == null) { + log.error("Authentication token is null"); + throw new RuntimeException("Authentication token is null"); + } + try { + Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey()); + JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); + DecodedJWT jwt = verifier.verify(token); + new ApiAuthentication.ApiAuthenticationBuild().operator(jwt.getClaim("operator").asString()).audience(jwt.getAudience().get(0)).issuer(jwt.getIssuer()) + .issuedAt(jwt.getIssuedAt()).expireDateTime(jwt.getExpiresAt()).bulid(); + } catch (JWTVerificationException e) { + log.error(e.getMessage()); + throw e; + } + } + + /** + * 基于连接点信息获取目标方法对象 + * @author TanYibin + * @createDate 2023年2月14日 + * @param joinPoint + * @return + * @throws NoSuchMethodException + */ + private Method getTargetMethod(JoinPoint joinPoint) throws NoSuchMethodException { + // 获取目标类对象 + Class<?> clazz = joinPoint.getTarget().getClass(); + // 获取方法签名信息,方法名和参数列表 + MethodSignature signature = (MethodSignature)joinPoint.getSignature(); + // 获取目标方法对象 + return clazz.getDeclaredMethod(signature.getName(), signature.getParameterTypes()); + } + + /** + * 获取方法类全名+方法名 + * @author TanYibin + * @createDate 2023年2月14日 + * @param method + * @return + */ + private String getClassAndMethodName(Method method) { + // 获取类全名 + String className = method.getDeclaringClass().getName(); + // 获取方法名 + String methodName = method.getName(); + return new StringBuffer(className).append(".").append(methodName).toString(); + } +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiLoggerAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiLoggerAspect.java new file mode 100644 index 0000000..b2ec98f --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/ApiLoggerAspect.java @@ -0,0 +1,556 @@ +package org.jeecg.utils.aspect; + +import java.net.InetAddress; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.exception.ExceptionUtils; +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.jeecg.JeecgSystemApplication; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.wms.config.address.service.IAddressService; +import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog; +import org.jeecg.modules.wms.monitor.apiLog.service.IApiLogService; +import org.jeecg.utils.HuahengJwtUtil; +import org.jeecg.utils.ServletUtils; +import org.jeecg.utils.SpringUtils; +import org.jeecg.utils.StringUtils; +import org.jeecg.utils.support.ApiLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.stereotype.Component; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import okhttp3.Request; +import okhttp3.Response; + +/** + * API调用日志记录处理 + * @author huaheng + */ +@Aspect +@Component +@EnableAsync +public class ApiLoggerAspect { + private static final Logger log = LoggerFactory.getLogger(ApiLoggerAspect.class); + + private static IApiLogService apiLogService; + + private static IAddressService addressService; + + @Autowired + public void setApiLogService(IApiLogService apiLogService) { + ApiLoggerAspect.apiLogService = apiLogService; + } + + @Autowired + public void setAddressService(IAddressService addressService) { + ApiLoggerAspect.addressService = addressService; + } + + // 配置织入点 + @Pointcut("@annotation(org.jeecg.utils.support.ApiLogger)") + public void logPointCut() {} + + @Around("logPointCut() && @annotation(apiLogger)") + public Object around(ProceedingJoinPoint point, ApiLogger apiLogger) throws Throwable { + return aroundXXX2Wms(point, apiLogger); + } + + /** 记录第三方系统调用WMS接口的日志 **/ + private Object aroundXXX2Wms(ProceedingJoinPoint point, ApiLogger apiLogger) { + Object ret = null; + ApiLog apiLog = initApiLog(apiLogger, point); + try { + ret = point.proceed(); + } catch (Throwable e) { + setApiLogThrowable(apiLog, e); + ret = Result.error(e.getMessage()); + return ret; + } finally { + if (ret != null) { + finishApiLog(apiLog, ret); + } + } + return ret; + } + +// /** 记录WMS调用第三方接口的日志 **/ +// private Object aroundWms2XXX(ProceedingJoinPoint point, ApiLogger apiLogger) { +// Object ret = null; +// ApiLog log = new ApiLog(); +// +// HttpURLConnection connection = null; +// String body = null; +// +// try { +// connection = (HttpURLConnection)point.getArgs()[0]; +// body = (String)point.getArgs()[1]; +// initApiLog(connection, body); +// ret = point.proceed(); +// } catch (Throwable e) { +// setApiLogThrowable(log, e); +// ret = Result.error(e.getMessage()); +// } finally { +// if (ret != null) { +// finishApiLog(log, connection, ret.toString()); +// } +// } +// return ret; +// } + +// /** +// * 记录响应头信息,保存日志到数据库 +// */ +// public static void finishApiLog(ApiLog log, HttpURLConnection connection, String body) { +// try { +// log.setResponseBody(body); +// log.setResponseTime(new Date()); +// Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); +// log.setDuration(duration.intValue()); +// log.setHttpCode(connection.getResponseCode()); +// +// // 响应头 +// Set<String> keyset = connection.getHeaderFields().keySet(); +// ArrayList<String> headerList = new ArrayList<>(); +// Iterator<String> it = keyset.iterator(); +// while (it.hasNext()) { +// String name = it.next(); +// String header = connection.getHeaderField(name); +// if (name == null || "".equals(name)) { +// // 第一行没有name +// // HTTP/1.1 200 OK +// headerList.add(header); +// } else { +// headerList.add(name + ": " + header); +// } +// } +// log.setResponseHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); +// Result json = JSON.parseObject(body, Result.class); +// log.setRetCode(json.getCode()); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// SpringUtils.getBean(ApiLogAspect.class).saveApiLog(log); +// } +// } + +// /** +// * 根据url,从address表中判断调用的去向 +// */ +// public static void parseUrl(ApiLog log, URL url, String warehouseCode) { +// try { +// String[] spList = url.toString().split("/"); +// String apiName = spList[spList.length - 1]; +// String ip = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); +// Address address = addressService.getAddressByUrl(url.toString(), warehouseCode); +// log.setApiName(apiName); +// log.setRequestFrom("WMS"); +// log.setIp(ip); +// log.setResponseBy(address.getParam().toUpperCase()); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + +// /** +// * 记录WMS调用第三方系统接口的请求信息 +// * 在HttpUtils.body POST方法中直接调用本类static方法 +// **/ +// public static ApiLog initApiLog(String Method, String urlStr, String body, HttpHeaders headers, String warehouseCode) { +// ApiLog log = new ApiLog(); +// try { +// URL url = new URL(urlStr); +// log.setApiMethod(Method); +// log.setUrl(urlStr); +// log.setRequestTime(new Date()); +// parseUrl(log, url, warehouseCode); +// +// // 请求头 +// Set<String> keySet = headers.keySet(); +// ArrayList<String> headerList = new ArrayList<>(); +// Iterator<String> it = keySet.iterator(); +// while (it.hasNext()) { +// String name = it.next(); +// String header = String.valueOf(headers.getContentType()); +// headerList.add(name + ": " + header); +// } +// +// log.setRequestHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); +// log.setRequestBody(body); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// return log; +// } + +// /** +// * 记录WMS调用第三方系统接口的请求信息 +// * 在HttpUtils.body POST方法中直接调用本类static方法 +// **/ +// public static ApiLog initApiLog(HttpURLConnection connection, String body) { +// ApiLog log = new ApiLog(); +// try { +// log.setApiMethod(connection.getRequestMethod()); +// log.setUrl(connection.getURL().toString()); +// log.setRequestTime(new Date()); +// parseUrl(log, connection.getURL()); +// +// // 请求头 +// Set<String> keySet = connection.getRequestProperties().keySet(); +// ArrayList<String> headerList = new ArrayList<>(); +// Iterator<String> it = keySet.iterator(); +// while (it.hasNext()) { +// String name = it.next(); +// String header = connection.getRequestProperty(name); +// headerList.add(name + ":" + header); +// } +// +// log.setRequestHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); +// log.setRequestBody(body); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// return log; +// } + + /** + * 记录WMS调用第三方系统接口的请求信息 + * 在OKHttpUtils.bodypost方法中直接调用本类static方法 + * @param apiLog + **/ + public static void initApiLog(ApiLog apiLog, Request request, String body) { + try { + apiLog.setApiMethod(request.method()); + apiLog.setUrl(request.url().toString()); + apiLog.setRequestTime(new Date()); + parseUrl(apiLog, request.url().url()); + apiLog.setRequestHeader(request.headers().toString()); + apiLog.setRequestBody(body); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** 记录响应头信息 **/ + public static void finishApiLog(ApiLog log, Response response, String responseBody) { + try { + log.setResponseTime(new Date()); + Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); + log.setDuration(duration.intValue()); + if (response == null) { + return; + } + log.setHttpCode(response.code()); + log.setResponseHeader(response.headers().toString()); + log.setResponseBody(responseBody); + Result result = null; + try { + result = JSON.parseObject(responseBody, Result.class); + } catch (Exception ex) { + responseBody = JSON.parse(responseBody).toString(); + result = JSON.parseObject(responseBody, Result.class); + } + log.setRetCode(result.getCode()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (StringUtils.isNotEmpty(log.getResponseBody()) && log.getResponseBody().length() > 2001) { + log.setResponseBody(log.getResponseBody().substring(0, 2000) + "...\n"); + } + } catch (Exception e) { + e.printStackTrace(); + } + SpringUtils.getBean(ApiLoggerAspect.class).saveApiLog(log); + } + } + + /** 根据url,从address表中判断调用的去向 **/ + public static void parseUrl(ApiLog apiLog, URL url) { + try { + String[] spList = url.toString().split("/"); + String apiName = spList[spList.length - 1]; + String ip = JeecgSystemApplication.getLocalHostExactAddress().getHostAddress(); + apiLog.setApiName(apiName); + apiLog.setRequestFrom(HuahengJwtUtil.HUAHENG_SYSTEM_ID); + apiLog.setIp(ip); +// Address address = addressService.getAddressByUrl(url.toString(), QuantityConstant.DEFAULT_WAREHOUSE); +// apiLog.setResponseBy(address.getParam().toUpperCase()); + } catch (Exception e) { + e.printStackTrace(); + } + } + +// /** +// * 记录响应头信息 +// **/ +// public static void finishApiLog(ApiLog log, HttpHeaders headers, String body) { +// try { +// log.setResponseBody(body); +// log.setResponseTime(new Date()); +// Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); +// log.setDuration(duration.intValue()); +// log.setHttpCode(200); +// +// // 响应头 +// Set<String> keyset = headers.keySet(); +// ArrayList<String> headerList = new ArrayList<>(); +// Iterator<String> it = keyset.iterator(); +// while (it.hasNext()) { +// String name = it.next(); +// String header = String.valueOf(headers.getContentType()); +// if (name == null || "".equals(name)) +// // 第一行没有name +// // HTTP/1.1 200 OK +// headerList.add(header); +// else +// headerList.add(name + ": " + header); +// } +// log.setResponseHeader(org.apache.commons.lang3.StringUtils.join(headerList, "\n")); +// Result json = JSON.parseObject(body, Result.class); +// log.setRetCode(json.getCode()); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// SpringUtils.getBean(ApiLogAspect.class).saveApiLog(log); +// } +// } + + private ApiLog initApiLog(ApiLogger apiLogger, ProceedingJoinPoint point) { + ApiLog log = new ApiLog(); + try { + log.setRequestTime(new Date()); + log.setRequestFrom(apiLogger.from()); + log.setResponseBy(apiLogger.to()); + log.setApiName(apiLogger.apiName()); + + HttpServletRequest request = ServletUtils.getRequest(); + String qryStr = request.getQueryString(); + String url = request.getRequestURL().toString(); + if (StringUtils.isNotEmpty(qryStr)) { + url = url + "?" + qryStr; + } + log.setUrl(url); + log.setApiMethod(request.getMethod()); + log.setIp(ApiLoggerAspect.getIpAddr(request)); + + rebuildRequestHeader(log); + rebuildRequestBody(log, request); + + // 如果reqeust中取不到post参数,就从接口方法参数中取json对象 + if (StringUtils.isEmpty(log.getRequestBody())) { + rebuildRequestBody(log, point); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return log; + } + + private void finishApiLog(ApiLog log, Object ret) { + try { + rebuildResponseHeader(log); + rebuildResponseBody(log, ret); + + log.setResponseTime(new Date()); + Long duration = log.getResponseTime().getTime() - log.getRequestTime().getTime(); + log.setDuration(duration.intValue()); + + HttpServletResponse resp = ServletUtils.getResponse(); + log.setHttpCode(resp.getStatus()); + + if (ret instanceof Result) { + int retCode = ((Result)ret).getCode(); + log.setRetCode(retCode); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + saveApiLog(log); + } + } + + public static void setApiLogException(ApiLog log, Exception e) { + try { + String exception = ExceptionUtils.getFullStackTrace(e); + String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 2000) + "..."; + log.setException(shortExpInfo); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static void setApiLogThrowable(ApiLog log, Throwable e) { + try { + String exception = ExceptionUtils.getFullStackTrace(e); + String shortExpInfo = e.getMessage() + "\n" + org.apache.commons.lang3.StringUtils.left(exception, 2000) + "..."; + log.setException(shortExpInfo); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void rebuildRequestHeader(ApiLog log) { + try { + HttpServletRequest req = ServletUtils.getRequest(); + Enumeration names = req.getHeaderNames(); + ArrayList<String> headerList = new ArrayList<>(); + while (names.hasMoreElements()) { + String name = (String)names.nextElement(); + String header = req.getHeader(name); + headerList.add(name + ":" + header); + } + String headers = org.apache.commons.lang3.StringUtils.join(headerList, "\n"); + log.setRequestHeader(headers); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** 先从post参数中构造request body */ + private void rebuildRequestBody(ApiLog log, HttpServletRequest request) { + try { + Set<String> keySet = request.getParameterMap().keySet(); + Iterator<String> it = keySet.iterator(); + StringBuffer sbf = new StringBuffer(); + while (it.hasNext()) { + String key = it.next(); + String value = request.getParameter(key); + sbf.append(key).append("=").append(value); + if (it.hasNext()) { + sbf.append("&"); + } + } + log.setRequestBody(sbf.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 根据接口中的参数构造request body + */ + private void rebuildRequestBody(ApiLog log, ProceedingJoinPoint point) { + try { + if (point.getArgs().length == 1) { + log.setRequestBody(JSONObject.toJSONString(point.getArgs()[0])); + return; + } + + MethodSignature m = (MethodSignature)point.getSignature(); + HashMap<String, Object> map = new HashMap<>(); + Object[] args = point.getArgs(); + for (int i = 0; i < m.getParameterNames().length; i++) { + String name = m.getParameterNames()[i]; +// Class type = m.getParameterTypes()[i]; + if (args[i] instanceof HttpServletRequest) { + continue; + } + if (args[i] instanceof HttpServletResponse) { + continue; + } + map.put(name, args[i]); + } + + if (!map.isEmpty()) { + if (map.keySet().size() == 1) { + log.setRequestBody(JSONObject.toJSONString(map.values().iterator().next())); + } else { + log.setRequestBody(JSONObject.toJSONString(map)); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void rebuildResponseHeader(ApiLog log) { + try { + HttpServletResponse resp = ServletUtils.getResponse(); + Collection<String> names = resp.getHeaderNames(); + ArrayList<String> headerList = new ArrayList<>(); + Iterator<String> it = names.iterator(); + while (it.hasNext()) { + String name = it.next(); + String header = resp.getHeader(name); + headerList.add(name + ": " + header); + } + String headers = org.apache.commons.lang3.StringUtils.join(headerList, "\n"); + log.setResponseHeader(headers); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void rebuildResponseBody(ApiLog log, Object ret) { + try { + log.setResponseBody(JSONObject.toJSON(ret).toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Async + public void saveApiLog(ApiLog log) { + try { + apiLogService.saveOrUpdate(log); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String getIpAddr(HttpServletRequest request) { + 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(); + if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) { + // 根据网卡取本机配置的IP + InetAddress inet = null; + try { + inet = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + ipAddress = inet.getHostAddress(); + } + } + // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 + // "***.***.***.***".length() = 15 + if (ipAddress != null && ipAddress.length() > 15) { + if (ipAddress.indexOf(",") > 0) { + ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); + } + } + return ipAddress; + } +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/LogRecordAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/LogRecordAspect.java new file mode 100644 index 0000000..112e312 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/LogRecordAspect.java @@ -0,0 +1,43 @@ +package org.jeecg.utils.aspect; + +import javax.servlet.http.HttpServletRequest; + +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.springframework.context.annotation.Configuration; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import lombok.extern.slf4j.Slf4j; + +// 暂时注释掉,提高系统性能 +@Slf4j +@Aspect // 定义一个切面 +@Configuration +public class LogRecordAspect { + + // 定义切点Pointcut + @Pointcut("execution(public * org.jeecg.modules.wms..*.controller..*.*(..))" + "&& (@annotation(org.springframework.web.bind.annotation.RequestMapping) " + + "|| @annotation(org.springframework.web.bind.annotation.GetMapping) " + "|| @annotation(org.springframework.web.bind.annotation.PostMapping))") + public void excudeService() {} + + @Around("excudeService()") + public Object doAround(ProceedingJoinPoint point) throws Throwable { + long startTime = System.currentTimeMillis(); + // 接收到请求,记录请求内容 + ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); + // 获取请求的request + HttpServletRequest request = attributes.getRequest(); + String url = request.getRequestURL().toString(); + String className = point.getTarget().getClass().getSimpleName(); + String methodName = point.getSignature().getName(); + log.info("[{}] {} [{}.{}] [{}]", request.getMethod(), url, className, methodName, ApiLoggerAspect.getIpAddr(request)); + // result的值就是被拦截方法的返回值 + Object result = point.proceed(); + long callTime = System.currentTimeMillis() - startTime; + log.info("[{}] {} [{}.{}] [{}ms]", request.getMethod(), url, className, methodName, callTime); + return result; + } +} \ No newline at end of file diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiAuthentication.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiAuthentication.java new file mode 100644 index 0000000..2e73147 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiAuthentication.java @@ -0,0 +1,106 @@ +package org.jeecg.utils.support; + +import java.util.Date; + +import org.jeecg.utils.HuahengJwtUtil; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import lombok.Data; + +/** + * 接口认证Token对象 + * @author TanYibin + * @createDate 2023年2月14日 + */ +@Data +public class ApiAuthentication { + + private static final ThreadLocal<ApiAuthentication> REQUEST_HEADER_CONTEXT_THREAD_LOCAL = new ThreadLocal<>(); + + /** Token提供方 */ + private String operator; + + /** Token使用方 */ + private String audience = "Unknown"; // 观众,相当于接受者 + + /** Token签发方(WMS) */ + private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; + + /** Token签发时间 */ + private Date issuedAt; + + /** Token失效时间 */ + private Date expireDateTime; + + public ApiAuthentication() {} + + public static ApiAuthentication getInstance() { + return REQUEST_HEADER_CONTEXT_THREAD_LOCAL.get(); + } + + public void setContext(ApiAuthentication context) { + REQUEST_HEADER_CONTEXT_THREAD_LOCAL.set(context); + } + + public static void clean() { + REQUEST_HEADER_CONTEXT_THREAD_LOCAL.remove(); + } + + private ApiAuthentication(ApiAuthenticationBuild apiAuthenticationBuild) { + this.operator = apiAuthenticationBuild.operator; + this.audience = apiAuthenticationBuild.audience; + this.issuer = apiAuthenticationBuild.issuer; + this.issuedAt = apiAuthenticationBuild.issuedAt; + this.expireDateTime = apiAuthenticationBuild.expireDateTime; + setContext(this); + } + + public static class ApiAuthenticationBuild { + + /** Token提供方 */ + private String operator; + + /** Token使用方 */ + private String audience; // 观众,相当于接受者 + + /** Token签发方(WMS) */ + private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; + + /** Token签发时间 */ + private Date issuedAt; + + /** Token失效时间 */ + private Date expireDateTime; + + public ApiAuthenticationBuild operator(String operator) { + this.operator = operator; + return this; + } + + public ApiAuthenticationBuild audience(String audience) { + this.audience = audience; + return this; + } + + public ApiAuthenticationBuild issuer(String issuer) { + this.issuer = issuer; + return this; + } + + public ApiAuthenticationBuild issuedAt(Date issuedAt) { + this.issuedAt = issuedAt; + return this; + } + + public ApiAuthenticationBuild expireDateTime(Date expireDateTime) { + this.expireDateTime = expireDateTime; + return this; + } + + public ApiAuthentication bulid() { + return new ApiAuthentication(this); + } + } + +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiLogger.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiLogger.java new file mode 100644 index 0000000..4e6b8a3 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ApiLogger.java @@ -0,0 +1,22 @@ +package org.jeecg.utils.support; + +import java.lang.annotation.*; + +/** + * 第三方系统API请求调用日志注解 + * @author huaheng + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface ApiLogger { + /** 接口名称 */ + String apiName() default ""; + + /** 接口调用方 */ + String from() default ""; + + /** 接口提供方 */ + String to() default "WMS"; + +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessStatus.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessStatus.java new file mode 100644 index 0000000..cea6f75 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessStatus.java @@ -0,0 +1,16 @@ +package org.jeecg.utils.support; + +/** + * 操作状态 + * @author huaheng + */ +public class BusinessStatus { + /** 其它 */ + public static final String OTHER = "-1"; + + /** 成功 */ + public static final String SUCCESS = "0"; + + /** 失败 */ + public static final String FAIL = "1"; +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessType.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessType.java new file mode 100644 index 0000000..e064ef3 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/BusinessType.java @@ -0,0 +1,26 @@ +package org.jeecg.utils.support; + +/** + * 业务操作类型 + * @author huaheng + */ +public class BusinessType { + /** 其它 */ + public static final String OTHER = "0"; + /** 新增 */ + public static final String INSERT = "1"; + /** 修改 */ + public static final String UPDATE = "2"; + /** 删除 */ + public static final String DELETE = "3"; + /** 授权 */ + public static final String GRANT = "4"; + /** 导出 */ + public static final String EXPORT = "5"; + /** 导入 */ + public static final String IMPORT = "6"; + /** 强退 */ + public static final String FORCE = "7"; + /** 生成代码 */ + public static final String GENCODE = "8"; +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/DataSourceName.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/DataSourceName.java new file mode 100644 index 0000000..af3c711 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/DataSourceName.java @@ -0,0 +1,16 @@ +package org.jeecg.utils.support; + +/** + * 多数据源别名 + * @author huaheng + */ +public class DataSourceName { + /** 主库 */ + public static final String MASTER = "master"; + + /** 从库 */ + public static final String SLAVE = "slave"; + + /** wcs库 */ + public static final String WCS = "wcs"; +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/OperatorType.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/OperatorType.java new file mode 100644 index 0000000..ba5fe4d --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/OperatorType.java @@ -0,0 +1,19 @@ +package org.jeecg.utils.support; + +/** + * 操作人类别 + * @author huaheng + */ +public class OperatorType { + /** 其它 */ + public static final String OTHER = "0"; + + /** 后台用户 */ + public static final String MANAGE = "1"; + + /** 渠道用户 */ + public static final String CHANNEL = "2"; + + /** 手机端用户 */ + public static final String MOBILE = "3"; +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/PassApiAuthentication.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/PassApiAuthentication.java new file mode 100644 index 0000000..a52e2a2 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/PassApiAuthentication.java @@ -0,0 +1,17 @@ +package org.jeecg.utils.support; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 跳过API身份验证注解 + * @author TanYibin + * @createDate 2023年2月13日 + */ +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface PassApiAuthentication { + boolean required() default true; +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ProcessCode.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ProcessCode.java new file mode 100644 index 0000000..9a4fc98 --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/ProcessCode.java @@ -0,0 +1,38 @@ +package org.jeecg.utils.support; + +/** + * 任务流程编码 + * @author xcq + */ +public class ProcessCode { + /** 入库任务 */ + public static final String RECEIPT_TASK_CODE = "receipt_task"; + /** 出库任务 */ + public static final String SHIPMENT_TASK_CODE = "shipment_task"; + /** 入库单据 */ + public static final String RECEIPT_BILL_CODE = "receipt_bill"; + /** 出库单据 */ + public static final String SHIPMENT_BILL_CODE = "shipment_bill"; + /** 其他任务 */ + public static final String OTHER_TASK_CODE = "other_task"; + + /** 从头部取值 */ + public static final String METHOD_HEAD = "head"; + /** 从返回结果取值 */ + public static final String METHOD_RESULT = "result"; + /** 通过表查询取值 */ + public static final String METHOD_SELECT = "SELECT"; + + /** 出库单据预约 */ + public static final String MODIFICATION_EDIT = "modificationEdit"; + + /** 出库单据审核 */ + public static final String REVIEW = "review"; + /** 出库单据销售单回传 */ + public static final String PUSH_SALES_DELIVERY = "pushSalesDelivery"; + + /** 入库单据创建 */ + public static final String CREATE_RECEIPT_TASK = "createReceiptTask"; + /** 入库单据回传 */ + public static final String RECEIPT_METHOD = "receiptMethod"; +} diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/support/RSA256Key.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/RSA256Key.java new file mode 100644 index 0000000..3c85d4f --- /dev/null +++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/support/RSA256Key.java @@ -0,0 +1,29 @@ +package org.jeecg.utils.support; + +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; + +import org.jeecg.utils.SecretKeyUtils; +import org.springframework.stereotype.Component; + +import lombok.Data; + +@Data +@Component +public class RSA256Key { + + /** 第三方HTTP访问 公钥 */ + private RSAPublicKey publicKey = + (RSAPublicKey)SecretKeyUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmYcmhWzpgLgWVD0j+uTyFvQW0BBktYVJmTRQvLlrKt4CHnkfQ4Dn" + + "SLaRXCcJK/TGgAY0BtnaKUgFBqqmTI9l82tpxEWqYRzp4KGRLnVA6/igidYib0JeBWroI6Bs0wR43fkSXA8XG+n32bVbmMTKNa9IFUJCzICVTEjQzMQrSAwIDAQAB"); + + /** 第三方HTTP访问 私钥 */ + private RSAPrivateKey privateKey = + (RSAPrivateKey)SecretKeyUtils.getPrivateKey("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKZhyaFbOmAuBZUPSP65PIW9BbQEGS1hUmZNFC8uWsq" + + "3gIeeR9DgOdItpFcJwkr9MaABjQG2dopSAUGqqZMj2Xza2nERaphHOngoZEudUDr+KCJ1iJvQl4FaugjoGzTBHjd+RJcDxcb6ffZtVuYxMo1r0gVQkLMgJVMSNDMxCtID" + + "AgMBAAECgYBhxluIMCVI+iKbqyTZVB/l8+PTGwl0qpmStr8iztnaASZODEzlya8Q/XNzFrAQA2TTQ7YKiKB2vqQwY8tNRab7jpR4t5WPApDVrMvjPfvqVvBsPzTYr2c08" + + "xMfqcj5HNzPLisb7Wvi7URSL4jIY/106lXN+9cJuMV0oDZzcAhaYQJBANdNMlSnzTDF8VQ7ETpzZQrF0UzlqKeKG0Pz/YeTXT4IjyBhzvaSOF3+hi1cWucrSU0xMUAR9F" + + "av+K1BlPTYW/MCQQDF1UqEAY7YGzpUZK311ECO12ysb0oMt2jTYMwmgPnfPZfctD6SlV3u/JtsgE+bN5dXwV0ktyfP/3vl395zGoWxAkEAt/bQMKGIpEoeILivyd/b0E6" + + "ivi/l4fIRxghu8y8plt29Xg/0xZ6+5yGaCJxHWAsWgQytZm9w9bk6pN/KpUNRnQJAbQS72oDNSdO/UhBlOOntZYnbTi7J3LYZoxpdhf5fNCFKFYqSTM7ZA8DamXEf7UY2" + + "NVrOTFROMTX1/dhfSojcEQJBALNxIrEP97uszxIc8oH2r7DfXzmhRMKuIvnBfmNe1TR" + "VLvh1G1SKIyCYUTStaQCFN0FcH//Fab+zPiAgDmXApWs="); +} -- libgit2 0.22.2