Commit 3097b14e by landerliang@163.com

修改检测报告PDF转换问题,已完美解决显示问题

parent 6db08f06
...@@ -7,9 +7,15 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -7,9 +7,15 @@ import org.springframework.web.multipart.MultipartFile;
@Data @Data
public class ReportFileUploadVo { public class ReportFileUploadVo {
@ApiModelProperty("检测报告") @ApiModelProperty("检测报告Id")
private Integer reportPdfId;
@ApiModelProperty("检测报告第一页")
private MultipartFile reportFile; private MultipartFile reportFile;
@ApiModelProperty("检测报告第二页")
private MultipartFile reportFile1;
@ApiModelProperty("行驶证1") @ApiModelProperty("行驶证1")
private MultipartFile drivingLicensePic1; private MultipartFile drivingLicensePic1;
...@@ -18,4 +24,7 @@ public class ReportFileUploadVo { ...@@ -18,4 +24,7 @@ public class ReportFileUploadVo {
@ApiModelProperty("身份证") @ApiModelProperty("身份证")
private MultipartFile idCardPic; private MultipartFile idCardPic;
@ApiModelProperty("维修凭证")
private MultipartFile certificatePic;
} }
...@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*; ...@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -38,12 +40,59 @@ public class ReportController { ...@@ -38,12 +40,59 @@ public class ReportController {
@ApiOperation("上传车检文件") @ApiOperation("上传车检文件")
@PostMapping(value = "/uploadReportFiles",produces = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/uploadReportFilesNotCertificate")
@ResponseBody
public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile, public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile,
@RequestParam(name = "reportFile1")MultipartFile reportFile1,
@RequestParam(name = "drivingLicensePic1")MultipartFile drivingLicensePic1, @RequestParam(name = "drivingLicensePic1")MultipartFile drivingLicensePic1,
@RequestParam(name = "drivingLicensePic2")MultipartFile drivingLicensePic2, @RequestParam(name = "drivingLicensePic2")MultipartFile drivingLicensePic2,
@RequestParam(name = "idCardPic")MultipartFile idCardPic, @RequestParam(name = "idCardPic")MultipartFile idCardPic,
@RequestParam(name = "applyTable")MultipartFile applyTable,
@RequestParam(name="reportPdfId")Integer reportPdfId){ @RequestParam(name="reportPdfId")Integer reportPdfId){
AssertUtil.isNotNull(reportPdfId,"缺少参数检测报告id");
AssertUtil.isNotNull(reportFile,"请上传检测报告第一页");
AssertUtil.isNotNull(reportFile1,"请上传检测报告第二页");
AssertUtil.isNotNull(drivingLicensePic1,"请上传行驶证1");
AssertUtil.isNotNull(drivingLicensePic2,"请上传行驶证2");
AssertUtil.isNotNull(idCardPic,"请上传身份证");
AssertUtil.isNotNull(applyTable,"请选择检测申请表");
ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
multipartFiles.add(reportFile);
multipartFiles.add(reportFile1);
multipartFiles.add(drivingLicensePic1);
multipartFiles.add(drivingLicensePic2);
multipartFiles.add(idCardPic);
multipartFiles.add(applyTable);
reportService.uploadReport(reportPdfId, multipartFiles);
return ResultVo.success();
}
@ApiOperation("上传车检文件")
@ResponseBody
@PostMapping(value = "/uploadReportFiles")
public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile,
@RequestParam(name = "reportFile1")MultipartFile reportFile1,
@RequestParam(name = "drivingLicensePic1")MultipartFile drivingLicensePic1,
@RequestParam(name = "drivingLicensePic2")MultipartFile drivingLicensePic2,
@RequestParam(name = "idCardPic")MultipartFile idCardPic,
@RequestParam(name = "certificatePic")MultipartFile certificatePic,
@RequestParam(name = "applyTable")MultipartFile applyTable,
@RequestParam(name="reportPdfId")Integer reportPdfId){
AssertUtil.isNotNull(reportPdfId,"缺少参数检测报告id");
AssertUtil.isNotNull(reportFile,"请上传检测报告第一页");
AssertUtil.isNotNull(reportFile1,"请上传检测报告第二页");
AssertUtil.isNotNull(drivingLicensePic1,"请上传行驶证1");
AssertUtil.isNotNull(drivingLicensePic2,"请上传行驶证2");
AssertUtil.isNotNull(idCardPic,"请上传身份证");
AssertUtil.isNotNull(applyTable,"请选择检测申请表");
ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
multipartFiles.add(reportFile);
multipartFiles.add(reportFile1);
multipartFiles.add(drivingLicensePic1);
multipartFiles.add(drivingLicensePic2);
multipartFiles.add(idCardPic);
multipartFiles.add(applyTable);
multipartFiles.add(certificatePic);
reportService.uploadReport(reportPdfId, multipartFiles);
return ResultVo.success(); return ResultVo.success();
} }
...@@ -64,9 +113,9 @@ public class ReportController { ...@@ -64,9 +113,9 @@ public class ReportController {
@ApiOperation("上传报告") @ApiOperation("上传报告")
@PostMapping("/upload") @PostMapping("/upload")
public ResultVo uploadReport(ReportUploadReqVo reqVo, @RequestParam(name = "files")MultipartFile[] files){ public ResultVo uploadReport(ReportUploadReqVo reqVo, @RequestParam(name = "files")List<MultipartFile> files){
AssertUtil.isNotNull(reqVo.getReportPdfId(),"缺少参数reportPdfId"); AssertUtil.isNotNull(reqVo.getReportPdfId(),"缺少参数reportPdfId");
AssertUtil.isTrue(files.length==4,"请按照提示选择文件上传"); AssertUtil.isTrue(files.size()==4,"请按照提示选择文件上传");
reportService.uploadReport(reqVo.getReportPdfId(),files); reportService.uploadReport(reqVo.getReportPdfId(),files);
return ResultVo.success(); return ResultVo.success();
} }
......
...@@ -107,7 +107,6 @@ public class ReportService { ...@@ -107,7 +107,6 @@ public class ReportService {
ReportDownloadRespVo reportDownloadRespVo = new ReportDownloadRespVo(); ReportDownloadRespVo reportDownloadRespVo = new ReportDownloadRespVo();
reportDownloadRespVo.setReportBase64(reportBase64); reportDownloadRespVo.setReportBase64(reportBase64);
reportDownloadRespVo.setReportNum(reportPdfVo.getReportNum()); reportDownloadRespVo.setReportNum(reportPdfVo.getReportNum());
System.out.println(reportBase64);
return reportDownloadRespVo; return reportDownloadRespVo;
} }
...@@ -126,7 +125,7 @@ public class ReportService { ...@@ -126,7 +125,7 @@ public class ReportService {
* @param reportPdfId * @param reportPdfId
* @param files * @param files
*/ */
public void uploadReport(Integer reportPdfId, MultipartFile [] files){ public void uploadReport(Integer reportPdfId, List<MultipartFile> files){
ReportPdfVo reportPdfVo = reportPdfMapper.selectById(reportPdfId); ReportPdfVo reportPdfVo = reportPdfMapper.selectById(reportPdfId);
AssertUtil.isNotNull(reportPdfVo,"不存在该检测报告,请刷新页面"); AssertUtil.isNotNull(reportPdfVo,"不存在该检测报告,请刷新页面");
DeptVo currUserDept = getCurrUserDept(); DeptVo currUserDept = getCurrUserDept();
...@@ -136,11 +135,14 @@ public class ReportService { ...@@ -136,11 +135,14 @@ public class ReportService {
int i =0; int i =0;
for (MultipartFile file : files) { for (MultipartFile file : files) {
String reportPath = carReportUtil.getReportPath(reportPdfVo.getReportNum() + "_" + i , ".jpg"); String reportPath = carReportUtil.getReportPath(reportPdfVo.getReportNum() + "_" + i , ".jpg");
if(FileUtil.exist(reportPath)){
FileUtil.del(reportPath);
}
FileUtil.writeBytes(file.getBytes(),reportPath); FileUtil.writeBytes(file.getBytes(),reportPath);
filePath.add(reportPath); filePath.add(reportPath);
i++; i++;
} }
carReportUtil.uploadReport(currUserDept.getEpAccount(),reportPdfVo.getPath(),reportPdfVo,currUserDept.getEpPassword(),filePath); carReportUtil.uploadReport(currUserDept.getEpAccount(),currUserDept.getEpPassword(),reportPdfVo,filePath);
} catch (Exception e) { } catch (Exception e) {
throw new BusinessException(e.getMessage()); throw new BusinessException(e.getMessage());
} finally { } finally {
...@@ -216,12 +218,14 @@ public class ReportService { ...@@ -216,12 +218,14 @@ public class ReportService {
//如果已经下载保存过PDF了则删除旧的pdf 再去抓取新的pdf //如果已经下载保存过PDF了则删除旧的pdf 再去抓取新的pdf
if(reportPdfVo != null && StrUtil.isNotBlank(reportPdfVo.getPath())){ if(reportPdfVo != null && StrUtil.isNotBlank(reportPdfVo.getPath())){
FileUtil.del(reportPdfVo.getPath()); FileUtil.del(reportPdfVo.getPath());
reportPdfVo.setPath("");
reportPdfVo.setReportName("");
} }
//测试用 //测试用
if(reportPdfVo != null && StrUtil.isNotBlank(reportPdfVo.getPath())){ /*if(reportPdfVo != null && StrUtil.isNotBlank(reportPdfVo.getPath())){
return reportPdfVo; return reportPdfVo;
} }*/
//获取当前用户的部门 //获取当前用户的部门
DeptVo deptVo = getCurrUserDept(); DeptVo deptVo = getCurrUserDept();
...@@ -237,6 +241,7 @@ public class ReportService { ...@@ -237,6 +241,7 @@ public class ReportService {
if(StrUtil.isNotBlank(reportPath)){ if(StrUtil.isNotBlank(reportPath)){
String name = FileUtil.file(reportPath).getName(); String name = FileUtil.file(reportPath).getName();
//保存下载的PDF报告信息 //保存下载的PDF报告信息
if(reportPdfVo == null){
reportPdfVo = new ReportPdfVo(); reportPdfVo = new ReportPdfVo();
reportPdfVo.setCarNum(detailsReqVo.getCarNum()); reportPdfVo.setCarNum(detailsReqVo.getCarNum());
reportPdfVo.setPath(reportPath); reportPdfVo.setPath(reportPath);
...@@ -244,6 +249,15 @@ public class ReportService { ...@@ -244,6 +249,15 @@ public class ReportService {
reportPdfVo.setCreateTime(DateUtil.date()); reportPdfVo.setCreateTime(DateUtil.date());
reportPdfVo.setReportName(name); reportPdfVo.setReportName(name);
reportPdfMapper.insert(reportPdfVo); reportPdfMapper.insert(reportPdfVo);
} else {
reportPdfVo.setCarNum(detailsReqVo.getCarNum());
reportPdfVo.setPath(reportPath);
reportPdfVo.setReportNum(detailsReqVo.getReportNum());
reportPdfVo.setCreateTime(DateUtil.date());
reportPdfVo.setReportName(name);
reportPdfMapper.updateById(reportPdfVo);
}
return reportPdfVo; return reportPdfVo;
} }
} }
......
...@@ -61,7 +61,7 @@ public class CarReportUtil { ...@@ -61,7 +61,7 @@ public class CarReportUtil {
* @param reportPath 要上传的检测报告路径 * @param reportPath 要上传的检测报告路径
* @param paths 其他文件的路径 * @param paths 其他文件的路径
*/ */
public void uploadReport(String username, String password,ReportPdfVo reportPdfVo, String reportPath, List<String> paths) throws InterruptedException { public void uploadReport(String username, String password,ReportPdfVo reportPdfVo, List<String> paths) throws InterruptedException {
WebDriver driver = null; WebDriver driver = null;
...@@ -165,38 +165,73 @@ public class CarReportUtil { ...@@ -165,38 +165,73 @@ public class CarReportUtil {
//上传方式选择本地上传 //上传方式选择本地上传
frameDriver.findElement(new By.ByXPath("//*[@id=\"form1\"]/div/div/table[3]/tbody/tr/td[2]/label[2]")).click(); frameDriver.findElement(new By.ByXPath("//*[@id=\"form1\"]/div/div/table[3]/tbody/tr/td[2]/label[2]")).click();
//行驶证1 //将file元素改为可见
WebElement pic1 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_3\"]/tbody/tr[1]/td/label")); JavascriptExecutor javascriptExecutor = (JavascriptExecutor) frameDriver;
javascriptExecutor.executeScript("document.getElementById('uploadify4').style.display='block';");
//检测测报告第一页
WebElement pic1 = frameDriver.findElement(new By.ById("uploadify4"));
pic1.sendKeys(paths.get(0)); pic1.sendKeys(paths.get(0));
//驶证2 //检测报告第二页
WebElement pic2 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_33\"]/tbody/tr[1]/td/label")); WebElement pic2 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_85\"]/tbody/tr[1]/td/label"));
pic2.sendKeys(paths.get(1)); pic2.sendKeys(paths.get(1));
//身份证 //行驶证1
WebElement pic3 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_39\"]/tbody/tr[1]/td/label")); WebElement pic3 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_3\"]/tbody/tr[1]/td/label"));
pic3.sendKeys(paths.get(2)); pic3.sendKeys(paths.get(2));
//检测申请表 //驶证2
WebElement pic4 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_40\"]/tbody/tr[1]/td/label")); WebElement pic4 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_33\"]/tbody/tr[1]/td/label"));
pic4.sendKeys(paths.get(3)); pic4.sendKeys(paths.get(3));
//取消勾选检测报告第二页 (生成的PDF就算有两页但是还是一个pdf文件) //身份证
frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_85\"]/tbody/tr[1]/td/label")).click(); WebElement pic5 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_39\"]/tbody/tr[1]/td/label"));
pic5.sendKeys(paths.get(4));
//检测申请表
WebElement pic6 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_40\"]/tbody/tr[1]/td/label"));
pic6.sendKeys(paths.get(5));
if(paths.size()>6){
//维修凭证
WebElement pic7 = frameDriver.findElement(new By.ByXPath("//*[@id=\"chb_14\"]/tbody/tr[1]/td/label"));
pic7.sendKeys(paths.get(6));
}
//将file元素改为可见
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) frameDriver;
javascriptExecutor.executeScript("document.getElementById('uploadify4').style.display='block';");
//上传检测报告
WebElement uploadTestReportBtn = frameDriver.findElement(new By.ById("uploadify4"));
uploadTestReportBtn.sendKeys(reportPath);
//点击上传已勾选的文件 //点击上传已勾选的文件
frameDriver.findElement(new By.ById("Button3")).click(); frameDriver.findElement(new By.ById("Button3")).click();
//校验是否上传成功
//延迟加载html
frameDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)
.setScriptTimeout(60,TimeUnit.SECONDS).pageLoadTimeout(60,TimeUnit.SECONDS);
//给线程睡眠4s
Thread.sleep(2000);
WebElement divContent = frameDriver.findElement(new By.ById("divContent"));
//如果全部成功
if(divContent.getText().contains("red")){
frameDriver.close(); frameDriver.close();
driver.close(); driver.close();
log.info(">> ======== 资料已上传完成 =========== <<"); log.info(">> ======== 资料已上传完成 =========== <<");
} else {
List<WebElement> elements = divContent.findElements(new By.ByXPath("//*[@id=\"divContent\"]/span[contains(@style,\"color: red;\")]"));
String errMsgList = "";
for(WebElement elem: elements){
errMsgList += elem.getText() +"\n";
}
frameDriver.close();
driver.close();
throw new BusinessException(errMsgList);
}
} }
...@@ -321,7 +356,7 @@ public class CarReportUtil { ...@@ -321,7 +356,7 @@ public class CarReportUtil {
if(browserVersion == null){ if(browserVersion == null){
driver = new HtmlUnitDriver(true); driver = new HtmlUnitDriver(true);
}else { }else {
new HtmlUnitDriver(browserVersion,true); driver = new HtmlUnitDriver(browserVersion,true);
} }
//进入登陆页 //进入登陆页
...@@ -367,9 +402,9 @@ public class CarReportUtil { ...@@ -367,9 +402,9 @@ public class CarReportUtil {
String fileName = detailsReqVo.getReportNum(); String fileName = detailsReqVo.getReportNum();
//如果已经下载有检测报告则直接return //如果已经下载有检测报告则直接return
String reportHtmlPath = getReportPath(fileName,".html"); String reportHtmlPath = getReportPath(fileName,".html");
if(FileUtil.isNotEmpty(FileUtil.file(fileName))){ /*if(FileUtil.isNotEmpty(FileUtil.file(fileName))){
return getReportPath(fileName,".pdf"); return getReportPath(fileName,".pdf");
} }*/
//登录环保 //登录环保
driver = loginEp(username, password,null); driver = loginEp(username, password,null);
...@@ -429,9 +464,14 @@ public class CarReportUtil { ...@@ -429,9 +464,14 @@ public class CarReportUtil {
WebElement reportFrame = frameDriver.findElement(new By.ById("iframe_divReport")); WebElement reportFrame = frameDriver.findElement(new By.ById("iframe_divReport"));
//切换到检测报告frame //切换到检测报告frame
WebDriver reportDriver = frameDriver.switchTo().frame(reportFrame); WebDriver reportDriver = frameDriver.switchTo().frame(reportFrame);
//抓取打印预览按钮进行点击
WebElement printView = reportDriver.findElement(new By.ById("A1"));
printView.click();
reportDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS) reportDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)
.setScriptTimeout(60, TimeUnit.SECONDS).pageLoadTimeout(120, TimeUnit.SECONDS); .setScriptTimeout(60, TimeUnit.SECONDS).pageLoadTimeout(120, TimeUnit.SECONDS);
//替换掉css样式的链接以及去掉多余的元素 //替换掉css样式的链接以及去掉多余的元素
Document parse = Jsoup.parse(reportDriver.getPageSource()); Document parse = Jsoup.parse(reportDriver.getPageSource());
parse.select("a").remove(); parse.select("a").remove();
...@@ -440,7 +480,12 @@ public class CarReportUtil { ...@@ -440,7 +480,12 @@ public class CarReportUtil {
.replace("黑体","SimSun").replace("<br> \n" + .replace("黑体","SimSun").replace("<br> \n" +
" <br>","<br style=\"page-break-after:always;\"> \n" + " <br>","<br style=\"page-break-after:always;\"> \n" +
" <br style=\"page-break-after:always;\">") " <br style=\"page-break-after:always;\">")
.replace("<div>","<div style=\"margin-left:-500px\">"); .replace("<br> \n" +
" <font color=\"#FF00FF\"> 打印控件未安装!点击这里 ,安装后请刷新页面或重新进入。 </font> \n" +
" <br> \n" +
" <br> \n" +
" <font color=\"#FF00FF\"> (如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装) </font>", " ")
.replace("<div>","<div style=\"margin-left:-460px\">");
Document parse1 = Jsoup.parse(reportHtml); Document parse1 = Jsoup.parse(reportHtml);
...@@ -472,10 +517,10 @@ public class CarReportUtil { ...@@ -472,10 +517,10 @@ public class CarReportUtil {
} catch (InterruptedException e) { } catch (InterruptedException e) {
driver.close(); driver.close();
log.error(e.getMessage()); log.error(e.getMessage());
throw new BusinessException("服务器繁忙请重试");
} }
return null;
} }
......
...@@ -47,7 +47,7 @@ public class PdfUtil { ...@@ -47,7 +47,7 @@ public class PdfUtil {
cmd.append(" "); cmd.append(" ");
cmd.append("-s A4"); cmd.append("-s A4");
cmd.append(" "); cmd.append(" ");
cmd.append("--zoom 2 -B 3cm -T 1.65cm -L 0 -R 0"); cmd.append("--disable-smart-shrinking -B 0 -T 0 -L 0 -R 0");
cmd.append(" \""); cmd.append(" \"");
cmd.append(srcPath); cmd.append(srcPath);
cmd.append("\" "); cmd.append("\" ");
......
...@@ -4,12 +4,12 @@ spring: ...@@ -4,12 +4,12 @@ spring:
druid: druid:
db-type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://${DB_HOST:47.107.148.253}:${DB_PORT:3306}/${DB_NAME:car-reptiles}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false # url: jdbc:log4jdbc:mysql://${DB_HOST:47.107.148.253}:${DB_PORT:3306}/${DB_NAME:car-reptiles}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: ${DB_USER:root}
password: ${DB_PWD:Dk2019!23456}
# url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:car-reptiles}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# username: ${DB_USER:root} # username: ${DB_USER:root}
# password: ${DB_PWD:} # password: ${DB_PWD:Dk2019!23456}
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:car-reptiles}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: ${DB_USER:root}
password: ${DB_PWD:111111}
# 初始连接数 # 初始连接数
initial-size: 5 initial-size: 5
# 最小连接数 # 最小连接数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment