Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
poc
poc-api
Commits
97d0dd48
Commit
97d0dd48
authored
Jan 12, 2026
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(storage): 扩展文件上传功能支持自定义文件名
parent
de20005a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
16 deletions
+25
-16
SoftwareCopyRightScheduler.java
...tware_copyright/scheduler/SoftwareCopyRightScheduler.java
+11
-11
BosConfigService.java
...main/java/cn/com/poc/common/service/BosConfigService.java
+3
-1
BosConfigServiceImpl.java
.../cn/com/poc/common/service/impl/BosConfigServiceImpl.java
+10
-3
ContentReportTest.java
src/test/java/cn/com/poc/expose/ContentReportTest.java
+1
-1
No files found.
src/main/java/cn/com/poc/ai_software_copyright/scheduler/SoftwareCopyRightScheduler.java
View file @
97d0dd48
...
@@ -191,7 +191,7 @@ public class SoftwareCopyRightScheduler {
...
@@ -191,7 +191,7 @@ public class SoftwareCopyRightScheduler {
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
obj
.
toString
());
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
obj
.
toString
());
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"result"
);
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"result"
);
if
(
jsonArray
!=
null
)
{
if
(
jsonArray
!=
null
)
{
String
url
=
createSourceCodeDocument
(
jsonArray
);
String
url
=
createSourceCodeDocument
(
jsonArray
,
"源代码"
);
recordEntity
.
setSourceCode
(
url
);
recordEntity
.
setSourceCode
(
url
);
isChange
=
true
;
isChange
=
true
;
}
}
...
@@ -212,7 +212,7 @@ public class SoftwareCopyRightScheduler {
...
@@ -212,7 +212,7 @@ public class SoftwareCopyRightScheduler {
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
obj
.
toString
());
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
obj
.
toString
());
String
result
=
jsonObject
.
getString
(
"result"
);
String
result
=
jsonObject
.
getString
(
"result"
);
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
String
url
=
createSimpleDocument
(
result
);
String
url
=
createSimpleDocument
(
result
,
"电脑使用说明书"
);
recordEntity
.
setPcOperatingManual
(
url
);
recordEntity
.
setPcOperatingManual
(
url
);
isChange
=
true
;
isChange
=
true
;
}
}
...
@@ -234,7 +234,7 @@ public class SoftwareCopyRightScheduler {
...
@@ -234,7 +234,7 @@ public class SoftwareCopyRightScheduler {
String
result
=
jsonObject
.
getString
(
"result"
);
String
result
=
jsonObject
.
getString
(
"result"
);
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
String
url
=
createSimpleDocument
(
result
);
String
url
=
createSimpleDocument
(
result
,
"手机使用说明书"
);
recordEntity
.
setPhOperatingManual
(
url
);
recordEntity
.
setPhOperatingManual
(
url
);
isChange
=
true
;
isChange
=
true
;
}
}
...
@@ -324,20 +324,20 @@ public class SoftwareCopyRightScheduler {
...
@@ -324,20 +324,20 @@ public class SoftwareCopyRightScheduler {
@Resource
@Resource
private
MD2WordService
md2WordService
;
private
MD2WordService
md2WordService
;
private
String
createSourceCodeDocument
(
JSONArray
jsonArray
)
throws
Exception
{
private
String
createSourceCodeDocument
(
JSONArray
jsonArray
,
String
fileName
)
throws
Exception
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
String
content
=
jsonArray
.
getString
(
i
);
String
content
=
jsonArray
.
getString
(
i
);
stringBuilder
.
append
(
content
);
stringBuilder
.
append
(
content
);
}
}
return
createSimpleDocument
(
stringBuilder
.
toString
());
return
createSimpleDocument
(
stringBuilder
.
toString
()
,
fileName
);
}
}
private
String
createSimpleDocument
(
String
content
)
throws
Exception
{
private
String
createSimpleDocument
(
String
content
,
String
fileName
)
throws
Exception
{
return
md2wordAndUploadURL
(
content
);
return
md2wordAndUploadURL
(
content
,
fileName
);
}
}
private
String
md2wordAndUploadURL
(
String
mdContent
)
throws
Exception
{
private
String
md2wordAndUploadURL
(
String
mdContent
,
String
fileName
)
throws
Exception
{
File
file
=
null
;
File
file
=
null
;
FileOutputStream
fileOutputStream
=
null
;
FileOutputStream
fileOutputStream
=
null
;
FileInputStream
fileInputStream
=
null
;
FileInputStream
fileInputStream
=
null
;
...
@@ -351,7 +351,7 @@ public class SoftwareCopyRightScheduler {
...
@@ -351,7 +351,7 @@ public class SoftwareCopyRightScheduler {
byte
[]
bytes
=
new
byte
[
fileInputStream
.
available
()];
byte
[]
bytes
=
new
byte
[
fileInputStream
.
available
()];
fileInputStream
.
read
(
bytes
);
fileInputStream
.
read
(
bytes
);
String
mdURL
=
uploadDocument
(
bytes
,
file
.
getName
()
);
String
mdURL
=
uploadDocument
(
bytes
,
file
Name
);
Md2WordResponse
response
=
new
Md2WordResponse
();
Md2WordResponse
response
=
new
Md2WordResponse
();
response
.
setFilePath
(
mdURL
);
response
.
setFilePath
(
mdURL
);
Md2WordResult
md2WordResult
=
md2WordService
.
md2Word
(
response
);
Md2WordResult
md2WordResult
=
md2WordService
.
md2Word
(
response
);
...
@@ -369,10 +369,10 @@ public class SoftwareCopyRightScheduler {
...
@@ -369,10 +369,10 @@ public class SoftwareCopyRightScheduler {
private
String
uploadDocument
(
byte
[]
documentBytes
,
String
fileName
)
throws
Exception
{
private
String
uploadDocument
(
byte
[]
documentBytes
,
String
fileName
)
throws
Exception
{
File
tempFile
=
null
;
File
tempFile
=
null
;
try
{
try
{
tempFile
=
File
.
createTempFile
(
fileName
,
DOCX_EXTENSION
);
tempFile
=
File
.
createTempFile
(
UUIDUtils
.
getUUID8
()
,
DOCX_EXTENSION
);
FileUtil
.
writeBytes
(
documentBytes
,
tempFile
);
FileUtil
.
writeBytes
(
documentBytes
,
tempFile
);
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
tempFile
))
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
tempFile
))
{
return
bosConfigService
.
upload
(
fileInputStream
,
DOCX_FILE_TYPE
,
""
);
return
bosConfigService
.
upload
(
fileInputStream
,
DOCX_FILE_TYPE
,
""
,
fileName
);
}
}
}
finally
{
}
finally
{
if
(
tempFile
!=
null
&&
tempFile
.
exists
())
{
if
(
tempFile
!=
null
&&
tempFile
.
exists
())
{
...
...
src/main/java/cn/com/poc/common/service/BosConfigService.java
View file @
97d0dd48
...
@@ -7,12 +7,14 @@ import java.io.InputStream;
...
@@ -7,12 +7,14 @@ import java.io.InputStream;
public
interface
BosConfigService
extends
BaseService
{
public
interface
BosConfigService
extends
BaseService
{
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
uploadFolder
,
String
fileName
,
String
fileType
)
throws
IOException
;
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
uploadFolder
,
String
fileName
,
String
fileType
)
throws
IOException
;
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
fileName
,
String
fileType
)
throws
IOException
;
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
fileName
,
String
fileType
)
throws
IOException
;
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
)
throws
IOException
;
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
)
throws
IOException
;
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
,
String
fileName
)
throws
IOException
;
String
uploadImageByBase64
(
String
base64
)
throws
IOException
;
String
uploadImageByBase64
(
String
base64
)
throws
IOException
;
...
...
src/main/java/cn/com/poc/common/service/impl/BosConfigServiceImpl.java
View file @
97d0dd48
...
@@ -37,7 +37,8 @@ public class BosConfigServiceImpl implements BosConfigService {
...
@@ -37,7 +37,8 @@ public class BosConfigServiceImpl implements BosConfigService {
@Override
@Override
public
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
uploadFolder
,
String
fileName
,
String
fileType
)
throws
IOException
{
public
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
uploadFolder
,
String
fileName
,
String
fileType
)
throws
IOException
{
String
BUCKET_NAME
=
fmxParamConfigService
.
getParam
(
"bos.bucketName"
);
String
BUCKET_NAME
=
fmxParamConfigService
.
getParam
(
"bos.bucketName"
);
String
END_POINT
=
fmxParamConfigService
.
getParam
(
"bos.endPoint"
);
String
END_POINT
=
fmxParamConfigService
.
getParam
(
"bos.endPoint"
);
String
FILE_NAME
=
fileName
+
"."
+
fileType
;
String
FILE_NAME
=
fileName
+
"."
+
fileType
;
...
@@ -79,7 +80,8 @@ public class BosConfigServiceImpl implements BosConfigService {
...
@@ -79,7 +80,8 @@ public class BosConfigServiceImpl implements BosConfigService {
}
}
@Override
@Override
public
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
)
{
public
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
,
String
fileName
)
throws
IOException
{
String
BUCKET_NAME
=
fmxParamConfigService
.
getParam
(
"bos.bucketName"
);
String
BUCKET_NAME
=
fmxParamConfigService
.
getParam
(
"bos.bucketName"
);
String
END_POINT
=
fmxParamConfigService
.
getParam
(
"bos.endPoint"
);
String
END_POINT
=
fmxParamConfigService
.
getParam
(
"bos.endPoint"
);
String
FILE_NAME
=
createFileName
(
fileType
);
String
FILE_NAME
=
createFileName
(
fileType
);
...
@@ -89,7 +91,7 @@ public class BosConfigServiceImpl implements BosConfigService {
...
@@ -89,7 +91,7 @@ public class BosConfigServiceImpl implements BosConfigService {
meta
.
setContentType
(
contentType
);
meta
.
setContentType
(
contentType
);
// 设置内容被下载时的名称。
// 设置内容被下载时的名称。
if
(
StringUtils
.
isNoneBlank
(
FILE_NAME
))
{
if
(
StringUtils
.
isNoneBlank
(
FILE_NAME
))
{
meta
.
setContentDisposition
(
"attachment; filename="
+
FILE_NAME
);
meta
.
setContentDisposition
(
"attachment; filename="
+
(
fileName
+
"."
+
fileType
)
);
}
}
// 设置内容被下载时的编码格式。
// 设置内容被下载时的编码格式。
meta
.
setContentEncoding
(
StandardCharsets
.
UTF_8
.
displayName
());
meta
.
setContentEncoding
(
StandardCharsets
.
UTF_8
.
displayName
());
...
@@ -130,6 +132,11 @@ public class BosConfigServiceImpl implements BosConfigService {
...
@@ -130,6 +132,11 @@ public class BosConfigServiceImpl implements BosConfigService {
}
}
}
}
@Override
public
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
)
throws
IOException
{
return
upload
(
inputStream
,
fileType
,
contentType
,
createFileName
(
fileType
));
}
@Override
@Override
public
String
uploadImageByBase64
(
String
base64
)
throws
IOException
{
public
String
uploadImageByBase64
(
String
base64
)
throws
IOException
{
...
...
src/test/java/cn/com/poc/expose/ContentReportTest.java
View file @
97d0dd48
...
@@ -73,7 +73,7 @@ public class ContentReportTest {
...
@@ -73,7 +73,7 @@ public class ContentReportTest {
FileOutputStream
ostream
=
new
FileOutputStream
(
file
);
FileOutputStream
ostream
=
new
FileOutputStream
(
file
);
poifs
.
writeFilesystem
(
ostream
);
poifs
.
writeFilesystem
(
ostream
);
FileInputStream
fileInputStream
=
new
FileInputStream
(
file
);
FileInputStream
fileInputStream
=
new
FileInputStream
(
file
);
String
upload
=
bosConfigService
.
upload
(
fileInputStream
,
"docx"
,
"application/msword"
);
String
upload
=
bosConfigService
.
upload
(
fileInputStream
,
"docx"
,
"application/msword"
,
"111-222"
);
bais
.
close
();
bais
.
close
();
ostream
.
close
();
ostream
.
close
();
poifs
.
close
();
poifs
.
close
();
...
...
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