Commit d169d576 by landerliang@163.com

最终完成的测试版本:

可以自动化下载检测报告并且签章上传
parent c410f4fa
...@@ -85,6 +85,16 @@ public class ReportService { ...@@ -85,6 +85,16 @@ public class ReportService {
/** /**
* 根据检测报告编号删除检测报告
* @param reportNum
*/
public void deleteReportPdf(String reportNum){
int rows = reportPdfMapper.delete(new QueryWrapper<ReportPdfVo>().lambda().eq(ReportPdfVo::getReportNum, reportNum));
if(rows>0){
log.info(">> 检测报告号码为:{} 的pdf文件记录已删除",reportNum);
}
}
/**
* 获取上传文件显示页面 * 获取上传文件显示页面
* @param businessKey * @param businessKey
* @return * @return
...@@ -142,8 +152,10 @@ public class ReportService { ...@@ -142,8 +152,10 @@ public class ReportService {
reportPdfVo.setBusinessKey(testReportVo.getBusinessKey()); reportPdfVo.setBusinessKey(testReportVo.getBusinessKey());
reportPdfVo.setCreateTime(DateUtil.date()); reportPdfVo.setCreateTime(DateUtil.date());
reportPdfVo.setCarNum(testReportVo.getVLPN()); reportPdfVo.setCarNum(testReportVo.getVLPN());
//写入pdf下载记录
reportPdfMapper.insert(reportPdfVo); reportPdfMapper.insert(reportPdfVo);
//根据snKey查询签章信息 //根据snKey查询签章信息
SignatureVo signatureVo1 = signatureService.getBySnKeyAndSnName(snKey1,snName1); SignatureVo signatureVo1 = signatureService.getBySnKeyAndSnName(snKey1,snName1);
AssertUtil.isNotNull(signatureVo1,"找不到snKey为: " + snKey1 + "的签名章"); AssertUtil.isNotNull(signatureVo1,"找不到snKey为: " + snKey1 + "的签名章");
...@@ -172,13 +184,18 @@ public class ReportService { ...@@ -172,13 +184,18 @@ public class ReportService {
reportPdfMapper.updateById(reportPdfVos); reportPdfMapper.updateById(reportPdfVos);
//上传文件 (连同检测报告全部文件) //上传文件 (连同检测报告全部文件)
carReportUtil.autoUploadReportPost(account,password,reportPdfVo,signatureVo1.getDeptId()); Integer success = carReportUtil.autoUploadReportPost(account, password, reportPdfVo, signatureVo1.getDeptId());
//上传成功的文件小于2个则视为上传失败,清除下载记录
if(success < 2){
deleteReportPdf(reportPdfVos.getReportNum());
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
//记录错误信息
log.error(e.getLocalizedMessage());
TaskErrorVo taskErrorVo = new TaskErrorVo(); TaskErrorVo taskErrorVo = new TaskErrorVo();
taskErrorVo.setCreateTime(DateUtil.date()); taskErrorVo.setCreateTime(DateUtil.date());
taskErrorVo.setErrMsg(e.getCause().getMessage()==null?e.getMessage():e.getCause().getMessage()); taskErrorVo.setErrMsg(e.getCause().getMessage()==null?e.getMessage():e.getCause().getMessage());
......
...@@ -23,11 +23,12 @@ import me.zhengjie.modules.system.service.UploadRecordService; ...@@ -23,11 +23,12 @@ import me.zhengjie.modules.system.service.UploadRecordService;
import me.zhengjie.utils.AssertUtil; import me.zhengjie.utils.AssertUtil;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.openqa.selenium.*; import org.openqa.selenium.By;
import org.openqa.selenium.UnhandledAlertException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -148,9 +149,10 @@ public class CarReportUtil { ...@@ -148,9 +149,10 @@ public class CarReportUtil {
* @param password * @param password
* @param reportPdfVo * @param reportPdfVo
*/ */
public void autoUploadReportPost(String username, String password,ReportPdfVo reportPdfVo,Long deptid){ public Integer autoUploadReportPost(String username, String password,ReportPdfVo reportPdfVo,Long deptid){
//登录环保系统获取token //登录环保系统获取token
WebDriver driver = null; WebDriver driver = null;
int success = 0;
try { try {
//检测报告文件和其他至少四个文件(检测申请表、身份证、行驶证1、行驶证2)都有了才上传 //检测报告文件和其他至少四个文件(检测申请表、身份证、行驶证1、行驶证2)都有了才上传
...@@ -200,6 +202,7 @@ public class CarReportUtil { ...@@ -200,6 +202,7 @@ public class CarReportUtil {
} else { } else {
//上传状态 //上传状态
uploadRecordVo.setState(1); uploadRecordVo.setState(1);
success ++;
} }
uploadRecordService.saveRecord(uploadRecordVo); uploadRecordService.saveRecord(uploadRecordVo);
...@@ -226,6 +229,7 @@ public class CarReportUtil { ...@@ -226,6 +229,7 @@ public class CarReportUtil {
uploadRecord.setState(0); uploadRecord.setState(0);
} else { } else {
uploadRecord.setState(1); uploadRecord.setState(1);
success ++;
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
...@@ -250,6 +254,7 @@ public class CarReportUtil { ...@@ -250,6 +254,7 @@ public class CarReportUtil {
uploadRecord.setState(0); uploadRecord.setState(0);
} else { } else {
uploadRecord.setState(1); uploadRecord.setState(1);
success ++;
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
...@@ -273,6 +278,7 @@ public class CarReportUtil { ...@@ -273,6 +278,7 @@ public class CarReportUtil {
uploadRecord.setState(0); uploadRecord.setState(0);
} else { } else {
uploadRecord.setState(1); uploadRecord.setState(1);
success ++;
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
...@@ -296,6 +302,7 @@ public class CarReportUtil { ...@@ -296,6 +302,7 @@ public class CarReportUtil {
uploadRecord.setState(0); uploadRecord.setState(0);
} else { } else {
uploadRecord.setState(1); uploadRecord.setState(1);
success ++;
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
...@@ -322,6 +329,7 @@ public class CarReportUtil { ...@@ -322,6 +329,7 @@ public class CarReportUtil {
} else { } else {
uploadRecord.setState(1); uploadRecord.setState(1);
success ++;
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
} }
...@@ -341,6 +349,7 @@ public class CarReportUtil { ...@@ -341,6 +349,7 @@ public class CarReportUtil {
e.printStackTrace(); e.printStackTrace();
throw new BusinessException(e.getLocalizedMessage()); throw new BusinessException(e.getLocalizedMessage());
} }
return success;
} }
...@@ -649,7 +658,7 @@ public class CarReportUtil { ...@@ -649,7 +658,7 @@ public class CarReportUtil {
//如果车牌号不为空 //如果车牌号不为空
if(reportPageQueryVo.getIsZero() == 1){ if(reportPageQueryVo.getIsZero() == 1){
List<TestReportVo> collect = pageVo.getRows().stream().filter(i -> i.getPDFCount().equals("0")).collect(Collectors.toList()); List<TestReportVo> collect = pageVo.getRows().stream().filter(i -> Integer.valueOf(i.getPDFCount())==0).collect(Collectors.toList());
pageVo.setRows(collect); pageVo.setRows(collect);
pageVo.setTotal(collect.size()); pageVo.setTotal(collect.size());
testReportVoPage.setSize(reportPageQueryVo.getSize()); testReportVoPage.setSize(reportPageQueryVo.getSize());
...@@ -930,7 +939,7 @@ public class CarReportUtil { ...@@ -930,7 +939,7 @@ public class CarReportUtil {
//开始检索 按照检测时间倒叙 目前只检索最新的5条 //开始检索 按照检测时间倒叙 目前只检索最新的5条
QueryDataVo queryDataVo=new QueryDataVo(MyContext.INSPEC_TABLE, QueryDataVo queryDataVo=new QueryDataVo(MyContext.INSPEC_TABLE,
MyContext.PHOTO_TABLE_NAME,MyContext.ESIGN_NULL,fldsVo.getFld(),conditionVoList,null,5); MyContext.PHOTO_TABLE_NAME,MyContext.PHOTO_WHERE,fldsVo.getFld(),conditionVoList,null,5);
JSONObject body = JSONUtil.createObj(); JSONObject body = JSONUtil.createObj();
body.put("data",queryDataVo); body.put("data",queryDataVo);
body.put("rows",20); body.put("rows",20);
...@@ -952,7 +961,7 @@ public class CarReportUtil { ...@@ -952,7 +961,7 @@ public class CarReportUtil {
//将结果转vo对象 //将结果转vo对象
InspecPageVo pageVo = JSONUtil.toBean(queryResult, InspecPageVo.class); InspecPageVo pageVo = JSONUtil.toBean(queryResult, InspecPageVo.class);
List<TestReportVo> collect = pageVo.getRows().stream().filter(i -> i.getPDFCount().equals("0")).collect(Collectors.toList()); List<TestReportVo> collect = pageVo.getRows().stream().filter(i -> Integer.valueOf(i.getPDFCount())==0).collect(Collectors.toList());
pageVo.setRows(collect); pageVo.setRows(collect);
pageVo.setTotal(collect.size()); pageVo.setTotal(collect.size());
return pageVo.getRows(); return pageVo.getRows();
...@@ -994,9 +1003,10 @@ public class CarReportUtil { ...@@ -994,9 +1003,10 @@ public class CarReportUtil {
} }
AssertUtil.isNotBlank(stationCode,"获取不到当前用户的站点编码"); AssertUtil.isNotBlank(stationCode,"获取不到当前用户的站点编码");
List<TestReportVo> testReportVoIPage = topReportList(stationCode, cookies); List<TestReportVo> testReportVoIPage = topReportList(stationCode, cookies);
log.info(">> 扫描到的检测报告:");
testReportVoIPage.forEach(testReportVo -> { testReportVoIPage.forEach(testReportVo -> {
testReportVo.setSiteName(stationSpan.getText()); testReportVo.setSiteName(stationSpan.getText());
System.out.println(testReportVo.toString());
}); });
return testReportVoIPage; return testReportVoIPage;
......
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.auto.load.popular.drivers=false log4jdbc.auto.load.popular.drivers=false
log4jdbc.drivers=com.mysql.cj.jdbc.Driver log4jdbc.drivers=com.mysql.cj.jdbc.Driver
log4jdbc.appender.D.encoding=UTF-8
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="false"> <configuration scan="true" scanPeriod="30 seconds" debug="false">
<contextName>reptiles</contextName> <contextName>reptiles</contextName>
<property name="log.charset" value="utf-8" /> <property name="log.charset" value="UTF-8" />
<property name="log.pattern" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)" /> <property name="log.pattern" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)" />
<!--输出到控制台--> <!--输出到控制台-->
......
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