Commit c410f4fa by landerliang@163.com

修复自动扫描不到未上传的检测报告问题,以及给自动签章上传的方法加上异步注解,修改了上传其他文件的后缀

parent ce3fa1f0
...@@ -23,26 +23,26 @@ public class MyConstants { ...@@ -23,26 +23,26 @@ public class MyConstants {
/** /**
* 身份证文件名后缀 * 身份证文件名后缀
*/ */
public static final String IDCARD_SUFFIX = "_1.jpg"; public static final String IDCARD_SUFFIX = "_sfz.jpg";
/** /**
* 申请表文件后缀 * 检测申请表文件后缀
*/ */
public static final String APPLY_SUFFIX = "_2.jpg"; public static final String APPLY_SUFFIX = "_jcsqb.jpg";
/** /**
* 维修凭证文件后缀 * 维修凭证文件后缀
*/ */
public static final String CERTIFICATE_SUFFIX = "_3.jpg"; public static final String CERTIFICATE_SUFFIX = "_wxpz.jpg";
/** /**
* 行驶证1文件后缀 * 行驶证1文件后缀
*/ */
public static final String DRIVER_SUFFIX1 = "_4.jpg"; public static final String DRIVER_SUFFIX1 = "_xsz1.jpg";
/** /**
* 行驶证2文件后缀 * 行驶证2文件后缀
*/ */
public static final String DRIVER_SUFFIX2 = "_5.jpg"; public static final String DRIVER_SUFFIX2 = "_xsz2.jpg";
} }
...@@ -3,10 +3,15 @@ package me.zhengjie.modules.system.domain.vo.report; ...@@ -3,10 +3,15 @@ package me.zhengjie.modules.system.domain.vo.report;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
/**
* @author Lander
*/
@Data @Data
public class ReportUploadReqVo { public class ReportUploadReqVo {
@ApiModelProperty("检测报告pdf自增ID") @ApiModelProperty("检测报告pdf自增ID")
private Integer reportPdfId; private Integer reportPdfId;
@ApiModelProperty("是否上传换检测报告 0-仅上传其他文件 1-连同检测报告一起上传")
private Integer type;
} }
...@@ -43,7 +43,7 @@ public class ReportController { ...@@ -43,7 +43,7 @@ public class ReportController {
@ApiOperation("上传车检文件") /*@ApiOperation("上传车检文件")
@PostMapping(value = "/uploadReportFilesNotCertificate") @PostMapping(value = "/uploadReportFilesNotCertificate")
@ResponseBody @ResponseBody
public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile, public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile,
...@@ -69,8 +69,12 @@ public class ReportController { ...@@ -69,8 +69,12 @@ public class ReportController {
multipartFiles.add(applyTable); multipartFiles.add(applyTable);
reportService.uploadReport(reportPdfId, multipartFiles); reportService.uploadReport(reportPdfId, multipartFiles);
return ResultVo.success(); return ResultVo.success();
} }*/
@ApiOperation("上传车检文件")
/* @ApiOperation("上传车检文件")
@ResponseBody @ResponseBody
@PostMapping(value = "/uploadReportFiles") @PostMapping(value = "/uploadReportFiles")
public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile, public ResultVo uploadReportFiles(@RequestParam(name = "reportFile")MultipartFile reportFile,
...@@ -98,7 +102,7 @@ public class ReportController { ...@@ -98,7 +102,7 @@ public class ReportController {
multipartFiles.add(certificatePic); multipartFiles.add(certificatePic);
reportService.uploadReport(reportPdfId, multipartFiles); reportService.uploadReport(reportPdfId, multipartFiles);
return ResultVo.success(); return ResultVo.success();
} }*/
@ApiOperation("下载检测报告Base64文件") @ApiOperation("下载检测报告Base64文件")
...@@ -115,21 +119,22 @@ public class ReportController { ...@@ -115,21 +119,22 @@ public class ReportController {
} }
@ApiOperation("上传当前检测报告") @ApiOperation("上传当前检测报告")
@GetMapping("/uploadCurrent/{reportPdfId}") @PostMapping("/uploadCurrent")
public ResultVo uploadCurrentReport(@PathVariable Integer reportPdfId){ public ResultVo uploadCurrentReport(@RequestBody ReportUploadReqVo reqVo){
AssertUtil.isNotNull(reportPdfId,"缺少参数reportPdfId"); AssertUtil.isNotNull(reqVo.getReportPdfId(),"缺少参数reportPdfId");
reportService.uploadReport(reportPdfId,null); AssertUtil.isNotNull(reqVo.getType(),"缺少参数type");
reportService.uploadReport(reqVo);
return ResultVo.success(); return ResultVo.success();
} }
@ApiOperation("上传报告") /*@ApiOperation("上传报告")
@PostMapping("/upload") @PostMapping("/upload")
public ResultVo uploadReport(ReportUploadReqVo reqVo, @RequestParam(name = "files")List<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.size()==4,"请按照提示选择文件上传"); AssertUtil.isTrue(files.size()==4,"请按照提示选择文件上传");
reportService.uploadReport(reqVo.getReportPdfId(),files); reportService.uploadReport(reqVo.getReportPdfId(),files);
return ResultVo.success(); return ResultVo.success();
} }*/
@ApiOperation("签章检测报告") @ApiOperation("签章检测报告")
@PostMapping("/signature") @PostMapping("/signature")
......
...@@ -30,6 +30,7 @@ import org.springframework.http.HttpEntity; ...@@ -30,6 +30,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
...@@ -82,21 +83,6 @@ public class ReportService { ...@@ -82,21 +83,6 @@ public class ReportService {
this.taskErrorMapper = taskErrorMapper; this.taskErrorMapper = taskErrorMapper;
} }
//调试用
static {
reportVoList = Arrays.asList(
TestReportVo.builder().InspectionNum("450107690120200529155024739")
.BusinessKey("450107690120200529155024739")
.VIN("2142435346475678")
.IUIDATE("2020-06-13 11:07:12.2345")
.ESignNo("1000001").DetectStartTime("2020-06-13T10:38:07").DetectEndTime("2020-06-13T12:38:07")
.InspectionReportNo("450107690120200529155024739").IUTYPE("A").NewVDCT("1").PDFCount("4").siteName("金盾西乡塘检测站")
.SceneCode("1231").UniqueString("450107690120200529155024739").VDCT("1").VehicleID("1231313213123").VerifyResult("1").VLPN("测试11111").VLPNColor("蓝")
.StationCode("4501001").build()
);
}
/** /**
* 获取上传文件显示页面 * 获取上传文件显示页面
...@@ -125,13 +111,16 @@ public class ReportService { ...@@ -125,13 +111,16 @@ public class ReportService {
/** /**
* 自动下载检测报告并签章上传 * 自动下载检测报告并签章上传
*
*/ */
@Async
public void autoDownloadAndSignAndUploadReport(String account,String password,String snKey1,String snKey2,String snKey3, public void autoDownloadAndSignAndUploadReport(String account,String password,String snKey1,String snKey2,String snKey3,
String snName1,String snName2,String snName3){ String snName1,String snName2,String snName3){
try { try {
List<TestReportVo> testReportVos = carReportUtil.taskReportList(account, password); List<TestReportVo> testReportVos = carReportUtil.taskReportList(account, password);
log.info(">> 定时扫描未签章上传的检测报告,扫描结果:{} 条数据",testReportVos.size());
for(TestReportVo testReportVo:testReportVos){ for(TestReportVo testReportVo:testReportVos){
//根据报告编码查询数据库是否已下载 未下载则进行自动下载签章和上传 //根据报告编码查询数据库是否已下载 未下载则进行自动下载签章和上传
ReportPdfVo reportPdfVo = reportPdfMapper.selectOne(new QueryWrapper<ReportPdfVo>().lambda().eq(ReportPdfVo::getReportNum, testReportVo.getInspectionNum())); ReportPdfVo reportPdfVo = reportPdfMapper.selectOne(new QueryWrapper<ReportPdfVo>().lambda().eq(ReportPdfVo::getReportNum, testReportVo.getInspectionNum()));
...@@ -182,14 +171,14 @@ public class ReportService { ...@@ -182,14 +171,14 @@ public class ReportService {
ReportPdfVo reportPdfVos = JSONUtil.toBean(JSONUtil.toJsonPrettyStr(responseEntity.getBody().getData()), ReportPdfVo.class); ReportPdfVo reportPdfVos = JSONUtil.toBean(JSONUtil.toJsonPrettyStr(responseEntity.getBody().getData()), ReportPdfVo.class);
reportPdfMapper.updateById(reportPdfVos); reportPdfMapper.updateById(reportPdfVos);
//上传文件 //上传文件 (连同检测报告全部文件)
carReportUtil.uploadReportPost(account,password,reportPdfVo,signatureVo1.getDeptId()); carReportUtil.autoUploadReportPost(account,password,reportPdfVo,signatureVo1.getDeptId());
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
//记录错误信息 //记录错误信息
log.error(e.getCause().getMessage()); 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());
...@@ -230,37 +219,12 @@ public class ReportService { ...@@ -230,37 +219,12 @@ public class ReportService {
/** /**
* 上传检测报告以及其他文件到公安 * 上传检测报告以及其他文件到公安
* @param reportPdfId
* @param files
*/ */
public void uploadReport(Integer reportPdfId, List<MultipartFile> files){ public void uploadReport(ReportUploadReqVo reqVo){
ReportPdfVo reportPdfVo = reportPdfMapper.selectById(reportPdfId); ReportPdfVo reportPdfVo = reportPdfMapper.selectById(reqVo.getReportPdfId());
AssertUtil.isNotNull(reportPdfVo,"不存在该检测报告,请刷新页面"); AssertUtil.isNotNull(reportPdfVo,"不存在该检测报告,请刷新页面");
DeptVo currUserDept = getCurrUserDept(); DeptVo currUserDept = getCurrUserDept();
carReportUtil.uploadReportPost(currUserDept.getEpAccount(),currUserDept.getEpPassword(),reportPdfVo,currUserDept.getDeptId(),reqVo.getType());
List<String> filePath=new ArrayList<>();
try {
/*int i =0;
for (MultipartFile file : files) {
String reportPath = carReportUtil.getReportPath(reportPdfVo.getReportNum() + "_" + i , ".jpg");
if(FileUtil.exist(reportPath)){
FileUtil.del(reportPath);
}
FileUtil.writeBytes(file.getBytes(),reportPath);
filePath.add(reportPath);
i++;
}*/
//carReportUtil.uploadReport(currUserDept.getEpAccount(),currUserDept.getEpPassword(),reportPdfVo);
carReportUtil.uploadReportPost(currUserDept.getEpAccount(),currUserDept.getEpPassword(),reportPdfVo,currUserDept.getDeptId());
} catch (Exception e) {
throw new BusinessException(e.getLocalizedMessage());
} finally {
//删除刚才保存的文件
filePath.forEach(path -> {
FileUtil.del(path);
});
}
} }
......
...@@ -25,10 +25,7 @@ import org.jsoup.Jsoup; ...@@ -25,10 +25,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.openqa.selenium.By; import org.openqa.selenium.*;
import org.openqa.selenium.JavascriptExecutor;
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.openqa.selenium.support.ui.Select;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -144,13 +141,217 @@ public class CarReportUtil { ...@@ -144,13 +141,217 @@ public class CarReportUtil {
return reportResp; return reportResp;
} }
/**
* 上传文件post
* @param username
* @param password
* @param reportPdfVo
*/
public void autoUploadReportPost(String username, String password,ReportPdfVo reportPdfVo,Long deptid){
//登录环保系统获取token
WebDriver driver = null;
try {
//检测报告文件和其他至少四个文件(检测申请表、身份证、行驶证1、行驶证2)都有了才上传
if(FileUtil.exist(reportPdfVo.getPath())&&
FileUtil.exist(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.APPLY_SUFFIX)&&
FileUtil.exist(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.IDCARD_SUFFIX)&&
FileUtil.exist(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX1)&&
FileUtil.exist(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX2)){
String errMsgList = "";
//登录环保
driver = loginEp(username, password,BrowserVersion.INTERNET_EXPLORER);
Object[] cookies = driver.manage().getCookies().toArray();
Map<String,Object> formData = new HashMap<>();
formData.put("umclData","{\"UploadFileDataID\":0,\"MAI_ID\":0}");
formData.put("folder","/Addins/Template/");
formData.put("businessKey", StrUtil.isNotBlank(reportPdfVo.getBusinessKey())?reportPdfVo.getBusinessKey():reportPdfVo.getReportNum());
formData.put("BusinessType", "11");
formData.put("fileext", "*.pdf;*.jpg;*.png");
formData.put("UniqueString", reportPdfVo.getUniqueString());
formData.put("VehicleID", reportPdfVo.getVehicleId());
formData.put("params", "Submit Query");
//检测报告上传
formData.put("contentType","multipart/form-data; boundary=----------ae0ei4Ef1gL6GI3GI3KM7gL6Ef1gL6");
formData.put("Filename",FileUtil.file(reportPdfVo.getPath()).getName());
formData.put("FileGroup", "04");
formData.put("FileData", FileUtil.file(reportPdfVo.getPath()));
HttpResponse reportResp = uploadPost(formData,uploadFileUrl,cookies);
UploadRecordVo uploadRecordVo = new UploadRecordVo();
uploadRecordVo.setBusinessKey(reportPdfVo.getBusinessKey());
uploadRecordVo.setCarNum(reportPdfVo.getCarNum());
uploadRecordVo.setReportNum(reportPdfVo.getReportNum());
uploadRecordVo.setFileType(0);
uploadRecordVo.setCreateTime(DateUtil.date());
uploadRecordVo.setDeptId(deptid);
uploadRecordVo.setPath(reportPdfVo.getPath());
if(reportResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传检测报告失败!\n";
//上传状态
uploadRecordVo.setState(0);
} else {
//上传状态
uploadRecordVo.setState(1);
}
uploadRecordService.saveRecord(uploadRecordVo);
//申请表上传
formData.put("contentType","multipart/form-data; boundary=----------gL6ei4cH2GI3ei4ae0ei4ae0ei4KM7");
formData.put("Filename",FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.APPLY_SUFFIX).getName());
formData.put("FileGroup", "21");
formData.put("FileData", FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.APPLY_SUFFIX));
HttpResponse applyResp = uploadPost(formData,uploadFileUrl,cookies);
UploadRecordVo uploadRecord = new UploadRecordVo();
uploadRecord.setReportNum(reportPdfVo.getReportNum());
uploadRecord.setCarNum(reportPdfVo.getCarNum());
uploadRecord.setBusinessKey(reportPdfVo.getBusinessKey());
uploadRecord.setDeptId(deptid);
uploadRecord.setCreateTime(DateUtil.date());
uploadRecord.setPath(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.APPLY_SUFFIX);
uploadRecord.setFileType(1);
if(applyResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传检测申请表失败!\n";
uploadRecord.setState(0);
} else {
uploadRecord.setState(1);
}
uploadRecordService.saveRecord(uploadRecord);
//身份证上传
formData.put("contentType","multipart/form-data; boundary=----------GI3gL6cH2GI3gL6GI3GI3KM7KM7ae0");
formData.put("Filename",FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.IDCARD_SUFFIX).getName());
formData.put("FileGroup", "02");
formData.put("FileData", FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.IDCARD_SUFFIX));
applyResp = uploadPost(formData,uploadFileUrl,cookies);
uploadRecord = new UploadRecordVo();
uploadRecord.setReportNum(reportPdfVo.getReportNum());
uploadRecord.setCarNum(reportPdfVo.getCarNum());
uploadRecord.setBusinessKey(reportPdfVo.getBusinessKey());
uploadRecord.setCreateTime(DateUtil.date());
uploadRecord.setFileType(2);
uploadRecord.setPath(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.IDCARD_SUFFIX);
uploadRecord.setDeptId(deptid);
if(applyResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传身份证失败!\n";
uploadRecord.setState(0);
} else {
uploadRecord.setState(1);
}
uploadRecordService.saveRecord(uploadRecord);
//行驶证1文件上传
formData.put("contentType","multipart/form-data; boundary=----------ei4Ef1ei4Ef1gL6KM7ei4cH2ei4cH2");
formData.put("Filename",FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX1).getName());
formData.put("FileGroup", "03");
formData.put("FileData", FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX1));
applyResp = uploadPost(formData,uploadFileUrl,cookies);
uploadRecord = new UploadRecordVo();
uploadRecord.setReportNum(reportPdfVo.getReportNum());
uploadRecord.setCarNum(reportPdfVo.getCarNum());
uploadRecord.setCreateTime(DateUtil.date());
uploadRecord.setBusinessKey(reportPdfVo.getBusinessKey());
uploadRecord.setFileType(3);
uploadRecord.setPath(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX1);
uploadRecord.setDeptId(deptid);
if(applyResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传行驶证1文件失败!\n";
uploadRecord.setState(0);
} else {
uploadRecord.setState(1);
}
uploadRecordService.saveRecord(uploadRecord);
//行驶证2文件上传
formData.put("contentType","multipart/form-data; boundary=----------GI3KM7Ij5GI3gL6ae0Ij5ae0KM7cH2");
formData.put("Filename",FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX2).getName());
formData.put("FileGroup", "19");
formData.put("FileData", FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX2));
applyResp = uploadPost(formData,uploadFileUrl,cookies);
uploadRecord = new UploadRecordVo();
uploadRecord.setReportNum(reportPdfVo.getReportNum());
uploadRecord.setCarNum(reportPdfVo.getCarNum());
uploadRecord.setCreateTime(DateUtil.date());
uploadRecord.setBusinessKey(reportPdfVo.getBusinessKey());
uploadRecord.setPath(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.DRIVER_SUFFIX2);
uploadRecord.setDeptId(deptid);
uploadRecord.setFileType(4);
if(applyResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传行驶证2文件失败!\n";
uploadRecord.setState(0);
} else {
uploadRecord.setState(1);
}
uploadRecordService.saveRecord(uploadRecord);
//维修凭证上传
if(FileUtil.exist(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.CERTIFICATE_SUFFIX)){
formData.put("contentType","multipart/form-data; boundary=----------GI3gL6cH2GI3gL6GI3GI3KM7KM7ae0");
formData.put("Filename",FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.CERTIFICATE_SUFFIX).getName());
formData.put("FileGroup", "02");
formData.put("FileData", FileUtil.file(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.CERTIFICATE_SUFFIX));
applyResp = uploadPost(formData,uploadFileUrl,cookies);
uploadRecord = new UploadRecordVo();
uploadRecord.setReportNum(reportPdfVo.getReportNum());
uploadRecord.setCarNum(reportPdfVo.getCarNum());
uploadRecord.setBusinessKey(reportPdfVo.getBusinessKey());
uploadRecord.setCreateTime(DateUtil.date());
uploadRecord.setPath(uploadFilePath + reportPdfVo.getCarNum() + MyConstants.CERTIFICATE_SUFFIX);
uploadRecord.setDeptId(deptid);
uploadRecord.setFileType(5);
if(applyResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传维修凭证失败!\n";
uploadRecord.setState(0);
} else {
uploadRecord.setState(1);
}
uploadRecordService.saveRecord(uploadRecord);
}
//如果有上传失败的则输出控制台
if(StrUtil.isNotBlank(errMsgList)){
log.error("检测报告:{},车牌号:{} 上传错误信息:{}",reportPdfVo.getReportNum(),reportPdfVo.getCarNum(),errMsgList);
}
} else {
log.warn(">> 自动上传签章的文件未准备好,本次不做上传!");
}
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException(e.getLocalizedMessage());
}
}
/** /**
* 上传文件post * 上传文件post
* @param username * @param username
* @param password * @param password
* @param reportPdfVo * @param reportPdfVo
* @param uploadReport 是否上传检测报告 0不上传 1上传
*/ */
public void uploadReportPost(String username, String password,ReportPdfVo reportPdfVo,Long deptid){ public void uploadReportPost(String username, String password,ReportPdfVo reportPdfVo,Long deptid,Integer uploadReport){
//登录环保系统获取token //登录环保系统获取token
WebDriver driver = null; WebDriver driver = null;
try { try {
...@@ -162,42 +363,44 @@ public class CarReportUtil { ...@@ -162,42 +363,44 @@ public class CarReportUtil {
Object[] cookies = driver.manage().getCookies().toArray(); Object[] cookies = driver.manage().getCookies().toArray();
Map<String,Object> formData = new HashMap<>(); Map<String,Object> formData = new HashMap<>();
AssertUtil.isTrue(FileUtil.exist(reportPdfVo.getPath()),"未扫描到当前检测报告文件");
//检测报告上传
formData.put("contentType","multipart/form-data; boundary=----------ae0ei4Ef1gL6GI3GI3KM7gL6Ef1gL6");
formData.put("Filename",FileUtil.file(reportPdfVo.getPath()).getName());
formData.put("umclData","{\"UploadFileDataID\":0,\"MAI_ID\":0}"); formData.put("umclData","{\"UploadFileDataID\":0,\"MAI_ID\":0}");
formData.put("folder","/Addins/Template/"); formData.put("folder","/Addins/Template/");
formData.put("businessKey", reportPdfVo.getBusinessKey()); formData.put("businessKey", StrUtil.isNotBlank(reportPdfVo.getBusinessKey())?reportPdfVo.getBusinessKey():reportPdfVo.getReportNum());
formData.put("FileGroup", "04");
formData.put("BusinessType", "11"); formData.put("BusinessType", "11");
formData.put("fileext", "*.pdf;*.jpg;*.png"); formData.put("fileext", "*.pdf;*.jpg;*.png");
formData.put("UniqueString", reportPdfVo.getUniqueString()); formData.put("UniqueString", reportPdfVo.getUniqueString());
formData.put("VehicleID", reportPdfVo.getVehicleId()); formData.put("VehicleID", reportPdfVo.getVehicleId());
formData.put("params", "Submit Query"); formData.put("params", "Submit Query");
formData.put("FileData", FileUtil.file(reportPdfVo.getPath()));
HttpResponse reportResp = uploadPost(formData,uploadFileUrl,cookies); //是否需要上传检测报告
if(uploadReport == 1){
UploadRecordVo uploadRecordVo = new UploadRecordVo(); AssertUtil.isTrue(FileUtil.exist(reportPdfVo.getPath()),"未扫描到当前检测报告文件");
uploadRecordVo.setBusinessKey(reportPdfVo.getBusinessKey()); //检测报告上传
uploadRecordVo.setCarNum(reportPdfVo.getCarNum()); formData.put("contentType","multipart/form-data; boundary=----------ae0ei4Ef1gL6GI3GI3KM7gL6Ef1gL6");
uploadRecordVo.setReportNum(reportPdfVo.getReportNum()); formData.put("Filename",FileUtil.file(reportPdfVo.getPath()).getName());
uploadRecordVo.setFileType(0); formData.put("FileGroup", "04");
uploadRecordVo.setCreateTime(DateUtil.date()); formData.put("FileData", FileUtil.file(reportPdfVo.getPath()));
uploadRecordVo.setDeptId(deptid); HttpResponse reportResp = uploadPost(formData,uploadFileUrl,cookies);
uploadRecordVo.setPath(reportPdfVo.getPath()); UploadRecordVo uploadRecordVo = new UploadRecordVo();
uploadRecordVo.setBusinessKey(reportPdfVo.getBusinessKey());
if(reportResp.getStatus() != HttpStatus.HTTP_OK){ uploadRecordVo.setCarNum(reportPdfVo.getCarNum());
errMsgList += "上传检测报告失败!\n"; uploadRecordVo.setReportNum(reportPdfVo.getReportNum());
//上传状态 uploadRecordVo.setFileType(0);
uploadRecordVo.setState(0); uploadRecordVo.setCreateTime(DateUtil.date());
} else { uploadRecordVo.setDeptId(deptid);
//上传状态 uploadRecordVo.setPath(reportPdfVo.getPath());
uploadRecordVo.setState(1);
if(reportResp.getStatus() != HttpStatus.HTTP_OK){
errMsgList += "上传检测报告失败!\n";
//上传状态
uploadRecordVo.setState(0);
} else {
//上传状态
uploadRecordVo.setState(1);
}
uploadRecordService.saveRecord(uploadRecordVo);
} }
uploadRecordService.saveRecord(uploadRecordVo);
...@@ -224,6 +427,8 @@ public class CarReportUtil { ...@@ -224,6 +427,8 @@ public class CarReportUtil {
uploadRecord.setState(1); uploadRecord.setState(1);
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
} else {
errMsgList += "没有找到申请表,申请表本次未上传\n";
} }
...@@ -250,6 +455,8 @@ public class CarReportUtil { ...@@ -250,6 +455,8 @@ public class CarReportUtil {
uploadRecord.setState(1); uploadRecord.setState(1);
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
}else {
errMsgList += "没有找到身份证,身份证本次未上传\n";
} }
//行驶证1文件上传 //行驶证1文件上传
...@@ -275,6 +482,8 @@ public class CarReportUtil { ...@@ -275,6 +482,8 @@ public class CarReportUtil {
uploadRecord.setState(1); uploadRecord.setState(1);
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
} else {
errMsgList += "没有找到行驶证1,行驶证1本次未上传\n";
} }
//行驶证2文件上传 //行驶证2文件上传
...@@ -300,6 +509,8 @@ public class CarReportUtil { ...@@ -300,6 +509,8 @@ public class CarReportUtil {
uploadRecord.setState(1); uploadRecord.setState(1);
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
} else {
errMsgList += "没有找到行驶证2,行驶证2本次未上传\n";
} }
...@@ -327,6 +538,8 @@ public class CarReportUtil { ...@@ -327,6 +538,8 @@ public class CarReportUtil {
uploadRecord.setState(1); uploadRecord.setState(1);
} }
uploadRecordService.saveRecord(uploadRecord); uploadRecordService.saveRecord(uploadRecord);
} else {
errMsgList += "没有找到维修凭证,维修凭证本次未上传\n";
} }
//如果有错误信息则抛出给客户端 //如果有错误信息则抛出给客户端
...@@ -334,195 +547,13 @@ public class CarReportUtil { ...@@ -334,195 +547,13 @@ public class CarReportUtil {
throw new BusinessException(errMsgList); throw new BusinessException(errMsgList);
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e.getLocalizedMessage()); e.printStackTrace();
throw new BusinessException(e.getLocalizedMessage()); throw new BusinessException(e.getLocalizedMessage());
} }
} }
/**
* 上传检测报告
* @param username 环保系统登录账号
* @param reportPdfVo 检测报告信息
* @param password 环保系统登录密码
*/
public void uploadReport(String username, String password,ReportPdfVo reportPdfVo) throws InterruptedException {
WebDriver driver = null;
//登录环保
driver = loginEp(username, password,BrowserVersion.INTERNET_EXPLORER);
//给线程睡眠10s
Thread.sleep(3000);
//抓取检测报告超链接
WebElement inspecReportBtn = driver.findElement(new By.ById("mainMenuTree_9_a"));
inspecReportBtn.click();
//延迟加载html
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)
.setScriptTimeout(60,TimeUnit.SECONDS).pageLoadTimeout(120,TimeUnit.SECONDS);
//给线程睡眠10s
Thread.sleep(4000);
//点击上传资料的超链接后,抓取frame窗口的元素
WebElement homeFrame = driver.findElement(new By.ByXPath("//*[@id=\"tabs\"]/div[2]/div[2]/div/iframe"));
//切换到iframe页面
WebDriver frameDriver = driver.switchTo().frame(homeFrame);
//延迟加载html
frameDriver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS)
.setScriptTimeout(120,TimeUnit.SECONDS).pageLoadTimeout(120,TimeUnit.SECONDS);
//给线程睡眠4s
Thread.sleep(4000);
WebElement element = frameDriver.findElement(new By.ByXPath("/html/body/form/div/div/table[1]/tbody/tr/td[2]/table/tbody/tr"));
List<WebElement> inputs = element.findElements(new By.ByTagName("input"));
inputs.get(0).click();
//延迟加载html
frameDriver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS)
.setScriptTimeout(120,TimeUnit.SECONDS).pageLoadTimeout(120,TimeUnit.SECONDS);
//给线程睡眠4s
Thread.sleep(4000);
//抓取文件组下拉选项
Select fileGroupSelect = new Select(frameDriver.findElement(new By.ByXPath("//select[@id='wjz']")));
fileGroupSelect.selectByIndex(1);
//抓取选择检测数据按钮
WebElement checkTestDataBtn = frameDriver.findElement(new By.ById("selectInsp"));
checkTestDataBtn.click();
//延迟加载html
frameDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)
.setScriptTimeout(60,TimeUnit.SECONDS).pageLoadTimeout(60,TimeUnit.SECONDS);
//给线程睡眠4s
Thread.sleep(3000);
//抓取选择检测数据弹窗
WebElement testDataFrame = frameDriver.findElement(new By.ByXPath("/html/body/div[8]"));
//抓取车牌号输入框
WebElement carNumInput = testDataFrame.findElement(new By.ByXPath("/html/body/div[8]/div[2]/div[1]/div/table[1]/tbody/tr[1]/td[2]/input"));
//抓取车主姓名输入框
WebElement driverName = testDataFrame.findElement(new By.ByXPath("/html/body/div[8]/div[2]/div[1]/div/table[1]/tbody/tr[2]/td[2]/input"));
//抓取车架号或其他信息输入框
WebElement otherInput = testDataFrame.findElement(new By.ByXPath("/html/body/div[8]/div[2]/div[1]/div/table[1]/tbody/tr[1]/td[4]/input"));
//抓取表单重置按钮
WebElement reset = testDataFrame.findElement(new By.ByXPath("/html/body/div[8]/div[2]/div[1]/div/table[1]/tbody/tr[2]/td[3]/input[1]"));
//抓取表单提交按钮
WebElement submit = testDataFrame.findElement(new By.ByXPath("/html/body/div[8]/div[2]/div[1]/div/table[1]/tbody/tr[2]/td[3]/input[2]"));
//写死只筛选车牌号码
carNumInput.sendKeys(reportPdfVo.getCarNum());
//开始检索
submit.click();
//延迟加载html
frameDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)
.setScriptTimeout(60,TimeUnit.SECONDS).pageLoadTimeout(60,TimeUnit.SECONDS);
//给线程睡眠4s
Thread.sleep(3000);
//抓取检索出来的记录
List<WebElement> tableTrList = frameDriver.findElements(new By.ByXPath("/html/body/div[8]/div[2]/div[1]/div/div/div/div/div[2]/div[2]/table/tbody/tr"));
if(tableTrList.size()<1){
log.warn(">> 没有该车辆信息的检测记录");
throw new BusinessException("上传文档失败,没有该车辆信息的检测记录");
}
//选择第一条记录(最新检测的记录)
tableTrList.get(0).click();
//要上传的报告记录
WebElement record= null;
for (WebElement webElement : tableTrList) {
//判断返回的列表记录是否包含当前检测报告的检测编号
if(webElement.getText().contains(reportPdfVo.getReportNum())){
record = webElement;
}
}
AssertUtil.isNotNull(record,"没有该车辆信息的检测记录");
//确定选择
frameDriver.findElement(new By.ByXPath("/html/body/div[8]/div[2]/div[2]/a[1]")).click();
//上传方式选择本地上传
frameDriver.findElement(new By.ByXPath("//*[@id=\"form1\"]/div/div/table[3]/tbody/tr/td[2]/label[2]")).click();
//将file元素改为可见
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) frameDriver;
javascriptExecutor.executeScript("document.getElementById('uploadify4').style.display='block';");
//检测测报告第一页
WebElement pic1 = frameDriver.findElement(new By.ById("fileQueue4"));
pic1.sendKeys(reportPdfVo.getPath());
//点击上传检测报告
frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_4\"]/tbody/tr[2]/td[2]/input")).click();
/*//检测报告第二页
WebElement pic2 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_85\"]/tbody/tr[1]/td/label"));
pic2.sendKeys(paths.get(1));
//行驶证1
WebElement pic3 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_3\"]/tbody/tr[1]/td/label"));
pic3.sendKeys(paths.get(2));
//驶证2
WebElement pic4 = frameDriver.findElement(new By.ByXPath("//*[@id=\"tb_33\"]/tbody/tr[1]/td/label"));
pic4.sendKeys(paths.get(3));
//身份证
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));
}*/
//点击上传已勾选的文件
/*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("green")){
frameDriver.close();
driver.close();
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("检测报告上传失败");
}
}
/** /**
...@@ -688,6 +719,8 @@ public class CarReportUtil { ...@@ -688,6 +719,8 @@ public class CarReportUtil {
return driver; return driver;
} }
/** /**
* 下载检测报告 并 转 PDF * 下载检测报告 并 转 PDF
* @param username * @param username
...@@ -819,10 +852,10 @@ public class CarReportUtil { ...@@ -819,10 +852,10 @@ public class CarReportUtil {
log.info(">> 检测报告下载完成!"); log.info(">> 检测报告下载完成!");
return getReportPath(fileName, ".pdf"); return getReportPath(fileName, ".pdf");
} catch (InterruptedException | UnsupportedEncodingException e) { } catch (InterruptedException | UnsupportedEncodingException | UnhandledAlertException e) {
driver.close(); driver.close();
log.error(e.getMessage()); e.printStackTrace();
throw new BusinessException("服务器繁忙请重试"); throw new BusinessException("检测报告下载失败");
} }
...@@ -919,7 +952,7 @@ public class CarReportUtil { ...@@ -919,7 +952,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 -> i.getPDFCount().equals("0")).collect(Collectors.toList());
pageVo.setRows(collect); pageVo.setRows(collect);
pageVo.setTotal(collect.size()); pageVo.setTotal(collect.size());
return pageVo.getRows(); return pageVo.getRows();
......
...@@ -5,7 +5,7 @@ spring: ...@@ -5,7 +5,7 @@ spring:
freemarker: freemarker:
check-template-location: false check-template-location: false
profiles: profiles:
active: prod active: dev
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8
data: data:
......
package me.zhengjie; package me.zhengjie;
import cn.hutool.core.io.FileUtil;
import me.zhengjie.utils.DateUtil; import me.zhengjie.utils.DateUtil;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class EladminSystemApplicationTests { public class EladminSystemApplicationTests {
@Test @Test
...@@ -17,6 +17,12 @@ public class EladminSystemApplicationTests { ...@@ -17,6 +17,12 @@ public class EladminSystemApplicationTests {
System.out.println(DateUtil.fromTimeStamp(1592023087L).toString()); System.out.println(DateUtil.fromTimeStamp(1592023087L).toString());
} }
@Test
public void testFileExit() {
String filePath ="C:\\reptiles\\uploadPicture\\粤JHB607_jcsqb.jpg";
System.out.println(FileUtil.exist(filePath));
}
public static void main(String[] args) { public static void main(String[] args) {
} }
} }
......
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