#taskUser读 taskuser.read=0 #taskUser写 taskuser.write=1 #taskUserData读 taskuserdata.read=1 #taskUserData写 taskuserdata.write=1
@Aspect @Component public class TaskUserDaoMapperAspect { private static final Logger logger = LoggerFactory.getLogger(TaskUserDaoMapperAspect.class); private static final List<String> readList = Lists.newArrayList("find", "poll"); private static final List<String> writeList = Lists.newArrayList("insert", "update"); @Resource private TaskUserDataMapper taskUserDataMapper; @Resource private ConfigService configService; @Around("execution(* cn.hello.dal.mapper.TaskUserMapper.*(..))") public Object around(ProceedingJoinPoint pjp) { Object result = null; try { String methodName = pjp.getSignature().getName(); logger.info("TaskUserMapper {} {} invoked", methodName, pjp.getArgs()); if(readList.contains(methodName)){ if(configService.isReadTaskUser()){ result = pjp.proceed(); } else if(configService.isReadTaskUserData()){ result = invokeTaskUserDaoMapper(pjp); } } else if(writeList.contains(methodName)){ if(configService.isWriteTaskUser()){ result = pjp.proceed(); } if(configService.isWriteTaskUserData()){ result = invokeTaskUserDaoMapper(pjp); } } else { logger.error("unknown TaskUserMapper method {}", methodName); result = pjp.proceed(); } } catch (OctopusException e) { throw e; } catch (Throwable e) { logger.error("failed@AroundDaoAspect.around", e); throw new DalException("DAL ERROR", e); } return result; } private Object invokeTaskUserDaoMapper(ProceedingJoinPoint pjp) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { String methodName = pjp.getSignature().getName(); Class[] parameterTypes = ((MethodSignature)pjp.getSignature()).getMethod().getParameterTypes(); Method method = TaskUserDataMapper.class.getMethod(methodName, parameterTypes); Object result = method.invoke(taskUserDataMapper, pjp.getArgs()); return result; } }