Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0f964b4c
authored
Mar 25, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]文件列表展示
1 parent
5ab16466
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
9 deletions
src/main/java/com/glsx/smart/controller/SysFileController.java
src/main/java/com/glsx/smart/service/SmartSysFileService.java
src/main/java/com/glsx/smart/service/impl/SmartSysFileServiceImpl.java
src/main/java/com/glsx/smart/controller/SysFileController.java
View file @
0f964b4
package
com
.
glsx
.
smart
.
controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.smart.pojo.FileDTO
;
import
com.glsx.smart.service.SmartSysFileService
;
...
...
@@ -10,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
/**
* <p>Description:
...
...
@@ -36,12 +39,13 @@ public class SysFileController {
@RequestMapping
(
value
=
"/batchSaveFile"
,
method
=
{
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"批量保存图片"
)
public
R
saveFile
(
@RequestBody
List
<
FileDTO
>
files
)
{
List
<
Map
<
String
,
Object
>>
mapList
=
null
;
try
{
sysFileService
.
saveFile
(
files
);
mapList
=
sysFileService
.
saveFile
(
files
);
}
catch
(
Exception
e
)
{
return
R
.
error
();
}
return
R
.
ok
();
return
R
.
ok
()
.
data
(
mapList
)
;
}
@RequestMapping
(
value
=
"/saveFile"
,
method
=
{
RequestMethod
.
POST
})
...
...
src/main/java/com/glsx/smart/service/SmartSysFileService.java
View file @
0f964b4
...
...
@@ -4,6 +4,7 @@ import com.glsx.smart.dao.entity.SmartSysFile;
import
com.glsx.smart.pojo.FileDTO
;
import
java.util.List
;
import
java.util.Map
;
/**
* <p>Description:
...
...
@@ -19,7 +20,7 @@ public interface SmartSysFileService {
List
<
FileDTO
>
findByType
(
Byte
type
);
void
saveFile
(
List
<
FileDTO
>
files
);
List
<
Map
<
String
,
Object
>>
saveFile
(
List
<
FileDTO
>
files
);
FileDTO
updateFile
(
FileDTO
fileDTO
);
}
src/main/java/com/glsx/smart/service/impl/SmartSysFileServiceImpl.java
View file @
0f964b4
...
...
@@ -11,8 +11,11 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -31,7 +34,7 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
@Override
public
Long
insertOrUpdate
(
SmartSysFile
sysFile
)
{
if
(
sysFile
.
getId
()
==
null
)
{
fileMapper
.
insert
Selective
(
sysFile
);
fileMapper
.
insert
(
sysFile
);
}
else
{
SmartSysFile
record
=
fileMapper
.
selectByPrimaryKey
(
sysFile
.
getId
());
if
(
record
!=
null
)
{
...
...
@@ -51,7 +54,7 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
*/
@Override
public
List
<
FileDTO
>
findByType
(
Byte
type
)
{
List
<
SmartSysFile
>
list
=
fileMapper
.
findByType
(
type
);
List
<
SmartSysFile
>
list
=
fileMapper
.
findByType
(
type
);
List
<
FileDTO
>
fileDTOS
=
list
.
stream
().
map
(
index
->
{
FileDTO
fileDTO
=
new
FileDTO
();
BeanUtils
.
copyProperties
(
index
,
fileDTO
);
...
...
@@ -66,16 +69,22 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
* @param files 文件集合
*/
@Override
public
void
saveFile
(
List
<
FileDTO
>
files
)
{
public
List
<
Map
<
String
,
Object
>>
saveFile
(
List
<
FileDTO
>
files
)
{
List
<
Map
<
String
,
Object
>>
longList
=
new
ArrayList
<>();
List
<
SmartSysFile
>
list
=
files
.
stream
().
map
(
index
->
{
SmartSysFile
fileDTO
=
new
SmartSysFile
();
fileDTO
.
setCreateTime
(
new
Date
());
BeanUtils
.
copyProperties
(
index
,
fileDTO
);
return
fileDTO
;
}).
collect
(
Collectors
.
toList
());
list
.
forEach
(
index
->{
insertOrUpdate
(
index
);
list
.
forEach
(
index
->
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Long
aLong
=
insertOrUpdate
(
index
);
map
.
put
(
"id"
,
aLong
);
map
.
put
(
"name"
,
index
.
getName
());
longList
.
add
(
map
);
});
return
longList
;
}
/**
...
...
@@ -86,7 +95,7 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
@Override
public
FileDTO
updateFile
(
FileDTO
fileDTO
)
{
SmartSysFile
smartSysFile
=
new
SmartSysFile
();
BeanUtils
.
copyProperties
(
fileDTO
,
smartSysFile
);
BeanUtils
.
copyProperties
(
fileDTO
,
smartSysFile
);
fileDTO
.
setId
(
insertOrUpdate
(
smartSysFile
));
return
fileDTO
;
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment