系统交互传递附件方式一 --Base64

附件所在系统

   @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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

懒羊羊--搞点小技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值