Commit d2c90297 by Suvalue

接口入参拦截器

parent 51669d17
package com.bsoft.api.common.aspect;
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.slf4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
@Aspect
@Component
@Order(2)
@Profile({"test","prod"})
public class RequestMappingAspect {
@Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)")
public void getMappingAspect(){}
@Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
public void postMappingAspect(){}
@Around("getMappingAspect()")
public Object get(ProceedingJoinPoint joinPoint) throws Throwable {
return request(joinPoint);
}
@Around("postMappingAspect()")
public Object post(ProceedingJoinPoint joinPoint) throws Throwable {
return request(joinPoint);
}
private Object request(ProceedingJoinPoint joinPoint) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Logger logger = org.slf4j.LoggerFactory.getLogger(joinPoint.getTarget().getClass());
Object result = joinPoint.proceed();
String uri = request.getRequestURI();
Object[] params = joinPoint.getArgs();
List<Object> paramsList = Arrays.asList(params);
logger.debug("URL:" + uri + "入参参数:" + paramsList+"返回结果:"+result);
return result;
}
}
package com.bsoft.api.common.configurations; package com.bsoft.api.common.configurations;
import com.bsoft.api.common.intercepters.LoginIntercepter; import com.bsoft.api.common.intercepters.LoginInterceptor;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -38,7 +38,7 @@ public class LoginConfigure implements WebMvcConfigurer { ...@@ -38,7 +38,7 @@ public class LoginConfigure implements WebMvcConfigurer {
} }
@Bean @Bean
public LoginIntercepter loginIntercepter(){ public LoginInterceptor loginIntercepter(){
return new LoginIntercepter(); return new LoginInterceptor();
} }
} }
...@@ -12,11 +12,11 @@ import javax.servlet.http.HttpServletResponse; ...@@ -12,11 +12,11 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
public class LoginIntercepter implements HandlerInterceptor { public class LoginInterceptor implements HandlerInterceptor {
Logger logger = org.slf4j.LoggerFactory.getLogger(LoginIntercepter.class); Logger logger = org.slf4j.LoggerFactory.getLogger(LoginInterceptor.class);
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("LoginIntercepter----------->preHandle"); System.out.println("LoginInterceptor----------->preHandle");
String token = request.getHeader(Constants.TOKEN_KEY); String token = request.getHeader(Constants.TOKEN_KEY);
if(!TokenUtil.checkToken(token)){ if(!TokenUtil.checkToken(token)){
...@@ -45,7 +45,7 @@ public class LoginIntercepter implements HandlerInterceptor { ...@@ -45,7 +45,7 @@ public class LoginIntercepter implements HandlerInterceptor {
@Override @Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
System.out.println("LoginIntercepter----------->postHandle"); System.out.println("LoginInterceptor----------->postHandle");
...@@ -55,7 +55,7 @@ public class LoginIntercepter implements HandlerInterceptor { ...@@ -55,7 +55,7 @@ public class LoginIntercepter implements HandlerInterceptor {
@Override @Override
public void afterCompletion(HttpServletRequest request, public void afterCompletion(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) throws Exception { HttpServletResponse response, Object handler, Exception ex) throws Exception {
System.out.println("LoginIntercepter------->afterCompletion"); System.out.println("LoginInterceptor------->afterCompletion");
HandlerInterceptor.super.afterCompletion(request, response, handler, ex); HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
......
...@@ -43,6 +43,10 @@ public class TokenUtil { ...@@ -43,6 +43,10 @@ public class TokenUtil {
*/ */
public static boolean checkToken(String token){ public static boolean checkToken(String token){
SysUser user = (SysUser) RedisUtil.get(token); SysUser user = (SysUser) RedisUtil.get(token);
return user != null && JWTUtil.verifier(token, user.getPassword()); boolean result = user != null && JWTUtil.verifier(token, user.getPassword());
if(result){
RedisUtil.expire(token,TOKEN_TIME_OUT);
}
return result;
} }
} }
...@@ -3,9 +3,11 @@ package com.bsoft.api.controller; ...@@ -3,9 +3,11 @@ package com.bsoft.api.controller;
import com.bsoft.api.common.Result; import com.bsoft.api.common.Result;
import com.bsoft.api.common.annotations.Token; import com.bsoft.api.common.annotations.Token;
import com.bsoft.api.common.handlers.GlobalExceptionHandler; import com.bsoft.api.common.handlers.GlobalExceptionHandler;
import com.bsoft.api.model.reqmodel.ExportReq;
import com.bsoft.api.service.ExcelService; import com.bsoft.api.service.ExcelService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -26,12 +28,11 @@ public class ExcelController { ...@@ -26,12 +28,11 @@ public class ExcelController {
@PostMapping("export") @PostMapping("export")
@Token @Token
@ApiOperation("将Table转换为Xls") @ApiOperation("将Table转换为Xls")
public Object tableToXls(HttpServletRequest request,@RequestBody String tableStr){ public Object tableToXls(HttpServletRequest request,@RequestBody ExportReq info){
String tableStr =StringEscapeUtils.unescapeHtml4(info.getTabaleStr());
log.info("table参数:"+tableStr); log.info("table参数:"+tableStr);
String realPath = request.getSession().getServletContext().getRealPath("/"); String realPath = request.getSession().getServletContext().getRealPath("/");
String fileUrl =excelService.tableToXls(realPath,tableStr); String fileUrl =excelService.tableToXls(realPath,tableStr);
return Result.success(fileUrl); return Result.success(fileUrl);
} }
} }
...@@ -7,7 +7,17 @@ import javax.validation.constraints.NotNull; ...@@ -7,7 +7,17 @@ import javax.validation.constraints.NotNull;
@ApiModel(description = "调用blockValues请求的数据") @ApiModel(description = "调用blockValues请求的数据")
public class BlockValues { public class BlockValues {
@ApiModelProperty(value = "pageCode",required = true)
private Integer pageCode;
@ApiModelProperty("病组")
private Integer disease;
@ApiModelProperty("科室")
private Integer department;
@ApiModelProperty("医生")
private Integer doctor;
@ApiModelProperty("时间")
@NotNull(message = "time 参数必传")
private Integer time;
public Integer getPageCode() { public Integer getPageCode() {
return pageCode; return pageCode;
...@@ -49,15 +59,14 @@ public class BlockValues { ...@@ -49,15 +59,14 @@ public class BlockValues {
this.time = time; this.time = time;
} }
@ApiModelProperty(value = "pageCode",required = true) @Override
private Integer pageCode; public String toString() {
@ApiModelProperty("病组") return "BlockValues{" +
private Integer disease; "pageCode=" + pageCode +
@ApiModelProperty("科室") ", disease=" + disease +
private Integer department; ", department=" + department +
@ApiModelProperty("医生") ", doctor=" + doctor +
private Integer doctor; ", time=" + time +
@ApiModelProperty("时间") '}';
@NotNull(message = "time 参数必传") }
private Integer time;
} }
...@@ -27,4 +27,12 @@ public class BlockValuesNew { ...@@ -27,4 +27,12 @@ public class BlockValuesNew {
public void setDim(Map<String, String> dim) { public void setDim(Map<String, String> dim) {
this.dim = dim; this.dim = dim;
} }
@Override
public String toString() {
return "BlockValuesNew{" +
"pageCode=" + pageCode +
", dim=" + dim +
'}';
}
} }
...@@ -29,4 +29,12 @@ public class CodeAndPwd { ...@@ -29,4 +29,12 @@ public class CodeAndPwd {
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
@Override
public String toString() {
return "CodeAndPwd{" +
"loginName='" + loginName + '\'' +
", password='" + password + '\'' +
'}';
}
} }
...@@ -62,6 +62,17 @@ public class Disease { ...@@ -62,6 +62,17 @@ public class Disease {
public void setDept(String dept) { public void setDept(String dept) {
this.dept = dept; this.dept = dept;
} }
@Override
public String toString() {
return "DiseaseIDorLevel{" +
"date='" + date + '\'' +
", disease='" + disease + '\'' +
", level=" + level +
", doctor='" + doctor + '\'' +
", dept='" + dept + '\'' +
'}';
}
} }
/** /**
...@@ -90,6 +101,14 @@ public class Disease { ...@@ -90,6 +101,14 @@ public class Disease {
public void setMdcName(String mdcName) { public void setMdcName(String mdcName) {
this.mdcName = mdcName; this.mdcName = mdcName;
} }
@Override
public String toString() {
return "DiseaseName{" +
"date='" + date + '\'' +
", mdcName='" + mdcName + '\'' +
'}';
}
} }
} }
......
...@@ -53,4 +53,13 @@ public class DiseaseDoc { ...@@ -53,4 +53,13 @@ public class DiseaseDoc {
this.deptCode = deptCode; this.deptCode = deptCode;
} }
@Override
public String toString() {
return "DiseaseDoc{" +
"docCode='" + docCode + '\'' +
", mdcCode='" + mdcCode + '\'' +
", deptCode='" + deptCode + '\'' +
", date='" + date + '\'' +
'}';
}
} }
package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModelProperty;
public class ExportReq {
@ApiModelProperty("Table Html")
private String tableStr;
public String getTabaleStr() {
return tableStr;
}
public void setTableStr(String tableStr) {
this.tableStr = tableStr;
}
@Override
public String toString() {
return "ExportReq{" +
"tableStr='" + tableStr + '\'' +
'}';
}
}
...@@ -38,4 +38,13 @@ public class ReqDimValue { ...@@ -38,4 +38,13 @@ public class ReqDimValue {
public void setDate(String date) { public void setDate(String date) {
this.date = date; this.date = date;
} }
@Override
public String toString() {
return "ReqDimValue{" +
"pageCode='" + pageCode + '\'' +
", orgId=" + orgId +
", date='" + date + '\'' +
'}';
}
} }
...@@ -29,4 +29,12 @@ public class BlockValue { ...@@ -29,4 +29,12 @@ public class BlockValue {
public void setBody(List<Map<String, Object>> body) { public void setBody(List<Map<String, Object>> body) {
this.body = body; this.body = body;
} }
@Override
public String toString() {
return "BlockValue{" +
"blockId=" + blockId +
", body=" + body +
'}';
}
} }
...@@ -26,4 +26,12 @@ public class DimValue { ...@@ -26,4 +26,12 @@ public class DimValue {
public void setDimValues(List<SerDimValue> dimValues) { public void setDimValues(List<SerDimValue> dimValues) {
this.dimValues = dimValues; this.dimValues = dimValues;
} }
@Override
public String toString() {
return "DimValue{" +
"dicDim=" + dicDim +
", dimValues=" + dimValues +
'}';
}
} }
...@@ -96,5 +96,19 @@ public class DiseaseLevel { ...@@ -96,5 +96,19 @@ public class DiseaseLevel {
this.diseaseLevelList = diseaseLevelList; this.diseaseLevelList = diseaseLevelList;
} }
@Override
public String toString() {
return "DiseaseLevel{" +
"id=" + id +
", mdcCode='" + mdcCode + '\'' +
", mdcName='" + mdcName + '\'' +
", date=" + date +
", mdcNum=" + mdcNum +
", parentId=" + parentId +
", level=" + level +
", orgId=" + orgId +
", orgName='" + orgName + '\'' +
", diseaseLevelList=" + diseaseLevelList +
'}';
}
} }
...@@ -65,4 +65,15 @@ public class ListPage<T> { ...@@ -65,4 +65,15 @@ public class ListPage<T> {
public void setListData(List<T> listData) { public void setListData(List<T> listData) {
this.listData = listData; this.listData = listData;
} }
@Override
public String toString() {
return "ListPage{" +
"totalCount=" + totalCount +
", totalPageCount=" + totalPageCount +
", curPageIndex=" + curPageIndex +
", pageSize=" + pageSize +
", listData=" + listData +
'}';
}
} }
...@@ -15,6 +15,13 @@ public class SysMenuList extends SysMenu { ...@@ -15,6 +15,13 @@ public class SysMenuList extends SysMenu {
public List<SysMenuList> getSysMenuList() { public List<SysMenuList> getSysMenuList() {
return this.sysMenuList; return this.sysMenuList;
} }
@Override
public String toString() {
return "SysMenuList{" +
"sysMenuList=" + sysMenuList +
'}';
}
} }
...@@ -58,5 +58,14 @@ public interface LoginService { ...@@ -58,5 +58,14 @@ public interface LoginService {
public void setOrg(List<DicOrg> org) { public void setOrg(List<DicOrg> org) {
this.org = org; this.org = org;
} }
@Override
public String toString() {
return "LoginInfo{" +
"token='" + token + '\'' +
", user=" + user +
", org=" + org +
'}';
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment