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
0f0392d7
Commit
0f0392d7
authored
Sep 26, 2019
by
dqjdda
Browse files
Merge branch '2.2DEV'
parents
d0ffe1a8
f9bb8cf2
Changes
72
Expand all
Hide whitespace changes
Inline
Side-by-side
eladmin-tools/src/main/java/me/zhengjie/rest/QiniuController.java
View file @
0f0392d7
...
...
@@ -38,6 +38,7 @@ public class QiniuController {
@PutMapping
(
value
=
"/qiNiuConfig"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
QiniuConfig
qiniuConfig
){
qiNiuService
.
update
(
qiniuConfig
);
qiNiuService
.
update
(
qiniuConfig
.
getType
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
...
...
eladmin-tools/src/main/java/me/zhengjie/service/LocalStorageService.java
0 → 100644
View file @
0f0392d7
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
;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@CacheConfig
(
cacheNames
=
"localStorage"
)
public
interface
LocalStorageService
{
/**
* queryAll 分页
* @param criteria
* @param pageable
* @return
*/
@Cacheable
Object
queryAll
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
);
/**
* queryAll 不分页
* @param criteria
* @return
*/
@Cacheable
public
Object
queryAll
(
LocalStorageQueryCriteria
criteria
);
/**
* findById
* @param id
* @return
*/
@Cacheable
(
key
=
"#p0"
)
LocalStorageDTO
findById
(
Long
id
);
/**
* create
* @param name
* @param file
* @return
*/
@CacheEvict
(
allEntries
=
true
)
LocalStorageDTO
create
(
String
name
,
MultipartFile
file
);
/**
* update
* @param resources
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
LocalStorage
resources
);
/**
* delete
* @param id
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
@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 @
0f0392d7
...
...
@@ -20,7 +20,7 @@ public interface PictureService {
* @param pageable
* @return
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
@Cacheable
Object
queryAll
(
PictureQueryCriteria
criteria
,
Pageable
pageable
);
/**
...
...
eladmin-tools/src/main/java/me/zhengjie/service/QiNiuService.java
View file @
0f0392d7
...
...
@@ -8,6 +8,7 @@ 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
;
/**
...
...
@@ -23,7 +24,7 @@ public interface QiNiuService {
* @param pageable
* @return
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
@Cacheable
Object
queryAll
(
QiniuQueryCriteria
criteria
,
Pageable
pageable
);
/**
...
...
@@ -89,4 +90,7 @@ public interface QiNiuService {
*/
@CacheEvict
(
allEntries
=
true
)
void
deleteAll
(
Long
[]
ids
,
QiniuConfig
config
);
@CacheEvict
(
allEntries
=
true
)
void
update
(
String
type
);
}
eladmin-tools/src/main/java/me/zhengjie/service/dto/LocalStorageDTO.java
0 → 100644
View file @
0f0392d7
package
me.zhengjie.service.dto
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Data
public
class
LocalStorageDTO
implements
Serializable
{
// ID
private
Long
id
;
private
String
realName
;
// 文件名
private
String
name
;
// 后缀
private
String
suffix
;
// 类型
private
String
type
;
// 大小
private
String
size
;
// 操作人
private
String
operate
;
// 创建日期
private
Timestamp
createTime
;
// 修改日期
private
Timestamp
updateTime
;
}
\ No newline at end of file
eladmin-tools/src/main/java/me/zhengjie/service/dto/LocalStorageQueryCriteria.java
0 → 100644
View file @
0f0392d7
package
me.zhengjie.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
me.zhengjie.annotation.Query
;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Data
public
class
LocalStorageQueryCriteria
{
// 模糊
@Query
(
blurry
=
"name,suffix,type,operate,size"
)
private
String
blurry
;
}
\ No newline at end of file
eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java
0 → 100644
View file @
0f0392d7
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
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.web.multipart.MultipartFile
;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
LocalStorageServiceImpl
implements
LocalStorageService
{
@Autowired
private
LocalStorageRepository
localStorageRepository
;
@Autowired
private
LocalStorageMapper
localStorageMapper
;
@Value
(
"${file.path}"
)
private
String
path
;
@Value
(
"${file.maxSize}"
)
private
long
maxSize
;
@Override
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
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
());
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
LocalStorageDTO
create
(
String
name
,
MultipartFile
multipartFile
)
{
FileUtil
.
checkSize
(
maxSize
,
multipartFile
.
getSize
());
String
suffix
=
FileUtil
.
getExtensionName
(
multipartFile
.
getOriginalFilename
());
String
type
=
FileUtil
.
getFileType
(
suffix
);
File
file
=
FileUtil
.
upload
(
multipartFile
,
path
+
type
+
File
.
separator
);
try
{
name
=
StringUtils
.
isBlank
(
name
)
?
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
())
:
name
;
LocalStorage
localStorage
=
new
LocalStorage
(
file
.
getName
(),
name
,
suffix
,
file
.
getPath
(),
type
,
FileUtil
.
getSize
(
multipartFile
.
getSize
()),
SecurityUtils
.
getUsername
()
);
return
localStorageMapper
.
toDto
(
localStorageRepository
.
save
(
localStorage
));
}
catch
(
Exception
e
){
FileUtil
.
del
(
file
);
throw
e
;
}
}
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
)
{
Optional
<
LocalStorage
>
optionalLocalStorage
=
localStorageRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalLocalStorage
,
"LocalStorage"
,
"id"
,
resources
.
getId
());
LocalStorage
localStorage
=
optionalLocalStorage
.
get
();
localStorage
.
copy
(
resources
);
localStorageRepository
.
save
(
localStorage
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
LocalStorage
storage
=
localStorageRepository
.
findById
(
id
).
get
();
FileUtil
.
del
(
storage
.
getPath
());
localStorageRepository
.
delete
(
storage
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteAll
(
Long
[]
ids
)
{
for
(
Long
id
:
ids
)
{
LocalStorage
storage
=
localStorageRepository
.
findById
(
id
).
get
();
FileUtil
.
del
(
storage
.
getPath
());
localStorageRepository
.
delete
(
storage
);
}
}
}
\ No newline at end of file
eladmin-tools/src/main/java/me/zhengjie/service/impl/PictureServiceImpl.java
View file @
0f0392d7
...
...
@@ -37,7 +37,7 @@ public class PictureServiceImpl implements PictureService {
public
static
final
String
CODE
=
"code"
;
public
static
final
String
MSG
=
"m
sg
"
;
public
static
final
String
MSG
=
"m
essage
"
;
@Override
public
Object
queryAll
(
PictureQueryCriteria
criteria
,
Pageable
pageable
){
...
...
@@ -56,7 +56,7 @@ public class PictureServiceImpl implements PictureService {
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
result
);
Picture
picture
=
null
;
if
(!
jsonObject
.
get
(
CODE
).
toString
().
equals
(
SUCCESS
)){
throw
new
BadRequestException
(
jsonObject
.
get
(
MSG
).
toString
());
throw
new
BadRequestException
(
TranslatorUtil
.
translate
(
jsonObject
.
get
(
MSG
).
toString
())
)
;
}
//转成实体类
picture
=
JSON
.
parseObject
(
jsonObject
.
get
(
"data"
).
toString
(),
Picture
.
class
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java
View file @
0f0392d7
...
...
@@ -73,11 +73,7 @@ public class QiNiuServiceImpl implements QiNiuService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
QiniuContent
upload
(
MultipartFile
file
,
QiniuConfig
qiniuConfig
)
{
Long
size
=
maxSize
*
1024
*
1024
;
if
(
file
.
getSize
()
>
size
){
throw
new
BadRequestException
(
"文件超出规定大小"
);
}
FileUtil
.
checkSize
(
maxSize
,
file
.
getSize
());
if
(
qiniuConfig
.
getId
()
==
null
){
throw
new
BadRequestException
(
"请先添加相应配置,再操作"
);
}
...
...
@@ -98,9 +94,10 @@ public class QiNiuServiceImpl implements QiNiuService {
DefaultPutRet
putRet
=
new
Gson
().
fromJson
(
response
.
bodyString
(),
DefaultPutRet
.
class
);
//存入数据库
QiniuContent
qiniuContent
=
new
QiniuContent
();
qiniuContent
.
setSuffix
(
FileUtil
.
getExtensionName
(
putRet
.
key
));
qiniuContent
.
setBucket
(
qiniuConfig
.
getBucket
());
qiniuContent
.
setType
(
qiniuConfig
.
getType
());
qiniuContent
.
setKey
(
putRet
.
key
);
qiniuContent
.
setKey
(
FileUtil
.
getFileNameNoEx
(
putRet
.
key
)
)
;
qiniuContent
.
setUrl
(
qiniuConfig
.
getHost
()+
"/"
+
putRet
.
key
);
qiniuContent
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
file
.
getSize
()+
""
)));
return
qiniuContentRepository
.
save
(
qiniuContent
);
...
...
@@ -140,7 +137,7 @@ public class QiNiuServiceImpl implements QiNiuService {
Auth
auth
=
Auth
.
create
(
config
.
getAccessKey
(),
config
.
getSecretKey
());
BucketManager
bucketManager
=
new
BucketManager
(
auth
,
cfg
);
try
{
bucketManager
.
delete
(
content
.
getBucket
(),
content
.
getKey
());
bucketManager
.
delete
(
content
.
getBucket
(),
content
.
getKey
()
+
"."
+
content
.
getSuffix
()
);
qiniuContentRepository
.
delete
(
content
);
}
catch
(
QiniuException
ex
)
{
qiniuContentRepository
.
delete
(
content
);
...
...
@@ -170,10 +167,11 @@ public class QiNiuServiceImpl implements QiNiuService {
QiniuContent
qiniuContent
=
null
;
FileInfo
[]
items
=
fileListIterator
.
next
();
for
(
FileInfo
item
:
items
)
{
if
(
qiniuContentRepository
.
findByKey
(
item
.
key
)
==
null
){
if
(
qiniuContentRepository
.
findByKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
)
)
==
null
){
qiniuContent
=
new
QiniuContent
();
qiniuContent
.
setSize
(
FileUtil
.
getSize
(
Integer
.
parseInt
(
item
.
fsize
+
""
)));
qiniuContent
.
setKey
(
item
.
key
);
qiniuContent
.
setSuffix
(
FileUtil
.
getExtensionName
(
item
.
key
));
qiniuContent
.
setKey
(
FileUtil
.
getFileNameNoEx
(
item
.
key
));
qiniuContent
.
setType
(
config
.
getType
());
qiniuContent
.
setBucket
(
config
.
getBucket
());
qiniuContent
.
setUrl
(
config
.
getHost
()+
"/"
+
item
.
key
);
...
...
@@ -189,4 +187,10 @@ public class QiNiuServiceImpl implements QiNiuService {
delete
(
findByContentId
(
id
),
config
);
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
String
type
)
{
qiNiuConfigRepository
.
update
(
type
);
}
}
eladmin-tools/src/main/java/me/zhengjie/service/mapper/LocalStorageMapper.java
0 → 100644
View file @
0f0392d7
package
me.zhengjie.service.mapper
;
import
me.zhengjie.mapper.EntityMapper
;
import
me.zhengjie.domain.LocalStorage
;
import
me.zhengjie.service.dto.LocalStorageDTO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
LocalStorageMapper
extends
EntityMapper
<
LocalStorageDTO
,
LocalStorage
>
{
}
\ No newline at end of file
pom.xml
View file @
0f0392d7
...
...
@@ -17,7 +17,7 @@
<module>
eladmin-generator
</module>
</modules>
<name>
el-admin
</name>
<name>
EL-ADMIN后台管理系统
</name>
<url>
http://auauz.net
</url>
<parent>
...
...
@@ -155,6 +155,22 @@
<artifactId>
ip2region
</artifactId>
<version>
1.7.2
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.17
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
3.17
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
<dependency>
<groupId>
xerces
</groupId>
<artifactId>
xercesImpl
</artifactId>
<version>
2.11.0
</version>
</dependency>
<!-- fastjson -->
<dependency>
...
...
sql/eladmin.sql
View file @
0f0392d7
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
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