附件所在系统
@Override
public String queryAttach(int id, String loginname, String password, String ip, int workflowid, String formid) {
DocServiceImpl docServiceImpl = new DocServiceImpl();
try {
String sessionCode = docServiceImpl.login(loginname, password, 2, ip);
DocInfo docInfo = docServiceImpl.getDoc(id, sessionCode);
DocAttachment[] das = docInfo.getAttachments();
String fileTypeAll = OAPropUtil.ocr_scan_file_type;
logger.info("进入附件=");
for (DocAttachment da : das) {
logger.info("是否有附件");
String fileType = da.getFilename().substring(da.getFilename().lastIndexOf(".") + 1);
if (fileTypeAll.indexOf(fileType) > -1) {
logger.info("有附件");
byte[] content = Base64.decode(da.getFilecontent());
String url = OAPropUtil.ocr_scan_url;
// String url = "http://10.1.62.28:16783/ocr";
logger.info("ocr服务器="+url);
JSONObject object = new JSONObject();
object.put("content", content);
object.put("fileName", da.getFilename());
object.put("fileType", fileType);
String json = OAUtil.post(url, JSON.toJSONString(object));
接收附件系统
@PostMapping("/file")
public String getOcrInfo(@RequestBody String json) {
String ocrResult = null;
try {
// log.info("进入链接");
long start = System.currentTimeMillis();
// log.info("开始访问="+start);
JSONObject obj = JSON.parseObject(json);
String fileName = obj.getString("fileName");
byte[] content = obj.getBytes("content");
String fileType = obj.getString("fileType");
String localPath = File.separator + "tmp" + File.separator + "contract" + File.separator + fileName;
File file = new File(localPath);
// 校验文件夹目录是否存在,不存在就创建一个目录
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
//写数据
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(content);
bos.close();
fos.close();
if (file.exists()) {
if ("doc".equals(fileType) || "docx".equals(fileType)) {
//word文件扫描
ocrResult = wordEleExtract.extract(file, 12, null);
} else {
//单个文件抽取
ocrResult = universalEleExtract.extract(file, 12, null);
}
file.delete();
long end = System.currentTimeMillis();
long m = (end-start)/1000;
}
} catch (Exception e) {
e.printStackTrace();
}
return ocrResult;
}