Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gdtel-gztel-school-center
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴学德
gdtel-gztel-school-center
Commits
16eab68a
Commit
16eab68a
authored
Mar 06, 2020
by
吴学德
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加图片上传功能
parent
6977221d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
13 deletions
+139
-13
.gitignore
+1
-0
common/src/main/java/com/winsun/utils/FileUtil.java
+20
-0
service-manager/src/main/java/com/winsun/controller/PackageController.java
+118
-13
No files found.
.gitignore
View file @
16eab68a
...
...
@@ -7,6 +7,7 @@
/gdtel-gztel-jyyy-service-manager/target/
/gdtel-gztel-jyyy-task/target/
/logs/
/BackgroundImg/
# Compiled class file
*.class
...
...
common/src/main/java/com/winsun/utils/FileUtil.java
View file @
16eab68a
...
...
@@ -35,4 +35,24 @@ public class FileUtil {
}
return
true
;
}
public
static
boolean
makefile1
(
String
path
,
MultipartFile
file
,
String
filename
){
File
dir
=
new
File
(
path
);
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
File
savePath
=
new
File
(
dir
,
filename
);
OutputStream
os
=
null
;
try
{
os
=
new
FileOutputStream
(
savePath
);
os
.
write
(
file
.
getBytes
());
os
.
flush
();
}
catch
(
IOException
e
)
{
log
.
error
(
"上传文件失败:"
+
e
.
getMessage
(),
e
);
return
false
;
}
finally
{
IOUtils
.
closeQuite
(
os
);
}
return
true
;
}
}
service-manager/src/main/java/com/winsun/controller/PackageController.java
View file @
16eab68a
...
...
@@ -17,12 +17,17 @@ import com.winsun.utils.MyBatisPlusUpdateUtils;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.http.MediaType
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.*
;
/**
...
...
@@ -44,6 +49,9 @@ public class PackageController extends BaseController {
private
static
String
FILENAME
=
"adv_img.jpg"
;
private
static
String
XIAOTUFILENAME
=
"logo.png"
;
@Autowired
public
PackageController
(
PackageMapper
packageMapper
,
SchoolPackageMapper
schoolPackageMapper
)
{
PackageController
.
packageMapper
=
packageMapper
;
...
...
@@ -174,20 +182,117 @@ public class PackageController extends BaseController {
@Permission
(
menuname
=
"上传背景图"
,
value
=
"backgroundUpload"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
backgroundUpload
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
)
{
EntityWrapper
<
Package
>
packagewrapper
=
new
EntityWrapper
<>();
packagewrapper
.
setSqlSelect
(
"max(id) as id"
);
List
<
Map
<
String
,
Object
>>
selectMaps
=
packageMapper
.
selectMaps
(
packagewrapper
);
String
id
=
selectMaps
.
get
(
0
).
get
(
"id"
).
toString
();
Integer
fileid
=
Integer
.
valueOf
(
id
)+
1
;
public
ResponseData
<
String
>
backgroundUpload
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"id"
,
required
=
false
)
String
id
)
{
//路径BackgroundImg/images/pkg/
String
backgroundpath
=
FilePath
.
BACKGROUNDIMG
.
getValue
()+
"/"
+
DEFAULTPATH
+
"/"
+
fileid
.
toString
();
String
backgroundpath
=
FilePath
.
BACKGROUNDIMG
.
getValue
()+
"/"
+
DEFAULTPATH
+
"/"
;
if
(
StringUtils
.
isBlank
(
id
)){
EntityWrapper
<
Package
>
packagewrapper
=
new
EntityWrapper
<>();
packagewrapper
.
setSqlSelect
(
"max(id) as id"
);
List
<
Map
<
String
,
Object
>>
selectMaps
=
packageMapper
.
selectMaps
(
packagewrapper
);
id
=
selectMaps
.
get
(
0
).
get
(
"id"
).
toString
();
Integer
fileid
=
Integer
.
valueOf
(
id
)+
1
;
backgroundpath
=
backgroundpath
+
fileid
.
toString
();
}
else
{
backgroundpath
=
backgroundpath
+
id
;
}
boolean
makefile
=
FileUtil
.
makefile
(
backgroundpath
,
file
,
FILENAME
);
if
(!
makefile
){
return
ResponseData
.
error
(
"上传失败!"
);
}
return
ResponseData
.
success
(
"上传成功"
);
}
//xiaotudUpload
@Permission
(
menuname
=
"上传小图"
,
value
=
"xiaotuUpload"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
xiaotuUpload
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"id"
,
required
=
false
)
String
id
)
{
String
backgroundpath
=
FilePath
.
BACKGROUNDIMG
.
getValue
()+
"/"
+
DEFAULTPATH
+
"/"
;
if
(
StringUtils
.
isBlank
(
id
)){
EntityWrapper
<
Package
>
packagewrapper
=
new
EntityWrapper
<>();
packagewrapper
.
setSqlSelect
(
"max(id) as id"
);
List
<
Map
<
String
,
Object
>>
selectMaps
=
packageMapper
.
selectMaps
(
packagewrapper
);
id
=
selectMaps
.
get
(
0
).
get
(
"id"
).
toString
();
Integer
fileid
=
Integer
.
valueOf
(
id
)+
1
;
backgroundpath
=
backgroundpath
+
fileid
.
toString
();
}
else
{
backgroundpath
=
backgroundpath
+
id
;
}
boolean
makefile
=
FileUtil
.
makefile
(
backgroundpath
,
file
,
XIAOTUFILENAME
);
if
(!
makefile
){
return
ResponseData
.
error
(
"上传失败!"
);
}
return
ResponseData
.
success
(
"上传成功"
);
}
//menuname = "展示背景图"
@RequestMapping
(
value
=
"getbackground/{id}"
,
produces
=
MediaType
.
IMAGE_JPEG_VALUE
)
public
byte
[]
getbackground
(
@PathVariable
(
value
=
"id"
)
String
id
)
{
byte
[]
bytes
={};
if
(!
StringUtils
.
isBlank
(
id
)){
EntityWrapper
<
Package
>
packagewrapper
=
new
EntityWrapper
<>();
packagewrapper
.
eq
(
"id"
,
id
);
packagewrapper
.
setSqlSelect
(
"adv_img as imgurl"
);
List
<
Map
<
String
,
Object
>>
selectMaps
=
packageMapper
.
selectMaps
(
packagewrapper
);
if
(!
CollectionUtils
.
isEmpty
(
selectMaps
)){
String
imgurl
=
selectMaps
.
get
(
0
).
get
(
"imgurl"
).
toString
();
imgurl
=
FilePath
.
BACKGROUNDIMG
.
getValue
()+
"/"
+
imgurl
;
File
file
=
new
File
(
imgurl
);
FileInputStream
inputStream
=
null
;
try
{
inputStream
=
new
FileInputStream
(
file
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
bytes
=
new
byte
[
0
];
try
{
bytes
=
new
byte
[
inputStream
.
available
()];
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
inputStream
.
read
(
bytes
,
0
,
inputStream
.
available
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
bytes
;
}
}
return
bytes
;
}
//menuname = "展示小图"
@RequestMapping
(
value
=
"getxiaotu/{id}"
,
produces
=
MediaType
.
IMAGE_JPEG_VALUE
)
public
byte
[]
getxiaotu
(
@PathVariable
(
value
=
"id"
)
String
id
)
{
byte
[]
bytes
={};
if
(!
StringUtils
.
isBlank
(
id
)){
EntityWrapper
<
Package
>
packagewrapper
=
new
EntityWrapper
<>();
packagewrapper
.
eq
(
"id"
,
id
);
packagewrapper
.
setSqlSelect
(
"logo as imgurl"
);
List
<
Map
<
String
,
Object
>>
selectMaps
=
packageMapper
.
selectMaps
(
packagewrapper
);
if
(!
CollectionUtils
.
isEmpty
(
selectMaps
)){
String
imgurl
=
selectMaps
.
get
(
0
).
get
(
"imgurl"
).
toString
();
imgurl
=
FilePath
.
BACKGROUNDIMG
.
getValue
()+
"/"
+
imgurl
;
File
file
=
new
File
(
imgurl
);
FileInputStream
inputStream
=
null
;
try
{
inputStream
=
new
FileInputStream
(
file
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
bytes
=
new
byte
[
0
];
try
{
bytes
=
new
byte
[
inputStream
.
available
()];
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
inputStream
.
read
(
bytes
,
0
,
inputStream
.
available
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
bytes
;
}
}
return
bytes
;
}
}
Write
Preview
Markdown
is supported
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