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
2d83a6d0
Commit
2d83a6d0
authored
Jul 06, 2023
by
Zheng Jie
Browse files
Merge branch 'master' into deploy
parents
2c5b045b
8cb96509
Changes
5
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java
View file @
2d83a6d0
...
@@ -15,9 +15,9 @@
...
@@ -15,9 +15,9 @@
*/
*/
package
me.zhengjie.utils
;
package
me.zhengjie.utils
;
import
c
n.hutool.
json.JSON
Array
;
import
c
om.alibaba.fast
json.JSON
;
import
c
n.hutool.
json.JSON
Object
;
import
c
om.alibaba.fast
json.JSON
Array
;
import
c
n.hutool.
json.JSON
Util
;
import
c
om.alibaba.fast
json.JSON
Object
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.utils.enums.DataScopeEnum
;
import
me.zhengjie.utils.enums.DataScopeEnum
;
...
@@ -68,7 +68,9 @@ public class SecurityUtils {
...
@@ -68,7 +68,9 @@ public class SecurityUtils {
*/
*/
public
static
Long
getCurrentUserId
()
{
public
static
Long
getCurrentUserId
()
{
UserDetails
userDetails
=
getCurrentUser
();
UserDetails
userDetails
=
getCurrentUser
();
return
new
JSONObject
(
new
JSONObject
(
userDetails
).
get
(
"user"
)).
get
(
"id"
,
Long
.
class
);
// 将 Java 对象转换为 JSONObject 对象
JSONObject
jsonObject
=
(
JSONObject
)
JSON
.
toJSON
(
userDetails
);
return
jsonObject
.
getJSONObject
(
"user"
).
getLong
(
"id"
);
}
}
/**
/**
...
@@ -77,8 +79,10 @@ public class SecurityUtils {
...
@@ -77,8 +79,10 @@ public class SecurityUtils {
*/
*/
public
static
List
<
Long
>
getCurrentUserDataScope
(){
public
static
List
<
Long
>
getCurrentUserDataScope
(){
UserDetails
userDetails
=
getCurrentUser
();
UserDetails
userDetails
=
getCurrentUser
();
JSONArray
array
=
JSONUtil
.
parseArray
(
new
JSONObject
(
userDetails
).
get
(
"dataScopes"
));
// 将 Java 对象转换为 JSONObject 对象
return
JSONUtil
.
toList
(
array
,
Long
.
class
);
JSONObject
jsonObject
=
(
JSONObject
)
JSON
.
toJSON
(
userDetails
);
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"dataScopes"
);
return
JSON
.
parseArray
(
jsonArray
.
toJSONString
(),
Long
.
class
);
}
}
/**
/**
...
...
eladmin-common/src/main/java/me/zhengjie/utils/TranslatorUtil.java
deleted
100644 → 0
View file @
2c5b045b
/*
* 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
me.zhengjie.utils
;
import
cn.hutool.json.JSONArray
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
/**
* @author Zheng Jie
* 翻译工具类
*/
public
class
TranslatorUtil
{
public
static
String
translate
(
String
word
){
try
{
String
url
=
"https://translate.googleapis.com/translate_a/single?"
+
"client=gtx&"
+
"sl=en"
+
"&tl=zh-CN"
+
"&dt=t&q="
+
URLEncoder
.
encode
(
word
,
"UTF-8"
);
URL
obj
=
new
URL
(
url
);
HttpURLConnection
con
=
(
HttpURLConnection
)
obj
.
openConnection
();
con
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/5.0"
);
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
()));
String
inputLine
;
StringBuilder
response
=
new
StringBuilder
();
while
((
inputLine
=
in
.
readLine
())
!=
null
)
{
response
.
append
(
inputLine
);
}
in
.
close
();
return
parseResult
(
response
.
toString
());
}
catch
(
Exception
e
){
return
word
;
}
}
private
static
String
parseResult
(
String
inputJson
){
JSONArray
jsonArray2
=
(
JSONArray
)
new
JSONArray
(
inputJson
).
get
(
0
);
StringBuilder
result
=
new
StringBuilder
();
for
(
Object
o
:
jsonArray2
)
{
result
.
append
(((
JSONArray
)
o
).
get
(
0
).
toString
());
}
return
result
.
toString
();
}
}
eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java
View file @
2d83a6d0
...
@@ -17,8 +17,8 @@ package me.zhengjie.service.impl;
...
@@ -17,8 +17,8 @@ package me.zhengjie.service.impl;
import
cn.hutool.core.lang.Dict
;
import
cn.hutool.core.lang.Dict
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
c
n.hutool.
json.JSON
Object
;
import
c
om.alibaba.fast
json.JSON
;
import
c
n.hutool.
json.JSON
Util
;
import
c
om.alibaba.fast
json.JSON
Object
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
me.zhengjie.domain.SysLog
;
import
me.zhengjie.domain.SysLog
;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.repository.LogRepository
;
...
@@ -36,7 +36,6 @@ import org.springframework.stereotype.Service;
...
@@ -36,7 +36,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -98,9 +97,9 @@ public class SysLogServiceImpl implements SysLogService {
...
@@ -98,9 +97,9 @@ public class SysLogServiceImpl implements SysLogService {
sysLog
.
setParams
(
getParameter
(
method
,
joinPoint
.
getArgs
()));
sysLog
.
setParams
(
getParameter
(
method
,
joinPoint
.
getArgs
()));
// 记录登录用户,隐藏密码信息
// 记录登录用户,隐藏密码信息
if
(
signature
.
getName
().
equals
(
"login"
)
&&
StringUtils
.
isNotEmpty
(
sysLog
.
getParams
())){
if
(
signature
.
getName
().
equals
(
"login"
)
&&
StringUtils
.
isNotEmpty
(
sysLog
.
getParams
())){
JSONObject
obj
=
JSON
Util
.
parseObj
(
sysLog
.
getParams
());
JSONObject
obj
=
JSON
.
parseObj
ect
(
sysLog
.
getParams
());
sysLog
.
setUsername
(
obj
.
getStr
(
"username"
,
""
));
sysLog
.
setUsername
(
obj
.
getStr
ing
(
"username"
));
sysLog
.
setParams
(
JSON
Util
.
toJsonStr
(
Dict
.
create
().
set
(
"username"
,
sysLog
.
getUsername
())));
sysLog
.
setParams
(
JSON
.
toJSONString
(
Dict
.
create
().
set
(
"username"
,
sysLog
.
getUsername
())));
}
}
sysLog
.
setBrowser
(
browser
);
sysLog
.
setBrowser
(
browser
);
logRepository
.
save
(
sysLog
);
logRepository
.
save
(
sysLog
);
...
@@ -133,7 +132,7 @@ public class SysLogServiceImpl implements SysLogService {
...
@@ -133,7 +132,7 @@ public class SysLogServiceImpl implements SysLogService {
if
(
argList
.
isEmpty
())
{
if
(
argList
.
isEmpty
())
{
return
""
;
return
""
;
}
}
return
argList
.
size
()
==
1
?
JSON
Util
.
toJsonStr
(
argList
.
get
(
0
))
:
JSON
Util
.
toJsonStr
(
argList
);
return
argList
.
size
()
==
1
?
JSON
.
toJSONString
(
argList
.
get
(
0
))
:
JSON
.
toJSONString
(
argList
);
}
}
@Override
@Override
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/websocket/WebSocketServer.java
View file @
2d83a6d0
...
@@ -15,10 +15,9 @@
...
@@ -15,10 +15,9 @@
*/
*/
package
me.zhengjie.modules.mnt.websocket
;
package
me.zhengjie.modules.mnt.websocket
;
import
com.alibaba.fastjson.JSON
Object
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.websocket.*
;
import
javax.websocket.*
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.ServerEndpoint
;
import
javax.websocket.server.ServerEndpoint
;
...
@@ -37,7 +36,7 @@ public class WebSocketServer {
...
@@ -37,7 +36,7 @@ public class WebSocketServer {
/**
/**
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
*/
*/
private
static
CopyOnWriteArraySet
<
WebSocketServer
>
webSocketSet
=
new
CopyOnWriteArraySet
<
WebSocketServer
>();
private
static
final
CopyOnWriteArraySet
<
WebSocketServer
>
webSocketSet
=
new
CopyOnWriteArraySet
<
WebSocketServer
>();
/**
/**
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
...
@@ -55,11 +54,7 @@ public class WebSocketServer {
...
@@ -55,11 +54,7 @@ public class WebSocketServer {
public
void
onOpen
(
Session
session
,
@PathParam
(
"sid"
)
String
sid
)
{
public
void
onOpen
(
Session
session
,
@PathParam
(
"sid"
)
String
sid
)
{
this
.
session
=
session
;
this
.
session
=
session
;
//如果存在就先删除一个,防止重复推送消息
//如果存在就先删除一个,防止重复推送消息
for
(
WebSocketServer
webSocket:
webSocketSet
)
{
webSocketSet
.
removeIf
(
webSocket
->
webSocket
.
sid
.
equals
(
sid
));
if
(
webSocket
.
sid
.
equals
(
sid
))
{
webSocketSet
.
remove
(
webSocket
);
}
}
webSocketSet
.
add
(
this
);
webSocketSet
.
add
(
this
);
this
.
sid
=
sid
;
this
.
sid
=
sid
;
}
}
...
@@ -105,7 +100,7 @@ public class WebSocketServer {
...
@@ -105,7 +100,7 @@ public class WebSocketServer {
* 群发自定义消息
* 群发自定义消息
* */
* */
public
static
void
sendInfo
(
SocketMsg
socketMsg
,
@PathParam
(
"sid"
)
String
sid
)
throws
IOException
{
public
static
void
sendInfo
(
SocketMsg
socketMsg
,
@PathParam
(
"sid"
)
String
sid
)
throws
IOException
{
String
message
=
JSON
Object
.
toJSONString
(
socketMsg
);
String
message
=
JSON
.
toJSONString
(
socketMsg
);
log
.
info
(
"推送消息到"
+
sid
+
",推送内容:"
+
message
);
log
.
info
(
"推送消息到"
+
sid
+
",推送内容:"
+
message
);
for
(
WebSocketServer
item
:
webSocketSet
)
{
for
(
WebSocketServer
item
:
webSocketSet
)
{
try
{
try
{
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java
View file @
2d83a6d0
...
@@ -119,7 +119,7 @@ public class QiNiuServiceImpl implements QiNiuService {
...
@@ -119,7 +119,7 @@ public class QiNiuServiceImpl implements QiNiuService {
qiniuContent
.
setType
(
qiniuConfig
.
getType
());
qiniuContent
.
setType
(
qiniuConfig
.
getType
());
qiniuContent
.
setKey
(
FileUtil
.
getFileNameNoEx
(
putRet
.
key
));
qiniuContent
.
setKey
(
FileUtil
.
getFileNameNoEx
(
putRet
.
key
));
qiniuContent
.
setUrl
(
qiniuConfig
.
getHost
()+
"/"
+
putRet
.
key
);
qiniuContent
.
setUrl
(
qiniuConfig
.
getHost
()+
"/"
+
putRet
.
key
);
qiniuContent
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
file
.
getSize
()
+
""
)));
qiniuContent
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
String
.
valueOf
(
file
.
getSize
()
)
)));
return
qiniuContentRepository
.
save
(
qiniuContent
);
return
qiniuContentRepository
.
save
(
qiniuContent
);
}
}
return
content
;
return
content
;
...
@@ -190,7 +190,7 @@ public class QiNiuServiceImpl implements QiNiuService {
...
@@ -190,7 +190,7 @@ public class QiNiuServiceImpl implements QiNiuService {
for
(
FileInfo
item
:
items
)
{
for
(
FileInfo
item
:
items
)
{
if
(
qiniuContentRepository
.
findByKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
))
==
null
){
if
(
qiniuContentRepository
.
findByKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
))
==
null
){
qiniuContent
=
new
QiniuContent
();
qiniuContent
=
new
QiniuContent
();
qiniuContent
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
item
.
fsize
+
""
)));
qiniuContent
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
String
.
valueOf
(
item
.
fsize
)
)));
qiniuContent
.
setSuffix
(
FileUtil
.
getExtensionName
(
item
.
key
));
qiniuContent
.
setSuffix
(
FileUtil
.
getExtensionName
(
item
.
key
));
qiniuContent
.
setKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
));
qiniuContent
.
setKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
));
qiniuContent
.
setType
(
config
.
getType
());
qiniuContent
.
setType
(
config
.
getType
());
...
@@ -203,6 +203,7 @@ public class QiNiuServiceImpl implements QiNiuService {
...
@@ -203,6 +203,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
}
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteAll
(
Long
[]
ids
,
QiniuConfig
config
)
{
public
void
deleteAll
(
Long
[]
ids
,
QiniuConfig
config
)
{
for
(
Long
id
:
ids
)
{
for
(
Long
id
:
ids
)
{
delete
(
findByContentId
(
id
),
config
);
delete
(
findByContentId
(
id
),
config
);
...
...
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