Merge remote-tracking branch 'origin/master' into feature/dingdingLogin
This commit is contained in:
commit
ca2a2aca5c
@ -23,6 +23,8 @@ public enum FormInstanceRespCode implements IModuleRespCode {
|
||||
FORM_DATA_PARSE_ERROR_BY_IMAGE("008", "表单图片组件的数据解析异常"),
|
||||
FORM_DATA_PARSE_ERROR_BY_CUSTOM_COMPONENT("009", "表单自定义组件的数据解析异常"),
|
||||
FORM_DATA_PARSE_ERROR_BY_AMOUNT("010", "表单金额组件的数据解析异常"),
|
||||
FORM_DATA_PARSE_ERROR_BY_CHECKBOX("011", "表单复选框组件的数据解析异常"),
|
||||
FORM_DATA_PARSE_ERROR_BY_RADIO("012", "表单单选框组件的数据解析异常"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@ -3,8 +3,10 @@ package cn.axzo.workflow.common.enums;
|
||||
import cn.axzo.workflow.common.model.dto.AmountFieldDTO;
|
||||
import cn.axzo.workflow.common.model.dto.ContactsPersonDTO;
|
||||
import cn.axzo.workflow.common.model.dto.UploadFieldDTO;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -21,6 +23,7 @@ import java.util.Objects;
|
||||
* @author wangli
|
||||
* @since 2025-08-04 11:44
|
||||
*/
|
||||
@Slf4j
|
||||
public enum FormFieldTypeEnum {
|
||||
input("input", "文本", new TypeReference<String>() {
|
||||
}),
|
||||
@ -46,7 +49,10 @@ public enum FormFieldTypeEnum {
|
||||
}),
|
||||
decimal("decimal", "小数", new TypeReference<Map<String, Object>>() {
|
||||
}),
|
||||
;
|
||||
checkbox("checkbox", "复选框", new TypeReference<List<String>>() {
|
||||
}),
|
||||
radio("radio", "单选框", new TypeReference<String>() {
|
||||
});
|
||||
|
||||
private final String type;
|
||||
private final String desc;
|
||||
@ -113,7 +119,23 @@ public enum FormFieldTypeEnum {
|
||||
}
|
||||
return objectMapper.readValue(json, typeReference);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("字段值解析失败: " + fieldValue, e);
|
||||
log.warn("字段值解析失败: {}", fieldValue, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws JsonProcessingException {
|
||||
String json = "";
|
||||
FormFieldTypeEnum[] values = FormFieldTypeEnum.values();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
for (FormFieldTypeEnum value : values) {
|
||||
try {
|
||||
System.out.println(" type: " + value.getType());
|
||||
Object o = objectMapper.readValue(json, value.getTypeReference());
|
||||
System.out.println("o = " + o);
|
||||
} catch (Exception e) {
|
||||
System.out.println("e.getMessage() = " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ import java.util.Map;
|
||||
public class FormFieldDTO {
|
||||
|
||||
/**
|
||||
* 字段类型, 如果是分组:FormContainer,其他表单组件:FormField
|
||||
* 字段类型, 如果是分组:FormContainer,单选复选组件:OptionFormField,其他表单组件:FormField,
|
||||
*/
|
||||
@ApiModelProperty(value = "表单字段类型")
|
||||
@NotBlank(message = "字段类型不能为空")
|
||||
@ -41,6 +41,9 @@ public class FormFieldDTO {
|
||||
* { label: "变洽签单", value: "changeSignatureOrder" },
|
||||
* { label: "通讯录", value: "contacts" },
|
||||
* { label: "金额", value: "amount" },
|
||||
* { label: "复选", value: "checkbox" },
|
||||
* { label: "单选", value: "radio" },
|
||||
*
|
||||
*/
|
||||
@ApiModelProperty(value = "前端的组件类型")
|
||||
private String type;
|
||||
@ -76,6 +79,14 @@ public class FormFieldDTO {
|
||||
@ApiModelProperty(value = "该表单字段的其他扩展属性,期望 JSON 格式")
|
||||
private Map<String, Object> params;
|
||||
|
||||
/**
|
||||
* 单选复选框的选项
|
||||
* <p>
|
||||
* {@see org.flowable.form.model.OptionFormField}
|
||||
*/
|
||||
@ApiModelProperty(value = "单选复选框的选项,配合 fieldType=OptionFormField 使用")
|
||||
private List<OptionDTO> options;
|
||||
|
||||
/**
|
||||
* 当 fieldType=FormContainer 时,这里的代表内部的集合
|
||||
*/
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.axzo.workflow.common.model.request.form.definition;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 单选复选框的选项入参模型
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2025-11-20 10:57
|
||||
*/
|
||||
@ApiModel("单选复选框的选项入参模型")
|
||||
@Data
|
||||
public class OptionDTO {
|
||||
/**
|
||||
* 选项 ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 选项名称
|
||||
*/
|
||||
private String name;
|
||||
}
|
||||
@ -28,8 +28,14 @@ public class FormDataVO {
|
||||
* @return
|
||||
*/
|
||||
public Object getFormatDecimalValue() {
|
||||
if (Objects.isNull(fieldType)) {
|
||||
return null;
|
||||
}
|
||||
switch (fieldType) {
|
||||
case decimal:
|
||||
if (Objects.isNull(fieldValue)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> decimalMap = (Map<String, Object>) fieldValue;
|
||||
Object value = decimalMap.getOrDefault("value", "");
|
||||
if (Objects.isNull(value)) {
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.axzo.workflow.core.engine.cmd;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.engine.impl.util.CommandContextUtil;
|
||||
import org.flowable.form.api.FormEngineConfigurationApi;
|
||||
import org.flowable.form.api.FormInfo;
|
||||
import org.flowable.form.api.FormInstance;
|
||||
import org.flowable.form.api.FormRepositoryService;
|
||||
import org.flowable.form.api.FormService;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 通过审批实例 ID 获取对应的表单定义实体的自定义命令
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2025-11-20 10:18
|
||||
*/
|
||||
public class CustomGetFormModelByProcessInstanceIdCmd extends AbstractCommand<FormInfo> implements Serializable {
|
||||
private final String processInstanceId;
|
||||
|
||||
public CustomGetFormModelByProcessInstanceIdCmd(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 FormInfo executeInternal(CommandContext commandContext) {
|
||||
FormEngineConfigurationApi formEngineConfiguration = CommandContextUtil.getFormEngineConfiguration(commandContext);
|
||||
FormService formService = formEngineConfiguration.getFormService();
|
||||
|
||||
List<FormInstance> list = formService.createFormInstanceQuery().processInstanceId(processInstanceId).orderBySubmittedDate().desc().list();
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String formDefinitionId = list.get(0).getFormDefinitionId();
|
||||
FormRepositoryService formRepositoryService = formEngineConfiguration.getFormRepositoryService();
|
||||
return formRepositoryService.getFormModelById(formDefinitionId);
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.flowable.bpmn.model.FlowElement;
|
||||
import org.flowable.bpmn.model.Process;
|
||||
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
|
||||
@ -30,6 +31,8 @@ import org.flowable.form.api.FormService;
|
||||
import org.flowable.form.model.FormContainer;
|
||||
import org.flowable.form.model.FormField;
|
||||
import org.flowable.form.model.FormFieldTypes;
|
||||
import org.flowable.form.model.Option;
|
||||
import org.flowable.form.model.OptionFormField;
|
||||
import org.flowable.form.model.SimpleFormModel;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@ -47,9 +50,12 @@ import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.axzo.workflow.common.code.FormInstanceRespCode.FORM_DATA_PARSE_ERROR_BY_CHECKBOX;
|
||||
import static cn.axzo.workflow.common.code.FormInstanceRespCode.FORM_DATA_PARSE_ERROR_BY_RADIO;
|
||||
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.SEQUENCE_FLOW_ID;
|
||||
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;
|
||||
@ -79,7 +85,7 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
|
||||
|
||||
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", "date", "textarea", "image", "contacts", "amount", "decimal");
|
||||
private static final List<String> SUPPORTED_FORM_TYPES = Lists.newArrayList("input", "date", "textarea", "image", "contacts", "amount", "decimal", "checkbox", "radio");
|
||||
|
||||
public CustomGetProcessInstanceVariablesToObjectCmd(String processInstanceId) {
|
||||
this.processInstanceId = processInstanceId;
|
||||
@ -223,6 +229,39 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
|
||||
.type(convert(field.getType()))
|
||||
.build());
|
||||
}
|
||||
} else if (Objects.equals(field.getType(), "checkbox")) {
|
||||
if (field instanceof OptionFormField) {
|
||||
OptionFormField optionField = (OptionFormField) field;
|
||||
if (StringUtils.hasText(fieldValue.toString())
|
||||
&& fieldValue.toString().startsWith("[")
|
||||
&& fieldValue.toString().endsWith("]")) {
|
||||
List<String> selectedOptions = JSON.parseArray((String) fieldValue, String.class);
|
||||
List<String> optionNames = ListUtils.emptyIfNull(optionField.getOptions()).stream().filter(i -> selectedOptions.contains(i.getId())).map(Option::getName).collect(Collectors.toList());
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(field.getId())
|
||||
.desc(field.getName())
|
||||
.value(StringUtils.collectionToDelimitedString(optionNames, ";"))
|
||||
.type(convert(field.getType()))
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
throw new WorkflowEngineException(FORM_DATA_PARSE_ERROR_BY_CHECKBOX);
|
||||
}
|
||||
} else if (Objects.equals(field.getType(), "radio")) {
|
||||
if (field instanceof OptionFormField) {
|
||||
OptionFormField optionField = (OptionFormField) field;
|
||||
if (StringUtils.hasText(fieldValue.toString())) {
|
||||
List<String> optionNames = ListUtils.emptyIfNull(optionField.getOptions()).stream().filter(i -> Objects.equals(fieldValue, i.getId())).map(Option::getName).collect(Collectors.toList());
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(field.getId())
|
||||
.desc(field.getName())
|
||||
.value(StringUtils.collectionToDelimitedString(optionNames, ";"))
|
||||
.type(convert(field.getType()))
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
throw new WorkflowEngineException(FORM_DATA_PARSE_ERROR_BY_RADIO);
|
||||
}
|
||||
} else {
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(field.getId())
|
||||
@ -260,6 +299,9 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
|
||||
Map<String, SignatureDTO> signMap = signatures.stream().collect(Collectors.toMap(SignatureDTO::getActivityId, Function.identity(), (s, t) -> s));
|
||||
|
||||
bpmnElementMap.forEach((k, v) -> {
|
||||
if (k.contains(SEQUENCE_FLOW_ID)) {
|
||||
return;
|
||||
}
|
||||
SignatureDTO sign = signMap.getOrDefault(k, null);
|
||||
variables.add(VariableObjectDTO.builder()
|
||||
.key(Objects.nonNull(sign) ? sign.getActivityId() : v.getId())
|
||||
@ -336,6 +378,8 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
|
||||
case "amount":
|
||||
case "contacts":
|
||||
case "decimal":
|
||||
case "checkbox":
|
||||
case "radio":
|
||||
return VariableObjectDTO.Type.text;
|
||||
case "image":
|
||||
return VariableObjectDTO.Type.img;
|
||||
|
||||
@ -3,6 +3,7 @@ package cn.axzo.workflow.form.service.converter;
|
||||
import cn.axzo.workflow.common.model.request.form.definition.FormFieldDTO;
|
||||
import org.flowable.form.model.FormContainer;
|
||||
import org.flowable.form.model.FormField;
|
||||
import org.flowable.form.model.OptionFormField;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@ -34,6 +35,16 @@ public interface FormFieldConverter extends EntityConverter<FormFieldDTO, FormFi
|
||||
@Mapping(target = "params", source = "entity.params")
|
||||
FormFieldDTO toVo(FormField entity);
|
||||
|
||||
@Mapping(target = "fieldType", expression = "java(entity.getClass().getSimpleName())")
|
||||
@Mapping(target = "id", source = "entity.id")
|
||||
@Mapping(target = "name", source = "entity.name")
|
||||
@Mapping(target = "type", source = "entity.type")
|
||||
@Mapping(target = "value", expression = "java(ConversionUtils.convertObject(entity.getValue()))")
|
||||
@Mapping(target = "placeholder", source = "entity.placeholder")
|
||||
@Mapping(target = "params", source = "entity.params")
|
||||
@Mapping(target = "options", source = "entity.options")
|
||||
FormFieldDTO toVo(OptionFormField entity);
|
||||
|
||||
@Mapping(target = "fieldType", expression = "java(entity.getClass().getSimpleName())")
|
||||
@Mapping(target = "id", source = "entity.id")
|
||||
@Mapping(target = "name", source = "entity.name")
|
||||
@ -50,7 +61,9 @@ public interface FormFieldConverter extends EntityConverter<FormFieldDTO, FormFi
|
||||
for (FormField entity : entities) {
|
||||
if(entity instanceof FormContainer) {
|
||||
dtos.add(toVo((FormContainer) entity));
|
||||
} else{
|
||||
} else if (entity instanceof OptionFormField) {
|
||||
dtos.add(toVo((OptionFormField) entity));
|
||||
} else {
|
||||
dtos.add(toVo((FormField) entity));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
package cn.axzo.workflow.form.service.converter;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.form.definition.FormFieldDTO;
|
||||
import cn.axzo.workflow.common.model.request.form.definition.OptionDTO;
|
||||
import cn.axzo.workflow.common.model.response.form.instance.FormInstanceVO;
|
||||
import cn.axzo.workflow.common.model.response.form.model.FormModelVO;
|
||||
import org.flowable.form.api.FormInstanceInfo;
|
||||
import org.flowable.form.api.FormModel;
|
||||
import org.flowable.form.model.FormContainer;
|
||||
import org.flowable.form.model.FormField;
|
||||
import org.flowable.form.model.Option;
|
||||
import org.flowable.form.model.OptionFormField;
|
||||
import org.flowable.form.model.SimpleFormModel;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -64,6 +68,11 @@ public interface FormInstanceConverter extends EntityConverter<FormInstanceVO, F
|
||||
formFieldDTO.setValue(ConversionUtils.convertObject(formField.getValue()));
|
||||
formFieldDTO.setPlaceholder(formField.getPlaceholder());
|
||||
formFieldDTO.setParams(formField.getParams());
|
||||
if (formField instanceof OptionFormField) {
|
||||
OptionFormField optionFormField = (OptionFormField) formField;
|
||||
formFieldDTO.setFieldType(optionFormField.getClass().getSimpleName());
|
||||
formFieldDTO.setOptions(optionsToOptionDTOs(optionFormField.getOptions()));
|
||||
}
|
||||
if (formField instanceof FormContainer) {
|
||||
FormContainer formContainer = (FormContainer) formField;
|
||||
formFieldDTO.setFieldType(formContainer.getClass().getSimpleName());
|
||||
@ -72,6 +81,19 @@ public interface FormInstanceConverter extends EntityConverter<FormInstanceVO, F
|
||||
return formFieldDTO;
|
||||
}
|
||||
|
||||
default List<OptionDTO> optionsToOptionDTOs(List<Option> options) {
|
||||
if (CollectionUtils.isEmpty(options)) {
|
||||
return null;
|
||||
}
|
||||
return options.stream()
|
||||
.map(option -> {
|
||||
OptionDTO optionDTO = new OptionDTO();
|
||||
optionDTO.setId(option.getId());
|
||||
optionDTO.setName(option.getName());
|
||||
return optionDTO;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 辅助方法,用于处理List<FormContainer>到List<FormFieldDTO>的转换,调用上面自定义的转换方法
|
||||
default List<FormFieldDTO> formContainersToFormFieldDTOs(List<FormField> formContainers) {
|
||||
|
||||
@ -44,6 +44,15 @@ public class RpcExternalUtil {
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
public static <T> T rpcApiResultFProcessor(Supplier<cn.axzo.foundation.result.ApiResult<T>> supplier, String operationType, Object... param) {
|
||||
log.info(operationType + "-Param: " + JSONUtil.toJsonStr(param));
|
||||
cn.axzo.foundation.result.ApiResult<T> result = printLatency(supplier, operationType);
|
||||
log.info(operationType + "-Result: " + JSONUtil.toJsonStr(result));
|
||||
Assert.notNull(result, "服务调用异常");
|
||||
Assert.isTrue(result.getCode() == 200, "服务调用异常:" + result.getMsg());
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 常用的RPC请求返回值解析,如果 被请求方 返回非200会抛出异常
|
||||
*
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -2,13 +2,15 @@ package cn.axzo.workflow.server.controller.web.manage;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.maokai.api.client.OrganizationalNodeUserQueryApi;
|
||||
import cn.axzo.maokai.api.vo.request.OrgNodeUserBriefInfoListReq;
|
||||
import cn.axzo.maokai.api.vo.response.OrgNodeUserBriefInfoResp;
|
||||
import cn.axzo.nanopart.doc.api.conversion.DocConversionApi;
|
||||
import cn.axzo.nanopart.doc.api.conversion.req.QueryConversionTaskRequestV2;
|
||||
import cn.axzo.nanopart.doc.api.conversion.req.SubmitConversionTaskRequest;
|
||||
import cn.axzo.nanopart.doc.api.conversion.res.FileConvertResultResp;
|
||||
import cn.axzo.nanopart.doc.api.enums.DocConversionTypeEnum;
|
||||
import cn.axzo.orggateway.api.nodeuser.OrgNodeUserApi;
|
||||
import cn.axzo.orggateway.api.nodeuser.dto.OrgNodeUserDTO;
|
||||
import cn.axzo.orggateway.api.nodeuser.req.ListOrgNodeUserReq;
|
||||
import cn.axzo.orgmanax.dto.nodeuser.req.ListNodeUserReq;
|
||||
import cn.axzo.oss.http.api.ServerFileServiceApi;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlDownloadRequest;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlDownloadResponse;
|
||||
@ -39,6 +41,7 @@ import cn.axzo.workflow.common.model.response.print.ProcessLogPdfResultDTO;
|
||||
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
||||
import cn.axzo.workflow.core.conf.SupportRefreshProperties;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomGetFormInstanceLatestValuesCmd;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomGetFormModelByProcessInstanceIdCmd;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomGetProcessInstanceVariablesCmd;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxProcessLog;
|
||||
import cn.axzo.workflow.core.service.BpmnProcessDefinitionService;
|
||||
@ -68,6 +71,8 @@ import org.flowable.form.api.FormRepositoryService;
|
||||
import org.flowable.form.model.FormContainer;
|
||||
import org.flowable.form.model.FormField;
|
||||
import org.flowable.form.model.FormFieldTypes;
|
||||
import org.flowable.form.model.Option;
|
||||
import org.flowable.form.model.OptionFormField;
|
||||
import org.flowable.form.model.SimpleFormModel;
|
||||
import org.flowable.spring.SpringProcessEngineConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
@ -187,7 +192,8 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
private SupportRefreshProperties refreshProperties;
|
||||
@Resource
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
@Resource
|
||||
private OrgNodeUserApi orgNodeUserApi;
|
||||
/**
|
||||
* 查询指定流程实例是否能使用打印
|
||||
*
|
||||
@ -406,21 +412,30 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
// 生成系统字段的变量
|
||||
generateSystemFieldVariables(processInstanceId, result);
|
||||
|
||||
FormInfo formInfo = commandExecutor.execute(new CustomGetFormModelByProcessInstanceIdCmd(processInstanceId));
|
||||
// 将所有变量都转换成 JSON 对象返回
|
||||
convertValueToObject(result);
|
||||
convertValueToObject(result, formInfo);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
private void convertValueToObject(Map<String, Object> result) {
|
||||
if (CollectionUtils.isEmpty(result)) {
|
||||
private void convertValueToObject(Map<String, Object> result, FormInfo formInfo) {
|
||||
if (CollectionUtils.isEmpty(result) || Objects.isNull(formInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, FormField> stringFormFieldMap = ((SimpleFormModel) formInfo.getFormModel()).allFieldsAsMap();
|
||||
result.forEach((key, value) -> {
|
||||
if (!(value instanceof String)) {
|
||||
return;
|
||||
}
|
||||
if (((String) value).startsWith("[")) {
|
||||
|
||||
if (stringFormFieldMap.containsKey(key) && stringFormFieldMap.get(key) instanceof OptionFormField) {
|
||||
OptionFormField optionFormField = (OptionFormField) stringFormFieldMap.get(key);
|
||||
if (Objects.equals("checkbox", optionFormField.getType())) {
|
||||
result.put(key, buildOptionFieldValue(optionFormField, JSONObject.parseArray((String) value, String.class)));
|
||||
} else if (Objects.equals("radio", optionFormField.getType())) {
|
||||
result.put(key, buildOptionFieldValue(optionFormField, Lists.newArrayList((String) value)));
|
||||
}
|
||||
} else if (((String) value).startsWith("[")) {
|
||||
result.put(key, JSONArray.parseArray((String) value));
|
||||
} else if (((String) value).startsWith("{")) {
|
||||
result.put(key, JSONObject.parseObject((String) value));
|
||||
@ -428,6 +443,16 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
});
|
||||
}
|
||||
|
||||
private String buildOptionFieldValue(OptionFormField optionFormField, List<String> selectedValues) {
|
||||
if (CollectionUtils.isEmpty(optionFormField.getOptions())) {
|
||||
return "";
|
||||
}
|
||||
return optionFormField.getOptions().stream()
|
||||
.filter(i -> selectedValues.contains(i.getId()))
|
||||
.map(Option::getName)
|
||||
.collect(Collectors.joining(";"));
|
||||
}
|
||||
|
||||
private void generateSystemFieldVariables(String processInstanceId, Map<String, Object> result) {
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
Map<String, Object> variables = commandExecutor.execute(new CustomGetProcessInstanceVariablesCmd(processInstanceId));
|
||||
@ -435,11 +460,11 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
// 解析发起人
|
||||
BpmnTaskDelegateAssigner initiator = BpmnTaskDelegateAssigner.toObjectCompatible(variables.getOrDefault(PRINT_VAR_PROCESS_INITIATOR, null));
|
||||
if (Objects.nonNull(initiator)) {
|
||||
Optional<OrgNodeUserBriefInfoResp> user = getUserInfo(initiator);
|
||||
Optional<OrgNodeUserDTO> user = getUserInfo(initiator);
|
||||
variables.put(PRINT_VAR_PROCESS_INITIATOR_NAME, user.isPresent() ? user.get().getRealName() : "");
|
||||
variables.put(PRINT_VAR_PROCESS_INITIATOR_POSITION, user.isPresent() && Objects.nonNull(user.get().getJob()) ? user.get().getJob().getName() : "");
|
||||
variables.put(PRINT_VAR_PROCESS_INITIATOR_PHONE, user.isPresent() ? user.get().getProfile().getPhone() : "");
|
||||
variables.put(PRINT_VAR_PROCESS_INITIATOR_UNIT, user.isPresent() ? user.get().getOrganizationalUnitName() : "");
|
||||
variables.put(PRINT_VAR_PROCESS_INITIATOR_PHONE, user.isPresent() ? user.get().getPersonProfile().getPhone() : "");
|
||||
variables.put(PRINT_VAR_PROCESS_INITIATOR_UNIT, user.isPresent() ? user.get().getUnit().getName() : "");
|
||||
variables.remove(PRINT_VAR_PROCESS_INITIATOR);
|
||||
}
|
||||
// 填充审批日志
|
||||
@ -456,9 +481,9 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
Map<String, Object> taskLogMap = new HashMap<>();
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_ACTIVITY_NAME, taskLog.getName());
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_ACTIVITY_NODE_TYPE, taskLog.getNodeType().getType());
|
||||
Optional<OrgNodeUserBriefInfoResp> user = getUserInfo(taskLog.getAssigneeSnapshot());
|
||||
Optional<OrgNodeUserDTO> user = getUserInfo(taskLog.getAssigneeSnapshot());
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_APPROVER_NAME, user.isPresent() ? user.get().getRealName() : "");
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_UNIT, user.isPresent() ? user.get().getOrganizationalUnitName() : "");
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_UNIT, user.isPresent() ? user.get().getUnit().getName() : "");
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_POSITION, user.isPresent() && Objects.nonNull(user.get().getJob()) ? user.get().getJob().getName() : "");
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_ADVICE, taskLog.getAdvice());
|
||||
taskLogMap.put(PRINT_VAR_PROCESS_LOG_OPERATION, taskLog.getOperationDesc());
|
||||
@ -471,35 +496,34 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
result.putAll(variables);
|
||||
}
|
||||
|
||||
private Optional<OrgNodeUserBriefInfoResp> getUserInfo(BpmnTaskDelegateAssigner assigner) {
|
||||
private Optional<OrgNodeUserDTO> getUserInfo(BpmnTaskDelegateAssigner assigner) {
|
||||
if (Objects.isNull(assigner)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
OrgNodeUserBriefInfoListReq req = new OrgNodeUserBriefInfoListReq();
|
||||
ListOrgNodeUserReq req = new ListOrgNodeUserReq();
|
||||
if (StringUtils.hasText(assigner.getTenantId()) && !Objects.equals(assigner.getTenantId(), "null")) {
|
||||
req.setWorkspaceId(Long.valueOf(assigner.getTenantId()));
|
||||
}
|
||||
if (StringUtils.hasText(assigner.getOuId()) && !Objects.equals(assigner.getTenantId(), "null")) {
|
||||
req.setOuId(Long.valueOf(assigner.getOuId()));
|
||||
if (StringUtils.hasText(assigner.getOuId()) && !Objects.equals(assigner.getOuId(), "null")) {
|
||||
req.setOrganizationalUnitId(Long.valueOf(assigner.getOuId()));
|
||||
}
|
||||
if (StringUtils.hasText(assigner.getNodeId()) && !Objects.equals(assigner.getTenantId(), "null")) {
|
||||
req.setOrgNodeIds(Lists.newArrayList(Long.valueOf(assigner.getNodeId())));
|
||||
if (StringUtils.hasText(assigner.getNodeId()) && !Objects.equals(assigner.getNodeId(), "null")) {
|
||||
req.setAncestorNodeIds(Lists.newArrayList(Long.valueOf(assigner.getNodeId())));
|
||||
}
|
||||
if (StringUtils.hasText(assigner.getPersonId()) && !Objects.equals(assigner.getTenantId(), "null")) {
|
||||
if (StringUtils.hasText(assigner.getPersonId()) && !Objects.equals(assigner.getPersonId(), "null")) {
|
||||
req.setPersonIds(Lists.newArrayList(Long.valueOf(assigner.getPersonId())));
|
||||
}
|
||||
req.setNeedJob(true);
|
||||
req.setNeedUnit(true);
|
||||
req.setNeedProfile(true);
|
||||
req.setContainsExited(true);
|
||||
List<OrgNodeUserBriefInfoResp> users = RpcExternalUtil.rpcApiResultProcessor(() -> organizationalNodeUserQueryApi.listOrgNodeUsers(req),
|
||||
"查询审批人员组织信息", req);
|
||||
req.setNeeds(ListNodeUserReq.Needs.builder().job(true).unit(true).personProfile(true).build());
|
||||
req.setIncludeDeleted(true);
|
||||
|
||||
List<OrgNodeUserDTO> users = RpcExternalUtil.rpcApiResultFProcessor(() -> orgNodeUserApi.list(req), "查询审批人员组织信息", req).getData();
|
||||
// RpcExternalUtil.rpcApiResultProcessor(() -> orgNodeUserApi.list(req), "查询审批人员组织信息", req);
|
||||
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return users.stream().sorted(Comparator.comparing(OrgNodeUserBriefInfoResp::getExited).reversed())
|
||||
return users.stream().sorted(Comparator.comparing(OrgNodeUserDTO::getIsDelete).reversed())
|
||||
.collect(Collectors.toList()).stream().findFirst();
|
||||
}
|
||||
|
||||
@ -527,7 +551,7 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
// 解析发起人
|
||||
BpmnTaskDelegateAssigner initiator = BpmnTaskDelegateAssigner.toObjectCompatible(variables.getOrDefault(PRINT_VAR_PROCESS_INITIATOR, null));
|
||||
if (Objects.nonNull(initiator)) {
|
||||
Optional<OrgNodeUserBriefInfoResp> user = getUserInfo(initiator);
|
||||
Optional<OrgNodeUserDTO> user = getUserInfo(initiator);
|
||||
systemVarItems.add(TableItemDTO.builder()
|
||||
.label(PRINT_VAR_PROCESS_INITIATOR_NAME_DESC)
|
||||
.code(PRINT_VAR_PROCESS_INITIATOR_NAME)
|
||||
@ -538,7 +562,7 @@ public class PrintAdminController implements PrintAdminApi {
|
||||
.label(PRINT_VAR_PROCESS_INITIATOR_UNIT_DESC)
|
||||
.code(PRINT_VAR_PROCESS_INITIATOR_UNIT)
|
||||
.type(FORM_FIELD_TYPE_INPUT)
|
||||
.value(user.isPresent() ? user.get().getOrganizationalUnitName() : "")
|
||||
.value(user.isPresent() ? user.get().getUnit().getName() : "")
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user