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-tools/src/main/java/me/zhengjie/service/impl/PictureServiceImpl.java
View file @
bf7c1eeb
...
...
@@ -11,7 +11,9 @@ import me.zhengjie.repository.PictureRepository;
import
me.zhengjie.service.PictureService
;
import
me.zhengjie.service.dto.PictureQueryCriteria
;
import
me.zhengjie.utils.*
;
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.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
...
...
@@ -19,7 +21,6 @@ import org.springframework.transaction.annotation.Transactional;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.Optional
;
/**
* @author Zheng Jie
...
...
@@ -27,6 +28,7 @@ import java.util.Optional;
*/
@Slf4j
@Service
(
value
=
"pictureService"
)
@CacheConfig
(
cacheNames
=
"picture"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
PictureServiceImpl
implements
PictureService
{
...
...
@@ -43,28 +45,32 @@ public class PictureServiceImpl implements PictureService {
}
@Override
@Cacheable
public
Object
queryAll
(
PictureQueryCriteria
criteria
,
Pageable
pageable
){
return
PageUtil
.
toPage
(
pictureRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
));
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Throwable
.
class
)
public
Picture
upload
(
MultipartFile
multipartFile
,
String
username
)
{
File
file
=
FileUtil
.
toFile
(
multipartFile
);
// 验证是否重复上传
Picture
picture
=
pictureRepository
.
findByMd5Code
(
FileUtil
.
getMD5
(
file
));
if
(
picture
!=
null
){
return
picture
;
}
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>(
1
);
paramMap
.
put
(
"smfile"
,
file
);
String
result
=
HttpUtil
.
post
(
ElAdminConstant
.
Url
.
SM_MS_URL
,
paramMap
);
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
result
);
Picture
picture
=
null
;
if
(!
jsonObject
.
get
(
CODE
).
toString
().
equals
(
SUCCESS
)){
throw
new
BadRequestException
(
TranslatorUtil
.
translate
(
jsonObject
.
get
(
MSG
).
toString
()));
}
//转成实体类
picture
=
JSON
.
parseObject
(
jsonObject
.
get
(
"data"
).
toString
(),
Picture
.
class
);
picture
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
picture
.
getSize
())));
picture
.
setUsername
(
username
);
picture
.
setMd5Code
(
FileUtil
.
getMD5
(
file
));
picture
.
setFilename
(
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
())+
"."
+
FileUtil
.
getExtensionName
(
multipartFile
.
getOriginalFilename
()));
pictureRepository
.
save
(
picture
);
//删除临时文件
...
...
@@ -74,17 +80,19 @@ public class PictureServiceImpl implements PictureService {
}
@Override
@Cacheable
(
key
=
"#p0"
)
public
Picture
findById
(
Long
id
)
{
Optional
<
Picture
>
picture
=
pictureRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
picture
,
"Picture"
,
"id"
,
id
);
return
picture
.
get
()
;
Picture
picture
=
pictureRepository
.
findById
(
id
)
.
orElseGet
(
Picture:
:
new
)
;
ValidationUtil
.
isNull
(
picture
.
getId
()
,
"Picture"
,
"id"
,
id
);
return
picture
;
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Picture
picture
)
{
try
{
String
result
=
HttpUtil
.
get
(
picture
.
getDelete
());
HttpUtil
.
get
(
picture
.
getDelete
());
pictureRepository
.
delete
(
picture
);
}
catch
(
Exception
e
){
pictureRepository
.
delete
(
picture
);
...
...
@@ -93,6 +101,7 @@ public class PictureServiceImpl implements PictureService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
deleteAll
(
Long
[]
ids
)
{
for
(
Long
id
:
ids
)
{
delete
(
findById
(
id
));
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java
View file @
bf7c1eeb
...
...
@@ -21,15 +21,16 @@ import me.zhengjie.utils.PageUtil;
import
me.zhengjie.utils.QiNiuUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.Map
;
import
java.util.Optional
;
/**
...
...
@@ -37,6 +38,7 @@ import java.util.Optional;
* @date 2018-12-31
*/
@Service
@CacheConfig
(
cacheNames
=
"qiNiu"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
QiNiuServiceImpl
implements
QiNiuService
{
...
...
@@ -53,17 +55,20 @@ public class QiNiuServiceImpl implements QiNiuService {
private
Long
maxSize
;
@Override
@Cacheable
public
Object
queryAll
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
){
return
PageUtil
.
toPage
(
qiniuContentRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
));
}
@Override
@Cacheable
(
key
=
"'1'"
)
public
QiniuConfig
find
()
{
Optional
<
QiniuConfig
>
qiniuConfig
=
qiNiuConfigRepository
.
findById
(
1L
);
return
qiniuConfig
.
orElseGet
(
QiniuConfig:
:
new
);
}
@Override
@CachePut
(
cacheNames
=
"qiNiuConfig"
,
key
=
"'1'"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
QiniuConfig
update
(
QiniuConfig
qiniuConfig
)
{
if
(!(
qiniuConfig
.
getHost
().
toLowerCase
().
startsWith
(
"http://"
)||
qiniuConfig
.
getHost
().
toLowerCase
().
startsWith
(
"https://"
)))
{
...
...
@@ -74,6 +79,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
QiniuContent
upload
(
MultipartFile
file
,
QiniuConfig
qiniuConfig
)
{
FileUtil
.
checkSize
(
maxSize
,
file
.
getSize
());
...
...
@@ -109,15 +115,17 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@Cacheable
public
QiniuContent
findByContentId
(
Long
id
)
{
Optional
<
QiniuContent
>
qiniuContent
=
qiniuContentRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
qiniuContent
,
"QiniuContent"
,
"id"
,
id
);
return
qiniuContent
.
get
()
;
QiniuContent
qiniuContent
=
qiniuContentRepository
.
findById
(
id
)
.
orElseGet
(
QiniuContent:
:
new
)
;
ValidationUtil
.
isNull
(
qiniuContent
.
getId
()
,
"QiniuContent"
,
"id"
,
id
);
return
qiniuContent
;
}
@Override
@Cacheable
public
String
download
(
QiniuContent
content
,
QiniuConfig
config
){
String
finalUrl
=
null
;
String
finalUrl
;
String
TYPE
=
"公开"
;
if
(
TYPE
.
equals
(
content
.
getType
())){
finalUrl
=
content
.
getUrl
();
...
...
@@ -131,6 +139,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
QiniuContent
content
,
QiniuConfig
config
)
{
//构造一个带指定Zone对象的配置类
...
...
@@ -146,6 +155,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
synchronize
(
QiniuConfig
config
)
{
if
(
config
.
getId
()
==
null
){
...
...
@@ -165,7 +175,7 @@ public class QiNiuServiceImpl implements QiNiuService {
BucketManager
.
FileListIterator
fileListIterator
=
bucketManager
.
createFileListIterator
(
config
.
getBucket
(),
prefix
,
limit
,
delimiter
);
while
(
fileListIterator
.
hasNext
())
{
//处理获取的file list结果
QiniuContent
qiniuContent
=
null
;
QiniuContent
qiniuContent
;
FileInfo
[]
items
=
fileListIterator
.
next
();
for
(
FileInfo
item
:
items
)
{
if
(
qiniuContentRepository
.
findByKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
))
==
null
){
...
...
@@ -183,6 +193,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
deleteAll
(
Long
[]
ids
,
QiniuConfig
config
)
{
for
(
Long
id
:
ids
)
{
delete
(
findByContentId
(
id
),
config
);
...
...
@@ -190,6 +201,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
String
type
)
{
qiNiuConfigRepository
.
update
(
type
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/VerificationCodeServiceImpl.java
View file @
bf7c1eeb
...
...
@@ -11,12 +11,10 @@ import me.zhengjie.domain.vo.EmailVo;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.repository.VerificationCodeRepository
;
import
me.zhengjie.service.VerificationCodeService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.concurrent.*
;
...
...
@@ -28,17 +26,20 @@ import java.util.concurrent.*;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
VerificationCodeServiceImpl
implements
VerificationCodeService
{
@Autowired
private
VerificationCodeRepository
verificationCodeRepository
;
private
final
VerificationCodeRepository
verificationCodeRepository
;
@Value
(
"${code.expiration}"
)
private
Integer
expiration
;
public
VerificationCodeServiceImpl
(
VerificationCodeRepository
verificationCodeRepository
)
{
this
.
verificationCodeRepository
=
verificationCodeRepository
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
EmailVo
sendEmail
(
VerificationCode
code
)
{
EmailVo
emailVo
=
null
;
String
content
=
""
;
EmailVo
emailVo
;
String
content
;
VerificationCode
verificationCode
=
verificationCodeRepository
.
findByScenesAndTypeAndValueAndStatusIsTrue
(
code
.
getScenes
(),
code
.
getType
(),
code
.
getValue
());
// 如果不存在有效的验证码,就创建一个新的
TemplateEngine
engine
=
TemplateUtil
.
createEngine
(
new
TemplateConfig
(
"template"
,
TemplateConfig
.
ResourceMode
.
CLASSPATH
));
...
...
eladmin-tools/src/main/java/me/zhengjie/utils/AliPayStatusEnum.java
View file @
bf7c1eeb
...
...
@@ -7,24 +7,12 @@ package me.zhengjie.utils;
*/
public
enum
AliPayStatusEnum
{
/**
* 交易成功
*/
FINISHED
(
"交易成功"
,
"TRADE_FINISHED"
),
/**
* 支付成功
*/
SUCCESS
(
"支付成功"
,
"TRADE_SUCCESS"
),
/**
* 交易创建
*/
BUYER_PAY
(
"交易创建"
,
"WAIT_BUYER_PAY"
),
/**
* 交易关闭
*/
CLOSED
(
"交易关闭"
,
"TRADE_CLOSED"
);
private
String
value
;
...
...
eladmin-tools/src/main/java/me/zhengjie/utils/AlipayUtils.java
View file @
bf7c1eeb
package
me.zhengjie.utils
;
import
cn.hutool.core.util.StrUtil
;
import
com.alipay.api.AlipayApiException
;
import
com.alipay.api.internal.util.AlipaySignature
;
import
me.zhengjie.domain.AlipayConfig
;
...
...
@@ -9,7 +8,6 @@ import javax.servlet.http.HttpServletRequest;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
...
...
@@ -22,6 +20,7 @@ public class AlipayUtils {
/**
* 生成订单号
* @return String
*/
public
String
getOrderCode
()
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
...
...
@@ -39,6 +38,9 @@ public class AlipayUtils {
/**
* 校验签名
* @param request HttpServletRequest
* @param alipay 阿里云配置
* @return boolean
*/
public
boolean
rsaCheck
(
HttpServletRequest
request
,
AlipayConfig
alipay
){
...
...
@@ -65,8 +67,4 @@ public class AlipayUtils {
return
false
;
}
}
public
boolean
isEmpty
(
String
str
){
return
StrUtil
.
isEmpty
(
str
);
}
}
eladmin-tools/src/main/java/me/zhengjie/utils/QiNiuUtil.java
View file @
bf7c1eeb
...
...
@@ -21,6 +21,8 @@ public class QiNiuUtil {
/**
* 得到机房的对应关系
* @param zone 机房名称
* @return Region
*/
public
static
Region
getRegion
(
String
zone
){
...
...
@@ -40,6 +42,8 @@ public class QiNiuUtil {
/**
* 默认不指定key的情况下,以文件内容的hash值作为文件名
* @param file 文件名
* @return String
*/
public
static
String
getKey
(
String
file
){
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
...
...
Prev
1
…
4
5
6
7
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