泛微 OA - 根据流程 requestid 获取流程中的附件

泛微 OA - 根据流程 requestid 获取流程中的附件

在泛微 OA 流程中,附件是通过加密上传的,如果在第三方系统想要调用 OA 系统获取 OA 附件,暂时没有很好的方法实现。但是可以在本地进行调用,得到附件 url 地址、附件 id、附件上传者等信息,拿到这些信息后,可以用过 url 地址在本地下载。

废话不多说,演示开始,封装了一个小代码:

GetDocApiByRequestId.java

此路径记得白名单加白:/test/workflow/getDocApiByRequestId

@Path("/test/workflow/getDocApiByRequestId")
public class GetDocApiByRequestId extends GetDocApiByRequestIdAction {
}

GetDocApiByRequestIdAction.java

public class GetDocApiByRequestIdAction {
    Logger logger = LoggerFactory.getLogger(GetDocApiByRequestIdAction.class);

    @GET
    @Path("/getDoc")
    @Produces(MediaType.APPLICATION_JSON)
    public String doGet(@Context HttpServletRequest request) throws Exception {
        String token = request.getHeader("token"); // 获取 token、appid、userid,在下文会用到
        String appid = request.getHeader("appid");
        String userid = request.getHeader("userid");
        String requestid = request.getParameter("requestid");
        Map<String, Object> resultMap = new HashMap<>(3);

        if (requestid.isEmpty() || 判断requestid 是否在流程中存在,此处不再演示了) {
            resultMap.put("code", "fail");
            resultMap.put("data", "");
            resultMap.put("msg", "requestid 错误");
            return JSON.toJSONString(resultMap);
        }

        // 目标地址,此地址是泛微官方获取流程数据的接口,原文链接:https://e-cloudstore.com/ec/api/applist/index.html#/
        String url = "http://192.168.190.5:8080/api/workflow/paService/getRequestResources?requestid=" + requestid;
        HttpGet httpGet = new HttpGet(url);

        // 设置类型 "application/x-www-form-urlencoded" "application/json"
        httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
        httpGet.setHeader("token", token);
        httpGet.setHeader("appid", appid);
        httpGet.setHeader("userid", userid);
        logger.info("调用 url: " + httpGet.getURI());

        // httpClient实例化
        CloseableHttpClient httpClient = HttpClients.createDefault();
        // 执行请求并获取返回
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity entity = response.getEntity();
        logger.info("返回状态码:" + response.getStatusLine());

        // 显示结果
        BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
        String line = null;
        StringBuffer responseSB = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            responseSB.append(line);
        }
        logger.info("返回消息:" + responseSB);

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonNode = objectMapper.readTree(responseSB.toString());
        JsonNode dataNode = jsonNode.get("data");

        List<DocEntity> list = new ArrayList<>();
        for (int i=0; i< dataNode.size(); i++) {
            DocEntity docEntity =  objectMapper.convertValue(dataNode.get(i), DocEntity.class);
            list.add(docEntity);
        }

        resultMap.put("code", "success");
        resultMap.put("data", list);
        resultMap.put("msg", "获取成功");

        reader.close();
        httpClient.close();
        return JSON.toJSONString(resultMap);
    }
}

附件信息的实体类:
DocEntity.java

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DocEntity {
    private String createdate; // 附件上传日期
    private String createrName; // 创建人名字
    private String createrid; // 用户id
    private String createtime; // 上传具体时间
    private String downloadUrl; // 附件 url (本次演示重点要得到的内容)
    private String id; // 附件id
    private String name; // 附件名字
    private String type; // 附件形式
}

代码结束,打包上传服务器,postman 演示:

url:

http://192.168.190.5:8080/api/test/workflow/getDocApiByRequestId/getDoc

记得在请求头中携带 token、appid、加密后的 userid

在这里插入图片描述

获取成功,在 url 前面拼接服务器地址就可以下载附件了。

相关推荐

  1. E9 流程附件发送第三方系统

    2024-03-15 17:32:01       28 阅读
  2. 附录C:招聘流程

    2024-03-15 17:32:01       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-15 17:32:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-15 17:32:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-15 17:32:01       82 阅读
  4. Python语言-面向对象

    2024-03-15 17:32:01       91 阅读

热门阅读

  1. [Vue]插槽

    2024-03-15 17:32:01       40 阅读
  2. openssl生成免费证书

    2024-03-15 17:32:01       44 阅读
  3. verilog中,何时用reg和wire

    2024-03-15 17:32:01       43 阅读
  4. Cron 表达式

    2024-03-15 17:32:01       41 阅读
  5. Python中Pandas常用函数及案例详解

    2024-03-15 17:32:01       38 阅读
  6. jvm 垃圾回收机制原理

    2024-03-15 17:32:01       45 阅读
  7. Day34|贪心算法|分发糖果

    2024-03-15 17:32:01       45 阅读
  8. 大龄程序员的出路在哪里?

    2024-03-15 17:32:01       38 阅读