Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
exam_master
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
exam_master
Commits
95d5baa2
Commit
95d5baa2
authored
Jun 25, 2024
by
陈立彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传、语音文字提取接口
parent
5e0558a5
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
395 additions
and
6 deletions
+395
-6
pom.xml
pom.xml
+26
-0
ExamController.java
src/main/java/cn/aibreeze/exam/api/ExamController.java
+32
-4
UploadController.java
src/main/java/cn/aibreeze/exam/api/UploadController.java
+84
-0
FileUploadResult.java
src/main/java/cn/aibreeze/exam/config/FileUploadResult.java
+15
-0
MinioConfig.java
src/main/java/cn/aibreeze/exam/config/MinioConfig.java
+43
-0
MinioFileProperties.java
...ain/java/cn/aibreeze/exam/config/MinioFileProperties.java
+25
-0
VoiceToContentResult.java
src/main/java/cn/aibreeze/exam/dto/VoiceToContentResult.java
+13
-0
FileService.java
src/main/java/cn/aibreeze/exam/service/FileService.java
+27
-0
PrivateFileService.java
...ain/java/cn/aibreeze/exam/service/PrivateFileService.java
+80
-0
AliyunNLSFacade.java
src/main/java/cn/aibreeze/exam/util/AliyunNLSFacade.java
+0
-1
application.yml
src/main/resources/application.yml
+50
-1
No files found.
pom.xml
View file @
95d5baa2
...
@@ -71,6 +71,32 @@
...
@@ -71,6 +71,32 @@
<version>
4.6.4
</version>
<version>
4.6.4
</version>
</dependency>
</dependency>
<!-- 分布式文件传输(自建的minio) 和 阿里云OSS的sdk -->
<dependency>
<groupId>
io.minio
</groupId>
<artifactId>
minio
</artifactId>
<version>
8.5.2
</version>
</dependency>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<version>
3.16.2
</version>
</dependency>
<dependency>
<groupId>
cn.smartbreeze.core
</groupId>
<artifactId>
elastic-file-client
</artifactId>
<version>
3.0.7-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
javax.activation
</groupId>
<artifactId>
activation
</artifactId>
<version>
1.1.1
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/cn/aibreeze/exam/api/ExamController.java
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
api
;
package
cn
.
aibreeze
.
exam
.
api
;
import
cn.aibreeze.exam.dto.ApiResponse
;
import
cn.aibreeze.exam.dto.*
;
import
cn.aibreeze.exam.dto.GetQuestionResponseResult
;
import
cn.aibreeze.exam.dto.SessionExamResult
;
import
cn.aibreeze.exam.dto.UpdateQuestionRequestDto
;
import
cn.aibreeze.exam.entity.ElehKnowledgeDo
;
import
cn.aibreeze.exam.entity.ElehKnowledgeDo
;
import
cn.aibreeze.exam.entity.ElehKnowledgeTagDo
;
import
cn.aibreeze.exam.entity.ElehKnowledgeTagDo
;
import
cn.aibreeze.exam.entity.ElehSessionQaRecordDo
;
import
cn.aibreeze.exam.entity.ElehSessionQaRecordDo
;
import
cn.aibreeze.exam.mapper.ElehKnowledgeMapper
;
import
cn.aibreeze.exam.mapper.ElehKnowledgeMapper
;
import
cn.aibreeze.exam.mapper.ElehKnowledgeTagMapper
;
import
cn.aibreeze.exam.mapper.ElehKnowledgeTagMapper
;
import
cn.aibreeze.exam.mapper.ElehSessionQaRecordMapper
;
import
cn.aibreeze.exam.mapper.ElehSessionQaRecordMapper
;
import
cn.aibreeze.exam.util.AliyunNLSFacade
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
io.micrometer.common.util.StringUtils
;
import
io.micrometer.common.util.StringUtils
;
...
@@ -38,6 +36,8 @@ public class ExamController {
...
@@ -38,6 +36,8 @@ public class ExamController {
private
final
StringRedisTemplate
redisTemplate
;
private
final
StringRedisTemplate
redisTemplate
;
private
final
AliyunNLSFacade
aliyunNLSFacade
;
private
static
String
EXAM_REDIS_SESSION_KEY
=
"EXAM_MASTER:%d:%s:%s"
;
private
static
String
EXAM_REDIS_SESSION_KEY
=
"EXAM_MASTER:%d:%s:%s"
;
@GetMapping
(
value
=
"/list"
)
@GetMapping
(
value
=
"/list"
)
...
@@ -156,4 +156,32 @@ public class ExamController {
...
@@ -156,4 +156,32 @@ public class ExamController {
return
ApiResponse
.
ok
(
result
);
return
ApiResponse
.
ok
(
result
);
}
}
@GetMapping
(
value
=
"/voice_to_content"
)
public
ApiResponse
<
VoiceToContentResult
>
voiceToContent
(
@RequestParam
(
value
=
"tenant"
,
required
=
false
)
Integer
tenant
,
@RequestParam
(
value
=
"session_id"
,
required
=
false
)
String
sessionId
,
@RequestParam
(
value
=
"user_id"
,
required
=
false
)
String
userId
,
@RequestParam
(
"file_url"
)
String
fileUrl
)
{
VoiceToContentResult
resultContent
=
new
VoiceToContentResult
();
P2PResponse
<
String
>
textFromMedia
=
aliyunNLSFacade
.
getTextFromMedia
(
fileUrl
);
if
(
textFromMedia
.
isSuccess
())
{
boolean
asrDone
=
false
;
do
{
P2PResponse
<
String
>
asrResult
=
aliyunNLSFacade
.
getAsrResult
(
textFromMedia
.
getBody
());
asrDone
=
asrResult
.
isSuccess
();
resultContent
.
setContent
(
asrResult
.
getBody
());
if
(!
asrDone
)
{
try
{
Thread
.
sleep
(
3000L
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
while
(!
asrDone
);
}
return
ApiResponse
.
ok
(
resultContent
);
}
}
}
src/main/java/cn/aibreeze/exam/api/UploadController.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
api
;
import
cn.aibreeze.exam.config.FileUploadResult
;
import
cn.aibreeze.exam.dto.ApiResponse
;
import
cn.aibreeze.exam.service.PrivateFileService
;
import
cn.aibreeze.exam.util.PeerException
;
import
cn.hutool.core.io.FileUtil
;
import
com.google.common.collect.Lists
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.PostMapping
;
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
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
@Slf4j
@RestController
@RequestMapping
(
value
=
"/common"
)
@RequiredArgsConstructor
public
class
UploadController
{
private
final
PrivateFileService
fileService
;
@PostMapping
(
value
=
"/upload"
)
public
ApiResponse
<
List
<
String
>>
upload
(
@RequestParam
(
"files"
)
MultipartFile
[]
files
)
{
List
<
String
>
urls
=
Lists
.
newArrayList
();
// 判断文件数组长度
if
(
files
.
length
<=
0
){
return
ApiResponse
.
fail
(
"请选择文件"
);
}
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
PeerException
(
"上传失败:"
+
e
.
getMessage
());
}
finally
{
if
(
tmp
!=
null
)
{
tmp
.
delete
();
}
}
}
return
ApiResponse
.
ok
(
urls
);
}
@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
(
"请选择文件"
);
}
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
PeerException
(
"上传失败:"
+
e
.
getMessage
());
}
finally
{
if
(
tmp
!=
null
)
{
tmp
.
delete
();
}
}
}
return
ApiResponse
.
ok
(
fileList
);
}
}
src/main/java/cn/aibreeze/exam/config/FileUploadResult.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
config
;
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/aibreeze/exam/config/MinioConfig.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
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/aibreeze/exam/config/MinioFileProperties.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
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/aibreeze/exam/dto/VoiceToContentResult.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
dto
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
@Data
public
class
VoiceToContentResult
implements
Serializable
{
@JsonProperty
(
"content"
)
private
String
content
;
}
src/main/java/cn/aibreeze/exam/service/FileService.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
service
;
import
java.io.File
;
import
java.io.InputStream
;
public
interface
FileService
{
String
upload
(
String
key
,
File
file
);
String
upload
(
String
key
,
InputStream
inputStream
);
String
getPrefix
();
default
String
processKey
(
String
key
)
{
if
(
key
.
startsWith
(
"/"
))
{
key
=
key
.
substring
(
1
);
}
return
this
.
getPrefix
().
endsWith
(
"/"
)
?
this
.
getPrefix
()
+
key
:
this
.
getPrefix
()
+
"/"
+
key
;
}
InputStream
getFileInputStream
(
String
key
);
// Mono<InputStream> getObjectByKey(String key);
String
getPrivateFileUrlForDownload
(
String
key
);
}
src/main/java/cn/aibreeze/exam/service/PrivateFileService.java
0 → 100644
View file @
95d5baa2
package
cn
.
aibreeze
.
exam
.
service
;
import
cn.aibreeze.exam.config.MinioFileProperties
;
import
cn.aibreeze.exam.util.PeerException
;
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
implements
FileService
{
private
final
MinioFileClient
minioFileClient
;
private
final
MinioFileProperties
fileProperties
;
@Override
public
String
upload
(
String
filename
,
File
file
)
{
return
upload
(
filename
,
IoUtil
.
toStream
(
file
));
}
@Override
public
String
upload
(
String
key
,
InputStream
inputStream
)
{
String
[]
url
=
{
null
};
minioFileClient
.
uploadFile
(
key
,
inputStream
)
.
doOnError
(
e
->
{
log
.
error
(
"上传文件失败"
,
e
);
throw
new
PeerException
(
"上传文件失败"
);
})
.
subscribe
(
res
->
{
url
[
0
]
=
res
.
getUrl
();
});
return
url
[
0
];
}
@Override
public
String
getPrefix
()
{
return
null
;
}
@Override
public
InputStream
getFileInputStream
(
String
key
)
{
return
minioFileClient
.
getFileByKey
(
key
).
block
();
}
@Override
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/java/cn/aibreeze/exam/util/AliyunNLSFacade.java
View file @
95d5baa2
...
@@ -136,7 +136,6 @@ public class AliyunNLSFacade {
...
@@ -136,7 +136,6 @@ public class AliyunNLSFacade {
}
else
if
(
StringUtils
.
equals
(
"3"
,
line
.
getString
(
"SpeakerId"
)))
{
}
else
if
(
StringUtils
.
equals
(
"3"
,
line
.
getString
(
"SpeakerId"
)))
{
sb
.
append
(
"说话人3:"
+
line
.
getString
(
"Text"
)
+
"\n"
);
sb
.
append
(
"说话人3:"
+
line
.
getString
(
"Text"
)
+
"\n"
);
}
}
System
.
out
.
println
(
"美容师:"
+
line
.
getString
(
"Text"
));
}
}
}
}
return
P2PResponse
.
ok
(
sb
.
toString
());
return
P2PResponse
.
ok
(
sb
.
toString
());
...
...
src/main/resources/application.yml
View file @
95d5baa2
...
@@ -32,7 +32,34 @@ spring:
...
@@ -32,7 +32,34 @@ spring:
username
:
future
username
:
future
password
:
future123456
password
:
future123456
url
:
jdbc:mysql://125.94.43.20:30306/pilot?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
url
:
jdbc:mysql://125.94.43.20:30306/pilot?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
data
:
redis
:
password
:
future123456
host
:
127.0.0.1
port
:
6379
database
:
6
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/
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
:
spring
:
config
:
config
:
...
@@ -47,4 +74,26 @@ spring:
...
@@ -47,4 +74,26 @@ spring:
password
:
future123456
password
:
future123456
host
:
redis-standalone.infra
host
:
redis-standalone.infra
port
:
6379
port
:
6379
database
:
6
database
:
6
\ No newline at end of file
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/
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/
\ No newline at end of file
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