Commit 85c69978 authored by wujiang's avatar wujiang

修改aop代码问题

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