Commit 85c69978 authored by wujiang's avatar wujiang

修改aop代码问题

parent 1eba123e
...@@ -43,8 +43,8 @@ import com.yeejoin.amos.feign.systemctl.Systemctl; ...@@ -43,8 +43,8 @@ import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel; import com.yeejoin.amos.feign.systemctl.model.RegionModel;
/** /**
* controller层切面 用于用户数据缓存 供 sql自动填充使用 * controller层切面 用于用户数据缓存 供 sql自动填充使用 (使用粒度过大的Aop会创建大量代理对象,影响性能,占用内存,考虑使用
* (使用粒度过大的Aop会创建大量代理对象,影响性能,占用内存,考虑使用 WebMvcConfigurer#addInterceptors 添加拦截器 ) * WebMvcConfigurer#addInterceptors 添加拦截器 )
* *
* @author Admin * @author Admin
*/ */
...@@ -65,7 +65,7 @@ public class ControllerAop { ...@@ -65,7 +65,7 @@ public class ControllerAop {
+ "|| execution(public * com.yeejoin.amos.*.business.controller..*(..))" + "|| execution(public * com.yeejoin.amos.*.business.controller..*(..))"
+ " && !@annotation(org.springframework.scheduling.annotation.Scheduled))" + " && !@annotation(org.springframework.scheduling.annotation.Scheduled))"
+ "|| execution(public * com.yeejoin.equipmanage.controller..*.*(..))" + "|| execution(public * com.yeejoin.equipmanage.controller..*.*(..))"
+ "||execution(public * com.yeejoin.amos.api.openapi.controller..*(..))") + "|| execution(public * com.yeejoin.amos.api.openapi.controller..*(..))")
public void userCache() { public void userCache() {
} }
...@@ -75,28 +75,31 @@ public class ControllerAop { ...@@ -75,28 +75,31 @@ public class ControllerAop {
PermissionInterceptorContext.clean(); PermissionInterceptorContext.clean();
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = null; HttpServletRequest request = null;
if(ObjectUtils.isNotEmpty(attributes)){ if (ObjectUtils.isNotEmpty(attributes)) {
request = attributes.getRequest(); request = attributes.getRequest();
} else { } else {
return; return;
} }
// 不需要添加请求头的接口 // 不需要添加请求头的接口
String[] url = new String[]{"/api/user/save/curCompany", "/jcs/command/lookHtmlText", String[] url = new String[] { "/api/user/save/curCompany", "/jcs/command/lookHtmlText",
"/jcs/common/duty-person/findByDutyAreaId", "/tzs/wechatBack", "/tzs/elevator/getElevatorInfo", "/jcs/common/duty-person/findByDutyAreaId", "/tzs/wechatBack", "/tzs/elevator/getElevatorInfo",
"/openapi/bizToken/applyToken"}; "/openapi/bizToken/applyToken", "/tzs/reg-unit-info/management-unit/tree",
"/tzs/flc-unit-info/region/tree", "/tzs/reg-unit-info/unit-type/list" };
// 获取请求路径 // 获取请求路径
for (String uri : url) { for (String uri : url) {
if (request.getRequestURI().indexOf(uri) != -1) { if (request.getRequestURI().indexOf(uri) != -1) {
return; return;
} }
} }
//TODO tyboot 框架拦截器已缓存数据 // TODO tyboot 框架拦截器已缓存数据
String token = RequestContext.getToken(); String token = RequestContext.getToken();
// 不需要校验token的接口直接返回 // 不需要校验token的接口直接返回
if (joinPoint.getSignature() instanceof MethodSignature) { if (joinPoint.getSignature() instanceof MethodSignature) {
if (!((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(TycloudOperation.class).needAuth() && !request.getParameterMap().containsKey("token") && ValidationUtil.isEmpty(token)) {
return; return;
} }
}
// 平台studio配置的下载接口token从url里取 // 平台studio配置的下载接口token从url里取
if (ValidationUtil.isEmpty(token)) { if (ValidationUtil.isEmpty(token)) {
...@@ -105,7 +108,7 @@ public class ControllerAop { ...@@ -105,7 +108,7 @@ public class ControllerAop {
} }
if (token != null) { if (token != null) {
String pattern = RedisKey.buildPatternKey(token); String pattern = RedisKey.buildPatternKey(token);
//验证token有效性,防止token失效 // 验证token有效性,防止token失效
AgencyUserModel userModel; AgencyUserModel userModel;
try { try {
FeignClientResult<AgencyUserModel> agencyUserModel = Privilege.agencyUserClient.getme(); FeignClientResult<AgencyUserModel> agencyUserModel = Privilege.agencyUserClient.getme();
...@@ -115,7 +118,7 @@ public class ControllerAop { ...@@ -115,7 +118,7 @@ public class ControllerAop {
} }
RequestContext.setExeUserId(userModel.getUserId()); RequestContext.setExeUserId(userModel.getUserId());
} catch (Exception e) { } catch (Exception e) {
//删除失效token缓存 // 删除失效token缓存
redisUtils.getAndDeletePatternKeys(pattern); redisUtils.getAndDeletePatternKeys(pattern);
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} }
...@@ -133,12 +136,12 @@ public class ControllerAop { ...@@ -133,12 +136,12 @@ public class ControllerAop {
CompanyBo company = new CompanyBo(); CompanyBo company = new CompanyBo();
DepartmentBo department = new DepartmentBo(); DepartmentBo department = new DepartmentBo();
RoleBo role = new RoleBo(); RoleBo role = new RoleBo();
//平台更新 人员部门可能为NULL 导致redis缓存不到人员信息 // 平台更新 人员部门可能为NULL 导致redis缓存不到人员信息
Map<Long, List<DepartmentModel>> mapDepartments = new HashMap<>(); Map<Long, List<DepartmentModel>> mapDepartments = new HashMap<>();
DepartmentModel departmentM = new DepartmentModel(); DepartmentModel departmentM = new DepartmentModel();
CompanyModel companyM = user.getCompanys() != null ? user.getCompanys().get(0) : null; CompanyModel companyM = user.getCompanys() != null ? user.getCompanys().get(0) : null;
Bean.copyExistPropertis(companyM, company); Bean.copyExistPropertis(companyM, company);
if (!ValidationUtil.isEmpty(user.getCompanyDepartments())){ if (!ValidationUtil.isEmpty(user.getCompanyDepartments())) {
mapDepartments = user.getCompanyDepartments(); mapDepartments = user.getCompanyDepartments();
departmentM = companyM != null ? mapDepartments.get(companyM.getSequenceNbr()).get(0) : null; departmentM = companyM != null ? mapDepartments.get(companyM.getSequenceNbr()).get(0) : null;
} }
...@@ -156,9 +159,9 @@ public class ControllerAop { ...@@ -156,9 +159,9 @@ public class ControllerAop {
} else { } else {
roleM = roles.get(sequenceNbr).get(0); roleM = roles.get(sequenceNbr).get(0);
} }
if(companyM!=null&&companyM.getRegionSeq()!=null) if (companyM != null && companyM.getRegionSeq() != null) {
{ FeignClientResult<RegionModel> result = Systemctl.regionClient
FeignClientResult<RegionModel> result = Systemctl.regionClient.getRegion(Long.valueOf(companyM.getRegionSeq())); .getRegion(Long.valueOf(companyM.getRegionSeq()));
company.setRegionCode(String.valueOf(result.getResult().getRegionCode())); company.setRegionCode(String.valueOf(result.getResult().getRegionCode()));
} }
Bean.copyExistPropertis(roleM, role); Bean.copyExistPropertis(roleM, role);
...@@ -172,7 +175,7 @@ public class ControllerAop { ...@@ -172,7 +175,7 @@ public class ControllerAop {
@AfterReturning(returning = "ret", pointcut = "userCache()") @AfterReturning(returning = "ret", pointcut = "userCache()")
public void doAfterReturning(Object ret) throws Throwable { public void doAfterReturning(Object ret) throws Throwable {
//统一redis管理 // 统一redis管理
// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpServletRequest request = attributes.getRequest(); // HttpServletRequest request = attributes.getRequest();
// String token = request.getHeader("token"); // String token = request.getHeader("token");
...@@ -182,11 +185,19 @@ public class ControllerAop { ...@@ -182,11 +185,19 @@ public class ControllerAop {
} }
private void fillRequestContext(HttpServletRequest request) { private void fillRequestContext(HttpServletRequest request) {
String token = request.getParameterMap().get("token")[0]; String token = null;
String product = request.getParameterMap().get("product")[0]; String product = null;
String appKey = request.getParameterMap().get("appKey")[0]; String appKey = null;
if (request != null && request.getParameterMap() != null) {
if (request.getParameterMap().get("token") != null && request.getParameterMap().get("product") != null
&& request.getParameterMap().get("appKey") != null) {
token = request.getParameterMap().get("token")[0];
product = request.getParameterMap().get("product")[0];
appKey = request.getParameterMap().get("appKey")[0];
RequestContext.setToken(token); RequestContext.setToken(token);
RequestContext.setProduct(product); RequestContext.setProduct(product);
RequestContext.setAppKey(appKey); RequestContext.setAppKey(appKey);
} }
}
}
} }
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