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
bf7c1eeb
Commit
bf7c1eeb
authored
Oct 24, 2019
by
dqjdda
Browse files
代码优化完成,去除大量idea警告,代码生成器优化等
parent
e3c3ebb1
Changes
146
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/annotation/Query.java
View file @
bf7c1eeb
...
@@ -13,9 +13,9 @@ import java.lang.annotation.Target;
...
@@ -13,9 +13,9 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
Query
{
public
@interface
Query
{
/
**
Dong ZhaoYang 2017/8/7 基本对象的属性名
*/
/
/
Dong ZhaoYang 2017/8/7 基本对象的属性名
String
propName
()
default
""
;
String
propName
()
default
""
;
/
**
Dong ZhaoYang 2017/8/7 查询方式
*/
/
/
Dong ZhaoYang 2017/8/7 查询方式
Type
type
()
default
Type
.
EQUAL
;
Type
type
()
default
Type
.
EQUAL
;
/**
/**
...
...
eladmin-common/src/main/java/me/zhengjie/redis/FastJsonRedisSerializer.java
View file @
bf7c1eeb
...
@@ -35,7 +35,7 @@ public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
...
@@ -35,7 +35,7 @@ public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
return
null
;
return
null
;
}
}
String
str
=
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
String
str
=
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
return
(
T
)
JSON
.
parseObject
(
str
,
clazz
);
return
JSON
.
parseObject
(
str
,
clazz
);
}
}
}
}
eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerConfig.java
View file @
bf7c1eeb
...
@@ -35,7 +35,7 @@ public class SwaggerConfig {
...
@@ -35,7 +35,7 @@ public class SwaggerConfig {
@Bean
@Bean
public
Docket
createRestApi
()
{
public
Docket
createRestApi
()
{
ParameterBuilder
ticketPar
=
new
ParameterBuilder
();
ParameterBuilder
ticketPar
=
new
ParameterBuilder
();
List
<
Parameter
>
pars
=
new
ArrayList
<
Parameter
>();
List
<
Parameter
>
pars
=
new
ArrayList
<>();
ticketPar
.
name
(
tokenHeader
).
description
(
"token"
)
ticketPar
.
name
(
tokenHeader
).
description
(
"token"
)
.
modelRef
(
new
ModelRef
(
"string"
))
.
modelRef
(
new
ModelRef
(
"string"
))
.
parameterType
(
"header"
)
.
parameterType
(
"header"
)
...
...
eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java
View file @
bf7c1eeb
...
@@ -19,9 +19,6 @@ public class EncryptUtils {
...
@@ -19,9 +19,6 @@ public class EncryptUtils {
/**
/**
* 对称加密
* 对称加密
* @param source
* @return
* @throws Exception
*/
*/
public
static
String
desEncrypt
(
String
source
)
throws
Exception
{
public
static
String
desEncrypt
(
String
source
)
throws
Exception
{
if
(
source
==
null
||
source
.
length
()
==
0
){
if
(
source
==
null
||
source
.
length
()
==
0
){
...
...
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
View file @
bf7c1eeb
...
@@ -11,6 +11,7 @@ import javax.activation.MimetypesFileTypeMap;
...
@@ -11,6 +11,7 @@ import javax.activation.MimetypesFileTypeMap;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.io.*
;
import
java.security.MessageDigest
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -92,7 +93,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
...
@@ -92,7 +93,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
* 文件大小转换
* 文件大小转换
*/
*/
public
static
String
getSize
(
long
size
){
public
static
String
getSize
(
long
size
){
String
resultSize
=
""
;
String
resultSize
;
if
(
size
/
GB
>=
1
)
{
if
(
size
/
GB
>=
1
)
{
//如果当前Byte的值大于等于1GB
//如果当前Byte的值大于等于1GB
resultSize
=
DF
.
format
(
size
/
(
float
)
GB
)
+
"GB "
;
resultSize
=
DF
.
format
(
size
/
(
float
)
GB
)
+
"GB "
;
...
@@ -117,7 +118,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
...
@@ -117,7 +118,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
return
file
;
return
file
;
}
}
OutputStream
os
=
new
FileOutputStream
(
file
);
OutputStream
os
=
new
FileOutputStream
(
file
);
int
bytesRead
=
0
;
int
bytesRead
;
byte
[]
buffer
=
new
byte
[
8192
];
byte
[]
buffer
=
new
byte
[
8192
];
while
((
bytesRead
=
ins
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
while
((
bytesRead
=
ins
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
os
.
write
(
buffer
,
0
,
bytesRead
);
...
@@ -144,7 +145,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
...
@@ -144,7 +145,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
if
(!
dest
.
getParentFile
().
exists
())
{
if
(!
dest
.
getParentFile
().
exists
())
{
dest
.
getParentFile
().
mkdirs
();
dest
.
getParentFile
().
mkdirs
();
}
}
String
d
=
dest
.
getPath
();
file
.
transferTo
(
dest
);
// 文件写入
file
.
transferTo
(
dest
);
// 文件写入
return
dest
;
return
dest
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -155,7 +155,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
...
@@ -155,7 +155,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
public
static
String
fileToBase64
(
File
file
)
throws
Exception
{
public
static
String
fileToBase64
(
File
file
)
throws
Exception
{
FileInputStream
inputFile
=
new
FileInputStream
(
file
);
FileInputStream
inputFile
=
new
FileInputStream
(
file
);
String
base64
=
null
;
String
base64
;
byte
[]
buffer
=
new
byte
[(
int
)
file
.
length
()];
byte
[]
buffer
=
new
byte
[(
int
)
file
.
length
()];
inputFile
.
read
(
buffer
);
inputFile
.
read
(
buffer
);
inputFile
.
close
();
inputFile
.
close
();
...
@@ -210,4 +210,64 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
...
@@ -210,4 +210,64 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
throw
new
BadRequestException
(
"文件超出规定大小"
);
throw
new
BadRequestException
(
"文件超出规定大小"
);
}
}
}
}
/**
* 判断两个文件是否相同
*/
public
static
boolean
check
(
File
file1
,
File
file2
)
{
String
img1Md5
=
getMD5
(
file1
);
String
img2Md5
=
getMD5
(
file2
);
return
img1Md5
.
equals
(
img2Md5
);
}
/**
* 判断两个文件是否相同
*/
public
static
boolean
check
(
String
file1Md5
,
String
file2Md5
)
{
return
file1Md5
.
equals
(
file2Md5
);
}
private
static
byte
[]
getByte
(
File
file
)
{
// 得到文件长度
byte
[]
b
=
new
byte
[(
int
)
file
.
length
()];
try
{
InputStream
in
=
new
FileInputStream
(
file
);
try
{
in
.
read
(
b
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
b
;
}
private
static
String
getMD5
(
byte
[]
bytes
)
{
// 16进制字符
char
[]
hexDigits
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
MessageDigest
mdTemp
=
MessageDigest
.
getInstance
(
"MD5"
);
mdTemp
.
update
(
bytes
);
byte
[]
md
=
mdTemp
.
digest
();
int
j
=
md
.
length
;
char
[]
str
=
new
char
[
j
*
2
];
int
k
=
0
;
// 移位 输出字符串
for
(
byte
byte0
:
md
)
{
str
[
k
++]
=
hexDigits
[
byte0
>>>
4
&
0xf
];
str
[
k
++]
=
hexDigits
[
byte0
&
0xf
];
}
return
new
String
(
str
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
String
getMD5
(
File
file
)
{
return
getMD5
(
getByte
(
file
));
}
}
}
eladmin-common/src/main/java/me/zhengjie/utils/QueryHelp.java
View file @
bf7c1eeb
...
@@ -112,7 +112,8 @@ public class QueryHelp {
...
@@ -112,7 +112,8 @@ public class QueryHelp {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
return
cb
.
and
(
list
.
toArray
(
new
Predicate
[
list
.
size
()]));
int
size
=
list
.
size
();
return
cb
.
and
(
list
.
toArray
(
new
Predicate
[
size
]));
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
@@ -124,8 +125,7 @@ public class QueryHelp {
...
@@ -124,8 +125,7 @@ public class QueryHelp {
}
}
}
}
@SuppressWarnings
(
"unchecked"
)
private
static
boolean
isBlank
(
final
CharSequence
cs
)
{
public
static
boolean
isBlank
(
final
CharSequence
cs
)
{
int
strLen
;
int
strLen
;
if
(
cs
==
null
||
(
strLen
=
cs
.
length
())
==
0
)
{
if
(
cs
==
null
||
(
strLen
=
cs
.
length
())
==
0
)
{
return
true
;
return
true
;
...
@@ -138,7 +138,6 @@ public class QueryHelp {
...
@@ -138,7 +138,6 @@ public class QueryHelp {
return
true
;
return
true
;
}
}
@SuppressWarnings
(
"unchecked"
)
private
static
List
<
Field
>
getAllFields
(
Class
clazz
,
List
<
Field
>
fields
)
{
private
static
List
<
Field
>
getAllFields
(
Class
clazz
,
List
<
Field
>
fields
)
{
if
(
clazz
!=
null
)
{
if
(
clazz
!=
null
)
{
fields
.
addAll
(
Arrays
.
asList
(
clazz
.
getDeclaredFields
()));
fields
.
addAll
(
Arrays
.
asList
(
clazz
.
getDeclaredFields
()));
...
...
eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java
View file @
bf7c1eeb
...
@@ -13,7 +13,7 @@ import org.springframework.security.core.userdetails.UserDetails;
...
@@ -13,7 +13,7 @@ import org.springframework.security.core.userdetails.UserDetails;
public
class
SecurityUtils
{
public
class
SecurityUtils
{
public
static
UserDetails
getUserDetails
()
{
public
static
UserDetails
getUserDetails
()
{
UserDetails
userDetails
=
null
;
UserDetails
userDetails
;
try
{
try
{
userDetails
=
(
UserDetails
)
org
.
springframework
.
security
.
core
.
context
.
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
userDetails
=
(
UserDetails
)
org
.
springframework
.
security
.
core
.
context
.
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java
View file @
bf7c1eeb
...
@@ -7,7 +7,7 @@ import org.springframework.context.ApplicationContext;
...
@@ -7,7 +7,7 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationContextAware
;
/**
/**
* @author
* @author
Jie
* @date 2019-01-07
* @date 2019-01-07
*/
*/
@Slf4j
@Slf4j
...
@@ -15,14 +15,6 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
...
@@ -15,14 +15,6 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
private
static
ApplicationContext
applicationContext
=
null
;
private
static
ApplicationContext
applicationContext
=
null
;
/**
* 取得存储在静态变量中的ApplicationContext.
*/
public
static
ApplicationContext
getApplicationContext
()
{
assertContextInjected
();
return
applicationContext
;
}
/**
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
*/
...
@@ -53,14 +45,14 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
...
@@ -53,14 +45,14 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
/**
/**
* 清除SpringContextHolder中的ApplicationContext为Null.
* 清除SpringContextHolder中的ApplicationContext为Null.
*/
*/
p
ublic
static
void
clearHolder
()
{
p
rivate
static
void
clearHolder
()
{
log
.
debug
(
"清除SpringContextHolder中的ApplicationContext:"
log
.
debug
(
"清除SpringContextHolder中的ApplicationContext:"
+
applicationContext
);
+
applicationContext
);
applicationContext
=
null
;
applicationContext
=
null
;
}
}
@Override
@Override
public
void
destroy
()
throws
Exception
{
public
void
destroy
(){
SpringContextHolder
.
clearHolder
();
SpringContextHolder
.
clearHolder
();
}
}
...
...
eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java
View file @
bf7c1eeb
...
@@ -18,25 +18,6 @@ import java.util.Date;
...
@@ -18,25 +18,6 @@ import java.util.Date;
public
class
StringUtils
extends
org
.
apache
.
commons
.
lang3
.
StringUtils
{
public
class
StringUtils
extends
org
.
apache
.
commons
.
lang3
.
StringUtils
{
private
static
final
char
SEPARATOR
=
'_'
;
private
static
final
char
SEPARATOR
=
'_'
;
private
static
final
String
CHARSET_NAME
=
"UTF-8"
;
/**
* 是否包含字符串
*
* @param str 验证字符串
* @param strs 字符串组
* @return 包含返回true
*/
static
boolean
inString
(
String
str
,
String
...
strs
)
{
if
(
str
!=
null
)
{
for
(
String
s
:
strs
)
{
if
(
str
.
equals
(
trim
(
s
)))
{
return
true
;
}
}
}
return
false
;
}
/**
/**
* 驼峰命名法工具
* 驼峰命名法工具
...
@@ -151,9 +132,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
...
@@ -151,9 +132,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
DbConfig
config
=
new
DbConfig
();
DbConfig
config
=
new
DbConfig
();
File
file
=
FileUtil
.
inputStreamToFile
(
new
ClassPathResource
(
path
).
getStream
(),
name
);
File
file
=
FileUtil
.
inputStreamToFile
(
new
ClassPathResource
(
path
).
getStream
(),
name
);
DbSearcher
searcher
=
new
DbSearcher
(
config
,
file
.
getPath
());
DbSearcher
searcher
=
new
DbSearcher
(
config
,
file
.
getPath
());
Method
method
=
null
;
Method
method
;
method
=
searcher
.
getClass
().
getMethod
(
"btreeSearch"
,
String
.
class
);
method
=
searcher
.
getClass
().
getMethod
(
"btreeSearch"
,
String
.
class
);
DataBlock
dataBlock
=
null
;
DataBlock
dataBlock
;
dataBlock
=
(
DataBlock
)
method
.
invoke
(
searcher
,
ip
);
dataBlock
=
(
DataBlock
)
method
.
invoke
(
searcher
,
ip
);
String
address
=
dataBlock
.
getRegion
().
replace
(
"0|"
,
""
);
String
address
=
dataBlock
.
getRegion
().
replace
(
"0|"
,
""
);
if
(
address
.
charAt
(
address
.
length
()-
1
)
==
'|'
){
if
(
address
.
charAt
(
address
.
length
()-
1
)
==
'|'
){
...
...
eladmin-common/src/main/java/me/zhengjie/utils/TranslatorUtil.java
View file @
bf7c1eeb
...
@@ -36,7 +36,7 @@ public class TranslatorUtil {
...
@@ -36,7 +36,7 @@ public class TranslatorUtil {
}
}
}
}
private
static
String
parseResult
(
String
inputJson
)
throws
Exception
{
private
static
String
parseResult
(
String
inputJson
){
JSONArray
jsonArray2
=
(
JSONArray
)
new
JSONArray
(
inputJson
).
get
(
0
);
JSONArray
jsonArray2
=
(
JSONArray
)
new
JSONArray
(
inputJson
).
get
(
0
);
StringBuilder
result
=
new
StringBuilder
();
StringBuilder
result
=
new
StringBuilder
();
for
(
Object
o
:
jsonArray2
)
{
for
(
Object
o
:
jsonArray2
)
{
...
...
eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java
View file @
bf7c1eeb
package
me.zhengjie.utils
;
package
me.zhengjie.utils
;
import
cn.hutool.core.util.ObjectUtil
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
import
java.util.Optional
;
/**
/**
* 验证工具
* 验证工具
...
@@ -13,11 +13,9 @@ public class ValidationUtil{
...
@@ -13,11 +13,9 @@ public class ValidationUtil{
/**
/**
* 验证空
* 验证空
*/
*/
public
static
void
isNull
(
Optional
optional
,
String
entity
,
String
parameter
,
Object
value
){
public
static
void
isNull
(
Object
obj
,
String
entity
,
String
parameter
,
Object
value
){
if
(!
optional
.
isPresent
()){
if
(
ObjectUtil
.
isNull
(
obj
)){
String
msg
=
entity
String
msg
=
entity
+
" 不存在: "
+
parameter
+
" is "
+
value
;
+
" 不存在 "
+
"{ "
+
parameter
+
":"
+
value
.
toString
()
+
" }"
;
throw
new
BadRequestException
(
msg
);
throw
new
BadRequestException
(
msg
);
}
}
}
}
...
...
eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java
View file @
bf7c1eeb
...
@@ -11,12 +11,6 @@ import static org.junit.Assert.*;
...
@@ -11,12 +11,6 @@ import static org.junit.Assert.*;
public
class
StringUtilsTest
{
public
class
StringUtilsTest
{
@Test
public
void
testInString
()
{
assertTrue
(
inString
(
"?"
,
"?"
));
assertFalse
(
inString
(
"?"
,
new
String
[]{}));
}
@Test
@Test
public
void
testToCamelCase
()
{
public
void
testToCamelCase
()
{
assertNull
(
toCamelCase
(
null
));
assertNull
(
toCamelCase
(
null
));
...
...
eladmin-generator/src/main/java/me/zhengjie/domain/GenConfig.java
View file @
bf7c1eeb
...
@@ -16,26 +16,26 @@ public class GenConfig {
...
@@ -16,26 +16,26 @@ public class GenConfig {
@Id
@Id
private
Long
id
;
private
Long
id
;
/
**
包路径
**/
/
/
包路径
private
String
pack
;
private
String
pack
;
/
**
模块名
**/
/
/
模块名
@Column
(
name
=
"module_name"
)
@Column
(
name
=
"module_name"
)
private
String
moduleName
;
private
String
moduleName
;
/
**
前端文件路径
**/
/
/
前端文件路径
private
String
path
;
private
String
path
;
/
**
前端文件路径
**/
/
/
前端文件路径
@Column
(
name
=
"api_path"
)
@Column
(
name
=
"api_path"
)
private
String
apiPath
;
private
String
apiPath
;
/
**
作者
**/
/
/
作者
private
String
author
;
private
String
author
;
/
**
表前缀
**/
/
/
表前缀
private
String
prefix
;
private
String
prefix
;
/
**
是否覆盖
**/
/
/
是否覆盖
private
Boolean
cover
;
private
Boolean
cover
;
}
}
eladmin-generator/src/main/java/me/zhengjie/domain/vo/ColumnInfo.java
View file @
bf7c1eeb
...
@@ -14,27 +14,27 @@ import lombok.NoArgsConstructor;
...
@@ -14,27 +14,27 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@NoArgsConstructor
public
class
ColumnInfo
{
public
class
ColumnInfo
{
/
**
数据库字段名称
**/
/
/
数据库字段名称
private
Object
columnName
;
private
Object
columnName
;
/
**
允许空值
**/
/
/
允许空值
private
Object
isNullable
;
private
Object
isNullable
;
/
**
数据库字段类型
**/
/
/
数据库字段类型
private
Object
columnType
;
private
Object
columnType
;
/
**
数据库字段注释
**/
/
/
数据库字段注释
private
Object
columnComment
;
private
Object
columnComment
;
/
**
数据库字段键类型
**/
/
/
数据库字段键类型
private
Object
columnKey
;
private
Object
columnKey
;
/
**
额外的参数
**/
/
/
额外的参数
private
Object
extra
;
private
Object
extra
;
/
**
查询 1:模糊 2:精确
**/
/
/
查询 1:模糊 2:精确
private
String
columnQuery
;
private
String
columnQuery
;
/
**
是否在列表显示
**/
/
/
是否在列表显示
private
String
columnShow
;
private
String
columnShow
;
}
}
eladmin-generator/src/main/java/me/zhengjie/domain/vo/TableInfo.java
View file @
bf7c1eeb
...
@@ -14,10 +14,10 @@ import lombok.NoArgsConstructor;
...
@@ -14,10 +14,10 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@NoArgsConstructor
public
class
TableInfo
{
public
class
TableInfo
{
/
**
表名称
**/
/
/
表名称
private
Object
tableName
;
private
Object
tableName
;
/
**
创建日期
**/
/
/
创建日期
private
Object
createTime
;
private
Object
createTime
;
// 数据库引擎
// 数据库引擎
...
...
eladmin-generator/src/main/java/me/zhengjie/rest/GenConfigController.java
View file @
bf7c1eeb
package
me.zhengjie.rest
;
package
me.zhengjie.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.service.GenConfigService
;
import
me.zhengjie.service.GenConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
...
@@ -13,23 +14,25 @@ import org.springframework.web.bind.annotation.*;
...
@@ -13,23 +14,25 @@ import org.springframework.web.bind.annotation.*;
* @date 2019-01-14
* @date 2019-01-14
*/
*/
@RestController
@RestController
@RequestMapping
(
"api"
)
@RequestMapping
(
"/api/genConfig"
)
@Api
(
tags
=
"系统:代码生成器配置管理"
)
public
class
GenConfigController
{
public
class
GenConfigController
{
@Autowired
private
final
GenConfigService
genConfigService
;
private
GenConfigService
genConfigService
;
/**
public
GenConfigController
(
GenConfigService
genConfigService
)
{
* 查询生成器配置
this
.
genConfigService
=
genConfigService
;
* @return
}
*/
@GetMapping
(
value
=
"/genConfig"
)
@ApiOperation
(
"查询"
)
@GetMapping
public
ResponseEntity
get
(){
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
genConfigService
.
find
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
genConfigService
.
find
(),
HttpStatus
.
OK
);
}
}
@PutMapping
(
value
=
"/genConfig"
)
@ApiOperation
(
"修改"
)
@PutMapping
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
GenConfig
genConfig
){
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
GenConfig
genConfig
){
return
new
ResponseEntity
(
genConfigService
.
update
(
genConfig
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
genConfigService
.
update
(
genConfig
),
HttpStatus
.
OK
);
}
}
}
}
eladmin-generator/src/main/java/me/zhengjie/rest/GeneratorController.java
View file @
bf7c1eeb
package
me.zhengjie.rest
;
package
me.zhengjie.rest
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.PageUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.domain.vo.ColumnInfo
;
import
me.zhengjie.domain.vo.ColumnInfo
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.service.GenConfigService
;
import
me.zhengjie.service.GenConfigService
;
import
me.zhengjie.service.GeneratorService
;
import
me.zhengjie.service.GeneratorService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
...
@@ -17,49 +18,39 @@ import java.util.List;
...
@@ -17,49 +18,39 @@ import java.util.List;
* @date 2019-01-02
* @date 2019-01-02
*/
*/
@RestController
@RestController
@RequestMapping
(
"api"
)
@RequestMapping
(
"/api/generator"
)
@Api
(
tags
=
"系统:代码生成管理"
)
public
class
GeneratorController
{
public
class
GeneratorController
{
@Autowired
private
final
GeneratorService
generatorService
;
private
GeneratorService
generatorService
;
@Autowired
private
final
GenConfigService
genConfigService
;
private
GenConfigService
genConfigService
;
@Value
(
"${generator.enabled}"
)
@Value
(
"${generator.enabled}"
)
private
Boolean
generatorEnabled
;
private
Boolean
generatorEnabled
;
/**
public
GeneratorController
(
GeneratorService
generatorService
,
GenConfigService
genConfigService
)
{
* 查询数据库元数据
this
.
generatorService
=
generatorService
;
* @param name
this
.
genConfigService
=
genConfigService
;
* @param page
}
* @param size
* @return
@ApiOperation
(
"查询数据库元数据"
)
*/
@GetMapping
(
value
=
"/tables"
)
@GetMapping
(
value
=
"/generator/tables"
)
public
ResponseEntity
getTables
(
@RequestParam
(
defaultValue
=
""
)
String
name
,
public
ResponseEntity
getTables
(
@RequestParam
(
defaultValue
=
""
)
String
name
,
@RequestParam
(
defaultValue
=
"0"
)
Integer
page
,
@RequestParam
(
defaultValue
=
"0"
)
Integer
page
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
size
){
@RequestParam
(
defaultValue
=
"10"
)
Integer
size
){
int
[]
startEnd
=
PageUtil
.
transToStartEnd
(
page
+
1
,
size
);
int
[]
startEnd
=
PageUtil
.
transToStartEnd
(
page
+
1
,
size
);
return
new
ResponseEntity
(
generatorService
.
getTables
(
name
,
startEnd
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
generatorService
.
getTables
(
name
,
startEnd
),
HttpStatus
.
OK
);
}
}
/**
@ApiOperation
(
"查询表内元数据"
)
* 查询表内元数据
@GetMapping
(
value
=
"/columns"
)
* @param tableName
* @return
*/
@GetMapping
(
value
=
"/generator/columns"
)
public
ResponseEntity
getTables
(
@RequestParam
String
tableName
){
public
ResponseEntity
getTables
(
@RequestParam
String
tableName
){
return
new
ResponseEntity
(
generatorService
.
getColumns
(
tableName
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
generatorService
.
getColumns
(
tableName
),
HttpStatus
.
OK
);
}
}
/**
@ApiOperation
(
"生成代码"
)
* 生成代码
@PostMapping
* @param columnInfos
* @return
*/
@PostMapping
(
value
=
"/generator"
)
public
ResponseEntity
generator
(
@RequestBody
List
<
ColumnInfo
>
columnInfos
,
@RequestParam
String
tableName
){
public
ResponseEntity
generator
(
@RequestBody
List
<
ColumnInfo
>
columnInfos
,
@RequestParam
String
tableName
){
if
(!
generatorEnabled
){
if
(!
generatorEnabled
){
throw
new
BadRequestException
(
"此环境不允许生成代码!"
);
throw
new
BadRequestException
(
"此环境不允许生成代码!"
);
...
...
eladmin-generator/src/main/java/me/zhengjie/service/GenConfigService.java
View file @
bf7c1eeb
...
@@ -10,21 +10,9 @@ import org.springframework.cache.annotation.Cacheable;
...
@@ -10,21 +10,9 @@ import org.springframework.cache.annotation.Cacheable;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-01-14
* @date 2019-01-14
*/
*/
@CacheConfig
(
cacheNames
=
"genConfig"
)
public
interface
GenConfigService
{
public
interface
GenConfigService
{
/**
* find
* @return
*/
@Cacheable
(
key
=
"'1'"
)
GenConfig
find
();
GenConfig
find
();
/**
* update
* @param genConfig
* @return
*/
@CacheEvict
(
allEntries
=
true
)
GenConfig
update
(
GenConfig
genConfig
);
GenConfig
update
(
GenConfig
genConfig
);
}
}
eladmin-generator/src/main/java/me/zhengjie/service/GeneratorService.java
View file @
bf7c1eeb
...
@@ -12,24 +12,24 @@ public interface GeneratorService {
...
@@ -12,24 +12,24 @@ public interface GeneratorService {
/**
/**
* 查询数据库元数据
* 查询数据库元数据
* @param name
* @param name
表名
* @param startEnd
* @param startEnd
分页参数
* @return
* @return
/
*/
*/
Object
getTables
(
String
name
,
int
[]
startEnd
);
Object
getTables
(
String
name
,
int
[]
startEnd
);
/**
/**
* 得到数据表的元数据
* 得到数据表的元数据
* @param name
* @param name
表名
* @return
* @return
/
*/
*/
Object
getColumns
(
String
name
);
Object
getColumns
(
String
name
);
/**
/**
* 生成代码
* 生成代码
* @param columnInfos
* @param columnInfos
表字段数据
* @param genConfig
* @param genConfig
代码生成配置
* @param tableName
* @param tableName
表名
*/
*/
void
generator
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
);
void
generator
(
List
<
ColumnInfo
>
columnInfos
,
GenConfig
genConfig
,
String
tableName
);
}
}
eladmin-generator/src/main/java/me/zhengjie/service/impl/GenConfigServiceImpl.java
View file @
bf7c1eeb
...
@@ -3,9 +3,10 @@ package me.zhengjie.service.impl;
...
@@ -3,9 +3,10 @@ package me.zhengjie.service.impl;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.repository.GenConfigRepository
;
import
me.zhengjie.repository.GenConfigRepository
;
import
me.zhengjie.service.GenConfigService
;
import
me.zhengjie.service.GenConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
import
java.io.File
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -14,35 +15,37 @@ import java.util.Optional;
...
@@ -14,35 +15,37 @@ import java.util.Optional;
* @date 2019-01-14
* @date 2019-01-14
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"genConfig"
)
public
class
GenConfigServiceImpl
implements
GenConfigService
{
public
class
GenConfigServiceImpl
implements
GenConfigService
{
@Autowired
private
final
GenConfigRepository
genConfigRepository
;
private
GenConfigRepository
genConfigRepository
;
public
GenConfigServiceImpl
(
GenConfigRepository
genConfigRepository
)
{
this
.
genConfigRepository
=
genConfigRepository
;
}
@Override
@Override
@Cacheable
(
key
=
"'1'"
)
public
GenConfig
find
()
{
public
GenConfig
find
()
{
Optional
<
GenConfig
>
genConfig
=
genConfigRepository
.
findById
(
1L
);
Optional
<
GenConfig
>
genConfig
=
genConfigRepository
.
findById
(
1L
);
if
(
genConfig
.
isPresent
()){
return
genConfig
.
orElseGet
(
GenConfig:
:
new
);
return
genConfig
.
get
();
}
else
{
return
new
GenConfig
();
}
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
public
GenConfig
update
(
GenConfig
genConfig
)
{
public
GenConfig
update
(
GenConfig
genConfig
)
{
genConfig
.
setId
(
1L
);
genConfig
.
setId
(
1L
);
// 自动设置Api路径,注释掉前需要同步取消前端的注释
// 自动设置Api路径,注释掉前需要同步取消前端的注释
String
separator
=
File
.
separator
;
String
separator
=
File
.
separator
;
String
[]
paths
=
null
;
String
[]
paths
;
if
(
separator
.
equals
(
"\\"
))
{
if
(
separator
.
equals
(
"\\"
))
{
paths
=
genConfig
.
getPath
().
split
(
"\\\\"
);
paths
=
genConfig
.
getPath
().
split
(
"\\\\"
);
}
else
paths
=
genConfig
.
getPath
().
split
(
File
.
separator
);
}
else
paths
=
genConfig
.
getPath
().
split
(
File
.
separator
);
StringBu
ff
er
api
=
new
StringBu
ff
er
();
StringBu
ild
er
api
=
new
StringBu
ild
er
();
for
(
int
i
=
0
;
i
<
paths
.
length
;
i
++
)
{
for
(
String
path
:
paths
)
{
api
.
append
(
path
s
[
i
]
);
api
.
append
(
path
);
api
.
append
(
separator
);
api
.
append
(
separator
);
if
(
path
s
[
i
]
.
equals
(
"src"
)){
if
(
path
.
equals
(
"src"
))
{
api
.
append
(
"api"
);
api
.
append
(
"api"
);
break
;
break
;
}
}
...
...
Prev
1
2
3
4
5
…
8
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