Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
40852235
"vscode:/vscode.git/clone" did not exist on "bb59b315830b8ae4646b6eba783a665400976981"
Commit
40852235
authored
Nov 24, 2019
by
dqjdda
Browse files
Merge branch '2.4dev' into 2.3opt
parents
4681ca6e
776cee4b
Changes
89
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/annotation/Query.java
View file @
40852235
...
...
@@ -50,6 +50,10 @@ public @interface Query {
,
LESS_THAN_NQ
// jie 2019/6/4 包含
,
IN
// 不等于
,
NOT_EQUAL
// between
,
BETWEEN
}
/**
...
...
eladmin-common/src/main/java/me/zhengjie/utils/QueryHelp.java
View file @
40852235
...
...
@@ -106,6 +106,14 @@ public class QueryHelp {
list
.
add
(
getExpression
(
attributeName
,
join
,
root
).
in
((
Collection
<
Long
>)
val
));
}
break
;
case
NOT_EQUAL:
list
.
add
(
cb
.
notEqual
(
getExpression
(
attributeName
,
join
,
root
),
val
));
break
;
case
BETWEEN:
List
<
Object
>
between
=
new
ArrayList
<>((
List
<
Object
>)
val
);
list
.
add
(
cb
.
between
(
getExpression
(
attributeName
,
join
,
root
).
as
((
Class
<?
extends
Comparable
>)
between
.
get
(
0
).
getClass
()),
(
Comparable
)
between
.
get
(
0
),
(
Comparable
)
between
.
get
(
1
)));
break
;
default
:
break
;
}
}
...
...
eladmin-generator/pom.xml
0 → 100644
View file @
40852235
<?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>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<version>
2.3
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
eladmin-generator
</artifactId>
<name>
代码生成模块
</name>
<properties>
<configuration.version>
1.9
</configuration.version>
</properties>
<dependencies>
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-common
</artifactId>
<version>
2.3
</version>
</dependency>
<!--模板引擎-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-freemarker
</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-configuration/commons-configuration -->
<dependency>
<groupId>
commons-configuration
</groupId>
<artifactId>
commons-configuration
</artifactId>
<version>
${configuration.version}
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
eladmin-generator/src/main/java/me/zhengjie/domain/ColumnInfo.java
0 → 100644
View file @
40852235
package
me.zhengjie.domain
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
me.zhengjie.utils.GenUtil
;
import
javax.persistence.*
;
/**
* 列的数据信息
* @author Zheng Jie
* @date 2019-01-02
*/
@Data
@Entity
@NoArgsConstructor
@Table
(
name
=
"column_config"
)
public
class
ColumnInfo
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@Column
(
name
=
"id"
)
private
Long
id
;
private
String
tableName
;
// 数据库字段名称
private
String
columnName
;
// 数据库字段类型
private
String
columnType
;
// 数据库字段键类型
private
String
keyType
;
// 字段额外的参数
private
String
extra
;
// 数据库字段描述
private
String
remark
;
// 必填
private
Boolean
notNull
;
// 是否在列表显示
private
Boolean
listShow
;
// 是否表单显示
private
Boolean
formShow
;
// 表单类型
private
String
formType
;
// 查询 1:模糊 2:精确
private
String
queryType
;
// 字典名称
private
String
dictName
;
// 日期注解
private
String
dateAnnotation
;
public
ColumnInfo
(
String
tableName
,
String
columnName
,
Boolean
notNull
,
String
columnType
,
String
remark
,
String
keyType
,
String
extra
)
{
this
.
tableName
=
tableName
;
this
.
columnName
=
columnName
;
this
.
columnType
=
columnType
;
this
.
keyType
=
keyType
;
this
.
extra
=
extra
;
this
.
notNull
=
notNull
;
if
(
GenUtil
.
PK
.
equalsIgnoreCase
(
keyType
)
&&
GenUtil
.
EXTRA
.
equalsIgnoreCase
(
extra
)){
this
.
notNull
=
false
;
}
this
.
remark
=
remark
;
this
.
listShow
=
true
;
this
.
formShow
=
true
;
}
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
domain/GenConfig.java
→
eladmin-
generator
/src/main/java/me/zhengjie/domain/GenConfig.java
View file @
40852235
package
me.zhengjie.
modules.generator.
domain
;
package
me.zhengjie.domain
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
/**
* 代码生成配置
...
...
@@ -13,20 +12,35 @@ import javax.persistence.Table;
*/
@Data
@Entity
@NoArgsConstructor
@Table
(
name
=
"gen_config"
)
public
class
GenConfig
{
public
GenConfig
(
String
tableName
)
{
this
.
cover
=
false
;
this
.
moduleName
=
"eladmin-system"
;
this
.
tableName
=
tableName
;
}
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@Column
(
name
=
"id"
)
private
Long
id
;
@NotBlank
private
String
tableName
;
// 包路径
@NotBlank
private
String
pack
;
// 模块名
@Column
(
name
=
"module_name"
)
@NotBlank
private
String
moduleName
;
// 前端文件路径
@NotBlank
private
String
path
;
// 前端文件路径
...
...
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
domain/vo/TableInfo.java
→
eladmin-
generator
/src/main/java/me/zhengjie/domain/vo/TableInfo.java
View file @
40852235
package
me.zhengjie.
modules.generator.
domain.vo
;
package
me.zhengjie.domain.vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
...
...
eladmin-generator/src/main/java/me/zhengjie/repository/ColumnInfoRepository.java
0 → 100644
View file @
40852235
package
me.zhengjie.repository
;
import
me.zhengjie.domain.ColumnInfo
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
java.util.List
;
/**
* @author Zheng Jie
* @date 2019-01-14
*/
public
interface
ColumnInfoRepository
extends
JpaRepository
<
ColumnInfo
,
Long
>
{
List
<
ColumnInfo
>
findByTableNameOrderByIdAsc
(
String
tableName
);
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
repository/GenConfigRepository.java
→
eladmin-
generator
/src/main/java/me/zhengjie/repository/GenConfigRepository.java
View file @
40852235
package
me.zhengjie.
modules.generator.
repository
;
package
me.zhengjie.repository
;
import
me.zhengjie.
modules.generator.
domain.GenConfig
;
import
me.zhengjie.domain.GenConfig
;
import
org.springframework.data.jpa.repository.JpaRepository
;
/**
...
...
@@ -8,4 +8,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @date 2019-01-14
*/
public
interface
GenConfigRepository
extends
JpaRepository
<
GenConfig
,
Long
>
{
GenConfig
findByTableName
(
String
tableName
);
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
rest/GenConfigController.java
→
eladmin-
generator
/src/main/java/me/zhengjie/rest/GenConfigController.java
View file @
40852235
package
me.zhengjie.
modules.generator.
rest
;
package
me.zhengjie.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.
modules.generator.
domain.GenConfig
;
import
me.zhengjie.
modules.generator.
service.GenConfigService
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.service.GenConfigService
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -25,14 +25,14 @@ public class GenConfigController {
}
@ApiOperation
(
"查询"
)
@GetMapping
public
ResponseEntity
get
(){
return
new
ResponseEntity
<>(
genConfigService
.
find
(),
HttpStatus
.
OK
);
@GetMapping
(
value
=
"/{tableName}"
)
public
ResponseEntity
get
(
@PathVariable
String
tableName
){
return
new
ResponseEntity
<>(
genConfigService
.
find
(
tableName
),
HttpStatus
.
OK
);
}
@ApiOperation
(
"修改"
)
@PutMapping
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
GenConfig
genConfig
){
return
new
ResponseEntity
<>(
genConfigService
.
update
(
genConfig
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
genConfigService
.
update
(
genConfig
.
getTableName
(),
genConfig
),
HttpStatus
.
OK
);
}
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
rest/GeneratorController.java
→
eladmin-
generator
/src/main/java/me/zhengjie/rest/GeneratorController.java
View file @
40852235
package
me.zhengjie.
modules.generator.
rest
;
package
me.zhengjie.rest
;
import
cn.hutool.core.util.PageUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.domain.ColumnInfo
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.
modules.generator.domain.vo.ColumnInfo
;
import
me.zhengjie.
modules.generator.
service.Gen
Config
Service
;
import
me.zhengjie.
modules.generator.service.GeneratorService
;
import
me.zhengjie.
service.GenConfigService
;
import
me.zhengjie.service.Gen
erator
Service
;
import
me.zhengjie.
utils.PageUtil
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
...
...
@@ -35,7 +34,13 @@ public class GeneratorController {
this
.
genConfigService
=
genConfigService
;
}
@ApiOperation
(
"查询数据库元数据"
)
@ApiOperation
(
"查询数据库数据"
)
@GetMapping
(
value
=
"/tables/all"
)
public
ResponseEntity
getTables
(){
return
new
ResponseEntity
<>(
generatorService
.
getTables
(),
HttpStatus
.
OK
);
}
@ApiOperation
(
"查询数据库数据"
)
@GetMapping
(
value
=
"/tables"
)
public
ResponseEntity
getTables
(
@RequestParam
(
defaultValue
=
""
)
String
name
,
@RequestParam
(
defaultValue
=
"0"
)
Integer
page
,
...
...
@@ -44,19 +49,34 @@ public class GeneratorController {
return
new
ResponseEntity
<>(
generatorService
.
getTables
(
name
,
startEnd
),
HttpStatus
.
OK
);
}
@ApiOperation
(
"查询
表内元
数据"
)
@ApiOperation
(
"查询
字段
数据"
)
@GetMapping
(
value
=
"/columns"
)
public
ResponseEntity
getTables
(
@RequestParam
String
tableName
){
return
new
ResponseEntity
<>(
generatorService
.
getColumns
(
tableName
),
HttpStatus
.
OK
);
List
<
ColumnInfo
>
columnInfos
=
generatorService
.
getColumns
(
tableName
);
// 异步同步表信息
generatorService
.
sync
(
columnInfos
);
return
new
ResponseEntity
<>(
PageUtil
.
toPage
(
columnInfos
,
columnInfos
.
size
()),
HttpStatus
.
OK
);
}
@ApiOperation
(
"保存字段数据"
)
@PutMapping
public
ResponseEntity
save
(
@RequestBody
List
<
ColumnInfo
>
columnInfos
){
generatorService
.
save
(
columnInfos
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@ApiOperation
(
"生成代码"
)
@PostMapping
public
ResponseEntity
generator
(
@
RequestBody
List
<
ColumnInfo
>
columnInfos
,
@RequestParam
String
tableNam
e
){
@PostMapping
(
value
=
"/{tableName}/{type}"
)
public
ResponseEntity
generator
(
@
PathVariable
String
tableName
,
@PathVariable
Integer
typ
e
){
if
(!
generatorEnabled
){
throw
new
BadRequestException
(
"此环境不允许生成代码!"
);
}
generatorService
.
generator
(
columnInfos
,
genConfigService
.
find
(),
tableName
);
switch
(
type
){
// 生成代码
case
0
:
generatorService
.
generator
(
genConfigService
.
find
(
tableName
),
generatorService
.
getColumns
(
tableName
));
break
;
default
:
break
;
}
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
service/GenConfigService.java
→
eladmin-
generator
/src/main/java/me/zhengjie/service/GenConfigService.java
View file @
40852235
package
me.zhengjie.
modules.generator.
service
;
package
me.zhengjie.service
;
import
me.zhengjie.
modules.generator.
domain.GenConfig
;
import
me.zhengjie.domain.GenConfig
;
/**
* @author Zheng Jie
...
...
@@ -8,7 +8,7 @@ import me.zhengjie.modules.generator.domain.GenConfig;
*/
public
interface
GenConfigService
{
GenConfig
find
();
GenConfig
find
(
String
tableName
);
GenConfig
update
(
GenConfig
genConfig
);
GenConfig
update
(
String
tableName
,
GenConfig
genConfig
);
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
service/GeneratorService.java
→
eladmin-
generator
/src/main/java/me/zhengjie/service/GeneratorService.java
View file @
40852235
package
me.zhengjie.modules.generator.service
;
package
me.zhengjie.service
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.ColumnInfo
;
import
org.springframework.scheduling.annotation.Async
;
import
me.zhengjie.modules.generator.domain.GenConfig
;
import
me.zhengjie.modules.generator.domain.vo.ColumnInfo
;
import
java.util.List
;
/**
...
...
@@ -23,13 +25,32 @@ public interface GeneratorService {
* @param name 表名
* @return /
*/
Object
getColumns
(
String
name
);
List
<
ColumnInfo
>
getColumns
(
String
name
);
/**
* 同步表数据
* @param columnInfos /
*/
@Async
void
sync
(
List
<
ColumnInfo
>
columnInfos
);
/**
* 保持数据
* @param columnInfos /
*/
void
save
(
List
<
ColumnInfo
>
columnInfos
);
/**
* 获取所有table
* @return /
*/
Object
getTables
();
/**
*
生成
代码
* @param
columnInfos 表字段数据
* @param
genConfig 代码生成配置
* @
param tableName 表名
* 代码
生成
* @param
genConfig 配置信息
* @param
columns 字段信息
* @
return /
*/
void
generator
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
);
Object
generator
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
);
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
service/impl/GenConfigServiceImpl.java
→
eladmin-
generator
/src/main/java/me/zhengjie/service/impl/GenConfigServiceImpl.java
View file @
40852235
package
me.zhengjie.
modules.generator.
service.impl
;
package
me.zhengjie.service.impl
;
import
me.zhengjie.
modules.generator.
domain.GenConfig
;
import
me.zhengjie.
modules.generator.
repository.GenConfigRepository
;
import
me.zhengjie.
modules.generator.
service.GenConfigService
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.repository.GenConfigRepository
;
import
me.zhengjie.service.GenConfigService
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.Cache
Evic
t
;
import
org.springframework.cache.annotation.Cache
Pu
t
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
import
java.util.Optional
;
/**
* @author Zheng Jie
...
...
@@ -25,16 +24,18 @@ public class GenConfigServiceImpl implements GenConfigService {
}
@Override
@Cacheable
(
key
=
"'1'"
)
public
GenConfig
find
()
{
Optional
<
GenConfig
>
genConfig
=
genConfigRepository
.
findById
(
1L
);
return
genConfig
.
orElseGet
(
GenConfig:
:
new
);
@Cacheable
(
key
=
"#p0"
)
public
GenConfig
find
(
String
tableName
)
{
GenConfig
genConfig
=
genConfigRepository
.
findByTableName
(
tableName
);
if
(
genConfig
==
null
){
return
new
GenConfig
(
tableName
);
}
return
genConfig
;
}
@Override
@CacheEvict
(
allEntries
=
true
)
public
GenConfig
update
(
GenConfig
genConfig
)
{
genConfig
.
setId
(
1L
);
@CachePut
(
key
=
"#p0"
)
public
GenConfig
update
(
String
tableName
,
GenConfig
genConfig
)
{
// 自动设置Api路径,注释掉前需要同步取消前端的注释
String
separator
=
File
.
separator
;
String
[]
paths
;
...
...
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
service/impl/GeneratorServiceImpl.java
→
eladmin-
generator
/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java
View file @
40852235
package
me.zhengjie.
modules.generator.
service.impl
;
package
me.zhengjie.service.impl
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.ColumnInfo
;
import
me.zhengjie.domain.vo.TableInfo
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.generator.domain.GenConfig
;
import
me.zhengjie.modules.generator.domain.vo.ColumnInfo
;
import
me.zhengjie.modules.generator.domain.vo.TableInfo
;
import
me.zhengjie.modules.generator.service.GeneratorService
;
import
me.zhengjie.modules.generator.utils.GenUtil
;
import
me.zhengjie.repository.ColumnInfoRepository
;
import
me.zhengjie.service.GeneratorService
;
import
me.zhengjie.utils.GenUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.StringUtils
;
import
org.springframework.stereotype.Service
;
...
...
@@ -22,13 +24,29 @@ import java.util.List;
* @date 2019-01-02
*/
@Service
@SuppressWarnings
(
"all"
)
public
class
GeneratorServiceImpl
implements
GeneratorService
{
@PersistenceContext
private
EntityManager
em
;
private
final
ColumnInfoRepository
columnInfoRepository
;
public
GeneratorServiceImpl
(
ColumnInfoRepository
columnInfoRepository
)
{
this
.
columnInfoRepository
=
columnInfoRepository
;
}
@Override
public
Object
getTables
()
{
// 使用预编译防止sql注入
String
sql
=
"select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables "
+
"where table_schema = (select database()) "
+
"order by create_time desc"
;
Query
query
=
em
.
createNativeQuery
(
sql
);
return
query
.
getResultList
();
}
@Override
@SuppressWarnings
(
"all"
)
public
Object
getTables
(
String
name
,
int
[]
startEnd
)
{
// 使用预编译防止sql注入
String
sql
=
"select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables "
+
...
...
@@ -50,31 +68,62 @@ public class GeneratorServiceImpl implements GeneratorService {
}
@Override
@SuppressWarnings
(
"all"
)
public
Object
getColumns
(
String
name
)
{
public
List
<
ColumnInfo
>
getColumns
(
String
tableName
)
{
List
<
ColumnInfo
>
columnInfos
=
columnInfoRepository
.
findByTableNameOrderByIdAsc
(
tableName
);
if
(
CollectionUtil
.
isNotEmpty
(
columnInfos
)){
return
columnInfos
;
}
else
{
columnInfos
=
query
(
tableName
);
return
columnInfoRepository
.
saveAll
(
columnInfos
);
}
}
public
List
<
ColumnInfo
>
query
(
String
tableName
){
// 使用预编译防止sql注入
String
sql
=
"select column_name, is_nullable, data_type, column_comment, column_key, extra from information_schema.columns "
+
"where table_name = ? and table_schema = (select database()) order by ordinal_position"
;
Query
query
=
em
.
createNativeQuery
(
sql
);
query
.
setParameter
(
1
,
StringUtils
.
isNotBlank
(
name
)
?
name
:
null
);
query
.
setParameter
(
1
,
tableName
);
List
result
=
query
.
getResultList
();
List
<
ColumnInfo
>
columnInfos
=
new
ArrayList
<>();
for
(
Object
obj
:
result
)
{
Object
[]
arr
=
(
Object
[])
obj
;
columnInfos
.
add
(
new
ColumnInfo
(
arr
[
0
],
arr
[
1
],
arr
[
2
],
arr
[
3
],
arr
[
4
],
arr
[
5
],
null
,
"true"
));
columnInfos
.
add
(
new
ColumnInfo
(
tableName
,
arr
[
0
].
toString
(),
arr
[
1
].
equals
(
"NO"
),
arr
[
2
].
toString
(),
ObjectUtil
.
isNotNull
(
arr
[
3
])
?
arr
[
3
].
toString
()
:
null
,
ObjectUtil
.
isNotNull
(
arr
[
4
])
?
arr
[
4
].
toString
()
:
null
,
ObjectUtil
.
isNotNull
(
arr
[
5
])
?
arr
[
5
].
toString
()
:
null
)
);
}
return
PageUtil
.
toPage
(
columnInfos
,
columnInfos
.
size
());
return
columnInfos
;
}
@Override
public
void
sync
(
List
<
ColumnInfo
>
columnInfos
)
{
}
@Override
public
void
save
(
List
<
ColumnInfo
>
columnInfos
)
{
columnInfoRepository
.
saveAll
(
columnInfos
);
}
@Override
public
void
generator
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
)
{
public
Object
generator
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
)
{
if
(
genConfig
.
getId
()
==
null
){
throw
new
BadRequestException
(
"请先配置生成器"
);
}
try
{
GenUtil
.
generatorCode
(
columnInfos
,
genConfig
,
tableName
);
// 查询是否存在关联实体字段信息
GenUtil
.
generatorCode
(
columns
,
genConfig
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
e
.
printStackTrace
();
throw
new
BadRequestException
(
"生成失败,请手动处理已生成的文件"
);
}
return
null
;
}
}
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
utils/ColUtil.java
→
eladmin-
generator
/src/main/java/me/zhengjie/utils/ColUtil.java
View file @
40852235
package
me.zhengjie.
modules.generator.
utils
;
package
me.zhengjie.utils
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.ConfigurationException
;
import
org.apache.commons.configuration.PropertiesConfiguration
;
import
org.apache.commons.configuration.*
;
/**
* sql字段转java
...
...
eladmin-
tools
/src/main/java/me/zhengjie/
modules/generator/
utils/GenUtil.java
→
eladmin-
generator
/src/main/java/me/zhengjie/utils/GenUtil.java
View file @
40852235
package
me.zhengjie.
modules.generator.
utils
;
package
me.zhengjie.utils
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.extra.template.*
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.modules.generator.domain.GenConfig
;
import
me.zhengjie.modules.generator.domain.vo.ColumnInfo
;
import
me.zhengjie.utils.FileUtil
;
import
me.zhengjie.utils.StringUtils
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.ColumnInfo
;
import
org.springframework.util.ObjectUtils
;
import
java.io.File
;
import
java.io.FileWriter
;
...
...
@@ -30,9 +28,9 @@ public class GenUtil {
private
static
final
String
BIGDECIMAL
=
"BigDecimal"
;
p
rivate
static
final
String
PK
=
"PRI"
;
p
ublic
static
final
String
PK
=
"PRI"
;
p
rivate
static
final
String
EXTRA
=
"auto_increment"
;
p
ublic
static
final
String
EXTRA
=
"auto_increment"
;
/**
* 获取后端代码模板名称
...
...
@@ -63,85 +61,159 @@ public class GenUtil {
return
templateNames
;
}
/**
* 生成代码
* @param columnInfos 表元数据
* @param genConfig 生成代码的参数配置,如包路径,作者
*/
public
static
void
generatorCode
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
)
throws
IOException
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"package"
,
genConfig
.
getPack
());
map
.
put
(
"moduleName"
,
genConfig
.
getModuleName
());
map
.
put
(
"author"
,
genConfig
.
getAuthor
());
map
.
put
(
"date"
,
LocalDate
.
now
().
toString
());
map
.
put
(
"tableName"
,
tableName
);
String
className
=
StringUtils
.
toCapitalizeCamelCase
(
tableName
);
String
changeClassName
=
StringUtils
.
toCamelCase
(
tableName
);
public
static
void
generatorCode
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
)
throws
IOException
{
// 存储模版字段数据
Map
<
String
,
Object
>
genMap
=
new
HashMap
<>();
// 包名称
genMap
.
put
(
"package"
,
genConfig
.
getPack
());
// 模块名称
genMap
.
put
(
"moduleName"
,
genConfig
.
getModuleName
());
// 作者
genMap
.
put
(
"author"
,
genConfig
.
getAuthor
());
// 创建日期
genMap
.
put
(
"date"
,
LocalDate
.
now
().
toString
());
// 表名
genMap
.
put
(
"tableName"
,
genConfig
.
getTableName
());
// 大写开头的类名
String
className
=
StringUtils
.
toCapitalizeCamelCase
(
genConfig
.
getTableName
());
// 小写开头的类名
String
changeClassName
=
StringUtils
.
toCamelCase
(
genConfig
.
getTableName
());
// 判断是否去除表前缀
if
(
StringUtils
.
isNotEmpty
(
genConfig
.
getPrefix
()))
{
className
=
StringUtils
.
toCapitalizeCamelCase
(
StrUtil
.
removePrefix
(
t
ableName
,
genConfig
.
getPrefix
()));
changeClassName
=
StringUtils
.
toCamelCase
(
StrUtil
.
removePrefix
(
t
ableName
,
genConfig
.
getPrefix
()));
className
=
StringUtils
.
toCapitalizeCamelCase
(
StrUtil
.
removePrefix
(
genConfig
.
getT
ableName
()
,
genConfig
.
getPrefix
()));
changeClassName
=
StringUtils
.
toCamelCase
(
StrUtil
.
removePrefix
(
genConfig
.
getT
ableName
()
,
genConfig
.
getPrefix
()));
}
map
.
put
(
"className"
,
className
);
map
.
put
(
"upperCaseClassName"
,
className
.
toUpperCase
());
map
.
put
(
"changeClassName"
,
changeClassName
);
map
.
put
(
"hasTimestamp"
,
false
);
map
.
put
(
"queryHasTimestamp"
,
false
);
map
.
put
(
"queryHasBigDecimal"
,
false
);
map
.
put
(
"hasBigDecimal"
,
false
);
map
.
put
(
"hasQuery"
,
false
);
map
.
put
(
"auto"
,
false
);
// 保存类名
genMap
.
put
(
"className"
,
className
);
// 保存小写开头的类名
genMap
.
put
(
"changeClassName"
,
changeClassName
);
// 存在 Timestamp 字段
genMap
.
put
(
"hasTimestamp"
,
false
);
// 查询类中存在 Timestamp 字段
genMap
.
put
(
"queryHasTimestamp"
,
false
);
// 存在 BigDecimal 字段
genMap
.
put
(
"hasBigDecimal"
,
false
);
// 查询类中存在 BigDecimal 字段
genMap
.
put
(
"queryHasBigDecimal"
,
false
);
// 是否需要创建查询
genMap
.
put
(
"hasQuery"
,
false
);
// 自增主键
genMap
.
put
(
"auto"
,
false
);
// 存在字典
genMap
.
put
(
"hasDict"
,
false
);
// 存在日期注解
genMap
.
put
(
"hasDateAnnotation"
,
false
);
// 保存字段信息
List
<
Map
<
String
,
Object
>>
columns
=
new
ArrayList
<>();
// 保存查询字段的信息
List
<
Map
<
String
,
Object
>>
queryColumns
=
new
ArrayList
<>();
// 存储字典信息
List
<
String
>
dicts
=
new
ArrayList
<>();
// 存储 DateRange 信息
List
<
Map
<
String
,
Object
>>
dateRanges
=
new
ArrayList
<>();
// 存储不为空的字段信息
List
<
Map
<
String
,
Object
>>
isNotNullColumns
=
new
ArrayList
<>();
for
(
ColumnInfo
column
:
columnInfos
)
{
Map
<
String
,
Object
>
listMap
=
new
HashMap
<>();
listMap
.
put
(
"columnComment"
,
column
.
getColumnComment
());
listMap
.
put
(
"columnKey"
,
column
.
getColumnKey
());
String
colType
=
ColUtil
.
cloToJava
(
column
.
getColumnType
().
toString
());
// 字段描述
listMap
.
put
(
"remark"
,
column
.
getRemark
());
// 字段类型
listMap
.
put
(
"columnKey"
,
column
.
getKeyType
());
// 主键类型
String
colType
=
ColUtil
.
cloToJava
(
column
.
getColumnType
());
// 小写开头的字段名
String
changeColumnName
=
StringUtils
.
toCamelCase
(
column
.
getColumnName
().
toString
());
// 大写开头的字段名
String
capitalColumnName
=
StringUtils
.
toCapitalizeCamelCase
(
column
.
getColumnName
().
toString
());
if
(
PK
.
equals
(
column
.
getColumnKey
())){
map
.
put
(
"pkColumnType"
,
colType
);
map
.
put
(
"pkChangeColName"
,
changeColumnName
);
map
.
put
(
"pkCapitalColName"
,
capitalColumnName
);
if
(
PK
.
equals
(
column
.
getKeyType
())){
// 存储主键类型
genMap
.
put
(
"pkColumnType"
,
colType
);
// 存储小写开头的字段名
genMap
.
put
(
"pkChangeColName"
,
changeColumnName
);
// 存储大写开头的字段名
genMap
.
put
(
"pkCapitalColName"
,
capitalColumnName
);
}
// 是否存在 Timestamp 类型的字段
if
(
TIMESTAMP
.
equals
(
colType
)){
m
ap
.
put
(
"hasTimestamp"
,
true
);
genM
ap
.
put
(
"hasTimestamp"
,
true
);
}
// 是否存在 BigDecimal 类型的字段
if
(
BIGDECIMAL
.
equals
(
colType
)){
m
ap
.
put
(
"hasBigDecimal"
,
true
);
genM
ap
.
put
(
"hasBigDecimal"
,
true
);
}
// 主键是否自增
if
(
EXTRA
.
equals
(
column
.
getExtra
())){
map
.
put
(
"auto"
,
true
);
genMap
.
put
(
"auto"
,
true
);
}
// 主键存在字典
if
(
StringUtils
.
isNotBlank
(
column
.
getDictName
())){
genMap
.
put
(
"hasDict"
,
true
);
dicts
.
add
(
column
.
getDictName
());
}
// 存储字段类型
listMap
.
put
(
"columnType"
,
colType
);
// 存储字原始段名称
listMap
.
put
(
"columnName"
,
column
.
getColumnName
());
listMap
.
put
(
"isNullable"
,
column
.
getIsNullable
());
listMap
.
put
(
"columnShow"
,
column
.
getColumnShow
());
// 不为空
listMap
.
put
(
"istNotNull"
,
column
.
getNotNull
());
// 字段列表显示
listMap
.
put
(
"columnShow"
,
column
.
getListShow
());
// 表单显示
listMap
.
put
(
"formShow"
,
column
.
getFormShow
());
// 表单组件类型
listMap
.
put
(
"formType"
,
column
.
getFormType
());
// 小写开头的字段名称
listMap
.
put
(
"changeColumnName"
,
changeColumnName
);
//大写开头的字段名称
listMap
.
put
(
"capitalColumnName"
,
capitalColumnName
);
// 字典名称
listMap
.
put
(
"dictName"
,
column
.
getDictName
());
// 日期注解
listMap
.
put
(
"dateAnnotation"
,
column
.
getDateAnnotation
());
if
(
StringUtils
.
isNotBlank
(
column
.
getDateAnnotation
())){
genMap
.
put
(
"hasDateAnnotation"
,
true
);
}
// 添加非空字段信息
if
(
column
.
getNotNull
()){
isNotNullColumns
.
add
(
listMap
);
}
// 判断是否有查询,如有则把查询的字段set进columnQuery
if
(!
StringUtils
.
isBlank
(
column
.
getColumnQuery
())){
listMap
.
put
(
"columnQuery"
,
column
.
getColumnQuery
());
map
.
put
(
"hasQuery"
,
true
);
if
(!
StringUtils
.
isBlank
(
column
.
getQueryType
())){
// 查询类型
listMap
.
put
(
"queryType"
,
column
.
getQueryType
());
// 是否存在查询
genMap
.
put
(
"hasQuery"
,
true
);
if
(
TIMESTAMP
.
equals
(
colType
)){
map
.
put
(
"queryHasTimestamp"
,
true
);
// 查询中存储 Timestamp 类型
genMap
.
put
(
"queryHasTimestamp"
,
true
);
}
if
(
BIGDECIMAL
.
equals
(
colType
)){
map
.
put
(
"queryHasBigDecimal"
,
true
);
// 查询中存储 BigDecimal 类型
genMap
.
put
(
"queryHasBigDecimal"
,
true
);
}
if
(
"DateRange"
.
equalsIgnoreCase
(
column
.
getQueryType
())){
dateRanges
.
add
(
listMap
);
}
else
{
// 添加到查询列表中
queryColumns
.
add
(
listMap
);
}
queryColumns
.
add
(
listMap
);
}
// 添加到字段列表中
columns
.
add
(
listMap
);
}
map
.
put
(
"columns"
,
columns
);
map
.
put
(
"queryColumns"
,
queryColumns
);
// 保存字段列表
genMap
.
put
(
"columns"
,
columns
);
// 保存查询列表
genMap
.
put
(
"queryColumns"
,
queryColumns
);
// 保存字段列表
genMap
.
put
(
"dicts"
,
dicts
);
// 保存查询列表
genMap
.
put
(
"dateRanges"
,
dateRanges
);
// 保存非空字段信息
genMap
.
put
(
"isNotNullColumns"
,
isNotNullColumns
);
TemplateEngine
engine
=
TemplateUtil
.
createEngine
(
new
TemplateConfig
(
"template"
,
TemplateConfig
.
ResourceMode
.
CLASSPATH
));
// 生成后端代码
List
<
String
>
templates
=
getAdminTemplateNames
();
for
(
String
templateName
:
templates
)
{
...
...
@@ -156,14 +228,14 @@ public class GenUtil {
continue
;
}
// 生成代码
genFile
(
file
,
template
,
m
ap
);
genFile
(
file
,
template
,
genM
ap
);
}
// 生成前端代码
templates
=
getFrontTemplateNames
();
for
(
String
templateName
:
templates
)
{
Template
template
=
engine
.
getTemplate
(
"generator/front/"
+
templateName
+
".ftl"
);
String
filePath
=
getFrontFilePath
(
templateName
,
genConfig
,
m
ap
.
get
(
"changeClassName"
).
toString
());
String
filePath
=
getFrontFilePath
(
templateName
,
genConfig
,
genM
ap
.
get
(
"changeClassName"
).
toString
());
assert
filePath
!=
null
;
File
file
=
new
File
(
filePath
);
...
...
@@ -173,7 +245,7 @@ public class GenUtil {
continue
;
}
// 生成代码
genFile
(
file
,
template
,
m
ap
);
genFile
(
file
,
template
,
genM
ap
);
}
}
...
...
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogQueryCriteria.java
View file @
40852235
...
...
@@ -2,8 +2,8 @@ package me.zhengjie.service.dto;
import
lombok.Data
;
import
me.zhengjie.annotation.Query
;
import
java.sql.Timestamp
;
import
java.util.List
;
/**
* 日志查询类
...
...
@@ -20,9 +20,6 @@ public class LogQueryCriteria {
@Query
private
String
logType
;
@Query
(
type
=
Query
.
Type
.
GREATER_THAN
,
propName
=
"createTime"
)
private
Timestamp
startTime
;
@Query
(
type
=
Query
.
Type
.
LESS_THAN
,
propName
=
"createTime"
)
private
Timestamp
endTime
;
@Query
(
type
=
Query
.
Type
.
BETWEEN
)
private
List
<
Timestamp
>
createTime
;
}
eladmin-system/pom.xml
View file @
40852235
...
...
@@ -17,6 +17,18 @@
</properties>
<dependencies>
<!-- 代码生成模块 -->
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-generator
</artifactId>
<version>
2.3
</version>
<exclusions>
<exclusion>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-common
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- tools 模块包含了 common 和 logging 模块 -->
<dependency>
...
...
eladmin-system/src/main/java/me/zhengjie/AppRun.java
View file @
40852235
...
...
@@ -3,6 +3,9 @@ package me.zhengjie;
import
me.zhengjie.utils.SpringContextHolder
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.servlet.server.ServletWebServerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
...
...
@@ -24,4 +27,11 @@ public class AppRun {
public
SpringContextHolder
springContextHolder
()
{
return
new
SpringContextHolder
();
}
@Bean
public
ServletWebServerFactory
webServerFactory
()
{
TomcatServletWebServerFactory
fa
=
new
TomcatServletWebServerFactory
();
fa
.
addConnectorCustomizers
((
TomcatConnectorCustomizer
)
connector
->
connector
.
setProperty
(
"relaxedQueryChars"
,
"[]{}"
));
return
fa
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java
View file @
40852235
...
...
@@ -54,7 +54,7 @@ public class QuartzJobController {
@Log
(
"导出日志数据"
)
@ApiOperation
(
"导出日志数据"
)
@GetMapping
(
value
=
"/download
/log
"
)
@GetMapping
(
value
=
"/
logs/
download"
)
@PreAuthorize
(
"@el.check('timing:list')"
)
public
void
downloadLog
(
HttpServletResponse
response
,
JobQueryCriteria
criteria
)
throws
IOException
{
quartzJobService
.
downloadLog
(
quartzJobService
.
queryAllLog
(
criteria
),
response
);
...
...
Prev
1
2
3
4
5
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment