Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
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
8timerv2
8timerapiv200
Commits
828d4d66
Commit
828d4d66
authored
Apr 21, 2021
by
Your Name
Committed by
chenzg
Jul 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新了上传文件的出现的问题
parent
60f77b3f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
42 deletions
+48
-42
pom.xml
+4
-0
src/main/java/cn/timer/api/controller/oss/OSSController.java
+14
-41
src/main/java/cn/timer/api/service/OSSService.java
+26
-0
src/main/java/cn/timer/api/service/impl/OSSServiceImpl.java
+3
-0
src/main/java/cn/timer/api/utils/aliyun/AliyunSMS.java
+1
-1
No files found.
pom.xml
View file @
828d4d66
...
@@ -421,6 +421,10 @@
...
@@ -421,6 +421,10 @@
<artifactId>
htmlunit
</artifactId>
<artifactId>
htmlunit
</artifactId>
<version>
2.43.0
</version>
<version>
2.43.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
</dependency>
</dependencies>
</dependencies>
<repositories>
<repositories>
...
...
src/main/java/cn/timer/api/controller/oss/OSSController.java
View file @
828d4d66
...
@@ -3,17 +3,12 @@ package cn.timer.api.controller.oss;
...
@@ -3,17 +3,12 @@ package cn.timer.api.controller.oss;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.UUID
;
import
cn.timer.api.service.OSSService
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
cn.timer.api.config.annotation.CurrentUser
;
import
cn.timer.api.config.annotation.CurrentUser
;
...
@@ -32,6 +27,8 @@ import io.swagger.annotations.ApiOperation;
...
@@ -32,6 +27,8 @@ import io.swagger.annotations.ApiOperation;
public
class
OSSController
{
public
class
OSSController
{
@Autowired
@Autowired
private
OSSUtil
oss
;
private
OSSUtil
oss
;
@Autowired
private
OSSService
ossService
;
/**
/**
* 上传普通文件
* 上传普通文件
...
@@ -41,21 +38,11 @@ public class OSSController {
...
@@ -41,21 +38,11 @@ public class OSSController {
*/
*/
@PostMapping
(
value
=
"/upload"
)
@PostMapping
(
value
=
"/upload"
)
@ApiOperation
(
value
=
"上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
String
>
upload
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@ResponseBody
@Param
(
"file"
)
MultipartFile
file
)
{
public
Result
<
String
>
upload
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@RequestParam
(
"filename"
)
MultipartFile
file
)
throws
Exception
{
String
url
=
null
;
Result
<
String
>
data
=
ossService
.
upload
(
userBean
.
getOrgCode
(),
moudle
,
file
);
int
uuid
=
(
int
)
(
Math
.
random
()*
100
+
1
);
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
uuid
+
"-"
+
file
.
getOriginalFilename
();
return
data
;
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
try
{
url
=
oss
.
uploadFile
(
path
,
file
.
getInputStream
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
ResultUtil
.
data
(
url
,
"上传成功!"
);
}
}
}
/**
/**
...
@@ -68,23 +55,10 @@ public class OSSController {
...
@@ -68,23 +55,10 @@ public class OSSController {
@ApiOperation
(
value
=
"批量上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"批量上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
uploads
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
public
Result
<
Object
>
uploads
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@Param
(
"files"
)
List
<
MultipartFile
>
files
)
{
@Param
(
"files"
)
List
<
MultipartFile
>
files
)
{
String
url
=
null
;
Result
<
Object
>
data
=
ossService
.
uploads
(
userBean
.
getOrgCode
(),
moudle
,
files
);
List
<
String
>
list
=
new
ArrayList
<
String
>();
for
(
MultipartFile
file
:
files
)
{
return
data
;
int
uuid
=
(
int
)
(
Math
.
random
()*
100
+
1
);
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
uuid
+
"-"
+
file
.
getOriginalFilename
();
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
try
{
url
=
oss
.
uploadFile
(
path
,
file
.
getInputStream
());
list
.
add
(
url
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ResultUtil
.
data
(
list
,
"上传成功!"
);
}
}
/**
/**
...
@@ -94,8 +68,7 @@ public class OSSController {
...
@@ -94,8 +68,7 @@ public class OSSController {
@ApiOperation
(
value
=
"上传私密文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
@ApiOperation
(
value
=
"上传私密文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
String
>
uploadPrivate
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
public
Result
<
String
>
uploadPrivate
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@Param
(
"file"
)
MultipartFile
file
)
{
@Param
(
"file"
)
MultipartFile
file
)
{
int
uuid
=
(
int
)
(
Math
.
random
()*
100
+
1
);
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
file
.
getOriginalFilename
();
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
uuid
+
"-"
+
file
.
getOriginalFilename
();
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
}
else
{
...
...
src/main/java/cn/timer/api/service/OSSService.java
View file @
828d4d66
...
@@ -11,6 +11,8 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -11,6 +11,8 @@ import org.springframework.web.multipart.MultipartFile;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* 上传文件的实现层
* 上传文件的实现层
...
@@ -54,4 +56,28 @@ public class OSSService implements OSSServiceImpl {
...
@@ -54,4 +56,28 @@ public class OSSService implements OSSServiceImpl {
File
filePath
=
new
File
(
path
);
File
filePath
=
new
File
(
path
);
return
filePath
;
return
filePath
;
}
}
public
Result
<
Object
>
uploads
(
int
orgCode
,
String
moudle
,
List
<
MultipartFile
>
files
){
String
url
=
null
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
for
(
MultipartFile
file
:
files
)
{
String
randomNickname
=
RandomNum
.
getRandomNickname
();
File
filePath
=
filePathUpload
(
orgCode
,
moudle
,
randomNickname
,
file
.
getOriginalFilename
());
int
i
=
0
;
while
(
filePath
.
exists
())
{
filePath
=
filePathUpload
(
orgCode
,
moudle
,
randomNickname
,
file
.
getOriginalFilename
());
i
++;
}
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
try
{
url
=
oss
.
uploadFile
(
filePath
,
file
.
getInputStream
());
list
.
add
(
url
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ResultUtil
.
data
(
list
,
"上传成功!"
);
}
}
}
src/main/java/cn/timer/api/service/impl/OSSServiceImpl.java
View file @
828d4d66
...
@@ -3,7 +3,10 @@ package cn.timer.api.service.impl;
...
@@ -3,7 +3,10 @@ package cn.timer.api.service.impl;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.Result
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
public
interface
OSSServiceImpl
{
public
interface
OSSServiceImpl
{
public
Result
<
String
>
upload
(
int
orgCode
,
String
moudle
,
MultipartFile
file
);
public
Result
<
String
>
upload
(
int
orgCode
,
String
moudle
,
MultipartFile
file
);
public
Result
<
Object
>
uploads
(
int
orgCode
,
String
moudle
,
List
<
MultipartFile
>
files
);
}
}
src/main/java/cn/timer/api/utils/aliyun/AliyunSMS.java
View file @
828d4d66
...
@@ -61,7 +61,7 @@ public class AliyunSMS {
...
@@ -61,7 +61,7 @@ public class AliyunSMS {
/**
/**
*
*
* @param
phon
e
* @param
cod
e
* @param templateCode 1."身份验证验证码" 2."登录确认验证码" 3."登录异常验证码" 4."用户注册验证码"
* @param templateCode 1."身份验证验证码" 2."登录确认验证码" 3."登录异常验证码" 4."用户注册验证码"
* 5."修改密码验证码" 6."信息变更验证码"
* 5."修改密码验证码" 6."信息变更验证码"
*/
*/
...
...
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