Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
datax-cloud
Commits
04cdf60d
Commit
04cdf60d
authored
Nov 27, 2019
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
5554970f
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
203 additions
and
43 deletions
+203
-43
BaseDao.java
...mmon-core/src/main/java/cn/datax/common/base/BaseDao.java
+8
-0
BaseQueryParams.java
...e/src/main/java/cn/datax/common/base/BaseQueryParams.java
+2
-2
BaseServiceImpl.java
...e/src/main/java/cn/datax/common/base/BaseServiceImpl.java
+1
-1
DataScope.java
...on-core/src/main/java/cn/datax/common/base/DataScope.java
+6
-6
DataScopeAop.java
...java/cn/datax/common/mybatis/annotation/DataScopeAop.java
+9
-0
DataScopeAspect.java
...java/cn/datax/common/mybatis/aspectj/DataScopeAspect.java
+19
-13
DataBatisPlusConfig.java
...a/cn/datax/common/mybatis/config/DataBatisPlusConfig.java
+10
-0
DataLogicSqlInjector.java
...n/datax/common/mybatis/injector/DataLogicSqlInjector.java
+27
-0
SelectListDataScope.java
.../common/mybatis/injector/methods/SelectListDataScope.java
+21
-0
SelectPageDataScope.java
.../common/mybatis/injector/methods/SelectPageDataScope.java
+21
-0
DataScopeInterceptor.java
...atax/common/mybatis/interceptor/DataScopeInterceptor.java
+21
-21
TestController.java
...va/cn/datax/service/system/controller/TestController.java
+43
-0
UserService.java
...ain/java/cn/datax/service/system/service/UserService.java
+7
-0
UserServiceImpl.java
...cn/datax/service/system/service/impl/UserServiceImpl.java
+8
-0
No files found.
datax-common/datax-common-core/src/main/java/cn/datax/common/base/BaseDao.java
View file @
04cdf60d
package
cn
.
datax
.
common
.
base
;
package
cn
.
datax
.
common
.
base
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
BaseDao
<
T
>
extends
BaseMapper
<
T
>
{
public
interface
BaseDao
<
T
>
extends
BaseMapper
<
T
>
{
List
<
T
>
selectListDataScope
(
@Param
(
"ew"
)
Wrapper
<
T
>
queryWrapper
,
@Param
(
"dataScope"
)
DataScope
dataScope
);
IPage
<
T
>
selectPageDataScope
(
IPage
<
T
>
page
,
@Param
(
"ew"
)
Wrapper
<
T
>
queryWrapper
,
@Param
(
"dataScope"
)
DataScope
dataScope
);
}
}
datax-common/datax-common-core/src/main/java/cn/datax/common/base/BaseQueryParams.java
View file @
04cdf60d
...
@@ -11,9 +11,9 @@ public class BaseQueryParams implements Serializable {
...
@@ -11,9 +11,9 @@ public class BaseQueryParams implements Serializable {
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
// 当前页码
// 当前页码
private
Integer
pageNum
;
private
Integer
pageNum
=
1
;
// 分页条数
// 分页条数
private
Integer
pageSize
;
private
Integer
pageSize
=
20
;
// 显示字段
// 显示字段
private
List
<
String
>
columnList
;
private
List
<
String
>
columnList
;
// 排序
// 排序
...
...
datax-common/datax-common-core/src/main/java/cn/datax/common/base/BaseServiceImpl.java
View file @
04cdf60d
...
@@ -6,5 +6,5 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -6,5 +6,5 @@ import org.springframework.beans.factory.annotation.Autowired;
public
abstract
class
BaseServiceImpl
<
M
extends
BaseDao
<
T
>,
T
>
extends
ServiceImpl
<
M
,
T
>
implements
BaseService
<
T
>
{
public
abstract
class
BaseServiceImpl
<
M
extends
BaseDao
<
T
>,
T
>
extends
ServiceImpl
<
M
,
T
>
implements
BaseService
<
T
>
{
@Autowired
@Autowired
protected
M
B
aseDao
;
protected
M
b
aseDao
;
}
}
datax-common/datax-common-
mybatis/src/main/java/cn/datax/common/mybatis/annotation
/DataScope.java
→
datax-common/datax-common-
core/src/main/java/cn/datax/common/base
/DataScope.java
View file @
04cdf60d
package
cn
.
datax
.
common
.
mybatis
.
annotation
;
package
cn
.
datax
.
common
.
base
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.HashMap
;
/**
/**
* 数据权限查询参数
* 数据权限查询参数
*/
*/
@Data
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
DataScope
{
public
class
DataScope
extends
HashMap
{
/**
/**
* 部门表的别名
* 部门表的别名
*/
*/
private
String
deptAlias
=
"sys_dept"
;
private
String
deptAlias
=
"sys_dept"
;
private
String
deptScopeName
=
"dept_id"
;
/**
/**
* 用户表的别名
* 用户表的别名
*/
*/
private
String
userAlias
=
"sys_user"
;
private
String
userAlias
=
"sys_user"
;
private
String
userScopeName
=
"create_by"
;
}
}
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/annotation/DataScopeAop.java
View file @
04cdf60d
...
@@ -13,12 +13,21 @@ import java.lang.annotation.*;
...
@@ -13,12 +13,21 @@ import java.lang.annotation.*;
public
@interface
DataScopeAop
{
public
@interface
DataScopeAop
{
/**
/**
* 表的别名
*/
String
alias
()
default
"sys_user"
;
/**
* 部门表的别名
* 部门表的别名
*/
*/
String
deptAlias
()
default
"sys_dept"
;
String
deptAlias
()
default
"sys_dept"
;
String
deptScopeName
()
default
"dept_id"
;
/**
/**
* 用户表的别名
* 用户表的别名
*/
*/
String
userAlias
()
default
"sys_user"
;
String
userAlias
()
default
"sys_user"
;
String
userScopeName
()
default
"create_by"
;
}
}
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/aspectj/DataScopeAspect.java
View file @
04cdf60d
...
@@ -20,7 +20,7 @@ import org.aspectj.lang.annotation.Pointcut;
...
@@ -20,7 +20,7 @@ import org.aspectj.lang.annotation.Pointcut;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.aspectj.lang.reflect.MethodSignature
;
/**
/**
* 数据过滤处理(基于注解式)
* 数据过滤处理(基于注解式
,用于自定义sql
)
*/
*/
@Slf4j
@Slf4j
@Aspect
@Aspect
...
@@ -68,27 +68,33 @@ public class DataScopeAspect {
...
@@ -68,27 +68,33 @@ public class DataScopeAspect {
break
;
break
;
}
else
if
(
DataConstant
.
DataScope
.
CUSTOM
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
CUSTOM
.
getKey
().
equals
(
roleDataScope
))
{
sqlString
.
append
(
StrUtil
.
format
(
sqlString
.
append
(
StrUtil
.
format
(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
,
" OR ( SELECT dept_id FROM sys_user_dept WHERE user_id = {}.{} ) IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
dataScope
.
deptAlias
()
,
dataScope
.
alias
()
,
role
.
getId
()
,
dataScope
.
userScopeName
()
,
"'"
+
role
.
getId
()
+
"'"
));
));
}
else
if
(
DataConstant
.
DataScope
.
DEPT
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
DEPT
.
getKey
().
equals
(
roleDataScope
))
{
sqlString
.
append
(
StrUtil
.
format
(
sqlString
.
append
(
StrUtil
.
format
(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) "
,
" OR ( SELECT dept_id FROM sys_user_dept WHERE user_id = {}.{} ) IN ( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) "
dataScope
.
deptAlias
()
,
dataScope
.
alias
()
,
user
.
getId
()
,
dataScope
.
userScopeName
()
,
"'"
+
user
.
getId
()
+
"'"
));
));
}
else
if
(
DataConstant
.
DataScope
.
DEPTANDCHILD
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
DEPTANDCHILD
.
getKey
().
equals
(
roleDataScope
))
{
sqlString
.
append
(
StrUtil
.
format
(
sqlString
.
append
(
StrUtil
.
format
(
" OR {}.dept_id IN ( SELECT descendant FROM sys_dept_relation WHERE ancestor = {} )"
,
" OR ( SELECT dept_id FROM sys_user_dept WHERE user_id = {}.{} ) IN ( SELECT descendant FROM sys_dept_relation WHERE ancestor = {} )"
dataScope
.
deptAlias
()
,
dataScope
.
alias
()
,
role
.
getId
()
,
dataScope
.
userScopeName
()
,
"'"
+
role
.
getId
()
+
"'"
));
));
}
else
if
(
DataConstant
.
DataScope
.
SELF
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
SELF
.
getKey
().
equals
(
roleDataScope
))
{
if
(
StrUtil
.
isNotBlank
(
dataScope
.
userAlias
()))
{
if
(
StrUtil
.
isNotBlank
(
dataScope
.
alias
()))
{
sqlString
.
append
(
StrUtil
.
format
(
" OR {}.user_id = {} "
,
dataScope
.
userAlias
(),
user
.
getId
()));
sqlString
.
append
(
StrUtil
.
format
(
" OR {}.{} = {} "
,
dataScope
.
alias
()
,
dataScope
.
userScopeName
()
,
user
.
getId
()));
}
else
{
}
else
{
// 数据权限为仅本人且没有
userA
lias别名不查询任何数据
// 数据权限为仅本人且没有
a
lias别名不查询任何数据
sqlString
.
append
(
" OR 1=0 "
);
sqlString
.
append
(
" OR 1=0 "
);
}
}
}
}
...
...
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/config/DataBatisPlusConfig.java
View file @
04cdf60d
package
cn
.
datax
.
common
.
mybatis
.
config
;
package
cn
.
datax
.
common
.
mybatis
.
config
;
import
cn.datax.common.mybatis.aspectj.DataScopeAspect
;
import
cn.datax.common.mybatis.aspectj.DataScopeAspect
;
import
cn.datax.common.mybatis.injector.DataLogicSqlInjector
;
import
cn.datax.common.mybatis.interceptor.DataScopeInterceptor
;
import
cn.datax.common.mybatis.interceptor.DataScopeInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.mybatis.spring.annotation.MapperScan
;
...
@@ -40,4 +41,13 @@ public class DataBatisPlusConfig {
...
@@ -40,4 +41,13 @@ public class DataBatisPlusConfig {
public
DataScopeAspect
dataScopeAspect
()
{
public
DataScopeAspect
dataScopeAspect
()
{
return
new
DataScopeAspect
();
return
new
DataScopeAspect
();
}
}
/**
* 自定义 SqlInjector
* 里面包含自定义的全局方法
*/
@Bean
public
DataLogicSqlInjector
myLogicSqlInjector
()
{
return
new
DataLogicSqlInjector
();
}
}
}
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/injector/DataLogicSqlInjector.java
0 → 100644
View file @
04cdf60d
package
cn
.
datax
.
common
.
mybatis
.
injector
;
import
cn.datax.common.mybatis.injector.methods.SelectListDataScope
;
import
cn.datax.common.mybatis.injector.methods.SelectPageDataScope
;
import
com.baomidou.mybatisplus.core.injector.AbstractMethod
;
import
com.baomidou.mybatisplus.core.injector.DefaultSqlInjector
;
import
java.util.List
;
/**
* 自定义 SqlInjector
*/
public
class
DataLogicSqlInjector
extends
DefaultSqlInjector
{
/**
* 如果只需增加方法,保留MP自带方法
* 可以super.getMethodList() 再add
* @return
*/
@Override
public
List
<
AbstractMethod
>
getMethodList
(
Class
<?>
mapperClass
)
{
List
<
AbstractMethod
>
methodList
=
super
.
getMethodList
(
mapperClass
);
methodList
.
add
(
new
SelectListDataScope
());
methodList
.
add
(
new
SelectPageDataScope
());
return
methodList
;
}
}
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/injector/methods/SelectListDataScope.java
0 → 100644
View file @
04cdf60d
package
cn
.
datax
.
common
.
mybatis
.
injector
.
methods
;
import
com.baomidou.mybatisplus.core.enums.SqlMethod
;
import
com.baomidou.mybatisplus.core.injector.AbstractMethod
;
import
com.baomidou.mybatisplus.core.metadata.TableInfo
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlSource
;
public
class
SelectListDataScope
extends
AbstractMethod
{
public
SelectListDataScope
()
{
}
@Override
public
MappedStatement
injectMappedStatement
(
Class
<?>
mapperClass
,
Class
<?>
modelClass
,
TableInfo
tableInfo
)
{
SqlMethod
sqlMethod
=
SqlMethod
.
SELECT_LIST
;
String
sql
=
String
.
format
(
sqlMethod
.
getSql
(),
this
.
sqlSelectColumns
(
tableInfo
,
true
),
tableInfo
.
getTableName
(),
this
.
sqlWhereEntityWrapper
(
true
,
tableInfo
),
this
.
sqlComment
());
SqlSource
sqlSource
=
this
.
languageDriver
.
createSqlSource
(
this
.
configuration
,
sql
,
modelClass
);
return
this
.
addSelectMappedStatementForTable
(
mapperClass
,
"selectListDataScope"
,
sqlSource
,
tableInfo
);
}
}
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/injector/methods/SelectPageDataScope.java
0 → 100644
View file @
04cdf60d
package
cn
.
datax
.
common
.
mybatis
.
injector
.
methods
;
import
com.baomidou.mybatisplus.core.enums.SqlMethod
;
import
com.baomidou.mybatisplus.core.injector.AbstractMethod
;
import
com.baomidou.mybatisplus.core.metadata.TableInfo
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlSource
;
public
class
SelectPageDataScope
extends
AbstractMethod
{
public
SelectPageDataScope
()
{
}
@Override
public
MappedStatement
injectMappedStatement
(
Class
<?>
mapperClass
,
Class
<?>
modelClass
,
TableInfo
tableInfo
)
{
SqlMethod
sqlMethod
=
SqlMethod
.
SELECT_PAGE
;
String
sql
=
String
.
format
(
sqlMethod
.
getSql
(),
this
.
sqlSelectColumns
(
tableInfo
,
true
),
tableInfo
.
getTableName
(),
this
.
sqlWhereEntityWrapper
(
true
,
tableInfo
),
this
.
sqlComment
());
SqlSource
sqlSource
=
this
.
languageDriver
.
createSqlSource
(
this
.
configuration
,
sql
,
modelClass
);
return
this
.
addSelectMappedStatementForTable
(
mapperClass
,
"selectPageDataScope"
,
sqlSource
,
tableInfo
);
}
}
datax-common/datax-common-mybatis/src/main/java/cn/datax/common/mybatis/interceptor/DataScopeInterceptor.java
View file @
04cdf60d
package
cn
.
datax
.
common
.
mybatis
.
interceptor
;
package
cn
.
datax
.
common
.
mybatis
.
interceptor
;
import
cn.datax.common.base.DataScope
;
import
cn.datax.common.core.DataConstant
;
import
cn.datax.common.core.DataConstant
;
import
cn.datax.common.core.DataRole
;
import
cn.datax.common.core.DataRole
;
import
cn.datax.common.core.DataUser
;
import
cn.datax.common.core.DataUser
;
import
cn.datax.common.mybatis.annotation.DataScope
;
import
cn.datax.common.utils.SecurityUtil
;
import
cn.datax.common.utils.SecurityUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
...
@@ -58,12 +58,13 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
...
@@ -58,12 +58,13 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
if
(
null
!=
currentUser
)
{
if
(
null
!=
currentUser
)
{
// 如果是超级管理员,则不过滤数据
// 如果是超级管理员,则不过滤数据
if
(!
currentUser
.
isAdmin
())
{
if
(!
currentUser
.
isAdmin
())
{
dataScopeFilter
(
currentUser
,
dataScope
);
String
sqlString
=
dataScopeFilter
(
currentUser
,
dataScope
);
// originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
if
(
StrUtil
.
isNotBlank
(
sqlString
))
{
// metaObject.setValue("delegate.boundSql.sql", originalSql);
originalSql
=
"SELECT * FROM ("
+
originalSql
+
") temp_data_scope WHERE 1=1 AND ("
+
sqlString
.
substring
(
4
)
+
")"
;
metaObject
.
setValue
(
"delegate.boundSql.sql"
,
originalSql
);
}
}
}
}
}
log
.
info
(
"originalSql:{}"
,
originalSql
);
return
invocation
.
proceed
();
return
invocation
.
proceed
();
}
}
}
}
...
@@ -74,7 +75,7 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
...
@@ -74,7 +75,7 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
* @param user
* @param user
* @param dataScope
* @param dataScope
*/
*/
private
void
dataScopeFilter
(
DataUser
user
,
DataScope
dataScope
)
{
private
String
dataScopeFilter
(
DataUser
user
,
DataScope
dataScope
)
{
StringBuilder
sqlString
=
new
StringBuilder
();
StringBuilder
sqlString
=
new
StringBuilder
();
List
<
DataRole
>
roles
=
user
.
getRoles
();
List
<
DataRole
>
roles
=
user
.
getRoles
();
if
(
CollUtil
.
isNotEmpty
(
roles
)){
if
(
CollUtil
.
isNotEmpty
(
roles
)){
...
@@ -85,33 +86,32 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
...
@@ -85,33 +86,32 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
break
;
break
;
}
else
if
(
DataConstant
.
DataScope
.
CUSTOM
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
CUSTOM
.
getKey
().
equals
(
roleDataScope
))
{
sqlString
.
append
(
StrUtil
.
format
(
sqlString
.
append
(
StrUtil
.
format
(
" OR
{}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
,
" OR
( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
dataScope
.
getDeptAlias
()
,
dataScope
.
getUserScopeName
()
,
role
.
getId
()
,
"'"
+
role
.
getId
()
+
"'"
));
));
}
else
if
(
DataConstant
.
DataScope
.
DEPT
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
DEPT
.
getKey
().
equals
(
roleDataScope
))
{
sqlString
.
append
(
StrUtil
.
format
(
sqlString
.
append
(
StrUtil
.
format
(
" OR
{}.dept_id IN ( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) "
,
" OR
( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) IN ( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) "
dataScope
.
getDeptAlias
()
,
dataScope
.
getUserScopeName
()
,
user
.
getId
()
,
"'"
+
user
.
getId
()
+
"'"
));
));
}
else
if
(
DataConstant
.
DataScope
.
DEPTANDCHILD
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
DEPTANDCHILD
.
getKey
().
equals
(
roleDataScope
))
{
sqlString
.
append
(
StrUtil
.
format
(
sqlString
.
append
(
StrUtil
.
format
(
" OR
{}.dept_id IN ( SELECT descendant FROM sys_dept_relation WHERE ancestor = {} )"
,
" OR
( SELECT dept_id FROM sys_user_dept WHERE user_id = {} ) IN ( SELECT descendant FROM sys_dept_relation WHERE ancestor = {} )"
dataScope
.
getDeptAlias
()
,
dataScope
.
getUserScopeName
()
,
role
.
getId
()
,
"'"
+
role
.
getId
()
+
"'"
));
));
}
else
if
(
DataConstant
.
DataScope
.
SELF
.
getKey
().
equals
(
roleDataScope
))
{
}
else
if
(
DataConstant
.
DataScope
.
SELF
.
getKey
().
equals
(
roleDataScope
))
{
if
(
StrUtil
.
isNotBlank
(
dataScope
.
getUserAlias
()))
{
sqlString
.
append
(
StrUtil
.
format
(
" OR {} = {} "
sqlString
.
append
(
StrUtil
.
format
(
" OR {}.user_id = {} "
,
dataScope
.
getUserAlias
(),
user
.
getId
()));
,
dataScope
.
getUserScopeName
()
}
else
{
,
"'"
+
user
.
getId
()
+
"'"
// 数据权限为仅本人且没有userAlias别名不查询任何数据
));
sqlString
.
append
(
" OR 1=0 "
);
}
}
}
}
}
}
}
log
.
info
(
"数据范围过滤:{}"
,
sqlString
);
log
.
info
(
"数据范围过滤:{}"
,
sqlString
);
return
sqlString
.
toString
();
}
}
/**
/**
...
...
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/controller/TestController.java
0 → 100644
View file @
04cdf60d
package
cn
.
datax
.
service
.
system
.
controller
;
import
cn.datax.common.base.BaseController
;
import
cn.datax.common.base.DataScope
;
import
cn.datax.common.core.R
;
import
cn.datax.service.system.api.entity.UserEntity
;
import
cn.datax.service.system.api.query.UserQuery
;
import
cn.datax.service.system.service.UserService
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/test"
)
public
class
TestController
extends
BaseController
{
@Autowired
private
UserService
userService
;
@GetMapping
(
"/users/pageDataScope"
)
public
R
getUserPageDataScope
(
UserQuery
userQuery
)
{
QueryWrapper
<
UserEntity
>
queryWrapper
=
new
QueryWrapper
<>();
if
(
CollUtil
.
isNotEmpty
(
userQuery
.
getColumnList
())){
queryWrapper
.
select
(
ArrayUtil
.
toArray
(
userQuery
.
getColumnList
(),
String
.
class
));
}
queryWrapper
.
like
(
StrUtil
.
isNotBlank
(
userQuery
.
getUsername
()),
"username"
,
userQuery
.
getUsername
());
queryWrapper
.
apply
(
StrUtil
.
isNotBlank
(
userQuery
.
getDeptId
()),
"(select dept_id from sys_user_dept where user_id = id) = {0}"
,
userQuery
.
getDeptId
());
if
(
CollUtil
.
isNotEmpty
(
userQuery
.
getOrderList
())){
userQuery
.
getOrderList
().
stream
().
forEach
(
orderItem
->
{
queryWrapper
.
orderBy
(
StrUtil
.
isNotBlank
(
orderItem
.
getColumn
()),
orderItem
.
isAsc
(),
orderItem
.
getColumn
());
});
}
IPage
<
UserEntity
>
page
=
userService
.
pageDataScope
(
new
Page
<>(
userQuery
.
getPageNum
(),
userQuery
.
getPageSize
()),
queryWrapper
,
new
DataScope
());
return
R
.
ok
().
setData
(
page
);
}
}
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/service/UserService.java
View file @
04cdf60d
package
cn
.
datax
.
service
.
system
.
service
;
package
cn
.
datax
.
service
.
system
.
service
;
import
cn.datax.common.base.BaseService
;
import
cn.datax.common.base.BaseService
;
import
cn.datax.common.base.DataScope
;
import
cn.datax.service.system.api.dto.UserDto
;
import
cn.datax.service.system.api.dto.UserDto
;
import
cn.datax.service.system.api.dto.UserPasswordDto
;
import
cn.datax.service.system.api.dto.UserPasswordDto
;
import
cn.datax.service.system.api.entity.UserEntity
;
import
cn.datax.service.system.api.entity.UserEntity
;
import
cn.datax.service.system.api.vo.UserInfo
;
import
cn.datax.service.system.api.vo.UserInfo
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
/**
/**
* <p>
* <p>
...
@@ -25,4 +30,6 @@ public interface UserService extends BaseService<UserEntity> {
...
@@ -25,4 +30,6 @@ public interface UserService extends BaseService<UserEntity> {
void
updateUserPassword
(
UserPasswordDto
user
);
void
updateUserPassword
(
UserPasswordDto
user
);
UserInfo
getUserByUsername
(
String
username
);
UserInfo
getUserByUsername
(
String
username
);
IPage
<
UserEntity
>
pageDataScope
(
IPage
<
UserEntity
>
page
,
Wrapper
<
UserEntity
>
queryWrapper
,
DataScope
dataScope
);
}
}
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/service/impl/UserServiceImpl.java
View file @
04cdf60d
package
cn
.
datax
.
service
.
system
.
service
.
impl
;
package
cn
.
datax
.
service
.
system
.
service
.
impl
;
import
cn.datax.common.base.DataScope
;
import
cn.datax.common.exception.DataException
;
import
cn.datax.common.exception.DataException
;
import
cn.datax.service.system.api.dto.UserDto
;
import
cn.datax.service.system.api.dto.UserDto
;
import
cn.datax.service.system.api.dto.UserPasswordDto
;
import
cn.datax.service.system.api.dto.UserPasswordDto
;
...
@@ -14,6 +15,8 @@ import cn.datax.common.base.BaseServiceImpl;
...
@@ -14,6 +15,8 @@ import cn.datax.common.base.BaseServiceImpl;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheConfig
;
...
@@ -177,4 +180,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
...
@@ -177,4 +180,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
}
}
return
userInfo
;
return
userInfo
;
}
}
@Override
public
IPage
<
UserEntity
>
pageDataScope
(
IPage
<
UserEntity
>
page
,
Wrapper
<
UserEntity
>
queryWrapper
,
DataScope
dataScope
)
{
return
baseMapper
.
selectPageDataScope
(
page
,
queryWrapper
,
dataScope
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment