diff --git a/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticCallbackTestApi.java b/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticCallbackTestApi.java index 997f77f626bb6067181416c6c519e0558fe5d14e..1d1e40b839dd51b05195a8c001e9082d5756e7b6 100644 --- a/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticCallbackTestApi.java +++ b/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticCallbackTestApi.java @@ -15,11 +15,13 @@ along with this program. If not, see .*/ package neatlogic.module.process.api.processtask.automatic; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.ApiAnonymousAccessSupportEnum; import neatlogic.framework.restful.constvalue.OperationTypeEnum; -import neatlogic.framework.restful.core.publicapi.PublicApiComponentBase; -import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; /** @@ -28,7 +30,7 @@ import org.springframework.stereotype.Service; **/ @Service @OperationType(type = OperationTypeEnum.SEARCH) -public class ProcessTaskStepAutomaticCallbackTestApi extends PublicApiComponentBase { +public class ProcessTaskStepAutomaticCallbackTestApi extends PrivateApiComponentBase { @Override public String getToken() { @@ -51,20 +53,42 @@ public class ProcessTaskStepAutomaticCallbackTestApi extends PublicApiComponentB }) @Output({ @Param(name = "outputParam1", type = ApiParamType.STRING, desc = "出参1"), - @Param(name = "outputParam2", type = ApiParamType.LONG, desc = "出参2") + @Param(name = "outputParam2", type = ApiParamType.LONG, desc = "出参2"), + @Param(name = "error", type = ApiParamType.STRING, desc = "异常信息") }) - @Description(desc = "自动处理步骤请求测试接口") + @Description(desc = "自动处理步骤回调测试接口") @Override public Object myDoService(JSONObject paramObj) throws Exception { String inputParam1 = paramObj.getString("inputParam1"); Long inputParam2 = paramObj.getLong("inputParam2"); - //System.out.println("inputParam1=" + inputParam1); - //System.out.println("inputParam2=" + inputParam2); + System.out.println("inputParam1=" + inputParam1); + System.out.println("inputParam2=" + inputParam2); + StringBuilder stringBuilder = new StringBuilder(); + if (!inputParam1.contains("自动处理节点2")) { + stringBuilder.append("入参'inputParam1'内容不包含'自动处理节点2'"); + } + if (inputParam2 < 20000L) { + stringBuilder.append(" 入参'inputParam2'值小于'20000'"); + } String outputParam1 = inputParam1 + "-out"; Long outputParam2 = inputParam2 + 10; JSONObject output = new JSONObject(); output.put("outputParam1", outputParam1); output.put("outputParam2", outputParam2); + String error = stringBuilder.toString(); + if (StringUtils.isNotBlank(error)) { + output.put("error", error); + } return output; } + + /** + * 是否支持匿名访问 + * + * @return true false + */ + @Override + public ApiAnonymousAccessSupportEnum supportAnonymousAccess() { + return ApiAnonymousAccessSupportEnum.ANONYMOUS_ACCESS_WITHOUT_ENCRYPTION; + } } diff --git a/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticFirstRequestTestApi.java b/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticFirstRequestTestApi.java index 0bb7dba4510b998620eb90cd68e306043ab0ceb5..acf4a604440a47a1a91b8080657d96ce0d4cf8ef 100644 --- a/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticFirstRequestTestApi.java +++ b/src/main/java/neatlogic/module/process/api/processtask/automatic/ProcessTaskStepAutomaticFirstRequestTestApi.java @@ -15,11 +15,13 @@ along with this program. If not, see .*/ package neatlogic.module.process.api.processtask.automatic; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.ApiAnonymousAccessSupportEnum; import neatlogic.framework.restful.constvalue.OperationTypeEnum; -import neatlogic.framework.restful.core.publicapi.PublicApiComponentBase; -import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; /** @@ -28,7 +30,7 @@ import org.springframework.stereotype.Service; **/ @Service @OperationType(type = OperationTypeEnum.SEARCH) -public class ProcessTaskStepAutomaticFirstRequestTestApi extends PublicApiComponentBase { +public class ProcessTaskStepAutomaticFirstRequestTestApi extends PrivateApiComponentBase { @Override public String getToken() { @@ -51,20 +53,42 @@ public class ProcessTaskStepAutomaticFirstRequestTestApi extends PublicApiCompon }) @Output({ @Param(name = "outputParam1", type = ApiParamType.STRING, desc = "出参1"), - @Param(name = "outputParam2", type = ApiParamType.LONG, desc = "出参2") + @Param(name = "outputParam2", type = ApiParamType.LONG, desc = "出参2"), + @Param(name = "error", type = ApiParamType.STRING, desc = "异常信息") }) @Description(desc = "自动处理步骤请求测试接口") @Override public Object myDoService(JSONObject paramObj) throws Exception { String inputParam1 = paramObj.getString("inputParam1"); Long inputParam2 = paramObj.getLong("inputParam2"); - //System.out.println("inputParam1=" + inputParam1); - //System.out.println("inputParam2=" + inputParam2); + System.out.println("inputParam1=" + inputParam1); + System.out.println("inputParam2=" + inputParam2); + StringBuilder stringBuilder = new StringBuilder(); + if (!inputParam1.contains("自动处理节点")) { + stringBuilder.append("入参'inputParam1'内容不包含'自动处理节点'"); + } + if (inputParam2 < 10000L) { + stringBuilder.append(" 入参'inputParam2'值小于'10000'"); + } String outputParam1 = inputParam1 + "-out"; Long outputParam2 = inputParam2 + 10; JSONObject output = new JSONObject(); output.put("outputParam1", outputParam1); output.put("outputParam2", outputParam2); + String error = stringBuilder.toString(); + if (StringUtils.isNotBlank(error)) { + output.put("error", error); + } return output; } + + /** + * 是否支持匿名访问 + * + * @return true false + */ + @Override + public ApiAnonymousAccessSupportEnum supportAnonymousAccess() { + return ApiAnonymousAccessSupportEnum.ANONYMOUS_ACCESS_WITHOUT_ENCRYPTION; + } } diff --git a/src/main/java/neatlogic/module/process/condition/handler/ProcessTaskFormAttributeCondition.java b/src/main/java/neatlogic/module/process/condition/handler/ProcessTaskFormAttributeCondition.java index 6266e3d58087c47bd604deb1a65a525b8aab1357..70bdd40824b82d38b2e467b510da1633f4fc938b 100644 --- a/src/main/java/neatlogic/module/process/condition/handler/ProcessTaskFormAttributeCondition.java +++ b/src/main/java/neatlogic/module/process/condition/handler/ProcessTaskFormAttributeCondition.java @@ -29,7 +29,6 @@ import neatlogic.framework.form.constvalue.FormConditionModel; import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.form.dto.AttributeDataVo; import neatlogic.framework.form.dto.FormAttributeVo; -import neatlogic.framework.form.dto.FormVersionVo; import neatlogic.framework.fulltextindex.utils.FullTextIndexUtil; import neatlogic.framework.process.condition.core.IProcessTaskCondition; import neatlogic.framework.process.condition.core.ProcessTaskConditionBase; @@ -97,54 +96,41 @@ public class ProcessTaskFormAttributeCondition extends ProcessTaskConditionBase @Override public Object valueConversionText(Object value, JSONObject config) { if (MapUtils.isNotEmpty(config)) { - //表单属性的uuid - String attributeUuid = config.getString("attributeUuid"); - //对应表单版本的form_config字段 - JSONObject formConfig = config.getJSONObject("formConfig"); - FormVersionVo formVersionVo = new FormVersionVo(); - formVersionVo.setFormConfig(formConfig); - List formAttributeList = formVersionVo.getFormAttributeList(); - if (CollectionUtils.isNotEmpty(formAttributeList)) { - for (FormAttributeVo formAttribute : formAttributeList) { - if (Objects.equals(attributeUuid, formAttribute.getUuid())) { - config.put("name", formAttribute.getLabel()); - if (value != null) { - IFormAttributeDataConversionHandler formAttributeHandler = - FormAttributeDataConversionHandlerFactory.getHandler(formAttribute.getHandler()); - if (formAttributeHandler != null) { - if (Objects.equals(formAttribute.getHandler(), FormHandler.FORMDATE.getHandler()) - || Objects.equals(formAttribute.getHandler(), FormHandler.FORMTIME.getHandler())) { - if (value instanceof String) { - return value; - } else if (value instanceof JSONArray) { - List textList = ((JSONArray) value).toJavaList(String.class); - return String.join("-", textList); - } - } else { - AttributeDataVo attributeDataVo = new AttributeDataVo(); - attributeDataVo.setAttributeUuid(attributeUuid); - attributeDataVo.setHandler(formAttribute.getHandler()); - if (value instanceof String) { - attributeDataVo.setData((String) value); - } else if (value instanceof JSONArray) { - attributeDataVo.setData(JSON.toJSONString(value)); - } + FormAttributeVo formAttribute = config.getObject("formAttribute", FormAttributeVo.class); + if (value != null) { + IFormAttributeDataConversionHandler formAttributeHandler = + FormAttributeDataConversionHandlerFactory.getHandler(formAttribute.getHandler()); + if (formAttributeHandler != null) { + if (Objects.equals(formAttribute.getHandler(), FormHandler.FORMDATE.getHandler()) + || Objects.equals(formAttribute.getHandler(), FormHandler.FORMTIME.getHandler())) { + if (value instanceof String) { + return value; + } else if (value instanceof JSONArray) { + List textList = ((JSONArray) value).toJavaList(String.class); + return String.join("-", textList); + } + } else { + AttributeDataVo attributeDataVo = new AttributeDataVo(); + attributeDataVo.setAttributeUuid(formAttribute.getUuid()); + attributeDataVo.setHandler(formAttribute.getHandler()); + if (value instanceof String) { + attributeDataVo.setData((String) value); + } else if (value instanceof JSONArray) { + attributeDataVo.setData(JSON.toJSONString(value)); + } - Object text = formAttributeHandler.valueConversionText(attributeDataVo, formAttribute.getConfig()); - if (text instanceof String) { - return text; - } else if (text instanceof List) { - List textList = JSON.parseArray(JSON.toJSONString(text), String.class); - if (FormHandler.FORMCASCADER.getHandler().equals(formAttribute.getHandler())) { - return String.join("/", textList); - } else { - return String.join("、", textList); - } - } - return text; - } + Object text = formAttributeHandler.valueConversionText(attributeDataVo, formAttribute.getConfig()); + if (text instanceof String) { + return text; + } else if (text instanceof List) { + List textList = JSON.parseArray(JSON.toJSONString(text), String.class); + if (FormHandler.FORMCASCADER.getHandler().equals(formAttribute.getHandler())) { + return String.join("/", textList); + } else { + return String.join("、", textList); } } + return text; } } } diff --git a/src/main/java/neatlogic/module/process/service/ProcessTaskAutomaticServiceImpl.java b/src/main/java/neatlogic/module/process/service/ProcessTaskAutomaticServiceImpl.java index c1b9274c97fd9f0b48823f93eccc89e299a2748b..5709b46ba090c470e21e4de9c8f4af6c1fb2634f 100644 --- a/src/main/java/neatlogic/module/process/service/ProcessTaskAutomaticServiceImpl.java +++ b/src/main/java/neatlogic/module/process/service/ProcessTaskAutomaticServiceImpl.java @@ -390,18 +390,20 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ // } } } - if (resultValue != null) { - List currentValueList = new ArrayList<>(); + List currentValueList = new ArrayList<>(); + if (StringUtils.isNotBlank(resultValue)) { currentValueList.add(resultValue); - String value = config.getString("value"); - List targetValueList = new ArrayList<>(); + } + List targetValueList = new ArrayList<>(); + String value = config.getString("value"); + if (StringUtils.isNotBlank(value)) { targetValueList.add(value); - String expression = config.getString("expression"); - try { - result = ConditionUtil.predicate(currentValueList, expression, targetValueList); - } catch (Exception e) { - logger.warn(e.getMessage(), e); - } + } + String expression = config.getString("expression"); + try { + result = ConditionUtil.predicate(currentValueList, expression, targetValueList); + } catch (Exception e) { + logger.warn(e.getMessage(), e); } } } @@ -447,7 +449,8 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ requestAudit.put("endTime", System.currentTimeMillis()); JSONObject auditResult = new JSONObject(); auditResult.put("json", resultJson); - auditResult.put("template", FreemarkerUtil.transform(JSON.parse(resultJson), template)); + String templateResult = FreemarkerUtil.transform(JSON.parse(resultJson), template); + auditResult.put("template", templateResult); requestAudit.put("result", auditResult); if (predicate(successConfig, resultVo, true)) {// 如果执行成功 @@ -504,13 +507,25 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ failedReason = integrationVo.getUrl() + "\n" + resultVo.getError(); } else { if (MapUtils.isNotEmpty(successConfig)) { - if (StringUtils.isBlank(successConfig.getString("name"))) { + String name = successConfig.getString("name"); + if (StringUtils.isBlank(name)) { failedReason = "-"; } else { - failedReason = String.format("不满足成功条件:%s%s%s", successConfig.getString("name"), successConfig.getString("expressionName"), successConfig.getString("value")); + String expressionName = successConfig.getString("expressionName"); + if (expressionName == null) { + expressionName = StringUtils.EMPTY; + } + String value = successConfig.getString("value"); + if (value == null) { + value = StringUtils.EMPTY; + } + failedReason = String.format("不满足成功条件:%s%s%s", name, expressionName, value); } } } + if (StringUtils.isNotBlank(templateResult)) { + failedReason = failedReason + "\n" + templateResult; + } requestAudit.put("failedReason", failedReason); failPolicy(automaticConfigVo, currentProcessTaskStepVo, failedReason, data); auditDataVo.setData(data.toJSONString()); @@ -591,7 +606,8 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ callbackAudit.put("endTime", System.currentTimeMillis()); JSONObject auditResult = new JSONObject(); auditResult.put("json", resultJson); - auditResult.put("template", FreemarkerUtil.transform(JSON.parse(resultJson), template)); + String templateResult = FreemarkerUtil.transform(JSON.parse(resultJson), template); + auditResult.put("template", templateResult); callbackAudit.put("result", auditResult); if (predicate(successConfig, resultVo, true)) {// 如果执行成功 @@ -616,13 +632,25 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ failedReason = integrationVo.getUrl() + "\n" + resultVo.getError(); } else { if (MapUtils.isNotEmpty(failConfig)) { - if (StringUtils.isBlank(failConfig.getString("name"))) { + String name = failConfig.getString("name"); + if (StringUtils.isBlank(name)) { failedReason = "-"; } else { - failedReason = String.format("满足失败条件:%s%s%s", failConfig.getString("name"), failConfig.getString("expressionName"), failConfig.getString("value")); + String expressionName = failConfig.getString("expressionName"); + if (expressionName == null) { + expressionName = StringUtils.EMPTY; + } + String value = failConfig.getString("value"); + if (value == null) { + value = StringUtils.EMPTY; + } + failedReason = String.format("满足失败条件:%s%s%s", name, expressionName, value); } } } + if (StringUtils.isNotBlank(templateResult)) { + failedReason = failedReason + "\n" + templateResult; + } callbackAudit.put("failedReason", failedReason); failPolicy(automaticConfigVo, currentProcessTaskStepVo, failedReason, data); isUnloadJob = true; @@ -730,6 +758,7 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ if (backStepList.size() == 1) { ProcessTaskStepVo nextProcessTaskStepVo = backStepList.get(0); if (processHandler != null) { + processStepHandlerUtil.saveStepRemind(currentProcessTaskStepVo, nextProcessTaskStepVo.getId(), failedReason, ProcessTaskStepRemindType.AUTOMATIC_ERROR); JSONObject jsonParam = currentProcessTaskStepVo.getParamObj(); jsonParam.put("action", ProcessTaskOperationType.STEP_BACK.getValue()); jsonParam.put("nextStepId", nextProcessTaskStepVo.getId()); @@ -741,6 +770,7 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ } else if (FailPolicy.KEEP_ON.getValue().equals(automaticConfigVo.getBaseFailPolicy())) { //补充下一步骤id List nextStepIdList = processTaskMapper.getToProcessTaskStepIdListByFromIdAndType(currentProcessTaskStepVo.getId(), ProcessFlowDirection.FORWARD.getValue()); + processStepHandlerUtil.saveStepRemind(currentProcessTaskStepVo, nextStepIdList.get(0), failedReason, ProcessTaskStepRemindType.AUTOMATIC_ERROR); // currentProcessTaskStepVo.getParamObj().put("nextStepId", nextStepIdList.get(0)); JSONObject jsonParam = currentProcessTaskStepVo.getParamObj(); jsonParam.put("action", ProcessTaskOperationType.STEP_COMPLETE.getValue()); @@ -751,6 +781,9 @@ public class ProcessTaskAutomaticServiceImpl implements ProcessTaskAutomaticServ ProcessTaskVo processTaskVo = new ProcessTaskVo(currentProcessTaskStepVo.getProcessTaskId()); processTaskVo.getParamObj().put(ProcessTaskAuditDetailType.AUTOMATICINFO.getParamName(), automaticInfo); processHandler.abortProcessTask(processTaskVo); + } else { + // 人工处理 + processStepHandlerUtil.saveStepRemind(currentProcessTaskStepVo, currentProcessTaskStepVo.getId(), failedReason, ProcessTaskStepRemindType.AUTOMATIC_ERROR); } } } diff --git a/src/main/java/neatlogic/module/process/stephandler/component/ConditionProcessComponent.java b/src/main/java/neatlogic/module/process/stephandler/component/ConditionProcessComponent.java index 0eb5319d52fb6d3dac91945aa573c0c93034f760..1d2a036a8d3dee6277cf5628c0b192a526af3a7f 100644 --- a/src/main/java/neatlogic/module/process/stephandler/component/ConditionProcessComponent.java +++ b/src/main/java/neatlogic/module/process/stephandler/component/ConditionProcessComponent.java @@ -20,8 +20,13 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONPath; import neatlogic.framework.asynchronization.threadlocal.ConditionParamContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; +import neatlogic.framework.common.constvalue.Expression; import neatlogic.framework.common.constvalue.SystemUser; +import neatlogic.framework.condition.core.IConditionHandler; import neatlogic.framework.dto.condition.ConditionConfigVo; +import neatlogic.framework.dto.condition.ConditionGroupVo; +import neatlogic.framework.dto.condition.ConditionVo; +import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.process.condition.core.ProcessTaskConditionFactory; import neatlogic.framework.process.constvalue.*; import neatlogic.framework.process.dto.ProcessTaskStepRelVo; @@ -35,6 +40,7 @@ import neatlogic.framework.util.javascript.JavascriptUtil; import neatlogic.module.process.dao.mapper.SelectContentByHashMapper; import neatlogic.module.process.dao.mapper.processtask.ProcessTaskMapper; import neatlogic.module.process.service.IProcessStepHandlerUtil; +import neatlogic.module.process.service.ProcessTaskService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -58,6 +64,9 @@ public class ConditionProcessComponent extends ProcessStepHandlerBase { @Resource private ProcessTaskMapper processTaskMapper; + @Resource + private ProcessTaskService processTaskService; + @Resource private SelectContentByHashMapper selectContentByHashMapper; @@ -150,6 +159,8 @@ public class ConditionProcessComponent extends ProcessStepHandlerBase { ConditionParamContext.init(conditionParamData).setTranslate(true); conditionConfigVo = new ConditionConfigVo(moveonConfig); String script = conditionConfigVo.buildScript(); + /* 将参数名称、表达式、值的value翻译成对应text,目前条件步骤生成活动时用到**/ + translate(conditionConfigVo, currentProcessTaskStepVo.getProcessTaskId()); // ((false || true) || (true && false) || (true || false)) canRun = RunScriptUtil.runScript(script); ruleObj.put("result", canRun); @@ -197,6 +208,44 @@ public class ConditionProcessComponent extends ProcessStepHandlerBase { } } + private void translate(ConditionConfigVo conditionConfigVo, Long processTaskId) { + List conditionGroupList = conditionConfigVo.getConditionGroupList(); + if (CollectionUtils.isNotEmpty(conditionGroupList)) { + List formAttributeList = processTaskService.getFormAttributeListByProcessTaskIdAngTag(processTaskId, ConditionProcessComponent.FORM_EXTEND_ATTRIBUTE_TAG); + Map formAttributeVoMap = formAttributeList.stream().collect(Collectors.toMap(FormAttributeVo::getUuid, e -> e)); + for (ConditionGroupVo conditionGroup : conditionGroupList) { + List conditionList = conditionGroup.getConditionList(); + if (CollectionUtils.isNotEmpty(conditionList)) { + for (ConditionVo condition : conditionList) { + if ("common".equals(condition.getType())) { + IConditionHandler conditionHandler = ProcessTaskConditionFactory.getHandler(condition.getName()); + if (conditionHandler != null) { + Object valueList = conditionHandler.valueConversionText(condition.getValueList(), null); + condition.setValueList(valueList); + String name = conditionHandler.getDisplayName(); + condition.setName(name); + } + } else if ("form".equals(condition.getType())) { + IConditionHandler conditionHandler = ProcessTaskConditionFactory.getHandler("form"); + if (conditionHandler != null) { + FormAttributeVo formAttribute = formAttributeVoMap.get(condition.getName()); + if (formAttribute != null) { + JSONObject configObj = new JSONObject(); + configObj.put("formAttribute", formAttribute); + Object valueList = conditionHandler.valueConversionText(condition.getValueList(), configObj); + condition.setValueList(valueList); + condition.setName(formAttribute.getLabel()); + } + } + } + String expressionName = Expression.getExpressionName(condition.getExpression()); + condition.setExpression(expressionName); + } + } + } + } + } + @Override protected int myRedo(ProcessTaskStepVo currentProcessTaskStepVo) { return 0;