Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
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
王飞
vehicle-quality-review
Commits
20424dcd
Commit
20424dcd
authored
Jun 20, 2024
by
wdy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
车型试验原始记录转为图片
parent
a01bd1ee
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
271 additions
and
0 deletions
+271
-0
Task.java
quality-review/src/main/java/com/ruoyi/domain/Task.java
+3
-0
TaskService.java
...y-review/src/main/java/com/ruoyi/service/TaskService.java
+2
-0
TaskServiceImpl.java
...src/main/java/com/ruoyi/service/impl/TaskServiceImpl.java
+117
-0
TaskController.java
...ty-review/src/main/java/com/ruoyi/web/TaskController.java
+6
-0
TaskPictureRequest.java
...c/main/java/com/ruoyi/web/request/TaskPictureRequest.java
+16
-0
TaskMapper.xml
quality-review/src/main/resources/mapper/TaskMapper.xml
+1
-0
pom.xml
ruoyi-admin/pom.xml
+7
-0
TestPdfBox.java
ruoyi-admin/src/test/java/com/ruoyi/TestPdfBox.java
+119
-0
No files found.
quality-review/src/main/java/com/ruoyi/domain/Task.java
View file @
20424dcd
...
...
@@ -178,6 +178,9 @@ public class Task {
@ApiModelProperty
(
"子任务指针最大值"
)
private
int
maxPointer
;
@ApiModelProperty
(
"图片地址"
)
private
String
pictureUrl
;
@ApiModelProperty
(
"检验项目名称"
)
@TableField
(
exist
=
false
)
private
String
inspectionItemName
;
...
...
quality-review/src/main/java/com/ruoyi/service/TaskService.java
View file @
20424dcd
...
...
@@ -68,4 +68,6 @@ public interface TaskService extends IService<Task> {
DataStatisticsResponse
dataStatistics
(
TaskGetInfoRequest
request
);
String
createProject
(
String
request
)
throws
IOException
;
String
getPicture
(
TaskPictureRequest
request
)
throws
IOException
;
}
quality-review/src/main/java/com/ruoyi/service/impl/TaskServiceImpl.java
View file @
20424dcd
...
...
@@ -23,13 +23,26 @@ import com.ruoyi.service.*;
import
com.ruoyi.system.service.ISysUserService
;
import
com.ruoyi.web.request.*
;
import
com.ruoyi.web.response.*
;
import
io.minio.MinioClient
;
import
io.minio.ObjectWriteArgs
;
import
io.minio.PutObjectArgs
;
import
okhttp3.*
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
...
...
@@ -38,6 +51,18 @@ import java.util.stream.Collectors;
@Service
public
class
TaskServiceImpl
extends
ServiceImpl
<
TaskMapper
,
Task
>
implements
TaskService
{
@Value
(
"${minio.bucketName}"
)
private
String
bucketName
;
@Value
(
"${minio.url}"
)
private
String
minioEndpoint
;
@Value
(
"${minio.accessKey}"
)
private
String
accessKey
;
@Value
(
"${minio.secretKey}"
)
private
String
secretKey
;
@Autowired
private
TaskMapper
taskMapper
;
...
...
@@ -819,6 +844,98 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
return
testSchemeId
;
}
@Override
public
String
getPicture
(
TaskPictureRequest
request
)
throws
IOException
{
Task
task
=
taskMapper
.
selectById
(
request
.
getTaskId
());
if
(
task
.
getPictureUrl
()
!=
null
)
{
return
task
.
getPictureUrl
();
}
else
{
String
pictureUrl
=
processRemotePDF
(
request
.
getUrl
());
task
.
setPictureUrl
(
pictureUrl
);
taskMapper
.
updateById
(
task
);
return
pictureUrl
;
}
}
public
String
processRemotePDF
(
String
urlStr
)
throws
IOException
{
URL
url
=
new
URL
(
urlStr
);
String
pictureUrl
=
""
;
// 打开远程连接
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"GET"
);
// 获取输入流
try
(
InputStream
inputStream
=
connection
.
getInputStream
())
{
// 加载PDF文档
PDDocument
doc
=
PDDocument
.
load
(
inputStream
);
PDFRenderer
renderer
=
new
PDFRenderer
(
doc
);
// 遍历每页pdf
for
(
int
i
=
0
;
i
<
doc
.
getNumberOfPages
();
i
++)
{
// dpi调到300左右即可,太小会模糊,太大会使图片变得很大
BufferedImage
image
=
renderer
.
renderImageWithDPI
(
i
,
300
);
// 将 BufferedImage 转换为 ByteArrayOutputStream
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
image
,
"jpg"
,
outputStream
);
pictureUrl
+=
uploadMinio
(
outputStream
,
"车型审查原始记录_"
+
i
+
getReportName
()
+
".jpg"
)
+
","
;
}
// 关闭文档
doc
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
// 关闭连接
connection
.
disconnect
();
}
if
(
pictureUrl
.
endsWith
(
","
))
{
pictureUrl
=
pictureUrl
.
substring
(
0
,
pictureUrl
.
length
()
-
1
);
}
return
pictureUrl
;
}
/**
* 上传到minio
* @param outputStream 输出流
* @param fileName 文件名
* @return minio存储地址
*/
private
String
uploadMinio
(
ByteArrayOutputStream
outputStream
,
String
fileName
)
throws
Exception
{
// 1.连接Minio
MinioClient
minioClient
=
MinioClient
.
builder
()
.
endpoint
(
minioEndpoint
)
.
credentials
(
accessKey
,
secretKey
)
.
build
();
// 2.上传
// 把os流转为is流
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
outputStream
.
toByteArray
());
String
newFileName
=
assemblyPdfName
(
fileName
);
PutObjectArgs
putObjectArgs
=
PutObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
newFileName
)
.
contentType
(
"image/jpeg"
)
.
stream
(
inputStream
,
inputStream
.
available
(),
ObjectWriteArgs
.
MIN_MULTIPART_SIZE
).
build
();
minioClient
.
putObject
(
putObjectArgs
);
return
newFileName
;
}
/**
* 拼接文件名
* @param name
* @return
*/
public
String
assemblyPdfName
(
String
name
)
{
return
StringUtils
.
format
(
"{}/{}"
,
DateUtils
.
datePath
(),
name
);
}
private
String
getReportName
()
{
return
DateUtils
.
parseDateToStr
(
"yyyyMMddHHmm"
,
new
Date
());
}
private
void
carTestStatistics
(
DataStatisticsResponse
response
,
Task
task
)
{
if
(
task
.
getModelTestTaskId
()
!=
null
)
{
...
...
quality-review/src/main/java/com/ruoyi/web/TaskController.java
View file @
20424dcd
...
...
@@ -204,4 +204,10 @@ public class TaskController extends BaseController {
return
R
.
ok
(
taskService
.
createProject
(
request
));
}
@ApiOperation
(
"查询车辆原始记录图片"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/getPicture"
)
public
R
<
String
>
getPicture
(
@Validated
@RequestBody
TaskPictureRequest
request
)
throws
IOException
{
return
R
.
ok
(
taskService
.
getPicture
(
request
));
}
}
quality-review/src/main/java/com/ruoyi/web/request/TaskPictureRequest.java
0 → 100644
View file @
20424dcd
package
com
.
ruoyi
.
web
.
request
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@ApiModel
(
value
=
"TaskPictureRequest"
,
description
=
"查看车辆实验图片"
)
@Data
public
class
TaskPictureRequest
{
@ApiModelProperty
(
"任务id"
)
private
Long
taskId
;
@ApiModelProperty
(
"图片url"
)
private
String
url
;
}
quality-review/src/main/resources/mapper/TaskMapper.xml
View file @
20424dcd
...
...
@@ -37,6 +37,7 @@
<result
property=
"taskList"
column=
"task_list"
jdbcType=
"VARCHAR"
/>
<result
property=
"pointer"
column=
"pointer"
jdbcType=
"BIGINT"
/>
<result
property=
"maxPointer"
column=
"max_pointer"
jdbcType=
"BIGINT"
/>
<result
property=
"pictureUrl"
column=
"picture_url"
jdbcType=
"VARCHAR"
/>
</resultMap>
<resultMap
id=
"ResponseMap"
type=
"com.ruoyi.web.response.TaskFindResponse"
>
...
...
ruoyi-admin/pom.xml
View file @
20424dcd
...
...
@@ -66,6 +66,13 @@
<artifactId>
quality-review
</artifactId>
</dependency>
<!-- pdfbox -->
<dependency>
<groupId>
org.apache.pdfbox
</groupId>
<artifactId>
pdfbox
</artifactId>
<version>
2.0.0
</version>
</dependency>
</dependencies>
<build>
...
...
ruoyi-admin/src/test/java/com/ruoyi/TestPdfBox.java
0 → 100644
View file @
20424dcd
package
com
.
ruoyi
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
io.minio.MinioClient
;
import
io.minio.ObjectWriteArgs
;
import
io.minio.PutObjectArgs
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Date
;
@SpringBootTest
public
class
TestPdfBox
{
// @Value("${minio.bucketName}")
private
static
String
bucketName
=
"vehicle-quality-review-oss"
;
// @Value("${minio.url}")
private
static
String
minioEndpoint
=
"http://106.3.99.64:22013"
;
// @Value("${minio.accessKey}")
private
static
String
accessKey
=
"FNGqDZnHJhrugLlZBh77"
;
// @Value("${minio.secretKey}")
private
static
String
secretKey
=
"TvnWeQxAQ1OYiAN68qlzEDJl5RqZ7tQYTMJ8XM0M"
;
@Test
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
url
=
"http://106.3.99.64:22013/vehicle-quality-review-oss/2024/06/14/车型审查原始记录-202406141755.pdf"
;
String
pictureUrl
=
processRemotePDF
(
url
);
System
.
out
.
println
(
pictureUrl
);
}
public
static
String
processRemotePDF
(
String
urlStr
)
throws
IOException
{
URL
url
=
new
URL
(
urlStr
);
String
pictureUrl
=
""
;
// 打开远程连接
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"GET"
);
// 获取输入流
try
(
InputStream
inputStream
=
connection
.
getInputStream
())
{
// 加载PDF文档
PDDocument
doc
=
PDDocument
.
load
(
inputStream
);
PDFRenderer
renderer
=
new
PDFRenderer
(
doc
);
// 遍历每页pdf
for
(
int
i
=
0
;
i
<
doc
.
getNumberOfPages
();
i
++)
{
// dpi调到300左右即可,太小会模糊,太大会使图片变得很大
BufferedImage
image
=
renderer
.
renderImageWithDPI
(
i
,
300
);
// 将 BufferedImage 转换为 ByteArrayOutputStream
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
image
,
"jpg"
,
outputStream
);
pictureUrl
+=
uploadMinio
(
outputStream
,
"车型审查原始记录_"
+
i
+
getReportName
()
+
".jpg"
)
+
","
;
}
// 关闭文档
doc
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
// 关闭连接
connection
.
disconnect
();
}
if
(
pictureUrl
.
endsWith
(
","
))
{
pictureUrl
=
pictureUrl
.
substring
(
0
,
pictureUrl
.
length
()
-
1
);
}
return
pictureUrl
;
}
/**
* 上传到minio
* @param outputStream 输出流
* @param fileName 文件名
* @return minio存储地址
*/
private
static
String
uploadMinio
(
ByteArrayOutputStream
outputStream
,
String
fileName
)
throws
Exception
{
// 1.连接Minio
MinioClient
minioClient
=
MinioClient
.
builder
()
.
endpoint
(
minioEndpoint
)
.
credentials
(
accessKey
,
secretKey
)
.
build
();
// 2.上传
// 把os流转为is流
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
outputStream
.
toByteArray
());
String
newFileName
=
assemblyPdfName
(
fileName
);
PutObjectArgs
putObjectArgs
=
PutObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
newFileName
)
.
contentType
(
"image/jpeg"
)
.
stream
(
inputStream
,
inputStream
.
available
(),
ObjectWriteArgs
.
MIN_MULTIPART_SIZE
).
build
();
minioClient
.
putObject
(
putObjectArgs
);
return
newFileName
;
}
/**
* 拼接文件名
* @param name
* @return
*/
public
static
String
assemblyPdfName
(
String
name
)
{
return
StringUtils
.
format
(
"{}/{}"
,
DateUtils
.
datePath
(),
name
);
}
private
static
String
getReportName
()
{
return
DateUtils
.
parseDateToStr
(
"yyyyMMddHHmm"
,
new
Date
());
}
}
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