Skip to content
本页内容

流程发送前做数据校验

应用场景

在流程发送之前,我们需要对第三方数据或在特定条件下对平台内部数据进行严格的校验,以确保数据的准确性和可靠性。

扩展接口实现

java
package com.kqgeo.co.ext.controller;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kqgeo.co.ext.config.Description;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ext/co/flow")
public class FlowDemo {

	/**
	 * 流程发送前数据校验
	 * @param parameter
	 * @return
	 * @throws JsonProcessingException
	 */
	@Exclude
	@RequestMapping(value = "/send/init/check-data", method = RequestMethod.POST)
	@Description(describe = "流程发送前数据校验", instructions = "SendCommit:INIT", requestType = "post", requestUrl = "/ext/co/flow/send/init/check-data")
	public KqcoParm send_init_check_data(@RequestBody ObjectNode parameter) {
		String m_sTicket ="tiket-5c396f8c702840fd9ae6523f9a70dac4";
		KqcoApi kqcoApi = KqcoApiUtils.getKocoApi(m_sTicket);
		kqcoApi.m_sAddr="trace-eb3eb80039444d9c9e2f6cf60a5a90dd";
		ParmImpl kqcoParm = (ParmImpl)kqcoApi.getKqcoParm();

		// 参数检查
		if (kqcoParm.setRequest(parameter) != 0)
			return kqcoParm;

		//数据校验
		boolean flag = true;
		if(!flag){//数据校验异常提示
			kqcoParm.error(500,"数据有误,请检查!");
			return kqcoParm;
		}

		//获取参数
		JsonNode argsJson = parameter.get("args");
		//设置返回值
		kqcoParm.setParameter(argsJson);
		return kqcoParm;
	}
}

package com.kqgeo.co.ext.controller;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kqgeo.co.ext.config.Description;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ext/co/flow")
public class FlowDemo {

	/**
	 * 流程发送前数据校验
	 * @param parameter
	 * @return
	 * @throws JsonProcessingException
	 */
	@Exclude
	@RequestMapping(value = "/send/init/check-data", method = RequestMethod.POST)
	@Description(describe = "流程发送前数据校验", instructions = "SendCommit:INIT", requestType = "post", requestUrl = "/ext/co/flow/send/init/check-data")
	public KqcoParm send_init_check_data(@RequestBody ObjectNode parameter) {
		String m_sTicket ="tiket-5c396f8c702840fd9ae6523f9a70dac4";
		KqcoApi kqcoApi = KqcoApiUtils.getKocoApi(m_sTicket);
		kqcoApi.m_sAddr="trace-eb3eb80039444d9c9e2f6cf60a5a90dd";
		ParmImpl kqcoParm = (ParmImpl)kqcoApi.getKqcoParm();

		// 参数检查
		if (kqcoParm.setRequest(parameter) != 0)
			return kqcoParm;

		//数据校验
		boolean flag = true;
		if(!flag){//数据校验异常提示
			kqcoParm.error(500,"数据有误,请检查!");
			return kqcoParm;
		}

		//获取参数
		JsonNode argsJson = parameter.get("args");
		//设置返回值
		kqcoParm.setParameter(argsJson);
		return kqcoParm;
	}
}

效果展示

二开后效果: scene-flowsend-init-check-20240612103035

Powerd by Vitepress.