17 changed files with 532 additions and 307 deletions
@ -0,0 +1,162 @@ |
|||||
|
package com.kms.aspect; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.aspectj.lang.JoinPoint; |
||||
|
import org.aspectj.lang.ProceedingJoinPoint; |
||||
|
import org.aspectj.lang.annotation.Around; |
||||
|
import org.aspectj.lang.annotation.Aspect; |
||||
|
import org.aspectj.lang.annotation.Pointcut; |
||||
|
import org.aspectj.lang.reflect.MethodSignature; |
||||
|
import org.springframework.beans.factory.InitializingBean; |
||||
|
import org.springframework.context.EnvironmentAware; |
||||
|
import org.springframework.core.env.Environment; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||
|
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.lang.reflect.Method; |
||||
|
import java.lang.reflect.Parameter; |
||||
|
import java.util.Collection; |
||||
|
import java.util.Enumeration; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 接口日志界面 |
||||
|
* |
||||
|
* @author hxh |
||||
|
**/ |
||||
|
@Aspect |
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class WebLogAspect implements EnvironmentAware, InitializingBean { |
||||
|
|
||||
|
private boolean printResponseEnable; |
||||
|
private Environment environment; |
||||
|
|
||||
|
/** |
||||
|
* 切点 |
||||
|
*/ |
||||
|
@Pointcut("@within(org.springframework.web.bind.annotation.RestController) || @within(org.springframework.stereotype.Controller)") |
||||
|
public void webLog() { |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 环绕切面 |
||||
|
* |
||||
|
* @param joinPoint ProceedingJoinPoint |
||||
|
* @return 结果 |
||||
|
* @throws Throwable 异常 |
||||
|
*/ |
||||
|
@Around("webLog()") |
||||
|
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { |
||||
|
long startTime = System.currentTimeMillis(); |
||||
|
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
||||
|
if (servletRequestAttributes == null) { |
||||
|
return joinPoint.proceed(); |
||||
|
} |
||||
|
HttpServletRequest request = servletRequestAttributes.getRequest(); |
||||
|
Class<?> targetCls = joinPoint.getTarget().getClass(); |
||||
|
MethodSignature ms = (MethodSignature) joinPoint.getSignature(); |
||||
|
//获取目标方法上的注解指定的操作名称
|
||||
|
Method targetMethod = |
||||
|
targetCls.getDeclaredMethod( |
||||
|
ms.getName(), |
||||
|
ms.getParameterTypes()); |
||||
|
String uri = request.getRequestURI(); |
||||
|
String httpMethod = request.getMethod(); |
||||
|
Object requestParams = getRequestParameter(request, joinPoint); |
||||
|
log.info("[{}] \"{}\" begin, params:{}", httpMethod, uri, |
||||
|
JSON.toJSONString(requestParams)); |
||||
|
Object result; |
||||
|
try { |
||||
|
result = joinPoint.proceed(); |
||||
|
if (printResponseEnable) { |
||||
|
log.info("[{}] \"{}\" response:{}", httpMethod, uri, JSON.toJSONString(result)); |
||||
|
} |
||||
|
return result; |
||||
|
} catch (Throwable ex) { |
||||
|
log.error("[{}] \"{}\" error:{}", httpMethod, uri, ex.getMessage()); |
||||
|
throw ex; |
||||
|
} finally { |
||||
|
log.info("[{}] \"{}\" end, use time:{}ms", httpMethod, uri, System.currentTimeMillis() - startTime); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取请求参数 |
||||
|
* |
||||
|
* @param request HttpServletRequest |
||||
|
* @param joinPoint JoinPoint |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
private Object getRequestParameter(HttpServletRequest request, JoinPoint joinPoint) { |
||||
|
Object[] args = joinPoint.getArgs(); |
||||
|
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); |
||||
|
Parameter[] parameters = method.getParameters(); |
||||
|
Map<String, Object> params = new HashMap<>(parameters.length); |
||||
|
//json数据
|
||||
|
for (int i = 0; i < parameters.length; i++) { |
||||
|
if (isFilterObject(args[i])) { |
||||
|
continue; |
||||
|
} |
||||
|
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class); |
||||
|
if (requestBody != null) { |
||||
|
//一个接口只会有一个RequestBody
|
||||
|
return args[i]; |
||||
|
} |
||||
|
} |
||||
|
//表单提交或url拼接
|
||||
|
Enumeration<String> paramNames = request.getParameterNames(); |
||||
|
while (paramNames.hasMoreElements()) { |
||||
|
String key = paramNames.nextElement(); |
||||
|
params.put(key, request.getParameter(key)); |
||||
|
} |
||||
|
return !params.isEmpty() ? params : null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 是否需要过滤 |
||||
|
* |
||||
|
* @param obj Object |
||||
|
* @return true or false |
||||
|
*/ |
||||
|
private boolean isFilterObject(final Object obj) { |
||||
|
if (obj == null) { |
||||
|
return true; |
||||
|
} |
||||
|
Class<?> clazz = obj.getClass(); |
||||
|
if (clazz.isArray()) { |
||||
|
return clazz.getComponentType().isAssignableFrom(MultipartFile.class); |
||||
|
} else if (Collection.class.isAssignableFrom(clazz)) { |
||||
|
Collection collection = (Collection) obj; |
||||
|
for (Object o : collection) { |
||||
|
return o instanceof MultipartFile; |
||||
|
} |
||||
|
} else if (Map.class.isAssignableFrom(clazz)) { |
||||
|
Map map = (Map) obj; |
||||
|
for (Object o : map.entrySet()) { |
||||
|
Map.Entry entry = (Map.Entry) o; |
||||
|
return entry.getValue() instanceof MultipartFile; |
||||
|
} |
||||
|
} |
||||
|
return obj instanceof MultipartFile || obj instanceof HttpServletRequest || obj instanceof HttpServletResponse; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setEnvironment(Environment environment) { |
||||
|
this.environment = environment; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void afterPropertiesSet() { |
||||
|
printResponseEnable = environment.getProperty("sy.public.log-config.print-response", Boolean.class, false); |
||||
|
} |
||||
|
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,25 @@ |
|||||
|
package com.kms.web.utils; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
/** |
||||
|
* @ClassName: WaterResultV2 |
||||
|
* @Description: TODO |
||||
|
* @Date: 2024/6/1 上午12:27 |
||||
|
* * |
||||
|
* @author: hxh |
||||
|
* @version: 1.0 |
||||
|
*/ |
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
public class WaterResultV2<T> { |
||||
|
private int code; |
||||
|
private String message; |
||||
|
private Boolean success; |
||||
|
private T data; |
||||
|
private String timestamp; |
||||
|
|
||||
|
} |
@ -0,0 +1,63 @@ |
|||||
|
package com.kms.yxgh.base.domain.df; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.kms.yxgh.base.SyBaseEntity; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@TableName("dws_rel_disc_dike") |
||||
|
@Data |
||||
|
@ApiModel("堤段所属堤防对象关系表") |
||||
|
public class DfDwsRelDiscDike extends SyBaseEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 堤段代码 |
||||
|
*/ |
||||
|
@ApiModelProperty("堤段代码") |
||||
|
@TableField("DISC_CODE") |
||||
|
private String discCode; |
||||
|
|
||||
|
/** |
||||
|
* 堤段名称 |
||||
|
*/ |
||||
|
@ApiModelProperty("堤段名称") |
||||
|
@TableField("DISC_NAME") |
||||
|
private String discName; |
||||
|
|
||||
|
/** |
||||
|
* 堤防代码 |
||||
|
*/ |
||||
|
@ApiModelProperty("堤防代码") |
||||
|
@TableField("DIKE_CODE") |
||||
|
private String dikeCode; |
||||
|
|
||||
|
/** |
||||
|
* 堤防名称 |
||||
|
*/ |
||||
|
@ApiModelProperty("堤防名称") |
||||
|
@TableField("DIKE_NAME") |
||||
|
private String dikeName; |
||||
|
|
||||
|
/** |
||||
|
* 关系建立时间 |
||||
|
*/ |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@ApiModelProperty("关系建立时间") |
||||
|
@TableField("FROM_DATE") |
||||
|
private Date fromDate; |
||||
|
|
||||
|
/** |
||||
|
* 关系终止时间 |
||||
|
*/ |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@ApiModelProperty("关系终止时间") |
||||
|
@TableField("TO_DATE") |
||||
|
private Date toDate; |
||||
|
} |
Loading…
Reference in new issue