Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elleai
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
ai-tech
E
ellehuis-group
backend
elleai
Commits
f64e2bc4
Commit
f64e2bc4
authored
Oct 23, 2024
by
陈立彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传
parent
8d003ad8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
261 additions
and
0 deletions
+261
-0
ElleaiApplication.java
src/main/java/cn/breeze/elleai/ElleaiApplication.java
+2
-0
FileUploadResult.java
...eze/elleai/application/dto/response/FileUploadResult.java
+15
-0
MinioConfig.java
src/main/java/cn/breeze/elleai/config/MinioConfig.java
+43
-0
MinioFileProperties.java
...ain/java/cn/breeze/elleai/config/MinioFileProperties.java
+25
-0
CommonController.java
...a/cn/breeze/elleai/controller/admin/CommonController.java
+67
-0
ExamineServiceImpl.java
...ze/elleai/domain/sparring/service/ExamineServiceImpl.java
+9
-0
PrivateFileService.java
src/main/java/cn/breeze/elleai/util/PrivateFileService.java
+75
-0
application.yml
src/main/resources/application.yml
+25
-0
No files found.
src/main/java/cn/breeze/elleai/ElleaiApplication.java
View file @
f64e2bc4
package
cn
.
breeze
.
elleai
;
import
cn.smartbreeze.core.file.config.EnableFileClient
;
import
com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -11,6 +12,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableAsync
@EnableKnife4j
@EnableScheduling
@EnableFileClient
public
class
ElleaiApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/cn/breeze/elleai/application/dto/response/FileUploadResult.java
0 → 100644
View file @
f64e2bc4
package
cn
.
breeze
.
elleai
.
application
.
dto
.
response
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
@Data
@Accessors
(
chain
=
true
)
public
class
FileUploadResult
implements
Serializable
{
private
String
fileName
;
private
String
filePath
;
}
src/main/java/cn/breeze/elleai/config/MinioConfig.java
0 → 100644
View file @
f64e2bc4
package
cn
.
breeze
.
elleai
.
config
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.smartbreeze.core.file.client.MinioFileClient
;
import
cn.smartbreeze.core.file.props.FileProperties
;
import
io.minio.MinioClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
@Configuration
public
class
MinioConfig
{
@Autowired
private
MinioFileProperties
fileProperties
;
@Bean
public
MinioClient
minioClient
()
{
return
MinioClient
.
builder
()
.
endpoint
(
fileProperties
.
getEndpoint
())
.
credentials
(
fileProperties
.
getSecretId
(),
fileProperties
.
getSecretKey
())
.
build
();
}
@Bean
public
MinioFileClient
privateFileClient
()
{
return
new
MinioFileClient
(
getFileProperties
(),
minioClient
());
}
@Bean
@Primary
public
MinioFileClient
minioFileClient
(
MinioClient
minioClient
)
{
return
new
MinioFileClient
(
getFileProperties
(),
minioClient
);
}
private
FileProperties
getFileProperties
()
{
FileProperties
properties
=
new
FileProperties
();
BeanUtil
.
copyProperties
(
fileProperties
,
properties
);
return
properties
;
}
}
src/main/java/cn/breeze/elleai/config/MinioFileProperties.java
0 → 100644
View file @
f64e2bc4
package
cn
.
breeze
.
elleai
.
config
;
import
cn.smartbreeze.core.file.config.StoreType
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
@ConfigurationProperties
(
prefix
=
"minio-file"
)
@EnableConfigurationProperties
@Configuration
@Data
public
class
MinioFileProperties
{
private
StoreType
store
;
private
String
bucket
;
private
String
secretId
;
private
String
secretKey
;
private
String
endpoint
;
private
String
uploadPrefix
=
""
;
private
String
domainPrefix
;
private
String
region
=
"default"
;
private
String
downloadUrlPrefix
;
}
src/main/java/cn/breeze/elleai/controller/admin/CommonController.java
View file @
f64e2bc4
...
...
@@ -6,18 +6,29 @@ import cn.breeze.elleai.application.dto.PageResult;
import
cn.breeze.elleai.application.dto.request.ProperNounRequestDto
;
import
cn.breeze.elleai.application.dto.request.ProperNounSaveDto
;
import
cn.breeze.elleai.application.dto.response.AppRoleDto
;
import
cn.breeze.elleai.application.dto.response.FileUploadResult
;
import
cn.breeze.elleai.application.dto.response.KnowledgeDataBaseCategoryDto
;
import
cn.breeze.elleai.application.dto.response.ProperNounDto
;
import
cn.breeze.elleai.application.service.AppCommonService
;
import
cn.breeze.elleai.config.QueryParam
;
import
cn.breeze.elleai.exception.InternalException
;
import
cn.breeze.elleai.util.PrivateFileService
;
import
cn.hutool.core.io.FileUtil
;
import
com.google.common.collect.Lists
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
@Slf4j
@RestController
@RequestMapping
(
value
=
"/admin/common"
)
@Tag
(
name
=
"管理端-公共服务"
,
description
=
"公共服务"
)
...
...
@@ -26,6 +37,8 @@ public class CommonController {
private
final
AppCommonService
commonService
;
private
final
PrivateFileService
fileService
;
@Operation
(
summary
=
"专有名词详情"
)
@GetMapping
(
"/proper_noun/detail/{id}"
)
...
...
@@ -77,4 +90,58 @@ public class CommonController {
List
<
AppRoleDto
>
result
=
commonService
.
appRoleList
();
return
ApiResponse
.
ok
(
result
);
}
@Operation
(
summary
=
"上传"
)
@PostMapping
(
value
=
"/upload"
)
public
ApiResponse
<
List
<
String
>>
upload
(
@RequestParam
(
"files"
)
MultipartFile
[]
files
)
{
List
<
String
>
urls
=
Lists
.
newArrayList
();
// 判断文件数组长度
if
(
files
.
length
<=
0
){
return
ApiResponse
.
fail
(-
1
,
"请选择文件"
);
}
for
(
MultipartFile
file
:
files
){
File
tmp
=
null
;
try
{
tmp
=
File
.
createTempFile
(
"upload"
,
""
);
file
.
transferTo
(
tmp
);
String
key
=
UUID
.
randomUUID
().
toString
()
+
"."
+
FileUtil
.
extName
(
file
.
getOriginalFilename
());
urls
.
add
(
fileService
.
upload
(
key
,
tmp
));
}
catch
(
Exception
e
)
{
log
.
error
(
"upload error,"
,
e
);
throw
new
InternalException
(
1000
,
"上传失败:"
+
e
.
getMessage
());
}
finally
{
if
(
tmp
!=
null
)
{
tmp
.
delete
();
}
}
}
return
ApiResponse
.
ok
(
urls
);
}
@Operation
(
summary
=
"上传带文件名返回"
)
@PostMapping
(
value
=
"file/upload"
)
public
ApiResponse
<
List
<
FileUploadResult
>>
fileUpload
(
@RequestParam
(
"files"
)
MultipartFile
[]
files
)
{
List
<
FileUploadResult
>
fileList
=
new
ArrayList
<>();
// 判断文件数组长度
if
(
files
.
length
<=
0
){
return
ApiResponse
.
fail
(-
1
,
"请选择文件"
);
}
for
(
MultipartFile
file
:
files
){
File
tmp
=
null
;
try
{
tmp
=
File
.
createTempFile
(
"upload"
,
""
);
file
.
transferTo
(
tmp
);
String
key
=
UUID
.
randomUUID
()
+
"."
+
FileUtil
.
extName
(
file
.
getOriginalFilename
());
fileList
.
add
(
new
FileUploadResult
().
setFileName
(
file
.
getOriginalFilename
()).
setFilePath
(
fileService
.
upload
(
key
,
tmp
)));
}
catch
(
Exception
e
)
{
log
.
error
(
"upload error,"
,
e
);
throw
new
InternalException
(
1000
,
"上传失败:"
+
e
.
getMessage
());
}
finally
{
if
(
tmp
!=
null
)
{
tmp
.
delete
();
}
}
}
return
ApiResponse
.
ok
(
fileList
);
}
}
src/main/java/cn/breeze/elleai/domain/sparring/service/ExamineServiceImpl.java
View file @
f64e2bc4
...
...
@@ -561,6 +561,9 @@ public class ExamineServiceImpl implements ExamineService {
if
(
Objects
.
nonNull
(
request
.
getStatus
()))
{
queryWrapper
.
and
(
WIKI_CATEGORY_ENTITY
.
STATUS
.
eq
(
request
.
getStatus
()));
}
if
(
Objects
.
nonNull
(
request
.
getParentId
()))
{
queryWrapper
.
and
(
WIKI_CATEGORY_ENTITY
.
PARENT_ID
.
eq
(
request
.
getParentId
()));
}
if
(
Objects
.
nonNull
(
request
.
getLevel
()))
{
queryWrapper
.
and
(
WIKI_CATEGORY_ENTITY
.
LEVEL
.
eq
(
request
.
getLevel
()));
}
...
...
@@ -581,6 +584,12 @@ public class ExamineServiceImpl implements ExamineService {
if
(
Objects
.
nonNull
(
request
.
getStatus
()))
{
queryWrapper
.
where
(
WIKI_CATEGORY_ENTITY
.
STATUS
.
eq
(
request
.
getStatus
()));
}
if
(
Objects
.
nonNull
(
request
.
getParentId
()))
{
queryWrapper
.
and
(
WIKI_CATEGORY_ENTITY
.
PARENT_ID
.
eq
(
request
.
getParentId
()));
}
if
(
Objects
.
nonNull
(
request
.
getLevel
()))
{
queryWrapper
.
and
(
WIKI_CATEGORY_ENTITY
.
LEVEL
.
eq
(
request
.
getLevel
()));
}
queryWrapper
.
orderBy
(
WIKI_CATEGORY_ENTITY
.
CREATE_TIME
,
false
);
return
wikiCategoryMapper
.
selectListByQueryAs
(
queryWrapper
,
WikiCategoryResponseModel
.
class
);
...
...
src/main/java/cn/breeze/elleai/util/PrivateFileService.java
0 → 100644
View file @
f64e2bc4
package
cn
.
breeze
.
elleai
.
util
;
import
cn.breeze.elleai.config.MinioFileProperties
;
import
cn.breeze.elleai.exception.InternalException
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.smartbreeze.core.file.client.MinioFileClient
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.io.InputStream
;
@Slf4j
@Component
@RequiredArgsConstructor
public
class
PrivateFileService
{
private
final
MinioFileClient
minioFileClient
;
private
final
MinioFileProperties
fileProperties
;
public
String
upload
(
String
filename
,
File
file
)
{
return
upload
(
filename
,
IoUtil
.
toStream
(
file
));
}
public
String
upload
(
String
key
,
InputStream
inputStream
)
{
String
[]
url
=
{
null
};
minioFileClient
.
uploadFile
(
key
,
inputStream
)
.
doOnError
(
e
->
{
log
.
error
(
"上传文件失败"
,
e
);
throw
new
InternalException
(
1000
,
"上传文件失败"
);
})
.
subscribe
(
res
->
{
url
[
0
]
=
res
.
getUrl
();
});
return
url
[
0
];
}
public
String
getPrefix
()
{
return
null
;
}
public
InputStream
getFileInputStream
(
String
key
)
{
return
minioFileClient
.
getFileByKey
(
key
).
block
();
}
public
String
getPrivateFileUrlForDownload
(
String
key
)
{
if
(
StrUtil
.
isBlank
(
key
))
{
return
""
;
}
String
prefix
=
fileProperties
.
getUploadPrefix
();
prefix
=
StrUtil
.
isBlank
(
prefix
)
?
""
:
prefix
;
if
(
prefix
.
startsWith
(
"/"
))
{
prefix
=
prefix
.
substring
(
1
);
}
if
(
prefix
.
endsWith
(
"/"
))
{
prefix
=
prefix
.
substring
(
0
,
prefix
.
length
()
-
1
);
}
if
(
key
.
startsWith
(
"/"
))
{
key
=
key
.
substring
(
1
);
}
String
query
=
prefix
.
concat
(
"/"
).
concat
(
key
);
return
StrUtil
.
nullToEmpty
(
fileProperties
.
getDownloadUrlPrefix
())
+
"admin/common/getfile?fn="
+
query
;
}
}
src/main/resources/application.yml
View file @
f64e2bc4
...
...
@@ -11,6 +11,10 @@ spring:
time-zone
:
GMT+8
default-property-inclusion
:
non_null
property-naming-strategy
:
SNAKE_CASE
http
:
multipart
:
max-file-size
:
100Mb
max-request-size
:
100Mb
springdoc
:
swagger-ui
:
path
:
/swagger-ui.html
...
...
@@ -54,6 +58,16 @@ spring:
password
:
future123456
database
:
11
minio-file
:
store
:
minio
bucket
:
files
endpoint
:
http://minio:9000
secret-id
:
smartbreeze
secret-key
:
smartbreeze
domain-prefix
:
http://files.hc.wxpai.cn/
intercept-prefix
:
http://minio:9000/
upload-prefix
:
upload
download-url-prefix
:
http://minio:9000/
---
spring
:
...
...
@@ -87,3 +101,14 @@ milvus:
host
:
10.0.8.210
port
:
19530
database
:
default
minio-file
:
store
:
minio
bucket
:
files
endpoint
:
http://10.0.8.210:9000
secret-id
:
admin
secret-key
:
future123456
domain-prefix
:
https://elleai.e-tools.cn/
intercept-prefix
:
http://10.0.8.210:9000/
upload-prefix
:
upload
download-url-prefix
:
http://10.0.8.210:9000/
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