泛微OA-E9与第三方系统集成开发企业级实战记录(八)

说明:

今天的实战记录要实现的是:金蝶ERP单据抛到OA审批,OA审批结束后回写审批状态。

实现思路:

1)编写2个自定义类文件(一个是传递审批通过的类文件,一个是传递审批不通过的类文件),类一定要继承BaseBean类或者实现Action接口,并在类中重写execute方法。在execute方法中发送Post请求调用金蝶提供的回写审批状态的接口。

2)将编译后的class文件(源文件也可以,重启后会自动编译成class文件)放到weaver/ecology/classbean目录下,重启服务。

3)配置附加操作,在流程节点"同意归档"节点点击"节点前附加操作",将传递审批通过的类路径配置上去;在流程节点"驳回归档"节点点击"节点前附加操作",将传递审批不通过的类路径配置上去。

实现过程:

1)新建传递审批通过的自定义类文件

复制代码
package weaver.interfaces.workflow;

import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;

public class AgreeAction extends BaseBean
  implements Action
{
  private static BaseBean log = new BaseBean();

  public String execute(RequestInfo request)
  {
    try {
      Map mainTableDataMap = new HashMap();
      //获取表单属性
      Property[] props = request.getMainTableInfo().getProperty();
      //将表单属性封装到HashMap
      for (int i = 0; i < props.length; i++) {
        String fieldname = props[i].getName().toLowerCase();
        String fieldval = Util.null2String(props[i].getValue());
        mainTableDataMap.put(fieldname, fieldval);
      }
      //获取表单里的回调地址(此地址约定由金蝶调用创建OA流程接口时传过来)
      String url = Util.null2String(mainTableDataMap.get("hdurl"));
      //获取流程唯一标识requestid
      String requestId = request.getRequestid();
      //组装审批同意的请求参数
      String pram = "{\"requestId\":\"" + requestId + "\",\"status\":\"3\"}";
      log.writeLog("OA调用异构系统传递的参数:" + pram);
      //发送post请求
      String res = sendPost(url, pram);
      log.writeLog("OA调用异构系统返回的结果:" + res);
      JSONObject resObject = JSONObject.parseObject(res);
      String bizcode = resObject.getString("bizcode");
      String bizmsg = resObject.getString("bizmsg");
      String data = resObject.getString("data");

      if (bizcode.equals("10000")) {
        //返回正常,放行流程
        return "1";
      }
      log.writeLog("OA调用异构系统的结果出现异常:" + bizmsg);
      request.getRequestManager().setMessage("-1");
      request.getRequestManager().setMessagecontent("OA调用异构系统的结果出现异常:" + bizmsg);
      //异常阻断流程执行
      return "0";
    }
    catch (Exception e) {
      log.writeLog("OA调用异构系统的结果出现异常:" + e);
      request.getRequestManager().setMessage("-1");
      request.getRequestManager().setMessagecontent("OA调用异构系统的结果出现异常:" + e);
    }
    return "0";
  }

  public static String sendPost(String url, String param)
  {
    OutputStreamWriter out = null;
    BufferedReader in = null;
    String result = "";
    try {
      URL realUrl = new URL(url);
      HttpURLConnection conn = null;

      conn = (HttpURLConnection)realUrl.openConnection();

      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      conn.setDoInput(true);

      conn.setRequestProperty("accept", "*/*");
      conn.setRequestProperty("connection", "Keep-Alive");
      conn.setRequestProperty("user-agent", 
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
      conn.setRequestProperty("Content-Type", "application/json");
      conn.connect();

      out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");

      out.write(param);

      out.flush();

      in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      String line;
      while ((line = in.readLine()) != null)
      {
        String line;
        result = result + line;
      }
    } catch (Exception e) {
      log.writeLog("OA调用异构系统的结果出现异常:" + e);
      try
      {
        if (out != null) {
          out.close();
        }
        if (in != null)
          in.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    finally
    {
      try
      {
        if (out != null) {
          out.close();
        }
        if (in != null)
          in.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    return result;
  }
}

2)新建传递审批不通过的自定义类文件

java 复制代码
package weaver.interfaces.workflow;

import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;

public class RejectAction extends BaseBean
  implements Action
{
  private static BaseBean log = new BaseBean();

  public String execute(RequestInfo request)
  {
    try {
      Map mainTableDataMap = new HashMap();
      Property[] props = request.getMainTableInfo().getProperty();
      for (int i = 0; i < props.length; i++) {
        String fieldname = props[i].getName().toLowerCase();
        String fieldval = Util.null2String(props[i].getValue());
        mainTableDataMap.put(fieldname, fieldval);
      }
      String url = Util.null2String(mainTableDataMap.get("hdurl"));
      String requestId = request.getRequestid();
      //组装审批不通过的请求参数
      String pram = "{\"requestId\":\"" + requestId + "\",\"status\":\"0\"}";
      log.writeLog("OA调用异构系统的结果传递参数:" + pram);
      String res = sendPost(url, pram);
      log.writeLog("OA调用异构系统的返回结果:" + res);
      JSONObject resObject = JSONObject.parseObject(res);
      String bizcode = resObject.getString("bizcode");
      String bizmsg = resObject.getString("bizmsg");
      String data = resObject.getString("data");

      if (bizcode.equals("10000")) {
        return "1";
      }
      log.writeLog("OA调用异构系统的结果出现异常:" + bizmsg);
      request.getRequestManager().setMessage("-1");
      request.getRequestManager().setMessagecontent("OA调用异构系统的结果出现异常:" + bizmsg);
      return "0";
    }
    catch (Exception e) {
      log.writeLog("OA调用异构系统的结果出现异常:" + e);
      request.getRequestManager().setMessage("-1");
      request.getRequestManager().setMessagecontent("OA调用异构系统的结果出现异常:" + e);
    }
    return "0";
  }

  public static String sendPost(String url, String param)
  {
    OutputStreamWriter out = null;
    BufferedReader in = null;
    String result = "";
    try {
      URL realUrl = new URL(url);
      HttpURLConnection conn = null;

      conn = (HttpURLConnection)realUrl.openConnection();

      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      conn.setDoInput(true);

      conn.setRequestProperty("accept", "*/*");
      conn.setRequestProperty("connection", "Keep-Alive");
      conn.setRequestProperty("user-agent", 
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
      conn.setRequestProperty("Content-Type", "application/json");
      conn.connect();

      out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");

      out.write(param);

      out.flush();

      in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      String line;
      while ((line = in.readLine()) != null)
      {
        String line;
        result = result + line;
      }
    } catch (Exception e) {
      log.writeLog("OA调用异构系统的结果出现异常:" + e);
      try
      {
        if (out != null) {
          out.close();
        }
        if (in != null)
          in.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    finally
    {
      try
      {
        if (out != null) {
          out.close();
        }
        if (in != null)
          in.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    return result;
  }
}

3)将代码文件放到OA服务器

根据代码文件里的包路径:package weaver.interfaces.workflow;

将编译后的class文件或者java源文件放到如下目录:weaver/ecology/classbean/weaver/interfaces/workflow

重启OA应用服务

4)配置节点前附加操作

将审批通过的代码类路径配置到"同意归档",将审批不通过的代码类路径配置到"驳回归档"节点的"节点前附加操作",类路径为包路径+类名称,示例如下:

审批通过的类路径:weaver.interfaces.workflow.AgreeAction

审批不通过的类路径:weaver.interfaces.workflow.RejectAction

相关推荐
迷藏4941 天前
**eBPF实战进阶:从零构建网络流量监控与过滤系统**在现代云原生架构中,**网络可观测性**和**安全隔离**已成为
java·网络·python·云原生·架构
迷藏4941 天前
**发散创新:基于Solid协议的Web3.0去中心化身份认证系统实战解析**在Web3.
java·python·web3·去中心化·区块链
qq_433502181 天前
Codex cli 飞书文档创建进阶实用命令 + Skill 创建&使用 小白完整教程
java·前端·飞书
safestar20121 天前
ES批量写入性能调优:BulkProcessor 参数详解与实战案例
java·大数据·运维·jenkins
还在忙碌的吴小二1 天前
Harness 最佳实践:Java Spring Boot 项目落地 OpenSpec + Claude Code
java·开发语言·spring boot·后端·spring
风吹迎面入袖凉1 天前
【Redis】Redis的五种核心数据类型详解
java·redis
夕除1 天前
javaweb--02
java·tomcat
ailvyuanj1 天前
2026年Java AI开发实战:Spring AI完全指南
java
张np1 天前
java进阶-Dubbo
java·dubbo
汽车仪器仪表相关领域1 天前
NHFID-1000型非甲烷总烃分析仪:技术破局,重构固定污染源监测新体验
java·大数据·网络·人工智能·单元测试·可用性测试·安全性测试