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
f0211db0
Commit
f0211db0
authored
Oct 24, 2019
by
dqjdda
Browse files
优化代码
parent
a8230bbd
Changes
58
Hide whitespace changes
Inline
Side-by-side
eladmin-tools/src/main/java/me/zhengjie/rest/PictureController.java
View file @
f0211db0
package
me.zhengjie.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.domain.Picture
;
import
me.zhengjie.service.PictureService
;
import
me.zhengjie.service.dto.PictureQueryCriteria
;
import
me.zhengjie.utils.SecurityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -20,28 +21,28 @@ import java.util.Map;
* @date 2018/09/20 14:13:32
*/
@RestController
@RequestMapping
(
"/api"
)
@RequestMapping
(
"/api/pictures"
)
@Api
(
tags
=
"免费图床管理"
)
public
class
PictureController
{
@Autowired
private
PictureService
pictureService
;
private
final
PictureService
pictureService
;
public
PictureController
(
PictureService
pictureService
)
{
this
.
pictureService
=
pictureService
;
}
@Log
(
"查询图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')"
)
@GetMapping
(
value
=
"/pictures"
)
@GetMapping
@ApiOperation
(
value
=
"查询图片"
)
public
ResponseEntity
getRoles
(
PictureQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
(
pictureService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
pictureService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
/**
* 上传图片
* @param file
* @return
* @throws Exception
*/
@Log
(
"上传图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')"
)
@PostMapping
(
value
=
"/pictures"
)
@PostMapping
@ApiOperation
(
value
=
"上传图片"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
String
userName
=
SecurityUtils
.
getUsername
();
Picture
picture
=
pictureService
.
upload
(
file
,
userName
);
...
...
@@ -49,30 +50,22 @@ public class PictureController {
map
.
put
(
"errno"
,
0
);
map
.
put
(
"id"
,
picture
.
getId
());
map
.
put
(
"data"
,
new
String
[]{
picture
.
getUrl
()});
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
map
,
HttpStatus
.
OK
);
}
/**
* 删除图片
* @param id
* @return
*/
@Log
(
"删除图片"
)
@ApiOperation
(
value
=
"删除图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')"
)
@DeleteMapping
(
value
=
"/
pictures/
{id}"
)
@DeleteMapping
(
value
=
"/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
)
{
pictureService
.
delete
(
pictureService
.
findById
(
id
));
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
/**
* 删除多张图片
* @param ids
* @return
*/
@Log
(
"删除图片"
)
@Log
(
"多选删除图片"
)
@ApiOperation
(
value
=
"多选删除图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')"
)
@DeleteMapping
(
value
=
"/pictures"
)
@DeleteMapping
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
pictureService
.
deleteAll
(
ids
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/QiniuController.java
View file @
f0211db0
package
me.zhengjie.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.domain.QiniuConfig
;
import
me.zhengjie.domain.QiniuContent
;
import
me.zhengjie.service.QiNiuService
;
import
me.zhengjie.service.dto.QiniuQueryCriteria
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -24,17 +25,22 @@ import java.util.Map;
@Slf4j
@RestController
@RequestMapping
(
"api"
)
@Api
(
tags
=
"七牛云存储管理"
)
public
class
QiniuController
{
@Autowired
private
QiNiuService
qiNiuService
;
private
final
QiNiuService
qiNiuService
;
public
QiniuController
(
QiNiuService
qiNiuService
)
{
this
.
qiNiuService
=
qiNiuService
;
}
@GetMapping
(
value
=
"/qiNiuConfig"
)
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
qiNiuService
.
find
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
qiNiuService
.
find
(),
HttpStatus
.
OK
);
}
@Log
(
"配置七牛云存储"
)
@ApiOperation
(
value
=
"配置七牛云存储"
)
@PutMapping
(
value
=
"/qiNiuConfig"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
QiniuConfig
qiniuConfig
){
qiNiuService
.
update
(
qiniuConfig
);
...
...
@@ -43,72 +49,51 @@ public class QiniuController {
}
@Log
(
"查询文件"
)
@ApiOperation
(
value
=
"查询文件"
)
@GetMapping
(
value
=
"/qiNiuContent"
)
public
ResponseEntity
getRoles
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
(
qiNiuService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
qiNiuService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
/**
* 上传文件到七牛云
* @param file
* @return
*/
@Log
(
"上传文件"
)
@ApiOperation
(
value
=
"上传文件"
)
@PostMapping
(
value
=
"/qiNiuContent"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
QiniuContent
qiniuContent
=
qiNiuService
.
upload
(
file
,
qiNiuService
.
find
());
Map
map
=
new
HashMap
(
3
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>
(
3
);
map
.
put
(
"id"
,
qiniuContent
.
getId
());
map
.
put
(
"errno"
,
0
);
map
.
put
(
"data"
,
new
String
[]{
qiniuContent
.
getUrl
()});
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
map
,
HttpStatus
.
OK
);
}
/**
* 同步七牛云数据到数据库
* @return
*/
@Log
(
"同步七牛云数据"
)
@ApiOperation
(
value
=
"同步七牛云数据"
)
@PostMapping
(
value
=
"/qiNiuContent/synchronize"
)
public
ResponseEntity
synchronize
(){
log
.
warn
(
"REST request to synchronize qiNiu : {}"
);
qiNiuService
.
synchronize
(
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
/**
* 下载七牛云文件
* @param id
* @return
* @throws Exception
*/
@Log
(
"下载文件"
)
@ApiOperation
(
value
=
"下载文件"
)
@GetMapping
(
value
=
"/qiNiuContent/download/{id}"
)
public
ResponseEntity
download
(
@PathVariable
Long
id
){
Map
map
=
new
HashMap
(
1
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>
(
1
);
map
.
put
(
"url"
,
qiNiuService
.
download
(
qiNiuService
.
findByContentId
(
id
),
qiNiuService
.
find
()));
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>
(
map
,
HttpStatus
.
OK
);
}
/**
* 删除七牛云文件
* @param id
* @return
* @throws Exception
*/
@Log
(
"删除文件"
)
@ApiOperation
(
value
=
"删除文件"
)
@DeleteMapping
(
value
=
"/qiNiuContent/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
qiNiuService
.
delete
(
qiNiuService
.
findByContentId
(
id
),
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
/**
* 删除多张图片
* @param ids
* @return
*/
@Log
(
"删除图片"
)
@Log
(
"删除多张图片"
)
@ApiOperation
(
value
=
"删除多张图片"
)
@DeleteMapping
(
value
=
"/qiNiuContent"
)
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
qiNiuService
.
deleteAll
(
ids
,
qiNiuService
.
find
());
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/VerificationCodeController.java
View file @
f0211db0
package
me.zhengjie.rest
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.domain.VerificationCode
;
import
me.zhengjie.domain.vo.EmailVo
;
import
me.zhengjie.service.EmailService
;
import
me.zhengjie.service.VerificationCodeService
;
import
me.zhengjie.utils.ElAdminConstant
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -18,19 +19,20 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@RequestMapping
(
"api"
)
@Api
(
tags
=
"验证码管理"
)
public
class
VerificationCodeController
{
@Autowired
private
VerificationCodeService
verificationCodeService
;
private
final
VerificationCodeService
verificationCodeService
;
@Autowired
@Qualifier
(
"jwtUserDetailsService"
)
private
UserDetailsService
userDetailsService
;
private
final
EmailService
emailService
;
@Autowired
private
EmailService
emailService
;
public
VerificationCodeController
(
VerificationCodeService
verificationCodeService
,
@Qualifier
(
"jwtUserDetailsService"
)
UserDetailsService
userDetailsService
,
EmailService
emailService
)
{
this
.
verificationCodeService
=
verificationCodeService
;
this
.
emailService
=
emailService
;
}
@PostMapping
(
value
=
"/code/resetEmail"
)
@ApiOperation
(
value
=
"重置邮箱,发送验证码"
)
public
ResponseEntity
resetEmail
(
@RequestBody
VerificationCode
code
)
throws
Exception
{
code
.
setScenes
(
ElAdminConstant
.
RESET_MAIL
);
EmailVo
emailVo
=
verificationCodeService
.
sendEmail
(
code
);
...
...
@@ -39,6 +41,7 @@ public class VerificationCodeController {
}
@PostMapping
(
value
=
"/code/email/resetPass"
)
@ApiOperation
(
value
=
"重置密码,发送验证码"
)
public
ResponseEntity
resetPass
(
@RequestParam
String
email
)
throws
Exception
{
VerificationCode
code
=
new
VerificationCode
();
code
.
setType
(
"email"
);
...
...
@@ -50,6 +53,7 @@ public class VerificationCodeController {
}
@GetMapping
(
value
=
"/code/validated"
)
@ApiOperation
(
value
=
"验证码验证"
)
public
ResponseEntity
validated
(
VerificationCode
code
){
verificationCodeService
.
validated
(
code
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/AlipayService.java
View file @
f0211db0
...
...
@@ -15,33 +15,33 @@ public interface AlipayService {
/**
* 处理来自PC的交易请求
* @param alipay
* @param trade
* @return
* @throws Exception
* @param alipay
支付宝配置
* @param trade
交易详情
* @return
String
* @throws Exception
异常
*/
String
toPayAsPC
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
;
/**
* 处理来自手机网页的交易请求
* @param alipay
* @param trade
* @return
* @throws Exception
* @param alipay
支付宝配置
* @param trade
交易详情
* @return
String
* @throws Exception
异常
*/
String
toPayAsWeb
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
;
/**
* 查询配置
* @return
* @return
AlipayConfig
*/
@Cacheable
(
key
=
"'1'"
)
AlipayConfig
find
();
/**
* 更新配置
* @param alipayConfig
* @return
* @param alipayConfig
支付宝配置
* @return
AlipayConfig
*/
@CachePut
(
key
=
"'1'"
)
AlipayConfig
update
(
AlipayConfig
alipayConfig
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/EmailService.java
View file @
f0211db0
...
...
@@ -16,24 +16,24 @@ public interface EmailService {
/**
* 更新邮件配置
* @param emailConfig
* @param old
* @return
* @param emailConfig
邮件配置
* @param old
旧的配置
* @return
EmailConfig
*/
@CachePut
(
key
=
"'1'"
)
EmailConfig
update
(
EmailConfig
emailConfig
,
EmailConfig
old
);
/**
* 查询配置
* @return
* @return
EmailConfig 邮件配置
*/
@Cacheable
(
key
=
"'1'"
)
EmailConfig
find
();
/**
* 发送邮件
* @param emailVo
* @param emailConfig
* @param emailVo
邮件发送的内容
* @param emailConfig
邮件配置
* @throws Exception
*/
@Async
...
...
eladmin-tools/src/main/java/me/zhengjie/service/LocalStorageService.java
View file @
f0211db0
...
...
@@ -18,52 +18,56 @@ public interface LocalStorageService {
/**
* queryAll 分页
* @param criteria
* @param pageable
* @return
* @param criteria
条件参数
* @param pageable
分页参数
* @return
Object
*/
@Cacheable
Object
queryAll
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
);
/**
* queryAll 不分页
* @param criteria
* @return
* @param criteria
条件参数
* @return
Object
*/
@Cacheable
public
Object
queryAll
(
LocalStorageQueryCriteria
criteria
);
Object
queryAll
(
LocalStorageQueryCriteria
criteria
);
/**
* findById
* @param id
* @return
* @return
LocalStorageDTO
*/
@Cacheable
(
key
=
"#p0"
)
LocalStorageDTO
findById
(
Long
id
);
/**
* create
* @param name
* @param file
* @return
* @param name
文件名称
* @param file
文件资源
* @return
LocalStorageDTO
*/
@CacheEvict
(
allEntries
=
true
)
LocalStorageDTO
create
(
String
name
,
MultipartFile
file
);
/**
* update
* @param resources
* @param resources
资源实体
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
LocalStorage
resources
);
/**
* delete
* @param id
* @param id
文件ID
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
/**
* 多文件删除
* @param ids 文件数组
*/
@CacheEvict
(
allEntries
=
true
)
void
deleteAll
(
Long
[]
ids
);
}
\ No newline at end of file
eladmin-tools/src/main/java/me/zhengjie/service/PictureService.java
View file @
f0211db0
...
...
@@ -16,17 +16,17 @@ public interface PictureService {
/**
* 查询图片
* @param criteria
* @param pageable
* @return
* @param criteria
条件参数
* @param pageable
分页参数
* @return
Object
*/
@Cacheable
Object
queryAll
(
PictureQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 上传图片
* @param file
* @param username
* @param file
文件
* @param username
用户名
* @return
*/
@CacheEvict
(
allEntries
=
true
)
...
...
@@ -34,7 +34,7 @@ public interface PictureService {
/**
* 根据ID查询
* @param id
* @param id
文件ID
* @return
*/
@Cacheable
(
key
=
"#p0"
)
...
...
@@ -42,14 +42,14 @@ public interface PictureService {
/**
* 删除图片
* @param picture
* @param picture
图片实体
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Picture
picture
);
/**
* 删除图片
* @param ids
* @param ids
文件ID数组
*/
@CacheEvict
(
allEntries
=
true
)
void
deleteAll
(
Long
[]
ids
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/QiNiuService.java
View file @
f0211db0
...
...
@@ -20,16 +20,16 @@ public interface QiNiuService {
/**
* 查询文件
* @param criteria
* @param pageable
* @return
* @param criteria
条件参数
* @param pageable
分页参数
* @return
Object
*/
@Cacheable
Object
queryAll
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 查配置
* @return
* @return
Cacheable
*/
@Cacheable
(
cacheNames
=
"qiNiuConfig"
,
key
=
"'1'"
)
QiniuConfig
find
();
...
...
@@ -37,7 +37,7 @@ public interface QiNiuService {
/**
* 修改配置
* @param qiniuConfig
* @return
* @return
QiniuConfig
*/
@CachePut
(
cacheNames
=
"qiNiuConfig"
,
key
=
"'1'"
)
QiniuConfig
update
(
QiniuConfig
qiniuConfig
);
...
...
@@ -46,7 +46,7 @@ public interface QiNiuService {
* 上传文件
* @param file
* @param qiniuConfig
* @return
* @return
QiniuContent
*/
@CacheEvict
(
allEntries
=
true
)
QiniuContent
upload
(
MultipartFile
file
,
QiniuConfig
qiniuConfig
);
...
...
@@ -54,7 +54,7 @@ public interface QiNiuService {
/**
* 查询文件
* @param id
* @return
* @return
QiniuContent
*/
@Cacheable
(
key
=
"'content:'+#p0"
)
QiniuContent
findByContentId
(
Long
id
);
...
...
@@ -63,34 +63,37 @@ public interface QiNiuService {
* 下载文件
* @param content
* @param config
* @return
* @return
String
*/
String
download
(
QiniuContent
content
,
QiniuConfig
config
);
/**
* 删除文件
* @param content
* @param config
* @return
* @param content 文件
* @param config 配置
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
QiniuContent
content
,
QiniuConfig
config
);
/**
* 同步数据
* @param config
* @param config
配置
*/
@CacheEvict
(
allEntries
=
true
)
void
synchronize
(
QiniuConfig
config
);
/**
* 删除文件
* @param ids
* @param config
* @param ids
文件ID数组
* @param config
配置
*/
@CacheEvict
(
allEntries
=
true
)
void
deleteAll
(
Long
[]
ids
,
QiniuConfig
config
);
/**
* 更新数据
* @param type 类型
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
String
type
);
}
eladmin-tools/src/main/java/me/zhengjie/service/VerificationCodeService.java
View file @
f0211db0
...
...
@@ -11,13 +11,14 @@ public interface VerificationCodeService {
/**
* 发送邮件验证码
* @param code
* @param code 验证码
* @return EmailVo
*/
EmailVo
sendEmail
(
VerificationCode
code
);
/**
* 验证
* @param code
* @param code
验证码
*/
void
validated
(
VerificationCode
code
);
}
eladmin-tools/src/main/java/me/zhengjie/service/impl/AlipayServiceImpl.java
View file @
f0211db0
...
...
@@ -40,19 +40,13 @@ public class AlipayServiceImpl implements AlipayService {
double
money
=
Double
.
parseDouble
(
trade
.
getTotalAmount
());
/**
* 创建API对应的request(电脑网页版)
*/
// 创建API对应的request(电脑网页版)
AlipayTradePagePayRequest
request
=
new
AlipayTradePagePayRequest
();
/**
* 订单完成后返回的页面和异步通知地址
*/
// 订单完成后返回的页面和异步通知地址
request
.
setReturnUrl
(
alipay
.
getReturnUrl
());
request
.
setNotifyUrl
(
alipay
.
getNotifyUrl
());
/**
* 填充订单参数
*/
// 填充订单参数
request
.
setBizContent
(
"{"
+
" \"out_trade_no\":\""
+
trade
.
getOutTradeNo
()+
"\","
+
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\","
+
...
...
@@ -63,10 +57,7 @@ public class AlipayServiceImpl implements AlipayService {
" \"sys_service_provider_id\":\""
+
alipay
.
getSysServiceProviderId
()+
"\""
+
" }"
+
" }"
);
//填充业务参数
/**
* 调用SDK生成表单
* 通过GET方式,口可以获取url
*/
// 调用SDK生成表单, 通过GET方式,口可以获取url
return
alipayClient
.
pageExecute
(
request
,
"GET"
).
getBody
();
}
...
...
@@ -82,20 +73,10 @@ public class AlipayServiceImpl implements AlipayService {
if
(
money
<=
0
||
money
>=
5000
){
throw
new
BadRequestException
(
"测试金额过大"
);
}
/**
* 创建API对应的request(手机网页版)
*/
// 创建API对应的request(手机网页版)
AlipayTradeWapPayRequest
request
=
new
AlipayTradeWapPayRequest
();
/**
* 订单完成后返回的页面和异步通知地址
*/
request
.
setReturnUrl
(
alipay
.
getReturnUrl
());
request
.
setNotifyUrl
(
alipay
.
getNotifyUrl
());
/**
* 填充订单参数
*/
request
.
setBizContent
(
"{"
+
" \"out_trade_no\":\""
+
trade
.
getOutTradeNo
()+
"\","
+
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\","
+
...
...
@@ -106,21 +87,13 @@ public class AlipayServiceImpl implements AlipayService {
" \"sys_service_provider_id\":\""
+
alipay
.
getSysServiceProviderId
()+
"\""
+
" }"
+
" }"
);
//填充业务参数
/**
* 调用SDK生成表单
* 通过GET方式,口可以获取url
*/
return
alipayClient
.
pageExecute
(
request
,
"GET"
).
getBody
();
}
@Override
public
AlipayConfig
find
()
{
Optional
<
AlipayConfig
>
alipayConfig
=
alipayRepository
.
findById
(
1L
);
if
(
alipayConfig
.
isPresent
()){
return
alipayConfig
.
get
();
}
else
{
return
new
AlipayConfig
();
}
return
alipayConfig
.
orElseGet
(
AlipayConfig:
:
new
);
}
@Override
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java
View file @
f0211db0
...
...
@@ -2,15 +2,12 @@ package me.zhengjie.service.impl;
import
cn.hutool.extra.mail.Mail
;
import
cn.hutool.extra.mail.MailAccount
;
import
cn.hutool.extra.mail.MailUtil
;
import
me.zhengjie.domain.EmailConfig
;
import
me.zhengjie.domain.vo.EmailVo
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.repository.EmailRepository
;
import
me.zhengjie.service.EmailService
;
import
me.zhengjie.utils.ElAdminConstant
;
import
me.zhengjie.utils.EncryptUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -24,8 +21,11 @@ import java.util.Optional;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
EmailServiceImpl
implements
EmailService
{
@Autowired
private
EmailRepository
emailRepository
;
private
final
EmailRepository
emailRepository
;
public
EmailServiceImpl
(
EmailRepository
emailRepository
)
{
this
.
emailRepository
=
emailRepository
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
...
...
@@ -44,11 +44,7 @@ public class EmailServiceImpl implements EmailService {
@Override
public
EmailConfig
find
()
{
Optional
<
EmailConfig
>
emailConfig
=
emailRepository
.
findById
(
1L
);
if
(
emailConfig
.
isPresent
()){
return
emailConfig
.
get
();
}
else
{
return
new
EmailConfig
();
}
return
emailConfig
.
orElseGet
(
EmailConfig:
:
new
);
}
@Override
...
...
@@ -57,9 +53,7 @@ public class EmailServiceImpl implements EmailService {
if
(
emailConfig
==
null
){
throw
new
BadRequestException
(
"请先配置,再操作"
);
}
/**
* 封装
*/
// 封装
MailAccount
account
=
new
MailAccount
();
account
.
setHost
(
emailConfig
.
getHost
());
account
.
setPort
(
Integer
.
parseInt
(
emailConfig
.
getPort
()));
...
...
@@ -71,15 +65,14 @@ public class EmailServiceImpl implements EmailService {
throw
new
BadRequestException
(
e
.
getMessage
());
}
account
.
setFrom
(
emailConfig
.
getUser
()+
"<"
+
emailConfig
.
getFromUser
()+
">"
);
//ssl方式发送
//
ssl方式发送
account
.
setSslEnable
(
true
);
String
content
=
emailVo
.
getContent
();
/**
* 发送
*/
// 发送
try
{
int
size
=
emailVo
.
getTos
().
size
();
Mail
.
create
(
account
)
.
setTos
(
emailVo
.
getTos
().
toArray
(
new
String
[
emailVo
.
getTos
().
size
()
]))
.
setTos
(
emailVo
.
getTos
().
toArray
(
new
String
[
size
]))
.
setTitle
(
emailVo
.
getSubject
())
.
setContent
(
content
)
.
setHtml
(
true
)
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java
View file @
f0211db0
package
me.zhengjie.service.impl
;
import
me.zhengjie.domain.LocalStorage
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.utils.*
;
import
me.zhengjie.repository.LocalStorageRepository
;
import
me.zhengjie.service.LocalStorageService
;
import
me.zhengjie.service.dto.LocalStorageDTO
;
import
me.zhengjie.service.dto.LocalStorageQueryCriteria
;
import
me.zhengjie.service.mapper.LocalStorageMapper
;
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.io.File
;
import
java.util.Optional
;
import
org.springframework.data.domain.Page
;
...
...
@@ -28,11 +25,9 @@ import org.springframework.web.multipart.MultipartFile;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
LocalStorageServiceImpl
implements
LocalStorageService
{
@Autowired
private
LocalStorageRepository
localStorageRepository
;
private
final
LocalStorageRepository
localStorageRepository
;
@Autowired
private
LocalStorageMapper
localStorageMapper
;
private
final
LocalStorageMapper
localStorageMapper
;
@Value
(
"${file.path}"
)
private
String
path
;
...
...
@@ -40,6 +35,11 @@ public class LocalStorageServiceImpl implements LocalStorageService {
@Value
(
"${file.maxSize}"
)
private
long
maxSize
;
public
LocalStorageServiceImpl
(
LocalStorageRepository
localStorageRepository
,
LocalStorageMapper
localStorageMapper
)
{
this
.
localStorageRepository
=
localStorageRepository
;
this
.
localStorageMapper
=
localStorageMapper
;
}
@Override
public
Object
queryAll
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
){
Page
<
LocalStorage
>
page
=
localStorageRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
...
...
@@ -85,11 +85,6 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
}
public
static
void
main
(
String
[]
args
)
{
File
file
=
new
File
(
"C:\\Users\\Jie\\Pictures\\Saved Pictures\\demo1.jpg"
);
System
.
out
.
println
(
FileUtil
.
getType
(
file
));
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
LocalStorage
resources
)
{
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/PictureServiceImpl.java
View file @
f0211db0
...
...
@@ -30,14 +30,17 @@ import java.util.Optional;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
PictureServiceImpl
implements
PictureService
{
@Autowired
private
PictureRepository
pictureRepository
;
private
final
PictureRepository
pictureRepository
;
p
ublic
static
final
String
SUCCESS
=
"success"
;
p
rivate
static
final
String
SUCCESS
=
"success"
;
p
ublic
static
final
String
CODE
=
"code"
;
p
rivate
static
final
String
CODE
=
"code"
;
public
static
final
String
MSG
=
"message"
;
private
static
final
String
MSG
=
"message"
;
public
PictureServiceImpl
(
PictureRepository
pictureRepository
)
{
this
.
pictureRepository
=
pictureRepository
;
}
@Override
public
Object
queryAll
(
PictureQueryCriteria
criteria
,
Pageable
pageable
){
...
...
@@ -60,7 +63,7 @@ public class PictureServiceImpl implements PictureService {
}
//转成实体类
picture
=
JSON
.
parseObject
(
jsonObject
.
get
(
"data"
).
toString
(),
Picture
.
class
);
picture
.
setSize
(
FileUtil
.
getSize
(
Integer
.
valueOf
(
picture
.
getSize
())));
picture
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
picture
.
getSize
())));
picture
.
setUsername
(
username
);
picture
.
setFilename
(
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
())+
"."
+
FileUtil
.
getExtensionName
(
multipartFile
.
getOriginalFilename
()));
pictureRepository
.
save
(
picture
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java
View file @
f0211db0
...
...
@@ -29,6 +29,7 @@ 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
;
/**
...
...
@@ -39,17 +40,18 @@ import java.util.Optional;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
QiNiuServiceImpl
implements
QiNiuService
{
@Autowired
private
QiNiuConfigRepository
qiNiuConfigRepository
;
private
final
QiNiuConfigRepository
qiNiuConfigRepository
;
@Autowired
private
QiniuContentRepository
qiniuContentRepository
;
private
final
QiniuContentRepository
qiniuContentRepository
;
public
QiNiuServiceImpl
(
QiNiuConfigRepository
qiNiuConfigRepository
,
QiniuContentRepository
qiniuContentRepository
)
{
this
.
qiNiuConfigRepository
=
qiNiuConfigRepository
;
this
.
qiniuContentRepository
=
qiniuContentRepository
;
}
@Value
(
"${qiniu.max-size}"
)
private
Long
maxSize
;
private
final
String
TYPE
=
"公开"
;
@Override
public
Object
queryAll
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
){
return
PageUtil
.
toPage
(
qiniuContentRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
));
...
...
@@ -58,11 +60,7 @@ public class QiNiuServiceImpl implements QiNiuService {
@Override
public
QiniuConfig
find
()
{
Optional
<
QiniuConfig
>
qiniuConfig
=
qiNiuConfigRepository
.
findById
(
1L
);
if
(
qiniuConfig
.
isPresent
()){
return
qiniuConfig
.
get
();
}
else
{
return
new
QiniuConfig
();
}
return
qiniuConfig
.
orElseGet
(
QiniuConfig:
:
new
);
}
@Override
...
...
@@ -82,9 +80,7 @@ public class QiNiuServiceImpl implements QiNiuService {
if
(
qiniuConfig
.
getId
()
==
null
){
throw
new
BadRequestException
(
"请先添加相应配置,再操作"
);
}
/**
* 构造一个带指定Zone对象的配置类
*/
// 构造一个带指定Zone对象的配置类
Configuration
cfg
=
new
Configuration
(
QiNiuUtil
.
getRegion
(
qiniuConfig
.
getZone
()));
UploadManager
uploadManager
=
new
UploadManager
(
cfg
);
Auth
auth
=
Auth
.
create
(
qiniuConfig
.
getAccessKey
(),
qiniuConfig
.
getSecretKey
());
...
...
@@ -122,13 +118,12 @@ public class QiNiuServiceImpl implements QiNiuService {
@Override
public
String
download
(
QiniuContent
content
,
QiniuConfig
config
){
String
finalUrl
=
null
;
String
TYPE
=
"公开"
;
if
(
TYPE
.
equals
(
content
.
getType
())){
finalUrl
=
content
.
getUrl
();
}
else
{
Auth
auth
=
Auth
.
create
(
config
.
getAccessKey
(),
config
.
getSecretKey
());
/**
* 1小时,可以自定义链接过期时间
*/
// 1小时,可以自定义链接过期时间
long
expireInSeconds
=
3600
;
finalUrl
=
auth
.
privateDownloadUrl
(
content
.
getUrl
(),
expireInSeconds
);
}
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/VerificationCodeServiceImpl.java
View file @
f0211db0
...
...
@@ -17,6 +17,7 @@ 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.*
;
/**
...
...
@@ -45,12 +46,12 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
if
(
verificationCode
==
null
){
code
.
setCode
(
RandomUtil
.
randomNumbers
(
6
));
content
=
template
.
render
(
Dict
.
create
().
set
(
"code"
,
code
.
getCode
()));
emailVo
=
new
EmailVo
(
Arrays
.
as
List
(
code
.
getValue
()),
"eladmin后台管理系统"
,
content
);
emailVo
=
new
EmailVo
(
Collections
.
singleton
List
(
code
.
getValue
()),
"eladmin后台管理系统"
,
content
);
timedDestruction
(
verificationCodeRepository
.
save
(
code
));
// 存在就再次发送原来的验证码
}
else
{
content
=
template
.
render
(
Dict
.
create
().
set
(
"code"
,
verificationCode
.
getCode
()));
emailVo
=
new
EmailVo
(
Arrays
.
as
List
(
verificationCode
.
getValue
()),
"eladmin后台管理系统"
,
content
);
emailVo
=
new
EmailVo
(
Collections
.
singleton
List
(
verificationCode
.
getValue
()),
"eladmin后台管理系统"
,
content
);
}
return
emailVo
;
}
...
...
@@ -68,7 +69,7 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
/**
* 定时任务,指定分钟后改变验证码状态
* @param verifyCode
* @param verifyCode
验证码
*/
private
void
timedDestruction
(
VerificationCode
verifyCode
)
{
//以下示例为程序调用结束继续运行
...
...
eladmin-tools/src/main/java/me/zhengjie/utils/AliPayStatusEnum.java
View file @
f0211db0
...
...
@@ -27,11 +27,9 @@ public enum AliPayStatusEnum {
*/
CLOSED
(
"交易关闭"
,
"TRADE_CLOSED"
);
private
String
name
;
private
String
value
;
AliPayStatusEnum
(
String
name
,
String
value
)
{
this
.
name
=
name
;
this
.
value
=
value
;
}
...
...
eladmin-tools/src/main/java/me/zhengjie/utils/AlipayUtils.java
View file @
f0211db0
...
...
@@ -22,7 +22,6 @@ public class AlipayUtils {
/**
* 生成订单号
* @return
*/
public
String
getOrderCode
()
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
...
...
@@ -35,24 +34,19 @@ public class AlipayUtils {
String
[]
split1
=
s
.
split
(
" "
);
String
s1
=
split1
[
0
]
+
split1
[
1
];
String
[]
split2
=
s1
.
split
(
":"
);
String
s2
=
split2
[
0
]
+
split2
[
1
]
+
split2
[
2
]
+
a
;
return
s2
;
return
split2
[
0
]
+
split2
[
1
]
+
split2
[
2
]
+
a
;
}
/**
* 校验签名
* @param request
* @return
*/
public
boolean
rsaCheck
(
HttpServletRequest
request
,
AlipayConfig
alipay
){
/**
* 获取支付宝POST过来反馈信息
*/
// 获取支付宝POST过来反馈信息
Map
<
String
,
String
>
params
=
new
HashMap
<>(
1
);
Map
requestParams
=
request
.
getParameterMap
();
for
(
Iterator
iter
=
requestParams
.
keySet
()
.
iterator
();
iter
.
hasNext
();
)
{
String
name
=
(
String
)
iter
.
next
()
;
for
(
Object
o
:
requestParams
.
keySet
())
{
String
name
=
(
String
)
o
;
String
[]
values
=
(
String
[])
requestParams
.
get
(
name
);
String
valueStr
=
""
;
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
...
...
@@ -63,11 +57,10 @@ public class AlipayUtils {
}
try
{
boolean
verifyResult
=
AlipaySignature
.
rsaCheckV1
(
params
,
return
AlipaySignature
.
rsaCheckV1
(
params
,
alipay
.
getPublicKey
(),
alipay
.
getCharset
(),
alipay
.
getSignType
());
return
verifyResult
;
}
catch
(
AlipayApiException
e
)
{
return
false
;
}
...
...
eladmin-tools/src/main/java/me/zhengjie/utils/QiNiuUtil.java
View file @
f0211db0
...
...
@@ -11,18 +11,16 @@ import java.util.Date;
*/
public
class
QiNiuUtil
{
p
ublic
static
final
String
HUAD
=
"华东"
;
p
rivate
static
final
String
HUAD
=
"华东"
;
p
ublic
static
final
String
HUAB
=
"华北"
;
p
rivate
static
final
String
HUAB
=
"华北"
;
p
ublic
static
final
String
HUAN
=
"华南"
;
p
rivate
static
final
String
HUAN
=
"华南"
;
p
ublic
static
final
String
BEIM
=
"北美"
;
p
rivate
static
final
String
BEIM
=
"北美"
;
/**
* 得到机房的对应关系
* @param zone
* @return
*/
public
static
Region
getRegion
(
String
zone
){
...
...
@@ -42,17 +40,13 @@ public class QiNiuUtil {
/**
* 默认不指定key的情况下,以文件内容的hash值作为文件名
* @param file
* @return
*/
public
static
String
getKey
(
String
file
){
StringBuffer
key
=
new
StringBuffer
(
FileUtil
.
getFileNameNoEx
(
file
));
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
Date
date
=
new
Date
();
key
.
append
(
"-"
);
key
.
append
(
sdf
.
format
(
date
));
key
.
append
(
"."
);
key
.
append
(
FileUtil
.
getExtensionName
(
file
));
return
key
.
toString
();
return
FileUtil
.
getFileNameNoEx
(
file
)
+
"-"
+
sdf
.
format
(
date
)
+
"."
+
FileUtil
.
getExtensionName
(
file
);
}
}
Prev
1
2
3
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