content: package com.platform.common.aspectj;
  
  import com.platform.common.aspectj.lang.annotation.DataScope;
  import org.aspectj.lang.JoinPoint;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Before;
  import org.springframework.stereotype.Component;
  import com.platform.common.utils.StringUtils;
  import com.platform.common.web.domain.BaseEntity;
  
  /**
   * 数据过滤处理
   * 
   * @author AllDataDC
   */
  @Aspect
  @Component
  public class DataScopeAspect
  {
      /**
       * 全部数据权限
       */
      public static final String DATA_SCOPE_ALL = "1";
  
      /**
       * 自定数据权限
       */
      public static final String DATA_SCOPE_CUSTOM = "2";
  
      /**
       * 部门数据权限
       */
      public static final String DATA_SCOPE_DEPT = "3";
  
      /**
       * 部门及以下数据权限
       */
      public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
  
      /**
       * 仅本人数据权限
       */
      public static final String DATA_SCOPE_SELF = "5";
  
      /**
       * 数据权限过滤关键字
       */
      public static final String DATA_SCOPE = "dataScope";
  
      @Before("@annotation(controllerDataScope)")
      public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable
      {
          clearDataScope(point);
          handleDataScope(point, controllerDataScope);
      }
  
      protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope) {}
  
  
      /**
       * 拼接权限sql前先清空params.dataScope参数防止注入
       */
      private void clearDataScope(final JoinPoint joinPoint)
      {
          Object params = joinPoint.getArgs()[0];
          if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
          {
              BaseEntity baseEntity = (BaseEntity) params;
              baseEntity.getParams().put(DATA_SCOPE, "");
          }
      }
  }
  