Merge remote-tracking branch 'origin/feature/REQ-5965' into feature/REQ-5965

# Conflicts:
#	workflow-engine-server/src/main/java/cn/axzo/workflow/server/common/util/WpsUtil.java
This commit is contained in:
wangli 2025-12-22 10:00:14 +08:00
commit f9ab24fcea
4 changed files with 205 additions and 54 deletions

View File

@ -210,6 +210,9 @@ public class CustomApproveTaskCmd extends AbstractCommand<Void> implements Seria
List<AttachmentDTO> attachmentList,
String advice,
BpmnTaskDelegateAssigner approver) {
if (Objects.isNull(approver)) {
return;
}
List<SignatureDTO> signatures = runtimeService.getVariable(task.getProcessInstanceId(), SIGNATURE_COLLECTION, List.class);
if (Objects.isNull(signatures)) {
signatures = new ArrayList<>();
@ -220,16 +223,16 @@ public class CustomApproveTaskCmd extends AbstractCommand<Void> implements Seria
.setActivityId(task.getTaskDefinitionKey())
.setActivityName(task.getName())
.setSignatures(new ArrayList<>()));
ListUtils.emptyIfNull(attachmentList).stream()
.filter(i -> Objects.equals(i.getType(), AttachmentTypeEnum.signature))
.findFirst()
.ifPresent(attachment -> dto.getSignatures().add(0,
new SignatureDTO.SignDetail()
.setApproverName(approver.getAssignerName())
.setSignature(attachment.getUrl())
.setAdvice(advice)
.setResult(BpmnProcessTaskResultEnum.APPROVED.getDesc())
.setOperationTime(new Date())));
dto.getSignatures().add(0, new SignatureDTO.SignDetail()
.setApproverName(approver.getAssignerName())
.setSignature(ListUtils.emptyIfNull(attachmentList).stream()
.filter(i -> Objects.equals(i.getType(), AttachmentTypeEnum.signature))
.findFirst().orElse(new AttachmentDTO()).getUrl())
.setAdvice(advice)
.setResult(BpmnProcessTaskResultEnum.APPROVED.getDesc())
.setOperationTime(new Date())
);
if (!any.isPresent()) {
signatures.add(dto);
}

View File

@ -234,6 +234,7 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
}
private void addSignature(List<VariableObjectDTO> variables, List<SignatureDTO> signatures) {
log.info("addSignature{}", JSON.toJSONString(signatures));
if (CollectionUtils.isEmpty(signatures)) {
return;
}

View File

@ -22,6 +22,7 @@ import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.springframework.stereotype.Component;
@ -29,6 +30,7 @@ import org.springframework.util.CollectionUtils;
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;
@ -52,6 +54,7 @@ import static cn.axzo.workflow.common.model.dto.VariableObjectDTO.Type.signature
* @since 2025-04-09 20:41
*/
@Component
@Slf4j
public class WpsUtil {
public static final List<FileTypeEnum> WPS_SUPPORTED_FILE_TYPES = Lists.newArrayList(FileTypeEnum.WORD, FileTypeEnum.EXCEL);
@Resource
@ -61,6 +64,185 @@ public class WpsUtil {
@Resource
private OrganizationalNodeUserQueryApi organizationalNodeUserQueryApi;
public static void main(String[] args) {
String jsonStr = "[{\"desc\":\"审批编号\",\"key\":\"processInstanceId\",\"type\":\"text\",\"value\":\"202512200123200000000\"},{\"desc\":\"发起时间\",\"key\":\"startTime\",\"type\":\"text\",\"value\":\"2025.12.20 01:23:56\"},{\"desc\":\"审批结束时间\",\"key\":\"endTime\",\"type\":\"text\"},{\"desc\":\"业务名称\",\"key\":\"processDefinitionKey\",\"type\":\"text\",\"value\":\"安全教育签字(anquanjiaoyu)\"},{\"desc\":\"业务变量主讲人单位\",\"key\":\"speakerUnit\",\"type\":\"text\",\"value\":\"四川星腾贸易有限公司\"},{\"desc\":\"业务变量主讲人部门\",\"key\":\"speakerNode\",\"type\":\"text\",\"value\":\"四川星腾贸易有限公司\"},{\"desc\":\"业务变量项目名称\",\"key\":\"workspaceName\",\"type\":\"text\",\"value\":\"test-0925项目服务部\"},{\"desc\":\"业务变量签署发起时间\",\"key\":\"signingInitiationTime\",\"type\":\"text\",\"value\":\"20251219\"},{\"desc\":\"业务变量主讲人姓名\",\"key\":\"speakerName\",\"type\":\"text\",\"value\":\"罗福\"},{\"desc\":\"发起者\",\"key\":\"initiator\",\"type\":\"obj\",\"value\":\"{\\\"assignerName\\\":\\\"罗福\\\",\\\"avatar\\\":\\\"https://axzo-app.oss-cn-chengdu.aliyuncs.com/face/8c29d036-5db3-431d-b537-9d6d5c8019da.jpg\\\",\\\"nodeId\\\":\\\"7399\\\",\\\"ouId\\\":\\\"6158\\\",\\\"personId\\\":\\\"9000399522\\\",\\\"tenantId\\\":\\\"399\\\"}\"},{\"desc\":\"主讲人审批\",\"key\":\"node_330665593249_axv0\",\"type\":\"signatureAndAdvice\",\"value\":[{\"advice\":\"123\",\"approverName\":\"罗福\",\"operationTime\":1766165056926,\"result\":\"已同意\"}]},{\"desc\":\"教育日期\",\"key\":\"educationDate\",\"type\":\"text\",\"value\":\"2025-12-02\"},{\"desc\":\"教育时长\",\"key\":\"educationDuration\",\"type\":\"text\",\"value\":\"11小时\"},{\"desc\":\"图片\",\"key\":\"picture\",\"type\":\"img\",\"value\":\"[{\\\"fileName\\\":\\\"1738899982734-97oknewbe77.png\\\",\\\"fileUrl\\\":\\\"https://axzo-public.oss-cn-chengdu.aliyuncs.com/cms/cms_test/4c7875246b9049188a055fb1c80effa4.png\\\",\\\"fileKey\\\":\\\"4c7875246b9049188a055fb1c80effa4\\\"}]\"},{\"desc\":\"签字工人\",\"key\":\"worker\",\"type\":\"text\",\"value\":\"母春田\"},{\"desc\":\"主讲人审批姓名\",\"key\":\"node_330665593249_axv0_approverName\",\"type\":\"text\",\"value\":\"罗福\"},{\"desc\":\"主讲人审批审批结果\",\"key\":\"node_330665593249_axv0_activityResult\",\"type\":\"text\",\"value\":\"已同意\"},{\"desc\":\"主讲人审批电子签名\",\"key\":\"node_330665593249_axv0_signature\",\"type\":\"img\",\"value\":[{}]},{\"desc\":\"主讲人审批审批意见\",\"key\":\"node_330665593249_axv0_advice\",\"type\":\"text\",\"value\":\"123\"},{\"desc\":\"主讲人审批日期\",\"key\":\"node_330665593249_axv0_activityOperationTime\",\"type\":\"text\",\"value\":\"2025.12.20\"},{\"desc\":\"发起人姓名\",\"key\":\"initiatorName\",\"type\":\"text\",\"value\":\"罗福\"},{\"desc\":\"发起人岗位\",\"key\":\"initiatorPosition\",\"type\":\"text\",\"value\":\"测试岗位003\"},{\"desc\":\"发起人联系方式\",\"key\":\"initiatorPhone\",\"type\":\"text\",\"value\":\"18080995942\"}]";
String jsonStr2 = "[\n" +
" {\n" +
" \"desc\": \"审批编号\",\n" +
" \"key\": \"processInstanceId\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"202512200123200000000\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"发起时间\",\n" +
" \"key\": \"startTime\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"2025.12.20 01:23:56\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"审批结束时间\",\n" +
" \"key\": \"endTime\",\n" +
" \"type\": \"text\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"业务名称\",\n" +
" \"key\": \"processDefinitionKey\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"安全教育签字(anquanjiaoyu)\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"业务变量主讲人单位\",\n" +
" \"key\": \"speakerUnit\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"四川星腾贸易有限公司\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"业务变量主讲人部门\",\n" +
" \"key\": \"speakerNode\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"四川星腾贸易有限公司\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"业务变量项目名称\",\n" +
" \"key\": \"workspaceName\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"test-0925项目服务部\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"业务变量签署发起时间\",\n" +
" \"key\": \"signingInitiationTime\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"20251219\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"业务变量主讲人姓名\",\n" +
" \"key\": \"speakerName\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"罗福\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"发起者\",\n" +
" \"key\": \"initiator\",\n" +
" \"type\": \"obj\",\n" +
" \"value\": \"{\\\"assignerName\\\":\\\"罗福\\\",\\\"avatar\\\":\\\"https://axzo-app.oss-cn-chengdu.aliyuncs.com/face/8c29d036-5db3-431d-b537-9d6d5c8019da.jpg\\\",\\\"nodeId\\\":\\\"7399\\\",\\\"ouId\\\":\\\"6158\\\",\\\"personId\\\":\\\"9000399522\\\",\\\"tenantId\\\":\\\"399\\\"}\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"主讲人审批\",\n" +
" \"key\": \"node_330665593249_axv0\",\n" +
" \"type\": \"signatureAndAdvice\",\n" +
" \"value\": [\n" +
" {\n" +
" \"advice\": \"123\",\n" +
" \"approverName\": \"罗福\",\n" +
" \"operationTime\": 1766165056926,\n" +
" \"result\": \"已同意\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"desc\": \"教育日期\",\n" +
" \"key\": \"educationDate\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"2025-12-02\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"教育时长\",\n" +
" \"key\": \"educationDuration\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"11小时\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"图片\",\n" +
" \"key\": \"picture\",\n" +
" \"type\": \"img\",\n" +
" \"value\": \"[{\\\"fileName\\\":\\\"1738899982734-97oknewbe77.png\\\",\\\"fileUrl\\\":\\\"https://axzo-public.oss-cn-chengdu.aliyuncs.com/cms/cms_test/4c7875246b9049188a055fb1c80effa4.png\\\",\\\"fileKey\\\":\\\"4c7875246b9049188a055fb1c80effa4\\\"}]\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"签字工人\",\n" +
" \"key\": \"worker\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"母春田\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"主讲人审批姓名\",\n" +
" \"key\": \"node_330665593249_axv0_approverName\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"罗福\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"主讲人审批审批结果\",\n" +
" \"key\": \"node_330665593249_axv0_activityResult\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"已同意\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"主讲人审批电子签名\",\n" +
" \"key\": \"node_330665593249_axv0_signature\",\n" +
" \"type\": \"img\",\n" +
" \"value\": []\n" +
" },\n" +
" {\n" +
" \"desc\": \"主讲人审批审批意见\",\n" +
" \"key\": \"node_330665593249_axv0_advice\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"123\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"主讲人审批日期\",\n" +
" \"key\": \"node_330665593249_axv0_activityOperationTime\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"2025.12.20\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"发起人姓名\",\n" +
" \"key\": \"initiatorName\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"罗福\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"发起人岗位\",\n" +
" \"key\": \"initiatorPosition\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"测试岗位003\"\n" +
" },\n" +
" {\n" +
" \"desc\": \"发起人联系方式\",\n" +
" \"key\": \"initiatorPhone\",\n" +
" \"type\": \"text\",\n" +
" \"value\": \"18080995942\"\n" +
" }\n" +
"]";
List<VariableObjectDTO> wpsVariables = JSON.parseArray(jsonStr2, VariableObjectDTO.class);
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());
} else {
t.setContent(JSON.parseArray(JSON.toJSONString(s.getValue()), UploadFieldDTO.class).get(0).getFileUrl());
}
} else {
t.setContent(Objects.nonNull(s.getValue()) ? s.getValue().toString() : "");
}
t.setType(s.getType().name());
t.setPrefix("[");
t.setSuffix("]");
});
System.out.println("fileReplaceContents = " + fileReplaceContents);
}
/**
* 调用 wps 文件变量替换接口
*
* @param fileCode 基于该模板进行变量替换
* @param fileKey 如果有值则变量替换完成后直接将文档覆盖该 fileKey 对应的文件
* @return 返回替换变量后的文件oss fileKey
*/
public String wpsFileVariableReplace(List<VariableObjectDTO> wpsVariables,
String fileCode, String fileKey, String fileName, Boolean autoReplaceVariables) {
List<VariableObjectDTO> variables = wpsVariables.stream()
@ -115,50 +297,12 @@ public class WpsUtil {
}
}
/**
* 调用 wps 文件变量替换接口
*
* @param fileCode 基于该模板进行变量替换
* @param fileKey 如果有值则变量替换完成后直接将文档覆盖该 fileKey 对应的文件
* @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()))
.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")) {
List<UploadFieldDTO> uploadFieldDTOS;
if (isJson(s.getValue().toString())) {
uploadFieldDTOS = JSON.parseArray(s.getValue().toString(), UploadFieldDTO.class);
} else {
uploadFieldDTOS = 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 (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);
private static boolean checkNotEmptyColl(VariableObjectDTO i) {
if (!(i.getValue() instanceof Collection)) {
return true;
}
return !CollectionUtils.isEmpty((Collection<?>) i.getValue());
}
public List<VariableObjectDTO> getWpsReplaceVariables(ProcessEngineConfigurationImpl processEngineConfiguration, String processInstanceId) {
@ -169,6 +313,7 @@ public class WpsUtil {
List<VariableObjectDTO> signatureAndAdvices = Lists.newArrayList();
wpsVariables.stream().filter(i -> Objects.equals(signatureAndAdvice, i.getType())).forEach(variableObjectDTO -> {
List<SignatureDTO.SignDetail> signDetails = (List<SignatureDTO.SignDetail>) variableObjectDTO.getValue();
log.info("getWpsReplaceVariables signDetails: {}", JSON.toJSONString(signDetails));
if (!CollectionUtils.isEmpty(signDetails)) {
SignatureDTO.SignDetail signDetail = signDetails.get(0);
signatureAndAdvices.add(VariableObjectDTO.builder()
@ -189,7 +334,7 @@ public class WpsUtil {
signatureAndAdvices.add(VariableObjectDTO.builder()
.key(variableObjectDTO.getKey() + "_signature")
.desc(variableObjectDTO.getDesc() + "电子签名")
.value(Lists.newArrayList(UploadFieldDTO.builder().fileKey(signDetail.getSignature()).fileUrl(signUrl.get(0).getSignUrl()).build()))
.value(CollectionUtils.isEmpty(signUrl) ? Lists.newArrayList() : Lists.newArrayList(UploadFieldDTO.builder().fileKey(signDetail.getSignature()).fileUrl(CollectionUtils.isEmpty(signUrl) ? null : signUrl.get(0).getSignUrl()).build()))
.type(VariableObjectDTO.Type.img)
.build());
signatureAndAdvices.add(VariableObjectDTO.builder()
@ -228,6 +373,7 @@ public class WpsUtil {
.build());
});
log.info("wpsVariables: {}", JSON.toJSONString(wpsVariables));
return wpsVariables;
}

View File

@ -168,6 +168,7 @@ public class FirstCopyTemplateFileTaskEvent_105_Listener extends AbstractBpmnEve
signFileDTO.setFileTag(template.getFileTag());
signFileDTO.setFileType(template.getFileType());
signFileDTO.setFileCode(template.getFileCode());
signFileDTO.setNeedReplaceVariables(template.getNeedReplaceVariables());
if (Objects.equals(template.getFileType(), FileTypeEnum.WORD) || Objects.equals(template.getFileType(), FileTypeEnum.EXCEL)) {
String fileKey = wpsUtil.wpsFileVariableReplace(wpsReplaceVariables, template.getFileCode(), template.getFileKey(), template.getTemplateName() + template.getFileType().getSuffix());
signFileDTO.setFileKey(fileKey);