Skip to content
本页内容

JNI 开发

平台 V6.5 扩展开发前提

  • 了解构建平台基本知识
  • 掌握指令配置方法以及参数配置
  • 熟练 JAVA 开发语言

开发

  • 使用 com.fasterxml.jackson 解析 json
  • 使用注册包 co-service-macro-sdk-xx.xx.xx.jar 下载
  • 入参参数使用 byte[] macroHead,byte[][] argv 类型
  • 出差参数使用 byte[] 类型

手动将 jar 导入本地 maven 仓库

  • 执行以下命令将 jar 导入本地 maven 仓库,以 1.0.2 版本为例:
xml
mvn install:install-file -Dfile=C:\jar\co-service-macro-sdk-1.0.2.jar -DgroupId=com.kanq -DartifactId=co-service-macro-sdk -Dversion=1.0.2 -Dpackaging=jar
mvn install:install-file -Dfile=C:\jar\co-service-macro-sdk-1.0.2.jar -DgroupId=com.kanq -DartifactId=co-service-macro-sdk -Dversion=1.0.2 -Dpackaging=jar

新建项目

pom.xml 中引入 co-service-macro-sdk-x.x.x.jar 包:

xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.kanq</groupId>
  <artifactId>co-service-ext</artifactId>
  <version>1.0.1</version>
  <packaging>jar</packaging>

  <name>co_service_web_ext_demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

    <dependency>
        <groupId>com.kanq</groupId>
        <artifactId>co-service-macro-sdk</artifactId>
        <version>1.x.x</version>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.kanq</groupId>
  <artifactId>co-service-ext</artifactId>
  <version>1.0.1</version>
  <packaging>jar</packaging>

  <name>co_service_web_ext_demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

    <dependency>
        <groupId>com.kanq</groupId>
        <artifactId>co-service-macro-sdk</artifactId>
        <version>1.x.x</version>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

增加接口

  • 创建 java 类 com.kanq.MacroPrint
  • 增加 private static byte[] call(String macroHead,String[] argv); 方法
  • 增加指令注册注解 @Macro(describe = "方法描述", name = "指令名称")

注意

  • 入参说明:
    • macroHead 请求头,参数不定,格式: form:2\r\nuser:1
    • argv 入参参数
  • 出参说明:
    • 字符串:json 格式
    • 文件: 字节流
  • 注解说明:
    • describe 接口描述
    • name 指令名称 :::

macroHead 参数说明

  • addr 当前用户 IP
  • client f: 函数,m:移动动
  • busi 当前业务编号
  • role 当前角色
  • user 当前用户编号
  • stat 当前流程状态
  • tach 当前流程环节
  • flow 当前打开流程
  • form 当前打开表单
  • prev 父级表单
  • tent 指定租户编号
  • trace 链路日志
  • ticket 票据
  • MacroPrint.java
java
package com.kanq;

import com.kanq.print.printImpl.PrintImpl;
import com.kanq.sdk.config.Macro;

import java.io.*;

public class MacroPrint {

    @Macro( name = "getPdfBase64",describe = "打印")
    private static byte[] call(byte[] macroHead,byte[][] argv) {

        if(argv.length < 2){
            return null;
        }

        String sName ="print.pdf";
        if(argv.length > 0){
            sName = new String(argv[0], StandardCharsets.UTF_8);
        }

        String sTD = "";
        if(argv.length > 2){
            sTD = new String(argv[2], StandardCharsets.UTF_8);;
        }

        String xml = new String(argv[1], StandardCharsets.UTF_8);;
        ByteArrayOutputStream bos = getBos(xml,sName,sTD);
        byte[] arr = null;

        if(bos != null){
            arr= bos.toByteArray();
        }
        return arr;
    }

    public static ByteArrayOutputStream getBos(String xml,String name,String type) {
        ByteArrayOutputStream bos = new PrintImpl().getPdf(xml,"TD".equals(type),name);
        return bos;
    }
}

package com.kanq;

import com.kanq.print.printImpl.PrintImpl;
import com.kanq.sdk.config.Macro;

import java.io.*;

public class MacroPrint {

    @Macro( name = "getPdfBase64",describe = "打印")
    private static byte[] call(byte[] macroHead,byte[][] argv) {

        if(argv.length < 2){
            return null;
        }

        String sName ="print.pdf";
        if(argv.length > 0){
            sName = new String(argv[0], StandardCharsets.UTF_8);
        }

        String sTD = "";
        if(argv.length > 2){
            sTD = new String(argv[2], StandardCharsets.UTF_8);;
        }

        String xml = new String(argv[1], StandardCharsets.UTF_8);;
        ByteArrayOutputStream bos = getBos(xml,sName,sTD);
        byte[] arr = null;

        if(bos != null){
            arr= bos.toByteArray();
        }
        return arr;
    }

    public static ByteArrayOutputStream getBos(String xml,String name,String type) {
        ByteArrayOutputStream bos = new PrintImpl().getPdf(xml,"TD".equals(type),name);
        return bos;
    }
}

打包

将程序和依赖 jar 分离打包

  • 程序保存 ./jar/co/ 目录下
  • 依赖保存 ./jar/lib/ 目录下
xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.kanq</groupId>
  <artifactId>co-service-ext</artifactId>
  <version>1.0.1</version>
  <packaging>jar</packaging>

  <name>co_service_web_ext_demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <!-- 打包不含依赖jar -->
  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

  <!-- 依赖包导出lib文件夹下 -->
  <build>
        <finalName>Ext</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.2.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!--<fork>true</fork>-->
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <!-- 排除所有Jar -->
                            <groupId>nothing</groupId>
                            <artifactId>nothing</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!-- ${project.build.directory}是maven变量,内置的,表示target目录,如果不写,将在跟目录下创建/lib -->
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <!-- excludeTransitive:是否不包含间接依赖包,比如我们依赖A,但是A又依赖了B,我们是否也要把B打进去 默认不打-->
                            <excludeTransitive>false</excludeTransitive>
                            <!-- 复制的jar文件去掉版本信息 true去掉 false 不去-->
                            <stripVersion>false</stripVersion>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.kanq</groupId>
  <artifactId>co-service-ext</artifactId>
  <version>1.0.1</version>
  <packaging>jar</packaging>

  <name>co_service_web_ext_demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <!-- 打包不含依赖jar -->
  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

  <!-- 依赖包导出lib文件夹下 -->
  <build>
        <finalName>Ext</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.2.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!--<fork>true</fork>-->
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <!-- 排除所有Jar -->
                            <groupId>nothing</groupId>
                            <artifactId>nothing</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!-- ${project.build.directory}是maven变量,内置的,表示target目录,如果不写,将在跟目录下创建/lib -->
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <!-- excludeTransitive:是否不包含间接依赖包,比如我们依赖A,但是A又依赖了B,我们是否也要把B打进去 默认不打-->
                            <excludeTransitive>false</excludeTransitive>
                            <!-- 复制的jar文件去掉版本信息 true去掉 false 不去-->
                            <stripVersion>false</stripVersion>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

注意

  • 新接口需重启 co-service 后才能生效

下载

  • 开发依赖包 co-service-macro-sdk-xx.xx.xx.zip 下载

Powerd by Vitepress.