Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-boot-starters
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-boot-starters
提交
0d372a39
提交
0d372a39
编写于
7月 29, 2022
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
4f6069f5
变更
101
隐藏空白字符变更
内嵌
并排
正在显示
101 个修改的文件
包含
8547 行增加
和
0 行删除
+8547
-0
.gitignore
.gitignore
+15
-0
pom.xml
ibizlab-boot-starter-data/pom.xml
+114
-0
Audit.java
...-data/src/main/java/cn/ibizlab/util/annotation/Audit.java
+15
-0
DEField.java
...ata/src/main/java/cn/ibizlab/util/annotation/DEField.java
+82
-0
VersionCheck.java
...rc/main/java/cn/ibizlab/util/annotation/VersionCheck.java
+15
-0
DELogic.java
...er-data/src/main/java/cn/ibizlab/util/domain/DELogic.java
+22
-0
DTOBase.java
...er-data/src/main/java/cn/ibizlab/util/domain/DTOBase.java
+130
-0
DTOClient.java
...-data/src/main/java/cn/ibizlab/util/domain/DTOClient.java
+18
-0
EntityBase.java
...data/src/main/java/cn/ibizlab/util/domain/EntityBase.java
+145
-0
EntityClient.java
...ta/src/main/java/cn/ibizlab/util/domain/EntityClient.java
+31
-0
EntityMP.java
...r-data/src/main/java/cn/ibizlab/util/domain/EntityMP.java
+39
-0
EntityMongo.java
...ata/src/main/java/cn/ibizlab/util/domain/EntityMongo.java
+6
-0
IBZConfig.java
...-data/src/main/java/cn/ibizlab/util/domain/IBZConfig.java
+79
-0
IBZDataAudit.java
...ta/src/main/java/cn/ibizlab/util/domain/IBZDataAudit.java
+33
-0
IBZUSER.java
...er-data/src/main/java/cn/ibizlab/util/domain/IBZUSER.java
+116
-0
LiquibaseProp.java
...a/src/main/java/cn/ibizlab/util/domain/LiquibaseProp.java
+23
-0
MappingBase.java
...ata/src/main/java/cn/ibizlab/util/domain/MappingBase.java
+36
-0
DEFieldDefaultValueType.java
...n/java/cn/ibizlab/util/enums/DEFieldDefaultValueType.java
+63
-0
DEPredefinedFieldType.java
...ain/java/cn/ibizlab/util/enums/DEPredefinedFieldType.java
+71
-0
DupCheck.java
...er-data/src/main/java/cn/ibizlab/util/enums/DupCheck.java
+23
-0
ISearchContext.java
.../src/main/java/cn/ibizlab/util/filter/ISearchContext.java
+5
-0
QueryFilter.java
...ata/src/main/java/cn/ibizlab/util/filter/QueryFilter.java
+273
-0
QueryWrapperContext.java
...main/java/cn/ibizlab/util/filter/QueryWrapperContext.java
+222
-0
SearchContextBase.java
...c/main/java/cn/ibizlab/util/filter/SearchContextBase.java
+174
-0
DEFieldCacheMap.java
...src/main/java/cn/ibizlab/util/helper/DEFieldCacheMap.java
+252
-0
JSR310DateConverters.java
...ain/java/cn/ibizlab/util/helper/JSR310DateConverters.java
+149
-0
RuleUtils.java
...-data/src/main/java/cn/ibizlab/util/helper/RuleUtils.java
+690
-0
Setting.java
...er-data/src/main/java/cn/ibizlab/util/helper/Setting.java
+91
-0
IBZConfigMapper.java
...src/main/java/cn/ibizlab/util/mapper/IBZConfigMapper.java
+8
-0
IBZDataAuditMapper.java
.../main/java/cn/ibizlab/util/mapper/IBZDataAuditMapper.java
+7
-0
IBZUSERMapper.java
...a/src/main/java/cn/ibizlab/util/mapper/IBZUSERMapper.java
+8
-0
ConfigController.java
.../src/main/java/cn/ibizlab/util/rest/ConfigController.java
+72
-0
IBZConfigService.java
...c/main/java/cn/ibizlab/util/service/IBZConfigService.java
+78
-0
IBZDataAuditService.java
...ain/java/cn/ibizlab/util/service/IBZDataAuditService.java
+19
-0
SimpleAuditService.java
...main/java/cn/ibizlab/util/service/SimpleAuditService.java
+329
-0
IBZOperationParameterReader.java
...java/cn/ibizlab/util/web/IBZOperationParameterReader.java
+148
-0
SearchContextHandlerMethodArgumentResolver.java
.../util/web/SearchContextHandlerMethodArgumentResolver.java
+45
-0
pom.xml
ibizlab-boot-starter-parent/pom.xml
+315
-0
pom.xml
ibizlab-boot-starter/pom.xml
+117
-0
CaffeineCacheConfig.java
.../main/java/cn/ibizlab/util/cache/CaffeineCacheConfig.java
+39
-0
RedisCacheConfig.java
...src/main/java/cn/ibizlab/util/cache/RedisCacheConfig.java
+131
-0
CusCaffeineCache.java
...in/java/cn/ibizlab/util/cache/cache/CusCaffeineCache.java
+42
-0
CusRedisCache.java
.../main/java/cn/ibizlab/util/cache/cache/CusRedisCache.java
+31
-0
LayeringCache.java
.../main/java/cn/ibizlab/util/cache/cache/LayeringCache.java
+176
-0
CaffeineCacheManager.java
...ibizlab/util/cache/cacheManager/CaffeineCacheManager.java
+81
-0
LayeringCacheManager.java
...ibizlab/util/cache/cacheManager/LayeringCacheManager.java
+97
-0
RedisMessageListener.java
.../cn/ibizlab/util/cache/listener/RedisMessageListener.java
+70
-0
RedisPublisher.java
...n/java/cn/ibizlab/util/cache/listener/RedisPublisher.java
+39
-0
CustomJacksonSerializer.java
.../cn/ibizlab/util/cache/redis/CustomJacksonSerializer.java
+36
-0
IBZDictFallback.java
...src/main/java/cn/ibizlab/util/client/IBZDictFallback.java
+25
-0
IBZDictFeignClient.java
.../main/java/cn/ibizlab/util/client/IBZDictFeignClient.java
+27
-0
IBZLiteFallback.java
...src/main/java/cn/ibizlab/util/client/IBZLiteFallback.java
+14
-0
IBZLiteFeignClient.java
.../main/java/cn/ibizlab/util/client/IBZLiteFeignClient.java
+18
-0
IBZNotifyFallback.java
...c/main/java/cn/ibizlab/util/client/IBZNotifyFallback.java
+34
-0
IBZNotifyFeignClient.java
...ain/java/cn/ibizlab/util/client/IBZNotifyFeignClient.java
+25
-0
IBZOUFallback.java
...r/src/main/java/cn/ibizlab/util/client/IBZOUFallback.java
+15
-0
IBZOUFeignClient.java
...rc/main/java/cn/ibizlab/util/client/IBZOUFeignClient.java
+21
-0
IBZPayFallback.java
.../src/main/java/cn/ibizlab/util/client/IBZPayFallback.java
+29
-0
IBZPayFeignClient.java
...c/main/java/cn/ibizlab/util/client/IBZPayFeignClient.java
+24
-0
IBZUAAFallback.java
.../src/main/java/cn/ibizlab/util/client/IBZUAAFallback.java
+30
-0
IBZUAAFeignClient.java
...c/main/java/cn/ibizlab/util/client/IBZUAAFeignClient.java
+36
-0
IBZWFFallback.java
...r/src/main/java/cn/ibizlab/util/client/IBZWFFallback.java
+53
-0
IBZWFFeignClient.java
...rc/main/java/cn/ibizlab/util/client/IBZWFFeignClient.java
+46
-0
Catalog.java
...t-starter/src/main/java/cn/ibizlab/util/dict/Catalog.java
+218
-0
CodeItem.java
...-starter/src/main/java/cn/ibizlab/util/dict/CodeItem.java
+58
-0
CodeList.java
...-starter/src/main/java/cn/ibizlab/util/dict/CodeList.java
+224
-0
Option.java
...ot-starter/src/main/java/cn/ibizlab/util/dict/Option.java
+48
-0
FileItem.java
...tarter/src/main/java/cn/ibizlab/util/domain/FileItem.java
+21
-0
MsgBody.java
...starter/src/main/java/cn/ibizlab/util/domain/MsgBody.java
+62
-0
PayTrade.java
...tarter/src/main/java/cn/ibizlab/util/domain/PayTrade.java
+38
-0
RedisChannelTopic.java
...rc/main/java/cn/ibizlab/util/enums/RedisChannelTopic.java
+38
-0
BadRequestAlertException.java
...java/cn/ibizlab/util/errors/BadRequestAlertException.java
+40
-0
CustomParameterizedException.java
.../cn/ibizlab/util/errors/CustomParameterizedException.java
+41
-0
ErrorConstants.java
.../src/main/java/cn/ibizlab/util/errors/ErrorConstants.java
+16
-0
ExceptionTranslator.java
...main/java/cn/ibizlab/util/errors/ExceptionTranslator.java
+137
-0
FieldErrorVM.java
...er/src/main/java/cn/ibizlab/util/errors/FieldErrorVM.java
+33
-0
InternalServerErrorException.java
.../cn/ibizlab/util/errors/InternalServerErrorException.java
+11
-0
CachedBeanCopier.java
...rc/main/java/cn/ibizlab/util/helper/CachedBeanCopier.java
+18
-0
DataObject.java
...rter/src/main/java/cn/ibizlab/util/helper/DataObject.java
+620
-0
Globs.java
...t-starter/src/main/java/cn/ibizlab/util/helper/Globs.java
+195
-0
UniqueNameGenerator.java
...main/java/cn/ibizlab/util/helper/UniqueNameGenerator.java
+17
-0
AppController.java
...ter/src/main/java/cn/ibizlab/util/rest/AppController.java
+85
-0
AuthenticationController.java
...n/java/cn/ibizlab/util/rest/AuthenticationController.java
+58
-0
FileController.java
...er/src/main/java/cn/ibizlab/util/rest/FileController.java
+86
-0
AuthTokenUtil.java
...src/main/java/cn/ibizlab/util/security/AuthTokenUtil.java
+18
-0
AuthenticationEntryPoint.java
...va/cn/ibizlab/util/security/AuthenticationEntryPoint.java
+27
-0
AuthenticationInfo.java
...ain/java/cn/ibizlab/util/security/AuthenticationInfo.java
+19
-0
AuthenticationUser.java
...ain/java/cn/ibizlab/util/security/AuthenticationUser.java
+326
-0
AuthorizationLogin.java
...ain/java/cn/ibizlab/util/security/AuthorizationLogin.java
+43
-0
AuthorizationTokenFilter.java
...va/cn/ibizlab/util/security/AuthorizationTokenFilter.java
+96
-0
SimpleTokenUtil.java
...c/main/java/cn/ibizlab/util/security/SimpleTokenUtil.java
+172
-0
SpringContextHolder.java
...in/java/cn/ibizlab/util/security/SpringContextHolder.java
+41
-0
UAATokenUtil.java
.../src/main/java/cn/ibizlab/util/security/UAATokenUtil.java
+106
-0
AuthenticationUserService.java
...va/cn/ibizlab/util/service/AuthenticationUserService.java
+27
-0
FileService.java
...er/src/main/java/cn/ibizlab/util/service/FileService.java
+12
-0
IBZUAAUserService.java
.../main/java/cn/ibizlab/util/service/IBZUAAUserService.java
+51
-0
RemoteService.java
.../src/main/java/cn/ibizlab/util/service/RemoteService.java
+119
-0
SimpleFileService.java
.../main/java/cn/ibizlab/util/service/SimpleFileService.java
+73
-0
SimpleUserService.java
.../main/java/cn/ibizlab/util/service/SimpleUserService.java
+59
-0
FeignRequestInterceptor.java
...ain/java/cn/ibizlab/util/web/FeignRequestInterceptor.java
+43
-0
pom.xml
pom.xml
+34
-0
未找到文件。
.gitignore
0 → 100644
浏览文件 @
0d372a39
*volumes
*target
.settings
*node_modules
*bin
*.project
*.classpath
*.factorypath
.history
.vscode
.idea
**.iml
*.jar
*.log
.DS_Store
ibizlab-boot-starter-data/pom.xml
0 → 100644
浏览文件 @
0d372a39
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
ibizlab-boot-starter-parent
</artifactId>
<groupId>
cn.ibizlab
</groupId>
<version>
2.4.0-SNAPSHOT
</version>
<relativePath>
../ibizlab-boot-starter-parent/pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
ibizlab-boot-starter-data
</artifactId>
<groupId>
cn.ibizlab
</groupId>
<version>
2.4.0-SNAPSHOT
</version>
<name>
iBizLab Boot Starter Data
</name>
<description>
iBizLab Boot Starter Data
</description>
<dependencies>
<dependency>
<groupId>
cn.ibizlab
</groupId>
<artifactId>
ibizlab-boot-starter
</artifactId>
<version>
${parent.version}
</version>
</dependency>
<!-- 阿里Druid数据源 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
</dependency>
<!-- H2内存库 -->
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-commons
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
dynamic-datasource-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
jobs-spring-boot-starter
</artifactId>
<version>
${baomidou-jobs.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-mongodb
</artifactId>
</dependency>
<!-- Swagger2 -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
</dependency>
<!-- drools -->
<dependency>
<groupId>
org.drools
</groupId>
<artifactId>
drools-compiler
</artifactId>
</dependency>
<dependency>
<groupId>
org.drools
</groupId>
<artifactId>
drools-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.kie
</groupId>
<artifactId>
kie-spring
</artifactId>
</dependency>
<dependency>
<groupId>
org.kie
</groupId>
<artifactId>
kie-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.flowable
</groupId>
<artifactId>
flowable-json-converter
</artifactId>
</dependency>
<dependency>
<groupId>
org.flowable
</groupId>
<artifactId>
flowable-ui-modeler-conf
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-slf4j-impl
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/annotation/Audit.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
FIELD
})
public
@interface
Audit
{
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/annotation/DEField.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
annotation
;
import
cn.ibizlab.util.enums.DEFieldDefaultValueType
;
import
cn.ibizlab.util.enums.DEPredefinedFieldType
;
import
cn.ibizlab.util.enums.DupCheck
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
FIELD
})
public
@interface
DEField
{
/**
* 属性名称
* @return
*/
String
name
()
default
""
;
/**
* 属性名称
* @return
*/
String
value
()
default
""
;
/**
* 是否为数据主键
* @return
*/
boolean
isKeyField
()
default
false
;
/**
* 默认值
* @return
*/
String
defaultValue
()
default
""
;
/**
* 属性类型
* @return
*/
String
fieldType
()
default
""
;
/**
* 默认值类型
* @return
*/
DEFieldDefaultValueType
defaultValueType
()
default
DEFieldDefaultValueType
.
NONE
;
/**
* 预置属性类型
* @return
*/
DEPredefinedFieldType
preType
()
default
DEPredefinedFieldType
.
NONE
;
/**
* 逻辑删除有效值
* @return
*/
String
logicval
()
default
""
;
/**
* 逻辑删除无效值
* @return
*/
String
logicdelval
()
default
""
;
/**
* 代码表
* @return
*/
String
dict
()
default
""
;
/**
* 日期格式化
* @return
*/
String
format
()
default
""
;
/**
* 重复性检查
* @return
*/
DupCheck
dupCheck
()
default
DupCheck
.
NONE
;
/**
* 范围属性
*/
String
dupCheckField
()
default
""
;
boolean
dynaInstTagField
()
default
false
;
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/annotation/VersionCheck.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
METHOD
})
public
@interface
VersionCheck
{
String
entity
();
String
versionfield
();
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/DELogic.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
lombok.Data
;
import
org.flowable.bpmn.model.Process
;
import
org.springframework.core.io.Resource
;
import
org.kie.api.runtime.KieContainer
;
import
java.io.File
;
import
java.io.Serializable
;
import
java.util.List
;
@Data
public
class
DELogic
implements
Serializable
{
String
id
;
String
name
;
Process
process
;
KieContainer
container
;
List
<
DELogic
>
refLogic
;
List
<
Resource
>
refRuleFiles
;
String
md5
;
int
logicMode
;
long
loadedTime
;
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/DTOBase.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonAnyGetter
;
import
com.fasterxml.jackson.annotation.JsonAnySetter
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
cn.ibizlab.util.helper.DEFieldCacheMap
;
import
org.springframework.cglib.beans.BeanMap
;
import
org.springframework.data.annotation.Transient
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
@Data
public
class
DTOBase
implements
Serializable
{
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Set
<
String
>
focusNull
;
public
void
modify
(
String
field
,
Object
val
)
{
if
(
val
==
null
)
{
this
.
getFocusNull
(
true
).
add
(
field
.
toLowerCase
());
}
else
{
this
.
getFocusNull
(
true
).
remove
(
field
.
toLowerCase
());
}
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Set
<
String
>
getFocusNull
()
{
if
(
focusNull
==
null
)
{
focusNull
=
new
HashSet
<>();
}
if
(
focusNull
.
size
()>
0
&&
extensionparams
.
containsKey
(
"dirtyflagenable"
))
{
Set
<
String
>
nocheck
=
new
HashSet
<>();
for
(
String
key:
focusNull
)
{
if
(!
extensionparams
.
containsKey
(
key
+
"dirtyflag"
))
{
nocheck
.
add
(
key
);
}
}
for
(
String
key:
nocheck
)
{
focusNull
.
remove
(
key
);
}
}
return
focusNull
;
}
private
Set
<
String
>
getFocusNull
(
boolean
newflag
)
{
if
(
focusNull
==
null
)
{
focusNull
=
new
HashSet
<>();
}
return
focusNull
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Map
<
String
,
Object
>
extensionparams
=
new
HashMap
<
String
,
Object
>();
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Map
<
String
,
Object
>
getExtensionparams
()
{
return
extensionparams
;
}
public
void
setExtensionparams
(
Map
<
String
,
Object
>
extensionparams
)
{
this
.
extensionparams
=
extensionparams
;
}
@JsonAnyGetter
@JSONField
(
name
=
"_any"
,
unwrapped
=
true
,
serialize
=
true
,
deserialize
=
false
)
public
Map
<
String
,
Object
>
any
()
{
return
extensionparams
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
@Transient
private
BeanMap
map
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
@Transient
private
BeanMap
getMap
()
{
if
(
map
==
null
)
{
map
=
BeanMap
.
create
(
this
);
}
return
map
;
}
public
Object
get
(
String
field
)
{
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(!
ObjectUtils
.
isEmpty
(
fieldRealName
))
{
return
getMap
().
get
(
fieldRealName
);
}
else
{
return
this
.
extensionparams
.
get
(
field
.
toLowerCase
());
}
}
@JsonAnySetter
@JSONField
(
name
=
"_any"
,
unwrapped
=
true
,
serialize
=
false
,
deserialize
=
true
)
public
void
set
(
String
field
,
Object
value
)
{
field
=
field
.
toLowerCase
();
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(!
ObjectUtils
.
isEmpty
(
fieldRealName
))
{
if
(
value
==
null
)
{
getMap
().
put
(
fieldRealName
,
null
);
}
else
{
getMap
().
put
(
fieldRealName
,
DEFieldCacheMap
.
fieldValueOf
(
this
.
getClass
(),
fieldRealName
,
value
));
}
}
else
{
this
.
extensionparams
.
put
(
field
.
toLowerCase
(),
value
);
}
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/DTOClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
public
class
DTOClient
extends
DTOBase
{
@Override
public
void
modify
(
String
field
,
Object
val
)
{
getExtensionparams
().
put
(
"dirtyflagenable"
,
true
);
if
(
val
==
null
){
this
.
getFocusNull
().
add
(
field
.
toLowerCase
());
getExtensionparams
().
put
(
field
.
toLowerCase
()+
"dirtyflag"
,
true
);
}
else
{
this
.
getFocusNull
().
remove
(
field
.
toLowerCase
());
getExtensionparams
().
remove
(
field
.
toLowerCase
()+
"dirtyflag"
);
}
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/EntityBase.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
cn.ibizlab.util.helper.DEFieldCacheMap
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.fasterxml.jackson.annotation.JsonAnyGetter
;
import
com.fasterxml.jackson.annotation.JsonAnySetter
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
org.springframework.cglib.beans.BeanMap
;
import
org.springframework.data.annotation.Transient
;
import
org.springframework.util.AlternativeJdkIdGenerator
;
import
org.springframework.util.ObjectUtils
;
import
java.io.Serializable
;
import
java.lang.reflect.Field
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
public
class
EntityBase
implements
Serializable
{
@JsonIgnore
@JSONField
(
serialize
=
false
)
@TableField
(
exist
=
false
)
@Transient
private
Set
<
String
>
focusNull
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
@Transient
public
Set
<
String
>
getFocusNull
()
{
if
(
focusNull
==
null
)
{
focusNull
=
new
HashSet
<>();
}
return
focusNull
;
}
public
void
setFocusNull
(
Set
<
String
>
focusNull
)
{
this
.
focusNull
=
focusNull
;
}
public
void
modify
(
String
field
,
Object
val
)
{
}
public
Serializable
getDefaultKey
(
boolean
gen
)
{
String
Id
=(
new
AlternativeJdkIdGenerator
()).
generateId
().
toString
();
return
gen
?
Id
.
replace
(
"-"
,
""
):
Id
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
@TableField
(
exist
=
false
)
@Transient
private
BeanMap
map
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
@Transient
private
BeanMap
getMap
()
{
if
(
map
==
null
)
{
map
=
BeanMap
.
create
(
this
);
}
return
map
;
}
@JsonIgnore
@TableField
(
exist
=
false
)
@JSONField
(
serialize
=
false
)
@Transient
private
Map
<
String
,
Object
>
extensionparams
=
new
HashMap
<
String
,
Object
>();
@JsonIgnore
@JSONField
(
serialize
=
false
)
@Transient
public
Map
<
String
,
Object
>
getExtensionparams
()
{
return
extensionparams
;
}
public
void
setExtensionparams
(
Map
<
String
,
Object
>
extensionparams
)
{
this
.
extensionparams
=
extensionparams
;
}
public
Object
get
(
String
field
)
{
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(!
ObjectUtils
.
isEmpty
(
fieldRealName
))
{
return
getMap
().
get
(
fieldRealName
);
}
else
{
return
this
.
extensionparams
.
get
(
field
.
toLowerCase
());
}
}
@JsonAnyGetter
@JSONField
(
name
=
"_any"
,
unwrapped
=
true
,
serialize
=
true
,
deserialize
=
false
)
public
Map
<
String
,
Object
>
any
()
{
return
extensionparams
;
}
@JsonAnySetter
@JSONField
(
name
=
"_any"
,
unwrapped
=
true
,
serialize
=
false
,
deserialize
=
true
)
public
void
set
(
String
field
,
Object
value
)
{
field
=
field
.
toLowerCase
();
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(!
ObjectUtils
.
isEmpty
(
fieldRealName
))
{
if
(
value
==
null
)
{
getMap
().
put
(
fieldRealName
,
null
);
}
else
{
getMap
().
put
(
fieldRealName
,
DEFieldCacheMap
.
fieldValueOf
(
this
.
getClass
(),
fieldRealName
,
value
));
}
}
else
{
this
.
extensionparams
.
put
(
field
.
toLowerCase
(),
value
);
}
}
/**
* 复制当前对象数据到目标对象
* @param targetEntity 目标数据对象
* @param bIncEmpty 是否包括空值
* @param <T>
* @return
*/
public
<
T
>
T
copyTo
(
T
targetEntity
,
boolean
bIncEmpty
){
if
(
targetEntity
instanceof
EntityBase
){
EntityBase
target
=
(
EntityBase
)
targetEntity
;
Hashtable
<
String
,
Field
>
sourceFields
=
DEFieldCacheMap
.
getFieldMap
(
this
.
getClass
());
for
(
String
field
:
sourceFields
.
keySet
()){
Object
value
=
this
.
get
(
field
);
if
(
!
ObjectUtils
.
isEmpty
(
value
)
||
ObjectUtils
.
isEmpty
(
value
)
&&
getFocusNull
().
contains
(
field
)
&&
bIncEmpty
){
target
.
set
(
field
,
value
);
}
}
}
return
targetEntity
;
}
/**
* 重置当前数据对象属性值
* @param field
*/
public
void
reset
(
String
field
){
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/EntityClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
public
class
EntityClient
extends
EntityBase
{
@Override
public
void
modify
(
String
field
,
Object
val
)
{
getExtensionparams
().
put
(
"dirtyflagenable"
,
true
);
if
(
val
==
null
){
this
.
getFocusNull
().
add
(
field
.
toLowerCase
());
getExtensionparams
().
put
(
field
.
toLowerCase
()+
"dirtyflag"
,
true
);
}
else
{
this
.
getFocusNull
().
remove
(
field
.
toLowerCase
());
getExtensionparams
().
remove
(
field
.
toLowerCase
()+
"dirtyflag"
);
}
}
@Override
public
void
reset
(
String
field
)
{
if
(!
ObjectUtils
.
isEmpty
(
field
)){
String
resetField
=
field
.
toLowerCase
();
this
.
set
(
resetField
,
null
);
this
.
getFocusNull
().
remove
(
resetField
);
getExtensionparams
().
remove
(
resetField
+
"dirtyflag"
);
}
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/EntityMP.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
public
class
EntityMP
extends
EntityBase
{
public
UpdateWrapper
getUpdateWrapper
(
boolean
clean
)
{
UpdateWrapper
wrapper
=
new
UpdateWrapper
();
for
(
String
nullField:
getFocusNull
())
{
wrapper
.
set
(
nullField
,
null
);
}
if
(
clean
)
{
getFocusNull
().
clear
();
}
return
wrapper
;
}
@Override
public
void
modify
(
String
field
,
Object
val
)
{
if
(
val
==
null
)
{
this
.
getFocusNull
().
add
(
field
.
toLowerCase
());
}
else
{
this
.
getFocusNull
().
remove
(
field
.
toLowerCase
());
}
}
@Override
public
void
reset
(
String
field
){
if
(!
ObjectUtils
.
isEmpty
(
field
)){
String
resetField
=
field
.
toLowerCase
();
this
.
set
(
resetField
,
null
);
getFocusNull
().
remove
(
resetField
);
}
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/EntityMongo.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
public
class
EntityMongo
extends
EntityBase
{
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/IBZConfig.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.*
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.sql.Timestamp
;
@TableName
(
value
=
"IBZCFG"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
IBZConfig
{
/**
* 配置标识
* 系统+配置类型+引用对象+用户标识联合主键
*/
@TableId
private
String
cfgId
;
/**
* 系统标识
*/
private
String
systemId
;
/**
* 配置类型
* 门户配置/表格自定义配置/自定义查询...消费方自定义
*/
private
String
cfgType
;
/**
* 引用对象
* 门户页标识/具体表格视图标识...消费方具体使用位置的标识
*/
private
String
targetType
;
/**
* 用户标识
* 默认当前登录者
*/
private
String
userId
;
/**
* 配置
* JSONObject
*/
private
String
cfg
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
locale
=
"zh"
,
timezone
=
"GMT+8"
)
@JSONField
(
format
=
"yyyy-MM-dd HH:mm:ss"
)
private
Timestamp
updateDate
;
public
String
getCfgId
()
{
if
(
ObjectUtils
.
isEmpty
(
cfgId
)&&
(!(
ObjectUtils
.
isEmpty
(
systemId
)))&&
(!(
ObjectUtils
.
isEmpty
(
cfgType
)))&&
(!(
ObjectUtils
.
isEmpty
(
targetType
)))&&
(!(
ObjectUtils
.
isEmpty
(
userId
))))
{
cfgId
=
DigestUtils
.
md5DigestAsHex
((
systemId
+
"||"
+
cfgType
+
"||"
+
targetType
+
"||"
+
userId
).
getBytes
());
}
return
cfgId
;
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/IBZDataAudit.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
import
java.util.Objects
;
/**
* 实体[DataAudit] 数据对象
*/
@TableName
(
value
=
"IBZDATAAUDIT"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Data
public
class
IBZDataAudit
implements
Serializable
{
@TableId
(
value
=
"dataauditid"
,
type
=
IdType
.
UUID
)
//指定主键生成策略
private
String
dataauditid
;
private
String
dataauditname
;
private
String
oppersonid
;
private
String
oppersonname
;
private
String
audittype
;
private
Timestamp
optime
;
private
String
ipaddress
;
private
String
auditinfo
;
private
Object
auditobjectdata
;
private
String
auditobject
;
private
int
isdatachanged
;
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/IBZUSER.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
java.sql.Timestamp
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
import
javax.validation.constraints.Size
;
import
java.io.Serializable
;
/**
* 实体[IBZUSER] 数据对象
*/
@TableName
(
value
=
"IBZUSER"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Data
public
class
IBZUSER
implements
Serializable
{
@Size
(
min
=
0
,
max
=
100
,
message
=
"[用户标识]长度必须在[100]以内!"
)
@TableId
(
value
=
"userid"
,
type
=
IdType
.
INPUT
)
//指定主键生成策略
private
String
userid
;
@Size
(
min
=
0
,
max
=
200
,
message
=
"[用户全局名]长度必须在[200]以内!"
)
private
String
username
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[用户姓名]长度必须在[100]以内!"
)
private
String
personname
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[用户代码]长度必须在[100]以内!"
)
private
String
usercode
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[登录别名]长度必须在[100]以内!"
)
private
String
loginname
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[登录密码]长度必须在[100]以内!"
)
private
String
password
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[区属]长度必须在[100]以内!"
)
private
String
domains
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[主部门id]长度必须在[100]以内!"
)
private
String
mdeptid
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[主部门代码]长度必须在[100]以内!"
)
private
String
mdeptcode
;
@Size
(
min
=
0
,
max
=
200
,
message
=
"[主部门名称]长度必须在[200]以内!"
)
private
String
mdeptname
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[业务编码]长度必须在[100]以内!"
)
private
String
bcode
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[岗位id]长度必须在[100]以内!"
)
private
String
postid
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[岗位代码]长度必须在[100]以内!"
)
private
String
postcode
;
@Size
(
min
=
0
,
max
=
200
,
message
=
"[岗位名称]长度必须在[200]以内!"
)
private
String
postname
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[单位id]长度必须在[100]以内!"
)
private
String
orgid
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[单位代码]长度必须在[100]以内!"
)
private
String
orgcode
;
@Size
(
min
=
0
,
max
=
200
,
message
=
"[单位名称]长度必须在[200]以内!"
)
private
String
orgname
;
@Size
(
min
=
0
,
max
=
36
,
message
=
"[昵称]长度必须在[36]以内!"
)
private
String
nickname
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[邮箱]长度必须在[100]以内!"
)
private
String
email
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[通信账号]长度必须在[100]以内!"
)
private
String
avatar
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[联系电话]长度必须在[100]以内!"
)
private
String
phone
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[保留字段]长度必须在[100]以内!"
)
private
String
reserver
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[头像]长度必须在[100]以内!"
)
private
String
usericon
;
@Size
(
min
=
0
,
max
=
10
,
message
=
"[性别]长度必须在[10]以内!"
)
private
String
sex
;
private
Timestamp
birthday
;
@Size
(
min
=
0
,
max
=
36
,
message
=
"[证件号码]长度必须在[36]以内!"
)
private
String
certcode
;
@Size
(
min
=
0
,
max
=
200
,
message
=
"[地址]长度必须在[200]以内!"
)
private
String
addr
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[主题]长度必须在[100]以内!"
)
private
String
theme
;
@Size
(
min
=
0
,
max
=
100
,
message
=
"[语言]长度必须在[100]以内!"
)
private
String
lang
;
@Size
(
min
=
0
,
max
=
10
,
message
=
"[字号]长度必须在[10]以内!"
)
private
String
fontsize
;
@Size
(
min
=
0
,
max
=
500
,
message
=
"[备注]长度必须在[500]以内!"
)
private
String
memo
;
private
int
superuser
;
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/LiquibaseProp.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Data
@Component
@ConfigurationProperties
(
prefix
=
"spring.datasource.dynamic.datasource.master"
)
public
class
LiquibaseProp
{
private
String
url
;
private
String
username
;
private
String
password
;
private
String
isSyncDBSchema
;
private
String
defaultSchema
;
private
String
conf
;
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/MappingBase.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
java.util.List
;
/**
* 实体转换器基类
* @param <D> domainDTO
* @param <E> domain
*/
public
interface
MappingBase
<
D
,
E
>
{
/**
* dto转domain
* @param dto
* @return
*/
E
toDomain
(
D
dto
);
/**
* domain转dto
* @param entity
* @return
*/
D
toDto
(
E
entity
);
/**
* dto集合转domain集合
* @param dtoList
* @return
*/
List
<
E
>
toDomain
(
List
<
D
>
dtoList
);
/**
* domain集合转dto集合
* @param entityList
* @return
*/
List
<
D
>
toDto
(
List
<
E
>
entityList
);
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/enums/DEFieldDefaultValueType.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
enums
;
/**
* 实体属性默认值类型
*/
public
enum
DEFieldDefaultValueType
{
/**
* 用户全局对象
*/
SESSION
,
/**
* 系统全局对象
*/
APPLICATION
,
/**
* 唯一编码
*/
UNIQUEID
,
/**
* 网页请求
*/
CONTEXT
,
/**
* 数据对象属性
*/
PARAM
,
/**
* 当前时间
*/
CURTIME
,
/**
* 当前操作用户(编号)
*/
OPERATOR
,
/**
* 当前操作用户(名称)
*/
OPERATORNAME
,
/**
* 当前应用数据
*/
APPDATA
,
/**
* 默认值
*/
NONE
,
/**
* 用户自定义
*/
USER
,
/**
* 用户自定义2
*/
USER2
,
/**
* 用户自定义3
*/
USER3
,
/**
* 用户自定义4
*/
USER4
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/enums/DEPredefinedFieldType.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
enums
;
/**
* 实体属性预定义类型
*/
public
enum
DEPredefinedFieldType
{
/**
* 创建人标识
*/
CREATEMAN
,
/**
* 创建人名称
*/
CREATEMANNAME
,
/**
* 更新人标识
*/
UPDATEMAN
,
/**
* 更新人名称
*/
UPDATEMANNAME
,
/**
* 创建时间
*/
CREATEDATE
,
/**
* 更新时间
*/
UPDATEDATE
,
/**
* 组织机构标识
*/
ORGID
,
/**
* 组织机构名称
*/
ORGNAME
,
/**
* 部门标识
*/
ORGSECTORID
,
/**
* 部门名称
*/
ORGSECTORNAME
,
/**
* 逻辑有效
*/
LOGICVALID
,
/**
* 排序
*/
ORDERVALUE
,
/**
* 不处理
*/
NONE
,
/**
* 动态父类型
*/
PARENTTYPE
,
/**
* 动态父标识
*/
PARENTID
,
/**
* 动态父名称
*/
PARENTNAME
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/enums/DupCheck.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
enums
;
/**
* 属性重复值检查
*/
public
enum
DupCheck
{
/**
* 不检查
*/
NONE
,
/**
* 全部检查
*/
ALL
,
/**
* 非空检查
*/
NOTNULL
,
/**
* 指定范围检查
*/
RANGE
,
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/filter/ISearchContext.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
filter
;
public
interface
ISearchContext
{
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/filter/QueryFilter.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
filter
;
import
com.fasterxml.jackson.annotation.*
;
import
org.springframework.data.annotation.Transient
;
import
java.util.*
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
public
class
QueryFilter
{
public
static
QueryFilter
createQuery
()
{
QueryFilter
queryFilter
=
new
QueryFilter
();
return
queryFilter
;
}
public
QueryFilter
eq
(
String
column
,
Object
value
)
{
return
op
(
column
,
SegmentCond
.
eq
(
value
));
}
public
QueryFilter
ne
(
String
column
,
Object
value
)
{
return
op
(
column
,
SegmentCond
.
ne
(
value
));
}
public
QueryFilter
gt
(
String
column
,
Object
value
)
{
return
op
(
column
,
SegmentCond
.
gt
(
value
));
}
public
QueryFilter
ge
(
String
column
,
Object
value
)
{
return
op
(
column
,
SegmentCond
.
ge
(
value
));
}
public
QueryFilter
lt
(
String
column
,
Object
value
)
{
return
op
(
column
,
SegmentCond
.
lt
(
value
));
}
public
QueryFilter
le
(
String
column
,
Object
value
)
{
return
op
(
column
,
SegmentCond
.
le
(
value
));
}
public
QueryFilter
isnull
(
String
column
)
{
return
op
(
column
,
SegmentCond
.
isnull
());
}
public
QueryFilter
isnotnull
(
String
column
)
{
return
op
(
column
,
SegmentCond
.
isnotnull
());
}
public
QueryFilter
in
(
String
column
,
Collection
value
)
{
return
op
(
column
,
SegmentCond
.
in
(
value
));
}
public
QueryFilter
notin
(
String
column
,
Collection
value
)
{
return
op
(
column
,
SegmentCond
.
notin
(
value
));
}
public
QueryFilter
like
(
String
column
,
String
value
)
{
return
op
(
column
,
SegmentCond
.
like
(
value
));
}
public
QueryFilter
startsWith
(
String
column
,
String
value
)
{
return
op
(
column
,
SegmentCond
.
startsWith
(
value
));
}
public
QueryFilter
endsWith
(
String
column
,
String
value
)
{
return
op
(
column
,
SegmentCond
.
endsWith
(
value
));
}
public
QueryFilter
between
(
String
column
,
Object
from
,
Object
to
)
{
return
op
(
column
,
SegmentCond
.
between
(
from
,
to
));
}
@JsonIgnore
@Transient
private
Map
<
String
,
SegmentCond
>
map
;
private
Map
<
String
,
SegmentCond
>
getMap
()
{
if
(
map
==
null
)
{
map
=
new
LinkedHashMap
<>();
}
return
map
;
}
@JsonAnyGetter
public
Map
<
String
,
SegmentCond
>
any
()
{
return
getMap
();
}
@JsonAnySetter
public
void
set
(
String
column
,
SegmentCond
value
)
{
getMap
().
put
(
column
,
value
);
}
@JsonProperty
(
index
=
999
)
private
List
<
QueryFilter
>
$or
;
public
List
<
QueryFilter
>
get$or
()
{
return
$or
;
}
public
void
set$or
(
List
<
QueryFilter
>
$or
)
{
this
.
$or
=
$or
;
}
public
QueryFilter
or
(
QueryFilter
...
ors
)
{
if
(
$or
==
null
)
{
$or
=
new
ArrayList
();
}
Collections
.
addAll
(
$or
,
ors
);
return
this
;
}
@JsonProperty
(
index
=
999
)
private
List
<
QueryFilter
>
$and
;
public
List
<
QueryFilter
>
get$and
()
{
return
$and
;
}
public
void
set$and
(
List
<
QueryFilter
>
$and
)
{
this
.
$and
=
$and
;
}
public
QueryFilter
and
(
QueryFilter
...
ands
)
{
if
(
$and
==
null
)
{
$and
=
new
ArrayList
();
}
Collections
.
addAll
(
$and
,
ands
);
return
this
;
}
@Override
public
String
toString
()
{
return
"QueryFilter{"
+
"map="
+
map
+
", $or="
+
$or
+
'}'
;
}
private
QueryFilter
op
(
String
column
,
SegmentCond
segmentCond
)
{
if
(
this
.
getMap
().
containsKey
(
column
))
{
((
SegmentCond
)
this
.
getMap
().
get
(
column
)).
getMap
().
putAll
(
segmentCond
.
getMap
());
}
else
{
this
.
getMap
().
put
(
column
,
segmentCond
);
}
return
this
;
}
public
static
class
SegmentCond
{
@JsonIgnore
@Transient
private
Map
<
String
,
Object
>
map
;
@Override
public
String
toString
()
{
return
"SegmentCond{"
+
"map="
+
map
+
'}'
;
}
private
Map
<
String
,
Object
>
getMap
()
{
if
(
map
==
null
)
{
map
=
new
LinkedHashMap
<>();
}
return
map
;
}
@JsonAnyGetter
public
Map
<
String
,
Object
>
any
()
{
return
getMap
();
}
@JsonAnySetter
public
void
set
(
String
column
,
Object
value
)
{
getMap
().
put
(
column
,
value
);
}
public
static
SegmentCond
eq
(
Object
value
)
{
return
op
(
Segment
.
EQ
,
value
);
}
public
static
SegmentCond
ne
(
Object
value
)
{
return
op
(
Segment
.
NE
,
value
);
}
public
static
SegmentCond
gt
(
Object
value
)
{
return
op
(
Segment
.
GT
,
value
);
}
public
static
SegmentCond
ge
(
Object
value
)
{
return
op
(
Segment
.
GE
,
value
);
}
public
static
SegmentCond
lt
(
Object
value
)
{
return
op
(
Segment
.
LT
,
value
);
}
public
static
SegmentCond
le
(
Object
value
)
{
return
op
(
Segment
.
LE
,
value
);
}
public
static
SegmentCond
isnull
()
{
return
op
(
Segment
.
IS_NULL
,
true
);
}
public
static
SegmentCond
isnotnull
()
{
return
op
(
Segment
.
IS_NOT_NULL
,
true
);
}
public
static
SegmentCond
in
(
Collection
value
)
{
return
op
(
Segment
.
IN
,
value
);
}
public
static
SegmentCond
notin
(
Collection
value
)
{
return
op
(
Segment
.
NOTIN
,
value
);
}
public
static
SegmentCond
like
(
String
value
)
{
return
op
(
Segment
.
LIKE
,
value
);
}
public
static
SegmentCond
startsWith
(
String
value
)
{
return
op
(
Segment
.
LEFTLIKE
,
value
);
}
public
static
SegmentCond
endsWith
(
String
value
)
{
return
op
(
Segment
.
RIGHTLIKE
,
value
);
}
public
static
SegmentCond
between
(
Object
from
,
Object
to
)
{
return
op
(
Segment
.
GE
,
from
).
op
(
Segment
.
LT
,
to
);
}
private
static
SegmentCond
op
(
Segment
segment
,
Object
value
)
{
SegmentCond
segmentCond
=
new
SegmentCond
();
segmentCond
.
getMap
().
put
(
segment
.
keyword
,
value
);
return
segmentCond
;
}
}
public
enum
Segment
{
AND
(
"$and"
),
OR
(
"$or"
),
EQ
(
"$eq"
),
NE
(
"$ne"
),
GT
(
"$gt"
),
GE
(
"$gte"
),
LT
(
"$lt"
),
LE
(
"$lte"
),
IS_NULL
(
"$null"
),
IS_NOT_NULL
(
"$notNull"
),
IN
(
"$in"
),
NOTIN
(
"$notIn"
),
LIKE
(
"$like"
),
LEFTLIKE
(
"$startsWith"
),
RIGHTLIKE
(
"$endsWith"
),
EXISTS
(
"$exists"
),
NOTEXISTS
(
"$notExists"
);
private
final
String
keyword
;
Segment
(
final
String
keyword
)
{
this
.
keyword
=
keyword
;
}
}
/*
SQL: (field1>1 and field2='3' and (field3 like "a" or (field4 is not null and field5 in ['11','12']) )
JAVA: QueryFilter filter=QueryFilter.createQuery()
.gt("field1",1)
.eq("field2",'3')
.or(QueryFilter.createQuery().like("field3","a")
,QueryFilter.createQuery().isnotnull("field4").in("field5",Arrays.asList("11","12")));
JSON: {
"$or":[
{
"field3":{"$like":"a"}
},
{
"field4":{ "$notNull":true},
"field5":{"$in":["11","12"]}
}],
"field1":{"$gt":1},
"field2":{"$eq":"3" }
}
*/
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/filter/QueryWrapperContext.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
filter
;
import
cn.ibizlab.util.helper.DEFieldCacheMap
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.lang.reflect.ParameterizedType
;
import
java.util.*
;
import
java.util.function.Consumer
;
@Slf4j
@Data
public
class
QueryWrapperContext
<
T
>
extends
SearchContextBase
implements
ISearchContext
{
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
QueryWrapper
<
T
>
selectCond
=
new
QueryWrapper
<
T
>();
/**
* 解析查询上下文中的参数,构建mybatis-plus分页对象
* @return
*/
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Page
getPages
(){
Page
page
;
List
<
String
>
asc_fieldList
=
new
ArrayList
<>();
List
<
String
>
desc_fieldList
=
new
ArrayList
<>();
int
currentPage
=
getPageable
().
getPageNumber
();
int
pageSize
=
getPageable
().
getPageSize
();
//构造mybatis-plus分页
if
(
ObjectUtils
.
isEmpty
(
currentPage
)
||
ObjectUtils
.
isEmpty
(
pageSize
))
{
page
=
new
Page
(
1
,
Short
.
MAX_VALUE
);
}
else
{
page
=
new
Page
(
currentPage
+
1
,
pageSize
);
}
//构造mybatis-plus排序
Sort
sort
=
getPageable
().
getSort
();
Iterator
<
Sort
.
Order
>
it_sort
=
sort
.
iterator
();
if
(
ObjectUtils
.
isEmpty
(
it_sort
))
{
return
page
;
}
ParameterizedType
parameterizedType
=
(
ParameterizedType
)
getClass
().
getGenericSuperclass
();
Class
<
T
>
type
=
(
Class
<
T
>)
parameterizedType
.
getActualTypeArguments
()[
0
];
while
(
it_sort
.
hasNext
())
{
Sort
.
Order
sort_order
=
it_sort
.
next
();
if
(
sort_order
.
getDirection
()==
Sort
.
Direction
.
ASC
){
asc_fieldList
.
add
(
DEFieldCacheMap
.
getFieldColumnName
(
type
,
sort_order
.
getProperty
()));
}
else
if
(
sort_order
.
getDirection
()==
Sort
.
Direction
.
DESC
){
desc_fieldList
.
add
(
DEFieldCacheMap
.
getFieldColumnName
(
type
,
sort_order
.
getProperty
()));
}
}
if
(
asc_fieldList
.
size
()>
0
){
page
.
setAscs
(
asc_fieldList
);
}
if
(
desc_fieldList
.
size
()>
0
){
page
.
setDescs
(
desc_fieldList
);
}
return
page
;
}
public
QueryWrapper
<
T
>
getSearchCond
(){
return
this
.
selectCond
;
}
/**
* 填充自定义查询条件
* @return
*/
public
QueryWrapper
<
T
>
getSelectCond
()
{
if
(!
ObjectUtils
.
isEmpty
(
filter
)){
Consumer
queryWrapper
=
parseQueryFilter
(
filter
);
if
(!
ObjectUtils
.
isEmpty
(
queryWrapper
)){
selectCond
.
and
(
queryWrapper
);
}
}
return
selectCond
;
}
/**
* 解析自定义查询条件
* @param queryFilter
* @return
*/
private
Consumer
<
QueryWrapper
<
T
>>
parseQueryFilter
(
QueryFilter
queryFilter
){
if
(
queryFilter
.
any
().
size
()==
0
&&
queryFilter
.
get
$or
()==
null
&&
queryFilter
.
get
$and
()==
null
)
{
return
null
;
}
Consumer
<
QueryWrapper
<
T
>>
consumer
=
queryWrapper
->
{
Consumer
fieldConsumer
=
parseFieldMap
(
queryFilter
.
any
());
Consumer
orConsumer
=
parseOrQueryFilter
(
queryFilter
.
get
$or
());
Consumer
andConsumer
=
parseAndQueryFilter
(
queryFilter
.
get
$and
());
if
(!
ObjectUtils
.
isEmpty
(
fieldConsumer
)){
queryWrapper
.
and
(
fieldConsumer
);
}
if
(!
ObjectUtils
.
isEmpty
(
orConsumer
)){
queryWrapper
.
and
(
orConsumer
);
}
if
(!
ObjectUtils
.
isEmpty
(
andConsumer
)){
queryWrapper
.
and
(
andConsumer
);
}
};
return
consumer
;
}
/**
* 解析自定义条件[or]
* @param queryFilters
* @return
*/
private
Consumer
<
QueryWrapper
<
T
>>
parseOrQueryFilter
(
List
<
QueryFilter
>
queryFilters
)
{
if
(
queryFilters
==
null
||
queryFilters
.
size
()==
0
)
return
null
;
Consumer
<
QueryWrapper
<
T
>>
consumer
=
queryWrapper
->
{
for
(
QueryFilter
queryFilter:
queryFilters
){
Consumer
tempQueryWrapper
=
parseQueryFilter
(
queryFilter
);
queryWrapper
.
or
(
tempQueryWrapper
);
}
};
return
consumer
;
}
/**
* 解析自定义条件[and]
* @param queryFilters
* @return
*/
private
Consumer
<
QueryWrapper
<
T
>>
parseAndQueryFilter
(
List
<
QueryFilter
>
queryFilters
)
{
if
(
queryFilters
==
null
||
queryFilters
.
size
()==
0
)
{
return
null
;
}
Consumer
<
QueryWrapper
<
T
>>
consumer
=
queryWrapper
->
{
for
(
QueryFilter
queryFilter:
queryFilters
){
Consumer
tempQueryWrapper
=
parseQueryFilter
(
queryFilter
);
queryWrapper
.
and
(
tempQueryWrapper
);
}
};
return
consumer
;
}
/**
* 解析自定义条件[字段条件]
* @param fieldMap
* @return
*/
private
Consumer
<
QueryWrapper
<
T
>>
parseFieldMap
(
Map
<
String
,
QueryFilter
.
SegmentCond
>
fieldMap
)
{
if
(
fieldMap
.
size
()==
0
)
{
return
null
;
}
Consumer
<
QueryWrapper
<
T
>>
consumer
=
queryWrapper
->
{
for
(
Map
.
Entry
<
String
,
QueryFilter
.
SegmentCond
>
field:
fieldMap
.
entrySet
()){
String
fieldName
=
field
.
getKey
();
QueryFilter
.
SegmentCond
segmentCond
=
field
.
getValue
();
Map
<
String
,
Object
>
segmentCondMap
=
segmentCond
.
any
();
for
(
Map
.
Entry
<
String
,
Object
>
fieldCond:
segmentCondMap
.
entrySet
()){
Object
value
=
fieldCond
.
getValue
();
switch
(
fieldCond
.
getKey
()){
case
"$eq"
:
queryWrapper
.
eq
(
fieldName
,
value
);
break
;
case
"$ne"
:
queryWrapper
.
ne
(
fieldName
,
value
);
break
;
case
"$gt"
:
queryWrapper
.
gt
(
fieldName
,
value
);
break
;
case
"$gte"
:
queryWrapper
.
ge
(
fieldName
,
value
);
break
;
case
"$lt"
:
queryWrapper
.
lt
(
fieldName
,
value
);
break
;
case
"$lte"
:
queryWrapper
.
le
(
fieldName
,
value
);
break
;
case
"$null"
:
queryWrapper
.
isNull
(
fieldName
);
break
;
case
"$notNull"
:
queryWrapper
.
isNotNull
(
fieldName
);
break
;
case
"$in"
:
queryWrapper
.
in
(
fieldName
,(
Collection
)
value
);
break
;
case
"$notIn"
:
queryWrapper
.
notIn
(
fieldName
,(
Collection
)
value
);
break
;
case
"$like"
:
queryWrapper
.
like
(
fieldName
,
value
);
break
;
case
"$startsWith"
:
queryWrapper
.
likeRight
(
fieldName
,
value
);
break
;
case
"$endsWith"
:
queryWrapper
.
likeLeft
(
fieldName
,
value
);
break
;
case
"$exists"
:
break
;
case
"$notExists"
:
break
;
}
}
}
};
return
consumer
;
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/filter/SearchContextBase.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
filter
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
com.fasterxml.jackson.annotation.JsonAnyGetter
;
import
com.fasterxml.jackson.annotation.JsonAnySetter
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.PageRequest
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.ObjectUtils
;
import
java.util.*
;
@Slf4j
@Data
public
class
SearchContextBase
implements
ISearchContext
{
/**
* 自定义查询条件
*/
@JsonProperty
(
"customcond"
)
public
String
customCond
;
/**
* 自定义查询参数
*/
@JsonProperty
(
"customparams"
)
public
String
customParams
;
/**
* 快速搜索
*/
@JsonProperty
(
"query"
)
public
String
query
;
/**
* 条件表达式
*/
@JsonProperty
(
"filter"
)
public
QueryFilter
filter
;
/**
* 数据查询
*/
public
List
dataQueryList
;
/**
* 当前页数
*/
public
int
page
=
0
;
/**
* 每页显示条数
*/
public
int
size
=
20
;
/**
* 排序
*/
public
String
sort
;
/**
* 排序对象
*/
@JsonIgnore
public
Sort
pageSort
;
/**
* 工作流步骤标识
*/
public
String
userTaskId
;
/**
* 工作流流程标识
*/
public
String
processDefinitionKey
;
/**
* 工作流标识
*/
@JsonProperty
(
"srfwf"
)
public
String
srfWF
;
/**
* 获取工作流步骤标识
*/
public
String
getUserTaskId
()
{
if
(
ObjectUtils
.
isEmpty
(
userTaskId
)){
Object
taskId
=
params
.
get
(
"usertaskid"
);
return
ObjectUtils
.
isEmpty
(
taskId
)?
null
:
String
.
valueOf
(
taskId
);
}
else
{
return
userTaskId
;
}
}
/**
* 获取工作流流程标识
* @return
*/
public
String
getProcessDefinitionKey
()
{
if
(
ObjectUtils
.
isEmpty
(
processDefinitionKey
)){
Object
processKey
=
params
.
get
(
"processdefinitionkey"
);
return
ObjectUtils
.
isEmpty
(
processKey
)?
null
:
String
.
valueOf
(
processKey
);
}
else
{
return
processDefinitionKey
;
}
}
/**
* 获取分页参数
* @return
*/
public
Pageable
getPageable
()
{
if
(
ObjectUtils
.
isEmpty
(
pageSort
))
{
return
PageRequest
.
of
(
page
,
size
);
}
else
{
return
PageRequest
.
of
(
page
,
size
,
pageSort
);
}
}
/**
* 设置排序值
* @param strSort
*/
public
void
setSort
(
String
strSort
)
{
this
.
sort
=
strSort
;
if
(!
ObjectUtils
.
isEmpty
(
strSort
)){
String
sortArr
[]=
strSort
.
split
(
","
);
String
sortField
=
sortArr
[
0
];
String
sortDirection
=
sortArr
[
1
];
if
(
sortDirection
.
equalsIgnoreCase
(
"asc"
)){
this
.
pageSort
=
Sort
.
by
(
Sort
.
Direction
.
ASC
,
sortField
);
}
else
if
(
sortDirection
.
equalsIgnoreCase
(
"desc"
)){
this
.
pageSort
=
Sort
.
by
(
Sort
.
Direction
.
DESC
,
sortField
);
}
}
}
/**
* 上下文参数
*/
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>()
;
/**
* 获取数据上下文
* @return
*/
public
Map
<
String
,
Object
>
getDatacontext
()
{
return
params
;
}
/**
* 获取网页请求上下文
* @return
*/
public
Map
<
String
,
Object
>
getWebcontext
()
{
return
params
;
}
/**
* 获取用户上下文
* @return
*/
@JsonIgnore
public
Map
<
String
,
Object
>
getSessioncontext
()
{
return
AuthenticationUser
.
getAuthenticationUser
().
getSessionParams
();
}
@JsonAnyGetter
public
Map
<
String
,
Object
>
any
()
{
return
params
;
}
@JsonAnySetter
public
void
set
(
String
name
,
Object
value
)
{
params
.
put
(
name
,
value
);
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/helper/DEFieldCacheMap.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
cn.ibizlab.util.annotation.Audit
;
import
cn.ibizlab.util.annotation.DEField
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Hashtable
;
import
java.util.List
;
/**
* 实体对象属性缓存类
*/
public
class
DEFieldCacheMap
{
private
static
Hashtable
<
String
,
Hashtable
<
String
,
Field
>>
cacheMap
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
List
<
Field
>>
cacheList
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
Hashtable
<
String
,
String
>>
cacheKey
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
Hashtable
<
String
,
DEField
>>
cacheDEField
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
Hashtable
<
String
,
Audit
>>
cacheAuditField
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
String
>
cacheDEKeyField
=
new
Hashtable
<>();
private
static
Object
objLock1
=
new
Object
();
/**
* 将实体对象中的属性存入缓存中
* @param
* @return
*/
public
static
<
T
>
Hashtable
<
String
,
Field
>
getFieldMap
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheMap
.
containsKey
(
className
))
{
return
cacheMap
.
get
(
className
);
}
synchronized
(
objLock1
)
{
if
(
cacheMap
.
containsKey
(
className
))
{
return
cacheMap
.
get
(
className
);
}
Hashtable
<
String
,
Field
>
result
=
new
Hashtable
<
String
,
Field
>();
List
<
Field
>
list
=
new
ArrayList
<
Field
>();
Hashtable
<
String
,
String
>
keys
=
new
Hashtable
<
String
,
String
>();
Hashtable
<
String
,
DEField
>
defields
=
new
Hashtable
<>();
Hashtable
<
String
,
Audit
>
auditfields
=
new
Hashtable
<>();
Hashtable
<
String
,
String
>
dekeyfields
=
new
Hashtable
<>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field:
fields
){
result
.
put
(
field
.
getName
(),
field
);
list
.
add
(
field
);
keys
.
put
(
field
.
getName
().
toLowerCase
(),
field
.
getName
());
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
Audit
auditField
=
field
.
getAnnotation
(
Audit
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
deField
))
{
defields
.
put
(
field
.
getName
(),
deField
);
if
(
deField
.
isKeyField
())
{
cacheDEKeyField
.
put
(
className
,
field
.
getName
());
}
}
if
(!
ObjectUtils
.
isEmpty
(
auditField
))
{
auditfields
.
put
(
field
.
getName
(),
auditField
);
}
}
cacheMap
.
put
(
className
,
result
);
cacheList
.
put
(
className
,
list
);
cacheKey
.
put
(
className
,
keys
);
cacheDEField
.
put
(
className
,
defields
);
cacheAuditField
.
put
(
className
,
auditfields
);
return
result
;
}
}
public
static
Hashtable
<
String
,
Field
>
getFieldMap
(
String
className
)
{
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheMap
.
containsKey
(
className
))
{
return
cacheMap
.
get
(
className
);
}
Class
clazz
=
null
;
try
{
clazz
=
Class
.
forName
(
className
);
return
getFieldMap
(
clazz
);
}
catch
(
Exception
ex
)
{
cacheMap
.
put
(
className
,
new
Hashtable
<
String
,
Field
>());
return
cacheMap
.
get
(
className
);
}
}
/**
* 从缓存中查询实体对象属性集合
* @param
* @return
*/
public
static
<
T
>
Hashtable
<
String
,
DEField
>
getDEFields
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheDEField
.
containsKey
(
className
))
{
return
cacheDEField
.
get
(
className
);
}
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheDEField
.
get
(
className
);
}
}
/**
* 从缓存中查询审计属性集合
* @param
* @return
*/
public
static
<
T
>
Hashtable
<
String
,
Audit
>
getAuditFields
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheAuditField
.
containsKey
(
className
))
{
return
cacheAuditField
.
get
(
className
);
}
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheAuditField
.
get
(
className
);
}
}
/**
* 从缓存中查询实体对象主键
* @param
* @return
*/
public
static
<
T
>
String
getDEKeyField
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheDEKeyField
.
containsKey
(
className
))
{
return
cacheDEKeyField
.
get
(
className
);
}
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheDEKeyField
.
get
(
className
);
}
}
/**
* 从缓存中查询实体对象属性列表
* @param
* @return
*/
public
static
<
T
>
List
<
Field
>
getFields
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheList
.
containsKey
(
className
))
{
return
cacheList
.
get
(
className
);
}
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheList
.
get
(
className
);
}
}
public
static
List
<
Field
>
getFields
(
String
className
)
{
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheList
.
containsKey
(
className
))
{
return
cacheList
.
get
(
className
);
}
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheList
.
get
(
className
);
}
}
/**
* 从缓存中查询实体对象属性列表
* @param
* @return
*/
public
static
<
T
>
Hashtable
<
String
,
String
>
getFieldKeys
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
{
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
}
if
(
cacheKey
.
containsKey
(
className
))
{
return
cacheKey
.
get
(
className
);
}
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheKey
.
get
(
className
);
}
}
public
static
<
T
>
String
getFieldRealName
(
Class
<
T
>
clazz
,
String
fieldname
)
{
fieldname
=
fieldname
.
toLowerCase
();
Hashtable
<
String
,
String
>
keys
=
DEFieldCacheMap
.
getFieldKeys
(
clazz
);
if
(
keys
.
containsKey
(
fieldname
))
{
return
keys
.
get
(
fieldname
);
}
else
if
(
keys
.
containsKey
(
fieldname
.
replace
(
"_"
,
""
)))
{
return
keys
.
get
(
fieldname
.
replace
(
"_"
,
""
));
}
else
{
return
""
;
}
}
public
static
<
T
>
Field
getField
(
Class
<
T
>
clazz
,
String
fieldname
)
{
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
clazz
,
fieldname
);
if
(!
ObjectUtils
.
isEmpty
(
fieldRealName
))
{
return
DEFieldCacheMap
.
getFieldMap
(
clazz
).
get
(
fieldRealName
);
}
else
{
return
null
;
}
}
public
static
<
T
>
String
getFieldColumnName
(
Class
<
T
>
clazz
,
String
fieldname
)
{
Field
field
=
DEFieldCacheMap
.
getField
(
clazz
,
fieldname
);
if
(
field
!=
null
)
{
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
if
(
deField
!=
null
&&
!
ObjectUtils
.
isEmpty
(
deField
.
name
()))
return
deField
.
name
();
}
return
fieldname
;
}
public
static
<
T
>
Object
fieldValueOf
(
Class
<
T
>
clazz
,
String
fieldname
,
Object
fieldValue
)
{
if
(
fieldValue
==
null
)
return
null
;
Object
resultValue
=
fieldValue
;
Field
field
=
DEFieldCacheMap
.
getField
(
clazz
,
fieldname
);
if
(
field
!=
null
)
{
Class
<?>
type
=
field
.
getType
();
resultValue
=
DataObject
.
objectValueOf
(
type
,
fieldValue
);
}
return
resultValue
;
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/helper/JSR310DateConverters.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
org.springframework.core.convert.converter.Converter
;
import
java.sql.Timestamp
;
import
java.time.*
;
import
java.util.Date
;
/**
* <p>JSR310DateConverters class.</p>
*/
public
final
class
JSR310DateConverters
{
private
JSR310DateConverters
()
{
}
public
static
class
TimestampToDateConverter
implements
Converter
<
Timestamp
,
Date
>
{
public
static
final
TimestampToDateConverter
INSTANCE
=
new
TimestampToDateConverter
();
private
TimestampToDateConverter
()
{
}
@Override
public
Date
convert
(
Timestamp
source
)
{
return
source
==
null
?
null
:
new
Date
(
source
.
getTime
());
}
}
public
static
class
DateToTimestampConverter
implements
Converter
<
Date
,
Timestamp
>
{
public
static
final
DateToTimestampConverter
INSTANCE
=
new
DateToTimestampConverter
();
private
DateToTimestampConverter
()
{
}
@Override
public
Timestamp
convert
(
Date
source
)
{
return
source
==
null
?
null
:
new
Timestamp
(
source
.
getTime
());
}
}
public
static
class
LocalDateToDateConverter
implements
Converter
<
LocalDate
,
Date
>
{
public
static
final
LocalDateToDateConverter
INSTANCE
=
new
LocalDateToDateConverter
();
private
LocalDateToDateConverter
()
{
}
@Override
public
Date
convert
(
LocalDate
source
)
{
return
source
==
null
?
null
:
Date
.
from
(
source
.
atStartOfDay
(
ZoneId
.
systemDefault
()).
toInstant
());
}
}
public
static
class
DateToLocalDateConverter
implements
Converter
<
Date
,
LocalDate
>
{
public
static
final
DateToLocalDateConverter
INSTANCE
=
new
DateToLocalDateConverter
();
private
DateToLocalDateConverter
()
{
}
@Override
public
LocalDate
convert
(
Date
source
)
{
return
source
==
null
?
null
:
ZonedDateTime
.
ofInstant
(
source
.
toInstant
(),
ZoneId
.
systemDefault
())
.
toLocalDate
();
}
}
public
static
class
ZonedDateTimeToDateConverter
implements
Converter
<
ZonedDateTime
,
Date
>
{
public
static
final
ZonedDateTimeToDateConverter
INSTANCE
=
new
ZonedDateTimeToDateConverter
();
private
ZonedDateTimeToDateConverter
()
{
}
@Override
public
Date
convert
(
ZonedDateTime
source
)
{
return
source
==
null
?
null
:
Date
.
from
(
source
.
toInstant
());
}
}
public
static
class
DateToZonedDateTimeConverter
implements
Converter
<
Date
,
ZonedDateTime
>
{
public
static
final
DateToZonedDateTimeConverter
INSTANCE
=
new
DateToZonedDateTimeConverter
();
private
DateToZonedDateTimeConverter
()
{
}
@Override
public
ZonedDateTime
convert
(
Date
source
)
{
return
source
==
null
?
null
:
ZonedDateTime
.
ofInstant
(
source
.
toInstant
(),
ZoneId
.
systemDefault
());
}
}
public
static
class
LocalDateTimeToDateConverter
implements
Converter
<
LocalDateTime
,
Date
>
{
public
static
final
LocalDateTimeToDateConverter
INSTANCE
=
new
LocalDateTimeToDateConverter
();
private
LocalDateTimeToDateConverter
()
{
}
@Override
public
Date
convert
(
LocalDateTime
source
)
{
return
source
==
null
?
null
:
Date
.
from
(
source
.
atZone
(
ZoneId
.
systemDefault
()).
toInstant
());
}
}
public
static
class
DateToLocalDateTimeConverter
implements
Converter
<
Date
,
LocalDateTime
>
{
public
static
final
DateToLocalDateTimeConverter
INSTANCE
=
new
DateToLocalDateTimeConverter
();
private
DateToLocalDateTimeConverter
()
{
}
@Override
public
LocalDateTime
convert
(
Date
source
)
{
return
source
==
null
?
null
:
LocalDateTime
.
ofInstant
(
source
.
toInstant
(),
ZoneId
.
systemDefault
());
}
}
public
static
class
DurationToLongConverter
implements
Converter
<
Duration
,
Long
>
{
public
static
final
DurationToLongConverter
INSTANCE
=
new
DurationToLongConverter
();
private
DurationToLongConverter
()
{
}
@Override
public
Long
convert
(
Duration
source
)
{
return
source
==
null
?
null
:
source
.
toNanos
();
}
}
public
static
class
LongToDurationConverter
implements
Converter
<
Long
,
Duration
>
{
public
static
final
LongToDurationConverter
INSTANCE
=
new
LongToDurationConverter
();
private
LongToDurationConverter
()
{
}
@Override
public
Duration
convert
(
Long
source
)
{
return
source
==
null
?
null
:
Duration
.
ofNanos
(
source
);
}
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/helper/RuleUtils.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
cn.ibizlab.util.domain.EntityBase
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.sql.Timestamp
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
public
class
RuleUtils
{
public
static
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
public
static
Object
getObj
(
Object
object
,
String
members
)
{
if
(
object
==
null
)
{
return
null
;
}
Object
currentObj
=
object
;
String
[]
arrayOfString
=
members
.
split
(
"\\."
);
int
i
=
arrayOfString
.
length
;
for
(
int
j
=
0
;
j
<
i
;
++
j
)
{
String
methodName
=
arrayOfString
[
j
];
try
{
if
(
currentObj
instanceof
EntityBase
)
{
currentObj
=((
EntityBase
)
currentObj
).
get
(
methodName
);
if
(
currentObj
==
null
)
{
return
null
;
}
}
else
if
(
currentObj
instanceof
JSONObject
)
{
currentObj
=((
JSONObject
)
currentObj
).
get
(
methodName
);
if
(
currentObj
==
null
)
{
return
null
;
}
}
else
if
(
currentObj
instanceof
Map
)
{
currentObj
=((
Map
)
currentObj
).
get
(
methodName
);
if
(
currentObj
==
null
)
{
return
null
;
}
}
else
{
Class
clazz
=
currentObj
.
getClass
();
Method
method
=
null
;
try
{
method
=
clazz
.
getMethod
(
"get"
,
new
Class
[
0
]);
}
catch
(
Exception
e2
)
{
method
=
clazz
.
getDeclaredMethod
(
"get"
,
new
Class
[
0
]);
}
currentObj
=
method
.
invoke
(
currentObj
,
methodName
);
if
(
currentObj
==
null
){
return
null
;
}
}
}
catch
(
Exception
e
)
{
return
null
;
}
}
return
currentObj
;
}
public
static
boolean
test
(
Object
finalObject
,
String
option
,
Object
exp
)
{
if
(
option
.
equalsIgnoreCase
(
"eq"
)||
option
.
equalsIgnoreCase
(
"equal"
)||
option
.
equalsIgnoreCase
(
"="
)){
return
equal
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"noteq"
)||
option
.
equalsIgnoreCase
(
"notequal"
)||
option
.
equalsIgnoreCase
(
"<>"
)||
option
.
equalsIgnoreCase
(
"!="
)){
return
!
equal
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"gt"
)||
option
.
equalsIgnoreCase
(
">"
)){
return
gt
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"lt"
)||
option
.
equalsIgnoreCase
(
"<"
)){
return
lt
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"gtandeq"
)||
option
.
equalsIgnoreCase
(
"ge"
)||
option
.
equalsIgnoreCase
(
">="
)){
return
ge
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"ltandeq"
)||
option
.
equalsIgnoreCase
(
"le"
)||
option
.
equalsIgnoreCase
(
"<="
)){
return
le
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"null"
)||
option
.
equalsIgnoreCase
(
"isnull"
)){
return
isNull
(
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"notnull"
)||
option
.
equalsIgnoreCase
(
"isnotnull"
)){
return
isNotNull
(
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"like"
)||
option
.
equalsIgnoreCase
(
"matchor"
)){
return
matchor
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"leftlike"
)||
option
.
equalsIgnoreCase
(
"startswith"
)||
option
.
equalsIgnoreCase
(
"begin"
)){
return
leftmatchor
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"rightlike"
)||
option
.
equalsIgnoreCase
(
"endswith"
)||
option
.
equalsIgnoreCase
(
"end"
)){
return
rightmatchor
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"match"
)||
option
.
equalsIgnoreCase
(
"matchand"
)||
option
.
equalsIgnoreCase
(
"matches"
)){
return
matchand
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"in"
)){
return
in
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"notin"
)){
return
notin
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"NOTLIKE"
)){
return
notmatchor
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"LEFTNOTLIKE"
)){
return
!
leftmatchor
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"RIGHTNOTLIKE"
)){
return
!
rightmatchor
(
exp
,
finalObject
);
}
else
if
(
option
.
equalsIgnoreCase
(
"NOTMATCHES"
)){
return
notmatchand
(
exp
,
finalObject
);
}
else
{
return
false
;
}
}
public
static
boolean
equal
(
Object
exp
,
Object
object
,
String
members
)
{
return
equal
(
exp
,
getObj
(
object
,
members
));
}
public
static
boolean
equal
(
Object
exp
,
Object
finalObject
)
{
if
(
exp
==
null
){
return
false
;
}
if
(
finalObject
==
null
){
return
false
;
}
if
(
exp
instanceof
String
&&
((
String
)
exp
).
length
()==
10
&&
finalObject
instanceof
Timestamp
)
{
return
dateFormat
.
format
(
finalObject
).
equals
(
exp
);
}
else
if
(
exp
instanceof
Timestamp
&&
finalObject
instanceof
Timestamp
)
{
return
dateFormat
.
format
(
finalObject
).
equals
(
dateFormat
.
format
(
exp
));
}
else
if
(
finalObject
instanceof
Timestamp
)
{
Timestamp
tm
=
DataObject
.
getTimestampValue
(
exp
,
null
);
if
(
tm
==
null
)
return
false
;
return
ObjectUtils
.
nullSafeEquals
(
tm
,
finalObject
);
}
if
(
ObjectUtils
.
nullSafeEquals
(
exp
,
finalObject
)){
return
true
;
}
if
(
exp
.
toString
().
equalsIgnoreCase
(
finalObject
.
toString
())){
return
true
;
}
return
false
;
}
public
static
boolean
gt
(
Object
exp
,
Object
object
,
String
members
)
{
return
gt
(
exp
,
getObj
(
object
,
members
));
}
public
static
boolean
gt
(
Object
exp
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
finalObject
)){
return
false
;
}
try
{
if
(
finalObject
instanceof
java
.
sql
.
Timestamp
)
{
java
.
sql
.
Timestamp
finalTime
=(
java
.
sql
.
Timestamp
)
finalObject
;
Timestamp
tm
=
null
;
if
(
exp
instanceof
java
.
sql
.
Timestamp
)
{
tm
=(
java
.
sql
.
Timestamp
)
exp
;
}
else
{
tm
=
DataObject
.
getTimestampValue
(
exp
,
null
);
if
(
tm
==
null
){
return
false
;
}
}
return
finalTime
.
getTime
()>
tm
.
getTime
();
}
else
if
(
finalObject
instanceof
Integer
)
{
return
((
Integer
)
finalObject
)
>
DataObject
.
getIntegerValue
(
exp
,
Integer
.
MAX_VALUE
);
}
else
if
(
finalObject
instanceof
Double
)
{
return
((
Double
)
finalObject
)
>
DataObject
.
getDoubleValue
(
exp
,
Double
.
MAX_VALUE
);
}
else
if
(
finalObject
instanceof
Float
)
{
return
((
Float
)
finalObject
)
>
DataObject
.
getFloatValue
(
exp
,
Float
.
MAX_VALUE
);
}
else
if
(
finalObject
instanceof
BigDecimal
)
{
return
((
BigDecimal
)
finalObject
).
compareTo
(
DataObject
.
getBigDecimalValue
(
exp
,
BigDecimal
.
valueOf
(
Double
.
MAX_VALUE
)))>
0
;
}
else
if
(
finalObject
instanceof
BigInteger
)
{
return
((
BigInteger
)
finalObject
).
compareTo
(
DataObject
.
getBigIntegerValue
(
exp
,
BigInteger
.
valueOf
(
Long
.
MAX_VALUE
)))>
0
;
}
else
if
(
finalObject
instanceof
Long
)
{
return
((
Long
)
finalObject
)
>
DataObject
.
getLongValue
(
exp
,
Long
.
MAX_VALUE
);
}
else
if
(
finalObject
instanceof
String
)
{
return
finalObject
.
toString
().
compareToIgnoreCase
(
exp
.
toString
())>
0
;
}
else
{
return
false
;
}
}
catch
(
Exception
ex
)
{
return
false
;
}
}
public
static
boolean
lt
(
Object
exp
,
Object
object
,
String
members
)
{
return
lt
(
exp
,
getObj
(
object
,
members
));
}
public
static
boolean
lt
(
Object
exp
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
finalObject
)){
return
false
;
}
try
{
if
(
finalObject
instanceof
java
.
sql
.
Timestamp
)
{
java
.
sql
.
Timestamp
finalTime
=(
java
.
sql
.
Timestamp
)
finalObject
;
Timestamp
tm
=
null
;
if
((
exp
instanceof
String
)&&
(
exp
.
toString
().
trim
().
length
()==
10
))
{
tm
=
new
Timestamp
(
dateFormat
.
parse
(
exp
.
toString
().
trim
()).
getTime
());
}
else
if
(
exp
instanceof
java
.
sql
.
Timestamp
)
{
tm
=(
java
.
sql
.
Timestamp
)
exp
;
}
else
{
return
false
;
}
return
finalTime
.
getTime
()<
tm
.
getTime
();
}
else
if
(
finalObject
instanceof
Integer
)
{
return
Integer
.
parseInt
(
finalObject
.
toString
())
<
Integer
.
parseInt
(
exp
.
toString
());
}
else
if
(
finalObject
instanceof
Double
)
{
return
Double
.
parseDouble
(
finalObject
.
toString
())
<
Double
.
parseDouble
(
exp
.
toString
());
}
else
if
(
finalObject
instanceof
Float
)
{
return
Float
.
parseFloat
(
finalObject
.
toString
())
<
Float
.
parseFloat
(
exp
.
toString
());
}
else
if
(
finalObject
instanceof
String
)
{
return
finalObject
.
toString
().
compareToIgnoreCase
(
exp
.
toString
())<
0
;
}
else
if
(
finalObject
instanceof
Long
)
{
return
Long
.
parseLong
(
finalObject
.
toString
())
<
Long
.
parseLong
(
exp
.
toString
());
}
else
return
false
;
}
catch
(
Exception
ex
)
{
return
false
;
}
}
public
static
boolean
ge
(
Object
exp
,
Object
object
,
String
members
)
{
return
ge
(
exp
,
getObj
(
object
,
members
));
}
public
static
boolean
ge
(
Object
exp
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
finalObject
)){
return
false
;
}
return
(!(
lt
(
exp
,
finalObject
)));
}
public
static
boolean
le
(
Object
exp
,
Object
object
,
String
members
)
{
return
le
(
exp
,
getObj
(
object
,
members
));
}
public
static
boolean
le
(
Object
exp
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
finalObject
)){
return
false
;
}
return
(!(
gt
(
exp
,
finalObject
)));
}
public
static
boolean
notin
(
Object
expObj
,
Object
object
,
String
members
)
{
return
notin
(
expObj
,
getObj
(
object
,
members
));
}
public
static
boolean
notin
(
Object
expObj
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
finalObject
))
return
true
;
if
(
ObjectUtils
.
isEmpty
(
expObj
))
return
false
;
String
tvs
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
tvs
)){
return
false
;
}
return
(!
in
(
expObj
,
finalObject
));
}
public
static
boolean
in
(
Object
expObj
,
Object
object
,
String
members
)
{
return
in
(
expObj
,
getObj
(
object
,
members
));
}
public
static
boolean
in
(
Object
expObj
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
finalObject
))
return
false
;
if
(
ObjectUtils
.
isEmpty
(
expObj
))
return
false
;
String
tvs
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
tvs
)){
return
false
;
}
if
(
finalObject
instanceof
Integer
)
{
tvs
=
"i:"
+
tvs
;
}
else
if
(
finalObject
instanceof
String
)
{
tvs
=
"s:"
+
tvs
;
}
List
acts
=
parseTvs
(
tvs
);
for
(
Iterator
localIterator
=
acts
.
iterator
();
localIterator
.
hasNext
();)
{
Object
act
=
localIterator
.
next
();
if
(
equal
(
act
,
finalObject
))
return
true
;
}
return
false
;
}
public
static
boolean
isNotNull
(
Object
object
,
String
members
)
{
return
isNotNull
(
getObj
(
object
,
members
));
}
public
static
boolean
isNotNull
(
Object
finalObject
)
{
return
!
isNull
(
finalObject
);
}
public
static
boolean
isNull
(
Object
object
,
String
members
)
{
return
isNull
(
getObj
(
object
,
members
));
}
public
static
boolean
isNull
(
Object
finalObject
)
{
if
(
finalObject
instanceof
String
){
return
ObjectUtils
.
isEmpty
(
finalObject
.
toString
().
trim
());
}
return
(
ObjectUtils
.
isEmpty
(
finalObject
));
}
public
static
boolean
notmatchor
(
Object
expObj
,
Object
object
,
String
members
)
{
return
notmatchor
(
expObj
,
getObj
(
object
,
members
));
}
public
static
boolean
notmatchor
(
Object
expObj
,
Object
obj
)
{
if
(
ObjectUtils
.
isEmpty
(
obj
)){
return
true
;
}
if
(
ObjectUtils
.
isEmpty
(
expObj
)){
return
false
;
}
String
exp
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
return
(!
matchor
(
expObj
,
obj
));
}
public
static
boolean
notmatchand
(
Object
expObj
,
Object
object
,
String
members
)
{
return
notmatchand
(
expObj
,
getObj
(
object
,
members
));
}
public
static
boolean
notmatchand
(
Object
expObj
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
finalObject
)){
return
true
;
}
if
(
ObjectUtils
.
isEmpty
(
expObj
)){
return
false
;
}
String
exp
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
return
(!
matchand
(
expObj
,
finalObject
));
}
public
static
boolean
matchor
(
Object
expObj
,
Object
object
,
String
members
)
{
return
matchor
(
expObj
,
getObj
(
object
,
members
));
}
public
static
boolean
matchor
(
Object
expObj
,
Object
obj
)
{
if
(
ObjectUtils
.
isEmpty
(
obj
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
expObj
)){
return
false
;
}
String
exp
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
","
,
","
);
String
[]
arr
=
exp
.
split
(
","
);
boolean
bRt
=
false
;
for
(
String
strExp:
arr
)
{
bRt
=(
obj
.
toString
()).
matches
(
"(.*)"
+(
strExp
)+
"(.*)"
);
if
(
bRt
)
return
true
;
}
return
bRt
;
}
public
static
boolean
leftmatchor
(
Object
expObj
,
Object
obj
)
{
if
(
ObjectUtils
.
isEmpty
(
obj
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
expObj
)){
return
false
;
}
String
exp
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
","
,
","
);
String
[]
arr
=
exp
.
split
(
","
);
boolean
bRt
=
false
;
for
(
String
strExp:
arr
)
{
bRt
=
obj
.
toString
().
matches
(
strExp
+
"(.*)"
);
if
(
bRt
){
return
true
;
}
}
return
bRt
;
}
public
static
boolean
rightmatchor
(
Object
expObj
,
Object
obj
)
{
if
(
ObjectUtils
.
isEmpty
(
obj
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
expObj
)){
return
false
;
}
String
exp
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
","
,
","
);
String
[]
arr
=
exp
.
split
(
","
);
boolean
bRt
=
false
;
for
(
String
strExp:
arr
)
{
bRt
=
obj
.
toString
().
matches
(
"(.*)"
+
strExp
);
if
(
bRt
){
return
true
;
}
}
return
bRt
;
}
public
static
boolean
matchand
(
Object
expObj
,
Object
object
,
String
members
)
{
return
matchand
(
expObj
,
getObj
(
object
,
members
));
}
public
static
boolean
matchand
(
Object
expObj
,
Object
obj
)
{
if
(
ObjectUtils
.
isEmpty
(
obj
)){
return
false
;
}
if
(
ObjectUtils
.
isEmpty
(
expObj
)){
return
false
;
}
String
exp
=
expObj
.
toString
().
trim
();
if
(
ObjectUtils
.
isEmpty
(
exp
)){
return
false
;
}
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
";"
,
","
);
exp
=
exp
.
replace
(
","
,
","
);
String
[]
arr
=
exp
.
split
(
","
);
String
objstr
=
obj
.
toString
();
boolean
bRt
=
true
;
for
(
String
strExp:
arr
)
{
if
(
strExp
.
trim
().
length
()==
0
){
continue
;
}
bRt
=(
obj
.
toString
()).
matches
(
"(.*)"
+(
strExp
)+
"(.*)"
);
if
(!
bRt
){
return
false
;
}
}
return
bRt
;
}
private
static
List
<
Object
>
parseTvs
(
String
tvs
)
{
tvs
=
tvs
.
replace
(
";"
,
","
);
tvs
=
tvs
.
replace
(
";"
,
","
);
tvs
=
tvs
.
replace
(
","
,
","
);
String
[]
arrayOfString1
;
int
j
;
int
k
;
String
value
;
String
type
=
"s"
;
String
values
=
""
;
String
[]
tv
=
tvs
.
split
(
":"
);
if
(
tv
.
length
>
1
)
{
type
=
tv
[
0
];
values
=
tv
[
1
];
}
else
{
values
=
tvs
;
}
List
acts
=
new
ArrayList
();
String
str1
=
type
;
int
i
=
-
1
;
switch
(
str1
.
hashCode
())
{
case
105
:
if
(
str1
.
equals
(
"i"
)){
i
=
0
;
}
break
;
case
115
:
if
(
str1
.
equals
(
"s"
)){
i
=
1
;
}
}
switch
(
i
)
{
case
0
:
arrayOfString1
=
values
.
split
(
","
);
j
=
arrayOfString1
.
length
;
for
(
k
=
0
;
k
<
j
;
++
k
)
{
value
=
arrayOfString1
[
k
];
acts
.
add
(
new
Integer
(
value
.
trim
()));
}
break
;
case
1
:
arrayOfString1
=
values
.
split
(
","
);
j
=
arrayOfString1
.
length
;
for
(
k
=
0
;
k
<
j
;
++
k
)
{
value
=
arrayOfString1
[
k
];
acts
.
add
(
value
.
trim
());
}
}
return
acts
;
}
public
static
boolean
inc2s
(
String
tvs
,
Object
finalObject
)
{
if
(
ObjectUtils
.
isEmpty
(
finalObject
))
return
false
;
if
(
ObjectUtils
.
isEmpty
(
tvs
))
return
false
;
if
(
finalObject
instanceof
String
)
{
tvs
=
"s:"
+
tvs
;
}
else
return
false
;
List
acts
=
parseTvs
(
tvs
);
for
(
Iterator
localIterator
=
acts
.
iterator
();
localIterator
.
hasNext
();)
{
Object
act
=
localIterator
.
next
();
if
(
equal
(
c2s
(
act
.
toString
()),
c2s
(
finalObject
.
toString
())))
return
true
;
}
return
false
;
}
public
static
String
c2s
(
String
str
)
{
if
(
str
==
null
)
return
null
;
if
(
str
.
length
()<
300
)
{
str
=
str
.
trim
();
//1234567890()【】〔2018〕
str
=
str
.
replace
(
"1"
,
"1"
).
replace
(
"2"
,
"2"
).
replace
(
"3"
,
"3"
).
replace
(
"4"
,
"4"
).
replace
(
"5"
,
"5"
).
replace
(
"6"
,
"6"
).
replace
(
"7"
,
"7"
)
.
replace
(
"8"
,
"8"
).
replace
(
"9"
,
"9"
).
replace
(
"0"
,
"0"
)
.
replace
(
"("
,
"〔"
).
replace
(
")"
,
"〕"
)
.
replace
(
"("
,
"〔"
).
replace
(
")"
,
"〕"
)
.
replace
(
"【"
,
"〔"
).
replace
(
"】"
,
"〕"
)
.
replace
(
"["
,
"〔"
).
replace
(
"]"
,
"〕"
);
}
return
str
;
}
public
static
boolean
notinc2s
(
String
tvs
,
Object
finalObject
)
{
return
(!
inc2s
(
tvs
,
finalObject
));
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/helper/Setting.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
cn.ibizlab.util.domain.EntityBase
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.io.StringReader
;
import
java.util.*
;
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
public
class
Setting
{
private
String
property
;
private
String
value
;
public
static
String
getValue
(
String
configString
,
String
propertyName
)
{
return
DataObject
.
getStringValue
(
getMap
(
configString
).
get
(
propertyName
),
""
);
}
public
static
<
T
extends
EntityBase
>
T
getEntity
(
String
configString
,
T
entityBase
)
{
if
(
entityBase
!=
null
)
{
Map
map
=
getMap
(
configString
);
map
.
keySet
().
forEach
(
key
->{
entityBase
.
set
(
key
.
toString
(),
map
.
get
(
key
));
});
}
return
entityBase
;
}
public
static
Map
getMap
(
String
configString
)
{
Map
map
=
new
HashMap
();
map
.
put
(
"param"
,
configString
);
if
(!(
ObjectUtils
.
isEmpty
(
configString
)))
{
try
{
Object
obj
=
JSON
.
parse
(
configString
);
if
(
obj
==
null
)
return
map
;
else
if
(
obj
instanceof
JSONArray
)
{
List
<
Setting
>
settings
=
JSONArray
.
parseArray
(
configString
,
Setting
.
class
);
for
(
Setting
setting:
settings
)
map
.
put
(
setting
.
getProperty
(),
setting
.
getValue
());
}
else
if
(
obj
instanceof
JSONObject
)
{
JSONObject
jo
=
(
JSONObject
)
obj
;
jo
.
keySet
().
forEach
(
key
->{
map
.
put
(
key
,
jo
.
get
(
key
));
});
}
}
catch
(
Exception
ex
)
{
if
(
configString
.
indexOf
(
"="
)>
0
)
{
Properties
proper
=
new
Properties
();
try
{
proper
.
load
(
new
StringReader
(
configString
));
//把字符串转为reader
}
catch
(
IOException
e
)
{
}
Enumeration
enum1
=
proper
.
propertyNames
();
while
(
enum1
.
hasMoreElements
())
{
String
strKey
=
(
String
)
enum1
.
nextElement
();
String
strValue
=
proper
.
getProperty
(
strKey
);
map
.
put
(
strKey
,
strValue
);
}
}
}
}
return
map
;
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/mapper/IBZConfigMapper.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
mapper
;
import
cn.ibizlab.util.domain.IBZConfig
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
IBZConfigMapper
extends
BaseMapper
<
IBZConfig
>{
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/mapper/IBZDataAuditMapper.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
cn.ibizlab.util.domain.IBZDataAudit
;
public
interface
IBZDataAuditMapper
extends
BaseMapper
<
IBZDataAudit
>
{
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/mapper/IBZUSERMapper.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
cn.ibizlab.util.domain.IBZUSER
;
public
interface
IBZUSERMapper
extends
BaseMapper
<
IBZUSER
>{
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/rest/ConfigController.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
rest
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.service.IBZConfigService
;
import
com.alibaba.fastjson.JSONObject
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
java.util.*
;
@RestController
@RequestMapping
(
value
=
""
)
public
class
ConfigController
{
@Autowired
private
IBZConfigService
ibzConfigService
;
@RequestMapping
(
method
=
RequestMethod
.
PUT
,
value
=
"/configs/{configType}/{targetType}"
)
public
ResponseEntity
<
Boolean
>
saveConfig
(
@PathVariable
(
"configType"
)
String
configType
,
@PathVariable
(
"targetType"
)
String
targetType
,
@RequestBody
JSONObject
config
)
{
String
userId
=
AuthenticationUser
.
getAuthenticationUser
().
getUserid
();
if
(
ObjectUtils
.
isEmpty
(
userId
)){
throw
new
BadRequestAlertException
(
"保存配置失败,参数缺失"
,
"IBZConfig"
,
configType
);
}
return
ResponseEntity
.
ok
(
ibzConfigService
.
saveConfig
(
configType
,
targetType
,
userId
,
config
));
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/configs/{configType}/{targetType}"
)
public
ResponseEntity
<
JSONObject
>
getConfig
(
@PathVariable
(
"configType"
)
String
configType
,
@PathVariable
(
"targetType"
)
String
targetType
)
{
String
userId
=
AuthenticationUser
.
getAuthenticationUser
().
getUserid
();
if
(
ObjectUtils
.
isEmpty
(
userId
)){
throw
new
BadRequestAlertException
(
"获取配置失败,参数缺失"
,
"IBZConfig"
,
configType
);
}
return
ResponseEntity
.
ok
(
ibzConfigService
.
getConfig
(
configType
,
targetType
,
userId
));
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/configs/share/{id}"
)
public
ResponseEntity
<
JSONObject
>
getShareConfig
(
@PathVariable
(
"id"
)
String
id
)
{
JSONObject
jo
=
ibzConfigService
.
getShareConfig
(
id
);
if
(
jo
==
null
)
{
throw
new
BadRequestAlertException
(
"无效的共享配置数据"
,
"IBZConfig"
,
id
);
}
return
ResponseEntity
.
ok
(
jo
);
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/configs/share/{configType}/{targetType}"
)
public
ResponseEntity
<
String
>
shareConfig
(
@PathVariable
(
"configType"
)
String
configType
,
@PathVariable
(
"targetType"
)
String
targetType
)
{
String
userId
=
AuthenticationUser
.
getAuthenticationUser
().
getUserid
();
if
(
ObjectUtils
.
isEmpty
(
userId
))
{
throw
new
BadRequestAlertException
(
"分享配置失败,参数缺失"
,
"IBZConfig"
,
configType
);
}
String
id
=
IdWorker
.
get32UUID
();
ibzConfigService
.
saveShareConfig
(
id
,
configType
,
targetType
,
userId
);
return
ResponseEntity
.
ok
(
id
);
}
/**
* 应用参数扩展
* @param appData
*/
protected
void
fillAppData
(
JSONObject
appData
){
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/service/IBZConfigService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.domain.IBZConfig
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.DataObject
;
import
cn.ibizlab.util.mapper.IBZConfigMapper
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
@Slf4j
@Service
public
class
IBZConfigService
extends
ServiceImpl
<
IBZConfigMapper
,
IBZConfig
>
implements
IService
<
IBZConfig
>
{
@Value
(
"${ibiz.systemid:ibznotify}"
)
private
String
systemId
;
@Value
(
"${ibiz.admin.userid:0100}"
)
private
String
adminuserid
;
@Cacheable
(
value
=
"ibzrt_configs"
,
key
=
"'cfgid:'+#p0+'||'+#p1+'||'+#p2"
)
public
JSONObject
getConfig
(
String
cfgType
,
String
targetType
,
String
userId
)
{
if
(
ObjectUtils
.
isEmpty
(
userId
)
||
ObjectUtils
.
isEmpty
(
cfgType
)
||
ObjectUtils
.
isEmpty
(
targetType
))
{
throw
new
BadRequestAlertException
(
"获取配置失败,参数缺失"
,
"IBZConfig"
,
cfgType
);
}
IBZConfig
config
=
this
.
getOne
(
Wrappers
.
query
(
IBZConfig
.
builder
().
systemId
(
systemId
).
cfgType
(
cfgType
).
targetType
(
targetType
).
userId
(
userId
).
build
()),
false
);
if
(
config
==
null
)
{
config
=
this
.
getOne
(
Wrappers
.
query
(
IBZConfig
.
builder
().
systemId
(
systemId
).
cfgType
(
cfgType
).
targetType
(
targetType
).
userId
(
adminuserid
).
build
()),
false
);
if
(
config
==
null
)
{
return
new
JSONObject
();
}
}
return
JSON
.
parseObject
(
config
.
getCfg
());
}
@CacheEvict
(
value
=
"ibzrt_configs"
,
key
=
"'cfgid:'+#p0+'||'+#p1+'||'+#p2"
)
public
boolean
saveConfig
(
String
cfgType
,
String
targetType
,
String
userId
,
JSONObject
config
)
{
if
(
ObjectUtils
.
isEmpty
(
userId
)
||
ObjectUtils
.
isEmpty
(
cfgType
)
||
ObjectUtils
.
isEmpty
(
targetType
))
{
throw
new
BadRequestAlertException
(
"保存配置失败,参数缺失"
,
"IBZConfig"
,
cfgType
);
}
String
cfg
=
"{}"
;
if
(
config
!=
null
)
{
cfg
=
JSONObject
.
toJSONString
(
config
);
}
return
this
.
saveOrUpdate
(
IBZConfig
.
builder
().
systemId
(
systemId
).
cfgType
(
cfgType
).
targetType
(
targetType
).
userId
(
userId
).
cfg
(
cfg
).
updateDate
(
DataObject
.
getNow
()).
build
());
}
@CacheEvict
(
value
=
"ibzrt_configs"
,
key
=
"'cfgid:'+#p0+'||'+#p1+'||'+#p2"
)
public
void
resetConfig
(
String
cfgType
,
String
targetType
,
String
userId
)
{
if
(
ObjectUtils
.
isEmpty
(
userId
)
||
ObjectUtils
.
isEmpty
(
cfgType
)
||
ObjectUtils
.
isEmpty
(
targetType
))
{
throw
new
BadRequestAlertException
(
"重置配置失败,参数缺失"
,
"IBZConfig"
,
cfgType
);
}
this
.
remove
(
Wrappers
.
query
(
IBZConfig
.
builder
().
systemId
(
systemId
).
cfgType
(
cfgType
).
targetType
(
targetType
).
userId
(
userId
).
build
()));
}
@Cacheable
(
value
=
"ibzrt_shareconfigs"
,
key
=
"'cfgid:'+#p0"
)
public
JSONObject
saveShareConfig
(
String
id
,
String
cfgType
,
String
targetType
,
String
userId
){
return
this
.
getConfig
(
cfgType
,
targetType
,
userId
);
}
@Cacheable
(
value
=
"ibzrt_shareconfigs"
,
key
=
"'cfgid:'+#p0"
)
public
JSONObject
getShareConfig
(
String
id
){
return
null
;
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/service/IBZDataAuditService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.annotation.Audit
;
import
cn.ibizlab.util.domain.EntityBase
;
import
org.springframework.scheduling.annotation.Async
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Map
;
/**
* 实体[DataAudit] 服务对象接口
*/
public
interface
IBZDataAuditService
{
@Async
(
"asyncExecutor"
)
void
createAudit
(
HttpServletRequest
request
,
EntityBase
entity
,
Object
idValue
,
Map
<
String
,
Audit
>
auditFields
);
@Async
(
"asyncExecutor"
)
void
updateAudit
(
HttpServletRequest
request
,
EntityBase
beforeEntity
,
Object
serviceObj
,
Object
idValue
,
Map
<
String
,
Audit
>
auditFields
);
@Async
(
"asyncExecutor"
)
void
removeAudit
(
HttpServletRequest
request
,
EntityBase
entity
,
Object
idValue
,
Map
<
String
,
Audit
>
auditFields
);
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/service/SimpleAuditService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
cn.ibizlab.util.annotation.Audit
;
import
cn.ibizlab.util.annotation.DEField
;
import
cn.ibizlab.util.domain.EntityBase
;
import
cn.ibizlab.util.domain.IBZDataAudit
;
import
cn.ibizlab.util.helper.DEFieldCacheMap
;
import
cn.ibizlab.util.mapper.IBZDataAuditMapper
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ExpressionParser
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
java.sql.Timestamp
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* 实体[DataAudit] 服务对象接口实现
*/
@Service
@Slf4j
public
class
SimpleAuditService
extends
ServiceImpl
<
IBZDataAuditMapper
,
IBZDataAudit
>
implements
IBZDataAuditService
{
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
private
static
List
cacheMap
=
Collections
.
synchronizedList
(
new
ArrayList
());
/**
* 定时保存审计记录
*/
@Scheduled
(
fixedRate
=
10000
)
public
void
saveAudit
()
{
if
(
cacheMap
.
size
()>
0
)
{
log
.
info
(
String
.
format
(
"正在保存审计数据,当前审计集合数量为[%s]"
,
cacheMap
.
size
()));
List
temp
=
new
ArrayList
();
if
(
cacheMap
.
size
()<
500
)
{
temp
.
addAll
(
cacheMap
);
}
else
{
temp
.
addAll
(
cacheMap
.
subList
(
0
,
500
));
}
this
.
saveBatch
(
temp
);
cacheMap
.
removeAll
(
temp
);
log
.
info
(
String
.
format
(
"保存完成,当前审计集合数量为[%s]"
,
cacheMap
.
size
()));
}
}
/**
* 新建审计日志
* @param request
* @param entity
* @param idValue
* @param auditFields
*/
@Override
public
void
createAudit
(
HttpServletRequest
request
,
EntityBase
entity
,
Object
idValue
,
Map
<
String
,
Audit
>
auditFields
)
{
IBZDataAudit
dataAudit
=
new
IBZDataAudit
();
dataAudit
.
setOppersonid
(
AuthenticationUser
.
getAuthenticationUser
().
getUserid
());
dataAudit
.
setOppersonname
(
String
.
format
(
"%s[%s]"
,
AuthenticationUser
.
getAuthenticationUser
().
getPersonname
(),
AuthenticationUser
.
getAuthenticationUser
().
getOrgname
()));
dataAudit
.
setAudittype
(
"CREATE"
);
dataAudit
.
setAuditobject
(
entity
.
getClass
().
getSimpleName
());
dataAudit
.
setAuditobjectdata
(
idValue
);
dataAudit
.
setOptime
(
new
Timestamp
(
new
Date
().
getTime
()));
if
(
request
!=
null
)
{
dataAudit
.
setIpaddress
(
getIpAddress
(
request
,
AuthenticationUser
.
getAuthenticationUser
()));
}
dataAudit
.
setAuditinfo
(
getAuditInfo
(
entity
,
auditFields
));
dataAudit
.
setIsdatachanged
(
1
);
cacheMap
.
add
(
dataAudit
);
}
/**
* 更新审计日志
* @param request
* @param beforeEntity
* @param serviceObj
* @param idValue
* @param auditFields
*/
@SneakyThrows
public
void
updateAudit
(
HttpServletRequest
request
,
EntityBase
beforeEntity
,
Object
serviceObj
,
Object
idValue
,
Map
<
String
,
Audit
>
auditFields
)
{
//获取更新后的实体
EntityBase
afterEntity
=
getEntity
(
serviceObj
,
idValue
);
//获取更新后的审计内容
String
auditInfo
=
getUpdateAuditInfo
(
beforeEntity
,
afterEntity
,
auditFields
);
//比较更新前后差异内容
int
isDataChanged
=
1
;
//审计内容是否发生变化
if
(
ObjectUtils
.
isEmpty
(
auditInfo
))
{
isDataChanged
=
0
;
}
IBZDataAudit
dataAudit
=
new
IBZDataAudit
();
dataAudit
.
setOppersonid
(
AuthenticationUser
.
getAuthenticationUser
().
getUserid
());
dataAudit
.
setOppersonname
(
String
.
format
(
"%s[%s]"
,
AuthenticationUser
.
getAuthenticationUser
().
getPersonname
(),
AuthenticationUser
.
getAuthenticationUser
().
getOrgname
()));
dataAudit
.
setAudittype
(
"UPDATE"
);
dataAudit
.
setAuditobject
(
afterEntity
.
getClass
().
getSimpleName
());
dataAudit
.
setAuditobjectdata
(
idValue
);
dataAudit
.
setOptime
(
new
Timestamp
(
new
Date
().
getTime
()));
if
(
request
!=
null
)
{
dataAudit
.
setIpaddress
(
getIpAddress
(
request
,
AuthenticationUser
.
getAuthenticationUser
()));
}
dataAudit
.
setAuditinfo
(
auditInfo
);
dataAudit
.
setIsdatachanged
(
isDataChanged
);
cacheMap
.
add
(
dataAudit
);
}
/**
* 删除审计日志
* @param request
* @param entity
* @param idValue
* @param auditFields
*/
public
void
removeAudit
(
HttpServletRequest
request
,
EntityBase
entity
,
Object
idValue
,
Map
<
String
,
Audit
>
auditFields
)
{
IBZDataAudit
dataAudit
=
new
IBZDataAudit
();
dataAudit
.
setOppersonid
(
AuthenticationUser
.
getAuthenticationUser
().
getUserid
());
dataAudit
.
setOppersonname
(
String
.
format
(
"%s[%s]"
,
AuthenticationUser
.
getAuthenticationUser
().
getPersonname
(),
AuthenticationUser
.
getAuthenticationUser
().
getOrgname
()));
dataAudit
.
setAudittype
(
"REMOVE"
);
dataAudit
.
setAuditobject
(
entity
.
getClass
().
getSimpleName
());
dataAudit
.
setAuditobjectdata
(
idValue
);
dataAudit
.
setOptime
(
new
Timestamp
(
new
Date
().
getTime
()));
if
(
request
!=
null
)
{
dataAudit
.
setIpaddress
(
getIpAddress
(
request
,
AuthenticationUser
.
getAuthenticationUser
()));
}
dataAudit
.
setAuditinfo
(
getAuditInfo
(
entity
,
auditFields
));
dataAudit
.
setIsdatachanged
(
1
);
cacheMap
.
add
(
dataAudit
);
}
private
String
getAuditInfo
(
EntityBase
entity
,
Map
<
String
,
Audit
>
auditFields
)
{
String
auditResult
=
""
;
if
(
auditFields
.
size
()
==
0
)
{
return
auditResult
;
}
Map
<
String
,
DEField
>
deFields
=
DEFieldCacheMap
.
getDEFields
(
entity
.
getClass
());
if
(
deFields
.
size
()
==
0
)
{
return
auditResult
;
}
JSONArray
auditFieldArray
=
new
JSONArray
();
for
(
Map
.
Entry
<
String
,
Audit
>
auditField
:
auditFields
.
entrySet
())
{
Object
objFieldName
=
auditField
.
getKey
();
String
fieldName
=
String
.
valueOf
(
objFieldName
);
DEField
deField
=
null
;
if
(
deFields
.
containsKey
(
fieldName
))
{
deField
=
deFields
.
get
(
fieldName
);
}
if
(
ObjectUtils
.
isEmpty
(
deField
))
{
continue
;
}
Object
value
=
dataTransfer
(
entity
.
get
(
fieldName
),
deField
.
fieldType
(),
deField
.
format
());
if
(!
ObjectUtils
.
isEmpty
(
value
))
{
JSONObject
auditFieldObj
=
new
JSONObject
();
auditFieldObj
.
put
(
"field"
,
deField
.
value
());
auditFieldObj
.
put
(
"value"
,
value
);
if
(!
ObjectUtils
.
isEmpty
(
deField
.
dict
()))
{
auditFieldObj
.
put
(
"dict"
,
deField
.
dict
());
}
auditFieldArray
.
add
(
auditFieldObj
);
}
}
if
(
auditFieldArray
.
size
()>
0
)
{
auditResult
=
auditFieldArray
.
toString
();
}
return
auditResult
;
}
/**
* 获取更新审计内容
* @param oldData
* @param newData
* @param auditFields
* @return
*/
private
String
getUpdateAuditInfo
(
EntityBase
oldData
,
EntityBase
newData
,
Map
<
String
,
Audit
>
auditFields
){
String
auditResult
=
""
;
JSONArray
auditFieldArray
=
new
JSONArray
();
if
(
auditFields
.
size
()
==
0
)
{
return
auditResult
;
}
Map
<
String
,
DEField
>
deFields
=
DEFieldCacheMap
.
getDEFields
(
oldData
.
getClass
());
if
(
deFields
.
size
()
==
0
){
return
auditResult
;
}
for
(
Map
.
Entry
<
String
,
Audit
>
auditField
:
auditFields
.
entrySet
())
{
Object
objFieldName
=
auditField
.
getKey
();
//获取注解字段
String
fieldName
=
String
.
valueOf
(
objFieldName
);
//属性名称
DEField
deField
=
null
;
if
(
deFields
.
containsKey
(
fieldName
))
{
deField
=
deFields
.
get
(
fieldName
);
}
if
(
ObjectUtils
.
isEmpty
(
deField
))
{
continue
;
}
Object
oldValue
=
oldData
.
get
(
fieldName
);
//老属性值
Object
newValue
=
newData
.
get
(
fieldName
);
//新属性值
if
(!
compare
(
oldValue
,
newValue
))
{
oldValue
=
dataTransfer
(
oldValue
,
deField
.
fieldType
(),
deField
.
format
());
//属性值转换
newValue
=
dataTransfer
(
newValue
,
deField
.
fieldType
(),
deField
.
format
());
//属性值转换
JSONObject
auditFieldObj
=
new
JSONObject
();
auditFieldObj
.
put
(
"field"
,
deField
.
value
());
auditFieldObj
.
put
(
"beforevalue"
,
oldValue
);
auditFieldObj
.
put
(
"value"
,
newValue
);
if
(!
ObjectUtils
.
isEmpty
(
deField
.
dict
()))
{
auditFieldObj
.
put
(
"dict"
,
deField
.
dict
());
}
auditFieldArray
.
add
(
auditFieldObj
);
}
}
if
(
auditFieldArray
.
size
()>
0
)
{
auditResult
=
auditFieldArray
.
toString
();
}
return
auditResult
;
}
/**
* 数据转换
* @param value 转换值
* @param dataType 转换字段类型
* @param strFormat 转换字段格式化文本
* @return
*/
private
String
dataTransfer
(
Object
value
,
String
dataType
,
String
strFormat
)
{
if
(
value
==
null
)
{
return
""
;
}
String
transResult
=
value
.
toString
();
if
((
dataType
.
equals
(
"DATE"
)
||
dataType
.
equals
(
"DATETIME"
)
||
dataType
.
equals
(
"TIME"
))
&&
(!
ObjectUtils
.
isEmpty
(
strFormat
)))
{
//时间类型转换
Timestamp
timestamp
=
(
Timestamp
)
value
;
Date
date
=
timestamp
;
SimpleDateFormat
format
=
new
SimpleDateFormat
(
strFormat
);
transResult
=
format
.
format
(
date
);
}
return
transResult
;
}
/**
* 对象比较
* @param sourceObj 比较源对象
* @param targetObj 比较目标对象
* @return
*/
private
boolean
compare
(
Object
sourceObj
,
Object
targetObj
)
{
if
(
sourceObj
==
null
&&
targetObj
==
null
)
{
return
true
;
}
if
(
sourceObj
==
null
&&
targetObj
!=
null
)
{
return
false
;
}
return
sourceObj
.
equals
(
targetObj
);
}
/**
* 获取实体
* @param service
* @param id
* @return
*/
@SneakyThrows
private
EntityBase
getEntity
(
Object
service
,
Object
id
)
{
EntityBase
entity
=
null
;
if
(!
ObjectUtils
.
isEmpty
(
service
))
{
EvaluationContext
oldContext
=
new
StandardEvaluationContext
();
oldContext
.
setVariable
(
"service"
,
service
);
oldContext
.
setVariable
(
"id"
,
id
);
Expression
oldExp
=
parser
.
parseExpression
(
"#service.get(#id)"
);
return
oldExp
.
getValue
(
oldContext
,
EntityBase
.
class
);
}
return
entity
;
}
/**
* 获取Ip地址
* @param request
* @return
*/
public
String
getIpAddress
(
HttpServletRequest
request
,
AuthenticationUser
authenticationUser
)
{
//客户端有提交ip,以提交的ip为准
if
(
authenticationUser
!=
null
&&
!
ObjectUtils
.
isEmpty
(
authenticationUser
.
getAddr
()))
{
return
authenticationUser
.
getAddr
();
}
if
(
request
==
null
)
{
return
""
;
}
String
Xip
=
request
.
getHeader
(
"X-Real-IP"
);
String
XFor
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(!
ObjectUtils
.
isEmpty
(
XFor
)
&&
!
"unKnown"
.
equalsIgnoreCase
(
XFor
))
{
//多次反向代理后会有多个ip值,第一个ip才是真实ip
int
index
=
XFor
.
indexOf
(
","
);
if
(
index
!=
-
1
){
return
XFor
.
substring
(
0
,
index
);
}
else
{
return
XFor
;
}
}
XFor
=
Xip
;
if
(!
ObjectUtils
.
isEmpty
(
XFor
)
&&
!
"unKnown"
.
equalsIgnoreCase
(
XFor
))
{
return
XFor
;
}
if
(
ObjectUtils
.
isEmpty
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ObjectUtils
.
isEmpty
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ObjectUtils
.
isEmpty
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
}
if
(
ObjectUtils
.
isEmpty
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
}
if
(
ObjectUtils
.
isEmpty
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getRemoteAddr
();
}
return
XFor
;
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/web/IBZOperationParameterReader.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
web
;
import
cn.ibizlab.util.filter.SearchContextBase
;
import
com.fasterxml.classmate.ResolvedType
;
import
com.google.common.base.Predicate
;
import
com.google.common.collect.FluentIterable
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestPart
;
import
springfox.documentation.builders.ParameterBuilder
;
import
springfox.documentation.service.Parameter
;
import
springfox.documentation.service.ResolvedMethodParameter
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.schema.EnumTypeDeterminer
;
import
springfox.documentation.spi.service.OperationBuilderPlugin
;
import
springfox.documentation.spi.service.contexts.OperationContext
;
import
springfox.documentation.spi.service.contexts.ParameterContext
;
import
springfox.documentation.spring.web.plugins.DocumentationPluginsManager
;
import
springfox.documentation.spring.web.readers.parameter.ExpansionContext
;
import
springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander
;
import
java.lang.annotation.Annotation
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
static
com
.
google
.
common
.
base
.
Predicates
.*;
import
static
com
.
google
.
common
.
collect
.
Lists
.*;
import
static
springfox
.
documentation
.
schema
.
Collections
.*;
import
static
springfox
.
documentation
.
schema
.
Maps
.*;
import
static
springfox
.
documentation
.
schema
.
Types
.*;
//@Component
//@Order(Ordered.HIGHEST_PRECEDENCE)
public
class
IBZOperationParameterReader
implements
OperationBuilderPlugin
{
private
final
ModelAttributeParameterExpander
expander
;
private
final
EnumTypeDeterminer
enumTypeDeterminer
;
@Autowired
private
DocumentationPluginsManager
pluginsManager
;
@Autowired
public
IBZOperationParameterReader
(
ModelAttributeParameterExpander
expander
,
EnumTypeDeterminer
enumTypeDeterminer
)
{
this
.
expander
=
expander
;
this
.
enumTypeDeterminer
=
enumTypeDeterminer
;
}
@Override
public
void
apply
(
OperationContext
context
)
{
context
.
operationBuilder
().
parameters
(
context
.
getGlobalOperationParameters
());
context
.
operationBuilder
().
parameters
(
readParameters
(
context
));
}
@Override
public
boolean
supports
(
DocumentationType
delimiter
)
{
return
true
;
}
private
List
<
Parameter
>
readParameters
(
final
OperationContext
context
)
{
List
<
ResolvedMethodParameter
>
methodParameters
=
context
.
getParameters
();
List
<
Parameter
>
parameters
=
newArrayList
();
for
(
ResolvedMethodParameter
methodParameter
:
methodParameters
)
{
ResolvedType
alternate
=
context
.
alternateFor
(
methodParameter
.
getParameterType
());
if
(!
shouldIgnore
(
methodParameter
,
alternate
,
context
.
getIgnorableParameterTypes
()))
{
ParameterContext
parameterContext
=
new
ParameterContext
(
methodParameter
,
new
ParameterBuilder
(),
context
.
getDocumentationContext
(),
context
.
getGenericsNamingStrategy
(),
context
);
if
(
shouldExpand
(
methodParameter
,
alternate
))
{
parameters
.
addAll
(
expander
.
expand
(
new
ExpansionContext
(
""
,
alternate
,
context
)));
}
else
{
parameters
.
add
(
pluginsManager
.
parameter
(
parameterContext
));
}
}
}
return
FluentIterable
.
from
(
parameters
).
filter
(
not
(
hiddenParams
())).
toList
();
}
private
Predicate
<
Parameter
>
hiddenParams
()
{
return
new
Predicate
<
Parameter
>()
{
@Override
public
boolean
apply
(
Parameter
input
)
{
return
input
.
isHidden
();
}
};
}
private
boolean
shouldIgnore
(
final
ResolvedMethodParameter
parameter
,
ResolvedType
resolvedParameterType
,
final
Set
<
Class
>
ignorableParamTypes
)
{
if
(
ignorableParamTypes
.
contains
(
resolvedParameterType
.
getErasedType
()))
{
return
true
;
}
return
FluentIterable
.
from
(
ignorableParamTypes
)
.
filter
(
isAnnotation
())
.
filter
(
parameterIsAnnotatedWithIt
(
parameter
)).
size
()
>
0
;
}
private
Predicate
<
Class
>
parameterIsAnnotatedWithIt
(
final
ResolvedMethodParameter
parameter
)
{
return
new
Predicate
<
Class
>()
{
@Override
public
boolean
apply
(
Class
input
)
{
return
parameter
.
hasParameterAnnotation
(
input
);
}
};
}
private
Predicate
<
Class
>
isAnnotation
()
{
return
new
Predicate
<
Class
>()
{
@Override
public
boolean
apply
(
Class
input
)
{
return
Annotation
.
class
.
isAssignableFrom
(
input
);
}
};
}
private
boolean
shouldExpand
(
final
ResolvedMethodParameter
parameter
,
ResolvedType
resolvedParamType
)
{
return
!
parameter
.
hasParameterAnnotation
(
RequestBody
.
class
)
&&
!
parameter
.
hasParameterAnnotation
(
RequestPart
.
class
)
&&
!
parameter
.
hasParameterAnnotation
(
RequestParam
.
class
)
&&
!
parameter
.
hasParameterAnnotation
(
PathVariable
.
class
)
&&
!
isBaseType
(
typeNameFor
(
resolvedParamType
.
getErasedType
()))
&&
!
enumTypeDeterminer
.
isEnum
(
resolvedParamType
.
getErasedType
())
&&
!
isContainerType
(
resolvedParamType
)
&&
!
isMapType
(
resolvedParamType
)
&&
!
SearchContextBase
.
class
.
isAssignableFrom
(
resolvedParamType
.
getErasedType
());
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/web/SearchContextHandlerMethodArgumentResolver.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
web
;
import
cn.ibizlab.util.filter.SearchContextBase
;
import
cn.ibizlab.util.domain.DTOBase
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.MethodParameter
;
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
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
@Slf4j
@Configuration
public
class
SearchContextHandlerMethodArgumentResolver
implements
HandlerMethodArgumentResolver
{
@Value
(
"${ibiz.pageLimit:1000}"
)
private
int
pageLimit
=
1000
;
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
@Override
public
boolean
supportsParameter
(
MethodParameter
parameter
)
{
return
SearchContextBase
.
class
.
isAssignableFrom
(
parameter
.
getParameterType
())
||
DTOBase
.
class
.
isAssignableFrom
(
parameter
.
getParameterType
());
}
@Override
public
Object
resolveArgument
(
MethodParameter
parameter
,
ModelAndViewContainer
mavContainer
,
NativeWebRequest
webRequest
,
WebDataBinderFactory
binderFactory
)
throws
Exception
{
Map
<
String
,
String
[]>
params
=
webRequest
.
getParameterMap
();
LinkedHashMap
<
String
,
Object
>
set
=
new
LinkedHashMap
<>();
for
(
String
key
:
params
.
keySet
())
{
set
.
put
(
key
,
params
.
get
(
key
)[
0
]);
}
if
(
SearchContextBase
.
class
.
isAssignableFrom
(
parameter
.
getParameterType
())
&&
(!
set
.
containsKey
(
"size"
))){
set
.
put
(
"size"
,
pageLimit
);
}
String
json
=
objectMapper
.
writeValueAsString
(
set
);
return
objectMapper
.
readValue
(
json
,
parameter
.
getParameterType
());
}
}
\ No newline at end of file
ibizlab-boot-starter-parent/pom.xml
0 → 100644
浏览文件 @
0d372a39
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<!-- Spring Boot -->
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.4.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
pom
</packaging>
<artifactId>
ibizlab-boot-starter-parent
</artifactId>
<groupId>
cn.ibizlab
</groupId>
<version>
2.4.0-SNAPSHOT
</version>
<name>
iBizLab Boot Starter Parent
</name>
<description>
iBizLab Boot Starter Parent
</description>
<properties>
<maven-jar-plugin.version>
3.1.1
</maven-jar-plugin.version>
<spring-boot.version>
2.4.0
</spring-boot.version>
<spring-cloud.version>
2020.0.1
</spring-cloud.version>
<!-- Security -->
<spring-cloud-security.version>
2.2.5.RELEASE
</spring-cloud-security.version>
<!-- Zuul网关 -->
<spring-cloud-starter-netflix-zuul.version>
2.2.10.RELEASE
</spring-cloud-starter-netflix-zuul.version>
<!-- openfeign -->
<spring-cloud-openfeign.version>
2.2.5.RELEASE
</spring-cloud-openfeign.version>
<!-- Spring Cloud Alibaba compatibility -->
<spring-cloud-alibaba.version>
2021.1
</spring-cloud-alibaba.version>
<!-- eureka微服务注册中心 -->
<eureka-client.version>
2.2.5.RELEASE
</eureka-client.version>
<!--Java Web Token-->
<jsonwebtoken-jjwt.version>
0.9.1
</jsonwebtoken-jjwt.version>
<!--反序列化工具-->
<kryo.version>
4.0.2
</kryo.version>
<!-- Error -->
<zalando-problem-spring-web.version>
0.23.0
</zalando-problem-spring-web.version>
<!--httpClient -->
<openfeign-httpclient.version>
11.0
</openfeign-httpclient.version>
<!--log4j2 -->
<log4j2.version>
2.16.0
</log4j2.version>
<fastjson.version>
1.2.83
</fastjson.version>
<!-- Swagger2 -->
<springfox-swagger.version>
2.9.2
</springfox-swagger.version>
<!--MapStruct高性能属性映射工具-->
<mapstruct.version>
1.3.0.Final
</mapstruct.version>
<alibaba-druid.version>
1.2.11
</alibaba-druid.version>
<!--Liquibase数据库版本更新工具-->
<liquibase.version>
3.9.0
</liquibase.version>
<!-- Mybatis Plus -->
<mybatis-plus.version>
3.4.1
</mybatis-plus.version>
<mybatis-plus-dynamic-datasource.version>
3.4.1
</mybatis-plus-dynamic-datasource.version>
<!--baomidou-jobs定时服务 -->
<baomidou-jobs.version>
1.0.3
</baomidou-jobs.version>
<flowable-modeler.version>
6.4.2
</flowable-modeler.version>
<!-- JBPM+Drools -->
<drools-version>
7.23.0.Final
</drools-version>
<maven.deploy.skip>
false
</maven.deploy.skip>
<maven-jar-plugin.version>
2.6
</maven-jar-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot,not include plugin
management as the parent import style -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
${spring-boot.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
${spring-cloud.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-openfeign-dependencies
</artifactId>
<version>
${spring-cloud-openfeign.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!-- Spring Cloud -->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-security
</artifactId>
<version>
${spring-cloud-security.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-zuul
</artifactId>
<version>
${spring-cloud-starter-netflix-zuul.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-alibaba-dependencies
</artifactId>
<version>
${spring-cloud-alibaba.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!-- Alibaba Sentinel -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-sentinel
</artifactId>
<version>
${spring-cloud-alibaba.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
<version>
${eureka-client.version}
</version>
</dependency>
<dependency>
<groupId>
org.zalando
</groupId>
<artifactId>
problem-spring-web
</artifactId>
<version>
${zalando-problem-spring-web.version}
</version>
</dependency>
<dependency>
<groupId>
com.esotericsoftware
</groupId>
<artifactId>
kryo-shaded
</artifactId>
<version>
${kryo.version}
</version>
</dependency>
<dependency>
<groupId>
io.github.openfeign
</groupId>
<artifactId>
feign-httpclient
</artifactId>
<version>
${openfeign-httpclient.version}
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
${lombok.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
${fastjson.version}
</version>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
<version>
${jsonwebtoken-jjwt.version}
</version>
</dependency>
<!-- Swagger2 -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
${springfox-swagger.version}
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
${springfox-swagger.version}
</version>
</dependency>
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct-jdk8
</artifactId>
<version>
${mapstruct.version}
</version>
</dependency>
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct-processor
</artifactId>
<version>
${mapstruct.version}
</version>
</dependency>
<!-- Alibaba Druid -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
${alibaba-druid.version}
</version>
</dependency>
<!-- Mybatis Plus -->
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
${mybatis-plus.version}
</version>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
dynamic-datasource-spring-boot-starter
</artifactId>
<version>
${mybatis-plus-dynamic-datasource.version}
</version>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
jobs-spring-boot-starter
</artifactId>
<version>
${baomidou-jobs.version}
</version>
</dependency>
<!-- Liquibase -->
<dependency>
<groupId>
org.liquibase
</groupId>
<artifactId>
liquibase-core
</artifactId>
<version>
${liquibase.version}
</version>
</dependency>
<!-- JBPM -->
<dependency>
<groupId>
org.jbpm
</groupId>
<artifactId>
jbpm-flow-builder
</artifactId>
<version>
${drools-version}
</version>
</dependency>
<dependency>
<groupId>
org.jbpm
</groupId>
<artifactId>
jbpm-bpmn2
</artifactId>
<version>
${drools-version}
</version>
</dependency>
<!-- Drools -->
<dependency>
<groupId>
org.drools
</groupId>
<artifactId>
drools-compiler
</artifactId>
<version>
${drools-version}
</version>
</dependency>
<dependency>
<groupId>
org.drools
</groupId>
<artifactId>
drools-core
</artifactId>
<version>
${drools-version}
</version>
</dependency>
<dependency>
<groupId>
org.kie
</groupId>
<artifactId>
kie-spring
</artifactId>
<version>
${drools-version}
</version>
</dependency>
<dependency>
<groupId>
org.kie
</groupId>
<artifactId>
kie-api
</artifactId>
<version>
${drools-version}
</version>
</dependency>
<dependency>
<groupId>
org.flowable
</groupId>
<artifactId>
flowable-json-converter
</artifactId>
<version>
${flowable-modeler.version}
</version>
</dependency>
<dependency>
<groupId>
org.flowable
</groupId>
<artifactId>
flowable-ui-modeler-conf
</artifactId>
<version>
${flowable-modeler.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>
ibizmvnrepository
</id>
<url>
http://172.16.240.220:8081/repository/releases
</url>
</repository>
<snapshotRepository>
<id>
ibizmvnrepository
</id>
<url>
http://172.16.240.220:8081/repository/snapshots
</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>
ibizmvnrepository
</id>
<name>
ibizmvnrepository
</name>
<url>
http://172.16.240.220:8081/repository/public/
</url>
<layout>
default
</layout>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
true
</enabled>
<updatePolicy>
always
</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
ibizlab-boot-starter/pom.xml
0 → 100644
浏览文件 @
0d372a39
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
ibizlab-boot-starter-parent
</artifactId>
<groupId>
cn.ibizlab
</groupId>
<version>
2.4.0-SNAPSHOT
</version>
<relativePath>
../ibizlab-boot-starter-parent/pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
ibizlab-boot-starter
</artifactId>
<groupId>
cn.ibizlab
</groupId>
<version>
2.4.0-SNAPSHOT
</version>
<name>
iBizLab Boot Starter
</name>
<description>
iBizLab Boot Starter
</description>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
</dependency>
<!-- Alibaba Sentinel -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-sentinel
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
com.esotericsoftware
</groupId>
<artifactId>
kryo-shaded
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
</dependency>
<dependency>
<groupId>
org.zalando
</groupId>
<artifactId>
problem-spring-web
</artifactId>
</dependency>
<dependency>
<groupId>
io.github.openfeign
</groupId>
<artifactId>
feign-httpclient
</artifactId>
</dependency>
<!--MapStruct高性能属性映射工具-->
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct-jdk8
</artifactId>
</dependency>
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct-processor
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/CaffeineCacheConfig.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
;
import
cn.ibizlab.util.cache.cacheManager.CaffeineCacheManager
;
import
com.github.benmanes.caffeine.cache.CaffeineSpec
;
import
org.springframework.boot.autoconfigure.cache.CacheProperties
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.util.StringUtils
;
/**
* Caffeine缓存配置类
*/
@EnableCaching
@Configuration
@EnableConfigurationProperties
(
CacheProperties
.
class
)
@ConditionalOnExpression
(
"'${ibiz.cacheLevel:None}'.equals('L1')"
)
public
class
CaffeineCacheConfig
{
/**
* Caffeine配置:设置过期时间
* @return
*/
@Bean
@Primary
public
CacheManager
cacheManager
(
CacheProperties
cacheProperties
)
{
CaffeineCacheManager
caffeineCacheManager
=
new
CaffeineCacheManager
();
String
strCacheConfig
=
cacheProperties
.
getCaffeine
().
getSpec
();
if
(
StringUtils
.
hasText
(
strCacheConfig
))
{
caffeineCacheManager
.
setCaffeineCacheConfig
(
CaffeineSpec
.
parse
(
strCacheConfig
));
}
return
caffeineCacheManager
;
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/RedisCacheConfig.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
;
import
cn.ibizlab.util.cache.cacheManager.LayeringCacheManager
;
import
cn.ibizlab.util.cache.listener.RedisMessageListener
;
import
cn.ibizlab.util.cache.redis.CustomJacksonSerializer
;
import
cn.ibizlab.util.enums.RedisChannelTopic
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.github.benmanes.caffeine.cache.CaffeineSpec
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.cache.CacheProperties
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
org.springframework.data.redis.listener.adapter.MessageListenerAdapter
;
import
org.springframework.data.redis.serializer.RedisSerializationContext
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.util.StringUtils
;
import
java.time.Duration
;
/**
* 缓存配置类
* 1级缓存为caffeine
* 2级缓存为redis
*/
@EnableCaching
@Configuration
@EnableConfigurationProperties
(
CacheProperties
.
class
)
@ConditionalOnExpression
(
"'${ibiz.cacheLevel:None}'.equals('L2')"
)
public
class
RedisCacheConfig
{
@Value
(
"${spring.cache.redis.time-to-live:3600}"
)
private
long
timeToLive
;
/**
* 分层缓存管理器
* @param redisConnectionFactory
* @param cacheProperties
* @return
*/
@Bean
@Primary
public
CacheManager
cacheManager
(
RedisConnectionFactory
redisConnectionFactory
,
CacheProperties
cacheProperties
){
LayeringCacheManager
layeringCacheManager
=
new
LayeringCacheManager
(
redisCacheWriter
(
redisConnectionFactory
),
redisCacheConfiguration
(),
redisTemplate
(
redisConnectionFactory
));
String
strCacheConfig
=
cacheProperties
.
getCaffeine
().
getSpec
();
if
(
StringUtils
.
hasText
(
strCacheConfig
))
{
layeringCacheManager
.
setCaffeineCacheConfig
(
CaffeineSpec
.
parse
(
strCacheConfig
));
}
return
layeringCacheManager
;
}
/**
* redis配置:设置过期时间及序列化方式
* @return
*/
@Bean
public
RedisCacheConfiguration
redisCacheConfiguration
(){
CustomJacksonSerializer
jackson2JsonRedisSerializer
=
new
CustomJacksonSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jackson2JsonRedisSerializer
.
setObjectMapper
(
om
);
RedisCacheConfiguration
configuration
=
RedisCacheConfiguration
.
defaultCacheConfig
()
.
entryTtl
(
Duration
.
ofSeconds
(
timeToLive
))
.
serializeKeysWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
new
StringRedisSerializer
()))
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jackson2JsonRedisSerializer
))
.
disableCachingNullValues
();
return
configuration
;
}
/**
* 创建redis缓存
* @param connectionFactory
* @return
*/
@Bean
public
RedisCacheWriter
redisCacheWriter
(
RedisConnectionFactory
connectionFactory
){
RedisCacheWriter
redisCacheWriter
=
RedisCacheWriter
.
nonLockingRedisCacheWriter
(
connectionFactory
);
return
redisCacheWriter
;
}
/**
* 发送redis广播
* @param factory
* @return
*/
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
template
.
setConnectionFactory
(
factory
);
CustomJacksonSerializer
jacksonSerial
=
new
CustomJacksonSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
jacksonSerial
.
setObjectMapper
(
om
);
template
.
setValueSerializer
(
jacksonSerial
);
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
jacksonSerial
);
template
.
afterPropertiesSet
();
return
template
;
}
/**
* 监听redis指定频道
* @param redisConnectionFactory
* @param cacheManager
* @param redisTemplate
* @return
*/
@Bean
RedisMessageListenerContainer
redisContainer
(
RedisConnectionFactory
redisConnectionFactory
,
CacheManager
cacheManager
,
RedisTemplate
redisTemplate
)
{
RedisMessageListenerContainer
container
=
new
RedisMessageListenerContainer
();
MessageListenerAdapter
messageListener
=
new
RedisMessageListener
(
cacheManager
,
redisTemplate
);
container
.
setConnectionFactory
(
redisConnectionFactory
);
container
.
addMessageListener
(
messageListener
,
RedisChannelTopic
.
REDIS_CACHE_DELETE_TOPIC
.
getChannelTopic
());
container
.
addMessageListener
(
messageListener
,
RedisChannelTopic
.
REDIS_CACHE_CLEAR_TOPIC
.
getChannelTopic
());
container
.
addMessageListener
(
messageListener
,
RedisChannelTopic
.
REDIS_CACHE_DYNAMICMODEL_TOPIC
.
getChannelTopic
());
return
container
;
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/cache/CusCaffeineCache.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
cache
;
import
cn.ibizlab.util.helper.Globs
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
org.springframework.cache.caffeine.CaffeineCache
;
import
javax.validation.constraints.NotNull
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 自定义的Caffeine缓存
*/
public
class
CusCaffeineCache
extends
CaffeineCache
{
public
CusCaffeineCache
(
String
name
,
Cache
<
Object
,
Object
>
cache
)
{
super
(
name
,
cache
);
}
public
CusCaffeineCache
(
String
name
,
Cache
<
Object
,
Object
>
cache
,
boolean
allowNullValues
)
{
super
(
name
,
cache
,
allowNullValues
);
}
@Override
public
void
evict
(
@NotNull
Object
key
)
{
if
(
key
instanceof
String
&&
((
String
)
key
).
startsWith
(
"glob:"
))
{
String
globPattern
=
((
String
)
key
).
split
(
"glob:"
)[
1
];
// 将Glob匹配转换成正则匹配
String
regexPattern
=
Globs
.
toUnixRegexPattern
(
globPattern
);
// String regexPattern = Globs.toWindowsRegexPattern(globPattern);
Cache
<
Object
,
Object
>
cache
=
super
.
getNativeCache
();
Set
<
Object
>
keySet
=
cache
.
asMap
().
keySet
();
keySet
=
keySet
.
stream
().
filter
(
o
->
o
.
toString
().
matches
(
regexPattern
)).
collect
(
Collectors
.
toSet
());
cache
.
invalidateAll
(
keySet
);
}
else
{
super
.
evict
(
key
);
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/cache/CusRedisCache.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
cache
;
import
org.springframework.data.redis.cache.RedisCache
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
javax.validation.constraints.NotNull
;
/**
* 自定义的redis缓存
*/
public
class
CusRedisCache
extends
RedisCache
{
public
CusRedisCache
(
String
name
,
RedisCacheWriter
redisCacheWriter
,
RedisCacheConfiguration
configuration
)
{
super
(
name
,
redisCacheWriter
,
configuration
);
}
@Override
public
void
evict
(
@NotNull
Object
key
)
{
if
(
key
instanceof
String
&&
((
String
)
key
).
startsWith
(
"glob:"
))
{
String
globPattern
=
((
String
)
key
).
split
(
"glob:"
)[
1
];
byte
[]
globPatternBytes
=
super
.
getCacheConfiguration
().
getConversionService
().
convert
(
globPattern
,
byte
[].
class
);
if
(
globPatternBytes
!=
null
){
super
.
getNativeCache
().
clean
(
super
.
getName
(),
globPatternBytes
);
}
}
else
{
super
.
evict
(
key
);
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/cache/LayeringCache.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
cache
;
import
cn.ibizlab.util.cache.listener.RedisPublisher
;
import
cn.ibizlab.util.enums.RedisChannelTopic
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cache.caffeine.CaffeineCache
;
import
org.springframework.cache.support.AbstractValueAdaptingCache
;
import
org.springframework.cache.support.NullValue
;
import
org.springframework.data.redis.cache.RedisCache
;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.util.ObjectUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.Callable
;
/**
* 缓存分层类
* 1级缓存为caffeine
* 2级缓存为redis
*/
@Slf4j
public
class
LayeringCache
extends
AbstractValueAdaptingCache
{
/**
* 缓存的名称
*/
private
String
cacheName
;
/**
* Caffeine缓存
*/
private
CaffeineCache
caffeineCache
;
/**
* redis缓存
*/
private
RedisCache
redisCache
;
/**
* redis消息发布
*/
RedisOperations
<?
extends
Object
,
?
extends
Object
>
redisOperations
;
public
LayeringCache
(
String
cacheName
,
CaffeineCache
caffeineCache
,
RedisCache
redisCache
,
RedisOperations
redisOperations
)
{
super
(
true
);
this
.
cacheName
=
cacheName
;
this
.
caffeineCache
=
caffeineCache
;
this
.
redisCache
=
redisCache
;
this
.
redisOperations
=
redisOperations
;
}
@Override
public
String
getName
()
{
return
this
.
cacheName
;
}
@Override
public
Object
getNativeCache
()
{
return
this
;
}
@Override
public
ValueWrapper
get
(
Object
key
)
{
ValueWrapper
wrapper
=
caffeineCache
.
get
(
key
);
Object
value
=
ObjectUtils
.
isEmpty
(
wrapper
)
?
null
:
wrapper
.
get
();
log
.
debug
(
"查询一级缓存 key:{} "
,
key
,
value
);
if
(
ObjectUtils
.
isEmpty
(
value
))
{
wrapper
=
redisCache
.
get
(
key
);
value
=
ObjectUtils
.
isEmpty
(
wrapper
)
?
null
:
wrapper
.
get
();
log
.
debug
(
"查询二级缓存 key:{} "
,
key
);
if
(!
ObjectUtils
.
isEmpty
(
value
))
{
caffeineCache
.
put
(
key
,
value
);
log
.
debug
(
"查询二级缓存,并将数据放到一级缓存。 key:{} "
,
key
);
}
}
return
wrapper
;
}
@Override
public
<
T
>
T
get
(
Object
key
,
Class
<
T
>
type
)
{
T
value
=
caffeineCache
.
get
(
key
,
type
);
log
.
debug
(
"查询一级缓存 key:{}"
,
key
);
if
(
value
==
null
)
{
value
=
redisCache
.
get
(
key
,
type
);
caffeineCache
.
put
(
key
,
value
);
log
.
debug
(
"查询二级缓存,并将数据放到一级缓存。 key:{}"
,
key
);
}
return
value
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
<
T
>
T
get
(
Object
key
,
Callable
<
T
>
valueLoader
)
{
T
value
=
(
T
)
caffeineCache
.
getNativeCache
().
get
(
key
,
k
->
getSecondCacheValue
(
k
,
valueLoader
));
if
(
value
==
null
)
{
value
=
(
T
)
getSecondCacheValue
(
key
,
valueLoader
);
}
if
(
value
instanceof
NullValue
)
{
return
null
;
}
return
value
;
}
@Override
public
void
put
(
Object
key
,
Object
value
)
{
if
(
value
!=
null
)
{
caffeineCache
.
put
(
key
,
value
);
redisCache
.
put
(
key
,
value
);
}
}
@Override
public
ValueWrapper
putIfAbsent
(
Object
key
,
Object
value
)
{
caffeineCache
.
putIfAbsent
(
key
,
value
);
return
redisCache
.
putIfAbsent
(
key
,
value
);
}
@Override
public
void
evict
(
Object
key
)
{
redisCache
.
evict
(
key
);
//清除redis中的二级缓存
caffeineCache
.
evict
(
key
);
//清除本机一级缓存
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
message
.
put
(
"cacheName"
,
cacheName
);
message
.
put
(
"key"
,
key
);
RedisPublisher
redisPublisher
=
new
RedisPublisher
(
redisOperations
,
RedisChannelTopic
.
REDIS_CACHE_DELETE_TOPIC
.
getChannelTopic
());
// 创建redis发布者
redisPublisher
.
publisher
(
message
);
//发布消息,清除其它集群机器中的一级缓存
log
.
debug
(
String
.
format
(
"清除二级缓存数据[%s]"
,
key
));
}
@Override
public
void
clear
()
{
redisCache
.
clear
();
//清除redis中的二级缓存
caffeineCache
.
clear
();
//清除本机一级缓存
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
message
.
put
(
"cacheName"
,
cacheName
);
RedisPublisher
redisPublisher
=
new
RedisPublisher
(
redisOperations
,
RedisChannelTopic
.
REDIS_CACHE_CLEAR_TOPIC
.
getChannelTopic
());
// 创建redis发布者
redisPublisher
.
publisher
(
message
);
//发布消息,清除其它集群机器中的一级缓存
}
@Override
protected
Object
lookup
(
Object
key
)
{
Object
value
=
caffeineCache
.
get
(
key
);
log
.
debug
(
"查询一级缓存 key:{}"
,
key
);
if
(
value
==
null
)
{
value
=
redisCache
.
get
(
key
);
log
.
debug
(
"查询二级缓存 key:{}"
,
key
);
}
return
value
;
}
/**
* 获取caffeine缓存
* @return
*/
public
CaffeineCache
getFirstCache
()
{
return
this
.
caffeineCache
;
}
/**
* 获取redis缓存
* @return
*/
public
RedisCache
getSecondCache
()
{
return
this
.
redisCache
;
}
/**
* 查询二级缓存
* @param key
* @param valueLoader
* @return
*/
private
<
T
>
Object
getSecondCacheValue
(
Object
key
,
Callable
<
T
>
valueLoader
)
{
T
value
=
redisCache
.
get
(
key
,
valueLoader
);
log
.
debug
(
"查询二级缓存 key:{}"
,
key
);
return
toStoreValue
(
value
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/cacheManager/CaffeineCacheManager.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
cacheManager
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.CaffeineSpec
;
import
lombok.Data
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.caffeine.CaffeineCache
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.TimeUnit
;
/**
* Caffeine本地缓存
*/
@Data
public
class
CaffeineCacheManager
implements
CacheManager
{
private
final
ConcurrentMap
<
String
,
Cache
>
cacheMap
=
new
ConcurrentHashMap
<
String
,
Cache
>(
16
);
private
static
final
int
default_expire_after_write
=
1
;
private
static
final
int
default_initial_capacity
=
5
;
private
static
final
int
default_maximum_size
=
1_000
;
private
Caffeine
<
Object
,
Object
>
cacheBuilder
=
Caffeine
.
newBuilder
()
.
expireAfterAccess
(
default_expire_after_write
,
TimeUnit
.
HOURS
)
.
initialCapacity
(
default_initial_capacity
)
.
maximumSize
(
default_maximum_size
);
/**
* 获取缓存对象
* @param cacheName
* @return
*/
@Override
public
Cache
getCache
(
String
cacheName
)
{
Cache
cache
=
this
.
cacheMap
.
get
(
cacheName
);
if
(
cache
==
null
)
{
synchronized
(
this
.
cacheMap
)
{
cache
=
this
.
cacheMap
.
get
(
cacheName
);
if
(
cache
==
null
)
{
cache
=
createCache
(
cacheName
);
this
.
cacheMap
.
put
(
cacheName
,
cache
);
}
}
}
return
cache
;
}
/**
* 创建缓存
* @param cacheName
* @return
*/
protected
Cache
createCache
(
String
cacheName
)
{
return
new
CaffeineCache
(
cacheName
,
this
.
cacheBuilder
.
build
(),
true
);
}
/**
* 获取缓存名
* @return
*/
@Override
public
Collection
<
String
>
getCacheNames
()
{
return
Collections
.
unmodifiableSet
(
this
.
cacheMap
.
keySet
());
}
/**
* 缓存配置[缓存容量大小、时长等]
* @param caffeineCacheConfig
*/
public
void
setCaffeineCacheConfig
(
CaffeineSpec
caffeineCacheConfig
)
{
Caffeine
<
Object
,
Object
>
cacheBuilder
=
Caffeine
.
from
(
caffeineCacheConfig
);
if
(!
ObjectUtils
.
nullSafeEquals
(
this
.
cacheBuilder
,
cacheBuilder
))
{
this
.
cacheBuilder
=
cacheBuilder
;
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/cacheManager/LayeringCacheManager.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
cacheManager
;
import
cn.ibizlab.util.cache.cache.CusCaffeineCache
;
import
cn.ibizlab.util.cache.cache.CusRedisCache
;
import
cn.ibizlab.util.cache.cache.LayeringCache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.CaffeineSpec
;
import
lombok.Data
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.TimeUnit
;
/**
* 缓存分层
* 1级缓存为caffeine
* 2级缓存为redis
*/
@Data
public
class
LayeringCacheManager
implements
CacheManager
{
private
final
ConcurrentMap
<
String
,
Cache
>
cacheMap
=
new
ConcurrentHashMap
<
String
,
Cache
>(
16
);
private
static
final
int
default_expire_after_write
=
1
;
private
static
final
int
default_initial_capacity
=
5
;
private
static
final
int
default_maximum_size
=
1_000
;
private
Caffeine
<
Object
,
Object
>
cacheBuilder
=
Caffeine
.
newBuilder
()
.
expireAfterAccess
(
default_expire_after_write
,
TimeUnit
.
HOURS
)
.
initialCapacity
(
default_initial_capacity
)
.
maximumSize
(
default_maximum_size
);
private
RedisCacheWriter
redisCacheWriter
;
private
RedisCacheConfiguration
redisConfiguration
;
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
public
LayeringCacheManager
(
RedisCacheWriter
redisCacheWriter
,
RedisCacheConfiguration
redisConfiguration
,
RedisTemplate
<
String
,
Object
>
redisTemplate
){
this
.
redisCacheWriter
=
redisCacheWriter
;
this
.
redisConfiguration
=
redisConfiguration
;
this
.
redisTemplate
=
redisTemplate
;
}
/**
* 获取缓存对象
* @param cacheName
* @return
*/
@Override
public
Cache
getCache
(
String
cacheName
)
{
Cache
cache
=
this
.
cacheMap
.
get
(
cacheName
);
if
(
cache
==
null
)
{
synchronized
(
this
.
cacheMap
)
{
cache
=
this
.
cacheMap
.
get
(
cacheName
);
if
(
cache
==
null
)
{
cache
=
createCache
(
cacheName
);
this
.
cacheMap
.
put
(
cacheName
,
cache
);
}
}
}
return
cache
;
}
/**
* 获取集合中的缓存
* @return
*/
@Override
public
Collection
<
String
>
getCacheNames
()
{
return
Collections
.
unmodifiableSet
(
this
.
cacheMap
.
keySet
());
}
/**
* 创建缓存
* @param cacheName
* @return
*/
protected
Cache
createCache
(
String
cacheName
)
{
return
new
LayeringCache
(
cacheName
,
new
CusCaffeineCache
(
cacheName
,
this
.
cacheBuilder
.
build
(),
true
),
new
CusRedisCache
(
cacheName
,
redisCacheWriter
,
redisConfiguration
),
redisTemplate
);
}
/**
* 缓存配置[缓存容量大小、时长等]
* @param caffeineCacheConfig
*/
public
void
setCaffeineCacheConfig
(
CaffeineSpec
caffeineCacheConfig
)
{
Caffeine
<
Object
,
Object
>
cacheBuilder
=
Caffeine
.
from
(
caffeineCacheConfig
);
if
(!
ObjectUtils
.
nullSafeEquals
(
this
.
cacheBuilder
,
cacheBuilder
))
{
this
.
cacheBuilder
=
cacheBuilder
;
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/listener/RedisMessageListener.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
listener
;
import
cn.ibizlab.util.cache.cache.LayeringCache
;
import
cn.ibizlab.util.enums.RedisChannelTopic
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.data.redis.connection.Message
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.listener.adapter.MessageListenerAdapter
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.Map
;
/**
* redis消息的订阅者
*/
@Slf4j
public
class
RedisMessageListener
extends
MessageListenerAdapter
{
private
CacheManager
cacheManager
;
private
RedisTemplate
redisTemplate
;
public
RedisMessageListener
(
CacheManager
cacheManager
,
RedisTemplate
redisTemplate
){
this
.
cacheManager
=
cacheManager
;
this
.
redisTemplate
=
redisTemplate
;
}
@Override
public
void
onMessage
(
Message
message
,
byte
[]
pattern
)
{
RedisChannelTopic
channelTopic
=
RedisChannelTopic
.
getChannelTopicEnum
(
new
String
(
message
.
getChannel
()));
Map
<
String
,
Object
>
map
=
null
;
RedisSerializer
serializer
=
redisTemplate
.
getValueSerializer
();
Object
result
=
serializer
.
deserialize
(
message
.
getBody
());
if
(
result
instanceof
Map
){
map
=
(
Map
<
String
,
Object
>)
result
;
}
if
(
ObjectUtils
.
isEmpty
(
map
)||
(!
map
.
containsKey
(
"cacheName"
))){
log
.
debug
(
"解析缓存数据失败,无法获取指定值!"
);
return
;
}
log
.
debug
(
"redis消息订阅者接收到频道【{}】发布的消息。消息内容:{}"
,
channelTopic
.
getChannelTopicStr
(),
result
.
toString
());
String
cacheName
=
(
String
)
map
.
get
(
"cacheName"
);
Cache
cache
=
cacheManager
.
getCache
(
cacheName
);
// 根据缓存名称获取多级缓存
if
(
cache
!=
null
&&
cache
instanceof
LayeringCache
)
{
// 判断缓存是否是多级缓存
switch
(
channelTopic
)
{
case
REDIS_CACHE_DELETE_TOPIC:
// 获取一级缓存,并删除一级缓存数据
Object
cacheKey
=
map
.
get
(
"key"
);
if
(!
ObjectUtils
.
isEmpty
(
cacheKey
)){
((
LayeringCache
)
cache
).
getFirstCache
().
evict
(
cacheKey
);
((
LayeringCache
)
cache
).
getSecondCache
().
evict
(
cacheKey
);
log
.
debug
(
"同步删除缓存{}数据,key:{},"
,
cacheName
,
cacheKey
.
toString
());
}
else
{
log
.
debug
(
"同步删除缓存失败,{}缓存键值为空!"
,
cacheName
);
}
break
;
case
REDIS_CACHE_CLEAR_TOPIC:
// 获取一级缓存,并删除一级缓存数据
((
LayeringCache
)
cache
).
getFirstCache
().
clear
();
((
LayeringCache
)
cache
).
getSecondCache
().
clear
();
log
.
debug
(
"同步清除缓存{}数据"
,
cacheName
);
break
;
default
:
log
.
debug
(
"接收到没有定义的订阅消息频道数据"
);
break
;
}
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/listener/RedisPublisher.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
listener
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.data.redis.listener.ChannelTopic
;
/**
* redis消息的发布者
*/
public
class
RedisPublisher
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RedisPublisher
.
class
);
RedisOperations
<?
extends
Object
,
?
extends
Object
>
redisOperations
;
/**
* 频道名称
*/
ChannelTopic
channelTopic
;
/**
* @param redisOperations Redis客户端
* @param channelTopic 频道名称
*/
public
RedisPublisher
(
RedisOperations
<?
extends
Object
,
?
extends
Object
>
redisOperations
,
ChannelTopic
channelTopic
)
{
this
.
channelTopic
=
channelTopic
;
this
.
redisOperations
=
redisOperations
;
}
/**
* 发布消息到频道(Channel)
*
* @param message 消息内容
*/
public
void
publisher
(
Object
message
)
{
redisOperations
.
convertAndSend
(
channelTopic
.
toString
(),
message
);
logger
.
debug
(
"redis消息发布者向频道【{}】发布了【{}】消息"
,
channelTopic
.
toString
(),
message
.
toString
());
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/cache/redis/CustomJacksonSerializer.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
cache
.
redis
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.SerializationException
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
CustomJacksonSerializer
<
T
>
extends
Jackson2JsonRedisSerializer
<
T
>
{
public
static
final
String
DEFAULT_PACKAGE
=
"[\\w+\\.]+\\.AuthenticationUser"
;
public
static
final
String
CLASSNAME_EX
=
"_$$_"
;
public
static
final
String
CLASSNAME_EX_PATTEN
=
"(_\\$\\$_)(\\w+)"
;
public
static
final
String
USER_PACKAGE
=
AuthenticationUser
.
class
.
getName
();
public
CustomJacksonSerializer
(
Class
type
)
{
super
(
type
);
}
@Override
public
T
deserialize
(
byte
[]
bytes
)
throws
SerializationException
{
String
serializerContent
=
new
String
(
bytes
,
DEFAULT_CHARSET
);
Matcher
matcher
=
Pattern
.
compile
(
DEFAULT_PACKAGE
).
matcher
(
serializerContent
);
if
(
matcher
.
find
()){
serializerContent
=
serializerContent
.
replaceAll
(
DEFAULT_PACKAGE
,
USER_PACKAGE
);
}
if
(
serializerContent
.
contains
(
CLASSNAME_EX
)){
serializerContent
=
serializerContent
.
replaceAll
(
CLASSNAME_EX_PATTEN
,
""
);
}
return
super
.
deserialize
(
serializerContent
.
getBytes
());
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZDictFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.dict.Catalog
;
import
cn.ibizlab.util.dict.CodeList
;
import
com.alibaba.fastjson.JSONArray
;
import
org.springframework.stereotype.Component
;
@Component
public
class
IBZDictFallback
implements
IBZDictFeignClient
{
@Override
public
Boolean
syncRuntimeDict
(
JSONArray
catalogs
)
{
return
null
;
}
@Override
public
CodeList
getCodeList
(
String
code
)
{
return
null
;
}
@Override
public
Catalog
getCatalog
(
String
code
)
{
return
null
;
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZDictFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.dict.Catalog
;
import
cn.ibizlab.util.dict.CodeList
;
import
com.alibaba.fastjson.JSONArray
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"${ibiz.ref.service.dict:ibzdict-api}"
,
contextId
=
"dict"
,
fallback
=
IBZDictFallback
.
class
)
public
interface
IBZDictFeignClient
{
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dictionarys/catalogs/sync"
)
Boolean
syncRuntimeDict
(
@RequestBody
JSONArray
catalogs
);
@Cacheable
(
value
=
"dictcatalog"
,
key
=
"'codelist:'+#p0"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/dictionarys/codelist/{code}"
)
CodeList
getCodeList
(
@PathVariable
(
"code"
)
String
code
);
@Cacheable
(
value
=
"dictcatalog"
,
key
=
"'dict:'+#p0"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/dictionarys/catalogs/{code}"
)
Catalog
getCatalog
(
@PathVariable
(
"code"
)
String
code
);
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZLiteFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
@Component
public
class
IBZLiteFallback
implements
IBZLiteFeignClient
{
@Override
public
Boolean
syncSysModel
(
JSONObject
system
)
{
return
null
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZLiteFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
@FeignClient
(
value
=
"${ibiz.ref.service.lite:ibzlite-api}"
,
contextId
=
"lite"
,
fallback
=
IBZLiteFallback
.
class
)
public
interface
IBZLiteFeignClient
{
/**
* 同步系统资模型到lite
* @param system 系统模型信息
* @return
*/
@PostMapping
(
"/lite/syncsysmodel"
)
Boolean
syncSysModel
(
@RequestBody
JSONObject
system
);
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZNotifyFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.domain.MsgBody
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
@Component
public
class
IBZNotifyFallback
implements
IBZNotifyFeignClient
{
@Override
public
Boolean
sendMsg
(
MsgBody
msg
)
{
return
null
;
}
@Override
public
Boolean
createMsgTemplate
(
JSONObject
template
)
{
return
null
;
}
@Override
public
Boolean
sendDingTalkLinkMsg
(
MsgBody
msg
)
{
return
null
;
}
@Override
public
String
createDingTalkWorkRecord
(
MsgBody
msg
)
{
return
null
;
}
@Override
public
Boolean
finishDingTalkWorkRecord
(
String
msgId
)
{
return
null
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZNotifyFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.domain.MsgBody
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
@FeignClient
(
value
=
"${ibiz.ref.service.notify:ibznotify-api}"
,
contextId
=
"notify"
,
fallback
=
IBZNotifyFallback
.
class
)
public
interface
IBZNotifyFeignClient
{
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/notify/sendmsg"
)
Boolean
sendMsg
(
@RequestBody
MsgBody
msg
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/notify/createmsgtempl"
)
Boolean
createMsgTemplate
(
@RequestBody
JSONObject
template
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/notify/dingtalk/sendlinkmsg"
)
Boolean
sendDingTalkLinkMsg
(
@RequestBody
MsgBody
msg
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/notify/dingtalk/createworkrecord"
)
String
createDingTalkWorkRecord
(
@RequestBody
MsgBody
msg
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/notify/dingtalk/finishworkrecord/{msgid}"
)
Boolean
finishDingTalkWorkRecord
(
@PathVariable
(
"msgid"
)
String
msgId
);
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZOUFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
java.util.Set
;
@Component
public
class
IBZOUFallback
implements
IBZOUFeignClient
{
@Override
public
Map
<
String
,
Set
<
String
>>
getOUMapsByUserId
(
String
userId
)
{
return
null
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZOUFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
java.util.Map
;
import
java.util.Set
;
@FeignClient
(
value
=
"${ibiz.ref.service.ou:ibzou-api}"
,
contextId
=
"ou"
,
fallback
=
IBZOUFallback
.
class
)
public
interface
IBZOUFeignClient
{
/**
* 从ou中获取当前上下级组织、部门信息
* @param userId
* @return
*/
@GetMapping
(
"/sysemployees/{userId}/oumaps"
)
Map
<
String
,
Set
<
String
>>
getOUMapsByUserId
(
@PathVariable
(
"userId"
)
String
userId
);
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZPayFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.domain.PayTrade
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
@Component
public
class
IBZPayFallback
implements
IBZPayFeignClient
{
@Override
public
JSONObject
preCreate
(
PayTrade
trade
)
{
return
null
;
}
@Override
public
JSONObject
query
(
PayTrade
trade
)
{
return
null
;
}
@Override
public
JSONObject
cancel
(
PayTrade
trade
)
{
return
null
;
}
@Override
public
String
pagePay
(
PayTrade
trade
)
{
return
null
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZPayFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.domain.PayTrade
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"${ibiz.ref.service.pay:ibzpay-api}"
,
contextId
=
"pay"
,
fallback
=
IBZPayFallback
.
class
)
public
interface
IBZPayFeignClient
{
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/pay/trade/precreate"
)
JSONObject
preCreate
(
@RequestBody
PayTrade
trade
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/pay/trade/query"
)
JSONObject
query
(
@RequestBody
PayTrade
trade
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/pay/trade/cancel"
)
JSONObject
cancel
(
@RequestBody
PayTrade
trade
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/pay/trade/pagepay"
)
String
pagePay
(
@RequestBody
PayTrade
trade
);
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZUAAFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
@Component
public
class
IBZUAAFallback
implements
IBZUAAFeignClient
{
@Override
public
Boolean
syncSysAuthority
(
JSONObject
system
)
{
return
null
;
}
@Override
public
AuthenticationUser
login
(
AuthorizationLogin
authorizationLogin
)
{
return
null
;
}
@Override
public
AuthenticationUser
loginByUsername
(
String
username
)
{
return
null
;
}
@Override
public
String
getPublicKey
()
{
return
null
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZUAAFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
@FeignClient
(
value
=
"${ibiz.ref.service.uaa:ibzuaa-api}"
,
contextId
=
"uaa"
,
fallback
=
IBZUAAFallback
.
class
)
public
interface
IBZUAAFeignClient
{
/**
* 同步系统资源到uaa
* @param system 系统资源信息
* @return
*/
@PostMapping
(
"/syspssystems/save"
)
Boolean
syncSysAuthority
(
@RequestBody
JSONObject
system
);
/**
* 用户登录
* @param authorizationLogin 登录信息
* @return
*/
@PostMapping
(
value
=
"/uaa/login"
)
AuthenticationUser
login
(
@RequestBody
AuthorizationLogin
authorizationLogin
);
@PostMapping
(
value
=
"/uaa/loginbyusername"
)
AuthenticationUser
loginByUsername
(
@RequestBody
String
username
);
@Cacheable
(
value
=
"ibzuaa_publickey"
)
@GetMapping
(
value
=
"/uaa/publickey"
)
String
getPublicKey
();
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZWFFallback.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
IBZWFFallback
implements
IBZWFFeignClient
{
@Override
public
List
<
String
>
getbusinesskeys
(
String
system
,
String
appname
,
String
entity
,
String
processDefinitionKey
,
String
taskDefinitionKey
)
{
return
null
;
}
@Override
public
List
<
String
>
getbusinesskeysByUserId
(
String
system
,
String
userId
,
String
entity
,
String
processDefinitionKey
,
String
taskDefinitionKey
)
{
return
null
;
}
@Override
public
Boolean
deployBpmnFile
(
List
<
Map
<
String
,
Object
>>
bpmnfiles
)
{
return
null
;
}
@Override
public
JSONObject
wfstart
(
String
system
,
String
appname
,
String
entity
,
String
businessKey
,
JSONObject
instance
)
{
return
null
;
}
@Override
public
Map
<
String
,
Map
<
String
,
Object
>>
getTask
(
String
system
,
String
userId
,
String
entity
,
String
instTag
,
String
instTag2
,
String
taskType
)
{
return
null
;
}
@Override
public
Map
<
String
,
Map
<
String
,
Object
>>
getTaskByStep
(
String
system
,
String
userId
,
String
entity
,
String
instTag
,
String
instTag2
,
String
taskType
,
String
srfwfstep
)
{
return
null
;
}
@Override
public
Integer
getDataAccessMode
(
String
system
,
String
entity
,
Serializable
businessKey
)
{
return
null
;
}
@Override
public
Map
<
String
,
Map
<
String
,
Object
>>
getMyTask
(
String
system
,
String
appName
,
String
entity
)
{
return
null
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZWFFeignClient.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
client
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.Map
;
@FeignClient
(
value
=
"${ibiz.ref.service.wf:ibzwf-api}"
,
contextId
=
"wf"
,
fallback
=
IBZWFFallback
.
class
)
public
interface
IBZWFFeignClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/{system}-app-{appname}/{entity}/process-definitions/{processDefinitionKey}/usertasks/{taskDefinitionKey}/tasks"
)
List
<
String
>
getbusinesskeys
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"appname"
)
String
appname
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
"processDefinitionKey"
)
String
processDefinitionKey
,
@PathVariable
(
"taskDefinitionKey"
)
String
taskDefinitionKey
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/{system}-user-{userId}/{entity}/process-definitions/{processDefinitionKey}/usertasks/{taskDefinitionKey}/tasks"
)
List
<
String
>
getbusinesskeysByUserId
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"userId"
)
String
userId
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
"processDefinitionKey"
)
String
processDefinitionKey
,
@PathVariable
(
"taskDefinitionKey"
)
String
taskDefinitionKey
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/deploybpmn"
)
Boolean
deployBpmnFile
(
@RequestBody
List
<
Map
<
String
,
Object
>>
bpmnfiles
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/{system}-app-{appname}/{entity}/{businessKey}/process-instances"
)
JSONObject
wfstart
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"appname"
)
String
appname
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
"businessKey"
)
String
businessKey
,
@RequestBody
JSONObject
instance
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/{system}-user-{userId}/{insttag}/{insttag2}/{entity}/tasks"
)
Map
<
String
,
Map
<
String
,
Object
>>
getTask
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"userId"
)
String
userId
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
"insttag"
)
String
instTag
,
@PathVariable
(
"insttag2"
)
String
instTag2
,
@RequestParam
(
"srfwf"
)
String
taskType
);
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/{system}-user-{userId}/{insttag}/{insttag2}/{entity}/tasks"
)
Map
<
String
,
Map
<
String
,
Object
>>
getTaskByStep
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"userId"
)
String
userId
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
"insttag"
)
String
instTag
,
@PathVariable
(
"insttag2"
)
String
instTag2
,
@RequestParam
(
"srfwf"
)
String
taskType
,
@RequestParam
(
"n_taskdefinitionkey_eq"
)
String
srfwfstep
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/{system}/{entity}/{businessKey}/dataaccessmode"
)
Integer
getDataAccessMode
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
"businessKey"
)
Serializable
businessKey
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/{system}-app-{appname}/{entity}/mytasks"
)
Map
<
String
,
Map
<
String
,
Object
>>
getMyTask
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"appname"
)
String
appName
,
@PathVariable
(
"entity"
)
String
entity
);
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/dict/Catalog.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
dict
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors
(
chain
=
true
)
public
class
Catalog
{
private
String
code
;
private
String
name
;
@JSONField
(
name
=
"items"
)
@JsonProperty
(
"items"
)
private
List
<
Option
>
options
=
new
ArrayList
<>();
public
Option
findCodeItem
(
Object
value
)
{
return
findCodeItem
(
value
,
this
.
options
);
}
public
Option
findCodeItem
(
Object
value
,
List
<
Option
>
options
){
for
(
Option
codeItem
:
options
){
if
(
value
!=
null
&&
codeItem
.
getValue
()
!=
null
&&
value
.
equals
(
codeItem
.
getValue
()))
return
codeItem
;
else
if
(!
ObjectUtils
.
isEmpty
(
codeItem
.
getChildren
()))
{
Option
rt
=
findCodeItem
(
value
,
codeItem
.
getChildren
());
if
(
rt
!=
null
)
return
rt
;
}
}
return
null
;
}
private
Map
<
String
,
Object
>
advancedSettings
;
public
Catalog
putAdvancedSettings
(
String
settings
)
{
try
{
if
(!
ObjectUtils
.
isEmpty
(
settings
))
advancedSettings
=
JSON
.
parseObject
(
settings
,
Map
.
class
);
}
catch
(
Exception
ex
){}
return
this
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getUrl
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"url"
)!=
null
?
advancedSettings
.
get
(
"url"
).
toString
():
null
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getRequestMethod
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"requestMethod"
)!=
null
?
advancedSettings
.
get
(
"requestMethod"
).
toString
():
"GET"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getRequestBody
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"requestBody"
)!=
null
?
advancedSettings
.
get
(
"requestBody"
).
toString
():
"{}"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getNodeProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"nodeProp"
)!=
null
?
advancedSettings
.
get
(
"nodeProp"
).
toString
():
""
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getValueProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"valueProp"
)!=
null
?
advancedSettings
.
get
(
"valueProp"
).
toString
():
"value"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getLabelProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"labelProp"
)!=
null
?
advancedSettings
.
get
(
"labelProp"
).
toString
():
"label"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getParentProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"parentProp"
)!=
null
?
advancedSettings
.
get
(
"parentProp"
).
toString
():
"parent"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getChildrenProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"childrenProp"
)!=
null
?
advancedSettings
.
get
(
"childrenProp"
).
toString
():
"children"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getDisabledProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"disabledProp"
)!=
null
?
advancedSettings
.
get
(
"disabledProp"
).
toString
():
"disabled"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getFilterProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"filterProp"
)!=
null
?
advancedSettings
.
get
(
"filterProp"
).
toString
():
"filter"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getExpiredProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"expiredProp"
)!=
null
?
advancedSettings
.
get
(
"expiredProp"
).
toString
():
"expired"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getIconClassProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"iconClassProp"
)!=
null
?
advancedSettings
.
get
(
"iconClassProp"
).
toString
():
"iconClass"
;
}
public
Catalog
setNodes
(
List
<
Map
>
nodes
)
{
return
setNodes
(
nodes
,
null
,
null
);
}
public
Catalog
setNodes
(
List
<
Map
>
nodes
,
String
filter
,
String
subCode
)
{
Map
<
String
,
List
<
Option
>>
map
=
new
LinkedHashMap
<>();
Option
subOption
=
null
;
for
(
Map
item:
unfoldList
(
nodes
,
null
))
{
Map
<
String
,
Object
>
extension
=
new
HashMap
<>();
if
(!
ObjectUtils
.
isEmpty
(
item
.
get
(
"extension"
)))
extension
=
JSONObject
.
parseObject
(
item
.
get
(
"extension"
).
toString
(),
Map
.
class
);
String
pid
=
DataObject
.
getStringValue
(
item
.
get
(
this
.
getParentProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"pvalue"
),
"_root"
));
if
(
ObjectUtils
.
isEmpty
(
pid
))
pid
=
"_root"
;
List
<
Option
>
list
=
null
;
if
(!
map
.
containsKey
(
pid
))
{
list
=
new
ArrayList
<>();
map
.
put
(
pid
,
list
);
}
else
list
=
map
.
get
(
pid
);
Option
option
=
new
Option
().
setValue
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getValueProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"id"
),
null
)))
.
setId
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getValueProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"id"
),
null
)))
.
setDisabled
(
DataObject
.
getBooleanValue
(
item
.
get
(
this
.
getDisabledProp
()),
false
)||
DataObject
.
getBooleanValue
(
item
.
get
(
this
.
getExpiredProp
()),
false
))
.
setFilter
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getFilterProp
()),
null
)).
setIconClass
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getIconClassProp
()),
null
))
.
setLabel
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getLabelProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"text"
),
""
)))
.
setParent
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getParentProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"pvalue"
),
""
))).
setExtension
(
extension
);
if
(
option
.
getValue
().
equals
(
subCode
))
subOption
=
option
;
if
(
ObjectUtils
.
isEmpty
(
filter
)||
option
.
getFilterSet
().
contains
(
filter
))
list
.
add
(
option
);
}
List
<
Option
>
codeItemTreeList
=
loop
(
map
,
(
ObjectUtils
.
isEmpty
(
subCode
))?
"_root"
:
subCode
);
if
(
subOption
!=
null
)
{
subOption
.
setChildren
(
codeItemTreeList
).
setParent
(
""
);
this
.
getOptions
().
add
(
subOption
.
setParent
(
null
));
}
else
this
.
setOptions
(
codeItemTreeList
);
return
this
;
}
public
List
<
Map
>
unfoldList
(
List
<
Map
>
nodes
,
String
parent
)
{
List
<
Map
>
unfoldList
=
new
ArrayList
<>();
for
(
Map
item:
nodes
)
{
if
((!
ObjectUtils
.
isEmpty
(
parent
))&&
ObjectUtils
.
isEmpty
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getParentProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"pvalue"
),
null
))))
item
.
put
(
this
.
getParentProp
(),
parent
);
String
value
=
DataObject
.
getStringValue
(
item
.
get
(
this
.
getValueProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"id"
),
null
));
unfoldList
.
add
(
item
);
Object
child
=
item
.
get
(
this
.
getChildrenProp
());
if
(!
ObjectUtils
.
isEmpty
(
child
))
{
if
(
child
instanceof
List
&&
((
List
)
child
).
get
(
0
)
instanceof
Map
)
unfoldList
.
addAll
(
unfoldList
((
List
)
child
,
value
));
item
.
remove
(
this
.
getChildrenProp
());
}
}
return
unfoldList
;
}
public
List
<
Option
>
loop
(
Map
<
String
,
List
<
Option
>>
listCodeItem
,
Object
parentValue
)
{
List
<
Option
>
trees
=
new
ArrayList
<
Option
>();
if
(
listCodeItem
.
containsKey
(
parentValue
))
{
for
(
Option
codeItem
:
listCodeItem
.
get
(
parentValue
))
{
List
<
Option
>
childCodeItem
=
loop
(
listCodeItem
,
codeItem
.
getValue
());
if
(
childCodeItem
.
size
()
>
0
)
codeItem
.
setChildren
(
childCodeItem
);
trees
.
add
(
codeItem
);
}
}
return
trees
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/dict/CodeItem.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
dict
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors
(
chain
=
true
)
public
class
CodeItem
{
private
String
id
;
private
Object
value
;
private
String
label
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
List
<
CodeItem
>
children
;
private
String
iconClass
;
private
String
filter
;
private
Boolean
disabled
;
@JSONField
(
name
=
"pvalue"
)
@JsonProperty
(
"pvalue"
)
private
String
parent
;
private
Map
<
String
,
Object
>
extension
;
@JSONField
(
name
=
"text"
)
@JsonProperty
(
"text"
)
public
String
getText
()
{
return
label
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Set
<
String
>
getFilterSet
()
{
Set
<
String
>
set
=
new
HashSet
<>();
if
(!
ObjectUtils
.
isEmpty
(
filter
))
for
(
String
str:
filter
.
split
(
";|,"
))
set
.
add
(
str
);
return
set
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/dict/CodeList.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
dict
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors
(
chain
=
true
)
public
class
CodeList
{
@JSONField
(
name
=
"srfkey"
)
@JsonProperty
(
"srfkey"
)
private
String
code
;
private
String
name
;
@JSONField
(
name
=
"emptytext"
)
@JsonProperty
(
"emptytext"
)
public
String
getEmptytext
()
{
return
""
;
}
@JSONField
(
name
=
"items"
)
@JsonProperty
(
"items"
)
private
List
<
CodeItem
>
options
=
new
ArrayList
<>();
public
CodeItem
findCodeItem
(
Object
value
){
for
(
CodeItem
codeItem
:
options
){
if
(
value
!=
null
&&
codeItem
.
getValue
()
!=
null
&&
value
.
equals
(
codeItem
.
getValue
()))
return
codeItem
;
}
return
null
;
}
public
CodeItem
findChildren
(
Object
value
){
CodeItem
resultCodeItem
=
this
.
findCodeItem
(
value
);
List
<
CodeItem
>
children
=
new
ArrayList
<>();
for
(
CodeItem
codeItem
:
options
){
if
(
value
!=
null
&&
resultCodeItem
.
getValue
()
!=
null
&&
codeItem
.
getParent
()
!=
null
&&
codeItem
.
getParent
().
equals
(
resultCodeItem
.
getValue
()))
children
.
add
(
codeItem
);
}
resultCodeItem
.
setChildren
(
children
);
return
resultCodeItem
;
}
private
Map
<
String
,
Object
>
advancedSettings
;
public
CodeList
putAdvancedSettings
(
String
settings
)
{
try
{
if
(!
ObjectUtils
.
isEmpty
(
settings
))
advancedSettings
=
JSON
.
parseObject
(
settings
,
Map
.
class
);
}
catch
(
Exception
ex
){}
return
this
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getUrl
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"url"
)!=
null
?
advancedSettings
.
get
(
"url"
).
toString
():
null
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getRequestMethod
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"requestMethod"
)!=
null
?
advancedSettings
.
get
(
"requestMethod"
).
toString
():
"GET"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getRequestBody
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"requestBody"
)!=
null
?
advancedSettings
.
get
(
"requestBody"
).
toString
():
"{}"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getNodeProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"nodeProp"
)!=
null
?
advancedSettings
.
get
(
"nodeProp"
).
toString
():
""
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getValueProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"valueProp"
)!=
null
?
advancedSettings
.
get
(
"valueProp"
).
toString
():
"value"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getLabelProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"labelProp"
)!=
null
?
advancedSettings
.
get
(
"labelProp"
).
toString
():
"label"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getParentProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"parentProp"
)!=
null
?
advancedSettings
.
get
(
"parentProp"
).
toString
():
"parent"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getChildrenProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"childrenProp"
)!=
null
?
advancedSettings
.
get
(
"childrenProp"
).
toString
():
"children"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getDisabledProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"disabledProp"
)!=
null
?
advancedSettings
.
get
(
"disabledProp"
).
toString
():
"disabled"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getFilterProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"filterProp"
)!=
null
?
advancedSettings
.
get
(
"filterProp"
).
toString
():
"filter"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getExpiredProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"expiredProp"
)!=
null
?
advancedSettings
.
get
(
"expiredProp"
).
toString
():
"expired"
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getIconClassProp
()
{
return
advancedSettings
!=
null
&&
advancedSettings
.
get
(
"iconClassProp"
)!=
null
?
advancedSettings
.
get
(
"iconClassProp"
).
toString
():
"iconClass"
;
}
public
CodeList
setNodes
(
List
<
Map
>
nodes
,
String
filter
,
String
subCode
)
{
Map
<
String
,
List
<
CodeItem
>>
map
=
new
LinkedHashMap
<>();
List
<
CodeItem
>
alllist
=
new
ArrayList
<>();
CodeItem
subOption
=
null
;
for
(
Map
item:
unfoldList
(
nodes
,
null
))
{
Map
<
String
,
Object
>
extension
=
new
HashMap
<>();
if
(!
ObjectUtils
.
isEmpty
(
item
.
get
(
"extension"
)))
extension
=
JSONObject
.
parseObject
(
item
.
get
(
"extension"
).
toString
(),
Map
.
class
);
String
pid
=
DataObject
.
getStringValue
(
item
.
get
(
this
.
getParentProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"pvalue"
),
"_root"
));
if
(
ObjectUtils
.
isEmpty
(
pid
))
pid
=
"_root"
;
List
<
CodeItem
>
list
=
null
;
if
(!
map
.
containsKey
(
pid
))
{
list
=
new
ArrayList
<>();
map
.
put
(
pid
,
list
);
}
else
list
=
map
.
get
(
pid
);
CodeItem
option
=
new
CodeItem
().
setValue
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getValueProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"id"
),
null
)))
.
setId
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getValueProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"id"
),
null
)))
.
setDisabled
(
DataObject
.
getBooleanValue
(
item
.
get
(
this
.
getDisabledProp
()),
false
)||
DataObject
.
getBooleanValue
(
item
.
get
(
this
.
getExpiredProp
()),
false
))
.
setFilter
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getFilterProp
()),
null
)).
setIconClass
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getIconClassProp
()),
null
))
.
setLabel
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getLabelProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"text"
),
""
)))
.
setParent
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getParentProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"pvalue"
),
""
))).
setExtension
(
extension
);
if
(
option
.
getValue
().
equals
(
subCode
))
subOption
=
option
;
if
(
ObjectUtils
.
isEmpty
(
filter
)||
option
.
getFilterSet
().
contains
(
filter
))
{
alllist
.
add
(
option
);
list
.
add
(
option
);
}
}
if
(
subOption
!=
null
)
{
List
<
CodeItem
>
codeItemTreeList
=
loop
(
map
,
(
ObjectUtils
.
isEmpty
(
subCode
))?
"_root"
:
subCode
);
codeItemTreeList
.
add
(
0
,
subOption
.
setParent
(
null
));
this
.
setOptions
(
codeItemTreeList
);
}
else
this
.
setOptions
(
alllist
);
return
this
;
}
public
List
<
Map
>
unfoldList
(
List
<
Map
>
nodes
,
String
parent
)
{
List
<
Map
>
unfoldList
=
new
ArrayList
<>();
for
(
Map
item:
nodes
)
{
if
((!
ObjectUtils
.
isEmpty
(
parent
))&&
ObjectUtils
.
isEmpty
(
DataObject
.
getStringValue
(
item
.
get
(
this
.
getParentProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"pvalue"
),
null
))))
item
.
put
(
this
.
getParentProp
(),
parent
);
String
value
=
DataObject
.
getStringValue
(
item
.
get
(
this
.
getValueProp
()),
DataObject
.
getStringValue
(
item
.
get
(
"id"
),
null
));
unfoldList
.
add
(
item
);
Object
child
=
item
.
get
(
this
.
getChildrenProp
());
if
(!
ObjectUtils
.
isEmpty
(
child
))
{
if
(
child
instanceof
List
&&
((
List
)
child
).
get
(
0
)
instanceof
Map
)
unfoldList
.
addAll
(
unfoldList
((
List
)
child
,
value
));
item
.
remove
(
this
.
getChildrenProp
());
}
}
return
unfoldList
;
}
public
List
<
CodeItem
>
loop
(
Map
<
String
,
List
<
CodeItem
>>
listCodeItem
,
Object
parentValue
)
{
List
<
CodeItem
>
trees
=
new
ArrayList
<
CodeItem
>();
if
(
listCodeItem
.
containsKey
(
parentValue
))
{
for
(
CodeItem
codeItem
:
listCodeItem
.
get
(
parentValue
))
{
trees
.
add
(
codeItem
);
List
<
CodeItem
>
childCodeItem
=
loop
(
listCodeItem
,
codeItem
.
getValue
());
if
(
childCodeItem
.
size
()
>
0
)
trees
.
addAll
(
childCodeItem
);
}
}
return
trees
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/dict/Option.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
dict
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors
(
chain
=
true
)
public
class
Option
{
private
String
id
;
private
Object
value
;
private
String
label
;
private
List
<
Option
>
children
;
private
String
iconClass
;
private
String
filter
;
private
Boolean
disabled
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
String
parent
;
private
Map
<
String
,
Object
>
extension
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Set
<
String
>
getFilterSet
()
{
Set
<
String
>
set
=
new
HashSet
<>();
if
(!
ObjectUtils
.
isEmpty
(
filter
))
for
(
String
str:
filter
.
split
(
";|,"
))
set
.
add
(
str
);
return
set
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/domain/FileItem.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
@Data
@JsonInclude
(
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@AllArgsConstructor
public
class
FileItem
{
private
String
id
;
private
String
name
;
private
String
fileid
;
private
String
filename
;
private
long
size
;
private
String
ext
;
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/domain/MsgBody.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
/**
* 消息对象
*/
@Data
public
class
MsgBody
{
/**
* 接收用户
*/
@JSONField
(
name
=
"to_users"
)
@JsonProperty
(
"to_users"
)
private
String
toUsers
;
/**
* 标题
*/
@JSONField
(
name
=
"subject"
)
@JsonProperty
(
"subject"
)
private
String
subject
;
/**
* 内容
*/
@JSONField
(
name
=
"content"
)
@JsonProperty
(
"content"
)
private
String
content
;
/**
* 类型
*/
@JSONField
(
name
=
"msg_type"
)
@JsonProperty
(
"msg_type"
)
private
Integer
msgType
;
/**
* 模板标识
*/
@JSONField
(
name
=
"template_id"
)
@JsonProperty
(
"template_id"
)
private
String
templateId
;
/**
* 模板参数
*/
@JSONField
(
name
=
"template_params"
)
@JsonProperty
(
"template_params"
)
private
String
templateParams
;
/**
* 消息链接
*/
@JSONField
(
name
=
"msg_link"
)
@JsonProperty
(
"msg_link"
)
private
String
msgLink
;
/**
* 消息链接(pc)
*/
@JSONField
(
name
=
"msg_link_pc"
)
@JsonProperty
(
"msg_link_pc"
)
private
String
msgLinkPc
;
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/domain/PayTrade.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
domain
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
/**
* 实体[支付交易]
*/
@Data
public
class
PayTrade
{
/**
* 订单标题
*/
@JSONField
(
name
=
"subject"
)
@JsonProperty
(
"subject"
)
private
String
subject
;
/**
* 订单金额
*/
@JSONField
(
name
=
"total_amount"
)
@JsonProperty
(
"total_amount"
)
private
String
totalAmount
;
/**
* 订单号
*/
@JSONField
(
name
=
"out_trade_no"
)
@JsonProperty
(
"out_trade_no"
)
private
String
outTradeNo
;
/**
* rt开放平台配置标识(OpenAccessId或AppId)
*/
@JSONField
(
name
=
"access_id"
)
@JsonProperty
(
"access_id"
)
private
String
accessId
;
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/enums/RedisChannelTopic.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
enums
;
import
org.springframework.data.redis.listener.ChannelTopic
;
/**
* redis频道
*/
public
enum
RedisChannelTopic
{
REDIS_CACHE_DELETE_TOPIC
(
"redis:cache:delete:topic1"
,
"删除redis缓存消息频道"
),
REDIS_CACHE_CLEAR_TOPIC
(
"redis:cache:clear:topic2"
,
"清空redis缓存消息频道"
),
REDIS_CACHE_DYNAMICMODEL_TOPIC
(
"redis:cache:dynamicmodel:topic3"
,
"动态模型频道"
);
String
channelTopic
;
String
label
;
RedisChannelTopic
(
String
channelTopic
,
String
label
)
{
this
.
channelTopic
=
channelTopic
;
this
.
label
=
label
;
}
public
ChannelTopic
getChannelTopic
()
{
return
new
ChannelTopic
(
channelTopic
);
}
public
static
RedisChannelTopic
getChannelTopicEnum
(
String
channelTopic
)
{
for
(
RedisChannelTopic
awardTypeEnum
:
RedisChannelTopic
.
values
())
{
if
(
awardTypeEnum
.
getChannelTopicStr
().
equals
(
channelTopic
))
{
return
awardTypeEnum
;
}
}
return
null
;
}
public
String
getChannelTopicStr
()
{
return
channelTopic
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/errors/BadRequestAlertException.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
errors
;
import
org.zalando.problem.AbstractThrowableProblem
;
import
org.zalando.problem.Status
;
import
java.net.URI
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
BadRequestAlertException
extends
AbstractThrowableProblem
{
private
final
String
entityName
;
private
final
String
errorKey
;
public
BadRequestAlertException
(
String
defaultMessage
,
String
entityName
,
String
errorKey
)
{
this
(
ErrorConstants
.
DEFAULT_TYPE
,
defaultMessage
,
entityName
,
errorKey
);
}
public
BadRequestAlertException
(
URI
type
,
String
defaultMessage
,
String
entityName
,
String
errorKey
)
{
super
(
type
,
defaultMessage
,
Status
.
BAD_REQUEST
,
null
,
null
,
null
,
getAlertParameters
(
entityName
,
errorKey
));
this
.
entityName
=
entityName
;
this
.
errorKey
=
errorKey
;
}
public
String
getEntityName
()
{
return
entityName
;
}
public
String
getErrorKey
()
{
return
errorKey
;
}
private
static
Map
<
String
,
Object
>
getAlertParameters
(
String
entityName
,
String
errorKey
)
{
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"message"
,
"error."
+
errorKey
);
parameters
.
put
(
"params"
,
entityName
);
return
parameters
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/errors/CustomParameterizedException.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
errors
;
import
org.zalando.problem.AbstractThrowableProblem
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
zalando
.
problem
.
Status
.
BAD_REQUEST
;
public
class
CustomParameterizedException
extends
AbstractThrowableProblem
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
String
PARAM
=
"param"
;
public
CustomParameterizedException
(
String
message
,
String
...
params
)
{
this
(
message
,
toParamMap
(
params
));
}
public
CustomParameterizedException
(
String
message
,
Map
<
String
,
Object
>
paramMap
)
{
super
(
ErrorConstants
.
PARAMETERIZED_TYPE
,
"处理发生异常"
,
BAD_REQUEST
,
null
,
null
,
null
,
toProblemParameters
(
message
,
paramMap
));
}
public
static
Map
<
String
,
Object
>
toParamMap
(
String
...
params
)
{
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
if
(
params
!=
null
&&
params
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
paramMap
.
put
(
PARAM
+
i
,
params
[
i
]);
}
}
return
paramMap
;
}
public
static
Map
<
String
,
Object
>
toProblemParameters
(
String
message
,
Map
<
String
,
Object
>
paramMap
)
{
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"message"
,
message
);
parameters
.
put
(
"params"
,
paramMap
);
return
parameters
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/errors/ErrorConstants.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
errors
;
import
java.net.URI
;
public
final
class
ErrorConstants
{
public
static
final
String
ERR_CONCURRENCY_FAILURE
=
"处理请求发生错误"
;
public
static
final
String
ERR_VALIDATION
=
"数据校验发生错误"
;
public
static
final
String
PROBLEM_BASE_URL
=
""
;
public
static
final
URI
DEFAULT_TYPE
=
URI
.
create
(
PROBLEM_BASE_URL
+
"/problem-with-message"
);
public
static
final
URI
CONSTRAINT_VIOLATION_TYPE
=
URI
.
create
(
PROBLEM_BASE_URL
+
"/constraint-violation"
);
public
static
final
URI
PARAMETERIZED_TYPE
=
URI
.
create
(
PROBLEM_BASE_URL
+
"/parameterized"
);
private
ErrorConstants
()
{
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/errors/ExceptionTranslator.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
errors
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.dao.*
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.multipart.MaxUploadSizeExceededException
;
import
org.zalando.problem.DefaultProblem
;
import
org.zalando.problem.Problem
;
import
org.zalando.problem.ProblemBuilder
;
import
org.zalando.problem.Status
;
import
org.zalando.problem.spring.web.advice.ProblemHandling
;
import
org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem
;
import
javax.annotation.Nonnull
;
import
javax.annotation.Nullable
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@ControllerAdvice
public
class
ExceptionTranslator
implements
ProblemHandling
{
@Override
public
ResponseEntity
<
Problem
>
process
(
@Nullable
ResponseEntity
<
Problem
>
entity
,
NativeWebRequest
request
)
{
if
(
entity
==
null
||
entity
.
getBody
()
==
null
)
{
return
entity
;
}
Problem
problem
=
entity
.
getBody
();
if
(!(
problem
instanceof
ConstraintViolationProblem
||
problem
instanceof
DefaultProblem
))
{
return
entity
;
}
ProblemBuilder
builder
=
Problem
.
builder
()
.
withType
(
Problem
.
DEFAULT_TYPE
.
equals
(
problem
.
getType
())
?
ErrorConstants
.
DEFAULT_TYPE
:
problem
.
getType
())
.
withStatus
(
problem
.
getStatus
())
.
withTitle
(
problem
.
getTitle
())
.
with
(
"path"
,
request
.
getNativeRequest
(
HttpServletRequest
.
class
).
getRequestURI
());
if
(
problem
instanceof
ConstraintViolationProblem
)
{
builder
.
with
(
"violations"
,
((
ConstraintViolationProblem
)
problem
).
getViolations
())
.
with
(
"message"
,
ErrorConstants
.
ERR_VALIDATION
);
return
new
ResponseEntity
<>(
builder
.
build
(),
entity
.
getHeaders
(),
entity
.
getStatusCode
());
}
else
{
builder
.
withCause
(((
DefaultProblem
)
problem
).
getCause
())
.
withDetail
(
problem
.
getDetail
())
.
withInstance
(
problem
.
getInstance
());
problem
.
getParameters
().
forEach
(
builder:
:
with
);
if
(!
problem
.
getParameters
().
containsKey
(
"message"
)
&&
problem
.
getStatus
()
!=
null
)
{
builder
.
with
(
"message"
,
"error.http."
+
problem
.
getStatus
().
getStatusCode
());
}
return
new
ResponseEntity
<>(
builder
.
build
(),
entity
.
getHeaders
(),
entity
.
getStatusCode
());
}
}
@Override
public
ResponseEntity
<
Problem
>
handleMethodArgumentNotValid
(
MethodArgumentNotValidException
ex
,
@Nonnull
NativeWebRequest
request
)
{
BindingResult
result
=
ex
.
getBindingResult
();
List
<
FieldErrorVM
>
fieldErrors
=
result
.
getFieldErrors
().
stream
()
.
map
(
f
->
new
FieldErrorVM
(
f
.
getObjectName
(),
f
.
getField
(),
f
.
getDefaultMessage
()))
.
collect
(
Collectors
.
toList
());
Problem
problem
=
Problem
.
builder
()
.
withType
(
ErrorConstants
.
CONSTRAINT_VIOLATION_TYPE
)
.
withTitle
(
ErrorConstants
.
ERR_VALIDATION
)
.
withStatus
(
defaultConstraintViolationStatus
())
.
with
(
"message"
,
ErrorConstants
.
ERR_VALIDATION
)
.
with
(
"fieldErrors"
,
fieldErrors
)
.
build
();
return
create
(
ex
,
problem
,
request
);
}
@ExceptionHandler
(
BadRequestAlertException
.
class
)
public
ResponseEntity
<
Problem
>
handleBadRequestAlertException
(
BadRequestAlertException
ex
,
NativeWebRequest
request
)
{
return
create
(
ex
,
request
,
createFailureAlert
(
ex
.
getEntityName
(),
ex
.
getErrorKey
(),
ex
.
getMessage
()));
}
@ExceptionHandler
(
ConcurrencyFailureException
.
class
)
public
ResponseEntity
<
Problem
>
handleConcurrencyFailure
(
ConcurrencyFailureException
ex
,
NativeWebRequest
request
)
{
Problem
problem
=
Problem
.
builder
()
.
withStatus
(
Status
.
CONFLICT
)
.
with
(
"message"
,
ErrorConstants
.
ERR_CONCURRENCY_FAILURE
)
.
build
();
return
create
(
ex
,
problem
,
request
);
}
@ExceptionHandler
(
DataAccessException
.
class
)
public
ResponseEntity
<
Problem
>
handlerDataAccessFailure
(
DataAccessException
ex
,
NativeWebRequest
request
){
Problem
problem
=
Problem
.
builder
()
.
withStatus
(
Status
.
INTERNAL_SERVER_ERROR
)
.
with
(
"message"
,
ex
.
getMessage
())
.
build
();
return
create
(
ex
,
problem
,
request
,
createFailureAlert
(
ex
.
getClass
().
getSimpleName
(),
ex
.
getClass
().
getSimpleName
(),
ex
.
getMessage
()));
}
public
static
HttpHeaders
createFailureAlert
(
String
entityName
,
String
errorKey
,
String
defaultMessage
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"X-ibz-error"
,
errorKey
);
headers
.
add
(
"X-ibz-params"
,
entityName
);
return
headers
;
}
/**
* 上传文件大小超出限制异常
*/
@Value
(
"${spring.servlet.multipart.max-file-size}"
)
private
String
maxFileSize
;
@ExceptionHandler
(
MaxUploadSizeExceededException
.
class
)
public
ResponseEntity
<
Problem
>
handlerMaxUploadFile
(
MaxUploadSizeExceededException
ex
,
NativeWebRequest
request
){
Problem
problem
=
Problem
.
builder
()
.
withStatus
(
Status
.
BAD_REQUEST
)
.
withDetail
(
"上传文件不能大于"
+
maxFileSize
)
.
with
(
"message"
,
"上传文件不能大于"
+
maxFileSize
)
.
with
(
"exmessage"
,
""
+
ex
.
getMessage
())
.
build
();
return
create
(
ex
,
problem
,
request
);
}
@ExceptionHandler
(
Exception
.
class
)
public
ResponseEntity
<
Problem
>
handlerTest
(
Exception
ex
,
NativeWebRequest
request
){
Problem
problem
=
Problem
.
builder
()
.
withStatus
(
Status
.
INTERNAL_SERVER_ERROR
)
.
withDetail
(
"内部服务器异常"
)
.
with
(
"message"
,
"内部服务器异常"
)
.
with
(
"exmessage"
,
""
+
ex
.
getMessage
())
.
build
();
return
create
(
ex
,
problem
,
request
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/errors/FieldErrorVM.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
errors
;
import
java.io.Serializable
;
public
class
FieldErrorVM
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
String
objectName
;
private
final
String
field
;
private
final
String
message
;
public
FieldErrorVM
(
String
dto
,
String
field
,
String
message
)
{
this
.
objectName
=
dto
;
this
.
field
=
field
;
this
.
message
=
message
;
}
public
String
getObjectName
()
{
return
objectName
;
}
public
String
getField
()
{
return
field
;
}
public
String
getMessage
()
{
return
message
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/errors/InternalServerErrorException.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
errors
;
import
org.zalando.problem.AbstractThrowableProblem
;
import
org.zalando.problem.Status
;
public
class
InternalServerErrorException
extends
AbstractThrowableProblem
{
public
InternalServerErrorException
(
String
message
)
{
super
(
ErrorConstants
.
DEFAULT_TYPE
,
message
,
Status
.
INTERNAL_SERVER_ERROR
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/CachedBeanCopier.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
org.springframework.beans.BeanUtils
;
public
class
CachedBeanCopier
{
public
static
void
copy
(
Object
srcObj
,
Object
destObj
)
{
copy
(
srcObj
,
destObj
,
false
);
}
public
static
void
copy
(
Object
srcObj
,
Object
destObj
,
boolean
useConverter
)
{
if
(
srcObj
==
null
||
destObj
==
null
)
{
return
;
}
BeanUtils
.
copyProperties
(
srcObj
,
destObj
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/DataObject.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.sql.Timestamp
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
public
class
DataObject
{
final
static
public
DateFormat
datetimeFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
final
static
public
DateFormat
datetimeFormat2
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
final
static
public
DateFormat
dayFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
final
static
public
String
getStringValue
(
Object
objValue
,
String
strDefault
)
{
if
(
objValue
==
null
)
{
return
strDefault
;
}
if
(
objValue
instanceof
String
)
{
return
(
String
)
objValue
;
}
if
(
objValue
instanceof
Timestamp
||
objValue
instanceof
java
.
sql
.
Date
||
objValue
instanceof
Date
)
{
String
rt
=
datetimeFormat
.
format
(
objValue
);
if
(
rt
.
endsWith
(
" 00:00:00"
))
{
rt
=
dayFormat
.
format
(
objValue
);
}
else
if
(
rt
.
endsWith
(
":00"
))
{
rt
=
datetimeFormat2
.
format
(
objValue
);
}
return
rt
;
}
return
objValue
.
toString
();
}
public
static
<
T
>
Object
objectValueOf
(
Class
<
T
>
type
,
Object
fieldValue
)
{
if
(
fieldValue
==
null
)
{
return
null
;
}
Object
resultValue
=
fieldValue
;
String
targetType
=
type
.
getSimpleName
();
if
(
targetType
.
equalsIgnoreCase
(
fieldValue
.
getClass
().
getSimpleName
())){
return
resultValue
;
}
if
(
targetType
.
equals
(
"Boolean"
)){
resultValue
=
getBooleanValue
(
fieldValue
,
false
);
}
else
if
(
targetType
.
equals
(
"Character"
)){
resultValue
=
getCharacterValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Byte"
)){
resultValue
=
getBinaryValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Short"
)){
resultValue
=
Short
.
valueOf
(
fieldValue
.
toString
());
}
else
if
(
targetType
.
equals
(
"Integer"
)){
resultValue
=
getIntegerValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Long"
)){
resultValue
=
getLongValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Float"
)){
resultValue
=
getFloatValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Double"
)){
resultValue
=
getDoubleValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"BigDecimal"
)){
resultValue
=
getBigDecimalValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"BigInteger"
)){
resultValue
=
getBigIntegerValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Timestamp"
)){
resultValue
=
getTimestampValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"String"
))
{
resultValue
=
getStringValue
(
fieldValue
,
null
);
}
if
(
resultValue
==
null
)
{
return
null
;
}
return
resultValue
;
}
public
static
<
T
>
T
valueOf
(
Class
<
T
>
type
,
Object
fieldValue
)
{
return
(
T
)
objectValueOf
(
type
,
fieldValue
);
}
final
static
public
JSONObject
getJSONObjectValue
(
Object
objValue
,
JSONObject
jDefault
)
{
if
(
objValue
==
null
)
{
return
jDefault
;
}
if
(
objValue
instanceof
JSONObject
)
{
return
(
JSONObject
)
objValue
;
}
String
strValue
=
objValue
.
toString
();
try
{
return
JSONObject
.
parseObject
(
strValue
);
}
catch
(
Exception
ex
)
{
return
jDefault
;
}
}
final
static
public
JSONArray
getJSONArrayValue
(
Object
objValue
,
JSONArray
jDefault
)
{
if
(
objValue
==
null
)
{
return
jDefault
;
}
if
(
objValue
instanceof
JSONArray
)
{
return
(
JSONArray
)
objValue
;
}
String
strValue
=
objValue
.
toString
();
try
{
return
JSONArray
.
parseArray
(
strValue
);
}
catch
(
Exception
ex
)
{
return
jDefault
;
}
}
final
static
public
List
<
String
>
getListValue
(
Object
objValue
)
{
if
(
objValue
==
null
)
{
return
new
ArrayList
<
String
>();
}
JSONArray
arr
=(
getJSONArrayValue
(
objValue
,
null
));
if
(
arr
!=
null
)
{
List
<
String
>
chk1
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
arr
.
size
();
i
++)
{
if
(
arr
.
get
(
i
)
instanceof
String
)
{
chk1
.
add
(
arr
.
getString
(
i
));
}
}
return
chk1
;
}
else
{
return
new
ArrayList
<
String
>();
}
}
final
static
public
Boolean
getBooleanValue
(
Object
objValue
,
Boolean
bDefault
)
{
if
(
objValue
==
null
)
{
return
bDefault
;
}
if
(
objValue
instanceof
Boolean
)
{
return
(
Boolean
)
objValue
;
}
return
objValue
.
toString
().
equalsIgnoreCase
(
"true"
)||
objValue
.
toString
().
equals
(
"1"
)||
objValue
.
toString
().
equals
(
"y"
);
}
final
static
public
char
[]
getCharacterValue
(
Object
objValue
,
char
[]
cDefault
)
{
if
(
objValue
==
null
)
{
return
cDefault
;
}
return
objValue
.
toString
().
toCharArray
();
}
final
static
public
Double
getDoubleValue
(
Object
objValue
,
Double
dDefault
)
{
if
(
objValue
==
null
)
{
return
dDefault
;
}
if
(
objValue
instanceof
Double
)
{
return
(
Double
)
objValue
;
}
String
strValue
=
objValue
.
toString
();
if
(
ObjectUtils
.
isEmpty
(
strValue
))
{
return
null
;
}
strValue
=
strValue
.
replace
(
","
,
""
);
return
Double
.
parseDouble
(
strValue
);
}
final
static
public
int
getIntegerValue
(
Object
objValue
,
Integer
nDefault
)
{
if
(
objValue
==
null
)
{
return
nDefault
;
}
if
(
objValue
instanceof
Integer
)
{
return
(
Integer
)
objValue
;
}
if
(
objValue
instanceof
Double
)
{
return
((
Double
)
objValue
).
intValue
();
}
if
(
objValue
instanceof
BigDecimal
)
{
return
((
BigDecimal
)
objValue
).
intValue
();
}
String
strValue
=
objValue
.
toString
();
if
(
ObjectUtils
.
isEmpty
(
strValue
))
{
return
nDefault
;
}
strValue
=
strValue
.
replace
(
","
,
""
);
return
Integer
.
parseInt
(
strValue
);
}
final
static
public
Float
getFloatValue
(
Object
objValue
,
Float
fDefault
)
{
if
(
objValue
==
null
)
{
return
fDefault
;
}
try
{
if
(
objValue
instanceof
Float
)
{
return
(
Float
)
objValue
;
}
String
strValue
=
objValue
.
toString
();
if
(
ObjectUtils
.
isEmpty
(
strValue
))
{
return
fDefault
;
}
strValue
=
strValue
.
replace
(
","
,
""
);
return
Float
.
parseFloat
(
strValue
);
}
catch
(
Exception
ex
)
{
return
fDefault
;
}
}
final
static
public
BigDecimal
getBigDecimalValue
(
Object
objValue
,
BigDecimal
fDefault
)
{
if
(
objValue
==
null
)
{
return
fDefault
;
}
try
{
if
(
objValue
instanceof
BigDecimal
){
return
(
BigDecimal
)(
objValue
);
}
if
(
objValue
instanceof
Double
){
return
BigDecimal
.
valueOf
((
Double
)
objValue
);
}
if
(
objValue
instanceof
Long
){
return
BigDecimal
.
valueOf
((
Long
)
objValue
);
}
String
strValue
=
objValue
.
toString
();
if
(
ObjectUtils
.
isEmpty
(
strValue
))
{
return
fDefault
;
}
strValue
=
strValue
.
replace
(
","
,
""
);
return
BigDecimal
.
valueOf
(
Double
.
parseDouble
(
strValue
));
}
catch
(
Exception
ex
)
{
return
fDefault
;
}
}
final
static
public
BigInteger
getBigIntegerValue
(
Object
objValue
,
BigInteger
fDefault
)
{
if
(
objValue
==
null
)
{
return
fDefault
;
}
try
{
if
(
objValue
instanceof
BigInteger
){
return
(
BigInteger
)(
objValue
);
}
else
{
Long
l
=
getLongValue
(
objValue
,
null
);
if
(
l
!=
null
)
{
return
BigInteger
.
valueOf
(
l
);
}
}
}
catch
(
Exception
ex
)
{
}
return
fDefault
;
}
final
static
public
Long
getLongValue
(
Object
objValue
,
Long
nDefault
)
{
if
(
objValue
==
null
)
{
return
nDefault
;
}
try
{
if
(
objValue
instanceof
Long
)
return
(
Long
)
objValue
;
if
(
objValue
instanceof
Integer
)
{
return
((
Integer
)
objValue
).
longValue
();
}
if
(
objValue
instanceof
Double
)
{
return
((
Double
)
objValue
).
longValue
();
}
if
(
objValue
instanceof
BigDecimal
)
{
return
((
BigDecimal
)
objValue
).
longValue
();
}
String
strValue
=
objValue
.
toString
();
if
(
ObjectUtils
.
isEmpty
(
strValue
))
{
return
nDefault
;
}
strValue
=
strValue
.
replace
(
","
,
""
);
return
Long
.
parseLong
(
strValue
);
}
catch
(
Exception
ex
)
{
return
nDefault
;
}
}
final
static
public
byte
[]
getBinaryValue
(
Object
objValue
,
byte
[]
def
)
{
if
(
objValue
==
null
)
{
return
def
;
}
if
(
objValue
instanceof
byte
[]){
return
(
byte
[])
objValue
;
}
if
(
objValue
instanceof
String
){
return
Base64
.
getDecoder
().
decode
((
String
)
objValue
);
}
return
def
;
}
/**
* 转换对象值到时间值
*
* @param objValue
* @return
* @
*/
final
static
public
Timestamp
getTimestampValue
(
Object
objValue
,
Timestamp
tDefault
)
{
if
(
objValue
==
null
)
{
return
tDefault
;
}
if
(
objValue
instanceof
Timestamp
)
{
Timestamp
ti
=
(
Timestamp
)
objValue
;
return
ti
;
}
if
(
objValue
instanceof
java
.
sql
.
Date
)
{
java
.
sql
.
Date
date
=
(
java
.
sql
.
Date
)
objValue
;
return
new
Timestamp
(
date
.
getTime
());
}
if
(
objValue
instanceof
Date
)
{
Date
date
=
(
Date
)
objValue
;
return
new
Timestamp
(
date
.
getTime
());
}
if
(
objValue
instanceof
String
)
{
String
strValue
=
(
String
)
objValue
;
strValue
=
strValue
.
trim
();
if
(
ObjectUtils
.
isEmpty
(
strValue
))
{
return
null
;
}
try
{
Date
date
=
parse
((
String
)
objValue
);
return
new
Timestamp
(
date
.
getTime
());
}
catch
(
Exception
ex
)
{
return
tDefault
;
}
}
if
(
objValue
instanceof
Long
)
{
Long
lValue
=
(
Long
)
objValue
;
return
new
Timestamp
(
lValue
);
}
if
(
objValue
instanceof
Integer
)
{
int
lValue
=
(
int
)
objValue
;
return
new
Timestamp
(
lValue
);
}
return
tDefault
;
}
public
static
Object
testDateTime
(
String
strInput
)
throws
Exception
{
return
testDateTime
(
strInput
,
null
);
}
/**
* 转换文本值到日期时间
*
* @param strInput
* @param timeZone
* @return
* @
*/
public
static
Object
testDateTime
(
String
strInput
,
TimeZone
timeZone
)
throws
Exception
{
if
(
ObjectUtils
.
isEmpty
(
strInput
))
{
return
null
;
}
Date
dtDate
=
parse
(
strInput
,
timeZone
);
Timestamp
retDate
=
new
Timestamp
(
dtDate
.
getTime
());
return
retDate
;
}
/**
* 转换字符串到时间对象
*
* @param strTimeString
* @return
* @throws ParseException
* @
*/
public
static
Date
parse
(
String
strTimeString
)
throws
ParseException
,
Exception
{
return
parse
(
strTimeString
,
null
);
}
/**
* 分析时间串
*
* @param strTimeString MM/dd/yy yy-MM-dd HH:mm:ss 格式
* @param timeZone
* @return
* @throws ParseException
* @
*/
public
static
Date
parse
(
String
strTimeString
,
TimeZone
timeZone
)
throws
ParseException
,
Exception
{
strTimeString
=
strTimeString
.
trim
();
if
(
ObjectUtils
.
isEmpty
(
strTimeString
)){
throw
new
Exception
(
"unknown date(time) string"
);
}
if
(
strTimeString
.
indexOf
(
"Z"
)!=-
1
){
//有时区
String
[]
parts
=
strTimeString
.
split
(
"[Z]"
);
if
(
parts
.
length
>=
1
){
strTimeString
=
parts
[
0
];
}
if
(
parts
.
length
>=
2
){
if
(
timeZone
==
null
){
if
(!
ObjectUtils
.
isEmpty
(
parts
[
1
])){
timeZone
=
TimeZone
.
getTimeZone
(
parts
[
1
]);
}
}
}
}
// 判断是长数据还是短数据
String
strPart
[]
=
null
;
if
(
strTimeString
.
indexOf
(
"T"
)!=-
1
){
strPart
=
strTimeString
.
split
(
"[T]"
);
}
else
{
strPart
=
strTimeString
.
split
(
" "
);
}
if
(
strPart
.
length
==
2
)
{
// 两个部分
String
strDate
=
""
;
String
strTime
=
""
;
if
(
strPart
[
0
].
indexOf
(
":"
)
!=
-
1
)
{
strTime
=
strPart
[
0
];
strDate
=
strPart
[
1
];
}
else
{
strTime
=
strPart
[
1
];
strDate
=
strPart
[
0
];
}
strDate
=
strDate
.
trim
();
strTime
=
strTime
.
trim
();
strDate
=
getFormatDateString
(
strDate
);
strTime
=
getFormatTimeString
(
strTime
);
DateFormat
dtFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
if
(
timeZone
!=
null
)
{
dtFormat
.
setTimeZone
(
timeZone
);
}
return
dtFormat
.
parse
(
strDate
+
" "
+
strTime
);
}
else
{
// 一个部分
if
(
strTimeString
.
indexOf
(
":"
)
!=
-
1
)
{
// 时间
strTimeString
=
getFormatTimeString
(
strTimeString
);
DateFormat
dtFormat
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
if
(
timeZone
!=
null
)
{
dtFormat
.
setTimeZone
(
timeZone
);
}
return
dtFormat
.
parse
(
strTimeString
);
}
else
{
// 作为日期处理
strTimeString
=
getFormatDateString
(
strTimeString
);
DateFormat
dtFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
if
(
timeZone
!=
null
)
{
dtFormat
.
setTimeZone
(
timeZone
);
}
return
dtFormat
.
parse
(
strTimeString
);
}
}
}
/**
* 获取时间格式化串
*
* @param strOrigin
* @return
*/
private
static
String
getFormatTimeString
(
String
strOrigin
)
{
int
nDotPos
=
strOrigin
.
indexOf
(
"."
);
if
(
nDotPos
!=
-
1
)
{
strOrigin
=
strOrigin
.
substring
(
0
,
nDotPos
);
}
Object
Time
[]
=
new
Object
[
3
];
Time
[
0
]
=
0
;
Time
[
1
]
=
0
;
Time
[
2
]
=
0
;
String
timepart
[]
=
strOrigin
.
split
(
":"
);
int
nTimePartLength
=
timepart
.
length
;
if
(
nTimePartLength
>
3
)
{
nTimePartLength
=
3
;
}
for
(
int
i
=
0
;
i
<
nTimePartLength
;
i
++)
{
Time
[
i
]
=
Integer
.
parseInt
(
timepart
[
i
]);
}
return
String
.
format
(
"%1$02d:%2$02d:%3$02d"
,
Time
);
}
/**
* 获取时日期格式化串
*
* @param strOrigin
* @return
* @
*/
private
static
String
getFormatDateString
(
String
strOrigin
)
throws
Exception
{
return
getFormatDateString
(
strOrigin
,
true
);
}
/**
* 获取时日期格式化串
*
* @param strOrigin
* @param bAdv
* @return
* @
*/
private
static
String
getFormatDateString
(
String
strOrigin
,
boolean
bAdv
)
throws
Exception
{
Object
Date
[]
=
new
Object
[
3
];
Date
[
0
]
=
1970
;
Date
[
1
]
=
1
;
Date
[
2
]
=
1
;
if
(
strOrigin
.
indexOf
(
"-"
)
!=
-
1
)
{
String
datePart
[]
=
strOrigin
.
split
(
"-"
);
if
(
datePart
.
length
>=
1
)
{
Date
[
0
]
=
Integer
.
parseInt
(
datePart
[
0
]);
}
if
(
datePart
.
length
>=
2
)
{
Date
[
1
]
=
Integer
.
parseInt
(
datePart
[
1
]);
}
if
(
datePart
.
length
>=
3
)
{
Date
[
2
]
=
Integer
.
parseInt
(
datePart
[
2
]);
}
}
else
if
(
strOrigin
.
indexOf
(
"/"
)
!=
-
1
)
{
String
datePart
[]
=
strOrigin
.
split
(
"/"
);
if
(
datePart
.
length
>=
1
)
{
Date
[
1
]
=
Integer
.
parseInt
(
datePart
[
0
]);
}
if
(
datePart
.
length
>=
2
)
{
Date
[
2
]
=
Integer
.
parseInt
(
datePart
[
1
]);
}
if
(
datePart
.
length
>=
3
)
{
Date
[
0
]
=
Integer
.
parseInt
(
datePart
[
2
]);
}
}
else
{
if
(
bAdv
)
{
strOrigin
=
strOrigin
.
replace
(
"."
,
"-"
);
strOrigin
=
strOrigin
.
replace
(
"日"
,
""
);
strOrigin
=
strOrigin
.
replace
(
"天"
,
""
);
strOrigin
=
strOrigin
.
replace
(
"年"
,
"-"
);
strOrigin
=
strOrigin
.
replace
(
"月"
,
"-"
);
return
getFormatDateString
(
strOrigin
,
false
);
}
else
throw
new
Exception
(
"无法识别的时间字符串,"
+
strOrigin
);
}
return
String
.
format
(
"%1$04d-%2$02d-%3$02d"
,
Date
);
}
public
static
Timestamp
getBeginDate
()
{
Calendar
cl
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
cl
.
set
(
1900
,
1
,
1
);
return
new
Timestamp
(
cl
.
getTime
().
getTime
());
}
public
static
Timestamp
getEndDate
()
{
Calendar
cl
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
cl
.
set
(
2100
,
12
,
31
,
23
,
59
,
59
);
return
new
Timestamp
(
cl
.
getTime
().
getTime
());
}
public
static
Timestamp
getNow
()
{
Calendar
cl
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
return
new
Timestamp
(
cl
.
getTime
().
getTime
());
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/Globs.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
java.util.regex.PatternSyntaxException
;
/**
* Copy from class sun.nio.fs.Globs
*/
public
class
Globs
{
private
Globs
()
{
}
private
static
final
String
regexMetaChars
=
".^$+{[]|()"
;
private
static
final
String
globMetaChars
=
"\\*?[{"
;
private
static
boolean
isRegexMeta
(
char
c
)
{
return
regexMetaChars
.
indexOf
(
c
)
!=
-
1
;
}
private
static
boolean
isGlobMeta
(
char
c
)
{
return
globMetaChars
.
indexOf
(
c
)
!=
-
1
;
}
private
static
char
EOL
=
0
;
//TBD
private
static
char
next
(
String
glob
,
int
i
)
{
if
(
i
<
glob
.
length
())
{
return
glob
.
charAt
(
i
);
}
return
EOL
;
}
/**
* Creates a regex pattern from the given glob expression.
*
* @throws PatternSyntaxException
*/
private
static
String
toRegexPattern
(
String
globPattern
,
boolean
isDos
)
{
boolean
inGroup
=
false
;
StringBuilder
regex
=
new
StringBuilder
(
"^"
);
int
i
=
0
;
while
(
i
<
globPattern
.
length
())
{
char
c
=
globPattern
.
charAt
(
i
++);
switch
(
c
)
{
case
'\\'
:
// escape special characters
if
(
i
==
globPattern
.
length
())
{
throw
new
PatternSyntaxException
(
"No character to escape"
,
globPattern
,
i
-
1
);
}
char
next
=
globPattern
.
charAt
(
i
++);
if
(
isGlobMeta
(
next
)
||
isRegexMeta
(
next
))
{
regex
.
append
(
'\\'
);
}
regex
.
append
(
next
);
break
;
case
'/'
:
if
(
isDos
)
{
regex
.
append
(
"\\\\"
);
}
else
{
regex
.
append
(
c
);
}
break
;
case
'['
:
// don't match name separator in class
if
(
isDos
)
{
regex
.
append
(
"[[^\\\\]&&["
);
}
else
{
regex
.
append
(
"[[^/]&&["
);
}
if
(
next
(
globPattern
,
i
)
==
'^'
)
{
// escape the regex negation char if it appears
regex
.
append
(
"\\^"
);
i
++;
}
else
{
// negation
if
(
next
(
globPattern
,
i
)
==
'!'
)
{
regex
.
append
(
'^'
);
i
++;
}
// hyphen allowed at start
if
(
next
(
globPattern
,
i
)
==
'-'
)
{
regex
.
append
(
'-'
);
i
++;
}
}
boolean
hasRangeStart
=
false
;
char
last
=
0
;
while
(
i
<
globPattern
.
length
())
{
c
=
globPattern
.
charAt
(
i
++);
if
(
c
==
']'
)
{
break
;
}
if
(
c
==
'/'
||
(
isDos
&&
c
==
'\\'
))
{
throw
new
PatternSyntaxException
(
"Explicit 'name separator' in class"
,
globPattern
,
i
-
1
);
}
// TBD: how to specify ']' in a class?
if
(
c
==
'\\'
||
c
==
'['
||
c
==
'&'
&&
next
(
globPattern
,
i
)
==
'&'
)
{
// escape '\', '[' or "&&" for regex class
regex
.
append
(
'\\'
);
}
regex
.
append
(
c
);
if
(
c
==
'-'
)
{
if
(!
hasRangeStart
)
{
throw
new
PatternSyntaxException
(
"Invalid range"
,
globPattern
,
i
-
1
);
}
if
((
c
=
next
(
globPattern
,
i
++))
==
EOL
||
c
==
']'
)
{
break
;
}
if
(
c
<
last
)
{
throw
new
PatternSyntaxException
(
"Invalid range"
,
globPattern
,
i
-
3
);
}
regex
.
append
(
c
);
hasRangeStart
=
false
;
}
else
{
hasRangeStart
=
true
;
last
=
c
;
}
}
if
(
c
!=
']'
)
{
throw
new
PatternSyntaxException
(
"Missing ']"
,
globPattern
,
i
-
1
);
}
regex
.
append
(
"]]"
);
break
;
case
'{'
:
if
(
inGroup
)
{
throw
new
PatternSyntaxException
(
"Cannot nest groups"
,
globPattern
,
i
-
1
);
}
regex
.
append
(
"(?:(?:"
);
inGroup
=
true
;
break
;
case
'}'
:
if
(
inGroup
)
{
regex
.
append
(
"))"
);
inGroup
=
false
;
}
else
{
regex
.
append
(
'}'
);
}
break
;
case
','
:
if
(
inGroup
)
{
regex
.
append
(
")|(?:"
);
}
else
{
regex
.
append
(
','
);
}
break
;
case
'*'
:
if
(
next
(
globPattern
,
i
)
==
'*'
)
{
// crosses directory boundaries
regex
.
append
(
".*"
);
i
++;
}
else
{
// within directory boundary
if
(
isDos
)
{
regex
.
append
(
"[^\\\\]*"
);
}
else
{
regex
.
append
(
"[^/]*"
);
}
}
break
;
case
'?'
:
if
(
isDos
)
{
regex
.
append
(
"[^\\\\]"
);
}
else
{
regex
.
append
(
"[^/]"
);
}
break
;
default
:
if
(
isRegexMeta
(
c
))
{
regex
.
append
(
'\\'
);
}
regex
.
append
(
c
);
}
}
if
(
inGroup
)
{
throw
new
PatternSyntaxException
(
"Missing '}"
,
globPattern
,
i
-
1
);
}
return
regex
.
append
(
'$'
).
toString
();
}
public
static
String
toUnixRegexPattern
(
String
globPattern
)
{
return
toRegexPattern
(
globPattern
,
false
);
}
public
static
String
toWindowsRegexPattern
(
String
globPattern
)
{
return
toRegexPattern
(
globPattern
,
true
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/UniqueNameGenerator.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
helper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.annotation.AnnotationBeanNameGenerator
;
@Slf4j
public
class
UniqueNameGenerator
extends
AnnotationBeanNameGenerator
{
@Override
public
String
generateBeanName
(
BeanDefinition
definition
,
BeanDefinitionRegistry
registry
)
{
//全限定类名
String
beanName
=
definition
.
getBeanClassName
();
return
beanName
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/rest/AppController.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
rest
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.*
;
@RestController
@RequestMapping
(
value
=
""
)
public
class
AppController
{
@Value
(
"${ibiz.enablePermissionValid:false}"
)
boolean
enablePermissionValid
;
//是否开启权限校验
@Value
(
"${ibiz.systemid}"
)
private
String
systemId
;
@Autowired
private
AuthenticationUserService
userDetailsService
;
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/appdata"
)
public
ResponseEntity
<
JSONObject
>
getAppData
()
{
JSONObject
appData
=
new
JSONObject
()
;
Set
<
String
>
appMenu
=
new
HashSet
();
Set
<
String
>
uniRes
=
new
HashSet
();
AuthenticationUser
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
if
(
enablePermissionValid
&&(!
ObjectUtils
.
isEmpty
(
systemId
))){
Collection
<
GrantedAuthority
>
authorities
=
curUser
.
getAuthorities
();
Iterator
it
=
authorities
.
iterator
();
while
(
it
.
hasNext
())
{
GrantedAuthority
authority
=
(
GrantedAuthority
)
it
.
next
();
String
strAuthority
=
authority
.
getAuthority
();
if
(
strAuthority
.
startsWith
(
"UNIRES_"
+
systemId
))
{
uniRes
.
add
(
strAuthority
.
substring
(
systemId
.
length
()+
8
));
}
else
if
(
strAuthority
.
startsWith
(
"APPMENU_"
+
systemId
)){
appMenu
.
add
(
strAuthority
.
substring
(
systemId
.
length
()+
9
));
}
}
}
Map
<
String
,
Object
>
context
=
new
HashMap
<>();
context
.
putAll
(
curUser
.
getSessionParams
());
context
.
put
(
"srfusername"
,
curUser
.
getPersonname
());
appData
.
put
(
"context"
,
context
);
appData
.
put
(
"unires"
,
uniRes
);
appData
.
put
(
"appmenu"
,
appMenu
);
appData
.
put
(
"enablepermissionvalid"
,
enablePermissionValid
);
if
(
curUser
.
getSuperuser
()==
1
){
appData
.
put
(
"enablepermissionvalid"
,
false
);
}
else
{
appData
.
put
(
"enablepermissionvalid"
,
enablePermissionValid
);
}
fillAppData
(
appData
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
appData
);
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"${ibiz.auth.logoutpath:v7/logout}"
)
public
void
logout
()
{
if
(
AuthenticationUser
.
getAuthenticationUser
()!=
null
){
userDetailsService
.
resetByUsername
(
AuthenticationUser
.
getAuthenticationUser
().
getUsername
());
}
}
/**
* 应用参数扩展
* @param appData
*/
protected
void
fillAppData
(
JSONObject
appData
){
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/rest/AuthenticationController.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
rest
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RequestMapping
(
"/"
)
@ConditionalOnProperty
(
name
=
"ibiz.enablePermissionValid"
,
havingValue
=
"false"
)
public
class
AuthenticationController
{
@Value
(
"${ibiz.jwt.header:Authorization}"
)
private
String
tokenHeader
;
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
@Autowired
private
AuthenticationUserService
userDetailsService
;
@PostMapping
(
value
=
"${ibiz.auth.path:v7/login}"
)
public
ResponseEntity
<
AuthenticationInfo
>
login
(
@Validated
@RequestBody
AuthorizationLogin
authorizationLogin
){
userDetailsService
.
resetByUsername
(
authorizationLogin
.
getUsername
());
final
AuthenticationUser
authuserdetail
=
userDetailsService
.
loadUserByLogin
(
authorizationLogin
.
getUsername
(),
authorizationLogin
.
getPassword
());
// 生成令牌
final
String
token
=
jwtTokenUtil
.
generateToken
(
authuserdetail
);
// 返回 token
return
ResponseEntity
.
ok
().
body
(
new
AuthenticationInfo
(
token
,
authuserdetail
));
}
@GetMapping
(
value
=
"${ibiz.auth.account:ibizutil/account}"
)
public
ResponseEntity
<
AuthenticationUser
>
getUserInfo
(){
UserDetails
userDetails
=
(
UserDetails
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
AuthenticationUser
authuserdetail
=
new
AuthenticationUser
();
if
(
userDetails
==
null
){
throw
new
RuntimeException
(
"未能获取用户信息"
);
}
else
if
(
userDetails
instanceof
AuthenticationUser
)
{
authuserdetail
=
(
AuthenticationUser
)
userDetails
;
}
else
{
authuserdetail
=
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
}
return
ResponseEntity
.
ok
().
body
(
authuserdetail
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/rest/FileController.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
rest
;
import
cn.ibizlab.util.domain.FileItem
;
import
cn.ibizlab.util.service.FileService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
@Slf4j
@RestController
@RequestMapping
(
"/"
)
public
class
FileController
{
@Autowired
private
FileService
fileService
;
@PostMapping
(
value
=
"${ibiz.file.uploadpath:ibizutil/upload}"
)
public
ResponseEntity
<
FileItem
>
upload
(
@RequestParam
(
"file"
)
MultipartFile
multipartFile
){
return
ResponseEntity
.
ok
().
body
(
fileService
.
saveFile
(
multipartFile
));
}
private
final
String
defaultdownloadpath
=
"ibizutil/download/{id}"
;
@GetMapping
(
value
=
"${ibiz.file.downloadpath:"
+
defaultdownloadpath
+
"}"
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
void
download
(
@PathVariable
String
id
,
HttpServletResponse
response
){
File
file
=
fileService
.
getFile
(
id
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
getFileName
(
file
.
getName
()));
this
.
sendRespose
(
response
,
file
);
}
protected
void
sendRespose
(
HttpServletResponse
response
,
File
file
){
BufferedInputStream
bis
=
null
;
BufferedOutputStream
bos
=
null
;
try
{
bis
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
bos
=
new
BufferedOutputStream
(
response
.
getOutputStream
());
byte
[]
buff
=
new
byte
[
2048
];
int
bytesRead
;
while
(-
1
!=
(
bytesRead
=
bis
.
read
(
buff
,
0
,
buff
.
length
)))
{
bos
.
write
(
buff
,
0
,
bytesRead
);
}
}
catch
(
Exception
e
)
{
//throw e;
}
finally
{
if
(
bis
!=
null
)
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
}
}
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e
)
{
}
}
}
}
protected
String
getFileName
(
String
fileName
){
try
{
return
new
String
(
fileName
.
getBytes
(
"utf-8"
),
"iso8859-1"
);
//防止中文乱码
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
fileName
;
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthTokenUtil.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
java.util.Date
;
public
interface
AuthTokenUtil
{
String
generateToken
(
UserDetails
userDetails
);
Boolean
validateToken
(
String
token
,
UserDetails
userDetails
);
String
getUsernameFromToken
(
String
token
);
Date
getExpirationDateFromToken
(
String
token
)
;
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthenticationEntryPoint.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.Serializable
;
@Component
public
class
AuthenticationEntryPoint
implements
org
.
springframework
.
security
.
web
.
AuthenticationEntryPoint
,
Serializable
{
private
static
final
long
serialVersionUID
=
-
8970718410437077606L
;
@Override
public
void
commence
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
authException
)
throws
IOException
{
/**
* 当用户尝试访问安全的REST资源而不提供任何凭据时,将调用此方法发送401 响应
*/
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"账号身份已过期,请重新登录。"
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthenticationInfo.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.io.Serializable
;
@Getter
@AllArgsConstructor
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AuthenticationInfo
implements
Serializable
{
private
String
token
;
private
AuthenticationUser
user
;
public
AuthenticationInfo
()
{
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthenticationUser.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.util.ObjectUtils
;
import
java.sql.Timestamp
;
import
java.util.*
;
@Data
@AllArgsConstructor
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AuthenticationUser
implements
UserDetails
{
public
AuthenticationUser
(){}
/**
* 用戶标识
*/
private
String
userid
;
/**
* 用户全局名
*/
private
String
username
;
/**
* 用户姓名
*/
private
String
personname
;
/**
* 登录名
*/
private
String
loginname
;
/**
* 用户工号
*/
private
String
usercode
;
/**
* 登录密码
*/
private
String
password
;
/**
* 区属
*/
private
String
domain
;
/**
* 租户
*/
private
String
srfdcid
;
/**
* 系统标识
*/
private
String
srfsystemid
;
/**
/**
* 动态实例标识
*/
private
String
srfdynainstid
;
/**
* 部门标识
*/
private
String
mdeptid
;
/**
* 部门编码
*/
private
String
mdeptcode
;
/**
* 部门名称
*/
private
String
mdeptname
;
/**
* 业务编码
*/
private
String
bcode
;
/**
* 岗位标识
*/
private
String
postid
;
/**
* 岗位代码
*/
private
String
postcode
;
/**
* 岗位名称
*/
private
String
postname
;
/**
* 单位标识
*/
private
String
orgid
;
/**
* 单位编码
*/
private
String
orgcode
;
/**
* 单位名称
*/
private
String
orgname
;
/**
* 昵称别名
*/
private
String
nickname
;
/**
* 邮箱
*/
private
String
email
;
/**
* 社交账号
*/
private
String
avatar
;
/**
* 电话
*/
private
String
phone
;
/**
* 照片
*/
private
String
usericon
;
/**
* 性别
*/
private
String
sex
;
/**
* 出生日期
*/
private
Timestamp
birthday
;
/**
* 证件号码
*/
private
String
certcode
;
/**
* 地址
*/
private
String
addr
;
/**
* 主题
*/
private
String
theme
;
/**
* 字号
*/
private
String
fontsize
;
/**
* 语言
*/
private
String
lang
;
/**
* 备注
*/
private
String
memo
;
/**
* 保留字段
*/
private
String
reserver
;
/**
* 用户上下文参数
*/
private
Map
<
String
,
Object
>
sessionParams
;
/**
* 用户权限资源
*/
@JsonIgnore
private
Collection
<
GrantedAuthority
>
authorities
;
/**
* 是否为超级管理员
*/
private
int
superuser
;
/**
* 用户权限资源
*/
private
JSONObject
permissionList
;
/**
* 用户上下文参数
*/
@JsonIgnore
private
Map
<
String
,
Object
>
userSessionParam
;
/**
* 当前用户上下级组织信息
*/
private
Map
<
String
,
Set
<
String
>>
orgInfo
;
/**
* 上级组织
*/
private
String
porg
;
/**
* 下级组织
*/
private
String
sorg
;
/**
* 上级部门
*/
private
String
pdept
;
/**
* 下级部门
*/
private
String
sdept
;
@JsonIgnore
@Override
public
boolean
isAccountNonExpired
()
{
return
true
;
}
@JsonIgnore
@Override
public
boolean
isAccountNonLocked
()
{
return
true
;
}
@JsonIgnore
@Override
public
boolean
isCredentialsNonExpired
()
{
return
true
;
}
@JsonIgnore
@Override
public
String
getPassword
()
{
return
password
;
}
@Override
public
boolean
isEnabled
()
{
return
true
;
}
public
static
AuthenticationUser
getAuthenticationUser
()
{
if
(
SecurityContextHolder
.
getContext
()==
null
||
SecurityContextHolder
.
getContext
().
getAuthentication
()==
null
||
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
()==
null
){
return
new
AuthenticationUser
();
}
Object
userDetails
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
AuthenticationUser
authuserdetail
;
if
(
userDetails
instanceof
AuthenticationUser
)
{
authuserdetail
=
(
AuthenticationUser
)
userDetails
;
}
else
{
authuserdetail
=
new
AuthenticationUser
();
}
return
authuserdetail
;
}
public
static
AuthenticationUser
setAuthenticationUser
(
String
userId
,
String
userName
)
{
AuthenticationUser
user
=
new
AuthenticationUser
();
user
.
setUserid
(
userId
);
user
.
setPersonname
(
userName
);
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
user
,
null
,
user
.
getAuthorities
());
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
return
user
;
}
public
Map
<
String
,
Object
>
getSessionParams
()
{
if
(
this
.
sessionParams
==
null
)
{
sessionParams
=
getUserSessionParam
();
sessionParams
.
put
(
"srfsystemid"
,
this
.
getSrfsystemid
());
sessionParams
.
put
(
"srfpersonid"
,
this
.
getUserid
());
sessionParams
.
put
(
"srfpersonname"
,
this
.
getPersonname
());
sessionParams
.
put
(
"srforgsectorid"
,
this
.
getMdeptid
());
sessionParams
.
put
(
"srforgsectorcode"
,
this
.
getMdeptcode
());
sessionParams
.
put
(
"srforgsectorname"
,
this
.
getMdeptname
());
sessionParams
.
put
(
"srforgid"
,
this
.
getOrgid
());
sessionParams
.
put
(
"srforgcode"
,
this
.
getOrgcode
());
sessionParams
.
put
(
"srforgname"
,
this
.
getOrgname
());
sessionParams
.
put
(
"srfuserid"
,
this
.
getUserid
());
sessionParams
.
put
(
"srfusername"
,
this
.
getPersonname
());
sessionParams
.
put
(
"srfusermode"
,
""
);
sessionParams
.
put
(
"srforgsectorbc"
,
this
.
getBcode
());
sessionParams
.
put
(
"srfloginname"
,
this
.
getLoginname
());
sessionParams
.
put
(
"srflocale"
,
this
.
getLang
());
sessionParams
.
put
(
"srftimezone"
,
""
);
sessionParams
.
put
(
"srfusercode"
,
this
.
getUsercode
());
sessionParams
.
put
(
"srfporg"
,
this
.
getPorg
());
sessionParams
.
put
(
"srfsorg"
,
this
.
getSorg
());
sessionParams
.
put
(
"srfpdept"
,
this
.
getPdept
());
sessionParams
.
put
(
"srfsdept"
,
this
.
getSdept
());
}
return
this
.
sessionParams
;
}
private
Map
<
String
,
Object
>
getUserSessionParam
()
{
if
(
userSessionParam
!=
null
){
return
userSessionParam
;
}
else
{
return
new
HashMap
<>();
}
}
public
void
setOrgInfo
(
Map
<
String
,
Set
<
String
>>
orgInfo
)
{
this
.
orgInfo
=
orgInfo
;
if
(!
ObjectUtils
.
isEmpty
(
orgInfo
)
&&
!
ObjectUtils
.
isEmpty
(
orgInfo
.
get
(
"parentorg"
))){
porg
=(
String
.
format
(
"'%s'"
,
String
.
join
(
"','"
,
orgInfo
.
get
(
"parentorg"
))));
this
.
getSessionParams
().
put
(
"srfporg"
,
porg
);
}
if
(!
ObjectUtils
.
isEmpty
(
orgInfo
)
&&
!
ObjectUtils
.
isEmpty
(
orgInfo
.
get
(
"suborg"
))
){
sorg
=(
String
.
format
(
"'%s'"
,
String
.
join
(
"','"
,
orgInfo
.
get
(
"suborg"
))));
this
.
getSessionParams
().
put
(
"srfsorg"
,
sorg
);
}
if
(!
ObjectUtils
.
isEmpty
(
orgInfo
)
&&
!
ObjectUtils
.
isEmpty
(
orgInfo
.
get
(
"parentdept"
))){
pdept
=(
String
.
format
(
"'%s'"
,
String
.
join
(
"','"
,
orgInfo
.
get
(
"parentdept"
))));
this
.
getSessionParams
().
put
(
"srfpdept"
,
pdept
);
}
if
(!
ObjectUtils
.
isEmpty
(
orgInfo
)
&&
!
ObjectUtils
.
isEmpty
(
orgInfo
.
get
(
"subdept"
))){
sdept
=(
String
.
format
(
"'%s'"
,
String
.
join
(
"','"
,
orgInfo
.
get
(
"subdept"
))));
this
.
getSessionParams
().
put
(
"srfsdept"
,
sdept
);
}
}
public
void
setPermissionList
(
JSONObject
permissionList
)
{
this
.
permissionList
=
permissionList
;
if
(
authorities
==
null
&&
permissionList
!=
null
){
if
(
permissionList
.
getJSONArray
(
"authorities"
)!=
null
){
authorities
=
new
ArrayList
<>();
permissionList
.
getJSONArray
(
"authorities"
).
forEach
(
item
->
authorities
.
add
(
new
SimpleGrantedAuthority
(
String
.
valueOf
(
item
))));
}
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthorizationLogin.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
javax.validation.constraints.NotBlank
;
@Getter
@Setter
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AuthorizationLogin
{
private
String
domain
;
@NotBlank
(
message
=
"用户名不能为空"
)
private
String
loginname
;
@NotBlank
(
message
=
"密码不能为空"
)
private
String
password
;
public
String
getUsername
()
{
if
(!
ObjectUtils
.
isEmpty
(
domain
))
return
loginname
+
"|"
+
domain
;
return
loginname
;
}
@Override
public
String
toString
()
{
return
"AuthorizationLogin{"
+
"domain='"
+
domain
+
'\''
+
", loginname='"
+
loginname
+
'\''
+
", password='××××××'}"
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthorizationTokenFilter.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
io.jsonwebtoken.ExpiredJwtException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.web.authentication.WebAuthenticationDetailsSource
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.AntPathMatcher
;
import
org.springframework.util.PathMatcher
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Set
;
@Slf4j
@Component
public
class
AuthorizationTokenFilter
extends
OncePerRequestFilter
{
private
final
AuthenticationUserService
userDetailsService
;
private
final
AuthTokenUtil
authTokenUtil
;
private
final
String
tokenHeader
;
private
Set
<
String
>
excludesPattern
=
new
HashSet
<
String
>();
private
PathMatcher
pathMatcher
=
new
AntPathMatcher
();
public
AuthorizationTokenFilter
(
AuthenticationUserService
userDetailsService
,
AuthTokenUtil
authTokenUtil
,
@Value
(
"${ibiz.jwt.header:Authorization}"
)
String
tokenHeader
)
{
this
.
userDetailsService
=
userDetailsService
;
this
.
authTokenUtil
=
authTokenUtil
;
this
.
tokenHeader
=
tokenHeader
;
}
@Override
protected
void
doFilterInternal
(
HttpServletRequest
request
,
HttpServletResponse
response
,
FilterChain
chain
)
throws
ServletException
,
IOException
{
if
(
isExclusion
(
request
.
getRequestURI
()))
{
chain
.
doFilter
(
request
,
response
);
return
;
}
final
String
requestHeader
=
request
.
getHeader
(
this
.
tokenHeader
);
String
username
=
null
;
String
authToken
=
null
;
if
(
requestHeader
!=
null
&&
requestHeader
.
startsWith
(
"Bearer "
))
{
authToken
=
requestHeader
.
substring
(
7
);
try
{
username
=
authTokenUtil
.
getUsernameFromToken
(
authToken
);
}
catch
(
ExpiredJwtException
e
)
{
log
.
error
(
e
.
getMessage
());
}
}
if
(
username
!=
null
&&
SecurityContextHolder
.
getContext
().
getAuthentication
()
==
null
)
{
UserDetails
userDetails
=
this
.
userDetailsService
.
loadUserByUsername
(
username
);
if
(
authTokenUtil
.
validateToken
(
authToken
,
userDetails
))
{
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDetails
,
null
,
userDetails
.
getAuthorities
());
authentication
.
setDetails
(
new
WebAuthenticationDetailsSource
().
buildDetails
(
request
));
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
}
}
chain
.
doFilter
(
request
,
response
);
}
public
void
setExcludesPattern
(
String
excludesPattern
)
{
this
.
excludesPattern
=
new
HashSet
(
Arrays
.
asList
(
excludesPattern
.
split
(
"\\s*,\\s*"
)));
}
public
void
addExcludePattern
(
String
excludePattern
)
{
excludesPattern
.
add
(
excludePattern
);
}
private
boolean
isExclusion
(
String
requestURI
)
{
if
(
this
.
excludesPattern
==
null
)
{
return
false
;
}
else
{
Iterator
excludeIterator
=
this
.
excludesPattern
.
iterator
();
String
pattern
;
do
{
if
(!
excludeIterator
.
hasNext
())
{
return
false
;
}
pattern
=
(
String
)
excludeIterator
.
next
();
}
while
(!
pathMatcher
.
match
(
pattern
,
requestURI
));
return
true
;
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/SimpleTokenUtil.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Clock
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
io.jsonwebtoken.impl.DefaultClock
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.function.Function
;
@Component
@ConditionalOnExpression
(
"(!${ibiz.enablePermissionValid:false})&&'${ibiz.auth.token.util:UAATokenUtil}'.equals('SimpleTokenUtil')"
)
public
class
SimpleTokenUtil
implements
AuthTokenUtil
,
Serializable
{
private
static
final
long
serialVersionUID
=
-
3301605591108950415L
;
private
Clock
clock
=
DefaultClock
.
INSTANCE
;
@Value
(
"${ibiz.jwt.secret:ibzsecret}"
)
private
String
secret
;
@Value
(
"${ibiz.jwt.expiration:7200000}"
)
private
Long
expiration
;
@Value
(
"${ibiz.jwt.header:Authorization}"
)
private
String
tokenHeader
;
public
String
getUsernameFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getSubject
);
}
public
Date
getIssuedAtDateFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getIssuedAt
);
}
public
Date
getExpirationDateFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getExpiration
);
}
public
<
T
>
T
getClaimFromToken
(
String
token
,
Function
<
Claims
,
T
>
claimsResolver
)
{
final
Claims
claims
=
getAllClaimsFromToken
(
token
);
return
claimsResolver
.
apply
(
claims
);
}
private
Claims
getAllClaimsFromToken
(
String
token
)
{
return
Jwts
.
parser
()
.
setSigningKey
(
secret
)
.
parseClaimsJws
(
token
)
.
getBody
();
}
private
Boolean
isTokenExpired
(
String
token
)
{
final
Date
expiration
=
getExpirationDateFromToken
(
token
);
return
expiration
.
before
(
clock
.
now
());
}
private
Boolean
isCreatedBeforeLastPasswordReset
(
Date
created
,
Date
lastPasswordReset
)
{
return
(
lastPasswordReset
!=
null
&&
created
.
before
(
lastPasswordReset
));
}
private
Boolean
ignoreTokenExpiration
(
String
token
)
{
// here you specify tokens, for that the expiration is ignored
return
false
;
}
public
String
generateToken
(
UserDetails
userDetails
)
{
Map
<
String
,
Object
>
claims
=
new
HashMap
<>();
return
doGenerateToken
(
claims
,
userDetails
.
getUsername
());
}
private
String
doGenerateToken
(
Map
<
String
,
Object
>
claims
,
String
subject
)
{
final
Date
createdDate
=
clock
.
now
();
final
Date
expirationDate
=
calculateExpirationDate
(
createdDate
);
return
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setSubject
(
subject
)
.
setIssuedAt
(
createdDate
)
.
setExpiration
(
expirationDate
)
.
signWith
(
SignatureAlgorithm
.
HS512
,
secret
)
.
compact
();
}
public
Boolean
canTokenBeRefreshed
(
String
token
,
Date
lastPasswordReset
)
{
final
Date
created
=
getIssuedAtDateFromToken
(
token
);
return
!
isCreatedBeforeLastPasswordReset
(
created
,
lastPasswordReset
)
&&
(!
isTokenExpired
(
token
)
||
ignoreTokenExpiration
(
token
));
}
public
String
refreshToken
(
String
token
)
{
final
Date
createdDate
=
clock
.
now
();
final
Date
expirationDate
=
calculateExpirationDate
(
createdDate
);
final
Claims
claims
=
getAllClaimsFromToken
(
token
);
claims
.
setIssuedAt
(
createdDate
);
claims
.
setExpiration
(
expirationDate
);
return
Jwts
.
builder
()
.
setClaims
(
claims
)
.
signWith
(
SignatureAlgorithm
.
HS512
,
secret
)
.
compact
();
}
public
Boolean
validateToken
(
String
token
,
UserDetails
userDetails
)
{
AuthenticationUser
user
=
(
AuthenticationUser
)
userDetails
;
final
Date
created
=
getIssuedAtDateFromToken
(
token
);
return
(!
isTokenExpired
(
token
)
);
}
private
Date
calculateExpirationDate
(
Date
createdDate
)
{
return
new
Date
(
createdDate
.
getTime
()
+
expiration
);
}
/**
* Get the login of the current user.
*
* @return the login of the current user
*/
public
static
Optional
<
String
>
getCurrentUserLogin
()
{
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
return
Optional
.
ofNullable
(
securityContext
.
getAuthentication
())
.
map
(
authentication
->
{
if
(
authentication
.
getPrincipal
()
instanceof
UserDetails
)
{
UserDetails
springSecurityUser
=
(
UserDetails
)
authentication
.
getPrincipal
();
return
springSecurityUser
.
getUsername
();
}
else
if
(
authentication
.
getPrincipal
()
instanceof
String
)
{
return
(
String
)
authentication
.
getPrincipal
();
}
return
null
;
});
}
/**
* Check if a user is authenticated.
*
* @return true if the user is authenticated, false otherwise
*/
public
static
boolean
isAuthenticated
()
{
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
return
Optional
.
ofNullable
(
securityContext
.
getAuthentication
())
.
map
(
authentication
->
authentication
.
getAuthorities
().
stream
()
.
noneMatch
(
grantedAuthority
->
grantedAuthority
.
getAuthority
().
equals
(
"ANONYMOUS"
)))
.
orElse
(
false
);
}
/**
* If the current user has a specific authority (security role).
* <p>
* The name of this method comes from the isUserInRole() method in the Servlet API
*
* @param authority the authority to check
* @return true if the current user has the authority, false otherwise
*/
public
static
boolean
isCurrentUserInRole
(
String
authority
)
{
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
return
Optional
.
ofNullable
(
securityContext
.
getAuthentication
())
.
map
(
authentication
->
authentication
.
getAuthorities
().
stream
()
.
anyMatch
(
grantedAuthority
->
grantedAuthority
.
getAuthority
().
equals
(
authority
)))
.
orElse
(
false
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/SpringContextHolder.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
@Component
public
class
SpringContextHolder
implements
ApplicationContextAware
{
private
static
ApplicationContext
applicationContext
;
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
SpringContextHolder
.
applicationContext
=
applicationContext
;
}
public
static
ApplicationContext
getApplicationContext
()
{
assertApplicationContext
();
return
applicationContext
;
}
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
getBean
(
String
beanName
)
{
assertApplicationContext
();
return
(
T
)
applicationContext
.
getBean
(
beanName
);
}
public
static
<
T
>
T
getBean
(
Class
<
T
>
requiredType
)
{
assertApplicationContext
();
return
applicationContext
.
getBean
(
requiredType
);
}
private
static
void
assertApplicationContext
()
{
if
(
SpringContextHolder
.
applicationContext
==
null
)
{
throw
new
RuntimeException
(
"applicaitonContext属性为null,请检查是否注入了SpringContextHolder!"
);
}
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/UAATokenUtil.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
security
;
import
cn.ibizlab.util.client.IBZUAAFeignClient
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Clock
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.impl.DefaultClock
;
import
lombok.SneakyThrows
;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.security.KeyFactory
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.PublicKey
;
import
java.security.spec.InvalidKeySpecException
;
import
java.security.spec.X509EncodedKeySpec
;
import
java.util.Date
;
import
java.util.function.Function
;
@Component
@ConditionalOnExpression
(
"${ibiz.enablePermissionValid:false}||'${ibiz.auth.token.util:UAATokenUtil}'.equals('UAATokenUtil')"
)
public
class
UAATokenUtil
implements
AuthTokenUtil
,
Serializable
{
private
static
final
long
serialVersionUID
=
-
3301605591108950415L
;
private
Clock
clock
=
DefaultClock
.
INSTANCE
;
@Value
(
"${ibiz.jwt.secret:ibzsecret}"
)
private
String
secret
;
@Value
(
"${ibiz.jwt.expiration:7200000}"
)
private
Long
expiration
;
@Value
(
"${ibiz.jwt.header:Authorization}"
)
private
String
tokenHeader
;
@Autowired
private
IBZUAAFeignClient
uaaFeignClient
;
public
String
getUsernameFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getSubject
);
}
public
Date
getIssuedAtDateFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getIssuedAt
);
}
public
Date
getExpirationDateFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getExpiration
);
}
public
<
T
>
T
getClaimFromToken
(
String
token
,
Function
<
Claims
,
T
>
claimsResolver
)
{
final
Claims
claims
=
getAllClaimsFromToken
(
token
);
return
claimsResolver
.
apply
(
claims
);
}
public
Claims
getAllClaimsFromToken
(
String
token
)
{
PublicKey
publicKey
=
getPublicKey
(
getPublicKeyString
());
return
Jwts
.
parser
()
.
setSigningKey
(
publicKey
)
.
parseClaimsJws
(
token
)
.
getBody
();
}
private
Boolean
isTokenExpired
(
String
token
)
{
final
Date
expiration
=
getExpirationDateFromToken
(
token
);
return
expiration
.
before
(
clock
.
now
());
}
public
String
generateToken
(
UserDetails
userDetails
)
{
return
null
;
}
public
Boolean
validateToken
(
String
token
,
UserDetails
userDetails
)
{
AuthenticationUser
user
=
(
AuthenticationUser
)
userDetails
;
final
Date
created
=
getIssuedAtDateFromToken
(
token
);
return
(!
isTokenExpired
(
token
)
);
}
private
String
getPublicKeyString
(){
return
uaaFeignClient
.
getPublicKey
();
}
/**
* 获取PublicKey对象
* @param publicKeyBase64
* @return
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
@SneakyThrows
public
PublicKey
getPublicKey
(
String
publicKeyBase64
)
{
byte
[]
byteKey
=
Base64
.
decodeBase64
(
publicKeyBase64
);
X509EncodedKeySpec
x509EncodedKeySpec
=
new
X509EncodedKeySpec
(
byteKey
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
return
keyFactory
.
generatePublic
(
x509EncodedKeySpec
);
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/AuthenticationUserService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
public
interface
AuthenticationUserService
extends
UserDetailsService
{
@Override
@Cacheable
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
default
AuthenticationUser
loadUserByUsername
(
String
username
){
return
null
;
}
@Cacheable
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
AuthenticationUser
loadUserByLogin
(
String
username
,
String
password
);
@CacheEvict
(
value
=
"ibzuaa_users"
,
key
=
"'glob:*getByUsername:'+#p0"
)
default
void
resetByUsername
(
String
username
){}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/FileService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.domain.FileItem
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
public
interface
FileService
{
FileItem
saveFile
(
MultipartFile
multipartFile
);
File
getFile
(
String
fileid
);
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/IBZUAAUserService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.client.IBZUAAFeignClient
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.stereotype.Service
;
/**
* 实体[IBZUSER] 服务对象接口实现
*/
@Service
(
"IBZUAAUserService"
)
@ConditionalOnExpression
(
"${ibiz.enablePermissionValid:false}||'${ibiz.auth.service:IBZUAAUserService}'.equals('IBZUAAUserService')"
)
public
class
IBZUAAUserService
implements
AuthenticationUserService
{
@Autowired
private
IBZUAAFeignClient
uaaFeignClient
;
@Override
public
AuthenticationUser
loadUserByUsername
(
String
username
)
{
AuthenticationUser
user
=
uaaFeignClient
.
loginByUsername
(
username
);
if
(
user
==
null
)
{
throw
new
BadRequestAlertException
(
"登录失败"
,
"IBZUAAUser"
,
username
);
}
return
user
;
}
@Override
public
AuthenticationUser
loadUserByLogin
(
String
username
,
String
password
)
{
String
[]
data
=
username
.
split
(
"[|]"
);
String
loginname
=
username
;
String
domains
=
""
;
if
(
data
.
length
==
2
)
{
loginname
=
data
[
0
].
trim
();
domains
=
data
[
1
].
trim
();
}
AuthorizationLogin
logininfo
=
new
AuthorizationLogin
();
logininfo
.
setDomain
(
domains
);
logininfo
.
setLoginname
(
loginname
);
logininfo
.
setPassword
(
password
);
AuthenticationUser
user
=
uaaFeignClient
.
login
(
logininfo
);
if
(
user
==
null
){
throw
new
BadRequestAlertException
(
"登录失败"
,
"IBZUAAUser"
,
username
);
}
return
user
;
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/RemoteService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
feign.*
;
import
feign.codec.Decoder
;
import
feign.codec.Encoder
;
import
org.springframework.beans.factory.ObjectFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.http.HttpMessageConverters
;
import
org.springframework.cloud.openfeign.FeignContext
;
import
org.springframework.cloud.openfeign.support.SpringDecoder
;
import
org.springframework.cloud.openfeign.support.SpringEncoder
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 自定义feigen客户端配置
*
* @author
*/
@Service
public
class
RemoteService
{
/**
* FeignClientFactoryBean
*/
@Autowired
protected
FeignContext
feignContext
;
/**
* FeignClient 默认LoadBalancerFeignClient
*/
@Autowired
private
Client
feignClient
;
private
static
final
Map
<
String
,
Object
>
FEIGN_CLIENTS
=
new
ConcurrentHashMap
<>();
/**
* 定义远程通用接口
*/
public
interface
RemoteFeignClient
{
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/{path}"
)
JSONObject
post
(
@PathVariable
(
"path"
)
String
path
,
@RequestHeader
(
"Authorization"
)
String
token
,
@RequestBody
Map
param
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/{path}"
)
JSONObject
request
(
@PathVariable
(
"path"
)
String
path
,
@RequestHeader
(
"Authorization"
)
String
token
,
Map
param
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/{path}"
)
JSONObject
get
(
@PathVariable
(
"path"
)
String
path
,
@RequestHeader
(
"Authorization"
)
String
token
);
@RequestMapping
(
method
=
RequestMethod
.
PUT
,
value
=
"/{path}"
)
JSONObject
put
(
@PathVariable
(
"path"
)
String
path
,
@RequestHeader
(
"Authorization"
)
String
token
,
@RequestBody
Map
param
);
@RequestMapping
(
method
=
RequestMethod
.
DELETE
,
value
=
"/{path}"
)
JSONObject
delete
(
@PathVariable
(
"path"
)
String
path
,
@RequestHeader
(
"Authorization"
)
String
token
);
}
/**
* @param serverId
* @return
*/
public
RemoteFeignClient
getClient
(
String
serverId
)
{
return
this
.
create
(
RemoteFeignClient
.
class
,
serverId
);
}
/**
* 设置编码解码器为FastJson
*
* @param clazz
* @param serviceId
* @param <T>
* @return
*/
private
synchronized
<
T
>
T
create
(
Class
<
T
>
clazz
,
String
serviceId
)
{
Object
object
=
FEIGN_CLIENTS
.
get
(
serviceId
);
if
(
Objects
.
isNull
(
object
))
{
object
=
Feign
.
builder
()
//decoder指定对象解码方式
.
decoder
(
this
.
feignDecoder
())
.
encoder
(
this
.
feignEncoder
())
.
client
(
feignClient
)
//options方法指定连接超时时长及响应超时时长
.
options
(
new
Request
.
Options
(
5000
,
50000
))
//retryer方法指定重试策略
//.retryer(new Retryer.Default(5000, 5000, 3))
.
contract
(
feignContext
.
getInstance
(
serviceId
,
Contract
.
class
))
//target方法绑定接口与服务端地址。返回类型为绑定的接口类型。
.
target
(
clazz
,
"http://"
+
serviceId
);
FEIGN_CLIENTS
.
put
(
serviceId
,
object
);
}
return
(
T
)
object
;
}
private
Decoder
feignDecoder
()
{
return
new
SpringDecoder
(
feignHttpMessageConverter
());
}
private
Encoder
feignEncoder
()
{
return
new
SpringEncoder
(
feignHttpMessageConverter
());
}
private
ObjectFactory
<
HttpMessageConverters
>
feignHttpMessageConverter
()
{
HttpMessageConverter
jsonConverter
=
new
MappingJackson2HttpMessageConverter
(
new
ObjectMapper
());
final
HttpMessageConverters
httpMessageConverters
=
new
HttpMessageConverters
(
jsonConverter
);
return
()
->
httpMessageConverters
;
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/SimpleFileService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.domain.FileItem
;
import
cn.ibizlab.util.errors.InternalServerErrorException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
@Primary
@Slf4j
@Service
public
class
SimpleFileService
implements
FileService
{
@Value
(
"${ibiz.filePath:/app/file/}"
)
private
String
fileRoot
;
@Override
public
FileItem
saveFile
(
MultipartFile
multipartFile
)
{
FileItem
item
=
null
;
// 获取文件名
String
fileName
=
multipartFile
.
getOriginalFilename
();
// 获取文件后缀
String
extname
=
"."
+
getExtensionName
(
fileName
);
try
{
String
fileid
=
DigestUtils
.
md5DigestAsHex
(
multipartFile
.
getInputStream
());
String
fileFullPath
=
this
.
fileRoot
+
"ibizutil"
+
File
.
separator
+
fileid
+
File
.
separator
+
fileName
;
File
file
=
new
File
(
fileFullPath
);
File
parent
=
new
File
(
file
.
getParent
());
if
(!
parent
.
exists
())
{
parent
.
mkdirs
();
}
FileCopyUtils
.
copy
(
multipartFile
.
getInputStream
(),
Files
.
newOutputStream
(
file
.
toPath
()));
item
=
new
FileItem
(
fileid
,
fileName
,
fileid
,
fileName
,
(
int
)
multipartFile
.
getSize
(),
extname
);
}
catch
(
IOException
e
)
{
throw
new
InternalServerErrorException
(
"文件上传失败,"
+
e
);
}
return
item
;
}
@Override
public
File
getFile
(
String
fileid
)
{
String
dirpath
=
this
.
fileRoot
+
"ibizutil"
+
File
.
separator
+
fileid
;
File
parent
=
new
File
(
dirpath
);
if
(
parent
.
exists
()
&&
parent
.
isDirectory
()
&&
parent
.
listFiles
().
length
>
0
)
{
return
parent
.
listFiles
()[
0
];
}
throw
new
InternalServerErrorException
(
"文件未找到"
);
}
/**
* 获取文件扩展名
* @param filename
* @return
*/
public
static
String
getExtensionName
(
String
filename
)
{
if
((
filename
!=
null
)
&&
(
filename
.
length
()
>
0
))
{
int
dot
=
filename
.
lastIndexOf
(
'.'
);
if
((
dot
>-
1
)
&&
(
dot
<
(
filename
.
length
()
-
1
)))
{
return
filename
.
substring
(
dot
+
1
);
}
}
return
filename
;
}
}
\ No newline at end of file
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/SimpleUserService.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.stereotype.Service
;
/**
* 实体[IBZUSER] 服务对象接口实现
*/
@Primary
@Service
(
"SimpleUserService"
)
@ConditionalOnExpression
(
"(!${ibiz.enablePermissionValid:false})&&'${ibiz.auth.service:IBZUAAUserService}'.equals('SimpleUserService')"
)
public
class
SimpleUserService
implements
AuthenticationUserService
{
@Override
public
AuthenticationUser
loadUserByUsername
(
String
username
)
{
AuthenticationUser
user
=
new
AuthenticationUser
();
String
[]
data
=
username
.
split
(
"[|]"
);
String
loginname
=
username
;
String
domains
=
""
;
String
password
=
""
;
if
(
data
.
length
==
2
)
{
loginname
=
data
[
0
].
trim
();
domains
=
data
[
1
].
trim
();
}
user
.
setUserid
(
username
);
user
.
setUsercode
(
loginname
);
user
.
setUsername
(
username
);
user
.
setLoginname
(
loginname
);
user
.
setPersonname
(
loginname
);
user
.
setDomain
(
domains
);
user
.
setPassword
(
password
);
user
.
setOrgid
(
domains
);
user
.
setOrgcode
(
domains
);
user
.
setOrgname
(
domains
);
user
.
setSuperuser
(
1
);
user
.
setAuthorities
(
AuthorityUtils
.
createAuthorityList
(
"ROLE_SUPERADMIN"
));
return
user
;
}
@Override
public
AuthenticationUser
loadUserByLogin
(
String
username
,
String
password
)
{
AuthenticationUser
authuserdetail
=
loadUserByUsername
(
username
);
return
authuserdetail
;
}
@Override
public
void
resetByUsername
(
String
username
)
{
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/web/FeignRequestInterceptor.java
0 → 100644
浏览文件 @
0d372a39
package
cn
.
ibizlab
.
util
.
web
;
import
feign.RequestInterceptor
;
import
feign.RequestTemplate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Enumeration
;
/**
* feign请求拦截器
* 拦截所有使用feign发出的请求,附加原始请求Header参数及Token
*/
@Configuration
public
class
FeignRequestInterceptor
implements
RequestInterceptor
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Override
public
void
apply
(
RequestTemplate
requestTemplate
)
{
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
if
(
requestAttributes
!=
null
)
{
HttpServletRequest
request
=
requestAttributes
.
getRequest
();
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
if
(
headerNames
!=
null
)
{
while
(
headerNames
.
hasMoreElements
())
{
String
name
=
headerNames
.
nextElement
();
if
(
name
.
equalsIgnoreCase
(
"transfer-encoding"
))
{
continue
;
}
String
values
=
request
.
getHeader
(
name
);
requestTemplate
.
header
(
name
,
values
);
}
logger
.
info
(
"feign interceptor header:{}"
,
requestTemplate
);
}
}
}
}
\ No newline at end of file
pom.xml
0 → 100644
浏览文件 @
0d372a39
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
cn.ibizlab
</groupId>
<artifactId>
ibizlab-boot-starter-parent
</artifactId>
<version>
2.4.0-SNAPSHOT
</version>
<relativePath>
ibizlab-boot-starter-parent/pom.xml
</relativePath>
</parent>
<groupId>
cn.ibizlab
</groupId>
<artifactId>
ibizlab-boot-starters
</artifactId>
<version>
2.4.0-SNAPSHOT
</version>
<packaging>
pom
</packaging>
<name>
ibizlab-boot-starters
</name>
<description>
ibizlab-boot-starters
</description>
<properties>
<revision>
2.4.0-SNAPSHOT
</revision>
</properties>
<modules>
<module>
ibizlab-boot-starter-parent
</module>
<module>
ibizlab-boot-starter
</module>
<module>
ibizlab-boot-starter-data
</module>
</modules>
</project>
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录