/* */ package com.archive.framework.aspectj
;
/* */
/* */ import com.archive.common.utils.StringUtils ;
/* */ import com.archive.common.utils.security.ShiroUtils ;
/* */ import com.archive.framework.aspectj.lang.annotation.DataScope ;
/* */ import com.archive.framework.web.domain.BaseEntity ;
/* */ import com.archive.project.system.role.domain.Role ;
/* */ import com.archive.project.system.user.domain.User ;
/* */ import java.lang.reflect.Method ;
/* */ import org.aspectj.lang.JoinPoint ;
/* */ import org.aspectj.lang.Signature ;
/* */ import org.aspectj.lang.annotation.Aspect ;
/* */ import org.aspectj.lang.annotation.Before ;
/* */ import org.aspectj.lang.annotation.Pointcut ;
/* */ import org.aspectj.lang.reflect.MethodSignature ;
/* */ import org.springframework.stereotype.Component ;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ @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" ;
/* */
/* */ @Pointcut ( "@annotation(com.archive.framework.aspectj.lang.annotation.DataScope)" )
/* */ public void dataScopePointCut ( ) { }
/* */
/* */ @Before ( "dataScopePointCut()" )
/* */ public void doBefore ( JoinPoint point ) throws Throwable {
/* 66 */ handleDataScope ( point ) ;
/* */ }
/* */
/* */
/* */
/* */ protected void handleDataScope ( JoinPoint joinPoint ) {
/* 72 */ DataScope controllerDataScope = getAnnotationLog ( joinPoint ) ;
/* 73 */ if ( controllerDataScope = = null ) {
/* */ return ;
/* */ }
/* */
/* */
/* 78 */ User currentUser = ShiroUtils . getSysUser ( ) ;
/* 79 */ if ( currentUser ! = null )
/* */ {
/* */
/* 82 */ if ( ! currentUser . isAdmin ( ) )
/* */ {
/* 84 */ dataScopeFilter ( joinPoint , currentUser , controllerDataScope . deptAlias ( ) , controllerDataScope
/* 85 */ . userAlias ( ) ) ;
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public static void dataScopeFilter ( JoinPoint joinPoint , User user , String deptAlias , String userAlias ) {
/* 100 */ StringBuilder sqlString = new StringBuilder ( ) ;
/* */
/* 102 */ for ( Role role : user . getRoles ( ) ) {
/* */
/* 104 */ String dataScope = role . getDataScope ( ) ;
/* 105 */ if ( "1" . equals ( dataScope ) ) {
/* */
/* 107 */ sqlString = new StringBuilder ( ) ;
/* */ break ;
/* */ }
/* 110 */ if ( "2" . equals ( dataScope ) ) {
/* */
/* 112 */ sqlString . append ( StringUtils . format ( " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) " , new Object [ ] { deptAlias , role
/* */
/* 114 */ . getRoleId ( ) } ) ) ; continue ;
/* */ }
/* 116 */ if ( "3" . equals ( dataScope ) ) {
/* */
/* 118 */ sqlString . append ( StringUtils . format ( " OR {}.dept_id = {} " , new Object [ ] { deptAlias , user . getDeptId ( ) } ) ) ; continue ;
/* */ }
/* 120 */ if ( "4" . equals ( dataScope ) ) {
/* */
/* 122 */ sqlString . append ( StringUtils . format ( " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )" , new Object [ ] { deptAlias , user
/* */
/* 124 */ . getDeptId ( ) , user . getDeptId ( ) } ) ) ; continue ;
/* */ }
/* 126 */ if ( "5" . equals ( dataScope ) ) {
/* */
/* 128 */ if ( StringUtils . isNotBlank ( userAlias ) ) {
/* */
/* 130 */ sqlString . append ( StringUtils . format ( " OR {}.user_id = {} " , new Object [ ] { userAlias , user . getUserId ( ) } ) ) ;
/* */
/* */ continue ;
/* */ }
/* */
/* 135 */ sqlString . append ( " OR 1=0 " ) ;
/* */ }
/* */ }
/* */
/* */
/* 140 */ if ( StringUtils . isNotBlank ( sqlString . toString ( ) ) ) {
/* */
/* 142 */ Object params = joinPoint . getArgs ( ) [ 0 ] ;
/* 143 */ if ( StringUtils . isNotNull ( params ) & & params instanceof BaseEntity ) {
/* */
/* 145 */ BaseEntity baseEntity = ( BaseEntity ) params ;
/* 146 */ baseEntity . getParams ( ) . put ( "dataScope" , " AND (" + sqlString . substring ( 4 ) + ")" ) ;
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ private DataScope getAnnotationLog ( JoinPoint joinPoint ) {
/* 156 */ Signature signature = joinPoint . getSignature ( ) ;
/* 157 */ MethodSignature methodSignature = ( MethodSignature ) signature ;
/* 158 */ Method method = methodSignature . getMethod ( ) ;
/* */
/* 160 */ if ( method ! = null )
/* */ {
/* 162 */ return method . < DataScope > getAnnotation ( DataScope . class ) ;
/* */ }
/* 164 */ return null ;
/* */ }
/* */ }
/ * Location : C : \ Users \ Administrator \ Desktop \ extracted . zip ! \ extracted \ BOOT - INF \ classes \ com \ archive \ framework \ aspectj \ DataScopeAspect . class
* Java compiler version : 8 ( 52.0 )
* JD - Core Version : 1.1 .3
* /