Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
cloud-backend
Commits
1a088265
Commit
1a088265
authored
Sep 15, 2021
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.0.0
parent
230d15ae
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
969 additions
and
10 deletions
+969
-10
sys-server/pom.xml
+14
-1
sys-server/src/main/java/com/zq/system/modules/generator/domain/ColumnInfo.java
+99
-0
sys-server/src/main/java/com/zq/system/modules/generator/domain/GenConfig.java
+80
-0
sys-server/src/main/java/com/zq/system/modules/generator/domain/vo/TableInfo.java
+59
-0
sys-server/src/main/java/com/zq/system/modules/generator/repository/ColumnInfoRepository.java
+36
-0
sys-server/src/main/java/com/zq/system/modules/generator/repository/GenConfigRepository.java
+34
-0
sys-server/src/main/java/com/zq/system/modules/generator/rest/GenConfigController.java
+51
-0
sys-server/src/main/java/com/zq/system/modules/generator/rest/GeneratorController.java
+112
-0
sys-server/src/main/java/com/zq/system/modules/generator/service/GenConfigService.java
+42
-0
sys-server/src/main/java/com/zq/system/modules/generator/service/GeneratorService.java
+105
-0
sys-server/src/main/java/com/zq/system/modules/generator/service/impl/GenConfigServiceImpl.java
+67
-0
sys-server/src/main/java/com/zq/system/modules/generator/service/impl/GeneratorServiceImpl.java
+206
-0
sys-server/src/main/java/com/zq/system/modules/generator/utils/ColUtil.java
+56
-0
sys-server/src/main/java/com/zq/system/modules/generator/utils/GenUtil.java
+0
-0
sys-server/src/main/java/com/zq/system/modules/system/service/impl/DeptServiceImpl.java
+0
-1
sys-server/src/main/java/com/zq/system/modules/system/service/impl/MenuServiceImpl.java
+2
-3
sys-server/src/main/java/com/zq/system/modules/system/service/impl/MonitorServiceImpl.java
+2
-2
sys-server/src/main/java/com/zq/system/modules/system/service/impl/RoleServiceImpl.java
+0
-1
sys-server/src/main/resources/application.yml
+4
-2
No files found.
sys-server/pom.xml
View file @
1a088265
...
...
@@ -17,6 +17,7 @@
<mapstruct.version>
1.3.1.Final
</mapstruct.version>
<alipay.version>
4.9.153.ALL
</alipay.version>
<qiniu.version>
[7.2.0, 7.2.99]
</qiniu.version>
<configuration.version>
1.9
</configuration.version>
</properties>
<dependencies>
...
...
@@ -51,12 +52,24 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<!-- Spring boot websocket -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-websocket
</artifactId>
</dependency>
<!-- generator模块依赖-模板引擎-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-freemarker
</artifactId>
</dependency>
<!-- generator模块依赖- https://mvnrepository.com/artifact/commons-configuration/commons-configuration -->
<dependency>
<groupId>
commons-configuration
</groupId>
<artifactId>
commons-configuration
</artifactId>
<version>
${configuration.version}
</version>
</dependency>
<!--数据库相关-->
<dependency>
<groupId>
mysql
</groupId>
...
...
sys-server/src/main/java/com/zq/system/modules/generator/domain/ColumnInfo.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
domain
;
import
com.zq.system.modules.generator.utils.GenUtil
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
javax.persistence.*
;
import
java.io.Serializable
;
/**
* 列的数据信息
*
* @author Zheng Jie
* @date 2019-01-02
*/
@Getter
@Setter
@Entity
@NoArgsConstructor
@Table
(
name
=
"code_column_config"
)
public
class
ColumnInfo
implements
Serializable
{
@Id
@Column
(
name
=
"column_id"
)
@ApiModelProperty
(
value
=
"ID"
,
hidden
=
true
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
@ApiModelProperty
(
value
=
"表名"
)
private
String
tableName
;
@ApiModelProperty
(
value
=
"数据库字段名称"
)
private
String
columnName
;
@ApiModelProperty
(
value
=
"数据库字段类型"
)
private
String
columnType
;
@ApiModelProperty
(
value
=
"数据库字段键类型"
)
private
String
keyType
;
@ApiModelProperty
(
value
=
"字段额外的参数"
)
private
String
extra
;
@ApiModelProperty
(
value
=
"数据库字段描述"
)
private
String
remark
;
@ApiModelProperty
(
value
=
"是否必填"
)
private
Boolean
notNull
;
@ApiModelProperty
(
value
=
"是否在列表显示"
)
private
Boolean
listShow
;
@ApiModelProperty
(
value
=
"是否表单显示"
)
private
Boolean
formShow
;
@ApiModelProperty
(
value
=
"表单类型"
)
private
String
formType
;
@ApiModelProperty
(
value
=
"查询 1:模糊 2:精确"
)
private
String
queryType
;
@ApiModelProperty
(
value
=
"字典名称"
)
private
String
dictName
;
@ApiModelProperty
(
value
=
"日期注解"
)
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
;
}
}
sys-server/src/main/java/com/zq/system/modules/generator/domain/GenConfig.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
domain
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
/**
* 代码生成配置
*
* @author Zheng Jie
* @date 2019-01-03
*/
@Getter
@Setter
@Entity
@NoArgsConstructor
@Table
(
name
=
"code_gen_config"
)
public
class
GenConfig
implements
Serializable
{
public
GenConfig
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
@Id
@Column
(
name
=
"config_id"
)
@ApiModelProperty
(
value
=
"ID"
,
hidden
=
true
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
@NotBlank
@ApiModelProperty
(
value
=
"表名"
)
private
String
tableName
;
@ApiModelProperty
(
value
=
"接口名称"
)
private
String
apiAlias
;
@NotBlank
@ApiModelProperty
(
value
=
"包路径"
)
private
String
pack
;
@NotBlank
@ApiModelProperty
(
value
=
"模块名"
)
private
String
moduleName
;
@NotBlank
@ApiModelProperty
(
value
=
"前端文件路径"
)
private
String
path
;
@ApiModelProperty
(
value
=
"前端文件路径"
)
private
String
apiPath
;
@ApiModelProperty
(
value
=
"作者"
)
private
String
author
;
@ApiModelProperty
(
value
=
"表前缀"
)
private
String
prefix
;
@ApiModelProperty
(
value
=
"是否覆盖"
)
private
Boolean
cover
=
false
;
}
sys-server/src/main/java/com/zq/system/modules/generator/domain/vo/TableInfo.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
domain
.
vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* 表的数据信息
*
* @author Zheng Jie
* @date 2019-01-02
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
TableInfo
{
/**
* 表名称
*/
private
Object
tableName
;
/**
* 创建日期
*/
private
Object
createTime
;
/**
* 数据库引擎
*/
private
Object
engine
;
/**
* 编码集
*/
private
Object
coding
;
/**
* 备注
*/
private
Object
remark
;
}
sys-server/src/main/java/com/zq/system/modules/generator/repository/ColumnInfoRepository.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
repository
;
import
com.zq.system.modules.generator.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
>
{
/**
* 查询表信息
*
* @param tableName 表格名
* @return 表信息
*/
List
<
ColumnInfo
>
findByTableNameOrderByIdAsc
(
String
tableName
);
}
sys-server/src/main/java/com/zq/system/modules/generator/repository/GenConfigRepository.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
repository
;
import
com.zq.system.modules.generator.domain.GenConfig
;
import
org.springframework.data.jpa.repository.JpaRepository
;
/**
* @author Zheng Jie
* @date 2019-01-14
*/
public
interface
GenConfigRepository
extends
JpaRepository
<
GenConfig
,
Long
>
{
/**
* 查询表配置
*
* @param tableName 表名
* @return /
*/
GenConfig
findByTableName
(
String
tableName
);
}
sys-server/src/main/java/com/zq/system/modules/generator/rest/GenConfigController.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
rest
;
import
com.zq.system.modules.generator.domain.GenConfig
;
import
com.zq.system.modules.generator.service.GenConfigService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
* @author Zheng Jie
* @date 2019-01-14
*/
@RestController
@RequiredArgsConstructor
@RequestMapping
(
"/api/genConfig"
)
@Api
(
tags
=
"系统:代码生成器配置管理"
)
public
class
GenConfigController
{
private
final
GenConfigService
genConfigService
;
@ApiOperation
(
"查询"
)
@GetMapping
(
value
=
"/{tableName}"
)
public
ResponseEntity
<
Object
>
query
(
@PathVariable
String
tableName
)
{
return
new
ResponseEntity
<>(
genConfigService
.
find
(
tableName
),
HttpStatus
.
OK
);
}
@ApiOperation
(
"修改"
)
@PutMapping
public
ResponseEntity
<
Object
>
update
(
@Validated
@RequestBody
GenConfig
genConfig
)
{
return
new
ResponseEntity
<>(
genConfigService
.
update
(
genConfig
.
getTableName
(),
genConfig
),
HttpStatus
.
OK
);
}
}
sys-server/src/main/java/com/zq/system/modules/generator/rest/GeneratorController.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
rest
;
import
com.zq.system.exception.BadRequestException
;
import
com.zq.system.modules.generator.domain.ColumnInfo
;
import
com.zq.system.modules.generator.service.GenConfigService
;
import
com.zq.system.modules.generator.service.GeneratorService
;
import
com.zq.system.utils.PageUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
/**
* @author Zheng Jie
* @date 2019-01-02
*/
@RestController
@RequiredArgsConstructor
@RequestMapping
(
"/api/generator"
)
@Api
(
tags
=
"系统:代码生成管理"
)
public
class
GeneratorController
{
private
final
GeneratorService
generatorService
;
private
final
GenConfigService
genConfigService
;
@Value
(
"${generator.enabled}"
)
private
Boolean
generatorEnabled
;
@ApiOperation
(
"查询数据库数据"
)
@GetMapping
(
value
=
"/tables/all"
)
public
ResponseEntity
<
Object
>
queryTables
()
{
return
new
ResponseEntity
<>(
generatorService
.
getTables
(),
HttpStatus
.
OK
);
}
@ApiOperation
(
"查询数据库数据"
)
@GetMapping
(
value
=
"/tables"
)
public
ResponseEntity
<
Object
>
queryTables
(
@RequestParam
(
defaultValue
=
""
)
String
name
,
@RequestParam
(
defaultValue
=
"0"
)
Integer
page
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
size
)
{
int
[]
startEnd
=
PageUtil
.
transToStartEnd
(
page
,
size
);
return
new
ResponseEntity
<>(
generatorService
.
getTables
(
name
,
startEnd
),
HttpStatus
.
OK
);
}
@ApiOperation
(
"查询字段数据"
)
@GetMapping
(
value
=
"/columns"
)
public
ResponseEntity
<
Object
>
queryColumns
(
@RequestParam
String
tableName
)
{
List
<
ColumnInfo
>
columnInfos
=
generatorService
.
getColumns
(
tableName
);
return
new
ResponseEntity
<>(
PageUtil
.
toPage
(
columnInfos
,
columnInfos
.
size
()),
HttpStatus
.
OK
);
}
@ApiOperation
(
"保存字段数据"
)
@PutMapping
public
ResponseEntity
<
HttpStatus
>
save
(
@RequestBody
List
<
ColumnInfo
>
columnInfos
)
{
generatorService
.
save
(
columnInfos
);
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
@ApiOperation
(
"同步字段数据"
)
@PostMapping
(
value
=
"sync"
)
public
ResponseEntity
<
HttpStatus
>
sync
(
@RequestBody
List
<
String
>
tables
)
{
for
(
String
table
:
tables
)
{
generatorService
.
sync
(
generatorService
.
getColumns
(
table
),
generatorService
.
query
(
table
));
}
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
@ApiOperation
(
"生成代码"
)
@PostMapping
(
value
=
"/{tableName}/{type}"
)
public
ResponseEntity
<
Object
>
generator
(
@PathVariable
String
tableName
,
@PathVariable
Integer
type
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
(!
generatorEnabled
&&
type
==
0
)
{
throw
new
BadRequestException
(
"此环境不允许生成代码,请选择预览或者下载查看!"
);
}
switch
(
type
)
{
// 生成代码
case
0
:
generatorService
.
generator
(
genConfigService
.
find
(
tableName
),
generatorService
.
getColumns
(
tableName
));
break
;
// 预览
case
1
:
return
generatorService
.
preview
(
genConfigService
.
find
(
tableName
),
generatorService
.
getColumns
(
tableName
));
// 打包
case
2
:
generatorService
.
download
(
genConfigService
.
find
(
tableName
),
generatorService
.
getColumns
(
tableName
),
request
,
response
);
break
;
default
:
throw
new
BadRequestException
(
"没有这个选项"
);
}
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
}
sys-server/src/main/java/com/zq/system/modules/generator/service/GenConfigService.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
service
;
import
com.zq.system.modules.generator.domain.GenConfig
;
/**
* @author Zheng Jie
* @date 2019-01-14
*/
public
interface
GenConfigService
{
/**
* 查询表配置
*
* @param tableName 表名
* @return 表配置
*/
GenConfig
find
(
String
tableName
);
/**
* 更新表配置
*
* @param tableName 表名
* @param genConfig 表配置
* @return 表配置
*/
GenConfig
update
(
String
tableName
,
GenConfig
genConfig
);
}
sys-server/src/main/java/com/zq/system/modules/generator/service/GeneratorService.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
service
;
import
com.zq.system.modules.generator.domain.ColumnInfo
;
import
com.zq.system.modules.generator.domain.GenConfig
;
import
org.springframework.http.ResponseEntity
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
/**
* @author Zheng Jie
* @date 2019-01-02
*/
public
interface
GeneratorService
{
/**
* 查询数据库元数据
*
* @param name 表名
* @param startEnd 分页参数
* @return /
*/
Object
getTables
(
String
name
,
int
[]
startEnd
);
/**
* 得到数据表的元数据
*
* @param name 表名
* @return /
*/
List
<
ColumnInfo
>
getColumns
(
String
name
);
/**
* 同步表数据
*
* @param columnInfos /
* @param columnInfoList /
*/
void
sync
(
List
<
ColumnInfo
>
columnInfos
,
List
<
ColumnInfo
>
columnInfoList
);
/**
* 保持数据
*
* @param columnInfos /
*/
void
save
(
List
<
ColumnInfo
>
columnInfos
);
/**
* 获取所有table
*
* @return /
*/
Object
getTables
();
/**
* 代码生成
*
* @param genConfig 配置信息
* @param columns 字段信息
*/
void
generator
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
);
/**
* 预览
*
* @param genConfig 配置信息
* @param columns 字段信息
* @return /
*/
ResponseEntity
<
Object
>
preview
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
);
/**
* 打包下载
*
* @param genConfig 配置信息
* @param columns 字段信息
* @param request /
* @param response /
*/
void
download
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
,
HttpServletRequest
request
,
HttpServletResponse
response
);
/**
* 查询数据库的表字段数据数据
*
* @param table /
* @return /
*/
List
<
ColumnInfo
>
query
(
String
table
);
}
sys-server/src/main/java/com/zq/system/modules/generator/service/impl/GenConfigServiceImpl.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
service
.
impl
;
import
com.zq.system.modules.generator.domain.GenConfig
;
import
com.zq.system.modules.generator.repository.GenConfigRepository
;
import
com.zq.system.modules.generator.service.GenConfigService
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
/**
* @author Zheng Jie
* @date 2019-01-14
*/
@Service
@RequiredArgsConstructor
public
class
GenConfigServiceImpl
implements
GenConfigService
{
private
final
GenConfigRepository
genConfigRepository
;
@Override
public
GenConfig
find
(
String
tableName
)
{
GenConfig
genConfig
=
genConfigRepository
.
findByTableName
(
tableName
);
if
(
genConfig
==
null
)
{
return
new
GenConfig
(
tableName
);
}
return
genConfig
;
}
@Override
public
GenConfig
update
(
String
tableName
,
GenConfig
genConfig
)
{
String
separator
=
File
.
separator
;
String
[]
paths
;
String
symbol
=
"\\"
;
if
(
symbol
.
equals
(
separator
))
{
paths
=
genConfig
.
getPath
().
split
(
"\\\\"
);
}
else
{
paths
=
genConfig
.
getPath
().
split
(
File
.
separator
);
}
StringBuilder
api
=
new
StringBuilder
();
for
(
String
path
:
paths
)
{
api
.
append
(
path
);
api
.
append
(
separator
);
if
(
"src"
.
equals
(
path
))
{
api
.
append
(
"api"
);
break
;
}
}
genConfig
.
setApiPath
(
api
.
toString
());
return
genConfigRepository
.
save
(
genConfig
);
}
}
sys-server/src/main/java/com/zq/system/modules/generator/service/impl/GeneratorServiceImpl.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
service
.
impl
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ZipUtil
;
import
com.zq.system.exception.BadRequestException
;
import
com.zq.system.modules.generator.domain.ColumnInfo
;
import
com.zq.system.modules.generator.domain.GenConfig
;
import
com.zq.system.modules.generator.domain.vo.TableInfo
;
import
com.zq.system.modules.generator.repository.ColumnInfoRepository
;
import
com.zq.system.modules.generator.service.GeneratorService
;
import
com.zq.system.modules.generator.utils.GenUtil
;
import
com.zq.system.utils.FileUtil
;
import
com.zq.system.utils.PageUtil
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.Query
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author Zheng Jie
* @date 2019-01-02
*/
@Service
@RequiredArgsConstructor
public
class
GeneratorServiceImpl
implements
GeneratorService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
GeneratorServiceImpl
.
class
);
@PersistenceContext
private
EntityManager
em
;
private
final
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
public
Object
getTables
(
String
name
,
int
[]
startEnd
)
{
// 使用预编译防止sql注入
String
sql
=
"select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables "
+
"where table_schema = (select database()) "
+
"and table_name like :table order by create_time desc"
;
Query
query
=
em
.
createNativeQuery
(
sql
);
query
.
setFirstResult
(
startEnd
[
0
]);
query
.
setMaxResults
(
startEnd
[
1
]
-
startEnd
[
0
]);
query
.
setParameter
(
"table"
,
StringUtils
.
isNotBlank
(
name
)
?
(
"%"
+
name
+
"%"
)
:
"%%"
);
List
result
=
query
.
getResultList
();
List
<
TableInfo
>
tableInfos
=
new
ArrayList
<>();
for
(
Object
obj
:
result
)
{
Object
[]
arr
=
(
Object
[])
obj
;
tableInfos
.
add
(
new
TableInfo
(
arr
[
0
],
arr
[
1
],
arr
[
2
],
arr
[
3
],
ObjectUtil
.
isNotEmpty
(
arr
[
4
])
?
arr
[
4
]
:
"-"
));
}
String
countSql
=
"select count(1) from information_schema.tables "
+
"where table_schema = (select database()) and table_name like :table"
;
Query
queryCount
=
em
.
createNativeQuery
(
countSql
);
queryCount
.
setParameter
(
"table"
,
StringUtils
.
isNotBlank
(
name
)
?
(
"%"
+
name
+
"%"
)
:
"%%"
);
Object
totalElements
=
queryCount
.
getSingleResult
();
return
PageUtil
.
toPage
(
tableInfos
,
totalElements
);
}
@Override
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
);
}
}
@Override
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
,
tableName
);
List
result
=
query
.
getResultList
();
List
<
ColumnInfo
>
columnInfos
=
new
ArrayList
<>();
for
(
Object
obj
:
result
)
{
Object
[]
arr
=
(
Object
[])
obj
;
columnInfos
.
add
(
new
ColumnInfo
(
tableName
,
arr
[
0
].
toString
(),
"NO"
.
equals
(
arr
[
1
]),
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
columnInfos
;
}
@Override
public
void
sync
(
List
<
ColumnInfo
>
columnInfos
,
List
<
ColumnInfo
>
columnInfoList
)
{
// 第一种情况,数据库类字段改变或者新增字段
for
(
ColumnInfo
columnInfo
:
columnInfoList
)
{
// 根据字段名称查找
List
<
ColumnInfo
>
columns
=
columnInfos
.
stream
().
filter
(
c
->
c
.
getColumnName
().
equals
(
columnInfo
.
getColumnName
())).
collect
(
Collectors
.
toList
());
// 如果能找到,就修改部分可能被字段
if
(
CollectionUtil
.
isNotEmpty
(
columns
))
{
ColumnInfo
column
=
columns
.
get
(
0
);
column
.
setColumnType
(
columnInfo
.
getColumnType
());
column
.
setExtra
(
columnInfo
.
getExtra
());
column
.
setKeyType
(
columnInfo
.
getKeyType
());
if
(
StringUtils
.
isBlank
(
column
.
getRemark
()))
{
column
.
setRemark
(
columnInfo
.
getRemark
());
}
columnInfoRepository
.
save
(
column
);
}
else
{
// 如果找不到,则保存新字段信息
columnInfoRepository
.
save
(
columnInfo
);
}
}
// 第二种情况,数据库字段删除了
for
(
ColumnInfo
columnInfo
:
columnInfos
)
{
// 根据字段名称查找
List
<
ColumnInfo
>
columns
=
columnInfoList
.
stream
().
filter
(
c
->
c
.
getColumnName
().
equals
(
columnInfo
.
getColumnName
())).
collect
(
Collectors
.
toList
());
// 如果找不到,就代表字段被删除了,则需要删除该字段
if
(
CollectionUtil
.
isEmpty
(
columns
))
{
columnInfoRepository
.
delete
(
columnInfo
);
}
}
}
@Override
public
void
save
(
List
<
ColumnInfo
>
columnInfos
)
{
columnInfoRepository
.
saveAll
(
columnInfos
);
}
@Override
public
void
generator
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
)
{
if
(
genConfig
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
"请先配置生成器"
);
}
try
{
GenUtil
.
generatorCode
(
columns
,
genConfig
);
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
BadRequestException
(
"生成失败,请手动处理已生成的文件"
);
}
}
@Override
public
ResponseEntity
<
Object
>
preview
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
)
{
if
(
genConfig
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
"请先配置生成器"
);
}
List
<
Map
<
String
,
Object
>>
genList
=
GenUtil
.
preview
(
columns
,
genConfig
);
return
new
ResponseEntity
<>(
genList
,
HttpStatus
.
OK
);
}
@Override
public
void
download
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
(
genConfig
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
"请先配置生成器"
);
}
try
{
File
file
=
new
File
(
GenUtil
.
download
(
columns
,
genConfig
));
String
zipPath
=
file
.
getPath
()
+
".zip"
;
ZipUtil
.
zip
(
file
.
getPath
(),
zipPath
);
FileUtil
.
downloadFile
(
request
,
response
,
new
File
(
zipPath
),
true
);
}
catch
(
IOException
e
)
{
throw
new
BadRequestException
(
"打包失败"
);
}
}
}
sys-server/src/main/java/com/zq/system/modules/generator/utils/ColUtil.java
0 → 100644
View file @
1a088265
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
zq
.
system
.
modules
.
generator
.
utils
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.ConfigurationException
;
import
org.apache.commons.configuration.PropertiesConfiguration
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* sql字段转java
*
* @author Zheng Jie
* @date 2019-01-03
*/
public
class
ColUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ColUtil
.
class
);
/**
* 转换mysql数据类型为java数据类型
*
* @param type 数据库字段类型
* @return String
*/
static
String
cloToJava
(
String
type
)
{
Configuration
config
=
getConfig
();
assert
config
!=
null
;
return
config
.
getString
(
type
,
"unknowType"
);
}
/**
* 获取配置信息
*/
public
static
PropertiesConfiguration
getConfig
()
{
try
{
return
new
PropertiesConfiguration
(
"generator.properties"
);
}
catch
(
ConfigurationException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
}
sys-server/src/main/java/com/zq/system/modules/generator/utils/GenUtil.java
0 → 100644
View file @
1a088265
This diff is collapsed.
Click to expand it.
sys-server/src/main/java/com/zq/system/modules/system/service/impl/DeptServiceImpl.java
View file @
1a088265
...
...
@@ -61,7 +61,6 @@ public class DeptServiceImpl implements DeptService {
@Override
public
List
<
DeptDto
>
queryAll
(
DeptQueryCriteria
criteria
,
Boolean
isQuery
)
throws
Exception
{
// Sort sort = new Sort(Sort.Direction.ASC, "deptSort");
Sort
sort
=
Sort
.
by
(
Sort
.
Direction
.
ASC
,
"deptSort"
);
String
dataScopeType
=
SecurityUtils
.
getDataScopeType
();
if
(
isQuery
)
{
...
...
sys-server/src/main/java/com/zq/system/modules/system/service/impl/MenuServiceImpl.java
View file @
1a088265
...
...
@@ -17,6 +17,7 @@ package com.zq.system.modules.system.service.impl;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.zq.common.config.redis.RedisUtils
;
import
com.zq.system.exception.BadRequestException
;
import
com.zq.system.exception.EntityExistException
;
import
com.zq.system.modules.system.domain.Menu
;
...
...
@@ -36,7 +37,6 @@ import com.zq.system.utils.CacheKey;
import
com.zq.system.utils.FileUtil
;
import
com.zq.system.utils.QueryHelp
;
import
com.zq.system.utils.ValidationUtil
;
import
com.zq.common.config.redis.RedisUtils
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.cache.annotation.CacheConfig
;
...
...
@@ -67,9 +67,8 @@ public class MenuServiceImpl implements MenuService {
@Override
public
List
<
MenuDto
>
queryAll
(
MenuQueryCriteria
criteria
,
Boolean
isQuery
)
throws
Exception
{
// Sort sort = new Sort(Sort.Direction.ASC, "menuSort");
Sort
sort
=
Sort
.
by
(
Sort
.
Direction
.
ASC
,
"menuSort"
);
if
(
isQuery
)
{
if
(
Boolean
.
TRUE
.
equals
(
isQuery
)
)
{
criteria
.
setPidIsNull
(
true
);
List
<
Field
>
fields
=
QueryHelp
.
getAllFields
(
criteria
.
getClass
(),
new
ArrayList
<>());
for
(
Field
field
:
fields
)
{
...
...
sys-server/src/main/java/com/zq/system/modules/system/service/impl/MonitorServiceImpl.java
View file @
1a088265
...
...
@@ -15,7 +15,7 @@
*/
package
com
.
zq
.
system
.
modules
.
system
.
service
.
impl
;
import
cn.hutool.core.date.BetweenFormater
;
import
cn.hutool.core.date.BetweenFormat
t
er
;
import
cn.hutool.core.date.DateUtil
;
import
com.zq.common.http.HttpRequestUtils
;
import
com.zq.system.modules.system.service.MonitorService
;
...
...
@@ -188,7 +188,7 @@ public class MonitorServiceImpl implements MonitorService {
long
time
=
ManagementFactory
.
getRuntimeMXBean
().
getStartTime
();
Date
date
=
new
Date
(
time
);
// 计算项目运行时间
String
formatBetween
=
DateUtil
.
formatBetween
(
date
,
new
Date
(),
BetweenFormater
.
Level
.
HOUR
);
String
formatBetween
=
DateUtil
.
formatBetween
(
date
,
new
Date
(),
BetweenFormat
t
er
.
Level
.
HOUR
);
// 系统信息
systemInfo
.
put
(
"os"
,
os
.
toString
());
systemInfo
.
put
(
"day"
,
formatBetween
);
...
...
sys-server/src/main/java/com/zq/system/modules/system/service/impl/RoleServiceImpl.java
View file @
1a088265
...
...
@@ -68,7 +68,6 @@ public class RoleServiceImpl implements RoleService {
@Override
public
List
<
RoleDto
>
queryAll
()
{
// Sort sort = new Sort(Sort.Direction.ASC, "level");
Sort
sort
=
Sort
.
by
(
Sort
.
Direction
.
ASC
,
"level"
);
return
roleMapper
.
toDto
(
roleRepository
.
findAll
(
sort
));
}
...
...
sys-server/src/main/resources/application.yml
View file @
1a088265
...
...
@@ -59,11 +59,13 @@ spring:
multi-statement-allow
:
true
#配置 Jpa
jpa
:
properties
:
hibernate
:
ddl-auto
:
none
dialect
:
org.hibernate.dialect.MySQL5InnoDBDialect
open-in-view
:
true
properties
:
hibernate
:
dialect
:
org.hibernate.dialect.MySQL5InnoDBDialect
#七牛云
qiniu
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment