Skip to content

Commit daf819d

Browse files
authored
Merge pull request #58 from codingapi/dev
Dev
2 parents ba90d08 + 0abec0f commit daf819d

192 files changed

Lines changed: 4497 additions & 1946 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.

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
default nodejs 22
22
nodejs 22.22.0
3-
java openjdk-22
3+
java adoptopenjdk-17.0.17+10

flow-engine-framework/src/main/java/com/codingapi/flow/action/actions/PassAction.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public void run(FlowSession flowSession) {
7070
List<FlowRecord> recordList = new ArrayList<>();
7171
FlowRecord currentRecord = flowSession.getCurrentRecord();
7272
IFlowNode currentNode = flowSession.getCurrentNode();
73-
boolean done = currentNode.isDone(flowSession);
74-
currentRecord.update(flowSession, done);
73+
boolean isFinish = currentNode.isFinish(flowSession);
74+
currentRecord.update(flowSession, true);
7575
// 添加流程结束事件
7676
flowEvents.add(new FlowRecordDoneEvent(currentRecord));
7777
recordList.add(currentRecord);
@@ -89,7 +89,7 @@ public void run(FlowSession flowSession) {
8989
}
9090
}
9191

92-
if (done) {
92+
if (isFinish) {
9393
// 是否转交审批人的流程
9494
if (currentRecord.isForward()) {
9595
IFlowOperator forwardOperator = RepositoryHolderContext.getInstance().getOperatorById(currentRecord.getForwardOperatorId());
@@ -127,7 +127,6 @@ public void run(FlowSession flowSession) {
127127
});
128128
}
129129
}
130-
131130
RepositoryHolderContext.getInstance().saveRecords(recordList);
132131

133132
flowEvents.forEach(EventPusher::push);

flow-engine-framework/src/main/java/com/codingapi/flow/action/actions/RejectAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.codingapi.flow.event.FlowRecordTodoEvent;
99
import com.codingapi.flow.event.IFlowEvent;
1010
import com.codingapi.flow.exception.FlowStateException;
11-
import com.codingapi.flow.exception.FlowValidationException;
1211
import com.codingapi.flow.node.IFlowNode;
1312
import com.codingapi.flow.record.FlowRecord;
1413
import com.codingapi.flow.script.action.RejectActionScript;

flow-engine-framework/src/main/java/com/codingapi/flow/backup/WorkflowBackup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public WorkflowBackup(Workflow workflow) {
4747
this.workCode = workflow.getCode();
4848
this.workTitle = workflow.getTitle();
4949
this.createTime = System.currentTimeMillis();
50-
this.workVersion = workflow.getCreatedTime();
50+
this.workVersion = workflow.getUpdatedTime();
5151
}
5252

