Compare commits
2 Commits
b85c2ac097
...
f9ab24fcea
| Author | SHA1 | Date | |
|---|---|---|---|
| f9ab24fcea | |||
| 5e0204cd73 |
@ -93,4 +93,10 @@ public class CategoryCreateDTO {
|
||||
@ApiModelProperty(value = "版本号")
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 自定替换未设置的变量为空串
|
||||
*/
|
||||
@ApiModelProperty(value = "是否自动替换变量为空串,默认false")
|
||||
private Boolean autoReplaceVariables;
|
||||
|
||||
}
|
||||
|
||||
@ -47,6 +47,9 @@ public class CategoryItemVO {
|
||||
@ApiModelProperty(value = "版本号")
|
||||
private Integer version;
|
||||
|
||||
@ApiModelProperty(value = "自定替换未设置的变量为空串")
|
||||
private Boolean autoReplaceVariables;
|
||||
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Date updateAt;
|
||||
}
|
||||
|
||||
@ -273,15 +273,10 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
|
||||
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())
|
||||
.desc(group.getGroupName() + variable.getName())
|
||||
.value(value)
|
||||
.value(bizVariables.getOrDefault(variable.getCode(), null))
|
||||
.type(convert(variable.getType()))
|
||||
.build());
|
||||
});
|
||||
|
||||
@ -84,4 +84,9 @@ public class ExtAxDict extends BaseEntity<ExtAxDict> {
|
||||
* 版本号
|
||||
*/
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 自定替换未设置的变量为空串
|
||||
*/
|
||||
private Boolean autoReplaceVariables;
|
||||
}
|
||||
|
||||
@ -119,6 +119,7 @@ public class CategoryServiceImpl extends ServiceImpl<ExtAxDictMapper, ExtAxDict>
|
||||
dict.setIcon(dto.getIcon());
|
||||
dict.setDisplayInitiateMenu(dto.getDisplayInitiateMenu());
|
||||
dict.setVersion(dto.getVersion());
|
||||
dict.setAutoReplaceVariables(Boolean.TRUE.equals(dto.getAutoReplaceVariables()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -31,6 +31,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -243,20 +244,26 @@ public class WpsUtil {
|
||||
* @return 返回替换变量后的文件oss 的 fileKey
|
||||
*/
|
||||
public String wpsFileVariableReplace(List<VariableObjectDTO> wpsVariables,
|
||||
String fileCode, String fileKey, String fileName) {
|
||||
|
||||
List<FileReplaceContent> fileReplaceContents = BeanMapper.copyList(wpsVariables.stream()
|
||||
.filter(i -> Objects.nonNull(i.getValue()) && checkNotEmptyColl(i))
|
||||
.filter(i -> !(Objects.equals(i.getType().name(), "img") && !StringUtils.hasText(i.getValue().toString())))
|
||||
.filter(i -> Objects.equals(i.getType().name(), "img") || Objects.equals(i.getType().name(), "text"))
|
||||
.collect(Collectors.toList()), FileReplaceContent.class, (s, t) -> {
|
||||
t.setKey(s.getDesc());
|
||||
if (Objects.equals(s.getType().name(), "img")) {
|
||||
if (isJson(s.getValue().toString())) {
|
||||
t.setContent(JSON.parseArray(s.getValue().toString(), UploadFieldDTO.class).get(0).getFileUrl());
|
||||
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 {
|
||||
t.setContent(JSON.parseArray(JSON.toJSONString(s.getValue()), UploadFieldDTO.class).get(0).getFileUrl());
|
||||
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() : "");
|
||||
}
|
||||
@ -264,6 +271,17 @@ public class WpsUtil {
|
||||
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);
|
||||
|
||||
@ -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.VariableObjectDTO;
|
||||
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.utils.BpmnMetaParserHelper;
|
||||
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
|
||||
import cn.axzo.workflow.core.listener.BpmnProcessEventListener;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxDocContent;
|
||||
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.ExtAxModelDocService;
|
||||
import cn.axzo.workflow.core.service.ExtAxProcessSignService;
|
||||
@ -35,6 +37,8 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
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
|
||||
private ExtAxDocContentService extAxDocContentService;
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
@Resource
|
||||
private WpsUtil wpsUtil;
|
||||
|
||||
|
||||
@ -71,19 +77,21 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery()
|
||||
.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();
|
||||
ExtAxProcessSign processSign = extAxProcessSignService.findByProcessInstanceId(instance.getId());
|
||||
List<VariableObjectDTO> wpsReplaceVariables = wpsUtil.getWpsReplaceVariables(processEngineConfiguration, instance.getId());
|
||||
|
||||
processSign.getFileArchive().stream().filter(i -> Objects.equals(i.getFileType(), FileTypeEnum.WORD)
|
||||
|| Objects.equals(i.getFileType(), FileTypeEnum.EXCEL))
|
||||
.filter(i -> Boolean.TRUE.equals(i.getNeedReplaceVariables()))
|
||||
.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);
|
||||
});
|
||||
// 删除非 WPS 的临时文档
|
||||
@ -116,6 +124,6 @@ public class FileArchiveProcessEventListener extends AbstractBpmnEventListener<P
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MIN_VALUE + 3;
|
||||
return Integer.MIN_VALUE + 99;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user