泛微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

相关推荐
掌心向暖RPA自动化2 小时前
如何获取网页某个元素在屏幕可见部分的中心坐标影刀RPA懒加载坐标定位技巧
java·javascript·自动化·rpa·影刀rpa
日取其半万世不竭2 小时前
Minecraft Java版社区服务器搭建教程(Linux,适合新手)
java·linux·服务器
TeamDev3 小时前
JxBrowser 9.0.0 版本发布啦!
java·前端·混合应用·jxbrowser·浏览器控件·跨平台渲染·原声输入
AI人工智能+电脑小能手3 小时前
【大白话说Java面试题】【Java基础篇】第24题:Java面向对象有哪些特征
java·开发语言·后端·面试
AI人工智能+电脑小能手4 小时前
【大白话说Java面试题】【Java基础篇】第25题:JDK1.8的新特性有哪些
java·开发语言·后端·面试
likerhood4 小时前
SLF4J: Failed to load class “StaticLoggerBinder“ 解决
java·log4j·maven
早日退休!!!4 小时前
大模型推理瓶颈七层分析模型
java·服务器·数据库
叶小鸡4 小时前
Java 篇-项目实战-天机学堂(从0到1)-day9
java·开发语言
@#¥&~是乱码鱼啦5 小时前
Spring分层架构:Controller、Service、Mapper数据链路,IOC的真实工作意义
java·spring·架构
xieliyu.5 小时前
Java手搓数据结构:从零模拟实现无头双向非循环链表
java·数据结构·链表