泛微OA二次开发培训--自定义Action接口

该接口主要实现在流程的流转当中,实时通过自定义的动作去操作异构形体系统的数据或者是其他一些特定的操作。 在流程的每个出口或者节点都可以定义这样的自定义动作,从而实现在流程流转过程导入,导出流程的相关信息,或者将流程信息和其他应用相结合进行数据交互。

编写Action

新建Action实现类必须实现接口weaver.interfaces.workflow.action方法public String execute(RequestInfo request)

package weaver.interfaces.workflow.action;

import weaver.general.BaseBean;
import weaver.soa.workflow.request.DetailTableInfo;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

public class TestAction extends BaseBean implements Action {

    public String p1; //自定义参数1
    public String p2; //自定义参数2

    public String execute(RequestInfo requestinfo) {
        System.out.println("进入Action requestid="+requestinfo.getRequestid());
        String requestid = requestinfo.getRequestid();//请求ID
        String requestlevel = requestinfo.getRequestlevel();//请求紧急程度
        String src = requestinfo.getRequestManager().getSrc();
        //当前操作类型 submit:提交/reject:退回
        String workflowid = requestinfo.getWorkflowid();//流程ID
        String tablename = requestinfo.getRequestManager().getBillTableName();//表单名称
        int billid = requestinfo.getRequestManager().getBillid();//表单数据ID
        User usr = requestinfo.getRequestManager().getUser();//获取当前操作用户对象
        String requestname = requestinfo.getRequestManager().getRequestname();//请求标题
        String remark = requestinfo.getRequestManager().getRemark();//当前用户提交时的签字意见
        int formid = requestinfo.getRequestManager().getFormid();//表单ID
        int isbill = requestinfo.getRequestManager().getIsbill();//是否是自定义表单
        //取主表数据
        Property[] properties = request.getMainTableInfo().getProperty();// 获取表单主字段信息
        for (int i = 0; i < properties.length; i++) {
            String name = properties[i].getName();// 主字段名称
            String value = Util.null2String(properties[i].getValue());// 主字段对应的值
            System.out.println(name + " " + value);
        }
        //取明细数据
        DetailTable[] detailtable = request.getDetailTableInfo().getDetailTable();// 获取所有明细表
        if (detailtable.length > 0) {
            for (int i = 0; i < detailtable.length; i++) {
                DetailTable dt = detailtable[i];// 指定明细表
                Row[] s = dt.getRow();// 当前明细表的所有数据,按行存储
                for (int j = 0; j < s.length; j++) {
                    Row r = s[j];// 指定行
                    Cell c[] = r.getCell();// 每行数据再按列存储
                    for (int k = 0; k < c.length; k++) {
                        Cell c1 = c[k];// 指定列
                        String name = c1.getName();// 明细字段名称
                        String value = c1.getValue();// 明细字段的值
                        System.out.println(name + " " + value);
                    }
                }
            }
        }
        //控制流程流转,增加以下两行,流程不会向下流转,表单上显示返回的自定义错误信息
        requestinfo.getRequestManager().setMessagecontent("返回自定义的错误信息");
        requestinfo.getRequestManager().setMessageid("错误信息编号");

        System.out.println("Action执行完成 传入参数p1="+this.getP1()+"  p2="+this.getP2());

        return SUCCESS ;//return返回固定返回`SUCCESS`
    }
    public String getP1() {
        return p1;
    }
    public void setP1(String p1) {
        this.p1 = p1;
    }
    public String getP2() {
        return p2;
    }
    public void setP2(String p2) {
        this.p2 = p2;
    }


}

 

注册Action

进入后端引擎->集成中心->流程流转集成 

一个Action只要注册一次就可以。注册后可以在节点或者出口的附加操作中使用

 

 

配置Action

 

选择注册的Action,然后点击保存外部接口进行数据保存

 

Action示例

某个客户的回调SAP数据 调用接口的Action

 

package weaver.interfaces.workflow.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.soa.workflow.request.RequestInfo;
import weaver.system.SapWebserviceClient;

public class CallBackSapFor319Action extends BaseBean implements Action {

    private final static String joinstring = "|";
    public String execute(RequestInfo request) {
        String requestid = request.getRequestid() ;
        String tablename = request.getRequestManager().getBillTableName() ;
        String src = request.getRequestManager().getSrc() ;
        String workflowid = request.getWorkflowid() ;
        //读取配置的设置
        String projectfieldname = Util.null2String(getPropValue("SAPAjax","sapprj319fieldname"));//项目编号
        String ztfieldname = Util.null2String(getPropValue("SAPAjax","zt319fieldname"));//客户    
        SapWebserviceClient sap_api = new SapWebserviceClient();
        String projectid = "";
        String zt = "";

        RecordSet rs = new RecordSet();
        rs.executeSql("select "+projectfieldname+","+ztfieldname+"  from "+tablename+" where requestid="+requestid);
        rs.next();
        projectid = Util.null2String(rs.getString(1));
        zt = Util.null2String(rs.getString(2));

        if(projectid.equals("")){
            //调用异常 返回错误信息
            request.getRequestManager().setMessageid(System.currentTimeMillis()+"");
            request.getRequestManager().setMessagecontent("项目名称为空,请修改表单重新提交!");
        }else{
            try{
                sap_api.getPLM09Client(projectid, zt);
            }catch(Exception e){
                //调用异常 返回错误信息
                request.getRequestManager().setMessageid(System.currentTimeMillis()+"");
                request.getRequestManager().setMessagecontent("调用SAP接口9出现异常!"+e.getMessage());
                writeLog(e);//写日志
            }
        }
        return SUCCESS ;
    }

}

调用外部数据源 

package weaver.interfaces.workflow.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import weaver.general.BaseBean;
import weaver.general.StaticObj;
//泛微OA调用外部数据源源代码
//bw.ren 2019年12月2日16:33:04
public class DataSourceDemo extends BaseBean {
    public void testDatasource() {
        //此处是取得上文定义的数据源dt1,如果需要操作其他系统的数据才需要该定义
        Connection conn = getConnection("datasource.local");
        try {
            //通过jdbc获取人数
            PreparedStatement s = conn.prepareStatement("select count(*) as counthrm from hrmresource");
            ResultSet rs = s.executeQuery();
            if (rs.next()) {
                String counthrm = rs.getString("counthrm");
                //输出到控制台
                System.out.println("人数:" + counthrm);
                writeLog("人数:" + counthrm);
            }
            rs.close();//关闭记录集
            s.close();//关闭statement
        } catch (Exception e) {
            writeLog(e);
        } finally {
            try {
                closeConnection(conn);//关闭连接
            } catch (Exception e) {
                writeLog(e);
            }
        }
    }

    /**
     * 获取自定义datasource的connection
     *
     * @param datasourceid 数据源id,为"datasource"+数据源配置里面的数据源名称,
     *                     比如配置了一个数据源名称为local,那么这个数据源id为:datasource.local
     * @return
     */
    public Connection getConnection(String datasourceid) {
        Connection conn = null;
        try {
            weaver.interfaces.datasource.DataSource datasource = (weaver.interfaces.datasource.DataSource) StaticObj.getServiceByFullname(datasourceid, weaver.interfaces.datasource.DataSource.class);  //获取数据源的信息
            conn = datasource.getConnection(); //和数据源取得连接
        } catch (Exception e) {

        }
        return conn;
    }

    /**
     * 关闭Connection
     *
     * @param conn
     */
    public void closeConnection(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                writeLog(e);
            }
        }
    }
}



 

  • 16
    点赞
  • 104
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值