Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
713143a3
提交
713143a3
authored
4月 14, 2022
作者:
谭志磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 新增字典功能,导入导出字典翻译¥
上级
fd72e226
显示空白字符变更
内嵌
并排
正在显示
22 个修改的文件
包含
1437 行增加
和
94 行删除
+1437
-94
DictParam.java
app/src/main/java/com/yiring/app/param/dict/DictParam.java
+37
-0
DictQueryParam.java
...c/main/java/com/yiring/app/param/dict/DictQueryParam.java
+23
-0
DictTypeParam.java
...rc/main/java/com/yiring/app/param/dict/DictTypeParam.java
+30
-0
DictTypeQueryParam.java
...in/java/com/yiring/app/param/dict/DictTypeQueryParam.java
+21
-0
DictService.java
...rc/main/java/com/yiring/app/service/dict/DictService.java
+99
-0
DictTypeService.java
...ain/java/com/yiring/app/service/dict/DictTypeService.java
+42
-0
DictServiceImpl.java
...ava/com/yiring/app/service/dict/impl/DictServiceImpl.java
+184
-0
DictTypeServiceImpl.java
...com/yiring/app/service/dict/impl/DictTypeServiceImpl.java
+137
-0
DictController.java
...src/main/java/com/yiring/app/web/dict/DictController.java
+78
-0
DictTypeController.java
...main/java/com/yiring/app/web/dict/DictTypeController.java
+74
-0
build.gradle
basic-common/core/build.gradle
+3
-5
RedisCache.java
...rc/main/java/com/yiring/common/core/redis/RedisCache.java
+225
-0
Dict.java
...ommon/core/src/main/java/com/yiring/common/dict/Dict.java
+61
-0
DictRepository.java
.../src/main/java/com/yiring/common/dict/DictRepository.java
+42
-0
DictType.java
...n/core/src/main/java/com/yiring/common/dict/DictType.java
+52
-0
DictTypeRepository.java
.../main/java/com/yiring/common/dict/DictTypeRepository.java
+18
-0
build.gradle
basic-common/util/build.gradle
+6
-0
Excel.java
...til/src/main/java/com/yiring/common/annotation/Excel.java
+46
-42
RequestAspect.java
...src/main/java/com/yiring/common/aspect/RequestAspect.java
+0
-0
DictUtils.java
.../util/src/main/java/com/yiring/common/util/DictUtils.java
+162
-0
ExcelUtils.java
.../src/main/java/com/yiring/common/util/poi/ExcelUtils.java
+52
-47
SpringUtil.java
...c/main/java/com/yiring/common/util/spring/SpringUtil.java
+45
-0
没有找到文件。
app/src/main/java/com/yiring/app/param/dict/DictParam.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
param
.
dict
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
javax.validation.constraints.NotEmpty
;
/**
* @author tzl
* 2022/4/13 15:51
*/
@ApiModel
(
"DictParam"
)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
public
class
DictParam
{
@ApiModelProperty
(
value
=
"排序"
,
example
=
"1"
,
required
=
true
)
Integer
dictSort
;
@ApiModelProperty
(
value
=
"字典标签"
,
example
=
"男"
,
required
=
true
)
@NotEmpty
(
message
=
"字典标签不能为空"
)
String
dictLabel
;
@ApiModelProperty
(
value
=
"字典值"
,
example
=
"1"
,
required
=
true
)
@NotEmpty
(
message
=
"字典值不能为空"
)
String
dictValue
;
@ApiModelProperty
(
value
=
"字典类型"
,
example
=
"user_sex"
,
required
=
true
)
@NotEmpty
(
message
=
"字典类型不能为空"
)
String
dictType
;
@ApiModelProperty
(
value
=
"是否启用"
,
example
=
"1"
,
required
=
true
)
@NotEmpty
(
message
=
"是否启用必填"
)
String
status
;
@ApiModelProperty
(
value
=
"备注"
,
example
=
"性别"
,
required
=
true
)
String
remark
;
}
app/src/main/java/com/yiring/app/param/dict/DictQueryParam.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
param
.
dict
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
/**
* @author tzl
* 2022/4/13 16:06
*/
@ApiModel
(
"DictQueryParam"
)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
public
class
DictQueryParam
{
@ApiModelProperty
(
value
=
"字典标签"
,
example
=
"男"
)
String
dictLabel
;
@ApiModelProperty
(
value
=
"字典类型"
,
example
=
"user_sex"
)
String
dictType
;
}
app/src/main/java/com/yiring/app/param/dict/DictTypeParam.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
param
.
dict
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
javax.validation.constraints.NotEmpty
;
/**
* @author tzl
* 2022/4/13 15:51
*/
@ApiModel
(
"DictParam"
)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
public
class
DictTypeParam
{
@ApiModelProperty
(
value
=
"字典名称"
,
example
=
"性别"
,
required
=
true
)
@NotEmpty
(
message
=
"字典名称不能为空"
)
String
dictName
;
@ApiModelProperty
(
value
=
"字典类型"
,
example
=
"user_sex"
,
required
=
true
)
@NotEmpty
(
message
=
"字典类型不能为空"
)
String
dictType
;
@ApiModelProperty
(
value
=
"是否启用"
,
example
=
"1"
,
required
=
true
)
@NotEmpty
(
message
=
"是否启用必填"
)
String
status
;
}
app/src/main/java/com/yiring/app/param/dict/DictTypeQueryParam.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
param
.
dict
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
/**
* @author tzl
* 2022/4/13 16:06
*/
@ApiModel
(
"DictQueryParam"
)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
public
class
DictTypeQueryParam
{
@ApiModelProperty
(
value
=
"字典名称"
,
example
=
"性别"
)
String
dictName
;
}
app/src/main/java/com/yiring/app/service/dict/DictService.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
service
.
dict
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.app.param.dict.DictParam
;
import
com.yiring.app.param.dict.DictQueryParam
;
import
com.yiring.common.vo.PageVo
;
import
java.util.ArrayList
;
/**
* 字典
*
* @author tzl
* 2022/4/13 15:36
*/
public
interface
DictService
{
/**
* 根据条件分页查询字典数据
*
* @param dictQueryParam DictQueryParam
* @return 字典数据集合信息
*/
Result
<
PageVo
<
Dict
>>
pageDictInfo
(
DictQueryParam
dictQueryParam
,
PageParam
param
);
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType String
* @param dictValue String
* @return 字典标签
*/
Result
<
String
>
selectDictLabel
(
String
dictType
,
String
dictValue
);
/**
* 从缓存中获取字典
* @param dictType
* @return
*/
Result
<
ArrayList
<
Dict
>>
selectDict
(
String
dictType
);
/**
* 根据字典数据ID查询信息
*
* @param id Long
* @return 字典数据
*/
Result
<
Dict
>
getDictInfo
(
Long
id
);
/**
* 删除字典数据信息
*
* @param idParam 主键id
*/
Result
<
String
>
deleteDictById
(
IdParam
idParam
);
/**
* 新增字典数据信息
*
* @param dictParam 字典数据信息入参
* @return 结果
*/
Result
<
String
>
saveDictInfo
(
DictParam
dictParam
);
/**
* 修改字典数据信息
*
* @param idParam 主键id
* @param dictParam 字典数据信息入参
* @return 结果
*/
Result
<
String
>
updateDictInfo
(
DictParam
dictParam
,
IdParam
idParam
);
/**
* 是否已有该字典标签
*
* @param param String
* @return 是否存在
*/
boolean
has
(
String
param
);
/**
* 是否该类型字典已有该字典值
*
* @param dictType String
* @param dictValue String
* @return 是否存在
*/
boolean
hasValue
(
String
dictType
,
String
dictValue
);
/**
* 加载字典缓存
*/
void
loadingDictCache
();
}
app/src/main/java/com/yiring/app/service/dict/DictTypeService.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
service
.
dict
;
import
com.yiring.app.param.dict.DictParam
;
import
com.yiring.app.param.dict.DictQueryParam
;
import
com.yiring.app.param.dict.DictTypeParam
;
import
com.yiring.app.param.dict.DictTypeQueryParam
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.common.dict.DictType
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.vo.PageVo
;
import
java.util.ArrayList
;
/**
* @author tzl
* 2022/4/14 14:10
*/
public
interface
DictTypeService
{
/**
* 根据条件分页查询字典类型
*
* @param dictTypeQueryParam DictTypeQueryParam
* @return 字典类型分页信息
*/
Result
<
PageVo
<
DictType
>>
pageDictTypeInfo
(
DictTypeQueryParam
dictTypeQueryParam
,
PageParam
param
);
Result
<
DictType
>
getDictTypeInfo
(
Long
id
);
Result
<
String
>
delecteById
(
Long
id
);
Result
<
String
>
saveDictTypeInfo
(
DictTypeParam
dictTypeParam
);
Result
<
String
>
updateDictTypeInfo
(
DictTypeParam
dictTypeParam
,
IdParam
idParam
);
boolean
has
(
String
param
);
}
app/src/main/java/com/yiring/app/service/dict/impl/DictServiceImpl.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
service
.
dict
.
impl
;
import
com.yiring.app.service.dict.DictService
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.common.dict.DictRepository
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.app.param.dict.DictParam
;
import
com.yiring.app.param.dict.DictQueryParam
;
import
com.yiring.common.util.DictUtils
;
import
com.yiring.common.util.StrUtils
;
import
com.yiring.common.vo.PageVo
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.data.domain.Example
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.persistence.criteria.Predicate
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* 字典
*
* @author tzl
* 2022/4/13 15:37
*/
@Service
public
class
DictServiceImpl
implements
DictService
{
@Resource
DictRepository
dictRepository
;
/**
* 项目启动时,初始化字典到缓存
*/
@PostConstruct
public
void
init
()
{
loadingDictCache
();
}
/**
* 加载字典缓存数据
*/
@Override
public
void
loadingDictCache
()
{
Dict
dict
=
Dict
.
builder
().
status
(
"1"
).
build
();
Map
<
String
,
List
<
Dict
>>
dictDataMap
=
dictRepository
.
findAll
(
Example
.
of
(
dict
)).
stream
().
collect
(
Collectors
.
groupingBy
(
Dict:
:
getDictType
));
for
(
Map
.
Entry
<
String
,
List
<
Dict
>>
entry
:
dictDataMap
.
entrySet
())
{
DictUtils
.
setDictCache
(
entry
.
getKey
(),
entry
.
getValue
().
stream
().
sorted
(
Comparator
.
comparing
(
Dict:
:
getDictSort
)).
collect
(
Collectors
.
toList
()));
}
}
@Override
public
Result
<
PageVo
<
Dict
>>
pageDictInfo
(
DictQueryParam
dictQueryParam
,
PageParam
param
)
{
Page
<
Dict
>
all
=
dictRepository
.
findAll
(
condition
(
dictQueryParam
),
PageParam
.
toPageable
(
param
));
List
<
Dict
>
data
=
all
.
get
()
.
map
(
car
->
{
Dict
vo
=
new
Dict
();
BeanUtils
.
copyProperties
(
car
,
vo
);
return
vo
;
})
.
collect
(
Collectors
.
toList
());
PageVo
<
Dict
>
vo
=
PageVo
.
build
(
data
,
all
.
getTotalElements
());
return
Result
.
ok
(
vo
);
}
@Override
public
Result
<
String
>
selectDictLabel
(
String
dictType
,
String
dictValue
)
{
return
Result
.
ok
(
dictRepository
.
findDictLabel
(
dictType
,
dictValue
));
}
@Override
public
Result
<
ArrayList
<
Dict
>>
selectDict
(
String
dictType
)
{
List
<
Dict
>
dictCache1
=
DictUtils
.
getDictCache
(
dictType
);
ArrayList
<
Dict
>
dictCache
=
new
ArrayList
<>();
if
(
dictCache1
!=
null
)
{
dictCache
=
new
ArrayList
<>(
dictCache1
);
}
return
Result
.
ok
(
dictCache
);
}
@Override
public
Result
<
Dict
>
getDictInfo
(
Long
dictCode
)
{
return
Result
.
ok
(
dictRepository
.
getById
(
dictCode
));
}
@Override
public
Result
<
String
>
deleteDictById
(
IdParam
idParam
)
{
Optional
<
Dict
>
optional
=
dictRepository
.
findById
(
idParam
.
getId
());
if
(
optional
.
isEmpty
())
{
return
Result
.
no
(
Status
.
NOT_FOUND
);
}
Dict
entity
=
optional
.
get
();
dictRepository
.
delete
(
entity
);
//刷新缓存
List
<
Dict
>
byDictType
=
dictRepository
.
findByDictType
(
entity
.
getDictType
());
DictUtils
.
setDictCache
(
entity
.
getDictType
(),
byDictType
);
return
Result
.
ok
();
}
@Override
public
Result
<
String
>
saveDictInfo
(
DictParam
dictParam
)
{
if
(
has
(
dictParam
.
getDictLabel
()))
{
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"标签已存在"
);
}
if
(
hasValue
(
dictParam
.
getDictType
(),
dictParam
.
getDictValue
()))
{
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"该类型,字典值已存在"
);
}
Dict
dict
=
new
Dict
();
dict
.
setCreateTime
(
LocalDateTime
.
now
());
BeanUtils
.
copyProperties
(
dictParam
,
dict
);
dictRepository
.
saveAndFlush
(
dict
);
//刷新缓存
List
<
Dict
>
byDictType
=
dictRepository
.
findByDictType
(
dict
.
getDictType
());
DictUtils
.
setDictCache
(
dict
.
getDictType
(),
byDictType
);
return
Result
.
ok
();
}
@Override
public
Result
<
String
>
updateDictInfo
(
DictParam
dictParam
,
IdParam
idParam
)
{
Optional
<
Dict
>
optional
=
dictRepository
.
findById
(
idParam
.
getId
());
if
(
optional
.
isEmpty
())
{
return
Result
.
no
(
Status
.
NOT_FOUND
);
}
Dict
entity
=
optional
.
get
();
if
(!
entity
.
getDictLabel
().
equals
(
dictParam
.
getDictLabel
()))
{
if
(
has
(
dictParam
.
getDictLabel
()))
{
//当修改了字典标签时
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"标签已存在"
);
}
}
if
(!
entity
.
getDictValue
().
equals
(
dictParam
.
getDictValue
())
||
!
entity
.
getDictType
().
equals
(
dictParam
.
getDictType
()))
{
//当修改了字典类型或字典值时
if
(
hasValue
(
dictParam
.
getDictType
(),
dictParam
.
getDictValue
()))
{
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"该类型,字典值已存在"
);
}
}
BeanUtils
.
copyProperties
(
dictParam
,
entity
);
Dict
dict
=
dictRepository
.
saveAndFlush
(
entity
);
List
<
Dict
>
byDictType
=
dictRepository
.
findByDictType
(
dict
.
getDictType
());
DictUtils
.
setDictCache
(
dict
.
getDictType
(),
byDictType
);
return
Result
.
ok
();
}
public
Specification
<
Dict
>
condition
(
DictQueryParam
dictQueryParam
)
{
return
(
root
,
query
,
criteriaBuilder
)
->
{
List
<
Predicate
>
list
=
new
ArrayList
<>();
if
(
StrUtils
.
isNotBlank
(
dictQueryParam
.
getDictType
()))
{
list
.
add
(
criteriaBuilder
.
like
(
root
.
get
(
"dictType"
).
as
(
String
.
class
),
"%"
+
dictQueryParam
.
getDictType
()
+
"%"
));
}
if
(
StrUtils
.
isNotBlank
(
dictQueryParam
.
getDictLabel
()))
{
list
.
add
(
criteriaBuilder
.
like
(
root
.
get
(
"dictLabel"
).
as
(
String
.
class
),
"%"
+
dictQueryParam
.
getDictLabel
()
+
"%"
));
}
Predicate
[]
predicates
=
new
Predicate
[
list
.
size
()];
query
.
where
(
list
.
toArray
(
predicates
));
return
criteriaBuilder
.
and
(
list
.
toArray
(
predicates
));
};
}
@Override
public
boolean
has
(
String
param
)
{
Dict
entity
=
Dict
.
builder
().
dictLabel
(
param
).
build
();
long
count
=
dictRepository
.
count
(
Example
.
of
(
entity
));
return
count
>
0
;
}
@Override
public
boolean
hasValue
(
String
dictType
,
String
dictValue
)
{
Dict
entity
=
Dict
.
builder
().
dictType
(
dictType
).
dictValue
(
dictValue
).
build
();
long
count
=
dictRepository
.
count
(
Example
.
of
(
entity
));
return
count
>
0
;
}
}
app/src/main/java/com/yiring/app/service/dict/impl/DictTypeServiceImpl.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
service
.
dict
.
impl
;
import
com.yiring.app.param.dict.DictTypeParam
;
import
com.yiring.app.param.dict.DictTypeQueryParam
;
import
com.yiring.app.service.dict.DictTypeService
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.common.dict.DictRepository
;
import
com.yiring.common.dict.DictType
;
import
com.yiring.common.dict.DictTypeRepository
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.util.DictUtils
;
import
com.yiring.common.util.StrUtils
;
import
com.yiring.common.vo.PageVo
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.data.domain.Example
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.persistence.criteria.Predicate
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* 字典类型
*
* @author tzl
* 2022/4/14 14:23
*/
@Service
public
class
DictTypeServiceImpl
implements
DictTypeService
{
@Resource
DictTypeRepository
dictTypeRepository
;
@Resource
DictRepository
dictRepository
;
@Override
public
Result
<
PageVo
<
DictType
>>
pageDictTypeInfo
(
DictTypeQueryParam
dictTypeQueryParam
,
PageParam
param
)
{
Page
<
DictType
>
all
=
dictTypeRepository
.
findAll
(
condition
(
dictTypeQueryParam
),
PageParam
.
toPageable
(
param
));
List
<
DictType
>
data
=
all
.
get
()
.
map
(
car
->
{
DictType
vo
=
new
DictType
();
BeanUtils
.
copyProperties
(
car
,
vo
);
return
vo
;
})
.
collect
(
Collectors
.
toList
());
PageVo
<
DictType
>
vo
=
PageVo
.
build
(
data
,
all
.
getTotalElements
());
return
Result
.
ok
(
vo
);
}
@Override
public
Result
<
DictType
>
getDictTypeInfo
(
Long
id
)
{
return
Result
.
ok
(
dictTypeRepository
.
getById
(
id
));
}
@Override
public
Result
<
String
>
delecteById
(
Long
id
)
{
Optional
<
DictType
>
optional
=
dictTypeRepository
.
findById
(
id
);
if
(
optional
.
isEmpty
())
{
return
Result
.
no
(
Status
.
NOT_FOUND
);
}
DictType
entity
=
optional
.
get
();
List
<
Dict
>
byDictType1
=
dictRepository
.
findByDictType
(
entity
.
getDictType
());
if
(
byDictType1
.
size
()
>
0
)
{
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"该类型下有字典数据,无法删除"
);
}
dictTypeRepository
.
delete
(
entity
);
//移除该类型缓存
DictUtils
.
removeDictCache
(
entity
.
getDictType
());
return
Result
.
ok
();
}
@Override
public
Result
<
String
>
saveDictTypeInfo
(
DictTypeParam
dictTypeParam
)
{
if
(
has
(
dictTypeParam
.
getDictType
()))
{
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"字典类型已存在"
);
}
DictType
dictType
=
DictType
.
builder
().
createTime
(
LocalDateTime
.
now
()).
build
();
BeanUtils
.
copyProperties
(
dictTypeParam
,
dictType
);
dictTypeRepository
.
saveAndFlush
(
dictType
);
//添加空缓存
DictUtils
.
setDictCache
(
dictType
.
getDictType
(),
null
);
return
Result
.
ok
();
}
@Override
public
Result
<
String
>
updateDictTypeInfo
(
DictTypeParam
dictTypeParam
,
IdParam
idParam
)
{
Optional
<
DictType
>
optional
=
dictTypeRepository
.
findById
(
idParam
.
getId
());
if
(
optional
.
isEmpty
())
{
return
Result
.
no
(
Status
.
NOT_FOUND
);
}
DictType
dictType
=
optional
.
get
();
if
(!
dictType
.
getDictType
().
equals
(
dictTypeParam
.
getDictType
()))
{
//在修改字典类型时
if
(
has
(
dictTypeParam
.
getDictType
()))
{
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"字典类型已存在"
);
}
//将该字典类型下的字典数据一并修改
dictRepository
.
updateDictType
(
dictTypeParam
.
getDictType
(),
dictType
.
getDictType
());
//移除之前的缓存
DictUtils
.
removeDictCache
(
dictType
.
getDictType
());
}
BeanUtils
.
copyProperties
(
dictTypeParam
,
dictType
);
dictTypeRepository
.
saveAndFlush
(
dictType
);
//查询该字典类型下的字典值数据
List
<
Dict
>
byDictType
=
dictRepository
.
findByDictType
(
dictType
.
getDictType
());
//添加新缓存
DictUtils
.
setDictCache
(
dictType
.
getDictType
(),
byDictType
);
return
Result
.
ok
();
}
@Override
public
boolean
has
(
String
param
)
{
DictType
dictType
=
DictType
.
builder
().
dictType
(
param
).
build
();
return
dictTypeRepository
.
count
(
Example
.
of
(
dictType
))
>
0
;
}
public
Specification
<
DictType
>
condition
(
DictTypeQueryParam
dictTypeQueryParam
)
{
return
(
root
,
query
,
criteriaBuilder
)
->
{
List
<
Predicate
>
list
=
new
ArrayList
<>();
if
(
StrUtils
.
isNotBlank
(
dictTypeQueryParam
.
getDictName
()))
{
list
.
add
(
criteriaBuilder
.
like
(
root
.
get
(
"dictType"
).
as
(
String
.
class
),
"%"
+
dictTypeQueryParam
.
getDictName
()
+
"%"
));
}
Predicate
[]
predicates
=
new
Predicate
[
list
.
size
()];
query
.
where
(
list
.
toArray
(
predicates
));
return
criteriaBuilder
.
and
(
list
.
toArray
(
predicates
));
};
}
}
app/src/main/java/com/yiring/app/web/dict/DictController.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
web
.
dict
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.app.service.dict.DictService
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.app.param.dict.DictParam
;
import
com.yiring.app.param.dict.DictQueryParam
;
import
com.yiring.common.vo.PageVo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
java.util.ArrayList
;
/**
* 字典数据控制器
* @author tzl
* 2022/4/13 17:10
*/
@Slf4j
@Validated
@Api
(
tags
=
"Dict"
)
@RestController
@RequestMapping
(
"/Dict/"
)
public
class
DictController
{
@Resource
DictService
dictService
;
@ApiOperation
(
value
=
"新增字典信息"
)
@PostMapping
(
"saveDictInfo"
)
public
Result
<
String
>
saveDictInfo
(
@Valid
DictParam
dictParam
)
{
return
dictService
.
saveDictInfo
(
dictParam
);
}
@ApiOperation
(
value
=
"修改字典信息"
)
@PostMapping
(
"updateDictInfo"
)
public
Result
<
String
>
updateDictInfo
(
@Valid
DictParam
dictParam
,
@Valid
IdParam
idParam
)
{
return
dictService
.
updateDictInfo
(
dictParam
,
idParam
);
}
@ApiOperation
(
value
=
"删除字典信息"
)
@PostMapping
(
"deleteDictById"
)
public
Result
<
String
>
deleteDictById
(
@Valid
IdParam
idParam
)
{
return
dictService
.
deleteDictById
(
idParam
);
}
@ApiOperation
(
value
=
"查看字典信息(分页)"
)
@GetMapping
(
"pageDictInfo"
)
public
Result
<
PageVo
<
Dict
>>
pageDictInfo
(
@Valid
DictQueryParam
queryParam
,
@Valid
PageParam
param
)
{
return
dictService
.
pageDictInfo
(
queryParam
,
param
);
}
@ApiOperation
(
value
=
"查看字典信息详情"
)
@GetMapping
(
"getDictInfo"
)
public
Result
<
Dict
>
getDictInfo
(
@Valid
IdParam
idParam
)
{
return
dictService
.
getDictInfo
(
idParam
.
getId
());
}
@ApiOperation
(
value
=
"根据类型获取字典信息详情"
)
@ApiImplicitParam
(
value
=
"字典类型"
,
example
=
"user_sex"
,
required
=
true
,
name
=
"dictType"
)
@GetMapping
(
"selectDict"
)
public
Result
<
ArrayList
<
Dict
>>
selectDict
(
String
dictType
)
{
return
dictService
.
selectDict
(
dictType
);
}
}
app/src/main/java/com/yiring/app/web/dict/DictTypeController.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
app
.
web
.
dict
;
import
com.yiring.app.param.dict.DictParam
;
import
com.yiring.app.param.dict.DictQueryParam
;
import
com.yiring.app.param.dict.DictTypeParam
;
import
com.yiring.app.param.dict.DictTypeQueryParam
;
import
com.yiring.app.service.dict.DictService
;
import
com.yiring.app.service.dict.DictTypeService
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.common.dict.DictType
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.vo.PageVo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
java.util.ArrayList
;
/**
* 字典类型控制器
* @author tzl
* 2022/4/14 15:14
*/
@Slf4j
@Validated
@Api
(
tags
=
"DictType"
)
@RestController
@RequestMapping
(
"/DictType/"
)
public
class
DictTypeController
{
@Resource
DictTypeService
dictTypeService
;
@ApiOperation
(
value
=
"新增字典类型信息"
)
@PostMapping
(
"saveDictTypeInfo"
)
public
Result
<
String
>
saveDictTypeInfo
(
@Valid
DictTypeParam
dictTypeParam
)
{
return
dictTypeService
.
saveDictTypeInfo
(
dictTypeParam
);
}
@ApiOperation
(
value
=
"修改字典类型信息"
)
@PostMapping
(
"updateDictTypeInfo"
)
public
Result
<
String
>
updateDictTypeInfo
(
@Valid
DictTypeParam
dictTypeParam
,
@Valid
IdParam
idParam
)
{
return
dictTypeService
.
updateDictTypeInfo
(
dictTypeParam
,
idParam
);
}
@ApiOperation
(
value
=
"删除字典类型信息"
)
@PostMapping
(
"delecteById"
)
public
Result
<
String
>
delecteById
(
@Valid
IdParam
idParam
)
{
return
dictTypeService
.
delecteById
(
idParam
.
getId
());
}
@ApiOperation
(
value
=
"查看字典类型信息(分页)"
)
@GetMapping
(
"pageDictTypeInfo"
)
public
Result
<
PageVo
<
DictType
>>
pageDictInfo
(
@Valid
DictTypeQueryParam
queryParam
,
@Valid
PageParam
param
)
{
return
dictTypeService
.
pageDictTypeInfo
(
queryParam
,
param
);
}
@ApiOperation
(
value
=
"查看字典类型信息详情"
)
@GetMapping
(
"getDictTypeInfo"
)
public
Result
<
DictType
>
getDictTypeInfo
(
@Valid
IdParam
idParam
)
{
return
dictTypeService
.
getDictTypeInfo
(
idParam
.
getId
());
}
}
basic-common/core/build.gradle
浏览文件 @
713143a3
dependencies
{
implementation
project
(
":basic-common:util"
)
//
implementation project(":basic-common:util")
implementation
'org.springframework.boot:spring-boot-starter-aop'
implementation
'org.springframework.boot:spring-boot-starter-web'
...
...
@@ -9,10 +9,8 @@ dependencies {
implementation
"io.swagger:swagger-annotations:${swaggerAnnotationsVersion}"
implementation
"org.hibernate.validator:hibernate-validator:${hibernateValidatorVersion}"
// hutool-extra
implementation
"cn.hutool:hutool-extra:${hutoolVersion}"
implementation
"cn.dev33:sa-token-dao-redis-jackson:${saTokenVersion}"
// fastjson
implementation
"com.alibaba:fastjson:${fastJsonVersion}"
implementation
fileTree
(
dir:
project
.
rootDir
.
getPath
()
+
'\\libs'
,
includes:
[
'*jar'
])
}
basic-common/core/src/main/java/com/yiring/common/core/redis/RedisCache.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
core
.
redis
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.BoundSetOperations
;
import
org.springframework.data.redis.core.HashOperations
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.stereotype.Component
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* redis缓存 工具类
*
* @author tzl
* 2022/4/13 15:36
*/
@Component
public
class
RedisCache
{
@Autowired
public
RedisTemplate
redisTemplate
;
/**
* 缓存基本的对象,Integer、String、实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
*/
public
<
T
>
void
setCacheObject
(
final
String
key
,
final
T
value
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
}
/**
* 缓存基本的对象,Integer、String、实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
* @param timeout 时间
* @param timeUnit 时间颗粒度
*/
public
<
T
>
void
setCacheObject
(
final
String
key
,
final
T
value
,
final
Integer
timeout
,
final
TimeUnit
timeUnit
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
timeout
,
timeUnit
);
}
/**
* 设置有效时间
*
* @param key Redis键
* @param timeout 超时时间
* @return true=设置成功;false=设置失败
*/
public
boolean
expire
(
final
String
key
,
final
long
timeout
)
{
return
expire
(
key
,
timeout
,
TimeUnit
.
SECONDS
);
}
/**
* 设置有效时间
*
* @param key Redis键
* @param timeout 超时时间
* @param unit 时间单位
* @return true=设置成功;false=设置失败
*/
public
boolean
expire
(
final
String
key
,
final
long
timeout
,
final
TimeUnit
unit
)
{
return
Boolean
.
TRUE
.
equals
(
redisTemplate
.
expire
(
key
,
timeout
,
unit
));
}
/**
* 获得缓存的基本对象。
*
* @param key 缓存键值
* @return 缓存键值对应的数据
*/
public
<
T
>
T
getCacheObject
(
final
String
key
)
{
ValueOperations
<
String
,
T
>
operation
=
redisTemplate
.
opsForValue
();
return
operation
.
get
(
key
);
}
/**
* 删除单个对象
*
* @param key
*/
public
boolean
deleteObject
(
final
String
key
)
{
return
Boolean
.
TRUE
.
equals
(
redisTemplate
.
delete
(
key
));
}
/**
* 删除集合对象
*
* @param collection 多个对象
* @return
*/
public
long
deleteObject
(
final
Collection
collection
)
{
return
redisTemplate
.
delete
(
collection
);
}
/**
* 缓存List数据
*
* @param key 缓存的键值
* @param dataList 待缓存的List数据
* @return 缓存的对象
*/
public
<
T
>
long
setCacheList
(
final
String
key
,
final
List
<
T
>
dataList
)
{
Long
count
=
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
dataList
);
return
count
==
null
?
0
:
count
;
}
/**
* 获得缓存的list对象
*
* @param key 缓存的键值
* @return 缓存键值对应的数据
*/
public
<
T
>
List
<
T
>
getCacheList
(
final
String
key
)
{
return
redisTemplate
.
opsForList
().
range
(
key
,
0
,
-
1
);
}
/**
* 缓存Set
*
* @param key 缓存键值
* @param dataSet 缓存的数据
* @return 缓存数据的对象
*/
public
<
T
>
BoundSetOperations
<
String
,
T
>
setCacheSet
(
final
String
key
,
final
Set
<
T
>
dataSet
)
{
BoundSetOperations
<
String
,
T
>
setOperation
=
redisTemplate
.
boundSetOps
(
key
);
for
(
T
t
:
dataSet
)
{
setOperation
.
add
(
t
);
}
return
setOperation
;
}
/**
* 获得缓存的set
*
* @param key String
* @return
*/
public
<
T
>
Set
<
T
>
getCacheSet
(
final
String
key
)
{
return
redisTemplate
.
opsForSet
().
members
(
key
);
}
/**
* 缓存Map
*
* @param key
* @param dataMap
*/
public
<
T
>
void
setCacheMap
(
final
String
key
,
final
Map
<
String
,
T
>
dataMap
)
{
if
(
dataMap
!=
null
)
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
dataMap
);
}
}
/**
* 获得缓存的Map
*
* @param key
* @return
*/
public
<
T
>
Map
<
String
,
T
>
getCacheMap
(
final
String
key
)
{
return
redisTemplate
.
opsForHash
().
entries
(
key
);
}
/**
* 往Hash中存入数据
*
* @param key Redis键
* @param hKey Hash键
* @param value 值
*/
public
<
T
>
void
setCacheMapValue
(
final
String
key
,
final
String
hKey
,
final
T
value
)
{
redisTemplate
.
opsForHash
().
put
(
key
,
hKey
,
value
);
}
/**
* 获取Hash中的数据
*
* @param key Redis键
* @param hKey Hash键
* @return Hash中的对象
*/
public
<
T
>
T
getCacheMapValue
(
final
String
key
,
final
String
hKey
)
{
HashOperations
<
String
,
String
,
T
>
opsForHash
=
redisTemplate
.
opsForHash
();
return
opsForHash
.
get
(
key
,
hKey
);
}
/**
* 删除Hash中的数据
*
* @param key
* @param hKey
*/
public
void
delCacheMapValue
(
final
String
key
,
final
String
hKey
)
{
HashOperations
hashOperations
=
redisTemplate
.
opsForHash
();
hashOperations
.
delete
(
key
,
hKey
);
}
/**
* 获取多个Hash中的数据
*
* @param key Redis键
* @param hKeys Hash键集合
* @return Hash对象集合
*/
public
<
T
>
List
<
T
>
getMultiCacheMapValue
(
final
String
key
,
final
Collection
<
Object
>
hKeys
)
{
return
redisTemplate
.
opsForHash
().
multiGet
(
key
,
hKeys
);
}
/**
* 获得缓存的基本对象列表
*
* @param pattern 字符串前缀
* @return 对象列表
*/
public
Collection
<
String
>
keys
(
final
String
pattern
)
{
return
redisTemplate
.
keys
(
pattern
);
}
}
basic-common/core/src/main/java/com/yiring/common/dict/Dict.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
dict
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotaions.Comment
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.hibernate.snowflake.SnowflakeId
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* 字典表
*
* @author tzl
* 2022/4/13 15:36
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Entity
@Table
(
name
=
"SYS_DICT"
)
@Comment
(
"字典"
)
public
class
Dict
implements
Serializable
{
@Id
@Comment
(
"主键id"
)
@GeneratedValue
(
generator
=
SnowflakeId
.
GENERATOR
)
@GenericGenerator
(
name
=
SnowflakeId
.
GENERATOR
,
strategy
=
SnowflakeId
.
Strategy
.
LONG
)
Long
id
;
@Comment
(
"字典排序"
)
Integer
dictSort
;
@Comment
(
"字典标签"
)
String
dictLabel
;
@Comment
(
"字典键值"
)
String
dictValue
;
@Comment
(
"字典类型"
)
String
dictType
;
@Comment
(
"状态(0正常 1停用)"
)
String
status
;
@Comment
(
"创建时间"
)
LocalDateTime
createTime
;
}
basic-common/core/src/main/java/com/yiring/common/dict/DictRepository.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
dict
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @author tzl
* 2022/4/13 15:32
*/
public
interface
DictRepository
extends
JpaRepository
<
Dict
,
Serializable
>,
JpaSpecificationExecutor
<
Dict
>
{
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType String
* @param dictValue String
* @return 字典标签
*/
@Query
(
"select dictLabel from Dict where dictType = ?1 and dictValue = ?2"
)
String
findDictLabel
(
String
dictType
,
String
dictValue
);
/**
* 根据字典类型查询所有启用的字典数据
*
* @param dictType 字典类型
* @return 字典数据集合
*/
@Query
(
"select d from Dict d where d.dictType = ?1"
)
List
<
Dict
>
findByDictType
(
String
dictType
);
@Modifying
@Transactional
@Query
(
"update Dict set dictType=?1 where dictType=?2"
)
boolean
updateDictType
(
String
param
,
String
dictType
);
}
basic-common/core/src/main/java/com/yiring/common/dict/DictType.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
dict
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
org.hibernate.annotaions.Comment
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.hibernate.snowflake.SnowflakeId
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* @author tzl
* 2022/4/14 14:07
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Entity
@Table
(
name
=
"SYS_DICT_TYPE"
)
@Comment
(
"字典类型"
)
public
class
DictType
implements
Serializable
{
@Id
@Comment
(
"主键id"
)
@GeneratedValue
(
generator
=
SnowflakeId
.
GENERATOR
)
@GenericGenerator
(
name
=
SnowflakeId
.
GENERATOR
,
strategy
=
SnowflakeId
.
Strategy
.
LONG
)
Long
id
;
@Comment
(
"字典名称"
)
String
dictName
;
@Comment
(
"字典类型"
)
String
dictType
;
@Comment
(
"状态(0正常 1停用)"
)
String
status
;
@Comment
(
"创建时间"
)
LocalDateTime
createTime
;
}
basic-common/core/src/main/java/com/yiring/common/dict/DictTypeRepository.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
dict
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Query
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @author tzl
* 2022/4/13 15:32
*/
public
interface
DictTypeRepository
extends
JpaRepository
<
DictType
,
Serializable
>,
JpaSpecificationExecutor
<
DictType
>
{
}
basic-common/util/build.gradle
浏览文件 @
713143a3
dependencies
{
implementation
project
(
":basic-common:core"
)
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.springframework.boot:spring-boot-starter-aop'
// hutool-extra
implementation
"cn.hutool:hutool-extra:${hutoolVersion}"
// fastjson
implementation
"com.alibaba:fastjson:${fastJsonVersion}"
}
basic-common/util/src/main/java/com/yiring/common/annotation/Excel.java
浏览文件 @
713143a3
...
...
@@ -19,116 +19,120 @@ public @interface Excel {
/**
* 导出时在excel中排序
*/
int
sort
()
default
Integer
.
MAX_VALUE
;
public
int
sort
()
default
Integer
.
MAX_VALUE
;
/**
* 导出到Excel中的名字.
*/
String
name
()
default
""
;
public
String
name
()
default
""
;
/**
* 日期格式, 如: yyyy-MM-dd
*/
String
dateFormat
()
default
""
;
public
String
dateFormat
()
default
""
;
/**
* 如果是字典类型,请设置字典的type值 (如: user_sex)
*/
public
String
dictType
()
default
""
;
/**
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/
String
readConverterExp
()
default
""
;
public
String
readConverterExp
()
default
""
;
/**
* 分隔符,读取字符串组内容
*/
String
separator
()
default
","
;
public
String
separator
()
default
","
;
/**
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
*/
int
scale
()
default
-
1
;
public
int
scale
()
default
-
1
;
/**
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
*/
int
roundingMode
()
default
BigDecimal
.
ROUND_HALF_EVEN
;
public
int
roundingMode
()
default
BigDecimal
.
ROUND_HALF_EVEN
;
/**
* 导出类型(0数字 1字符串)
*/
ColumnType
cellType
()
default
ColumnType
.
STRING
;
public
ColumnType
cellType
()
default
ColumnType
.
STRING
;
/**
* 导出时在excel中每个列的高度 单位为字符
*/
double
height
()
default
14
;
public
double
height
()
default
14
;
/**
* 导出时在excel中每个列的宽 单位为字符
*/
double
width
()
default
16
;
public
double
width
()
default
16
;
/**
* 文字后缀,如% 90 变成90%
*/
String
suffix
()
default
""
;
public
String
suffix
()
default
""
;
/**
* 当值为空时,字段的默认值
*/
String
defaultValue
()
default
""
;
public
String
defaultValue
()
default
""
;
/**
* 提示信息
*/
String
prompt
()
default
""
;
public
String
prompt
()
default
""
;
/**
* 设置只能选择不能输入的列内容.
*/
String
[]
combo
()
default
{};
public
String
[]
combo
()
default
{};
/**
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
*/
boolean
isExport
()
default
true
;
public
boolean
isExport
()
default
true
;
/**
* 另一个类中的属性名称,支持多级获取,以小数点隔开
*/
String
targetAttr
()
default
""
;
public
String
targetAttr
()
default
""
;
/**
* 是否自动统计数据,在最后追加一行统计数据总和
*/
boolean
isStatistics
()
default
false
;
public
boolean
isStatistics
()
default
false
;
/**
* 导出字段对齐方式(0:默认;1:靠左;2:居中;3:靠右)
*/
Align
align
()
default
Align
.
AUTO
;
public
Align
align
()
default
Align
.
AUTO
;
/**
* 自定义数据处理器
*/
Class
<?>
handler
()
default
ExcelHandlerAdapter
.
class
;
public
Class
<?>
handler
()
default
ExcelHandlerAdapter
.
class
;
/**
* 自定义数据处理器参数
*/
String
[]
args
()
default
{};
enum
Align
{
AUTO
(
0
),
LEFT
(
1
),
CENTER
(
2
),
RIGHT
(
3
);
public
String
[]
args
()
default
{};
public
enum
Align
{
AUTO
(
0
),
LEFT
(
1
),
CENTER
(
2
),
RIGHT
(
3
);
private
final
int
value
;
Align
(
int
value
)
{
Align
(
int
value
)
{
this
.
value
=
value
;
}
public
int
value
()
{
public
int
value
()
{
return
this
.
value
;
}
}
...
...
@@ -138,34 +142,34 @@ public @interface Excel {
*/
Type
type
()
default
Type
.
ALL
;
enum
Type
{
ALL
(
0
),
EXPORT
(
1
),
IMPORT
(
2
);
public
enum
Type
{
ALL
(
0
),
EXPORT
(
1
),
IMPORT
(
2
);
private
final
int
value
;
Type
(
int
value
)
{
Type
(
int
value
)
{
this
.
value
=
value
;
}
int
value
()
{
public
int
value
()
{
return
this
.
value
;
}
}
enum
ColumnType
{
NUMERIC
(
0
),
STRING
(
1
),
IMAGE
(
2
);
public
enum
ColumnType
{
NUMERIC
(
0
),
STRING
(
1
),
IMAGE
(
2
);
private
final
int
value
;
ColumnType
(
int
value
)
{
ColumnType
(
int
value
)
{
this
.
value
=
value
;
}
int
value
()
{
public
int
value
()
{
return
this
.
value
;
}
}
...
...
basic-common/
core
/src/main/java/com/yiring/common/aspect/RequestAspect.java
→
basic-common/
util
/src/main/java/com/yiring/common/aspect/RequestAspect.java
浏览文件 @
713143a3
File moved
basic-common/util/src/main/java/com/yiring/common/util/DictUtils.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
util
;
import
com.yiring.common.core.redis.RedisCache
;
import
com.yiring.common.dict.Dict
;
import
com.yiring.common.util.spring.SpringUtil
;
import
java.util.Collection
;
import
java.util.List
;
/**
* 字典工具类
*
* @author tzl
*/
public
class
DictUtils
{
/**
* 分隔符
*/
public
static
final
String
SEPARATOR
=
","
;
/**
* 设置字典缓存
*
* @param key 参数键
* @param dictDatas 字典数据列表
*/
public
static
void
setDictCache
(
String
key
,
List
<
Dict
>
dictDatas
)
{
SpringUtil
.
getBean
(
RedisCache
.
class
).
setCacheObject
(
getCacheKey
(
key
),
dictDatas
);
}
/**
* 获取字典缓存
*
* @param key 参数键
* @return dictDatas 字典数据列表
*/
public
static
List
<
Dict
>
getDictCache
(
String
key
)
{
Object
cacheObj
=
SpringUtil
.
getBean
(
RedisCache
.
class
).
getCacheObject
(
getCacheKey
(
key
));
if
(
StrUtils
.
isNotNull
(
cacheObj
))
{
return
StrUtils
.
cast
(
cacheObj
);
}
return
null
;
}
/**
* 根据字典类型和字典值获取字典标签
*
* @param dictType 字典类型
* @param dictValue 字典值
* @return 字典标签
*/
public
static
String
getDictLabel
(
String
dictType
,
String
dictValue
)
{
return
getDictLabel
(
dictType
,
dictValue
,
SEPARATOR
);
}
/**
* 根据字典类型和字典标签获取字典值
*
* @param dictType 字典类型
* @param dictLabel 字典标签
* @return 字典值
*/
public
static
String
getDictValue
(
String
dictType
,
String
dictLabel
)
{
return
getDictValue
(
dictType
,
dictLabel
,
SEPARATOR
);
}
/**
* 根据字典类型和字典值获取字典标签
*
* @param dictType 字典类型
* @param dictValue 字典值
* @param separator 分隔符
* @return 字典标签
*/
public
static
String
getDictLabel
(
String
dictType
,
String
dictValue
,
String
separator
)
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
Dict
>
datas
=
getDictCache
(
dictType
);
if
(
StrUtils
.
containsAny
(
separator
,
dictValue
)
&&
StrUtils
.
isNotEmpty
(
datas
))
{
if
(
datas
!=
null
)
{
for
(
Dict
dict
:
datas
)
{
for
(
String
value
:
dictValue
.
split
(
separator
))
{
if
(
value
.
equals
(
dict
.
getDictValue
()))
{
propertyString
.
append
(
dict
.
getDictLabel
()).
append
(
separator
);
break
;
}
}
}
}
}
else
{
if
(
datas
!=
null
)
{
for
(
Dict
dict
:
datas
)
{
if
(
dictValue
.
equals
(
dict
.
getDictValue
()))
{
return
dict
.
getDictLabel
();
}
}
}
}
return
StrUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
);
}
/**
* 根据字典类型和字典标签获取字典值
*
* @param dictType 字典类型
* @param dictLabel 字典标签
* @param separator 分隔符
* @return 字典值
*/
public
static
String
getDictValue
(
String
dictType
,
String
dictLabel
,
String
separator
)
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
Dict
>
datas
=
getDictCache
(
dictType
);
if
(
StrUtils
.
containsAny
(
separator
,
dictLabel
)
&&
StrUtils
.
isNotEmpty
(
datas
))
{
if
(
datas
!=
null
)
{
for
(
Dict
dict
:
datas
)
{
for
(
String
label
:
dictLabel
.
split
(
separator
))
{
if
(
label
.
equals
(
dict
.
getDictLabel
()))
{
propertyString
.
append
(
dict
.
getDictValue
()).
append
(
separator
);
break
;
}
}
}
}
}
else
{
if
(
datas
!=
null
)
{
for
(
Dict
dict
:
datas
)
{
if
(
dictLabel
.
equals
(
dict
.
getDictLabel
()))
{
return
dict
.
getDictValue
();
}
}
}
}
return
StrUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
);
}
/**
* 删除指定字典缓存
*
* @param key 字典键
*/
public
static
void
removeDictCache
(
String
key
)
{
SpringUtil
.
getBean
(
RedisCache
.
class
).
deleteObject
(
getCacheKey
(
key
));
}
/**
* 清空字典缓存
*/
public
static
void
clearDictCache
()
{
Collection
<
String
>
keys
=
SpringUtil
.
getBean
(
RedisCache
.
class
).
keys
(
"sys_dict:*"
);
SpringUtil
.
getBean
(
RedisCache
.
class
).
deleteObject
(
keys
);
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
public
static
String
getCacheKey
(
String
configKey
)
{
return
"sys_dict:"
+
configKey
;
}
}
basic-common/util/src/main/java/com/yiring/common/util/poi/ExcelUtil.java
→
basic-common/util/src/main/java/com/yiring/common/util/poi/ExcelUtil
s
.java
浏览文件 @
713143a3
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
common
.
util
.
poi
;
import
com.yiring.common.annotation.Excel
;
import
com.yiring.common.annotation.Excel.ColumnType
;
import
com.yiring.common.annotation.Excel.Type
;
import
com.yiring.common.annotation.Excels
;
import
com.yiring.common.text.Convert
;
import
com.yiring.common.util.DictUtils
;
import
com.yiring.common.util.StrUtils
;
import
com.yiring.common.util.date.DateUtils
;
import
com.yiring.common.util.file.FileTypeUtils
;
import
com.yiring.common.util.file.ImageUtils
;
import
com.yiring.common.util.reflect.ReflectUtils
;
import
org.apache.commons.lang3.RegExUtils
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.apache.poi.util.IOUtils
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFClientAnchor
;
import
org.apache.poi.xssf.usermodel.XSSFDataValidation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -20,57 +33,21 @@ import java.math.BigDecimal;
import
java.text.DecimalFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.RegExUtils
;
import
org.apache.poi.ss.usermodel.BorderStyle
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellStyle
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.ClientAnchor
;
import
org.apache.poi.ss.usermodel.DataValidation
;
import
org.apache.poi.ss.usermodel.DataValidationConstraint
;
import
org.apache.poi.ss.usermodel.DataValidationHelper
;
import
org.apache.poi.ss.usermodel.DateUtil
;
import
org.apache.poi.ss.usermodel.Drawing
;
import
org.apache.poi.ss.usermodel.FillPatternType
;
import
org.apache.poi.ss.usermodel.Font
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.VerticalAlignment
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.WorkbookFactory
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.apache.poi.util.IOUtils
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFClientAnchor
;
import
org.apache.poi.xssf.usermodel.XSSFDataValidation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Excel相关处理
*
* @author ruoyi
*/
public
class
ExcelUtil
<
T
>
{
public
class
ExcelUtil
s
<
T
>
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ExcelUtil
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ExcelUtil
s
.
class
);
public
static
final
String
FORMULA_REGEX_STR
=
"=|-|\\+|@"
;
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
/**
* Excel sheet最大行数,默认65536
...
...
@@ -142,7 +119,7 @@ public class ExcelUtil<T> {
*/
public
Class
<
T
>
clazz
;
public
ExcelUtil
(
Class
<
T
>
clazz
)
{
public
ExcelUtil
s
(
Class
<
T
>
clazz
)
{
this
.
clazz
=
clazz
;
}
...
...
@@ -386,7 +363,7 @@ public class ExcelUtil<T> {
public
void
exportExcel
(
HttpServletResponse
response
)
{
try
{
writeSheet
();
//
wb.write(response.getOutputStream());
//
wb.write(response.getOutputStream());
FileOutputStream
fos
=
new
FileOutputStream
(
"D:/a.xls"
);
wb
.
write
(
fos
);
fos
.
close
();
...
...
@@ -633,10 +610,13 @@ public class ExcelUtil<T> {
String
dateFormat
=
attr
.
dateFormat
();
String
readConverterExp
=
attr
.
readConverterExp
();
String
separator
=
attr
.
separator
();
String
dictType
=
attr
.
dictType
();
if
(
StrUtils
.
isNotEmpty
(
dateFormat
)
&&
StrUtils
.
isNotNull
(
value
))
{
cell
.
setCellValue
(
parseDateToStr
(
dateFormat
,
value
));
}
else
if
(
StrUtils
.
isNotEmpty
(
readConverterExp
)
&&
StrUtils
.
isNotNull
(
value
))
{
cell
.
setCellValue
(
convertByExp
(
Convert
.
toStr
(
value
),
readConverterExp
,
separator
));
}
else
if
(
StrUtils
.
isNotEmpty
(
dictType
)
&&
StrUtils
.
isNotNull
(
value
))
{
cell
.
setCellValue
(
convertDictByExp
(
Convert
.
toStr
(
value
),
dictType
,
separator
));
}
else
if
(
value
instanceof
BigDecimal
&&
-
1
!=
attr
.
scale
())
{
cell
.
setCellValue
((((
BigDecimal
)
value
).
setScale
(
attr
.
scale
(),
attr
.
roundingMode
())).
toString
());
}
else
if
(!
attr
.
handler
().
equals
(
ExcelHandlerAdapter
.
class
))
{
...
...
@@ -753,6 +733,30 @@ public class ExcelUtil<T> {
}
/**
* 解析字典值
*
* @param dictValue 字典值
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典标签
*/
public
static
String
convertDictByExp
(
String
dictValue
,
String
dictType
,
String
separator
)
{
return
DictUtils
.
getDictLabel
(
dictType
,
dictValue
,
separator
);
}
/**
* 反向解析值字典值
*
* @param dictLabel 字典标签
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典值
*/
public
static
String
reverseDictByExp
(
String
dictLabel
,
String
dictType
,
String
separator
)
{
return
DictUtils
.
getDictValue
(
dictType
,
dictLabel
,
separator
);
}
/**
* 数据处理器
*
* @param value 数据值
...
...
@@ -762,7 +766,7 @@ public class ExcelUtil<T> {
public
String
dataFormatHandlerAdapter
(
Object
value
,
Excel
excel
)
{
try
{
Object
instance
=
excel
.
handler
().
newInstance
();
Method
formatMethod
=
excel
.
handler
().
getMethod
(
"format"
,
new
Class
[]
{
Object
.
class
,
String
[].
class
});
Method
formatMethod
=
excel
.
handler
().
getMethod
(
"format"
,
new
Class
[]
{
Object
.
class
,
String
[].
class
});
value
=
formatMethod
.
invoke
(
instance
,
value
,
excel
.
args
());
}
catch
(
Exception
e
)
{
log
.
error
(
"不能格式化数据 "
+
excel
.
handler
(),
e
.
getMessage
());
...
...
@@ -781,7 +785,8 @@ public class ExcelUtil<T> {
}
try
{
temp
=
Double
.
valueOf
(
text
);
}
catch
(
NumberFormatException
e
)
{}
}
catch
(
NumberFormatException
e
)
{
}
statistics
.
put
(
index
,
statistics
.
get
(
index
)
+
temp
);
}
}
...
...
@@ -875,7 +880,7 @@ public class ExcelUtil<T> {
Excel
attr
=
field
.
getAnnotation
(
Excel
.
class
);
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
field
.
setAccessible
(
true
);
fields
.
add
(
new
Object
[]
{
field
,
attr
});
fields
.
add
(
new
Object
[]
{
field
,
attr
});
}
}
...
...
@@ -886,7 +891,7 @@ public class ExcelUtil<T> {
for
(
Excel
attr
:
excels
)
{
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
field
.
setAccessible
(
true
);
fields
.
add
(
new
Object
[]
{
field
,
attr
});
fields
.
add
(
new
Object
[]
{
field
,
attr
});
}
}
}
...
...
basic-common/util/src/main/java/com/yiring/common/util/spring/SpringUtil.java
0 → 100644
浏览文件 @
713143a3
package
com
.
yiring
.
common
.
util
.
spring
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
/**
* spring工具类 方便在非spring管理环境中获取bean
*
* @author ruoyi
*/
@Component
public
final
class
SpringUtil
implements
BeanFactoryPostProcessor
,
ApplicationContextAware
{
/** Spring应用上下文环境 */
private
static
ConfigurableListableBeanFactory
beanFactory
;
private
static
ApplicationContext
applicationContext
;
@Override
public
void
postProcessBeanFactory
(
ConfigurableListableBeanFactory
beanFactory
)
throws
BeansException
{
SpringUtil
.
beanFactory
=
beanFactory
;
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
SpringUtil
.
applicationContext
=
applicationContext
;
}
/**
* 获取类型为requiredType的对象
*
* @param clz Class
* @return T
*
*/
public
static
<
T
>
T
getBean
(
Class
<
T
>
clz
)
throws
BeansException
{
return
(
T
)
beanFactory
.
getBean
(
clz
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论