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
"src/vscode:/vscode.git/clone" did not exist on "1353f7b09eb5fbbe13c509cb86f21abade8e9f97"
Commit
bf7c1eeb
authored
Oct 24, 2019
by
dqjdda
Browse files
代码优化完成,去除大量idea警告,代码生成器优化等
parent
e3c3ebb1
Changes
146
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/resources/template/generator/admin/Repository.ftl
View file @
bf7c1eeb
...
...
@@ -8,16 +8,11 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
*
@author $
{
author
}
*
@date $
{
date
}
*/
public
interface $
{
className
}
Repository extends JpaRepository<$
{
className
}
, $
{
pkColumnType
}
>, JpaSpecificationExecutor
{
public
interface $
{
className
}
Repository extends JpaRepository<$
{
className
}
, $
{
pkColumnType
}
>, JpaSpecificationExecutor
<$
{
className
}
>
{
<#
if
columns
??>
<#
list
columns
as
column
>
<#
if
column
.columnKey
=
'
UNI
'>
/
**
*
findBy
$
{
column
.capitalColumnName
}
*
@
param
$
{
column
.columnName
}
*
@
return
*
/
$
{
className
}
findBy
$
{
column
.capitalColumnName
}(
$
{
column
.columnType
}
$
{
column
.columnName
})
;
</#
if
>
</#
list
>
...
...
eladmin-system/src/main/resources/template/generator/admin/Service.ftl
View file @
bf7c1eeb
...
...
@@ -3,9 +3,6 @@ package ${package}.service;
import
$
{
package
}
.domain.$
{
className
}
;
import
$
{
package
}
.service.dto.$
{
className
}
DTO;
import
$
{
package
}
.service.dto.$
{
className
}
QueryCriteria;
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
java.util.Map;
import
java.util.List;
...
...
@@ -14,53 +11,33 @@ import java.util.List;
*
@author $
{
author
}
*
@date $
{
date
}
*/
//@
CacheConfig
(
cacheNames
=
"$
{
changeClassName
}
")
public
interface $
{
className
}
Service
{
/
**
*
查询数据分页
*
@
param
criteria
*
@
param
pageable
*
@
return
*
@
param
criteria
条件参数
*
@
param
pageable
分页参数
*
@
return
M
ap
<
S
tring
,
O
bject
>
*
/
//@
C
acheable
M
ap
<
S
tring
,
O
bject
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
)
;
/
**
*
查询所有数据不分页
*
@
param
criteria
*
@
return
*
@
param
criteria
条件参数
*
@
return
L
ist
<$
{
className
}
DTO
>
*
/
//@
C
acheable
L
ist
<$
{
className
}
DTO
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
)
;
/
**
*
根据
ID
查询
*
@
param
$
{
pkChangeColName
}
*
@
return
*
@
param
$
{
pkChangeColName
}
ID
*
@
return
$
{
className
}
DTO
*
/
//@
C
acheable
(
key
=
"#p0"
)
$
{
className
}
DTO
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
;
/
**
*
创建
*
@
param
resources
*
@
return
*
/
//@
C
acheEvict
(
allEntries
=
true
)
$
{
className
}
DTO
create
(
$
{
className
}
resources
)
;
/
**
*
编辑
*
@
param
resources
*
/
//@
C
acheEvict
(
allEntries
=
true
)
void
update
(
$
{
className
}
resources
)
;
/
**
*
删除
*
@
param
$
{
pkChangeColName
}
*
/
//@
C
acheEvict
(
allEntries
=
true
)
void
delete
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
;
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/admin/ServiceImpl.ftl
View file @
bf7c1eeb
...
...
@@ -16,11 +16,9 @@ import ${package}.service.${className}Service;
import
$
{
package
}
.service.dto.$
{
className
}
DTO;
import
$
{
package
}
.service.dto.$
{
className
}
QueryCriteria;
import
$
{
package
}
.service.mapper.$
{
className
}
Mapper;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional;
import
java.util.Optional;
<#
if
!auto && pkColumnType = 'Long'>
import
cn.hutool.core.lang.Snowflake;
import
cn.hutool.core.util.IdUtil;
...
...
@@ -28,6 +26,9 @@ import cn.hutool.core.util.IdUtil;
<#
if
!auto && pkColumnType = 'String'>
import
cn.hutool.core.util.IdUtil;
</#
if
>
import
org.springframework.cache.annotation.CacheConfig;
import
org.springframework.cache.annotation.CacheEvict;
import
org.springframework.cache.annotation.Cacheable;
import
org.springframework.data.domain.Page;
import
org.springframework.data.domain.Pageable;
import
me.zhengjie.utils.PageUtil;
...
...
@@ -40,34 +41,42 @@ import java.util.Map;
*
@date $
{
date
}
*/
@
Service
@
CacheConfig
(
cacheNames
=
"$
{
changeClassName
}
")
@
Transactional
(
propagation
=
Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public
class $
{
className
}
ServiceImpl implements $
{
className
}
Service
{
@
A
utowired
private
$
{
className
}
R
epository
$
{
changeClassName
}
R
epository
;
private
final
$
{
className
}
R
epository
$
{
changeClassName
}
R
epository
;
@
A
utowired
private
$
{
className
}
M
apper
$
{
changeClassName
}
M
apper
;
private
final
$
{
className
}
M
apper
$
{
changeClassName
}
M
apper
;
public
$
{
className
}
S
erviceImpl
(
$
{
className
}
R
epository
$
{
changeClassName
}
R
epository
,
$
{
className
}
M
apper
$
{
changeClassName
}
M
apper
)
{
this
.$
{
changeClassName
}
R
epository
=
$
{
changeClassName
}
R
epository
;
this
.$
{
changeClassName
}
M
apper
=
$
{
changeClassName
}
M
apper
;
}
@
O
verride
@
C
acheable
public
M
ap
<
S
tring
,
O
bject
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
){
P
age
<$
{
className
}
>
page
=
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
)
;
return
P
ageUtil
.toPage
(
page
.map
(
$
{
changeClassName
}
M
apper
::
toDto
))
;
}
@
O
verride
@
C
acheable
public
L
ist
<$
{
className
}
DTO
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
){
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
)))
;
}
@
O
verride
@
C
acheable
(
key
=
"#p0"
)
public
$
{
className
}
DTO
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
O
ptional
<
$
{
className
}
>
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
$
{
pkChangeColName
})
;
V
alidationUtil
.isNull
(
$
{
changeClassName
},
"${className}"
,
"${pkChangeColName}"
,
$
{
pkChangeColName
})
;
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
}
.get
()
)
;
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
$
{
pkChangeColName
})
.orElseGet
(
$
{
className
}::
new
)
;
V
alidationUtil
.isNull
(
$
{
changeClassName
}
.get
$
{
pkCapitalColName
}()
,
"${className}"
,
"${pkChangeColName}"
,
$
{
pkChangeColName
})
;
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
})
;
}
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
$
{
className
}
DTO
create
(
$
{
className
}
resources
)
{
<#
if
!
auto
&&
pkColumnType
=
'
L
ong
'>
...
...
@@ -90,11 +99,11 @@ public class ${className}ServiceImpl implements ${className}Service {
}
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
void
update
(
$
{
className
}
resources
)
{
O
ptional
<$
{
className
}
>
optional
$
{
className
}
=
$
{
changeClassName
}
R
epository
.findById
(
resources
.get
$
{
pkCapitalColName
}())
;
V
alidationUtil
.isNull
(
optional
$
{
className
},
"${className}"
,
"id"
,
resources
.get
$
{
pkCapitalColName
}())
;
$
{
className
}
$
{
changeClassName
}
=
optional
$
{
className
}
.get
()
;
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
resources
.get
$
{
pkCapitalColName
}())
.orElseGet
(
$
{
className
}::
new
)
;
V
alidationUtil
.isNull
(
$
{
changeClassName
}
.get
$
{
pkCapitalColName
}(),
"${className}"
,
"id"
,
resources
.get
$
{
pkCapitalColName
}())
;
<#
if
columns
??>
<#
list
columns
as
column
>
<#
if
column
.columnKey
=
'
UNI
'>
...
...
@@ -113,6 +122,7 @@ public class ${className}ServiceImpl implements ${className}Service {
}
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
void
delete
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
$
{
changeClassName
}
R
epository
.deleteById
(
$
{
pkChangeColName
})
;
...
...
eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java
View file @
bf7c1eeb
...
...
@@ -13,6 +13,5 @@ public class EladminSystemApplicationTests {
public
void
contextLoads
()
{
}
}
eladmin-tools/src/main/java/me/zhengjie/domain/Picture.java
View file @
bf7c1eeb
...
...
@@ -41,6 +41,9 @@ public class Picture implements Serializable {
@Column
(
name
=
"create_time"
)
private
Timestamp
createTime
;
// 用于检测文件是否重复
private
String
md5Code
;
@Override
public
String
toString
()
{
return
"Picture{"
+
...
...
eladmin-tools/src/main/java/me/zhengjie/repository/PictureRepository.java
View file @
bf7c1eeb
...
...
@@ -9,4 +9,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2018-12-27
*/
public
interface
PictureRepository
extends
JpaRepository
<
Picture
,
Long
>,
JpaSpecificationExecutor
<
Picture
>
{
Picture
findByUrl
(
String
url
);
Picture
findByMd5Code
(
String
code
);
}
eladmin-tools/src/main/java/me/zhengjie/rest/AliPayController.java
View file @
bf7c1eeb
...
...
@@ -9,7 +9,6 @@ import me.zhengjie.domain.vo.TradeVo;
import
me.zhengjie.service.AlipayService
;
import
me.zhengjie.utils.AliPayStatusEnum
;
import
me.zhengjie.utils.AlipayUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -27,7 +26,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequestMapping
(
"/api/aliPay"
)
@Api
(
tags
=
"支付宝
支付
管理"
)
@Api
(
tags
=
"
工具:
支付宝管理"
)
public
class
AliPayController
{
private
final
AlipayUtils
alipayUtils
;
...
...
@@ -45,6 +44,7 @@ public class AliPayController {
}
@Log
(
"配置支付宝"
)
@ApiOperation
(
"配置支付宝"
)
@PutMapping
public
ResponseEntity
payConfig
(
@Validated
@RequestBody
AlipayConfig
alipayConfig
){
alipayConfig
.
setId
(
1L
);
...
...
@@ -53,7 +53,7 @@ public class AliPayController {
}
@Log
(
"支付宝PC网页支付"
)
@ApiOperation
(
value
=
"PC网页支付"
)
@ApiOperation
(
"PC网页支付"
)
@PostMapping
(
value
=
"/toPayAsPC"
)
public
ResponseEntity
<
String
>
toPayAsPC
(
@Validated@RequestBody
TradeVo
trade
)
throws
Exception
{
AlipayConfig
alipay
=
alipayService
.
find
();
...
...
@@ -63,7 +63,7 @@ public class AliPayController {
}
@Log
(
"支付宝手机网页支付"
)
@ApiOperation
(
value
=
"手机网页支付"
)
@ApiOperation
(
"手机网页支付"
)
@PostMapping
(
value
=
"/toPayAsWeb"
)
public
ResponseEntity
<
String
>
toPayAsWeb
(
@Validated
@RequestBody
TradeVo
trade
)
throws
Exception
{
AlipayConfig
alipay
=
alipayService
.
find
();
...
...
@@ -74,8 +74,8 @@ public class AliPayController {
@ApiIgnore
@GetMapping
(
"/return"
)
@ApiOperation
(
value
=
"支付之后跳转的链接"
)
public
ResponseEntity
<
String
>
returnPage
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
@ApiOperation
(
"支付之后跳转的链接"
)
public
ResponseEntity
<
String
>
returnPage
(
HttpServletRequest
request
,
HttpServletResponse
response
){
AlipayConfig
alipay
=
alipayService
.
find
();
response
.
setContentType
(
"text/html;charset="
+
alipay
.
getCharset
());
//内容验签,防止黑客篡改参数
...
...
@@ -96,8 +96,8 @@ public class AliPayController {
@ApiIgnore
@RequestMapping
(
"/notify"
)
@ApiOperation
(
value
=
"支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理"
)
public
ResponseEntity
notify
(
HttpServletRequest
request
)
throws
Exception
{
@ApiOperation
(
"支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理"
)
public
ResponseEntity
notify
(
HttpServletRequest
request
){
AlipayConfig
alipay
=
alipayService
.
find
();
Map
<
String
,
String
[]>
parameterMap
=
request
.
getParameterMap
();
//内容验签,防止黑客篡改参数
...
...
@@ -111,9 +111,9 @@ public class AliPayController {
//付款金额
String
totalAmount
=
new
String
(
request
.
getParameter
(
"total_amount"
).
getBytes
(
StandardCharsets
.
ISO_8859_1
),
StandardCharsets
.
UTF_8
);
//验证
//
if(tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue())||tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())){
//
// 验证通过后应该根据业务需要处理订单
//
}
if
(
tradeStatus
.
equals
(
AliPayStatusEnum
.
SUCCESS
.
getValue
())||
tradeStatus
.
equals
(
AliPayStatusEnum
.
FINISHED
.
getValue
())){
// 验证通过后应该根据业务需要处理订单
}
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
return
new
ResponseEntity
(
HttpStatus
.
BAD_REQUEST
);
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/EmailController.java
View file @
bf7c1eeb
...
...
@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@RequestMapping
(
"api/email"
)
@Api
(
tags
=
"邮件管理"
)
@Api
(
tags
=
"
工具:
邮件管理"
)
public
class
EmailController
{
private
final
EmailService
emailService
;
...
...
@@ -34,7 +34,7 @@ public class EmailController {
@Log
(
"配置邮件"
)
@PutMapping
@ApiOperation
(
value
=
"配置邮件"
)
@ApiOperation
(
"配置邮件"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
EmailConfig
emailConfig
){
emailService
.
update
(
emailConfig
,
emailService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
@@ -42,7 +42,7 @@ public class EmailController {
@Log
(
"发送邮件"
)
@PostMapping
@ApiOperation
(
value
=
"发送邮件"
)
@ApiOperation
(
"发送邮件"
)
public
ResponseEntity
send
(
@Validated
@RequestBody
EmailVo
emailVo
)
throws
Exception
{
emailService
.
send
(
emailVo
,
emailService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/LocalStorageController.java
View file @
bf7c1eeb
...
...
@@ -17,7 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
* @author Zheng Jie
* @date 2019-09-05
*/
@Api
(
tags
=
"本地存储管理"
)
@Api
(
tags
=
"
工具:
本地存储管理"
)
@RestController
@RequestMapping
(
"/api/localStorage"
)
public
class
LocalStorageController
{
...
...
@@ -28,21 +28,21 @@ public class LocalStorageController {
this
.
localStorageService
=
localStorageService
;
}
@ApiOperation
(
value
=
"查询文件"
)
@ApiOperation
(
"查询文件"
)
@GetMapping
@PreAuthorize
(
"hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_SELECT')"
)
public
ResponseEntity
getLocalStorages
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
localStorageService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"上传文件"
)
@ApiOperation
(
"上传文件"
)
@PostMapping
@PreAuthorize
(
"hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_CREATE')"
)
public
ResponseEntity
create
(
@RequestParam
String
name
,
@RequestParam
(
"file"
)
MultipartFile
file
){
return
new
ResponseEntity
<>(
localStorageService
.
create
(
name
,
file
),
HttpStatus
.
CREATED
);
}
@ApiOperation
(
value
=
"修改文件"
)
@ApiOperation
(
"修改文件"
)
@PutMapping
@PreAuthorize
(
"hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
LocalStorage
resources
){
...
...
@@ -50,7 +50,7 @@ public class LocalStorageController {
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@ApiOperation
(
value
=
"删除文件"
)
@ApiOperation
(
"删除文件"
)
@DeleteMapping
(
value
=
"/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_DELETE')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
...
...
@@ -60,7 +60,7 @@ public class LocalStorageController {
@Log
(
"多选删除"
)
@DeleteMapping
@ApiOperation
(
value
=
"多选删除"
)
@ApiOperation
(
"多选删除"
)
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
localStorageService
.
deleteAll
(
ids
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/PictureController.java
View file @
bf7c1eeb
...
...
@@ -22,7 +22,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping
(
"/api/pictures"
)
@Api
(
tags
=
"免费图床管理"
)
@Api
(
tags
=
"
工具:
免费图床管理"
)
public
class
PictureController
{
private
final
PictureService
pictureService
;
...
...
@@ -34,7 +34,7 @@ public class PictureController {
@Log
(
"查询图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')"
)
@GetMapping
@ApiOperation
(
value
=
"查询图片"
)
@ApiOperation
(
"查询图片"
)
public
ResponseEntity
getRoles
(
PictureQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
pictureService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
...
...
@@ -42,7 +42,7 @@ public class PictureController {
@Log
(
"上传图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')"
)
@PostMapping
@ApiOperation
(
value
=
"上传图片"
)
@ApiOperation
(
"上传图片"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
String
userName
=
SecurityUtils
.
getUsername
();
Picture
picture
=
pictureService
.
upload
(
file
,
userName
);
...
...
@@ -54,7 +54,7 @@ public class PictureController {
}
@Log
(
"删除图片"
)
@ApiOperation
(
value
=
"删除图片"
)
@ApiOperation
(
"删除图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')"
)
@DeleteMapping
(
value
=
"/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
)
{
...
...
@@ -63,7 +63,7 @@ public class PictureController {
}
@Log
(
"多选删除图片"
)
@ApiOperation
(
value
=
"多选删除图片"
)
@ApiOperation
(
"多选删除图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')"
)
@DeleteMapping
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/QiniuController.java
View file @
bf7c1eeb
...
...
@@ -24,8 +24,8 @@ import java.util.Map;
*/
@Slf4j
@RestController
@RequestMapping
(
"api"
)
@Api
(
tags
=
"七牛云存储管理"
)
@RequestMapping
(
"
/
api
/qiNiuContent
"
)
@Api
(
tags
=
"
工具:
七牛云存储管理"
)
public
class
QiniuController
{
private
final
QiNiuService
qiNiuService
;
...
...
@@ -34,14 +34,14 @@ public class QiniuController {
this
.
qiNiuService
=
qiNiuService
;
}
@GetMapping
(
value
=
"/
qiNiuC
onfig"
)
@GetMapping
(
value
=
"/
c
onfig"
)
public
ResponseEntity
get
(){
return
new
ResponseEntity
<>(
qiNiuService
.
find
(),
HttpStatus
.
OK
);
}
@Log
(
"配置七牛云存储"
)
@ApiOperation
(
value
=
"配置七牛云存储"
)
@PutMapping
(
value
=
"/
qiNiuC
onfig"
)
@ApiOperation
(
"配置七牛云存储"
)
@PutMapping
(
value
=
"/
c
onfig"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
QiniuConfig
qiniuConfig
){
qiNiuService
.
update
(
qiniuConfig
);
qiNiuService
.
update
(
qiniuConfig
.
getType
());
...
...
@@ -49,15 +49,15 @@ public class QiniuController {
}
@Log
(
"查询文件"
)
@ApiOperation
(
value
=
"查询文件"
)
@GetMapping
(
value
=
"/qiNiuContent"
)
@ApiOperation
(
"查询文件"
)
@GetMapping
public
ResponseEntity
getRoles
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
qiNiuService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@Log
(
"上传文件"
)
@ApiOperation
(
value
=
"上传文件"
)
@PostMapping
(
value
=
"/qiNiuContent"
)
@ApiOperation
(
"上传文件"
)
@PostMapping
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
QiniuContent
qiniuContent
=
qiNiuService
.
upload
(
file
,
qiNiuService
.
find
());
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
3
);
...
...
@@ -68,16 +68,16 @@ public class QiniuController {
}
@Log
(
"同步七牛云数据"
)
@ApiOperation
(
value
=
"同步七牛云数据"
)
@PostMapping
(
value
=
"/
qiNiuContent/
synchronize"
)
@ApiOperation
(
"同步七牛云数据"
)
@PostMapping
(
value
=
"/synchronize"
)
public
ResponseEntity
synchronize
(){
qiNiuService
.
synchronize
(
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@Log
(
"下载文件"
)
@ApiOperation
(
value
=
"下载文件"
)
@GetMapping
(
value
=
"/
qiNiuContent/
download/{id}"
)
@ApiOperation
(
"下载文件"
)
@GetMapping
(
value
=
"/download/{id}"
)
public
ResponseEntity
download
(
@PathVariable
Long
id
){
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
1
);
map
.
put
(
"url"
,
qiNiuService
.
download
(
qiNiuService
.
findByContentId
(
id
),
qiNiuService
.
find
()));
...
...
@@ -85,16 +85,16 @@ public class QiniuController {
}
@Log
(
"删除文件"
)
@ApiOperation
(
value
=
"删除文件"
)
@DeleteMapping
(
value
=
"/
qiNiuContent/
{id}"
)
@ApiOperation
(
"删除文件"
)
@DeleteMapping
(
value
=
"/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
qiNiuService
.
delete
(
qiNiuService
.
findByContentId
(
id
),
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@Log
(
"删除多张图片"
)
@ApiOperation
(
value
=
"删除多张图片"
)
@DeleteMapping
(
value
=
"/qiNiuContent"
)
@ApiOperation
(
"删除多张图片"
)
@DeleteMapping
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
qiNiuService
.
deleteAll
(
ids
,
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/VerificationCodeController.java
View file @
bf7c1eeb
...
...
@@ -7,10 +7,8 @@ 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.Qualifier
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.web.bind.annotation.*
;
/**
...
...
@@ -18,21 +16,21 @@ import org.springframework.web.bind.annotation.*;
* @date 2018-12-26
*/
@RestController
@RequestMapping
(
"api"
)
@Api
(
tags
=
"验证码管理"
)
@RequestMapping
(
"
/
api
/code
"
)
@Api
(
tags
=
"
工具:
验证码管理"
)
public
class
VerificationCodeController
{
private
final
VerificationCodeService
verificationCodeService
;
private
final
EmailService
emailService
;
public
VerificationCodeController
(
VerificationCodeService
verificationCodeService
,
@Qualifier
(
"jwtUserDetailsService"
)
UserDetailsService
userDetailsService
,
EmailService
emailService
)
{
public
VerificationCodeController
(
VerificationCodeService
verificationCodeService
,
EmailService
emailService
)
{
this
.
verificationCodeService
=
verificationCodeService
;
this
.
emailService
=
emailService
;
}
@PostMapping
(
value
=
"/
code/
resetEmail"
)
@ApiOperation
(
value
=
"重置邮箱,发送验证码"
)
@PostMapping
(
value
=
"/resetEmail"
)
@ApiOperation
(
"重置邮箱,发送验证码"
)
public
ResponseEntity
resetEmail
(
@RequestBody
VerificationCode
code
)
throws
Exception
{
code
.
setScenes
(
ElAdminConstant
.
RESET_MAIL
);
EmailVo
emailVo
=
verificationCodeService
.
sendEmail
(
code
);
...
...
@@ -40,8 +38,8 @@ public class VerificationCodeController {
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@PostMapping
(
value
=
"/
code/
email/resetPass"
)
@ApiOperation
(
value
=
"重置密码,发送验证码"
)
@PostMapping
(
value
=
"/email/resetPass"
)
@ApiOperation
(
"重置密码,发送验证码"
)
public
ResponseEntity
resetPass
(
@RequestParam
String
email
)
throws
Exception
{
VerificationCode
code
=
new
VerificationCode
();
code
.
setType
(
"email"
);
...
...
@@ -52,8 +50,8 @@ public class VerificationCodeController {
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@GetMapping
(
value
=
"/
code/
validated"
)
@ApiOperation
(
value
=
"验证码验证"
)
@GetMapping
(
value
=
"/validated"
)
@ApiOperation
(
"验证码验证"
)
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 @
bf7c1eeb
...
...
@@ -10,7 +10,6 @@ import org.springframework.cache.annotation.Cacheable;
* @author Zheng Jie
* @date 2018-12-31
*/
@CacheConfig
(
cacheNames
=
"alipay"
)
public
interface
AlipayService
{
/**
...
...
@@ -35,7 +34,6 @@ public interface AlipayService {
* 查询配置
* @return AlipayConfig
*/
@Cacheable
(
key
=
"'1'"
)
AlipayConfig
find
();
/**
...
...
@@ -43,6 +41,5 @@ public interface AlipayService {
* @param alipayConfig 支付宝配置
* @return AlipayConfig
*/
@CachePut
(
key
=
"'1'"
)
AlipayConfig
update
(
AlipayConfig
alipayConfig
);
}
eladmin-tools/src/main/java/me/zhengjie/service/EmailService.java
View file @
bf7c1eeb
...
...
@@ -2,16 +2,12 @@ package me.zhengjie.service;
import
me.zhengjie.domain.EmailConfig
;
import
me.zhengjie.domain.vo.EmailVo
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.scheduling.annotation.Async
;
/**
* @author Zheng Jie
* @date 2018-12-26
*/
@CacheConfig
(
cacheNames
=
"email"
)
public
interface
EmailService
{
/**
...
...
@@ -20,14 +16,12 @@ public interface EmailService {
* @param old 旧的配置
* @return EmailConfig
*/
@CachePut
(
key
=
"'1'"
)
EmailConfig
update
(
EmailConfig
emailConfig
,
EmailConfig
old
);
/**
* 查询配置
* @return EmailConfig 邮件配置
*/
@Cacheable
(
key
=
"'1'"
)
EmailConfig
find
();
/**
...
...
eladmin-tools/src/main/java/me/zhengjie/service/LocalStorageService.java
View file @
bf7c1eeb
...
...
@@ -3,9 +3,6 @@ package me.zhengjie.service;
import
me.zhengjie.domain.LocalStorage
;
import
me.zhengjie.service.dto.LocalStorageDTO
;
import
me.zhengjie.service.dto.LocalStorageQueryCriteria
;
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.web.multipart.MultipartFile
;
...
...
@@ -13,61 +10,19 @@ import org.springframework.web.multipart.MultipartFile;
* @author Zheng Jie
* @date 2019-09-05
*/
@CacheConfig
(
cacheNames
=
"localStorage"
)
public
interface
LocalStorageService
{
/**
* queryAll 分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Object
*/
@Cacheable
Object
queryAll
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
);
/**
* queryAll 不分页
* @param criteria 条件参数
* @return Object
*/
@Cacheable
Object
queryAll
(
LocalStorageQueryCriteria
criteria
);
/**
* findById
* @param id
* @return LocalStorageDTO
*/
@Cacheable
(
key
=
"#p0"
)
LocalStorageDTO
findById
(
Long
id
);
/**
* create
* @param name 文件名称
* @param file 文件资源
* @return LocalStorageDTO
*/
@CacheEvict
(
allEntries
=
true
)
LocalStorageDTO
create
(
String
name
,
MultipartFile
file
);
/**
* update
* @param resources 资源实体
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
LocalStorage
resources
);
/**
* delete
* @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 @
bf7c1eeb
...
...
@@ -2,55 +2,22 @@ package me.zhengjie.service;
import
me.zhengjie.domain.Picture
;
import
me.zhengjie.service.dto.PictureQueryCriteria
;
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.web.multipart.MultipartFile
;
/**
* @author Zheng Jie
* @date 2018-12-27
*/
@CacheConfig
(
cacheNames
=
"picture"
)
public
interface
PictureService
{
/**
* 查询图片
* @param criteria 条件参数
* @param pageable 分页参数
* @return Object
*/
@Cacheable
Object
queryAll
(
PictureQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 上传图片
* @param file 文件
* @param username 用户名
* @return
*/
@CacheEvict
(
allEntries
=
true
)
Picture
upload
(
MultipartFile
file
,
String
username
);
/**
* 根据ID查询
* @param id 文件ID
* @return
*/
@Cacheable
(
key
=
"#p0"
)
Picture
findById
(
Long
id
);
/**
* 删除图片
* @param picture 图片实体
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Picture
picture
);
/**
* 删除图片
* @param ids 文件ID数组
*/
@CacheEvict
(
allEntries
=
true
)
void
deleteAll
(
Long
[]
ids
);
}
eladmin-tools/src/main/java/me/zhengjie/service/QiNiuService.java
View file @
bf7c1eeb
...
...
@@ -3,66 +3,49 @@ package me.zhengjie.service;
import
me.zhengjie.domain.QiniuConfig
;
import
me.zhengjie.domain.QiniuContent
;
import
me.zhengjie.service.dto.QiniuQueryCriteria
;
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.scheduling.annotation.Async
;
import
org.springframework.web.multipart.MultipartFile
;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@CacheConfig
(
cacheNames
=
"qiNiu"
)
public
interface
QiNiuService
{
/**
* 查询文件
* @param criteria 条件参数
* @param pageable 分页参数
* @return Object
*/
@Cacheable
Object
queryAll
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
);
/**
* 查配置
* @return Cacheable
*/
@Cacheable
(
cacheNames
=
"qiNiuConfig"
,
key
=
"'1'"
)
QiniuConfig
find
();
/**
* 修改配置
* @param qiniuConfig
* @param qiniuConfig
配置
* @return QiniuConfig
*/
@CachePut
(
cacheNames
=
"qiNiuConfig"
,
key
=
"'1'"
)
QiniuConfig
update
(
QiniuConfig
qiniuConfig
);
/**
* 上传文件
* @param file
* @param qiniuConfig
* @param file
文件
* @param qiniuConfig
配置
* @return QiniuContent
*/
@CacheEvict
(
allEntries
=
true
)
QiniuContent
upload
(
MultipartFile
file
,
QiniuConfig
qiniuConfig
);
/**
* 查询文件
* @param id
* @param id
文件ID
* @return QiniuContent
*/
@Cacheable
(
key
=
"'content:'+#p0"
)
QiniuContent
findByContentId
(
Long
id
);
/**
* 下载文件
* @param content
* @param config
* @param content
文件信息
* @param config
配置
* @return String
*/
String
download
(
QiniuContent
content
,
QiniuConfig
config
);
...
...
@@ -72,14 +55,12 @@ public interface QiNiuService {
* @param content 文件
* @param config 配置
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
QiniuContent
content
,
QiniuConfig
config
);
/**
* 同步数据
* @param config 配置
*/
@CacheEvict
(
allEntries
=
true
)
void
synchronize
(
QiniuConfig
config
);
/**
...
...
@@ -87,13 +68,11 @@ public interface QiNiuService {
* @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/impl/AlipayServiceImpl.java
View file @
bf7c1eeb
...
...
@@ -9,8 +9,9 @@ import me.zhengjie.domain.vo.TradeVo;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.repository.AlipayRepository
;
import
me.zhengjie.service.AlipayService
;
import
me.zhengjie.utils.AlipayUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -21,14 +22,15 @@ import java.util.Optional;
* @date 2018-12-31
*/
@Service
@CacheConfig
(
cacheNames
=
"alipay"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
AlipayServiceImpl
implements
AlipayService
{
@Autowired
AlipayUtils
alipayUtils
;
private
final
AlipayRepository
alipayRepository
;
@Autowired
private
AlipayRepository
alipayRepository
;
public
AlipayServiceImpl
(
AlipayRepository
alipayRepository
)
{
this
.
alipayRepository
=
alipayRepository
;
}
@Override
public
String
toPayAsPC
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
{
...
...
@@ -38,7 +40,7 @@ public class AlipayServiceImpl implements AlipayService {
}
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
alipay
.
getGatewayUrl
(),
alipay
.
getAppID
(),
alipay
.
getPrivateKey
(),
alipay
.
getFormat
(),
alipay
.
getCharset
(),
alipay
.
getPublicKey
(),
alipay
.
getSignType
());
double
money
=
Double
.
parseDouble
(
trade
.
getTotalAmount
());
//
double money = Double.parseDouble(trade.getTotalAmount());
// 创建API对应的request(电脑网页版)
AlipayTradePagePayRequest
request
=
new
AlipayTradePagePayRequest
();
...
...
@@ -91,12 +93,14 @@ public class AlipayServiceImpl implements AlipayService {
}
@Override
@Cacheable
(
key
=
"'1'"
)
public
AlipayConfig
find
()
{
Optional
<
AlipayConfig
>
alipayConfig
=
alipayRepository
.
findById
(
1L
);
return
alipayConfig
.
orElseGet
(
AlipayConfig:
:
new
);
}
@Override
@CachePut
(
key
=
"'1'"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
AlipayConfig
update
(
AlipayConfig
alipayConfig
)
{
return
alipayRepository
.
save
(
alipayConfig
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java
View file @
bf7c1eeb
...
...
@@ -8,6 +8,9 @@ import me.zhengjie.exception.BadRequestException;
import
me.zhengjie.repository.EmailRepository
;
import
me.zhengjie.service.EmailService
;
import
me.zhengjie.utils.EncryptUtils
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -18,6 +21,7 @@ import java.util.Optional;
* @date 2018-12-26
*/
@Service
@CacheConfig
(
cacheNames
=
"email"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
EmailServiceImpl
implements
EmailService
{
...
...
@@ -28,6 +32,7 @@ public class EmailServiceImpl implements EmailService {
}
@Override
@CachePut
(
key
=
"'1'"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
EmailConfig
update
(
EmailConfig
emailConfig
,
EmailConfig
old
)
{
try
{
...
...
@@ -42,6 +47,7 @@ public class EmailServiceImpl implements EmailService {
}
@Override
@Cacheable
(
key
=
"'1'"
)
public
EmailConfig
find
()
{
Optional
<
EmailConfig
>
emailConfig
=
emailRepository
.
findById
(
1L
);
return
emailConfig
.
orElseGet
(
EmailConfig:
:
new
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java
View file @
bf7c1eeb
package
me.zhengjie.service.impl
;
import
cn.hutool.core.util.ObjectUtil
;
import
me.zhengjie.domain.LocalStorage
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.utils.*
;
import
me.zhengjie.repository.LocalStorageRepository
;
import
me.zhengjie.service.LocalStorageService
;
...
...
@@ -8,11 +10,13 @@ import me.zhengjie.service.dto.LocalStorageDTO;
import
me.zhengjie.service.dto.LocalStorageQueryCriteria
;
import
me.zhengjie.service.mapper.LocalStorageMapper
;
import
org.springframework.beans.factory.annotation.Value
;
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.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.File
;
import
java.util.Optional
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -22,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
* @date 2019-09-05
*/
@Service
@CacheConfig
(
cacheNames
=
"localStorage"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
LocalStorageServiceImpl
implements
LocalStorageService
{
...
...
@@ -41,24 +46,28 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
@Override
@Cacheable
public
Object
queryAll
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
){
Page
<
LocalStorage
>
page
=
localStorageRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
localStorageMapper:
:
toDto
));
}
@Override
@Cacheable
public
Object
queryAll
(
LocalStorageQueryCriteria
criteria
){
return
localStorageMapper
.
toDto
(
localStorageRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
@Override
public
LocalStorageDTO
findById
(
Long
id
)
{
Optional
<
LocalStorage
>
localStorage
=
localStorageRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
localStorage
,
"LocalStorage"
,
"id"
,
id
);
return
localStorageMapper
.
toDto
(
localStorage
.
get
());
@Cacheable
(
key
=
"#p0"
)
public
LocalStorageDTO
findById
(
Long
id
){
LocalStorage
localStorage
=
localStorageRepository
.
findById
(
id
).
orElseGet
(
LocalStorage:
:
new
);
ValidationUtil
.
isNull
(
localStorage
.
getId
(),
"LocalStorage"
,
"id"
,
id
);
return
localStorageMapper
.
toDto
(
localStorage
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
LocalStorageDTO
create
(
String
name
,
MultipartFile
multipartFile
)
{
FileUtil
.
checkSize
(
maxSize
,
multipartFile
.
getSize
());
...
...
@@ -67,6 +76,9 @@ public class LocalStorageServiceImpl implements LocalStorageService {
// String type = FileUtil.getFileTypeByMimeType(suffix);
String
type
=
FileUtil
.
getFileType
(
suffix
);
File
file
=
FileUtil
.
upload
(
multipartFile
,
path
+
type
+
File
.
separator
);
if
(
ObjectUtil
.
isNull
(
file
)){
throw
new
BadRequestException
(
"上传失败"
);
}
try
{
name
=
StringUtils
.
isBlank
(
name
)
?
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
())
:
name
;
LocalStorage
localStorage
=
new
LocalStorage
(
...
...
@@ -86,28 +98,30 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
LocalStorage
resources
)
{
Optional
<
LocalStorage
>
optionalLocalStorage
=
localStorageRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalLocalStorage
,
"LocalStorage"
,
"id"
,
resources
.
getId
());
LocalStorage
localStorage
=
optionalLocalStorage
.
get
();
LocalStorage
localStorage
=
localStorageRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
LocalStorage:
:
new
);
ValidationUtil
.
isNull
(
localStorage
.
getId
(),
"LocalStorage"
,
"id"
,
resources
.
getId
());
localStorage
.
copy
(
resources
);
localStorageRepository
.
save
(
localStorage
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
LocalStorage
storage
=
localStorageRepository
.
findById
(
id
).
get
(
);
LocalStorage
storage
=
localStorageRepository
.
findById
(
id
).
orElseGet
(
LocalStorage:
:
new
);
FileUtil
.
del
(
storage
.
getPath
());
localStorageRepository
.
delete
(
storage
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteAll
(
Long
[]
ids
)
{
for
(
Long
id
:
ids
)
{
LocalStorage
storage
=
localStorageRepository
.
findById
(
id
).
get
(
);
LocalStorage
storage
=
localStorageRepository
.
findById
(
id
).
orElseGet
(
LocalStorage:
:
new
);
FileUtil
.
del
(
storage
.
getPath
());
localStorageRepository
.
delete
(
storage
);
}
...
...
Prev
1
…
3
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