Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-reptiles
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
梁辉
car-reptiles
Commits
44454d4e
Commit
44454d4e
authored
Jan 13, 2021
by
landerliang@163.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动签章上传,先判断当前车牌号下是否不为空,为空则不进行报告下载,节省资源
parent
010404dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
111 deletions
+127
-111
car-reptiles-system/src/main/java/me/zhengjie/modules/system/service/ReportService.java
+3
-3
car-reptiles-system/src/main/java/me/zhengjie/modules/system/util/CarReportUtil.java
+114
-108
car-reptiles-system/src/test/java/me/zhengjie/LoginCacheTest.java
+10
-0
No files found.
car-reptiles-system/src/main/java/me/zhengjie/modules/system/service/ReportService.java
View file @
44454d4e
...
...
@@ -137,13 +137,14 @@ public class ReportService {
reportDetailsReqVo
.
setCarNum
(
testReportVo
.
getVLPN
());
reportDetailsReqVo
.
setReportNum
(
testReportVo
.
getInspectionNum
());
//下载报告pdf 并写入数据库
reportPdfVo
=
new
ReportPdfVo
();
//下载报告pdf
String
path
=
carReportUtil
.
authDownloadReport
(
account
,
password
,
reportDetailsReqVo
);
//如果下载成功
if
(
StrUtil
.
isNotBlank
(
path
)){
// 写入数据库
reportPdfVo
=
new
ReportPdfVo
();
reportPdfVo
.
setPath
(
path
);
reportPdfVo
.
setVehicleId
(
testReportVo
.
getVehicleID
());
reportPdfVo
.
setUniqueString
(
testReportVo
.
getUniqueString
());
...
...
@@ -337,7 +338,6 @@ public class ReportService {
AssertUtil
.
isNotNull
(
deptVo
,
"列表获取失败,未找到当前账号所属部门"
);
String
reportPath
=
""
;
try
{
//下载检测报告
reportPath
=
carReportUtil
.
downloadReport
(
deptVo
.
getEpAccount
(),
deptVo
.
getEpPassword
(),
detailsReqVo
);
}
catch
(
Exception
e
)
{
...
...
car-reptiles-system/src/main/java/me/zhengjie/modules/system/util/CarReportUtil.java
View file @
44454d4e
...
...
@@ -766,146 +766,152 @@ public class CarReportUtil {
WebDriver
driver
=
null
;
try
{
//把检测报告编号作为该报告文件的文件名
String
fileName
=
detailsReqVo
.
getReportNum
();
//如果已经下载有检测报告则直接return
String
reportHtmlPath
=
getReportPath
(
fileName
,
".html"
);
//判断是否已拍照有文件再进行下载
if
(!
FileUtil
.
isDirEmpty
(
FileUtil
.
file
(
uploadFilePath
+
detailsReqVo
.
getCarNum
()))){
//把检测报告编号作为该报告文件的文件名
String
fileName
=
detailsReqVo
.
getReportNum
();
//如果已经下载有检测报告则直接return
String
reportHtmlPath
=
getReportPath
(
fileName
,
".html"
);
/*if(FileUtil.isNotEmpty(FileUtil.file(fileName))){
return getReportPath(fileName,".pdf");
}*/
//登录环保
driver
=
loginEp
(
username
,
password
,
BrowserVersion
.
INTERNET_EXPLORER
);
//登录环保
driver
=
loginEp
(
username
,
password
,
BrowserVersion
.
INTERNET_EXPLORER
);
Thread
.
sleep
(
1000
);
Thread
.
sleep
(
1000
);
//抓取检测报告超链接
WebElement
inspecReportBtn
=
driver
.
findElement
(
new
By
.
ById
(
"mainMenuTree_3_a"
));
inspecReportBtn
.
click
();
//抓取检测报告超链接
WebElement
inspecReportBtn
=
driver
.
findElement
(
new
By
.
ById
(
"mainMenuTree_3_a"
));
inspecReportBtn
.
click
();
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
3000
);
Thread
.
sleep
(
3000
);
//点击完检测报告的超链接后,抓取frame窗口的元素
WebElement
homeFrame
=
driver
.
findElement
(
new
By
.
ByXPath
(
"//*[@id=\"tabs\"]/div[2]/div[2]/div/iframe"
));
//切换到iframe页面
driver
=
driver
.
switchTo
().
frame
(
homeFrame
);
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
//点击完检测报告的超链接后,抓取frame窗口的元素
WebElement
homeFrame
=
driver
.
findElement
(
new
By
.
ByXPath
(
"//*[@id=\"tabs\"]/div[2]/div[2]/div/iframe"
));
//切换到iframe页面
driver
=
driver
.
switchTo
().
frame
(
homeFrame
);
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
2000
);
Thread
.
sleep
(
2000
);
WebElement
element
=
driver
.
findElement
(
new
By
.
ByXPath
(
"//*[@id=\"table_Condition\"]/tbody/tr[2]/td[3]/input"
));
element
.
click
();
WebElement
element
=
driver
.
findElement
(
new
By
.
ByXPath
(
"//*[@id=\"table_Condition\"]/tbody/tr[2]/td[3]/input"
));
element
.
click
();
//获取车牌号输入框
WebElement
carNumInput
=
driver
.
findElement
(
new
By
.
ByXPath
(
"//*[@id=\"conWindow\"]/div[1]/div/table/tbody/tr[1]/td[2]/input"
));
carNumInput
.
sendKeys
(
detailsReqVo
.
getCarNum
());
//获取车牌号输入框
WebElement
carNumInput
=
driver
.
findElement
(
new
By
.
ByXPath
(
"//*[@id=\"conWindow\"]/div[1]/div/table/tbody/tr[1]/td[2]/input"
));
carNumInput
.
sendKeys
(
detailsReqVo
.
getCarNum
());
//点击检索按钮
driver
.
findElement
(
new
By
.
ById
(
"btnVin"
)).
click
();
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
//点击检索按钮
driver
.
findElement
(
new
By
.
ById
(
"btnVin"
)).
click
();
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
2000
);
Thread
.
sleep
(
2000
);
//抓取检索后的列表
List
<
WebElement
>
trElements
=
driver
.
findElements
(
new
By
.
ByXPath
(
"//*[contains(@id,'datagrid-row-')]"
));
AssertUtil
.
isTrue
(
trElements
.
size
()>
0
,
"获取该检测报告失败!"
);
//拿出对应的那条记录(根据检测编码)
WebElement
trElement
=
null
;
for
(
WebElement
tr:
trElements
){
if
(
tr
.
getText
().
contains
(
detailsReqVo
.
getCarNum
())){
trElement
=
tr
;
//抓取检索后的列表
List
<
WebElement
>
trElements
=
driver
.
findElements
(
new
By
.
ByXPath
(
"//*[contains(@id,'datagrid-row-')]"
));
AssertUtil
.
isTrue
(
trElements
.
size
()>
0
,
"获取该检测报告失败!"
);
//拿出对应的那条记录(根据检测编码)
WebElement
trElement
=
null
;
for
(
WebElement
tr:
trElements
){
if
(
tr
.
getText
().
contains
(
detailsReqVo
.
getCarNum
())){
trElement
=
tr
;
}
}
}
//点击检索出来的列表
trElement
.
click
();
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
3000
);
//抓取检测报告frame
WebElement
reportFrame
=
driver
.
findElement
(
new
By
.
ById
(
"iframe_divReport"
));
//切换到检测报告frame
driver
=
driver
.
switchTo
().
frame
(
reportFrame
);
Thread
.
sleep
(
2000
);
//点击检索出来的列表
trElement
.
click
();
//延迟加载html
driver
.
manage
().
timeouts
().
implicitlyWait
(
60
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
60
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
3000
);
//抓取检测报告frame
WebElement
reportFrame
=
driver
.
findElement
(
new
By
.
ById
(
"iframe_divReport"
));
//切换到检测报告frame
driver
=
driver
.
switchTo
().
frame
(
reportFrame
);
Thread
.
sleep
(
2000
);
//抓取打印预览按钮进行点击
//WebElement printView = reportDriver.findElement(new By.ById("A1"));
WebElement
printView
=
driver
.
findElement
(
new
By
.
ById
(
"btnPlaySelectAll"
));
printView
.
click
();
driver
.
manage
().
timeouts
().
implicitlyWait
(
20
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
20
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
boolean
isError
=
driver
.
getPageSource
().
contains
(
"无检测方法结果数据不允许打印操作"
);
AssertUtil
.
isNotTrue
(
isError
,
"无检测方法结果数据不允许打印操作"
);
Thread
.
sleep
(
3000
);
//手动在授权人签字栏加上当天日期
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy.MM.dd"
);
String
todayStr
=
simpleDateFormat
.
format
(
DateUtil
.
date
());
//替换掉css样式的链接以及去掉多余的元素
Document
parse
=
Jsoup
.
parse
(
driver
.
getPageSource
());
parse
.
select
(
"a"
).
remove
();
String
reportHtml
=
parse
.
html
();
reportHtml
=
reportHtml
.
replace
(
"src=\"../.."
,
"src=\""
+
host
).
replace
(
"src=\"/businesscom"
,
"src=\""
+
host
+
"businesscom"
)
.
replace
(
"黑体"
,
"SimSun"
).
replace
(
"<br> \n"
+
" <br>"
,
"<br style=\"page-break-after:always;\"> \n"
+
" <br style=\"page-break-after:always;\">"
)
.
replace
(
"<br> \n"
+
" <font color=\"#FF00FF\"> 打印控件未安装!点击这里 ,安装后请刷新页面或重新进入。 </font> \n"
+
" <br> \n"
+
" <br> \n"
+
" <font color=\"#FF00FF\"> (如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装) </font>"
,
" "
)
.
replace
(
"<div>"
,
"<div style=\"margin-left:-460px\">"
)
.
replace
(
"<td style=\"width:13.25%;\"> 授权签字人 </td> \n"
+
" <td colspan=\"4\" style=\"width:30%;border-left:none;border-right:none;\"></td>"
,
"<td style=\"width:13.25%;\"> 授权签字人 </td> \n"
+
" <td colspan=\"4\" style=\"width:30%;border-left:none;border-right:none;padding-left:100px\">"
+
todayStr
+
"</td>"
);
Document
parse1
=
Jsoup
.
parse
(
reportHtml
);
String
imgSrc
=
parse1
.
getElementById
(
"qrImg"
).
attr
(
"src"
);
Object
[]
cookies
=
driver
.
manage
().
getCookies
().
toArray
();
byte
[]
respBytes
=
HttpUtil
.
createGet
(
imgSrc
).
header
(
"Cookie"
,
cookies
[
0
].
toString
()
+
";"
+
cookies
[
1
].
toString
()
+
";"
+
cookies
[
2
].
toString
()).
execute
().
bodyBytes
();
FileUtil
.
writeBytes
(
respBytes
,
getReportPath
(
fileName
,
".png"
));
//抓取打印预览按钮进行点击
//WebElement printView = reportDriver.findElement(new By.ById("A1"));
WebElement
printView
=
driver
.
findElement
(
new
By
.
ById
(
"btnPlaySelectAll"
));
printView
.
click
();
driver
.
manage
().
timeouts
().
implicitlyWait
(
20
,
TimeUnit
.
SECONDS
)
.
setScriptTimeout
(
20
,
TimeUnit
.
SECONDS
).
pageLoadTimeout
(
120
,
TimeUnit
.
SECONDS
);
boolean
isError
=
driver
.
getPageSource
().
contains
(
"无检测方法结果数据不允许打印操作"
);
AssertUtil
.
isNotTrue
(
isError
,
"无检测方法结果数据不允许打印操作"
);
Thread
.
sleep
(
3000
);
//手动在授权人签字栏加上当天日期
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy.MM.dd"
);
String
todayStr
=
simpleDateFormat
.
format
(
DateUtil
.
date
()
);
//将二维码转换成base64流 踩坑: 不转base64的话,转PDF后,图片显示不出来
BASE64Encoder
encoder
=
new
BASE64Encoder
(
);
String
base64Qrcode
=
encoder
.
encode
(
respBytes
);
//将base64流的二维码加到页面上
//替换掉css样式的链接以及去掉多余的元素
Document
parse
=
Jsoup
.
parse
(
driver
.
getPageSource
());
parse
.
select
(
"a"
).
remove
();
String
reportHtml
=
parse
.
html
();
reportHtml
=
reportHtml
.
replace
(
"src=\"../.."
,
"src=\""
+
host
).
replace
(
"src=\"/businesscom"
,
"src=\""
+
host
+
"businesscom"
)
.
replace
(
"黑体"
,
"SimSun"
).
replace
(
"<br> \n"
+
" <br>"
,
"<br style=\"page-break-after:always;\"> \n"
+
" <br style=\"page-break-after:always;\">"
)
.
replace
(
"<br> \n"
+
" <font color=\"#FF00FF\"> 打印控件未安装!点击这里 ,安装后请刷新页面或重新进入。 </font> \n"
+
" <br> \n"
+
" <br> \n"
+
" <font color=\"#FF00FF\"> (如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装) </font>"
,
" "
)
.
replace
(
"<div>"
,
"<div style=\"margin-left:-460px\">"
)
.
replace
(
"<td style=\"width:13.25%;\"> 授权签字人 </td> \n"
+
" <td colspan=\"4\" style=\"width:30%;border-left:none;border-right:none;\"></td>"
,
"<td style=\"width:13.25%;\"> 授权签字人 </td> \n"
+
" <td colspan=\"4\" style=\"width:30%;border-left:none;border-right:none;padding-left:100px\">"
+
todayStr
+
"</td>"
);
Document
parse1
=
Jsoup
.
parse
(
reportHtml
);
String
imgSrc
=
parse1
.
getElementById
(
"qrImg"
).
attr
(
"src"
);
Object
[]
cookies
=
driver
.
manage
().
getCookies
().
toArray
();
byte
[]
respBytes
=
HttpUtil
.
createGet
(
imgSrc
).
header
(
"Cookie"
,
cookies
[
0
].
toString
()
+
";"
+
cookies
[
1
].
toString
()
+
";"
+
cookies
[
2
].
toString
()).
execute
().
bodyBytes
();
FileUtil
.
writeBytes
(
respBytes
,
getReportPath
(
fileName
,
".png"
));
//将二维码转换成base64流 踩坑: 不转base64的话,转PDF后,图片显示不出来
BASE64Encoder
encoder
=
new
BASE64Encoder
();
String
base64Qrcode
=
encoder
.
encode
(
respBytes
);
parse1
.
getElementById
(
"qrImg"
).
attr
(
"src"
,
"data:image/png;base64,"
+
base64Qrcode
);
//将base64流的二维码加到页面上
FileUtil
.
writeBytes
(
parse1
.
html
().
getBytes
(
"UTF-8"
),
reportHtmlPath
);
parse1
.
getElementById
(
"qrImg"
).
attr
(
"src"
,
"data:image/png;base64,"
+
base64Qrcode
);
FileUtil
.
writeBytes
(
parse1
.
html
().
getBytes
(
"UTF-8"
),
reportHtmlPath
);
//将保存到本地的html转成pdf
PdfUtil
.
convert
(
reportHtmlPath
,
getReportPath
(
fileName
,
".pdf"
));
//离开当前检测报告页返回列表页面
//driver.switchTo().parentFrame();
//将保存到本地的html转成pdf
PdfUtil
.
convert
(
reportHtmlPath
,
getReportPath
(
fileName
,
".pdf"
));
log
.
info
(
">> 检测报告下载完成!"
);
//离开当前检测报告页返回列表页面
//driver.switchTo().parentFrame();
if
(
driver
!=
null
){
driver
.
quit
();
}
log
.
info
(
">> 检测报告下载完成!
"
);
return
getReportPath
(
fileName
,
".pdf
"
);
if
(
driver
!=
null
){
driver
.
quit
();
}
return
getReportPath
(
fileName
,
".pdf"
);
}
catch
(
InterruptedException
|
UnsupportedEncodingException
|
UnhandledAlertException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -1115,7 +1121,7 @@ public class CarReportUtil {
/**
* 获取最新
五
条没上传文件的检测报告
* 获取最新
十
条没上传文件的检测报告
* @param stationCode
* @param cookies
* @return
...
...
@@ -1140,7 +1146,7 @@ public class CarReportUtil {
MyContext
.
PHOTO_TABLE_NAME
,
MyContext
.
PHOTO_WHERE
,
fldsVo
.
getFld
(),
conditionVoList
,
null
,
5
);
JSONObject
body
=
JSONUtil
.
createObj
();
body
.
put
(
"data"
,
queryDataVo
);
body
.
put
(
"rows"
,
5
);
body
.
put
(
"rows"
,
10
);
body
.
put
(
"page"
,
1
);
body
.
put
(
"sort"
,
"DetectEndTime"
);
body
.
put
(
"order"
,
"DESC"
);
...
...
car-reptiles-system/src/test/java/me/zhengjie/LoginCacheTest.java
View file @
44454d4e
...
...
@@ -18,6 +18,16 @@ public class LoginCacheTest {
@Resource
(
name
=
"userDetailsService"
)
private
UserDetailsServiceImpl
userDetailsService
;
@Test
public
void
testIsDirEmptry
(){
String
dirPath
=
"C:\\Users\\Lander.LAPTOP-6VMQUJS1\\Desktop\\pdf"
;
boolean
dirEmpty
=
FileUtil
.
isDirEmpty
(
FileUtil
.
file
(
dirPath
));
System
.
out
.
println
(
"当前文件夹是否为空:"
+
dirEmpty
);
if
(!
dirEmpty
){
System
.
out
.
println
(
"不为空"
);
}
}
@Test
public
void
testCreateFileDirect
(){
...
...
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