feat(REQ-3340) - 优化解析表单实例数据的逻辑
This commit is contained in:
parent
475759a9cc
commit
e5a92af9ec
@ -298,61 +298,26 @@ public class CustomGetFormInstanceModelCmd extends GetFormInstanceModelCmd {
|
||||
}
|
||||
} else if (FORM_FIELD_TYPE_CUSTOM_COMPONENT.equals(field.getType())) {
|
||||
String listJson = (String) variables.get(field.getId());
|
||||
ObjectMapper objectMapper = formEngineConfiguration.getObjectMapper();
|
||||
try {
|
||||
List<Map> rows = objectMapper.readValue(listJson, new TypeReference<List<Map>>() {
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(rows)) {
|
||||
List<List<FormField>> fields = ((FormContainer) field).getFields();
|
||||
if (rows.size() == 1) {
|
||||
fields.get(0).forEach(sf -> {
|
||||
if (FORM_FIELD_TYPE_INPUT.equals(sf.getType())
|
||||
|| FORM_FIELD_TYPE_TEXTAREA.equals(sf.getType())) {
|
||||
if (rows.get(0).containsKey(sf.getId())) {
|
||||
sf.setValue(rows.get(0).get(sf.getId()));
|
||||
}
|
||||
} else if (FormFieldTypes.UPLOAD.equals(sf.getType())
|
||||
|| FORM_FIELD_TYPE_IMAGE.equals(sf.getType())) {
|
||||
if (rows.get(0).containsKey(sf.getId())) {
|
||||
|
||||
try {
|
||||
String updateValueJson = objectMapper.writeValueAsString(rows.get(0).get(sf.getId()));
|
||||
if (updateValueJson != null) {
|
||||
List<UploadFieldDTO> uploadFiles = formEngineConfiguration.getObjectMapper()
|
||||
.readValue(updateValueJson, new TypeReference<List<UploadFieldDTO>>() {
|
||||
});
|
||||
sf.setValue(uploadFiles);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new FlowableException("Error parsing upload files json ", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 根据传入的表单自定义组件数据,构建表单模型,Field 是二维数组,一维用于行,二维用于列
|
||||
for (int i = 1; i < rows.size(); i++) {
|
||||
List<FormField> newRow = new ArrayList<>();
|
||||
fields.get(0).forEach(e -> {
|
||||
newRow.add(FormFieldClone.clone(e));
|
||||
});
|
||||
fields.add(newRow);
|
||||
}
|
||||
// 为每行赋值
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
Map<String, Object> rowMap = rows.get(i);
|
||||
fields.get(i).forEach(sf -> {
|
||||
if (listJson != null) {
|
||||
ObjectMapper objectMapper = formEngineConfiguration.getObjectMapper();
|
||||
try {
|
||||
List<Map> rows = objectMapper.readValue(listJson, new TypeReference<List<Map>>() {
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(rows)) {
|
||||
List<List<FormField>> fields = ((FormContainer) field).getFields();
|
||||
if (rows.size() == 1) {
|
||||
fields.get(0).forEach(sf -> {
|
||||
if (FORM_FIELD_TYPE_INPUT.equals(sf.getType())
|
||||
|| FORM_FIELD_TYPE_TEXTAREA.equals(sf.getType())) {
|
||||
if (rowMap.containsKey(sf.getId())) {
|
||||
sf.setValue(rowMap.get(sf.getId()));
|
||||
if (rows.get(0).containsKey(sf.getId())) {
|
||||
sf.setValue(rows.get(0).get(sf.getId()));
|
||||
}
|
||||
} else if (FormFieldTypes.UPLOAD.equals(sf.getType())
|
||||
|| FORM_FIELD_TYPE_IMAGE.equals(sf.getType())) {
|
||||
if (rowMap.containsKey(sf.getId())) {
|
||||
if (rows.get(0).containsKey(sf.getId())) {
|
||||
|
||||
try {
|
||||
String updateValueJson = objectMapper.writeValueAsString(rowMap.get(sf.getId()));
|
||||
String updateValueJson = objectMapper.writeValueAsString(rows.get(0).get(sf.getId()));
|
||||
if (updateValueJson != null) {
|
||||
List<UploadFieldDTO> uploadFiles = formEngineConfiguration.getObjectMapper()
|
||||
.readValue(updateValueJson, new TypeReference<List<UploadFieldDTO>>() {
|
||||
@ -362,14 +327,51 @@ public class CustomGetFormInstanceModelCmd extends GetFormInstanceModelCmd {
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new FlowableException("Error parsing upload files json ", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 根据传入的表单自定义组件数据,构建表单模型,Field 是二维数组,一维用于行,二维用于列
|
||||
for (int i = 1; i < rows.size(); i++) {
|
||||
List<FormField> newRow = new ArrayList<>();
|
||||
fields.get(0).forEach(e -> {
|
||||
newRow.add(FormFieldClone.clone(e));
|
||||
});
|
||||
fields.add(newRow);
|
||||
}
|
||||
// 为每行赋值
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
Map<String, Object> rowMap = rows.get(i);
|
||||
fields.get(i).forEach(sf -> {
|
||||
if (FORM_FIELD_TYPE_INPUT.equals(sf.getType())
|
||||
|| FORM_FIELD_TYPE_TEXTAREA.equals(sf.getType())) {
|
||||
if (rowMap.containsKey(sf.getId())) {
|
||||
sf.setValue(rowMap.get(sf.getId()));
|
||||
}
|
||||
} else if (FormFieldTypes.UPLOAD.equals(sf.getType())
|
||||
|| FORM_FIELD_TYPE_IMAGE.equals(sf.getType())) {
|
||||
if (rowMap.containsKey(sf.getId())) {
|
||||
try {
|
||||
String updateValueJson = objectMapper.writeValueAsString(rowMap.get(sf.getId()));
|
||||
if (updateValueJson != null) {
|
||||
List<UploadFieldDTO> uploadFiles = formEngineConfiguration.getObjectMapper()
|
||||
.readValue(updateValueJson, new TypeReference<List<UploadFieldDTO>>() {
|
||||
});
|
||||
sf.setValue(uploadFiles);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new FlowableException("Error parsing upload files json ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new WorkflowEngineException(FORM_DATA_PARSE_ERROR_BY_CUSTOM_COMPONENT);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new WorkflowEngineException(FORM_DATA_PARSE_ERROR_BY_CUSTOM_COMPONENT);
|
||||
}
|
||||
} else {
|
||||
Object variableValue = variables.get(field.getId());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user