Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rs-cloud-platform
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周健威
rs-cloud-platform
Commits
3e362662
Commit
3e362662
authored
Sep 09, 2024
by
周健威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一数据库上传接口
parent
f787fe20
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
26 deletions
+45
-26
UploadController.java
...ns/platform/rs/universal/controller/UploadController.java
+8
-22
UploadService.java
...m/upyuns/platform/rs/universal/service/UploadService.java
+35
-0
AdminDataTempcacheController.java
...m/rs/website/controller/AdminDataTempcacheController.java
+2
-4
No files found.
rs-universal/rs-universal-server/src/main/java/com/upyuns/platform/rs/universal/controller/UploadController.java
View file @
3e362662
...
...
@@ -162,21 +162,14 @@ public class UploadController{
return
ObjectRestResponse
.
succ
(
data
);
}
// @PostMapping("/app/unauth/download")
// public byte[] downloadFile(@RequestBody String fileUrl) {
// byte[] fileBytes = null;
// try {
//
// File file = new File(fileUrl);
// InputStream inputStream = new FileInputStream(file);
// fileBytes = StreamUtils.copyToByteArray(inputStream);
// } catch (Exception e) {
// e.printStackTrace();
// }
// return fileBytes;
// }
@RequestMapping
(
value
=
"/app/unauth/admin/uploadTempcaheFile"
,
method
=
RequestMethod
.
POST
)
public
ObjectRestResponse
uploadTempcaheFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"prefix"
,
defaultValue
=
"upload"
)
String
prefix
)
throws
Exception
{
FileData
data
=
uploadService
.
uploadTempcaheFile
(
file
,
prefix
);
return
ObjectRestResponse
.
succ
(
data
);
}
@RequestMapping
(
value
=
"/app/unauth/admin/upload250"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
uploads250
(
...
...
@@ -184,13 +177,6 @@ public class UploadController{
@RequestParam
(
value
=
"prefix"
,
defaultValue
=
"admin"
)
String
prefix
)
throws
Exception
{
String
contentType
=
file
.
getContentType
();
//图片文件类型
// String fileName = file.getOriginalFilename(); //图片名字
/* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) {
return JsonResultUtil.createFailedResult(2001,"格式不对!!!");
}*/
// if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
// return JsonResultUtil.createFailedResult(2002,"大小超过限制!!!");
// }
return
JsonResultUtil
.
createSuccessResultWithObj
(
uploadService
.
uploadFile250
(
file
,
prefix
));
}
...
...
rs-universal/rs-universal-server/src/main/java/com/upyuns/platform/rs/universal/service/UploadService.java
View file @
3e362662
...
...
@@ -45,6 +45,9 @@ public class UploadService {
@Value
(
"${universal.gaindataPath}"
)
private
String
gaindataPath
;
@Value
(
"${universal.tempcachePath}"
)
private
String
tempcachePath
;
@Value
(
"${universal.videoUploadPath}"
)
private
String
videoUploadPath
;
...
...
@@ -175,6 +178,38 @@ public class UploadService {
return
fileData
;
}
public
FileData
uploadTempcaheFile
(
MultipartFile
file
,
String
prefix
)
throws
Exception
{
//创建本日存放目录
DateTime
now
=
DateTime
.
now
();
String
dirPath
=
"/"
+
prefix
;
String
todayStr
=
now
.
toString
(
GAINFILE_DATE_TIME_FORMATTER
);
String
redisNoKey
=
RedisKey
.
UPLOAD_FILE_NO_PREFIX
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
Long
no
=
redisTemplate
.
opsForValue
().
increment
(
redisNoKey
);
if
(
no
.
equals
(
1
l
)){
redisTemplate
.
expire
(
redisNoKey
,
1
,
TimeUnit
.
DAYS
);
}
String
noStr
=
todayStr
+
"_"
+
no
;
String
fileName
=
file
.
getOriginalFilename
();
String
realFileRelPath
=
tempcachePath
+
dirPath
+
"/"
+
noStr
+
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
String
filetype
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
long
fileSize
=
file
.
getSize
();
double
fileSizeInMB
=
(
double
)
fileSize
/
(
1024
*
1024
);
// 转换为 MB
double
roundedFileSizeInMB
=
Math
.
round
(
fileSizeInMB
*
100.0
)
/
100.0
;
// 保留两位小数
String
fileSizeString
=
String
.
format
(
"%.2f MB"
,
roundedFileSizeInMB
);
//文件存放路径
String
filePath
=
baseUploadPath
+
realFileRelPath
;
//将文件写入指定位置
FileUtils
.
copyInputStreamToFile
(
file
.
getInputStream
(),
new
File
(
filePath
));
realFileRelPath
=
xx_url
+
SystemConfig
.
XXMP_URL
+
realFileRelPath
;
FileData
fileData
=
new
FileData
();
fileData
.
setFilename
(
fileName
);
fileData
.
setFiletype
(
filetype
);
fileData
.
setFilesize
(
fileSizeString
);
fileData
.
setFileurl
(
realFileRelPath
);
fileData
.
setFilepath
(
filePath
);
return
fileData
;
}
// public String uploadFile250(MultipartFile file, String prefix) throws Exception {
//// // 创建本日存放目录
//// DateTime now = DateTime.now();
...
...
rs-website/rs-website-server/src/main/java/com/upyuns/platform/rs/website/controller/AdminDataTempcacheController.java
View file @
3e362662
...
...
@@ -21,10 +21,8 @@ import com.upyuns.platform.rs.website.entity.GainData;
import
io.swagger.annotations.ApiModelProperty
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
tk.mybatis.mapper.entity.Example
;
import
java.util.List
;
...
...
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