数据集参数管理高级规则支持返回自定义内容

Raod 3 years ago
parent 28771b8283
commit 616e553554

@ -226,11 +226,13 @@ public class DataSetServiceImpl implements DataSetService {
DataSource dataSource = dataSourceService.selectOne("source_code", dataSetDto.getSourceCode()); DataSource dataSource = dataSourceService.selectOne("source_code", dataSetDto.getSourceCode());
//3.参数替换 //3.参数替换
//3.1参数校验 //3.1参数校验
log.debug("参数校验替换前:{}", dto.getContextData());
boolean verification = dataSetParamService.verification(dataSetDto.getDataSetParamDtoList(), dto.getContextData()); boolean verification = dataSetParamService.verification(dataSetDto.getDataSetParamDtoList(), dto.getContextData());
if (!verification) { if (!verification) {
throw BusinessExceptionBuilder.build(ResponseCode.RULE_FIELDS_CHECK_ERROR); throw BusinessExceptionBuilder.build(ResponseCode.RULE_FIELDS_CHECK_ERROR);
} }
String dynSentence = dataSetParamService.transform(dto.getContextData(), dataSetDto.getDynSentence()); String dynSentence = dataSetParamService.transform(dto.getContextData(), dataSetDto.getDynSentence());
log.debug("参数校验替换后:{}", dto.getContextData());
//4.获取数据 //4.获取数据
DataSourceDto dataSourceDto = new DataSourceDto(); DataSourceDto dataSourceDto = new DataSourceDto();
BeanUtils.copyProperties(dataSource, dataSourceDto); BeanUtils.copyProperties(dataSource, dataSourceDto);

@ -39,7 +39,7 @@ public interface DataSetParamService extends GaeaBaseService<DataSetParamParam,
* @param dataSetParamDto * @param dataSetParamDto
* @return * @return
*/ */
boolean verification(DataSetParamDto dataSetParamDto); Object verification(DataSetParamDto dataSetParamDto);
/** /**
* js * js

@ -93,7 +93,7 @@ public class DataSetParamServiceImpl implements DataSetParamService {
* @return * @return
*/ */
@Override @Override
public boolean verification(DataSetParamDto dataSetParamDto) { public Object verification(DataSetParamDto dataSetParamDto) {
String validationRules = dataSetParamDto.getValidationRules(); String validationRules = dataSetParamDto.getValidationRules();
if (StringUtils.isNotBlank(validationRules)) { if (StringUtils.isNotBlank(validationRules)) {
@ -103,7 +103,12 @@ public class DataSetParamServiceImpl implements DataSetParamService {
Invocable invocable = (Invocable) engine; Invocable invocable = (Invocable) engine;
Object exec = invocable.invokeFunction("verification", dataSetParamDto); Object exec = invocable.invokeFunction("verification", dataSetParamDto);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
if (exec instanceof Boolean) {
return objectMapper.convertValue(exec, Boolean.class); return objectMapper.convertValue(exec, Boolean.class);
}else {
return objectMapper.convertValue(exec, String.class);
}
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -131,9 +136,20 @@ public class DataSetParamServiceImpl implements DataSetParamService {
String value = contextData.getOrDefault(dataSetParamDto.getParamName(), "").toString(); String value = contextData.getOrDefault(dataSetParamDto.getParamName(), "").toString();
dataSetParamDto.setSampleItem(value); dataSetParamDto.setSampleItem(value);
} }
if (!verification(dataSetParamDto)) {
Object verification = verification(dataSetParamDto);
if (verification instanceof Boolean) {
if (!(Boolean) verification) {
return false; return false;
} }
}else {
//将得到的值重新赋值给contextData
if (null != contextData) {
contextData.put(dataSetParamDto.getParamName(), verification);
}
dataSetParamDto.setSampleItem(verification.toString());
}
} }
return true; return true;
} }

@ -450,7 +450,7 @@ export default {
itemFilterList: [ itemFilterList: [
{ {
transformType: "js", transformType: "js",
transformScript: `function dataTransform(data){\n\t//自定义脚本内容\n\treturn data;\n}` transformScript: ``
} }
], ],
transformScript: `function dataTransform(data){\n\t//自定义脚本内容\n\treturn data;\n}`, transformScript: `function dataTransform(data){\n\t//自定义脚本内容\n\treturn data;\n}`,
@ -491,7 +491,7 @@ export default {
sampleItem: "", sampleItem: "",
mandatory: true, mandatory: true,
requiredFlag: 1, requiredFlag: 1,
validationRules: `function verification(data){\n\t//自定义脚本内容\n\treturn true;\n}` validationRules: `function verification(data){\n\t//自定义脚本内容\n\t//可返回true/false单纯校验键入的data正确性\n\t//可返回文本,实时替换,比如当前时间等\n\t//return "2099-01-01 00:00:00";\n\treturn true;\n}`
} }
], ],
isRowData: {}, isRowData: {},
@ -764,7 +764,7 @@ export default {
this.title = "自定义高级规则"; this.title = "自定义高级规则";
if (this.isRowData.sampleItem != "") { if (this.isRowData.sampleItem != "") {
this.isRowData = row; this.isRowData = row;
const fnCont = `function verification(data){\n\t//自定义脚本内容\n\treturn true;\n}`; const fnCont = `function verification(data){\n\t//自定义脚本内容\n\t//可返回true/false单纯校验键入的data正确性\n\t//可返回文本,实时替换,比如当前时间等\n\t//return "2099-01-01 00:00:00";\n\treturn true;\n}`;
this.validationRules = row.validationRules this.validationRules = row.validationRules
? row.validationRules ? row.validationRules
: fnCont; : fnCont;
@ -801,10 +801,11 @@ export default {
// //
async testResultset() { async testResultset() {
this.isRowData.validationRules = this.validationRules; this.isRowData.validationRules = this.validationRules;
console.log(this.isRowData,"12345678")
const { code, message, data } = await verificationSet(this.isRowData); const { code, message, data } = await verificationSet(this.isRowData);
if (code == "200") { if (code == "200") {
if (data) { if (data) {
this.$message.success("校验通过"); this.$message.success("返回结果:"+ data);
} else { } else {
this.$message.warning("当前示例值校验不通过"); this.$message.warning("当前示例值校验不通过");
} }
@ -825,7 +826,7 @@ export default {
sampleItem: "", sampleItem: "",
mandatory: true, mandatory: true,
requiredFlag: 1, requiredFlag: 1,
validationRules: `function verification(data){\n\t//自定义脚本内容\n\treturn true;\n}` validationRules: `function verification(data){\n\t//自定义脚本内容\n\t//可返回true/false单纯校验键入的data正确性\n\t//可返回文本,实时替换,比如当前时间等\n\t//return "2099-01-01 00:00:00";\n\treturn true;\n}`
}); });
}, },
async submit(formName) { async submit(formName) {

Loading…
Cancel
Save