feat(REQ-3769) - 处理流程创建后,和完成后的关联启用的文档模板变量替换逻辑
This commit is contained in:
parent
8bd381eccc
commit
7d8342710c
@ -27,6 +27,7 @@ public enum BpmnModelRespCode implements IModuleRespCode {
|
||||
MODEL_FILE_CONTENT_DATA_ERROR("012", "文档内容数据异常"),
|
||||
MODEL_FILE_QUERY_ERROR("013", "文档搜索参数实例 ID 和业务 ID 不能同时为空"),
|
||||
MODEL_FILE_HIPRINT_ID_INVAILD("014", "查询HiPrint文档主键参数非法"),
|
||||
MODEL_FILE_REPLACE_CONTENT_ERROR("015", "替换文档变量失败,原因:【{}】"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@ -42,4 +42,9 @@ public class SignFileDTO implements Serializable {
|
||||
* 文件的类型
|
||||
*/
|
||||
private FileTypeEnum fileType;
|
||||
|
||||
/**
|
||||
* 替换变量后的文件 fileKey
|
||||
*/
|
||||
private String fileKey;
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package cn.axzo.workflow.common.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 从流程实例中获取变量,携带数据类型的对象
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2025-04-09 11:46
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class VariableObjectDTO {
|
||||
|
||||
public enum Type {
|
||||
img, text, obj, coll
|
||||
}
|
||||
|
||||
/**
|
||||
* 变量 key
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 变量值
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* 变量类型
|
||||
*/
|
||||
@Builder.Default
|
||||
private Type type = Type.text;
|
||||
}
|
||||
@ -31,13 +31,6 @@ public class ApproverReadStatusDTO {
|
||||
@NotBlank(message = "流程实例 ID 不能为空")
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 任务 ID
|
||||
* 内部使用,前端不关心
|
||||
*/
|
||||
@ApiModelProperty(value = "任务 ID")
|
||||
private String taskId;
|
||||
|
||||
/**
|
||||
* 访问人
|
||||
*/
|
||||
|
||||
@ -22,13 +22,20 @@ import static cn.axzo.workflow.common.code.FormInstanceRespCode.FORM_INSTANCE_DA
|
||||
*/
|
||||
public class CustomGetFormInstanceLatestValuesCmd extends GetFormInstanceValuesCmd {
|
||||
private String processInstanceId;
|
||||
private Boolean throwException;
|
||||
|
||||
public CustomGetFormInstanceLatestValuesCmd(String processInstanceId) {
|
||||
this (null, processInstanceId);
|
||||
this(null, processInstanceId, true);
|
||||
}
|
||||
public CustomGetFormInstanceLatestValuesCmd(String formInstanceId, String processInstanceId) {
|
||||
|
||||
public CustomGetFormInstanceLatestValuesCmd(String processInstanceId, Boolean throwException) {
|
||||
this(processInstanceId, null, throwException);
|
||||
}
|
||||
|
||||
public CustomGetFormInstanceLatestValuesCmd(String formInstanceId, String processInstanceId, Boolean throwException) {
|
||||
super(formInstanceId);
|
||||
this.processInstanceId = processInstanceId;
|
||||
this.throwException = throwException;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,6 +50,10 @@ public class CustomGetFormInstanceLatestValuesCmd extends GetFormInstanceValuesC
|
||||
if (!CollectionUtils.isEmpty(formInstances)) {
|
||||
return formInstances.get(0).getFormValueBytes();
|
||||
}
|
||||
throw new WorkflowEngineException(FORM_INSTANCE_DATA_NOT_FOUND, processInstanceId);
|
||||
if (throwException) {
|
||||
throw new WorkflowEngineException(FORM_INSTANCE_DATA_NOT_FOUND, processInstanceId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public class CustomGetProcessInstanceVariablesCmd extends AbstractCommand<Map<St
|
||||
private void addProcessDefinitionKey(Map<String, Object> variables, HistoricProcessInstance historicProcessInstance) {
|
||||
CategoryService categoryService = SpringContextUtils.getBean(CategoryService.class);
|
||||
categoryService.get(BPM_MODEL_CATEGORY, historicProcessInstance.getProcessDefinitionKey()).ifPresent(category -> {
|
||||
variables.put(PRINT_VAR_PROCESS_DEFINITION_KEY, category.getValue());
|
||||
variables.put(PRINT_VAR_PROCESS_DEFINITION_KEY, category.getLabel() + "(" + category.getValue() + ")");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,239 @@
|
||||
package cn.axzo.workflow.core.engine.cmd;
|
||||
|
||||
import cn.axzo.workflow.common.enums.VarTypeEnum;
|
||||
import cn.axzo.workflow.common.exception.WorkflowEngineException;
|
||||
import cn.axzo.workflow.common.model.dto.SignatureDTO;
|
||||
import cn.axzo.workflow.common.model.dto.VariableObjectDTO;
|
||||
import cn.axzo.workflow.common.model.request.category.CategoryGroupVarSearchDto;
|
||||
import cn.axzo.workflow.common.model.response.category.CategoryGroupVarItemVo;
|
||||
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
|
||||
import cn.axzo.workflow.core.common.utils.SpringContextUtils;
|
||||
import cn.axzo.workflow.core.service.CategoryGroupService;
|
||||
import cn.axzo.workflow.core.service.CategoryService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.flowable.engine.impl.util.CommandContextUtil;
|
||||
import org.flowable.form.api.FormInfo;
|
||||
import org.flowable.form.api.FormRepositoryService;
|
||||
import org.flowable.form.model.FormContainer;
|
||||
import org.flowable.form.model.FormField;
|
||||
import org.flowable.form.model.SimpleFormModel;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.workflow.common.code.FormModelRespCode.FORM_MODEL_NOT_EXISTS;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.BPM_MODEL_CATEGORY;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.SIGNATURE_COLLECTION;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.SIGN_VARIABLE;
|
||||
import static cn.axzo.workflow.common.constant.VariableConstants.PRINT_VAR_PROCESS_DEFINITION_KEY;
|
||||
import static cn.axzo.workflow.common.constant.VariableConstants.PRINT_VAR_PROCESS_INITIATOR;
|
||||
import static cn.axzo.workflow.common.constant.VariableConstants.PRINT_VAR_PROCESS_INSTANCE_ID;
|
||||
import static cn.axzo.workflow.common.constant.VariableConstants.PRINT_VAR_PROCESS_START_TIME;
|
||||
import static cn.axzo.workflow.common.enums.BpmnFlowNodeType.NODE_STARTER;
|
||||
|
||||
/**
|
||||
* 自定义获取流程实例中的变量命令实现
|
||||
* <p>
|
||||
* 返回的变量包括如下:
|
||||
* 1、业务名称、审批编号、发起事件、发起人对象信息、节点签名和意见
|
||||
* 2、业务管理中的变量
|
||||
* 3、表单中变量
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2025-01-21 11:47
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractCommand<List<VariableObjectDTO>> implements Serializable {
|
||||
|
||||
private final String processInstanceId;
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
|
||||
private static final List<String> SUPPORTED_FORM_TYPES = Lists.newArrayList("input", "textarea", "image");
|
||||
|
||||
public CustomGetProcessInstanceVariablesToObjectCmd(String processInstanceId) {
|
||||
this.processInstanceId = processInstanceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramToJsonString() {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("processInstanceId", processInstanceId);
|
||||
return JSON.toJSONString(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VariableObjectDTO> executeInternal(CommandContext commandContext) {
|
||||
List<VariableObjectDTO> variables = new ArrayList<>();
|
||||
if (!StringUtils.hasText(processInstanceId)) {
|
||||
return variables;
|
||||
}
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(PRINT_VAR_PROCESS_INSTANCE_ID)
|
||||
.value(processInstanceId)
|
||||
.build());
|
||||
|
||||
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||
HistoryService historyService = processEngineConfiguration.getHistoryService();
|
||||
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
|
||||
.processInstanceId(processInstanceId).includeProcessVariables().singleResult();
|
||||
// 添加流程开始时间
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(PRINT_VAR_PROCESS_START_TIME)
|
||||
.value(sdf.format(historicProcessInstance.getStartTime()))
|
||||
.build());
|
||||
|
||||
Map<String, Object> processVariables = historicProcessInstance.getProcessVariables();
|
||||
// 添加流程业务 ID 和业务下分组变量信息
|
||||
addProcessDefinitionKeyAndVariables(variables, (Map<String, Object>) processVariables.getOrDefault(SIGN_VARIABLE, new HashMap<String, Object>()), historicProcessInstance);
|
||||
|
||||
// 发起人流程引擎内部模型,需要外部调用该命令时,再解析; 当前命令所在 module 不支持调用二方接口
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(PRINT_VAR_PROCESS_INITIATOR)
|
||||
.value(processVariables.get(INTERNAL_INITIATOR))
|
||||
.type(VariableObjectDTO.Type.obj)
|
||||
.build());
|
||||
|
||||
// 电子签名
|
||||
addSignature(variables, (List<SignatureDTO>) processVariables.get(SIGNATURE_COLLECTION));
|
||||
|
||||
// 表单中的变量
|
||||
addFormFieldValue(commandContext, historicProcessInstance, variables);
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
private void addFormFieldValue(CommandContext commandContext, HistoricProcessInstance instance, List<VariableObjectDTO> variables) {
|
||||
Map<String, Object> formFieldValues = new HashMap<>();
|
||||
byte[] formInstanceValue = commandContext.getCommandExecutor().execute(new CustomGetFormInstanceLatestValuesCmd(processInstanceId, false));
|
||||
if (!ObjectUtils.isEmpty(formInstanceValue)) {
|
||||
JSONObject treeNode = JSON.parseObject(new String(formInstanceValue));
|
||||
formFieldValues.putAll(treeNode.getJSONObject("values").getInnerMap());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(formFieldValues)) {
|
||||
return;
|
||||
}
|
||||
|
||||
FormRepositoryService formRepositoryService = CommandContextUtil.getFormRepositoryService(commandContext);
|
||||
FormInfo formModel;
|
||||
try {
|
||||
formModel = formRepositoryService.getFormModelByKey(instance.getProcessDefinitionKey(), instance.getTenantId(), true);
|
||||
} catch (FlowableObjectNotFoundException e) {
|
||||
log.warn("can't found form model");
|
||||
throw new WorkflowEngineException(FORM_MODEL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
List<FormField> formFields = ((SimpleFormModel) formModel.getFormModel()).getFields();
|
||||
|
||||
formFields.forEach(formField -> {
|
||||
FormContainer formContainer = (FormContainer) formField;
|
||||
formContainer.getFields().get(0).forEach(field -> {
|
||||
if (!(field instanceof FormContainer) && SUPPORTED_FORM_TYPES.contains(field.getType())) {
|
||||
Object fieldValue = formFieldValues.getOrDefault(field.getId(), null);
|
||||
if (Objects.nonNull(fieldValue)) {
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(field.getId())
|
||||
.value(fieldValue)
|
||||
.type(convert(field.getType()))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void addSignature(List<VariableObjectDTO> variables, List<SignatureDTO> signatures) {
|
||||
if (CollectionUtils.isEmpty(signatures)) {
|
||||
return;
|
||||
}
|
||||
signatures.forEach(sign -> {
|
||||
if (!Objects.equals(NODE_STARTER.getType(), sign.getActivityId())) {
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(sign.getActivityId())
|
||||
.value(sign.getSignatures())
|
||||
.type(VariableObjectDTO.Type.coll)
|
||||
.build());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addProcessDefinitionKeyAndVariables(List<VariableObjectDTO> variables, Map<String, Object> bizVariables, HistoricProcessInstance historicProcessInstance) {
|
||||
CategoryService categoryService = SpringContextUtils.getBean(CategoryService.class);
|
||||
categoryService.get(BPM_MODEL_CATEGORY, historicProcessInstance.getProcessDefinitionKey()).ifPresent(category -> {
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(PRINT_VAR_PROCESS_DEFINITION_KEY)
|
||||
.value(category.getLabel() + "(" + category.getValue() + ")")
|
||||
.build());
|
||||
// 添加业务下的变量
|
||||
addVariables(variables, category, bizVariables);
|
||||
});
|
||||
}
|
||||
|
||||
private void addVariables(List<VariableObjectDTO> variables, CategoryItemVO category, Map<String, Object> bizVariables) {
|
||||
CategoryGroupService categoryServiceGroup = SpringContextUtils.getBean(CategoryGroupService.class);
|
||||
List<CategoryGroupVarItemVo> groupVariables = categoryServiceGroup.searchGroupAndVarList(CategoryGroupVarSearchDto.builder()
|
||||
.dictId(category.getId())
|
||||
.category(category.getValue())
|
||||
.build());
|
||||
|
||||
groupVariables.forEach(group -> {
|
||||
if (!CollectionUtils.isEmpty(group.getVars())) {
|
||||
group.getVars().forEach(variable -> {
|
||||
Object value = bizVariables.getOrDefault(variable.getCode(), null);
|
||||
if (Objects.isNull(value)) {
|
||||
// 目前为了减少 wps 替换耗时,所以将没有值的变量,直接踢出
|
||||
return;
|
||||
}
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(variable.getCode())
|
||||
.value(value)
|
||||
.type(convert(variable.getType()))
|
||||
.build());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private VariableObjectDTO.Type convert(VarTypeEnum varType) {
|
||||
switch (varType) {
|
||||
case TEXT:
|
||||
return VariableObjectDTO.Type.text;
|
||||
case PICTURE:
|
||||
return VariableObjectDTO.Type.img;
|
||||
default:
|
||||
return VariableObjectDTO.Type.obj;
|
||||
}
|
||||
}
|
||||
|
||||
private VariableObjectDTO.Type convert(String type) {
|
||||
switch (type) {
|
||||
case "text":
|
||||
case "textarea":
|
||||
return VariableObjectDTO.Type.text;
|
||||
case "image":
|
||||
return VariableObjectDTO.Type.img;
|
||||
default:
|
||||
return VariableObjectDTO.Type.obj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1735,10 +1735,14 @@ public class BpmnProcessInstanceServiceImpl implements BpmnProcessInstanceServic
|
||||
List<DocBaseVO> docs = commandExecutor.execute(new CustomGetModelDocsCmd(dto.getProcessInstanceId(), true, extAxModelDocMapper));
|
||||
|
||||
ExtAxProcessSign processSign = extAxProcessSignService.findByProcessInstanceId(dto.getProcessInstanceId());
|
||||
Map<Long, String> archiveFileMap = processSign.getFileArchive().stream().collect(Collectors.toMap(SignFileDTO::getId, SignFileDTO::getFileCode));
|
||||
Map<Long, SignFileDTO> archiveFileMap = processSign.getFileArchive().stream().collect(Collectors.toMap(SignFileDTO::getId, Function.identity()));
|
||||
|
||||
return BeanMapper.copyList(docs, DocPendingVO.class, (s, t) -> {
|
||||
t.setFileRelationId(archiveFileMap.getOrDefault(t.getId(), ""));
|
||||
SignFileDTO archive = archiveFileMap.getOrDefault(t.getId(), null);
|
||||
if (Objects.nonNull(archive)) {
|
||||
t.setFileRelationId(archive.getFileCode());
|
||||
t.setFileKey(archive.getFileKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.workflow.server.controller.listener.process;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
|
||||
import cn.axzo.maokai.api.labour.api.ProjectWorkerApi;
|
||||
@ -11,15 +12,19 @@ import cn.axzo.msg.center.service.enums.BizCategoryEnum;
|
||||
import cn.axzo.msg.center.service.pending.client.PendingMessageClient;
|
||||
import cn.axzo.msg.center.service.pending.request.PendingMessagePushRequest;
|
||||
import cn.axzo.nanopart.doc.api.anonymous.DocAnonymousDatabaseApi;
|
||||
import cn.axzo.nanopart.doc.api.domain.FileReplaceContent;
|
||||
import cn.axzo.nanopart.doc.api.filetemplate.FileTemplateApi;
|
||||
import cn.axzo.nanopart.doc.api.filetemplate.request.FileTemplateReplaceRequest;
|
||||
import cn.axzo.nanopart.doc.api.index.request.CopyNodeRequest;
|
||||
import cn.axzo.workflow.common.exception.WorkflowEngineException;
|
||||
import cn.axzo.workflow.common.model.dto.SignFileDTO;
|
||||
import cn.axzo.workflow.common.model.dto.VariableObjectDTO;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.BpmnSignConf;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.common.model.response.bpmn.model.doc.DocBaseVO;
|
||||
import cn.axzo.workflow.core.common.context.ProcessOperationContext;
|
||||
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomGetModelDocsCmd;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomGetProcessInstanceVariablesToObjectCmd;
|
||||
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
|
||||
import cn.axzo.workflow.core.listener.BpmnProcessEventListener;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxProcessSign;
|
||||
@ -39,6 +44,7 @@ import org.flowable.common.engine.impl.interceptor.CommandExecutor;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.ProcessEngineConfiguration;
|
||||
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
|
||||
import org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.flowable.engine.impl.util.CommandContextUtil;
|
||||
@ -60,7 +66,6 @@ import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.axzo.workflow.common.code.BpmnModelRespCode.MODEL_FILE_CLONE_ERROR;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.SIGNATORIES;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.SIGN_PROCESS_ENABLE_DOC_IDS;
|
||||
@ -84,8 +89,10 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
@Resource
|
||||
private ExtAxProcessSignService extAxProcessSignService;
|
||||
@Resource
|
||||
private DocAnonymousDatabaseApi docApi;
|
||||
@Autowired
|
||||
private DocAnonymousDatabaseApi docAnonymousApi;
|
||||
@Resource
|
||||
private FileTemplateApi fileTemplateApi;
|
||||
@Resource
|
||||
private ExtAxModelDocService extAxModelDocService;
|
||||
@Autowired
|
||||
private PendingMessageClient pendingMessageClient;
|
||||
@ -94,26 +101,79 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
@Autowired
|
||||
private ProjectWorkerApi projectWorkerApi;
|
||||
|
||||
|
||||
/**
|
||||
* 创建流程成功,判断是否是签署业务,如果是签署业务,则进行第一次模型文件的副本创建,作为与当前流程对应版本使用
|
||||
* 流程实例启用成功后:
|
||||
* 1、将模型关联的且实例勾选使用过的文档进行原始模板复制
|
||||
* 2、进行初始数据的模板变量替换
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onCreated(FlowableEngineEntityEvent event) {
|
||||
Process mainProcess = ProcessDefinitionUtil.getBpmnModel(event.getProcessDefinitionId()).getMainProcess();
|
||||
public void onStarted(FlowableProcessStartedEvent event) {
|
||||
String processInstanceId = ((FlowableProcessStartedEventImpl) event).getProcessInstanceId();
|
||||
Process mainProcess = ProcessDefinitionUtil.getBpmnModel(((FlowableProcessStartedEventImpl) event).getProcessDefinitionId()).getMainProcess();
|
||||
Optional<BpmnSignConf> signConfig = BpmnMetaParserHelper.getSignConfig(mainProcess);
|
||||
if (!signConfig.isPresent()) {
|
||||
return;
|
||||
}
|
||||
// 流程发起时,需要基于基础文档,复制一份模板
|
||||
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) getEngineConfiguration();
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
List<DocBaseVO> docs = commandExecutor.execute(new CustomGetModelDocsCmd(event.getProcessInstanceId(), true, extAxModelDocMapper));
|
||||
if (CollectionUtils.isEmpty(docs)) {
|
||||
return;
|
||||
}
|
||||
List<DocBaseVO> docs = commandExecutor.execute(new CustomGetModelDocsCmd(processInstanceId, true, extAxModelDocMapper));
|
||||
ExtAxProcessSign processSign = new ExtAxProcessSign();
|
||||
processSign.setProcessInstanceId(processInstanceId);
|
||||
processSign.setSignType(signConfig.get().getSignType().getType());
|
||||
processSign.setPendingMessageId(signConfig.get().getSignPendingProperty().getPendingMessageId());
|
||||
if (!CollectionUtils.isEmpty(docs)) {
|
||||
// 复制基础模板
|
||||
List<SignFileDTO> docTemplates = copyTempTemplate(docs);
|
||||
processSign.setDocTemplate(docTemplates);
|
||||
|
||||
List<SignFileDTO> archives = replaceTemplateVariable(docTemplates, processEngineConfiguration, processInstanceId);
|
||||
processSign.setFileArchive(archives);
|
||||
}
|
||||
// 没有可用的文档,但仍然记录库表
|
||||
extAxProcessSignService.save(processSign);
|
||||
}
|
||||
|
||||
private List<SignFileDTO> replaceTemplateVariable(List<SignFileDTO> docTemplates, ProcessEngineConfigurationImpl processEngineConfiguration, String processInstanceId) {
|
||||
List<SignFileDTO> archives = new ArrayList<>();
|
||||
docTemplates.forEach(template -> {
|
||||
SignFileDTO signFileDTO = new SignFileDTO();
|
||||
signFileDTO.setId(template.getId());
|
||||
signFileDTO.setFileTag(template.getFileTag());
|
||||
signFileDTO.setFileType(template.getFileType());
|
||||
signFileDTO.setFileCode(template.getFileCode());
|
||||
String fileKey = wpsFileVariableReplace(processEngineConfiguration, processInstanceId, template.getFileCode(), null);
|
||||
signFileDTO.setFileKey(fileKey);
|
||||
archives.add(signFileDTO);
|
||||
});
|
||||
return archives;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用 wps 文件变量替换接口
|
||||
*
|
||||
* @param processEngineConfiguration
|
||||
* @param processInstanceId
|
||||
* @return 返回替换变量后的文件oss 的 fileKey
|
||||
*/
|
||||
private String wpsFileVariableReplace(ProcessEngineConfigurationImpl processEngineConfiguration, String processInstanceId, String fileCode, String fileKey) {
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
List<VariableObjectDTO> wpsVariables = commandExecutor.execute(new CustomGetProcessInstanceVariablesToObjectCmd(processInstanceId));
|
||||
FileTemplateReplaceRequest request = new FileTemplateReplaceRequest();
|
||||
request.setFileCode(fileCode);
|
||||
request.setFileKey(fileKey);
|
||||
request.setReplaceContentList(BeanMapper.copyList(wpsVariables.stream()
|
||||
.filter(i -> Objects.equals(i.getType().name(), "img") || Objects.equals(i.getType().name(), "text"))
|
||||
.collect(Collectors.toList()), FileReplaceContent.class, (s, t) -> {
|
||||
t.setContent(s.getValue().toString());
|
||||
}));
|
||||
return RpcExternalUtil.rpcProcessor(() -> fileTemplateApi.replaceWordText(request), "替换 WPS 文档变量", request);
|
||||
}
|
||||
|
||||
private List<SignFileDTO> copyTempTemplate(List<DocBaseVO> docs) {
|
||||
List<SignFileDTO> files = new ArrayList<>();
|
||||
docs.forEach(doc -> {
|
||||
SignFileDTO signFileDTO = new SignFileDTO();
|
||||
@ -125,11 +185,8 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
case EXCEL:
|
||||
CopyNodeRequest copy = new CopyNodeRequest();
|
||||
copy.setCode(doc.getFileRelationId());
|
||||
CommonResponse<String> response = docApi.copy(copy);
|
||||
if (Objects.isNull(response) || !Objects.equals(response.getCode(), 200)) {
|
||||
throw new WorkflowEngineException(MODEL_FILE_CLONE_ERROR, Objects.isNull(response) ? "网络异常" : response.getMsg());
|
||||
}
|
||||
signFileDTO.setFileCode(response.getData());
|
||||
String fileCode = RpcExternalUtil.rpcProcessor(() -> docAnonymousApi.copy(copy), "复制文档", copy);
|
||||
signFileDTO.setFileCode(fileCode);
|
||||
break;
|
||||
case HIPRINT:
|
||||
Long newDocId = extAxModelDocService.cloneDoc(doc.getId());
|
||||
@ -142,47 +199,11 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
}
|
||||
files.add(signFileDTO);
|
||||
});
|
||||
|
||||
ExtAxProcessSign processSign = new ExtAxProcessSign();
|
||||
processSign.setProcessInstanceId(event.getProcessInstanceId());
|
||||
processSign.setSignType(signConfig.get().getSignType().getType());
|
||||
processSign.setPendingMessageId(signConfig.get().getSignPendingProperty().getPendingMessageId());
|
||||
processSign.setDocTemplate(files);
|
||||
extAxProcessSignService.save(processSign);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程实例启用成功后,进行初始数据的模板变量替换
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onStarted(FlowableProcessStartedEvent event) {
|
||||
// TODO 将拷贝后的文档进行初始的模板变量替换
|
||||
ExtAxProcessSign processSign = extAxProcessSignService.findByProcessInstanceId(event.getNestedProcessInstanceId());
|
||||
if (processSign == null || CollectionUtils.isEmpty(processSign.getFileArchive())) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SignFileDTO> archives = new ArrayList<>();
|
||||
processSign.getDocTemplate().forEach(template -> {
|
||||
SignFileDTO signFileDTO = new SignFileDTO();
|
||||
signFileDTO.setId(template.getId());
|
||||
signFileDTO.setFileTag(template.getFileTag());
|
||||
signFileDTO.setFileType(template.getFileType());
|
||||
// TODO 替换变量后,获得新生成的文档code
|
||||
signFileDTO.setFileCode("");
|
||||
archives.add(signFileDTO);
|
||||
});
|
||||
|
||||
processSign.setFileArchive(archives);
|
||||
extAxProcessSignService.updateById(processSign);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(FlowableEngineEntityEvent event) {
|
||||
// TODO 将该模型关联的文档统一进行归档, 加载变量, 并发送业务待办
|
||||
Process mainProcess = ProcessDefinitionUtil.getBpmnModel(event.getProcessDefinitionId()).getMainProcess();
|
||||
Optional<BpmnSignConf> signConfig = BpmnMetaParserHelper.getSignConfig(mainProcess);
|
||||
if (!signConfig.isPresent()) {
|
||||
@ -196,38 +217,19 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
Map<String, Object> processVariables = instance.getProcessVariables();
|
||||
|
||||
// 文件归档,将审批过程中产生的数据全部替换文档模板变量
|
||||
archiveFinalDocs(processVariables, instance);
|
||||
archiveFinalDocs(instance);
|
||||
|
||||
// 发送业务待办
|
||||
sendSignPending(signConfig.get(), processVariables, instance);
|
||||
}
|
||||
|
||||
private void archiveFinalDocs(Map<String, Object> processVariables, HistoricProcessInstance instance) {
|
||||
private void archiveFinalDocs(HistoricProcessInstance instance) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) getEngineConfiguration();
|
||||
List<String> fileTags = getFileDocIds(processVariables);
|
||||
List<DocBaseVO> needFirstArchiveDocs = processEngineConfiguration.getCommandExecutor().execute(new CustomGetModelDocsCmd(instance.getId(), true, extAxModelDocMapper))
|
||||
.stream().filter(i -> fileTags.contains(i.getTag())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(needFirstArchiveDocs)) {
|
||||
return;
|
||||
}
|
||||
List<SignFileDTO> fileArchives = new ArrayList<>();
|
||||
needFirstArchiveDocs.forEach(docBaseVO -> {
|
||||
// TODO 进行文档变量替换,替换后,返回 fileKey
|
||||
|
||||
// TODO 上传 wps,返回文件 code
|
||||
|
||||
|
||||
SignFileDTO signFileDTO = new SignFileDTO();
|
||||
signFileDTO.setId(docBaseVO.getId());
|
||||
signFileDTO.setFileTag(docBaseVO.getTag());
|
||||
signFileDTO.setFileType(docBaseVO.getFileType());
|
||||
// TODO 上传后的 wps file code
|
||||
signFileDTO.setFileCode("");
|
||||
fileArchives.add(signFileDTO);
|
||||
});
|
||||
|
||||
ExtAxProcessSign processSign = extAxProcessSignService.findByProcessInstanceId(instance.getId());
|
||||
processSign.setFileArchive(fileArchives);
|
||||
processSign.getFileArchive().forEach(docBaseVO -> {
|
||||
String newFileKey = wpsFileVariableReplace(processEngineConfiguration, instance.getId(), docBaseVO.getFileCode(), docBaseVO.getFileKey());
|
||||
docBaseVO.setFileKey(newFileKey);
|
||||
});
|
||||
extAxProcessSignService.updateById(processSign);
|
||||
}
|
||||
|
||||
@ -247,7 +249,6 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
// 带班长签字-projectTeamManagerSignature
|
||||
// 工人签字-workerSignature
|
||||
// 工人签署时间-workerSignatureTime
|
||||
bpmnSignConf.getSignType();
|
||||
List<BpmnTaskDelegateAssigner> signatories = (List<BpmnTaskDelegateAssigner>) processVariables.getOrDefault(SIGNATORIES, Collections.emptyList());
|
||||
if (CollectionUtils.isEmpty(signatories)) {
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user