feat(REQ-5965) - 新增wps 替换变量时,需要对无内存变量修改为空串
This commit is contained in:
parent
cef429d4ab
commit
5e0204cd73
@ -93,4 +93,10 @@ public class CategoryCreateDTO {
|
|||||||
@ApiModelProperty(value = "版本号")
|
@ApiModelProperty(value = "版本号")
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定替换未设置的变量为空串
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "是否自动替换变量为空串,默认false")
|
||||||
|
private Boolean autoReplaceVariables;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,9 @@ public class CategoryItemVO {
|
|||||||
@ApiModelProperty(value = "版本号")
|
@ApiModelProperty(value = "版本号")
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "自定替换未设置的变量为空串")
|
||||||
|
private Boolean autoReplaceVariables;
|
||||||
|
|
||||||
@ApiModelProperty(value = "更新时间")
|
@ApiModelProperty(value = "更新时间")
|
||||||
private Date updateAt;
|
private Date updateAt;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -272,15 +272,10 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
|
|||||||
groupVariables.forEach(group -> {
|
groupVariables.forEach(group -> {
|
||||||
if (!CollectionUtils.isEmpty(group.getVars())) {
|
if (!CollectionUtils.isEmpty(group.getVars())) {
|
||||||
group.getVars().forEach(variable -> {
|
group.getVars().forEach(variable -> {
|
||||||
Object value = bizVariables.getOrDefault(variable.getCode(), null);
|
|
||||||
if (Objects.isNull(value)) {
|
|
||||||
// 目前为了减少 wps 替换耗时,所以将没有值的变量,直接踢出
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
variables.add(VariableObjectDTO.builder()
|
variables.add(VariableObjectDTO.builder()
|
||||||
.key(variable.getCode())
|
.key(variable.getCode())
|
||||||
.desc(group.getGroupName() + variable.getName())
|
.desc(group.getGroupName() + variable.getName())
|
||||||
.value(value)
|
.value(bizVariables.getOrDefault(variable.getCode(), null))
|
||||||
.type(convert(variable.getType()))
|
.type(convert(variable.getType()))
|
||||||
.build());
|
.build());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -84,4 +84,9 @@ public class ExtAxDict extends BaseEntity<ExtAxDict> {
|
|||||||
* 版本号
|
* 版本号
|
||||||
*/
|
*/
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定替换未设置的变量为空串
|
||||||
|
*/
|
||||||
|
private Boolean autoReplaceVariables;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,6 +119,7 @@ public class CategoryServiceImpl extends ServiceImpl<ExtAxDictMapper, ExtAxDict>
|
|||||||
dict.setIcon(dto.getIcon());
|
dict.setIcon(dto.getIcon());
|
||||||
dict.setDisplayInitiateMenu(dto.getDisplayInitiateMenu());
|
dict.setDisplayInitiateMenu(dto.getDisplayInitiateMenu());
|
||||||
dict.setVersion(dto.getVersion());
|
dict.setVersion(dto.getVersion());
|
||||||
|
dict.setAutoReplaceVariables(Boolean.TRUE.equals(dto.getAutoReplaceVariables()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -60,6 +61,60 @@ public class WpsUtil {
|
|||||||
@Resource
|
@Resource
|
||||||
private OrganizationalNodeUserQueryApi organizationalNodeUserQueryApi;
|
private OrganizationalNodeUserQueryApi organizationalNodeUserQueryApi;
|
||||||
|
|
||||||
|
public String wpsFileVariableReplace(List<VariableObjectDTO> wpsVariables,
|
||||||
|
String fileCode, String fileKey, String fileName, Boolean autoReplaceVariables) {
|
||||||
|
List<VariableObjectDTO> variables = wpsVariables.stream()
|
||||||
|
.filter(i -> Objects.equals(i.getType().name(), VariableObjectDTO.Type.img.name()) || Objects.equals(i.getType().name(), VariableObjectDTO.Type.text.name()))
|
||||||
|
.filter(i -> {
|
||||||
|
if (Objects.equals(Boolean.TRUE, autoReplaceVariables)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return Objects.nonNull(i.getValue());
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
List<FileReplaceContent> fileReplaceContents = BeanMapper.copyList(variables, FileReplaceContent.class, (s, t) -> {
|
||||||
|
t.setKey(s.getDesc());
|
||||||
|
if (Objects.equals(s.getType().name(), VariableObjectDTO.Type.img.name())) {
|
||||||
|
List<UploadFieldDTO> uploadFieldDTOS = new ArrayList<>();
|
||||||
|
if (isJson(s.getValue().toString())) {
|
||||||
|
uploadFieldDTOS.addAll(JSON.parseArray(s.getValue().toString(), UploadFieldDTO.class));
|
||||||
|
} else {
|
||||||
|
uploadFieldDTOS.addAll(JSON.parseArray(JSON.toJSONString(s.getValue()), UploadFieldDTO.class));
|
||||||
|
}
|
||||||
|
t.setContent(CollectionUtils.isEmpty(uploadFieldDTOS) ? "" : uploadFieldDTOS.get(0).getFileUrl());
|
||||||
|
} else {
|
||||||
|
t.setContent(Objects.nonNull(s.getValue()) ? s.getValue().toString() : "");
|
||||||
|
}
|
||||||
|
t.setType(s.getType().name());
|
||||||
|
t.setPrefix("[");
|
||||||
|
t.setSuffix("]");
|
||||||
|
});
|
||||||
|
|
||||||
|
// 处理空值
|
||||||
|
if (Objects.equals(Boolean.TRUE, autoReplaceVariables)) {
|
||||||
|
fileReplaceContents.stream()
|
||||||
|
.filter(i -> !StringUtils.hasText(i.getContent()))
|
||||||
|
.forEach(i -> {
|
||||||
|
// TODO 将变量替换未空串
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (StringUtils.hasText(fileCode)) {
|
||||||
|
FileTemplateReplaceRequest request = new FileTemplateReplaceRequest();
|
||||||
|
request.setFileCode(fileCode);
|
||||||
|
request.setFileKey(fileKey);
|
||||||
|
request.setReplaceContentList(fileReplaceContents);
|
||||||
|
return RpcExternalUtil.rpcProcessor(() -> fileTemplateApi.replaceWordText(request), "替换 WPS 文档变量", request);
|
||||||
|
} else {
|
||||||
|
SimpleFileTemplateReplaceRequest request = new SimpleFileTemplateReplaceRequest();
|
||||||
|
request.setFileName(fileName);
|
||||||
|
request.setFileKey(fileKey);
|
||||||
|
request.setReplaceContentList(fileReplaceContents);
|
||||||
|
return RpcExternalUtil.rpcProcessor(() -> fileTemplateApi.replaceWordTextForFileKey(request), "替换 WPS 文档变量(simple)", request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用 wps 文件变量替换接口
|
* 调用 wps 文件变量替换接口
|
||||||
*
|
*
|
||||||
@ -77,11 +132,13 @@ public class WpsUtil {
|
|||||||
.collect(Collectors.toList()), FileReplaceContent.class, (s, t) -> {
|
.collect(Collectors.toList()), FileReplaceContent.class, (s, t) -> {
|
||||||
t.setKey(s.getDesc());
|
t.setKey(s.getDesc());
|
||||||
if (Objects.equals(s.getType().name(), "img")) {
|
if (Objects.equals(s.getType().name(), "img")) {
|
||||||
|
List<UploadFieldDTO> uploadFieldDTOS;
|
||||||
if (isJson(s.getValue().toString())) {
|
if (isJson(s.getValue().toString())) {
|
||||||
t.setContent(JSON.parseArray(s.getValue().toString(), UploadFieldDTO.class).get(0).getFileUrl());
|
uploadFieldDTOS = JSON.parseArray(s.getValue().toString(), UploadFieldDTO.class);
|
||||||
} else {
|
} else {
|
||||||
t.setContent(JSON.parseArray(JSON.toJSONString(s.getValue()), UploadFieldDTO.class).get(0).getFileUrl());
|
uploadFieldDTOS = JSON.parseArray(JSON.toJSONString(s.getValue()), UploadFieldDTO.class);
|
||||||
}
|
}
|
||||||
|
t.setContent(CollectionUtils.isEmpty(uploadFieldDTOS) ? "" : uploadFieldDTOS.get(0).getFileUrl());
|
||||||
} else {
|
} else {
|
||||||
t.setContent(Objects.nonNull(s.getValue()) ? s.getValue().toString() : "");
|
t.setContent(Objects.nonNull(s.getValue()) ? s.getValue().toString() : "");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,14 @@ import cn.axzo.workflow.common.enums.FileTypeEnum;
|
|||||||
import cn.axzo.workflow.common.model.dto.SignFileDTO;
|
import cn.axzo.workflow.common.model.dto.SignFileDTO;
|
||||||
import cn.axzo.workflow.common.model.dto.VariableObjectDTO;
|
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.BpmnSignConf;
|
||||||
|
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
|
||||||
import cn.axzo.workflow.core.common.context.ProcessOperationContext;
|
import cn.axzo.workflow.core.common.context.ProcessOperationContext;
|
||||||
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
||||||
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
|
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
|
||||||
import cn.axzo.workflow.core.listener.BpmnProcessEventListener;
|
import cn.axzo.workflow.core.listener.BpmnProcessEventListener;
|
||||||
import cn.axzo.workflow.core.repository.entity.ExtAxDocContent;
|
import cn.axzo.workflow.core.repository.entity.ExtAxDocContent;
|
||||||
import cn.axzo.workflow.core.repository.entity.ExtAxProcessSign;
|
import cn.axzo.workflow.core.repository.entity.ExtAxProcessSign;
|
||||||
|
import cn.axzo.workflow.core.service.CategoryService;
|
||||||
import cn.axzo.workflow.core.service.ExtAxDocContentService;
|
import cn.axzo.workflow.core.service.ExtAxDocContentService;
|
||||||
import cn.axzo.workflow.core.service.ExtAxModelDocService;
|
import cn.axzo.workflow.core.service.ExtAxModelDocService;
|
||||||
import cn.axzo.workflow.core.service.ExtAxProcessSignService;
|
import cn.axzo.workflow.core.service.ExtAxProcessSignService;
|
||||||
@ -35,6 +37,8 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static cn.axzo.workflow.common.constant.BpmnConstants.BPM_MODEL_CATEGORY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签署业务,审批完成后,进行文件归档,并对所有工人发送业务待办
|
* 签署业务,审批完成后,进行文件归档,并对所有工人发送业务待办
|
||||||
*
|
*
|
||||||
@ -55,6 +59,8 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
|||||||
@Resource
|
@Resource
|
||||||
private ExtAxDocContentService extAxDocContentService;
|
private ExtAxDocContentService extAxDocContentService;
|
||||||
@Resource
|
@Resource
|
||||||
|
private CategoryService categoryService;
|
||||||
|
@Resource
|
||||||
private WpsUtil wpsUtil;
|
private WpsUtil wpsUtil;
|
||||||
|
|
||||||
|
|
||||||
@ -71,19 +77,21 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
|||||||
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery()
|
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery()
|
||||||
.processInstanceId(processInstanceId).includeProcessVariables().singleResult();
|
.processInstanceId(processInstanceId).includeProcessVariables().singleResult();
|
||||||
|
|
||||||
|
CategoryItemVO category = categoryService.get(BPM_MODEL_CATEGORY, mainProcess.getId()).orElse(new CategoryItemVO());
|
||||||
// 文件归档,将审批过程中产生的数据全部替换文档模板变量
|
// 文件归档,将审批过程中产生的数据全部替换文档模板变量
|
||||||
archiveFinalDocs(instance);
|
archiveFinalDocs(instance, category.getAutoReplaceVariables());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void archiveFinalDocs(HistoricProcessInstance instance) {
|
private void archiveFinalDocs(HistoricProcessInstance instance, Boolean autoReplaceVariables) {
|
||||||
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) getEngineConfiguration();
|
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) getEngineConfiguration();
|
||||||
ExtAxProcessSign processSign = extAxProcessSignService.findByProcessInstanceId(instance.getId());
|
ExtAxProcessSign processSign = extAxProcessSignService.findByProcessInstanceId(instance.getId());
|
||||||
List<VariableObjectDTO> wpsReplaceVariables = wpsUtil.getWpsReplaceVariables(processEngineConfiguration, instance.getId());
|
List<VariableObjectDTO> wpsReplaceVariables = wpsUtil.getWpsReplaceVariables(processEngineConfiguration, instance.getId());
|
||||||
|
|
||||||
processSign.getFileArchive().stream().filter(i -> Objects.equals(i.getFileType(), FileTypeEnum.WORD)
|
processSign.getFileArchive().stream().filter(i -> Objects.equals(i.getFileType(), FileTypeEnum.WORD)
|
||||||
|| Objects.equals(i.getFileType(), FileTypeEnum.EXCEL))
|
|| Objects.equals(i.getFileType(), FileTypeEnum.EXCEL))
|
||||||
.filter(i -> Boolean.TRUE.equals(i.getNeedReplaceVariables()))
|
.filter(i -> Boolean.TRUE.equals(i.getNeedReplaceVariables()))
|
||||||
.forEach(docBaseVO -> {
|
.forEach(docBaseVO -> {
|
||||||
String newFileKey = wpsUtil.wpsFileVariableReplace(wpsReplaceVariables, null, docBaseVO.getFileKey(), docBaseVO.getTemplateName() + docBaseVO.getFileType().getSuffix());
|
String newFileKey = wpsUtil.wpsFileVariableReplace(wpsReplaceVariables, null, docBaseVO.getFileKey(), docBaseVO.getTemplateName() + docBaseVO.getFileType().getSuffix(), autoReplaceVariables);
|
||||||
docBaseVO.setFileKey(newFileKey);
|
docBaseVO.setFileKey(newFileKey);
|
||||||
});
|
});
|
||||||
// 删除非 WPS 的临时文档
|
// 删除非 WPS 的临时文档
|
||||||
@ -116,6 +124,6 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
return Integer.MIN_VALUE + 3;
|
return Integer.MIN_VALUE + 99;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user