Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Springboot Plus
Commits
34c9ce81
Commit
34c9ce81
authored
Feb 07, 2020
by
trumansdo
Browse files
暂存,重新处理结果集映射
parent
404d2016
Changes
54
Hide whitespace changes
Inline
Side-by-side
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/dao/UserConsoleDao.java
View file @
34c9ce81
package
com.ibeetl.admin.console.dao
;
import
com.ibeetl.admin.core.service.param.CoreUserParam
;
import
org.beetl.sql.core.annotatoin.Param
;
import
org.beetl.sql.core.annotatoin.SqlResource
;
import
org.beetl.sql.core.engine.PageQuery
;
...
...
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/service/CoreOrgConsoleElService.java
0 → 100644
View file @
34c9ce81
package
com.ibeetl.admin.console.service
;
import
com.ibeetl.admin.core.dao.CoreOrgDao
;
import
com.ibeetl.admin.core.entity.CoreOrg
;
import
com.ibeetl.admin.core.service.CoreBaseService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.util.enums.DelFlagEnum
;
import
java.util.List
;
import
org.beetl.sql.core.query.Query
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
CoreOrgConsoleElService
extends
CoreBaseService
<
CoreOrg
>
{
@Autowired
CoreOrgDao
coreOrgDao
;
@Autowired
CorePlatformService
corePlatformService
;
/**
* Method getOrgListByParent ...<br>
* 可通过父级机构id获取下一级机构列表<br>
* 如果不传父级机构,会判断是否是admin前缀的超级管理。<br>
* 如果不是超级管理,则通过当前登录人登录时所选的机构id作为根级机构列表
*
* @param parentId of type Long
* @return List<CoreOrg>
*/
public
List
<
CoreOrg
>
getOrgListByParent
(
Long
parentId
)
{
if
(
parentId
==
null
||
parentId
==
0L
)
{
if
(
corePlatformService
.
isCurrentSupperAdmin
())
{
parentId
=
0L
;
}
else
{
parentId
=
corePlatformService
.
getCurrentOrgId
();
}
}
List
<
CoreOrg
>
coreOrgList
=
coreOrgDao
.
createLambdaQuery
()
.
andEq
(
CoreOrg:
:
getParentOrgId
,
parentId
)
.
andEq
(
CoreOrg:
:
getDelFlag
,
DelFlagEnum
.
NORMAL
)
.
select
();
return
coreOrgList
;
}
}
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/service/RoleConsoleService.java
View file @
34c9ce81
package
com.ibeetl.admin.console.service
;
import
com.ibeetl.admin.core.entity.CoreOrg
;
import
java.util.List
;
import
java.util.Optional
;
import
org.beetl.sql.core.SQLManager
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.slf4j.Logger
;
...
...
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/service/UserConsoleService.java
View file @
34c9ce81
package
com.ibeetl.admin.console.service
;
import
com.ibeetl.admin.core.entity.DictType
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
org.apache.commons.lang3.StringUtils
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ibeetl.admin.console.dao.UserConsoleDao
;
import
com.ibeetl.admin.console.exception.DeletedException
;
import
com.ibeetl.admin.console.exception.NoResourceException
;
...
...
@@ -19,6 +7,7 @@ import com.ibeetl.admin.console.web.dto.UserExcelExportData;
import
com.ibeetl.admin.console.web.query.UserRoleQuery
;
import
com.ibeetl.admin.core.conf.PasswordConfig.PasswordEncryptService
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.CoreOrg
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.entity.CoreUserRole
;
import
com.ibeetl.admin.core.file.FileService
;
...
...
@@ -26,10 +15,21 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import
com.ibeetl.admin.core.service.CoreBaseService
;
import
com.ibeetl.admin.core.service.CoreDictService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.service.param.CoreUserParam
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.enums.CoreDictType
;
import
com.ibeetl.admin.core.util.enums.DelFlagEnum
;
import
com.ibeetl.admin.core.util.enums.GeneralStateEnum
;
import
com.ibeetl.admin.core.util.enums.JobTypeEnum
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
org.apache.commons.lang3.StringUtils
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
@Transactional
...
...
@@ -53,6 +53,17 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
queryListAfter
(
ret
.
getList
());
}
/**
* 提供用户管理列表页数据
*
* @param coreUserParam
*/
public
PageQuery
<
CoreUser
>
getUsersByComplexSelect
(
CoreUserParam
coreUserParam
)
{
PageQuery
<
CoreUser
>
resultList
=
userConsoleDao
.
queryByCondtion
(
coreUserParam
.
createPageQuery
());
return
resultList
;
}
/**
* 插入一条用户数据
*
...
...
@@ -66,14 +77,12 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
throw
new
PlatformException
(
"保存用户信息失败,用户已经存在"
);
}
user
.
setCreateTime
(
new
Date
());
user
.
setState
(
GeneralStateEnum
.
ENABLE
.
getValue
());
user
.
setPassword
(
passwordEncryptService
.
password
(
user
.
getPassword
()));
user
.
setDelFlag
(
DelFlagEnum
.
NORMAL
.
getValue
());
userConsoleDao
.
insert
(
user
,
true
);
if
(
StringUtils
.
isNotEmpty
(
user
.
getAttachmentId
()))
{
// 更新附件详细信息,关联到这个用户
fileService
.
updateFile
(
user
.
getAttachmentId
(),
user
.
getName
(),
String
.
valueOf
(
user
.
getId
()));
fileService
.
updateFile
(
user
.
getAttachmentId
(),
user
.
getName
(),
String
.
valueOf
(
user
.
getId
()));
}
}
...
...
@@ -185,16 +194,17 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
userItem
.
setCode
(
user
.
getCode
());
userItem
.
setId
(
user
.
getId
());
userItem
.
setName
(
user
.
getName
());
CoreDict
dict
=
dictService
.
findCoreDict
(
CoreDictType
.
USER_STATE
,
user
.
getState
());
CoreDict
dict
=
dictService
.
findCoreDict
(
CoreDictType
.
USER_STATE
,
user
.
getState
()
.
getValue
()
);
userItem
.
setStateText
(
dict
.
getName
());
String
dictValue
=
Optional
.
ofNullable
(
user
.
getJobType1
()).
map
(
DictType:
:
getValue
).
orElse
(
null
);
String
dictValue
=
Optional
.
ofNullable
(
user
.
getJobType1
()).
map
(
JobTypeEnum:
:
getValue
).
orElse
(
null
);
if
(
StringUtils
.
isNotEmpty
(
dictValue
))
{
dict
=
dictService
.
findCoreDict
(
CoreDictType
.
JOB_TYPE
,
dictValue
);
userItem
.
setJobType1Text
(
dict
.
getName
());
}
String
orgName
=
orgRoot
.
findChild
(
user
.
getO
rgId
()
).
getName
();
Long
orgId
=
user
.
getOrgId
();
String
orgName
=
orgRoot
.
findChild
(
o
rgId
).
getName
();
userItem
.
setOrgText
(
orgName
);
items
.
add
(
userItem
);
}
...
...
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/util/VOUtil.java
View file @
34c9ce81
...
...
@@ -4,6 +4,7 @@ import cn.hutool.core.annotation.AnnotationUtil;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.map.MapBuilder
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.ibeetl.admin.core.annotation.ElColumn
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.ElCascaderData
;
...
...
@@ -11,15 +12,17 @@ import java.lang.reflect.Field;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Optional
;
import
java.util.Set
;
/**
* 视图
对象
工具类
* 视图工具类
*
* @author 一日看尽长安花
*/
public
class
VOUtil
{
static
final
String
JSON_PATH_KEY
=
"json_path"
;
/**
* Method resolveElColumn ... todo 预计重新定义一个类用来转换,而不是用map
*
...
...
@@ -33,11 +36,23 @@ public class VOUtil {
for
(
Field
field
:
declaredFields
)
{
Map
<
String
,
Object
>
annotationValueMap
=
AnnotationUtil
.
getAnnotationValueMap
(
field
,
ElColumn
.
class
);
ElColumn
elColumn
=
AnnotationUtil
.
getAnnotation
(
field
,
ElColumn
.
class
);
Optional
.
ofNullable
(
elColumn
)
.
ifPresent
(
column
->
mapBuilder
.
put
(
field
.
getName
(),
annotationValueMap
));
if
(
MapUtil
.
isEmpty
(
annotationValueMap
))
continue
;
Set
<
Entry
<
String
,
Object
>>
entrySet
=
annotationValueMap
.
entrySet
();
MapBuilder
<
Object
,
Object
>
camelKeyValueMap
=
MapUtil
.
builder
();
for
(
Entry
<
String
,
Object
>
entry
:
entrySet
)
{
String
key
=
entry
.
getKey
();
Object
value
=
entry
.
getValue
();
camelKeyValueMap
.
put
(
StrUtil
.
toUnderlineCase
(
key
),
value
);
}
String
camelKey
=
StrUtil
.
toUnderlineCase
(
field
.
getName
());
Map
<
Object
,
Object
>
buildMap
=
camelKeyValueMap
.
build
();
String
jsonPath
=
buildMap
.
getOrDefault
(
JSON_PATH_KEY
,
StrUtil
.
EMPTY
).
toString
();
if
(
StrUtil
.
isBlank
(
jsonPath
))
{
jsonPath
=
camelKey
;
}
buildMap
.
put
(
JSON_PATH_KEY
,
jsonPath
);
mapBuilder
.
put
(
camelKey
,
buildMap
);
}
return
mapBuilder
.
build
();
}
}
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/CoreUserElController.java
deleted
100644 → 0
View file @
404d2016
package
com.ibeetl.admin.console.web
;
import
com.ibeetl.admin.console.util.VOUtil
;
import
com.ibeetl.admin.console.web.query.CoreUserElQuery
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.service.CoreUserService
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.util.Map
;
import
javax.validation.constraints.NotNull
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@Validated
@RestController
public
class
CoreUserElController
{
@Autowired
private
CoreUserService
coreUserService
;
@GetMapping
(
"/users/metadata"
)
public
JsonResult
<
Map
>
usersMetedata
()
{
return
JsonResult
.
success
(
VOUtil
.
resolveElColumn
(
CoreUserElQuery
.
class
));
}
@GetMapping
(
"/users"
)
public
JsonResult
<
PageQuery
<
CoreUser
>>
users
(
@NotNull
Integer
page
,
@NotNull
Integer
limit
)
{
PageQuery
<
CoreUser
>
allUsers
=
coreUserService
.
getAllUsers
(
page
,
limit
);
return
JsonResult
.
success
(
allUsers
);
}
}
plus-admin/admin-co
r
e/src/main/java/com/ibeetl/admin/co
r
e/web/DictCascaderElController.java
→
plus-admin/admin-co
nsol
e/src/main/java/com/ibeetl/admin/co
nsol
e/web/DictCascaderElController.java
View file @
34c9ce81
package
com.ibeetl.admin.co
r
e.web
;
package
com.ibeetl.admin.co
nsol
e.web
;
import
cn.hutool.core.util.StrUtil
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.ElCascaderData
;
import
com.ibeetl.admin.core.service.CoreDictService
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -31,7 +32,7 @@ public class DictCascaderElController {
* @param type of type String 子级字典列表type
* @return JsonResult<List < ElCascaderData>>
*/
@GetMapping
@GetMapping
(
"/tree"
)
public
JsonResult
<
List
<
ElCascaderData
>>
obtainDcitsByCascader
(
Long
parentId
,
String
type
)
{
if
(
StrUtil
.
isBlank
(
type
)
&&
parentId
==
null
)
{
return
JsonResult
.
failMessage
(
"parentId and type should have at least one."
);
...
...
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/OrgCascaderElController.java
0 → 100644
View file @
34c9ce81
package
com.ibeetl.admin.console.web
;
import
com.ibeetl.admin.core.entity.CoreOrg
;
import
com.ibeetl.admin.core.entity.ElCascaderData
;
import
com.ibeetl.admin.console.service.CoreOrgConsoleElService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
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
;
/**
* 字典数据获取
*
* @author 一日看尽长安花
*/
@Slf4j
@RestController
@RequestMapping
(
value
=
"/core/orgs"
)
public
class
OrgCascaderElController
{
@Autowired
CorePlatformService
corePlatformService
;
@Autowired
CoreOrgConsoleElService
coreOrgService
;
/**
* Method obtainDcitsByCascader ...<br>
* 获取机构级联。如果是admin超级管理,可以获取所有的机构。<br>
* 如果不是,则根据当前登录人的机构id获取根级机构
*
* @param parentId of type Long 父级id
* @return JsonResult<List < ElCascaderData>>
*/
@GetMapping
(
"/tree"
)
public
JsonResult
<
List
<
ElCascaderData
>>
obtainOrgsByCascader
(
Long
parentId
)
{
List
<
CoreOrg
>
coreOrgList
=
coreOrgService
.
getOrgListByParent
(
parentId
);
return
JsonResult
.
success
(
convertToCascaderData
(
coreOrgList
));
}
private
List
<
ElCascaderData
>
convertToCascaderData
(
List
<
CoreOrg
>
coreOrgs
)
{
List
<
ElCascaderData
>
cascaderDataArrayList
=
new
ArrayList
<
ElCascaderData
>(
coreOrgs
.
size
());
for
(
CoreOrg
org
:
coreOrgs
)
{
ElCascaderData
data
=
new
ElCascaderData
();
data
.
setId
(
org
.
getId
());
data
.
setLabel
(
org
.
getName
());
data
.
setValue
(
org
.
getId
());
cascaderDataArrayList
.
add
(
data
);
}
return
cascaderDataArrayList
;
}
}
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/PageParams.java
deleted
100644 → 0
View file @
404d2016
package
com.ibeetl.admin.console.web
;
import
javax.validation.constraints.NotNull
;
import
lombok.Builder
;
import
lombok.Builder.Default
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
public
class
PageParams
{
@NotNull
Integer
page
=
1
;
@NotNull
Integer
limit
=
10
;
}
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/UserConsoleElController.java
0 → 100644
View file @
34c9ce81
package
com.ibeetl.admin.console.web
;
import
com.ibeetl.admin.console.service.UserConsoleService
;
import
com.ibeetl.admin.console.util.VOUtil
;
import
com.ibeetl.admin.console.web.query.CoreUserElQuery
;
import
com.ibeetl.admin.core.annotation.Function
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.service.CoreUserService
;
import
com.ibeetl.admin.core.service.param.CoreUserParam
;
import
com.ibeetl.admin.core.util.ConvertUtil
;
import
com.ibeetl.admin.core.util.ValidateConfig
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@Validated
@RequestMapping
(
"/users"
)
@RestController
public
class
UserConsoleElController
{
@Autowired
private
UserConsoleService
userConsoleService
;
@Autowired
private
CorePlatformService
platformService
;
@Function
(
"user.query"
)
@GetMapping
(
"/metadata"
)
public
JsonResult
<
Map
>
usersMetedata
()
{
return
JsonResult
.
success
(
VOUtil
.
resolveElColumn
(
CoreUserElQuery
.
class
));
}
@Function
(
"user.query"
)
@GetMapping
public
JsonResult
<
PageQuery
<
CoreUser
>>
users
(
CoreUserParam
coreUserParam
)
{
PageQuery
<
CoreUser
>
allUsers
=
userConsoleService
.
getUsersByComplexSelect
(
coreUserParam
);
return
JsonResult
.
success
(
allUsers
);
}
@Function
(
"user.add"
)
@PostMapping
public
JsonResult
<
Long
>
addUser
(
@Validated
(
ValidateConfig
.
ADD
.
class
)
CoreUser
user
)
{
if
(!
platformService
.
isAllowUserName
(
user
.
getCode
()))
{
return
JsonResult
.
failMessage
(
"不允许的注册名字 "
+
user
.
getCode
());
}
userConsoleService
.
saveUser
(
user
);
return
JsonResult
.
success
(
user
.
getId
());
}
@Function
(
"user.update"
)
@PutMapping
public
JsonResult
update
(
@Validated
(
ValidateConfig
.
UPDATE
.
class
)
CoreUser
user
)
{
boolean
success
=
userConsoleService
.
updateTemplate
(
user
);
if
(
success
)
{
this
.
platformService
.
clearFunctionCache
();
return
JsonResult
.
success
();
}
else
{
return
JsonResult
.
failMessage
(
"保存失败!"
);
}
}
@Function
(
"user.delete"
)
@DeleteMapping
public
JsonResult
delete
(
Long
[]
ids
)
{
userConsoleService
.
batchDelSysUser
(
Arrays
.
asList
(
ids
));
return
JsonResult
.
success
();
}
}
plus-admin/admin-console/src/main/java/com/ibeetl/admin/console/web/query/CoreUserElQuery.java
View file @
34c9ce81
...
...
@@ -17,19 +17,27 @@ import lombok.Data;
@Data
public
class
CoreUserElQuery
{
@ElColumn
(
name
=
"ID"
,
type
=
STRING
)
@ElColumn
(
name
=
"ID"
,
type
=
STRING
,
isShowSearchPanel
=
false
,
isShowTablePanel
=
false
,
isShowEditorPanel
=
false
)
protected
Long
id
;
@ElColumn
(
name
=
"创建时间"
,
type
=
DATE
)
protected
Date
createTime
;
@ElColumn
(
name
=
"用户名"
,
type
=
STRING
)
@ElColumn
(
name
=
"用户名"
,
type
=
STRING
,
isShowSearchPanel
=
false
)
private
String
code
;
@ElColumn
(
name
=
"姓名"
,
type
=
STRING
)
private
String
name
;
@ElColumn
(
name
=
"状态"
,
type
=
STRING
)
@ElColumn
(
name
=
"机构"
,
type
=
STRING
)
private
Long
orgId
;
@ElColumn
(
name
=
"状态"
,
type
=
DICT
)
private
String
state
;
@ElColumn
(
name
=
"职务"
,
type
=
DICT
)
...
...
plus-admin/admin-console/src/main/resources/sql/console/user.md
View file @
34c9ce81
queryByCondtion
===
select
@pageTag(){
u.
*
,o.name org_name
@}
from core_user u left join core_org o on u.org_id=o.id where 1=1 and u.del_flag = 0
@//数据权限,该sql语句功能点
and #function("user.query")#
@if(!isEmpty(orgId)){
and u.org_id =#orgId#
@}
@if(!isEmpty(orgId)){
and u.org_id =#orgId#
@}
@if(!isEmpty(code)){
and u.code like #"%"+code+"%"#
@}
@if(!isEmpty(name)){
and u.name like #"%"+name+"%"#
@}
@if(!isEmpty(state)){
and u.state = #state#
@}
@if(!isEmpty(jobType0)){
and u.job_type0= #jobType0#
@}
@if(!isEmpty(jobType1)){
and u.job_type1= #jobType1#
@}
@if(!isEmpty(createDateMin)){
and u.create_time>= #createDateMin#
@}
@if(!isEmpty(createDateMax)){
and u.create_time< #nextDay(createDateMax)#
@}
```
sql
select
@
pageTag
(){
u
.
*
,
o
.
name
org_name
@
}
from
core_user
u
left
join
core_org
o
on
u
.
org_id
=
o
.
id
where
1
=
1
and
u
.
del_flag
=
0
@//
数据权限,该
sql
语句功能点
and
#
function
(
"user.query"
)
#
@
if
(
!
isEmpty
(
orgId
)){
and
u
.
org_id
=#
orgId
#
@
}
@
if
(
!
isEmpty
(
code
)){
and
u
.
code
like
#
"%"
+
code
+
"%"
#
@
}
@
if
(
!
isEmpty
(
name
)){
and
u
.
name
like
#
"%"
+
name
+
"%"
#
@
}
@
if
(
!
isEmpty
(
state
)){
and
u
.
state
=
#
state
#
@
}
@
if
(
!
isEmpty
(
jobType0
)){
and
u
.
job_type0
=
#
jobType0
#
@
}
@
if
(
!
isEmpty
(
createTimeStart
)){
and
u
.
create_time
>=
#
createTimeStart
#
@
}
@
if
(
!
isEmpty
(
createTimeEnd
)){
and
u
.
create_time
<
#
nextDay
(
createTimeEnd
)
#
@
}
```
batchDelUserByIds
===
...
...
@@ -69,3 +62,28 @@ where u.id=#id#
and
role
.
id
=#
roleId
#
@
}
```
UsersMapping
===
```
var user_mapping_var={
"id": "core_route_map",
"mapping": {
"resultType": "com.ibeetl.admin.core.entity.CoreRoute",
"id": "id",
"createTime": "create_time",
"code": "code",
"name": "name",
"state": "state",
"jobType0": "job_type0",
"jobType1": "job_type1",
"updateTime": "update_time",
"attachmentId": "attachment_id",
"org": {
"resultType": "com.ibeetl.admin.core.entity.CoreOrg",
"id": "org_id",
"name": "org_name"
}
}
};
```
\ No newline at end of file
plus-admin/admin-console/src/test/java/CustomBeanProcessorTest.java
View file @
34c9ce81
import
cn.hutool.core.util.EnumUtil
;
import
com.ibeetl.admin.ConsoleApplication
;
import
com.ibeetl.admin.core.dao.CoreFunctionDao
;
import
com.ibeetl.admin.core.entity.CoreRoute
;
import
entity.CmsBlog
;
import
entity.CmsBlogTypeEnum
;
import
java.util.List
;
import
org.beetl.sql.core.SQLManager
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -21,5 +25,15 @@ public class CustomBeanProcessorTest {
}
@Test
public
void
test
()
{}
public
void
test
()
{
SQLManager
sqlManager
=
coreFunctionDao
.
getSQLManager
();
List
<
CmsBlog
>
cmsBlogList
=
sqlManager
.
lambdaQuery
(
CmsBlog
.
class
).
select
();
System
.
out
.
println
(
cmsBlogList
);
CmsBlog
blog
=
new
CmsBlog
();
blog
.
setTitle
(
"test title"
);
blog
.
setContent
(
"test content"
);
blog
.
setType
(
CmsBlogTypeEnum
.
FN1
);
blog
.
setCreateUserId
(
1L
);
sqlManager
.
lambdaQuery
(
CmsBlog
.
class
).
insert
(
blog
);
}
}
plus-admin/admin-console/src/test/java/entity/CmsBlog.java
0 → 100644
View file @
34c9ce81
package
entity
;
import
lombok.Data
;
import
org.beetl.sql.core.annotatoin.AutoID
;
@Data
public
class
CmsBlog
{
@AutoID
private
Long
id
;
private
String
title
;
private
String
content
;
private
Long
createUserId
;
private
CmsBlogTypeEnum
type
;
private
Long
createTime
;
}
plus-admin/admin-console/src/test/java/entity/CmsBlogTypeEnum.java
0 → 100644
View file @
34c9ce81
package
entity
;
import
org.beetl.sql.core.annotatoin.EnumMapping
;
@EnumMapping
(
"value"
)
public
enum
CmsBlogTypeEnum
{
FN0
(
"FN0"
,
"普通功能"
,
"function_type"
),
FN1
(
"FN1"
,
"含数据权限"
,
"function_type"
),
FN2
(
"FN2"
,
"菜单功能"
,
"function_type"
);
private
String
value
;
private
String
name
;
private
String
type
;
CmsBlogTypeEnum
(
String
value
,
String
name
,
String
type
)
{
this
.
value
=
value
;
this
.
name
=
name
;
this
.
type
=
type
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
}
plus-admin/admin-core/pom.xml
View file @
34c9ce81
...
...
@@ -54,7 +54,7 @@
<dependency>
<groupId>
com.ibeetl
</groupId>
<artifactId>
beetl-framework-starter
</artifactId>
<version>
1.2.
13
.RELEASE
</version>
<version>
1.2.
20
.RELEASE
</version>
</dependency>
<!-- Log4j2 异步支持 -->
<dependency>
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/annotation/ElColumn.java
View file @
34c9ce81
package
com.ibeetl.admin.core.annotation
;
import
cn.hutool.core.util.StrUtil
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
...
...
@@ -16,37 +17,57 @@ public @interface ElColumn {
/**
* 数据表格列头显示名称
* @return
* */
*
* @return
*/
String
name
();
/**
* 该列的类型。查看 {@link com.ibeetl.admin.core.util.enums.ElColumnType}
*
* @return
*
*/
*/
String
type
();
/**
* 在数据表格中取json的path。参照json path技术。
*
* @return String
*/
String
jsonPath
()
default
StrUtil
.
EMPTY
;
/**
* 开启element-ui 中数据表格列的手动排序
* @return
* */
*
* @return
*/
boolean
sortable
()
default
false
;
/**
* 是否在前端页面的查询条件区显示
*
* @return
*
*/
boolean
v
is
ible
()
default
true
;
*/
boolean
is
ShowSearchPanel
()
default
true
;
/**
* 是否在前端页面的数据表格列中显示
*
* @return
*/
boolean
isShowTablePanel
()
default
true
;
/**
* 是否在前端页面的编辑窗显示
*
* @return
*
*/
boolean
d
is
playable
()
default
true
;
*/
boolean
is
ShowEditorPanel
()
default
true
;
/**
* 是否在表单中是必填。暂时没做规则的生成功能,暂定没有
*
* @return
*
*/
*/
boolean
required
()
default
false
;
}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/annotation/SnakeCaseParameter.java
0 → 100644
View file @
34c9ce81
package
com.ibeetl.admin.core.annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
(
value
=
ElementType
.
PARAMETER
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
SnakeCaseParameter
{}
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/JasonConfig.java
View file @
34c9ce81
package
com.ibeetl.admin.core.conf
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.util.EnumUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser.NumberType
;
import
com.fasterxml.jackson.core.JsonToken
;
import
com.fasterxml.jackson.core.Version
;
import
com.fasterxml.jackson.core.type.WritableTypeId
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper
;
import
com.fasterxml.jackson.databind.jsontype.TypeSerializer
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.ser.std.StdSerializer
;
import
com.ibeetl.admin.core.util.enums.DictTypeEnum
;
import
com.ibeetl.admin.core.web.JsonResult
;
import
java.io.IOException
;
import
java.lang.reflect.Type
;
...
...
@@ -26,9 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author 一日看尽长安花
*/
/** @author 一日看尽长安花 */
@Configuration
public
class
JasonConfig
{
@Bean
...
...
@@ -36,13 +42,22 @@ public class JasonConfig {
public
ObjectMapper
getObjectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
setDateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
));
/*objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));*/
objectMapper
.
setPropertyNamingStrategy
(
PropertyNamingStrategy
.
SNAKE_CASE
);
objectMapper
.
setSerializationInclusion
(
Include
.
NON_NULL
);
objectMapper
.
configure
(
SerializationFeature
.
INDENT_OUTPUT
,
true
);
/*将date字段序列化为时间戳*/
objectMapper
.
configure
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
,
true
);
/*map中date的也序列化为时间戳*/
objectMapper
.
configure
(
SerializationFeature
.
WRITE_DATE_KEYS_AS_TIMESTAMPS
,
true
);
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
SimpleModule
simpleModule
=
new
SimpleModule
(
"SimpleModule"
,
Version
.
unknownVersion
());
simpleModule
.
addSerializer
(
JsonResult
.
class
,
new
CustomJsonResultSerializer
());
simpleModule
.
addSerializer
(
DictTypeEnum
.
class
,
new
DictTypeEnumSerializer
());
CustomLongSerializer
longSerializer
=
new
CustomLongSerializer
();
simpleModule
.
addSerializer
(
Long
.
class
,
longSerializer
);
...
...
@@ -53,6 +68,21 @@ public class JasonConfig {
}
}
class
DictTypeEnumSerializer
extends
JsonSerializer
<
DictTypeEnum
>
{
@Override
public
void
serialize
(
DictTypeEnum
value
,
JsonGenerator
gen
,
SerializerProvider
serializers
)
throws
IOException
{
gen
.
writeStartObject
();
if
(
value
instanceof
Enum
)
{
gen
.
writeObjectField
(
"name"
,
ReflectUtil
.
getFieldValue
(
value
,
"name"
));
gen
.
writeObjectField
(
"value"
,
ReflectUtil
.
getFieldValue
(
value
,
"value"
));
gen
.
writeObjectField
(
"type"
,
ReflectUtil
.
getFieldValue
(
value
,
"type"
));
}
gen
.
writeEndObject
();
}
}
/**
* 修正jackson转换Long类型的一个bug: jackson的转换Long类型时,如果数值在Integer范围,会变成Integer类型,然后通过强制转换为Long时就会报错。
* 这里采用安全的Long转换避免强制类型转换
...
...
@@ -100,9 +130,7 @@ class CustomJsonResultSerializer extends JsonSerializer<JsonResult> {
CustomJsonResultSerializer
()
{}
/**
* 处理 JsonResult 返回结果。自动分离分页信息,不需要手动在controller中分离
*/
/** 处理 JsonResult 返回结果。自动分离分页信息,不需要手动在controller中分离 */
@Override
public
void
serialize
(
JsonResult
value
,
JsonGenerator
gen
,
SerializerProvider
serializers
)
throws
IOException
{
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/conf/SpringWebMvcConfigurer.java
View file @
34c9ce81
package
com.ibeetl.admin.core.conf
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ClassUtil
;
import
cn.hutool.core.util.EnumUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.TypeUtil
;
...
...
@@ -10,22 +13,39 @@ import cn.hutool.json.JSONArray;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.ibeetl.admin.core.annotation.RequestBodyPlus
;
import
com.ibeetl.admin.core.annotation.SnakeCaseParameter
;
import
com.ibeetl.admin.core.service.CoreUserService
;
import
com.ibeetl.admin.core.util.HttpRequestLocal
;
import
com.ibeetl.admin.core.util.JoseJwtUtil
;
import
com.ibeetl.admin.core.util.enums.DictTypeEnum
;
import
java.io.IOException
;
import
java.lang.reflect.Type
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.beetl.core.GroupTemplate
;
import
org.beetl.ext.spring.BeetlGroupUtilConfiguration
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.PropertyAccessorFactory
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.converter.ConditionalGenericConverter
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.env.Environment
;
import
org.springframework.format.FormatterRegistry
;
import
org.springframework.format.datetime.DateFormatter
;
...
...
@@ -34,14 +54,12 @@ import org.springframework.http.MediaType;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.http.server.ServletServerHttpRequest
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.support.WebDataBinderFactory
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.ModelAndViewContainer
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
...
@@ -94,6 +112,11 @@ public class SpringWebMvcConfigurer implements WebMvcConfigurer, InitializingBea
registry
.
addMapping
(
"/**"
);
}
@Override
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
resolvers
)
{
// resolvers.add(new UnderlineToCamelArgumentResolver());
}
/**
* SpringMVC的请求响应消息的转换格式器
*
...
...
@@ -103,6 +126,71 @@ public class SpringWebMvcConfigurer implements WebMvcConfigurer, InitializingBea
public
void
addFormatters
(
FormatterRegistry
registry
)
{
registry
.
addFormatter
(
new
DateFormatter
(
"yyyy-MM-dd HH:mm:ss"
));
registry
.
addFormatter
(
new
DateFormatter
(
"yyyy-MM-dd"
));
registry
.
addConverter
(
new
ConditionalGenericConverter
()
{
@Override
public
boolean
matches
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
boolean
targetTypeMatches
=
Optional
.
ofNullable
(
targetType
.
getResolvableType
())
.
map
(
ResolvableType:
:
resolve
)
.
map
(
resolvableType
->
resolvableType
.
equals
(
Date
.
class
))
.
orElse
(
false
);
return
targetTypeMatches
;
}
@Override
public
Set
<
ConvertiblePair
>
getConvertibleTypes
()
{
return
CollUtil
.
newHashSet
(
new
ConvertiblePair
(
String
.
class
,
Date
.
class
),
new
ConvertiblePair
(
Long
.
class
,
Date
.
class
));
}
@Override
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
DateUtil
.
date
(
Convert
.
toLong
(
source
));
}
});
registry
.
addConverter
(
new
ConditionalGenericConverter
()
{
/**
* 处理从前端传递的字符串到对应的字典枚举,需要字典枚举类实现 {@link DictTypeEnum} 接口
*
* @return boolean
*/
@Override
public
boolean
matches
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Class
targetClass
=
Optional
.
ofNullable
(
targetType
.
getResolvableType
())
.
map
(
ResolvableType:
:
resolve
)
.
orElse
(
null
);
return
sourceType
.
getResolvableType
().
resolve
().
equals
(
String
.
class
)
&&
Enum
.
class
.
isAssignableFrom
(
targetClass
)
&&
DictTypeEnum
.
class
.
isAssignableFrom
(
targetClass
);
}
@Override
public
Set
<
ConvertiblePair
>
getConvertibleTypes
()
{
return
CollUtil
.
newHashSet
(
new
ConvertiblePair
(
String
.
class
,
DictTypeEnum
.
class
));
}
@Override
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Class
enumClass
=
targetType
.
getResolvableType
().
resolve
();
Map
<
String
,
Object
>
valueFieldMap
=
EnumUtil
.
getNameFieldMap
(
enumClass
,
"value"
);
Set
<
Entry
<
String
,
Object
>>
entrySet
=
valueFieldMap
.
entrySet
();
String
targetEnumName
=
StrUtil
.
EMPTY
;
for
(
Entry
<
String
,
Object
>
entry
:
entrySet
)
{
if
(
entry
.
getValue
().
equals
(
source
.
toString
()))
{
targetEnumName
=
entry
.
getKey
();
break
;
}
}
return
EnumUtil
.
fromStringQuietly
(
enumClass
,
targetEnumName
);
}
});
}
@Override
...
...
@@ -241,3 +329,54 @@ class RequestBodyPlusProcessor extends AbstractMessageConverterMethodProcessor {
ModelAndViewContainer
mavContainer
,
NativeWebRequest
webRequest
)
{}
}
/**
* Class UnderlineToCamelArgumentResolver : <br>
* 描述:处理请求参数的命名由下划线等转驼峰命名。<br>
* 但是与另一个{@link DictTypeEnum} 枚举处理有冲突,所以交给前端处理命名转换
*
* @author 一日看尽长安花 Created on 2020/2/2
*/
class
UnderlineToCamelArgumentResolver
implements
HandlerMethodArgumentResolver
{
/** 匹配下划线的格式 */
private
static
Pattern
pattern
=
Pattern
.
compile
(
"_(\\w)"
);
private
static
String
underLineToCamel
(
String
source
)
{
Matcher
matcher
=
pattern
.
matcher
(
source
);
StringBuffer
sb
=
new
StringBuffer
();
while
(
matcher
.
find
())
{
matcher
.
appendReplacement
(
sb
,
matcher
.
group
(
1
).
toUpperCase
());
}
matcher
.
appendTail
(
sb
);
return
sb
.
toString
();
}
@Override
public
boolean
supportsParameter
(
MethodParameter
methodParameter
)
{
return
methodParameter
.
hasParameterAnnotation
(
SnakeCaseParameter
.
class
);
}
@Override
public
Object
resolveArgument
(
MethodParameter
parameter
,
ModelAndViewContainer
container
,
NativeWebRequest
webRequest
,
WebDataBinderFactory
binderFactory
)
{
return
handleParameterNames
(
parameter
,
webRequest
);
}
private
Object
handleParameterNames
(
MethodParameter
parameter
,
NativeWebRequest
webRequest
)
{
Object
obj
=
BeanUtils
.
instantiateClass
(
parameter
.
getParameterType
());
BeanWrapper
wrapper
=
PropertyAccessorFactory
.
forBeanPropertyAccess
(
obj
);
Iterator
<
String
>
paramNames
=
webRequest
.
getParameterNames
();
while
(
paramNames
.
hasNext
())
{
String
paramName
=
paramNames
.
next
();
Object
o
=
webRequest
.
getParameter
(
paramName
);
try
{
wrapper
.
setPropertyValue
(
underLineToCamel
(
paramName
),
o
);
}
catch
(
BeansException
e
)
{
}
}
return
obj
;
}
}
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
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