Appearance
流程中表单树扩展开发
注意
本示例,使用 KQCO 服务 的地址是:192.168.1.13
端口是:8003
后面会使用此参数
在构建表单中配置扩展指令
说明
流程中的业务表单里的扩展指令配置函数 formTreeInProcess
新建 springboot 项目
pom.xml 中引入 jar 包: co-service-sdk-api-6.x.x.jar
:下载
xml
<dependency>
<groupId>com.kanq.co</groupId>
<artifactId>co-service-sdk-api</artifactId>
<version>6.x.x</version>
</dependency>
<dependency>
<groupId>com.kanq.co</groupId>
<artifactId>co-service-sdk-api</artifactId>
<version>6.x.x</version>
</dependency>
启动类 SpringBootApplication
类配置:
java
//启动类扫描SDK配置项设置--此处必须固定此路径
@ComponentScan({"com.kqgeo.co.ext.*"})
//忽略数据源配置的话可配置此注解
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}
//启动类扫描SDK配置项设置--此处必须固定此路径
@ComponentScan({"com.kqgeo.co.ext.*"})
//忽略数据源配置的话可配置此注解
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}
注意
springboot2.* @ComponentScan({"com.kqgeo.co.ext.*"})
springboot3.* @ComponentScan({"com.kqgeo.co.ext.*","com.kanq.co.core"})
yml 配置(完整配置详见):
yaml
server:
port: 8888 #端口
coservice: #C++服务相关配置
'0':
model: hotStandby
server:
- addr: 192.168.1.13 #二开程序的C++配置要与java运行服务使用的C++地址端口保持一致
port: 8003
cofile:
affix: C:\\affix\\ #文件存储路径
server:
port: 8888 #端口
coservice: #C++服务相关配置
'0':
model: hotStandby
server:
- addr: 192.168.1.13 #二开程序的C++配置要与java运行服务使用的C++地址端口保持一致
port: 8003
cofile:
affix: C:\\affix\\ #文件存储路径
coservice
coservice
配置要与平台配置保持一致
扩展接口实现
- 创建 java 类
com.kqgeo.co.ext.flow
- 增加
public KqcoParm formTreeInProcess(@RequestBody ObjectNode parameter);
方法 - 增加指令注册注解
@Description(describe = "流程中表单树扩展开发", instructions = "formTreeInProcess",requestType = "post", requestUrl = "/co/flow/formTreeInProcess")
注意
com.kqgeo.co.ext
包名需要与配置文件中的packageName
保持一致注解说明:
describe
接口描述requestType
请求方式requestUrl
请求路径,请求路径要求前面/
不可忽略instructions
指令名称
- 完整代码(参数详见)
java
package com.kqgeo.co.ext.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kqgeo.co.ext.config.Description;
import com.kqgeo.co.ext.sdk.KqcoApi;
import com.kqgeo.co.ext.sdk.KqcoParm;
import com.kqgeo.co.ext.sdk.ParmImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Administrator
*/
@Slf4j
@RestController
@RequestMapping("co/flow")
public class Flow {
@RequestMapping(value = "/formTreeInProcess", method = RequestMethod.POST)
@Description(describe = "流程中表单树扩展开发", instructions = "formTreeInProcess",requestType = "post", requestUrl = "/co/flow/formTreeInProcess")
public KqcoParm formTreeInProcess(@RequestBody ObjectNode parameter) {
String m_sTicket ="tiket-5c396f8c702840fd9ae6523f9a70dac4";
KqcoApi kqcoApi = KqcoApiUtils.getKocoApi(m_sTicket);
ParmImpl kqcoParm = (ParmImpl) kqcoApi.getKqcoParm();
// 参数检查
if (kqcoParm.setRequest(parameter) != 0) {
return kqcoParm;
}
//获取参数
ObjectNode parmJson = kqcoParm.getRequest();
JsonNode argsJson = parmJson.get("args");
String jsonString = argsJson.get(4).asText();
//使用alibaba fastjson将String转为JSONArray
JSONArray formArray = JSONArray.parseArray(jsonString);
//增加子级表单
JSONObject childrenObject = new JSONObject();
childrenObject.put("text", "入职");
childrenObject.put("id", "1581325687");
childrenObject.put("qtip", "入职");
childrenObject.put("leaf", "true");
childrenObject.put("default", "false");
formArray.add(childrenObject);
//设置返回值
kqcoParm.setParameter(formArray);
return kqcoParm;
}
}
package com.kqgeo.co.ext.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kqgeo.co.ext.config.Description;
import com.kqgeo.co.ext.sdk.KqcoApi;
import com.kqgeo.co.ext.sdk.KqcoParm;
import com.kqgeo.co.ext.sdk.ParmImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Administrator
*/
@Slf4j
@RestController
@RequestMapping("co/flow")
public class Flow {
@RequestMapping(value = "/formTreeInProcess", method = RequestMethod.POST)
@Description(describe = "流程中表单树扩展开发", instructions = "formTreeInProcess",requestType = "post", requestUrl = "/co/flow/formTreeInProcess")
public KqcoParm formTreeInProcess(@RequestBody ObjectNode parameter) {
String m_sTicket ="tiket-5c396f8c702840fd9ae6523f9a70dac4";
KqcoApi kqcoApi = KqcoApiUtils.getKocoApi(m_sTicket);
ParmImpl kqcoParm = (ParmImpl) kqcoApi.getKqcoParm();
// 参数检查
if (kqcoParm.setRequest(parameter) != 0) {
return kqcoParm;
}
//获取参数
ObjectNode parmJson = kqcoParm.getRequest();
JsonNode argsJson = parmJson.get("args");
String jsonString = argsJson.get(4).asText();
//使用alibaba fastjson将String转为JSONArray
JSONArray formArray = JSONArray.parseArray(jsonString);
//增加子级表单
JSONObject childrenObject = new JSONObject();
childrenObject.put("text", "入职");
childrenObject.put("id", "1581325687");
childrenObject.put("qtip", "入职");
childrenObject.put("leaf", "true");
childrenObject.put("default", "false");
formArray.add(childrenObject);
//设置返回值
kqcoParm.setParameter(formArray);
return kqcoParm;
}
}
启动服务
扩展开发注册成功如下:
测试表单打开函数
设置流程中表单树扩展方法之前结果:
设置指令触发处理表格数据方法之后打印结果:
本示例代码在 com.kqgeo.co.ext.FlowDemo
类中的 formTreeInProcess
方法