Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
datax-cloud
Commits
8e19e6f9
Commit
8e19e6f9
authored
Nov 27, 2019
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
04cdf60d
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1036 additions
and
56 deletions
+1036
-56
AuthenticationFailureEventListener.java
...tax/auth/listener/AuthenticationFailureEventListener.java
+16
-0
AuthenticationSuccessEventListener.java
...tax/auth/listener/AuthenticationSuccessEventListener.java
+18
-0
DataUserDetailService.java
...ain/java/cn/datax/auth/service/DataUserDetailService.java
+0
-1
DataOauthException.java
...ain/java/cn/datax/auth/translator/DataOauthException.java
+4
-0
DataWebResponseExceptionTranslator.java
...x/auth/translator/DataWebResponseExceptionTranslator.java
+7
-7
RedisConfig.java
...c/main/java/cn/datax/common/redis/config/RedisConfig.java
+12
-0
RedisService.java
...main/java/cn/datax/common/redis/service/RedisService.java
+556
-0
LoginController.java
...a/cn/datax/service/system/controller/LoginController.java
+0
-43
spy.properties
...e-parent/system-service/src/main/resources/spy.properties
+5
-0
CodeGenerator.java
.../main/java/cn/datax/tool/codegen/utils/CodeGenerator.java
+4
-5
controller.java.vm
...l-codegen/src/main/resources/templates/controller.java.vm
+42
-0
entity.java.vm
...-tool-codegen/src/main/resources/templates/entity.java.vm
+153
-0
entity.kt.vm
...ax-tool-codegen/src/main/resources/templates/entity.kt.vm
+114
-0
mapper.java.vm
...-tool-codegen/src/main/resources/templates/mapper.java.vm
+20
-0
mapper.xml.vm
...x-tool-codegen/src/main/resources/templates/mapper.xml.vm
+39
-0
service.java.vm
...tool-codegen/src/main/resources/templates/service.java.vm
+20
-0
serviceImpl.java.vm
...-codegen/src/main/resources/templates/serviceImpl.java.vm
+26
-0
No files found.
datax-auth/src/main/java/cn/datax/auth/listener/AuthenticationFailureEventListener.java
0 → 100644
View file @
8e19e6f9
package
cn
.
datax
.
auth
.
listener
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent
;
import
org.springframework.stereotype.Component
;
@Slf4j
@Component
public
class
AuthenticationFailureEventListener
implements
ApplicationListener
<
AbstractAuthenticationFailureEvent
>
{
@Override
public
void
onApplicationEvent
(
AbstractAuthenticationFailureEvent
event
)
{
log
.
info
(
"{}登录失败"
,
event
.
getAuthentication
().
getPrincipal
());
}
}
datax-auth/src/main/java/cn/datax/auth/listener/AuthenticationSuccessEventListener.java
0 → 100644
View file @
8e19e6f9
package
cn
.
datax
.
auth
.
listener
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.security.authentication.event.AuthenticationSuccessEvent
;
import
org.springframework.stereotype.Component
;
@Slf4j
@Component
public
class
AuthenticationSuccessEventListener
implements
ApplicationListener
<
AuthenticationSuccessEvent
>
{
@Override
public
void
onApplicationEvent
(
AuthenticationSuccessEvent
event
)
{
if
(!
event
.
getSource
().
getClass
().
getName
().
equals
(
"org.springframework.security.authentication.UsernamePasswordAuthenticationToken"
)){
log
.
info
(
"{}登录成功"
,
event
.
getAuthentication
().
getPrincipal
());
}
}
}
datax-auth/src/main/java/cn/datax/auth/service/DataUserDetailService.java
View file @
8e19e6f9
...
...
@@ -34,7 +34,6 @@ public class DataUserDetailService implements UserDetailsService {
public
UserDetails
loadUserByUsername
(
String
s
)
throws
UsernameNotFoundException
{
//远程获取用户
R
result
=
userServiceFeign
.
loginByUsername
(
s
);
log
.
info
(
JSON
.
toJSONString
(
result
));
if
(
result
==
null
||
!
result
.
isSuccess
()
||
ObjectUtil
.
isEmpty
(
result
.
getData
())){
throw
new
UsernameNotFoundException
(
StrUtil
.
format
(
"{}用户不存在"
,
s
));
}
...
...
datax-auth/src/main/java/cn/datax/auth/translator/DataOauthException.java
View file @
8e19e6f9
...
...
@@ -9,4 +9,8 @@ public class DataOauthException extends OAuth2Exception {
public
DataOauthException
(
String
msg
)
{
super
(
msg
);
}
public
DataOauthException
(
String
msg
,
Throwable
t
)
{
super
(
msg
,
t
);
}
}
datax-auth/src/main/java/cn/datax/auth/translator/DataWebResponseExceptionTranslator.java
View file @
8e19e6f9
...
...
@@ -17,14 +17,10 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
@Slf4j
@Component
public
class
DataWebResponseExceptionTranslator
implements
WebResponseExceptionTranslator
{
public
class
DataWebResponseExceptionTranslator
implements
WebResponseExceptionTranslator
<
OAuth2Exception
>
{
private
ThrowableAnalyzer
throwableAnalyzer
=
new
DefaultThrowableAnalyzer
();
public
void
setThrowableAnalyzer
(
ThrowableAnalyzer
throwableAnalyzer
)
{
this
.
throwableAnalyzer
=
throwableAnalyzer
;
}
@Override
public
ResponseEntity
<
OAuth2Exception
>
translate
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
...
...
@@ -86,12 +82,16 @@ public class DataWebResponseExceptionTranslator implements WebResponseExceptionT
}
else
if
(
StringUtils
.
containsIgnoreCase
(
e
.
getMessage
(),
"Access token expired"
))
{
message
=
"Token过期"
;
}
else
if
(
StringUtils
.
containsIgnoreCase
(
e
.
getMessage
(),
"locked"
))
{
message
=
"用户已被锁定
,请联系管理员
"
;
message
=
"用户已被锁定"
;
}
else
if
(
StringUtils
.
containsIgnoreCase
(
e
.
getMessage
(),
"Bad credentials"
))
{
message
=
"用户名或密码错误"
;
}
}
return
new
ResponseEntity
<>(
new
DataOauthException
(
message
),
headers
,
HttpStatus
.
valueOf
(
status
));
return
new
ResponseEntity
<
OAuth2Exception
>(
new
DataOauthException
(
message
,
e
),
headers
,
HttpStatus
.
valueOf
(
status
));
}
public
void
setThrowableAnalyzer
(
ThrowableAnalyzer
throwableAnalyzer
)
{
this
.
throwableAnalyzer
=
throwableAnalyzer
;
}
@SuppressWarnings
(
"serial"
)
...
...
datax-common/datax-common-redis/src/main/java/cn/datax/common/redis/config/RedisConfig.java
View file @
8e19e6f9
package
cn
.
datax
.
common
.
redis
.
config
;
import
cn.datax.common.redis.service.RedisService
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.interceptor.KeyGenerator
;
...
...
@@ -47,6 +50,7 @@ public class RedisConfig extends CachingConfigurerSupport {
}
@Bean
@ConditionalOnBean
(
name
=
"redisTemplate"
)
public
RedisCacheManager
redisCacheManager
(
RedisTemplate
redisTemplate
)
{
//spring cache注解序列化配置
RedisCacheConfiguration
redisCacheConfiguration
=
RedisCacheConfiguration
.
defaultCacheConfig
()
...
...
@@ -82,6 +86,7 @@ public class RedisConfig extends CachingConfigurerSupport {
* @return
*/
@Bean
@ConditionalOnClass
(
RedisOperations
.
class
)
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
<
String
,
Object
>
redisTemplate
=
new
RedisTemplate
<>();
Jackson2JsonRedisSerializer
jackson2JsonRedisSerializer
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
...
...
@@ -99,4 +104,10 @@ public class RedisConfig extends CachingConfigurerSupport {
redisTemplate
.
afterPropertiesSet
();
return
redisTemplate
;
}
@Bean
@ConditionalOnBean
(
name
=
"redisTemplate"
)
public
RedisService
redisService
()
{
return
new
RedisService
();
}
}
\ No newline at end of file
datax-common/datax-common-redis/src/main/java/cn/datax/common/redis/service/RedisService.java
0 → 100644
View file @
8e19e6f9
package
cn
.
datax
.
common
.
redis
.
service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* 定义常用的 Redis操作
*/
public
class
RedisService
{
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return Boolean
*/
public
Boolean
expire
(
String
key
,
Long
time
)
{
try
{
if
(
time
>
0
)
{
redisTemplate
.
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 根据key获取过期时间
*
* @param key 键 不能为 null
* @return 时间(秒) 返回 0代表为永久有效
*/
public
Long
getExpire
(
String
key
)
{
return
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
SECONDS
);
}
/**
* 判断 key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public
Boolean
hasKey
(
String
key
)
{
try
{
return
redisTemplate
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
public
void
del
(
String
...
key
)
{
if
(
key
!=
null
&&
key
.
length
>
0
)
{
if
(
key
.
length
==
1
)
{
redisTemplate
.
delete
(
key
[
0
]);
}
else
{
redisTemplate
.
delete
(
Arrays
.
asList
(
key
));
}
}
}
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public
Object
get
(
String
key
)
{
return
key
==
null
?
null
:
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public
Boolean
set
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public
Boolean
set
(
String
key
,
Object
value
,
Long
time
)
{
try
{
if
(
time
>
0
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
}
else
{
set
(
key
,
value
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 递增
*
* @param key 键
* @param delta 要增加几(大于0)
* @return Long
*/
public
Long
incr
(
String
key
,
Long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递增因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
delta
);
}
/**
* 递减
*
* @param key 键
* @param delta 要减少几(小于0)
* @return Long
*/
public
Long
decr
(
String
key
,
Long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递减因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
-
delta
);
}
/**
* HashGet
*
* @param key 键 不能为 null
* @param item 项 不能为 null
* @return 值
*/
public
Object
hget
(
String
key
,
String
item
)
{
return
redisTemplate
.
opsForHash
().
get
(
key
,
item
);
}
/**
* 获取 hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public
Map
<
Object
,
Object
>
hmget
(
String
key
)
{
return
redisTemplate
.
opsForHash
().
entries
(
key
);
}
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public
Boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
)
{
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public
Boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
Long
time
)
{
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public
Boolean
hset
(
String
key
,
String
item
,
Object
value
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public
Boolean
hset
(
String
key
,
String
item
,
Object
value
,
Long
time
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 删除hash表中的值
*
* @param key 键 不能为 null
* @param item 项 可以使多个不能为 null
*/
public
void
hdel
(
String
key
,
Object
...
item
)
{
redisTemplate
.
opsForHash
().
delete
(
key
,
item
);
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为 null
* @param item 项 不能为 null
* @return true 存在 false不存在
*/
public
Boolean
hHasKey
(
String
key
,
String
item
)
{
return
redisTemplate
.
opsForHash
().
hasKey
(
key
,
item
);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return Double
*/
public
Double
hincr
(
String
key
,
String
item
,
Double
by
)
{
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
by
);
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return Double
*/
public
Double
hdecr
(
String
key
,
String
item
,
Double
by
)
{
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
-
by
);
}
/**
* 根据 key获取 Set中的所有值
*
* @param key 键
* @return Set
*/
public
Set
<
Object
>
sGet
(
String
key
)
{
try
{
return
redisTemplate
.
opsForSet
().
members
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
Boolean
sHasKey
(
String
key
,
Object
value
)
{
try
{
return
redisTemplate
.
opsForSet
().
isMember
(
key
,
value
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public
Long
sSet
(
String
key
,
Object
...
values
)
{
try
{
return
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public
Long
sSetAndTime
(
String
key
,
Long
time
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
if
(
time
>
0
)
expire
(
key
,
time
);
return
count
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return Long
*/
public
Long
sGetSetSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public
Long
setRemove
(
String
key
,
Object
...
values
)
{
try
{
return
redisTemplate
.
opsForSet
().
remove
(
key
,
values
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return List
*/
public
List
<
Object
>
lGet
(
String
key
,
Long
start
,
Long
end
)
{
try
{
return
redisTemplate
.
opsForList
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return Long
*/
public
Long
lGetListSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForList
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;
* index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return Object
*/
public
Object
lGetIndex
(
String
key
,
Long
index
)
{
try
{
return
redisTemplate
.
opsForList
().
index
(
key
,
index
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return Boolean
*/
public
Boolean
lSet
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return Boolean
*/
public
Boolean
lSet
(
String
key
,
Object
value
,
Long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
if
(
time
>
0
)
expire
(
key
,
time
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return Boolean
*/
public
Boolean
lSet
(
String
key
,
List
<
Object
>
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return Boolean
*/
public
Boolean
lSet
(
String
key
,
List
<
Object
>
value
,
Long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
if
(
time
>
0
)
expire
(
key
,
time
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return Boolean
*/
public
Boolean
lUpdateIndex
(
String
key
,
Long
index
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
set
(
key
,
index
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 移除N个值为value
*
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public
Long
lRemove
(
String
key
,
Long
count
,
Object
value
)
{
try
{
return
redisTemplate
.
opsForList
().
remove
(
key
,
count
,
value
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
}
\ No newline at end of file
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/controller/LoginController.java
View file @
8e19e6f9
package
cn
.
datax
.
service
.
system
.
controller
;
import
cn.datax.common.base.BaseController
;
import
cn.datax.common.core.DataUser
;
import
cn.datax.common.core.R
;
import
cn.datax.common.security.annotation.DataInner
;
import
cn.datax.common.utils.SecurityUtil
;
import
cn.datax.service.system.api.vo.UserInfo
;
import
cn.datax.service.system.service.UserService
;
import
cn.hutool.core.util.StrUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.security.oauth2.common.OAuth2AccessToken
;
import
org.springframework.security.oauth2.common.OAuth2RefreshToken
;
import
org.springframework.security.oauth2.provider.token.TokenStore
;
import
org.springframework.util.Base64Utils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.Map
;
@Slf4j
@RestController
...
...
@@ -35,28 +24,6 @@ public class LoginController extends BaseController {
@Autowired
private
TokenStore
tokenStore
;
@Autowired
private
RestTemplate
restTemplate
;
@GetMapping
(
"/token"
)
public
R
getTokenUser
()
{
DataUser
user
=
SecurityUtil
.
getDataUser
();
return
R
.
ok
().
setData
(
user
);
}
@DataInner
@PostMapping
(
"/login"
)
public
R
login
(){
MultiValueMap
<
String
,
String
>
formData
=
new
LinkedMultiValueMap
();
HttpHeaders
headers
=
new
HttpHeaders
();
// headers.set("Authorization", this.getAuthorizationHeader(this.clientId, this.clientSecret));
Map
<
String
,
Object
>
map
=
this
.
postForMap
(
""
,
formData
,
headers
);
if
(
map
.
containsKey
(
"error"
))
{
return
R
.
error
();
}
return
R
.
ok
().
setData
(
map
);
}
@DataInner
@GetMapping
(
"/login/username/{username}"
)
public
R
loginByUsername
(
@PathVariable
String
username
)
{
...
...
@@ -78,14 +45,4 @@ public class LoginController extends BaseController {
tokenStore
.
removeRefreshToken
(
refreshToken
);
return
R
.
ok
();
}
private
String
getAuthorizationHeader
(
String
clientId
,
String
clientSecret
)
{
String
creds
=
String
.
format
(
"%s:%s"
,
clientId
,
clientSecret
);
return
"Basic "
+
new
String
(
Base64Utils
.
encode
(
creds
.
getBytes
()));
}
private
Map
<
String
,
Object
>
postForMap
(
String
path
,
MultiValueMap
<
String
,
String
>
formData
,
HttpHeaders
headers
)
{
Map
map
=
restTemplate
.
exchange
(
path
,
HttpMethod
.
POST
,
new
HttpEntity
(
formData
,
headers
),
Map
.
class
,
new
Object
[
0
]).
getBody
();
return
map
;
}
}
datax-modules/system-service-parent/system-service/src/main/resources/spy.properties
View file @
8e19e6f9
...
...
@@ -19,3 +19,7 @@ dateformat=yyyy-MM-dd HH:mm:ss
outagedetection
=
true
# 慢SQL记录标准 2 秒
outagedetectioninterval
=
2
# 开启过滤
filter
=
true
# 配置不打印的内容
exclude
=
select 1
\ No newline at end of file
datax-tools/datax-tool-codegen/src/main/java/cn/datax/tool/codegen/utils/CodeGenerator.java
View file @
8e19e6f9
...
...
@@ -57,6 +57,7 @@ public class CodeGenerator {
pc
.
setParent
(
"cn.datax.service"
);
// 父包模块名
pc
.
setModuleName
(
"system"
);
pc
.
setMapper
(
"dao"
);
mpg
.
setPackageInfo
(
pc
);
// 自定义配置
...
...
@@ -67,13 +68,10 @@ public class CodeGenerator {
}
};
// 如果模板引擎是 velocity
String
templatePath
=
"/templates/mapper.xml.vm"
;
// 自定义输出配置
List
<
FileOutConfig
>
focList
=
new
ArrayList
<>();
// 自定义配置会被优先输出
focList
.
add
(
new
FileOutConfig
(
templatePath
)
{
focList
.
add
(
new
FileOutConfig
(
"/templates/mapper.xml.vm"
)
{
@Override
public
String
outputFile
(
TableInfo
tableInfo
)
{
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
...
...
@@ -124,9 +122,10 @@ public class CodeGenerator {
strategy
.
setControllerMappingHyphenStyle
(
true
);
strategy
.
setTablePrefix
(
"sys_"
);
// strategy.setInclude(new String[]{"sys_user", "sys_role", "sys_dept", "sys_menu", "sys_post", "sys_user_role", "sys_user_dept", "sys_user_post", "sys_role_menu"});
strategy
.
setInclude
(
new
String
[]{
"sys_
dept_relation"
,
"sys_
role_dept"
});
strategy
.
setInclude
(
new
String
[]{
"sys_role_dept"
});
mpg
.
setStrategy
(
strategy
);
mpg
.
setTemplateEngine
(
new
VelocityTemplateEngine
());
mpg
.
execute
();
}
...
...
datax-tools/datax-tool-codegen/src/main/resources/templates/controller.java.vm
0 → 100644
View file @
8e19e6f9
package
${
package
.
Controller
};
import
org
.
springframework
.
web
.
bind
.
annotation
.
RequestMapping
;
#
if
(${
restControllerStyle
})
import
org
.
springframework
.
web
.
bind
.
annotation
.
RestController
;
#
else
import
org
.
springframework
.
stereotype
.
Controller
;
#
end
#
if
(${
superControllerClassPackage
})
import
${
superControllerClassPackage
};
#
end
/**
*
<
p
>
*
$
!{table.comment} 前端控制器
*
</
p
>
*
*
@
author
${
author
}
*
@
since
${
date
}
*/
#
if
(${
restControllerStyle
})
@
RestController
#
else
@
Controller
#
end
@
RequestMapping
(
"#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end"
)
#
if
(${
kotlin
})
class
${
table
.
controllerName
}#
if
(${
superControllerClass
})
:
${
superControllerClass
}()#
end
#
else
#
if
(${
superControllerClass
})
public
class
${
table
.
controllerName
}
extends
${
superControllerClass
}
{
#
else
public
class
${
table
.
controllerName
}
{
#
end
}
#
end
\ No newline at end of file
datax-tools/datax-tool-codegen/src/main/resources/templates/entity.java.vm
0 → 100644
View file @
8e19e6f9
package
${
package
.
Entity
};
#
foreach
($
pkg
in
${
table
.
importPackages
})
import
${
pkg
};
#
end
#
if
(${
swagger2
})
import
io
.
swagger
.
annotations
.
ApiModel
;
import
io
.
swagger
.
annotations
.
ApiModelProperty
;
#
end
#
if
(${
entityLombokModel
})
import
lombok
.
Data
;
import
lombok
.
EqualsAndHashCode
;
import
lombok
.
experimental
.
Accessors
;
#
end
/**
*
<
p
>
*
$
!{table.comment}
*
</
p
>
*
*
@
author
${
author
}
*
@
since
${
date
}
*/
#
if
(${
entityLombokModel
})
@
Data
#
if
(${
superEntityClass
})
@
EqualsAndHashCode
(
callSuper
=
true
)
#
else
@
EqualsAndHashCode
(
callSuper
=
false
)
#
end
@
Accessors
(
chain
=
true
)
#
end
#
if
(${
table
.
convert
})
@
TableName
(
"${table.name}"
)
#
end
#
if
(${
swagger2
})
@
ApiModel
(
value
=
"${entity}对象"
,
description
=
"$!{table.comment}"
)
#
end
#
if
(${
superEntityClass
})
public
class
${
entity
}
extends
${
superEntityClass
}#
if
(${
activeRecord
})<${
entity
}>#
end
{
#
elseif
(${
activeRecord
})
public
class
${
entity
}
extends
Model
<${
entity
}>
{
#
else
public
class
${
entity
}
implements
Serializable
{
#
end
#
if
(${
entitySerialVersionUID
})
private
static
final
long
serialVersionUID
=
1L
;
#
end
##
----------
BEGIN
字段循环遍历
----------
#
foreach
($
field
in
${
table
.
fields
})
#
if
(${
field
.
keyFlag
})
#
set
($
keyPropertyName
=${
field
.
propertyName
})
#
end
#
if
(
"$!field.comment"
!= "")
#
if
(${
swagger2
})
@
ApiModelProperty
(
value
=
"${field.comment}"
)
#
else
/**
*
${
field
.
comment
}
*/
#
end
#
end
#
if
(${
field
.
keyFlag
})
##
主键
#
if
(${
field
.
keyIdentityFlag
})
@
TableId
(
value
=
"${field.name}"
,
type
=
IdType
.
AUTO
)
#
elseif
(
!$null.isNull(${idType}) && "$!idType" != "")
@
TableId
(
value
=
"${field.name}"
,
type
=
IdType
.${
idType
})
#
elseif
(${
field
.
convert
})
@
TableId
(
"${field.name}"
)
#
end
##
普通字段
#
elseif
(${
field
.
fill
})
##
-----
存在字段填充设置
-----
#
if
(${
field
.
convert
})
@
TableField
(
value
=
"${field.name}"
,
fill
=
FieldFill
.${
field
.
fill
})
#
else
@
TableField
(
fill
=
FieldFill
.${
field
.
fill
})
#
end
#
elseif
(${
field
.
convert
})
@
TableField
(
"${field.name}"
)
#
end
##
乐观锁注解
#
if
(${
versionFieldName
}==${
field
.
name
})
@
Version
#
end
##
逻辑删除注解
#
if
(${
logicDeleteFieldName
}==${
field
.
name
})
@
TableLogic
#
end
private
${
field
.
propertyType
}
${
field
.
propertyName
};
#
end
##
----------
END
字段循环遍历
----------
#
if
(
!${entityLombokModel})
#
foreach
($
field
in
${
table
.
fields
})
#
if
(${
field
.
propertyType
.
equals
(
"boolean"
)})
#
set
($
getprefix
=
"is"
)
#
else
#
set
($
getprefix
=
"get"
)
#
end
public
${
field
.
propertyType
}
${
getprefix
}${
field
.
capitalName
}()
{
return
${
field
.
propertyName
};
}
#
if
(${
entityBuilderModel
})
public
${
entity
}
set
${
field
.
capitalName
}(${
field
.
propertyType
}
${
field
.
propertyName
})
{
#
else
public
void
set
${
field
.
capitalName
}(${
field
.
propertyType
}
${
field
.
propertyName
})
{
#
end
this
.${
field
.
propertyName
}
=
${
field
.
propertyName
};
#
if
(${
entityBuilderModel
})
return
this
;
#
end
}
#
end
#
end
#
if
(${
entityColumnConstant
})
#
foreach
($
field
in
${
table
.
fields
})
public
static
final
String
${
field
.
name
.
toUpperCase
()}
=
"${field.name}"
;
#
end
#
end
#
if
(${
activeRecord
})
@
Override
protected
Serializable
pkVal
()
{
#
if
(${
keyPropertyName
})
return
this
.${
keyPropertyName
};
#
else
return
null
;
#
end
}
#
end
#
if
(
!${entityLombokModel})
@
Override
public
String
toString
()
{
return
"${entity}{"
+
#
foreach
($
field
in
${
table
.
fields
})
#
if
($
!{foreach.index}==0)
"${field.propertyName}="
+
${
field
.
propertyName
}
+
#
else
", ${field.propertyName}="
+
${
field
.
propertyName
}
+
#
end
#
end
"}"
;
}
#
end
}
datax-tools/datax-tool-codegen/src/main/resources/templates/entity.kt.vm
0 → 100644
View file @
8e19e6f9
package
${
package
.
Entity
};
#
foreach
($
pkg
in
${
table
.
importPackages
})
import
${
pkg
};
#
end
#
if
(${
swagger2
})
import
io
.
swagger
.
annotations
.
ApiModel
;
import
io
.
swagger
.
annotations
.
ApiModelProperty
;
#
end
/**
*
<
p
>
*
$
!{table.comment}
*
</
p
>
*
*
@
author
${
author
}
*
@
since
${
date
}
*/
#
if
(${
table
.
convert
})
@
TableName
(
"${table.name}"
)
#
end
#
if
(${
swagger2
})
@
ApiModel
(
value
=
"${entity}对象"
,
description
=
"$!{table.comment}"
)
#
end
#
if
(${
superEntityClass
})
class
${
entity
}
:
${
superEntityClass
}#
if
(${
activeRecord
})<${
entity
}>#
end
()
{
#
elseif
(${
activeRecord
})
class
${
entity
}
:
Model
<${
entity
}>()
{
#
else
class
${
entity
}
:
Serializable
{
#
end
##
----------
BEGIN
字段循环遍历
----------
#
foreach
($
field
in
${
table
.
fields
})
#
if
(${
field
.
keyFlag
})
#
set
($
keyPropertyName
=${
field
.
propertyName
})
#
end
#
if
(
"$!field.comment"
!= "")
#
if
(${
swagger2
})
@
ApiModelProperty
(
value
=
"${field.comment}"
)
#
else
/**
*
${
field
.
comment
}
*/
#
end
#
end
#
if
(${
field
.
keyFlag
})
##
主键
#
if
(${
field
.
keyIdentityFlag
})
@
TableId
(
value
=
"${field.name}"
,
type
=
IdType
.
AUTO
)
#
elseif
(
!$null.isNull(${idType}) && "$!idType" != "")
@
TableId
(
value
=
"${field.name}"
,
type
=
IdType
.${
idType
})
#
elseif
(${
field
.
convert
})
@
TableId
(
"${field.name}"
)
#
end
##
普通字段
#
elseif
(${
field
.
fill
})
##
-----
存在字段填充设置
-----
#
if
(${
field
.
convert
})
@
TableField
(
value
=
"${field.name}"
,
fill
=
FieldFill
.${
field
.
fill
})
#
else
@
TableField
(
fill
=
FieldFill
.${
field
.
fill
})
#
end
#
elseif
(${
field
.
convert
})
@
TableField
(
"${field.name}"
)
#
end
##
乐观锁注解
#
if
(${
versionFieldName
}==${
field
.
name
})
@
Version
#
end
##
逻辑删除注解
#
if
(${
logicDeleteFieldName
}==${
field
.
name
})
@
TableLogic
#
end
#
if
(${
field
.
propertyType
}
==
"Integer"
)
var
${
field
.
propertyName
}:
Int
?
=
null
#
else
var
${
field
.
propertyName
}:
${
field
.
propertyType
}?
=
null
#
end
#
end
##
----------
END
字段循环遍历
----------
#
if
(${
entityColumnConstant
})
companion
object
{
#
foreach
($
field
in
${
table
.
fields
})
const
val
${
field
.
name
.
toUpperCase
()}
:
String
=
"${field.name}"
#
end
}
#
end
#
if
(${
activeRecord
})
override
fun
pkVal
():
Serializable
?
{
#
if
(${
keyPropertyName
})
return
${
keyPropertyName
}
#
else
return
null
#
end
}
#
end
override
fun
toString
():
String
{
return
"${entity}{"
+
#
foreach
($
field
in
${
table
.
fields
})
#
if
($
!{foreach.index}==0)
"${field.propertyName}="
+
${
field
.
propertyName
}
+
#
else
", ${field.propertyName}="
+
${
field
.
propertyName
}
+
#
end
#
end
"}"
}
}
datax-tools/datax-tool-codegen/src/main/resources/templates/mapper.java.vm
0 → 100644
View file @
8e19e6f9
package
${
package
.
Mapper
};
import
${
package
.
Entity
}.${
entity
};
import
${
superMapperClassPackage
};
/**
*
<
p
>
*
$
!{table.comment} Mapper 接口
*
</
p
>
*
*
@
author
${
author
}
*
@
since
${
date
}
*/
#
if
(${
kotlin
})
interface
${
table
.
mapperName
}
:
${
superMapperClass
}<${
entity
}>
#
else
public
interface
${
table
.
mapperName
}
extends
${
superMapperClass
}<${
entity
}>
{
}
#
end
datax-tools/datax-tool-codegen/src/main/resources/templates/mapper.xml.vm
0 → 100644
View file @
8e19e6f9
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"${package.Mapper}.${table.mapperName}"
>
#if(${enableCache})
<!-- 开启二级缓存 -->
<cache
type=
"org.mybatis.caches.ehcache.LoggingEhcache"
/>
#end
#if(${baseResultMap})
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"${package.Entity}.${entity}"
>
#foreach($field in ${table.fields})
#if(${field.keyFlag})##生成主键排在第一位
<id
column=
"${field.name}"
property=
"${field.propertyName}"
/>
#end
#end
#foreach($field in ${table.commonFields})##生成公共字段
<result
column=
"${field.name}"
property=
"${field.propertyName}"
/>
#end
#foreach($field in ${table.fields})
#if(!${field.keyFlag})##生成普通字段
<result
column=
"${field.name}"
property=
"${field.propertyName}"
/>
#end
#end
</resultMap>
#end
#if(${baseColumnList})
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
#foreach($field in ${table.commonFields})
${field.name},
#end
${table.fieldNames}
</sql>
#end
</mapper>
datax-tools/datax-tool-codegen/src/main/resources/templates/service.java.vm
0 → 100644
View file @
8e19e6f9
package
${
package
.
Service
};
import
${
package
.
Entity
}.${
entity
};
import
${
superServiceClassPackage
};
/**
*
<
p
>
*
$
!{table.comment} 服务类
*
</
p
>
*
*
@
author
${
author
}
*
@
since
${
date
}
*/
#
if
(${
kotlin
})
interface
${
table
.
serviceName
}
:
${
superServiceClass
}<${
entity
}>
#
else
public
interface
${
table
.
serviceName
}
extends
${
superServiceClass
}<${
entity
}>
{
}
#
end
datax-tools/datax-tool-codegen/src/main/resources/templates/serviceImpl.java.vm
0 → 100644
View file @
8e19e6f9
package
${
package
.
ServiceImpl
};
import
${
package
.
Entity
}.${
entity
};
import
${
package
.
Mapper
}.${
table
.
mapperName
};
import
${
package
.
Service
}.${
table
.
serviceName
};
import
${
superServiceImplClassPackage
};
import
org
.
springframework
.
stereotype
.
Service
;
/**
*
<
p
>
*
$
!{table.comment} 服务实现类
*
</
p
>
*
*
@
author
${
author
}
*
@
since
${
date
}
*/
@
Service
#
if
(${
kotlin
})
open
class
${
table
.
serviceImplName
}
:
${
superServiceImplClass
}<${
table
.
mapperName
},
${
entity
}>(),
${
table
.
serviceName
}
{
}
#
else
public
class
${
table
.
serviceImplName
}
extends
${
superServiceImplClass
}<${
table
.
mapperName
},
${
entity
}>
implements
${
table
.
serviceName
}
{
}
#
end
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