5353

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codingapi.flow.form;
2+
3+
public enum DataType {
4+
STRING,
5+
NUMBER,
6+
DATE,
7+
BOOLEAN
8+
}

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: 27 additions & 24 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,25 +50,28 @@ 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"));
69-
fieldMeta.setType((String) field.get("type"));
69+
fieldMeta.setType(DataType.valueOf((String) field.get("type")));
7070
fieldMeta.setRequired(Boolean.TRUE.equals(field.get("required")));
7171
fieldMeta.setDefaultValue((String) field.get("defaultValue"));
72+
fieldMeta.setPlaceholder((String) field.get("placeholder"));
73+
fieldMeta.setTooltip((String) field.get("tooltip"));
74+
fieldMeta.setHelp((String) field.get("help"));
7275
fieldList.add(fieldMeta);
7376
}
7477
}
@@ -78,7 +81,7 @@ public static FormMeta fromMap(Map<String, Object> map) {
7881

7982
List<Map<String, Object>> subForms = (List<Map<String, Object>>) map.get("subForms");
8083
if (subForms != null) {
81-
List<FormMeta> subFormList = new ArrayList<>();
84+
List<FlowForm> subFormList = new ArrayList<>();
8285
for (Map<String, Object> subForm : subForms) {
8386
subFormList.add(fromMap(subForm));
8487
}
@@ -91,7 +94,7 @@ public static FormMeta fromMap(Map<String, Object> map) {
9194
* 获取表单字段名称
9295
*/
9396
public List<String> loadFieldNames() {
94-
return fields.stream().map(FormFieldMeta::getName).toList();
97+
return fields.stream().map(FormField::getName).toList();
9598
}
9699

97100
/**
@@ -100,14 +103,14 @@ public List<String> loadFieldNames() {
100103
* @param fieldName 字段名称
101104
* @return 表单字段
102105
*/
103-
public FormFieldMeta getField(String fieldName) {
106+
public FormField getField(String fieldName) {
104107
return fields.stream().filter(field -> field.getName().equals(fieldName)).findFirst().orElse(null);
105108
}
106109

107-
private void initFormFieldTypes(FormMeta form, Map<String, String> types) {
108-
for (FormFieldMeta field : form.getFields()) {
110+
private void initFormFieldTypes(FlowForm form, Map<String, DataType> types) {
111+
for (FormField field : form.getFields()) {
109112
String key = form.getCode() + "." + field.getCode();
110-
String type = field.getType();
113+
DataType type = field.getType();
111114
types.put(key, type);
112115
}
113116
}
@@ -117,14 +120,14 @@ private void initFormFieldTypes(FormMeta form, Map<String, String> types) {
117120
*
118121
* @return 表单字段类型
119122
*/
120-
public Map<String, String> loadAllFieldTypeMaps() {
121-
Map<String, String> types = new HashMap<>();
122-
List<FormMeta> forms = this.getSubForms();
123+
public Map<String, DataType> loadAllFieldTypeMaps() {
124+
Map<String, DataType> types = new HashMap<>();
125+
List<FlowForm> forms = this.getSubForms();
123126
if (forms == null) {
124127
forms = new ArrayList<>();
125128
}
126129
forms.add(this);
127-
for (FormMeta subForm : forms) {
130+
for (FlowForm subForm : forms) {
128131
this.initFormFieldTypes(subForm, types);
129132
}
130133
return types;
@@ -136,17 +139,17 @@ public Map<String, String> loadAllFieldTypeMaps() {
136139
*
137140
* @return 表单字段类型
138141
*/
139-
public Map<String, String> loadMainFieldTypeMaps() {
140-
Map<String, String> types = new HashMap<>();
141-
List<FormMeta> forms = new ArrayList<>();
142+
public Map<String, DataType> loadMainFieldTypeMaps() {
143+
Map<String, DataType> types = new HashMap<>();
144+
List<FlowForm> forms = new ArrayList<>();
142145
forms.add(this);
143-
for (FormMeta subForm : forms) {
146+
for (FlowForm subForm : forms) {
144147
this.initFormFieldTypes(subForm, types);
145148
}
146149
return types;
147150
}
148151

149-
public FormMeta getSubForm(String formCode) {
152+
public FlowForm getSubForm(String formCode) {
150153
return this.subForms.stream().filter(form -> form.getCode().equals(formCode)).findFirst().orElse(null);
151154
}
152155
}
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, DataType 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: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.codingapi.flow.form;
22

3+
import com.codingapi.flow.exception.FlowValidationException;
34
import lombok.Getter;
45

56
import java.util.*;
@@ -11,16 +12,16 @@ public class FormData {
1112

1213
// 当前表单的元数据定义
1314
@Getter
14-
private final FormMeta formMeta;
15+
private final FlowForm flowForm;
1516
// 主表单数据内容
1617
@Getter
1718
private final DataBody dataBody;
1819
// 子表单数据内容
1920
private final Map<String, List<DataBody>> subDataBody;
2021

2122

22-
public FormData(FormMeta form) {
23-
this.formMeta = form;
23+
public FormData(FlowForm form) {
24+
this.flowForm = form;
2425
this.dataBody = new DataBody(form);
2526
this.subDataBody = new HashMap<>();
2627
}
@@ -40,11 +41,11 @@ public int countSubDataBody() {
4041
* @param formCode 子表单编号
4142
*/
4243
public DataBody addSubDataBody(String formCode) {
43-
FormMeta subFormMeta = getSubFormMeta(formCode);
44-
if (subFormMeta == null) {
44+
FlowForm subFlowForm = getSubFormMeta(formCode);
45+
if (subFlowForm == null) {
4546
return null;
4647
}
47-
DataBody subData = new DataBody(subFormMeta);
48+
DataBody subData = new DataBody(subFlowForm);
4849
List<DataBody> list = this.getSubDataBody(formCode);
4950
if (list == null) {
5051
list = new ArrayList<>();
@@ -108,22 +109,62 @@ public Map<String, Object> toMapData() {
108109
*
109110
* @param formCode 子表单编号
110111
*/
111-
private FormMeta getSubFormMeta(String formCode) {
112-
return formMeta.getSubForm(formCode);
112+
private FlowForm getSubFormMeta(String formCode) {
113+
return flowForm.getSubForm(formCode);
114+
}
115+
116+
/**
117+
* 校验formData
118+
*/
119+
public void verify() {
120+
for (FormField formField:flowForm.getFields()){
121+
Object value = this.dataBody.get(formField.getCode());
122+
Object defaultValue = formField.getDefaultValue();
123+
if(value==null && defaultValue!=null){
124+
this.dataBody.set(formField.getCode(),defaultValue);
125+
}
126+
if(formField.isRequired()){
127+
if(value==null && defaultValue==null){
128+
throw FlowValidationException.fieldNotFound(formField.getName());
129+
}
130+
}
131+
}
132+
133+
if(flowForm.getSubForms()!=null) {
134+
for (FlowForm subForm : flowForm.getSubForms()) {
135+
List<DataBody> subDataList = this.getSubDataBody(subForm.getCode());
136+
for (DataBody subData:subDataList) {
137+
for (FormField formField : subForm.getFields()) {
138+
Object value = subData.get(formField.getCode());
139+
Object defaultValue = formField.getDefaultValue();
140+
if(value==null && defaultValue!=null){
141+
subData.set(formField.getCode(),defaultValue);
142+
}
143+
if(formField.isRequired()){
144+
if(value==null && defaultValue==null){
145+
throw FlowValidationException.fieldNotFound(formField.getName());
146+
}
147+
}
148+
}
149+
}
150+
}
151+
}
152+
153+
113154
}
114155

115156
/**
116157
* 表单数据体
117158
*/
118159
public static class DataBody {
119-
private final FormMeta formMeta;
160+
private final FlowForm flowForm;
120161
private final Map<String, Object> data;
121-
private final Map<String, String> fieldTypes;
162+
private final Map<String, DataType> fieldTypes;
122163

123-
public DataBody(FormMeta formMeta) {
124-
this.formMeta = formMeta;
164+
public DataBody(FlowForm flowForm) {
165+
this.flowForm = flowForm;
125166
this.data = new HashMap<>();
126-
this.fieldTypes = formMeta.loadMainFieldTypeMaps();
167+
this.fieldTypes = flowForm.loadMainFieldTypeMaps();
127168
}
128169

129170

@@ -141,10 +182,10 @@ public void reset() {
141182
* @param value 表单字段值
142183
*/
143184
public DataBody set(String key, Object value) {
144-
String id = formMeta.getCode() + "." + key;
145-
String type = this.fieldTypes.get(id);
185+
String id = flowForm.getCode() + "." + key;
186+
DataType type = this.fieldTypes.get(id);
146187
if (type == null) {
147-
throw new RuntimeException("key:" + key + " not found");
188+
throw FlowValidationException.fieldNotFound(key);
148189
}
149190
this.data.put(id, value);
150191
return this;
@@ -157,7 +198,7 @@ public DataBody set(String key, Object value) {
157198
* @return 表单字段值
158199
*/
159200
public Object get(String key) {
160-
String id = formMeta.getCode() + "." + key;
201+
String id = flowForm.getCode() + "." + key;
161202
return this.data.get(id);
162203
}
163204

0 commit comments

Comments
 (0)