Skip to content

Commit 854f9ca

Browse files
committed
update FlowForm.java
1 parent 3aa8d6d commit 854f9ca

50 files changed

Lines changed: 334 additions & 294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormMeta.java renamed to flow-engine-framework/src/main/java/com/codingapi/flow/form/FlowForm.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
@Setter
1515
@Getter
16-
public class FormMeta {
16+
public class FlowForm {
1717

1818
/**
1919
* 表单名称
@@ -26,12 +26,12 @@ public class FormMeta {
2626
/**
2727
* 表单字段
2828
*/
29-
private List<FormFieldMeta> fields;
29+
private List<FormField> fields;
3030

3131
/**
3232
* 子表单
3333
*/
34-
private List<FormMeta> subForms;
34+
private List<FlowForm> subForms;
3535

3636

3737
public boolean isSubForm(String formCode) {
@@ -50,19 +50,19 @@ public Map<String, Object> toMap() {
5050
map.put("code", code);
5151
map.put("fields", fields);
5252
if (subForms != null && !subForms.isEmpty()) {
53-
map.put("subForms", subForms.stream().map(FormMeta::toMap).toList());
53+
map.put("subForms", subForms.stream().map(FlowForm::toMap).toList());
5454
}
5555
return map;
5656
}
5757

5858
@SuppressWarnings("unchecked")
59-
public static FormMeta fromMap(Map<String, Object> map) {
60-
FormMeta form = new FormMeta();
59+
public static FlowForm fromMap(Map<String, Object> map) {
60+
FlowForm form = new FlowForm();
6161
List<Map<String, Object>> fields = (List<Map<String, Object>>) map.get("fields");
62-
List<FormFieldMeta> fieldList = new ArrayList<>();
62+
List<FormField> fieldList = new ArrayList<>();
6363
if (fields != null && !fields.isEmpty()) {
6464
for (Map<String, Object> field : fields) {
65-
FormFieldMeta fieldMeta = new FormFieldMeta();
65+
FormField fieldMeta = new FormField();
6666
fieldMeta.setId((String) field.get("id"));
6767
fieldMeta.setName((String) field.get("name"));
6868
fieldMeta.setCode((String) field.get("code"));
@@ -78,7 +78,7 @@ public static FormMeta fromMap(Map<String, Object> map) {
7878

7979
List<Map<String, Object>> subForms = (List<Map<String, Object>>) map.get("subForms");
8080
if (subForms != null) {
81-
List<FormMeta> subFormList = new ArrayList<>();
81+
List<FlowForm> subFormList = new ArrayList<>();
8282
for (Map<String, Object> subForm : subForms) {
8383
subFormList.add(fromMap(subForm));
8484
}
@@ -91,7 +91,7 @@ public static FormMeta fromMap(Map<String, Object> map) {
9191
* 获取表单字段名称
9292
*/
9393
public List<String> loadFieldNames() {
94-
return fields.stream().map(FormFieldMeta::getName).toList();
94+
return fields.stream().map(FormField::getName).toList();
9595
}
9696

9797
/**
@@ -100,12 +100,12 @@ public List<String> loadFieldNames() {
100100
* @param fieldName 字段名称
101101
* @return 表单字段
102102
*/
103-
public FormFieldMeta getField(String fieldName) {
103+
public FormField getField(String fieldName) {
104104
return fields.stream().filter(field -> field.getName().equals(fieldName)).findFirst().orElse(null);
105105
}
106106

107-
private void initFormFieldTypes(FormMeta form, Map<String, String> types) {
108-
for (FormFieldMeta field : form.getFields()) {
107+
private void initFormFieldTypes(FlowForm form, Map<String, String> types) {
108+
for (FormField field : form.getFields()) {
109109
String key = form.getCode() + "." + field.getCode();
110110
String type = field.getType();
111111
types.put(key, type);
@@ -119,12 +119,12 @@ private void initFormFieldTypes(FormMeta form, Map<String, String> types) {
119119
*/
120120
public Map<String, String> loadAllFieldTypeMaps() {
121121
Map<String, String> types = new HashMap<>();
122-
List<FormMeta> forms = this.getSubForms();
122+
List<FlowForm> forms = this.getSubForms();
123123
if (forms == null) {
124124
forms = new ArrayList<>();
125125
}
126126
forms.add(this);
127-
for (FormMeta subForm : forms) {
127+
for (FlowForm subForm : forms) {
128128
this.initFormFieldTypes(subForm, types);
129129
}
130130
return types;
@@ -138,15 +138,15 @@ public Map<String, String> loadAllFieldTypeMaps() {
138138
*/
139139
public Map<String, String> loadMainFieldTypeMaps() {
140140
Map<String, String> types = new HashMap<>();
141-
List<FormMeta> forms = new ArrayList<>();
141+
List<FlowForm> forms = new ArrayList<>();
142142
forms.add(this);
143-
for (FormMeta subForm : forms) {
143+
for (FlowForm subForm : forms) {
144144
this.initFormFieldTypes(subForm, types);
145145
}
146146
return types;
147147
}
148148

149-
public FormMeta getSubForm(String formCode) {
149+
public FlowForm getSubForm(String formCode) {
150150
return this.subForms.stream().filter(form -> form.getCode().equals(formCode)).findFirst().orElse(null);
151151
}
152152
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.codingapi.flow.form;
2+
3+
import java.util.ArrayList;
4+
5+
public class FlowFormBuilder {
6+
7+
private FlowForm flowForm = new FlowForm();
8+
9+
private FlowFormBuilder() {
10+
}
11+
12+
public static FlowFormBuilder builder() {
13+
return new FlowFormBuilder();
14+
}
15+
16+
public FlowFormBuilder name(String name) {
17+
flowForm.setName(name);
18+
return this;
19+
}
20+
21+
public FlowFormBuilder code(String code) {
22+
flowForm.setCode(code);
23+
return this;
24+
}
25+
26+
public FlowFormBuilder addField(String name, String code, String type) {
27+
FormField field = new FormField();
28+
field.setName(name);
29+
field.setCode(code);
30+
field.setType(type);
31+
field.setRequired(true);
32+
field.setDefaultValue(null);
33+
return this.addField(field);
34+
}
35+
36+
public FlowFormBuilder addField(FormField field) {
37+
if (flowForm.getFields() == null) {
38+
flowForm.setFields(new ArrayList<>());
39+
}
40+
flowForm.getFields().add(field);
41+
return this;
42+
}
43+
44+
public FlowFormBuilder addSubForm(FlowForm subForm) {
45+
if (flowForm.getSubForms() == null) {
46+
flowForm.setSubForms(new ArrayList<>());
47+
}
48+
flowForm.getSubForms().add(subForm);
49+
return this;
50+
}
51+
52+
public FlowForm build() {
53+
FlowForm result = flowForm;
54+
flowForm = new FlowForm();
55+
return result;
56+
}
57+
}

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormData.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ public class FormData {
1111

1212
// 当前表单的元数据定义
1313
@Getter
14-
private final FormMeta formMeta;
14+
private final FlowForm flowForm;
1515
// 主表单数据内容
1616
@Getter
1717
private final DataBody dataBody;
1818
// 子表单数据内容
1919
private final Map<String, List<DataBody>> subDataBody;
2020

2121

22-
public FormData(FormMeta form) {
23-
this.formMeta = form;
22+
public FormData(FlowForm form) {
23+
this.flowForm = form;
2424
this.dataBody = new DataBody(form);
2525
this.subDataBody = new HashMap<>();
2626
}
@@ -40,11 +40,11 @@ public int countSubDataBody() {
4040
* @param formCode 子表单编号
4141
*/
4242
public DataBody addSubDataBody(String formCode) {
43-
FormMeta subFormMeta = getSubFormMeta(formCode);
44-
if (subFormMeta == null) {
43+
FlowForm subFlowForm = getSubFormMeta(formCode);
44+
if (subFlowForm == null) {
4545
return null;
4646
}
47-
DataBody subData = new DataBody(subFormMeta);
47+
DataBody subData = new DataBody(subFlowForm);
4848
List<DataBody> list = this.getSubDataBody(formCode);
4949
if (list == null) {
5050
list = new ArrayList<>();
@@ -108,22 +108,22 @@ public Map<String, Object> toMapData() {
108108
*
109109
* @param formCode 子表单编号
110110
*/
111-
private FormMeta getSubFormMeta(String formCode) {
112-
return formMeta.getSubForm(formCode);
111+
private FlowForm getSubFormMeta(String formCode) {
112+
return flowForm.getSubForm(formCode);
113113
}
114114

115115
/**
116116
* 表单数据体
117117
*/
118118
public static class DataBody {
119-
private final FormMeta formMeta;
119+
private final FlowForm flowForm;
120120
private final Map<String, Object> data;
121121
private final Map<String, String> fieldTypes;
122122

123-
public DataBody(FormMeta formMeta) {
124-
this.formMeta = formMeta;
123+
public DataBody(FlowForm flowForm) {
124+
this.flowForm = flowForm;
125125
this.data = new HashMap<>();
126-
this.fieldTypes = formMeta.loadMainFieldTypeMaps();
126+
this.fieldTypes = flowForm.loadMainFieldTypeMaps();
127127
}
128128

129129

@@ -141,7 +141,7 @@ public void reset() {
141141
* @param value 表单字段值
142142
*/
143143
public DataBody set(String key, Object value) {
144-
String id = formMeta.getCode() + "." + key;
144+
String id = flowForm.getCode() + "." + key;
145145
String type = this.fieldTypes.get(id);
146146
if (type == null) {
147147
throw new RuntimeException("key:" + key + " not found");
@@ -157,7 +157,7 @@ public DataBody set(String key, Object value) {
157157
* @return 表单字段值
158158
*/
159159
public Object get(String key) {
160-
String id = formMeta.getCode() + "." + key;
160+
String id = flowForm.getCode() + "." + key;
161161
return this.data.get(id);
162162
}
163163

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormFieldMeta.java renamed to flow-engine-framework/src/main/java/com/codingapi/flow/form/FormField.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* 表单字段元数据
88
*/
99
@Data
10-
public class FormFieldMeta {
10+
public class FormField {
1111

1212
// 字段编号
1313
private String id;
@@ -22,7 +22,7 @@ public class FormFieldMeta {
2222
// 默认值
2323
private String defaultValue;
2424

25-
public FormFieldMeta() {
25+
public FormField() {
2626
this.id = RandomUtils.generateStringId();
2727
}
2828

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormMetaBuilder.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

flow-engine-framework/src/main/java/com/codingapi/flow/manager/ActionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.codingapi.flow.action.IFlowAction;
44
import com.codingapi.flow.action.actions.*;
55
import com.codingapi.flow.exception.FlowValidationException;
6-
import com.codingapi.flow.form.FormMeta;
6+
import com.codingapi.flow.form.FlowForm;
77
import com.codingapi.flow.node.IFlowNode;
88
import com.codingapi.flow.node.nodes.ApprovalNode;
99
import com.codingapi.flow.node.nodes.EndNode;
@@ -54,7 +54,7 @@ public IFlowAction getActionById(String id) {
5454
return null;
5555
}
5656

57-
public void verify(FormMeta form) {
57+
public void verify(FlowForm form) {
5858

5959
}
6060

flow-engine-framework/src/main/java/com/codingapi/flow/manager/NodeStrategyManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.codingapi.flow.action.actions.PassAction;
55
import com.codingapi.flow.error.ErrorThrow;
66
import com.codingapi.flow.exception.FlowValidationException;
7-
import com.codingapi.flow.form.FormMeta;
7+
import com.codingapi.flow.form.FlowForm;
88
import com.codingapi.flow.session.FlowAdvice;
99
import com.codingapi.flow.session.FlowSession;
1010
import com.codingapi.flow.strategy.node.*;
@@ -133,7 +133,7 @@ public float getMultiOperatorAuditMergePercent() {
133133
return 0;
134134
}
135135

136-
public void verifyNode(FormMeta form) {
136+
public void verifyNode(FlowForm form) {
137137
for (INodeStrategy strategy : strategies) {
138138
strategy.verifyNode(form);
139139
}

flow-engine-framework/src/main/java/com/codingapi/flow/node/BaseAuditNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.codingapi.flow.action.IFlowAction;
44
import com.codingapi.flow.error.ErrorThrow;
55
import com.codingapi.flow.exception.FlowValidationException;
6-
import com.codingapi.flow.form.FormMeta;
6+
import com.codingapi.flow.form.FlowForm;
77
import com.codingapi.flow.manager.NodeStrategyManager;
88
import com.codingapi.flow.manager.OperatorManager;
99
import com.codingapi.flow.operator.IFlowOperator;
@@ -46,7 +46,7 @@ public Map<String, Object> toMap() {
4646
}
4747

4848

49-
public void verifyNode(FormMeta form) {
49+
public void verifyNode(FlowForm form) {
5050
super.verifyNode(form);
5151
if (!StringUtils.hasText(view)) {
5252
throw FlowValidationException.nodeRequired("view");

0 commit comments

Comments
 (0)