Skip to content

Commit 0c691e3

Browse files
committed
add action
1 parent 895da15 commit 0c691e3

18 files changed

Lines changed: 485 additions & 66 deletions

File tree

.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/manager/NodeStrategyManager.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingapi.flow.action.IFlowAction;
44
import com.codingapi.flow.action.actions.PassAction;
5+
import com.codingapi.flow.action.actions.RejectAction;
56
import com.codingapi.flow.error.ErrorThrow;
67
import com.codingapi.flow.exception.FlowValidationException;
78
import com.codingapi.flow.form.FlowForm;
@@ -67,26 +68,26 @@ public boolean isSequenceMultiOperatorType() {
6768

6869

6970
/**
70-
* 审批意见是否必须填写
71+
* 审批意见是否必填
7172
*/
72-
public boolean isEnableAdvice() {
73+
public boolean isAdviceRequired() {
7374
List<INodeStrategy> strategies = this.strategies;
7475
for (INodeStrategy strategy : strategies) {
7576
if (strategy instanceof AdviceStrategy) {
76-
return !((AdviceStrategy) strategy).isAdviceNullable();
77+
return ((AdviceStrategy) strategy).isAdviceRequired();
7778
}
7879
}
7980
return false;
8081
}
8182

8283
/**
83-
* 是否可签名
84+
* 签名是否必填
8485
*/
85-
public boolean isEnableSignable() {
86+
public boolean isSignRequired() {
8687
List<INodeStrategy> strategies = this.strategies;
8788
for (INodeStrategy strategy : strategies) {
8889
if (strategy instanceof AdviceStrategy) {
89-
return ((AdviceStrategy) strategy).isSignable();
90+
return ((AdviceStrategy) strategy).isSignRequired();
9091
}
9192
}
9293
return false;
@@ -163,23 +164,28 @@ public void verifySession(FlowSession session) {
163164

164165
FlowAdvice flowAdvice = session.getAdvice();
165166
IFlowAction flowAction = flowAdvice.getAction();
166-
// 是否必须填写审批意见
167-
if (this.isEnableAdvice()) {
168-
if (!StringUtils.hasText(flowAdvice.getAdvice())) {
169-
throw FlowValidationException.required("advice");
170-
}
171-
}
167+
168+
172169
// 通过操作
173-
if (flowAction instanceof PassAction) {
170+
if (flowAction instanceof PassAction || flowAction instanceof RejectAction) {
171+
172+
// 是否必须填写审批意见
173+
if (this.isAdviceRequired()) {
174+
if (!StringUtils.hasText(flowAdvice.getAdvice())) {
175+
throw FlowValidationException.required("advice");
176+
}
177+
}
178+
174179
// 是否必须签名
175-
if (this.isEnableSignable()) {
180+
if (this.isSignRequired()) {
176181
if (!StringUtils.hasText(flowAdvice.getSignKey())) {
177182
throw FlowValidationException.required("signKey");
178183
}
179184
}
185+
180186
}
181187

182-
for (INodeStrategy strategy : strategies){
188+
for (INodeStrategy strategy : strategies) {
183189
strategy.verifySession(session);
184190
}
185191
}
@@ -196,6 +202,7 @@ public <T extends INodeStrategy> T getStrategy(Class<T> clazz) {
196202

197203
/**
198204
* 错误触发(没有匹配到人时执行的逻辑)
205+
*
199206
* @param session 触发会话
200207
* @return 错误触发
201208
*/

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/response/FlowContent.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,35 @@ public class FlowContent {
3939
*/
4040
private String view;
4141

42+
/**
43+
* 节点名称
44+
*/
45+
private String nodeName;
46+
47+
/**
48+
* 节点Id
49+
*/
50+
private String nodeId;
51+
52+
/**
53+
* 节点类型
54+
*/
55+
private String nodeType;
56+
57+
/**
58+
* 流程标题
59+
*/
60+
private String title;
61+
4262
/**
4363
* 审批意见是否必填
4464
*/
45-
private boolean adviceNullable;
65+
private boolean adviceRequired;
4666

4767
/**
4868
* 签名是否必填
4969
*/
50-
private boolean signable;
70+
private boolean signRequired;
5171

5272
/**
5373
* 表单元数据
@@ -98,8 +118,11 @@ public void pushCurrentNode(IFlowNode currentNode) {
98118
ActionManager actionManager = currentNode.actionManager();
99119
NodeStrategyManager strategyManager = currentNode.strategyManager();
100120
this.actions = actionManager.getActions();
101-
this.adviceNullable = strategyManager.isEnableAdvice();
102-
this.signable = strategyManager.isEnableSignable();
121+
this.adviceRequired = strategyManager.isAdviceRequired();
122+
this.signRequired = strategyManager.isSignRequired();
123+
this.nodeId = currentNode.getId();
124+
this.nodeName = currentNode.getName();
125+
this.nodeType = currentNode.getType();
103126
Map<String,Object> nodeData = currentNode.toMap();
104127
this.view = (String) nodeData.get("view");
105128
}
@@ -116,6 +139,7 @@ public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
116139
this.mergeable = record.isMergeable();
117140
this.flowState = record.getFlowState();
118141
this.recordState = record.getRecordState();
142+
this.title = record.getTitle();
119143

120144
this.todos = new ArrayList<>();
121145
for (FlowRecord item : mergeRecords){

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,41 @@
1616
public class AdviceStrategy extends BaseStrategy {
1717

1818
/**
19-
* 是否可空
19+
* 意见必填
2020
*/
21-
private boolean adviceNullable;
21+
private boolean adviceRequired;
2222
/**
23-
* 是否可签名
23+
* 签名必填
2424
*/
25-
private boolean signable;
25+
private boolean signRequired;
2626

2727

2828
public static AdviceStrategy defaultStrategy() {
2929
AdviceStrategy strategy = new AdviceStrategy();
30-
strategy.setAdviceNullable(true);
31-
strategy.setSignable(false);
30+
strategy.setAdviceRequired(false);
31+
strategy.setSignRequired(false);
3232
return strategy;
3333
}
3434

3535
@Override
3636
public void copy(INodeStrategy target) {
37-
this.adviceNullable = ((AdviceStrategy) target).adviceNullable;
38-
this.signable = ((AdviceStrategy) target).signable;
37+
this.adviceRequired = ((AdviceStrategy) target).adviceRequired;
38+
this.signRequired = ((AdviceStrategy) target).signRequired;
3939
}
4040

4141
@Override
4242
public Map<String, Object> toMap() {
4343
Map<String, Object> map = super.toMap();
44-
map.put("adviceNullable", adviceNullable);
45-
map.put("signable", signable);
44+
map.put("adviceRequired", adviceRequired);
45+
map.put("signRequired", signRequired);
4646
return map;
4747
}
4848

4949
public static AdviceStrategy fromMap(Map<String, Object> map) {
5050
AdviceStrategy strategy = IMapConvertor.fromMap(map, AdviceStrategy.class);
5151
if (strategy == null) return null;
52-
strategy.setAdviceNullable((boolean) map.get("adviceNullable"));
53-
strategy.setSignable((boolean) map.get("signable"));
52+
strategy.setAdviceRequired((boolean) map.get("adviceRequired"));
53+
strategy.setSignRequired((boolean) map.get("signRequired"));
5454
return strategy;
5555
}
5656
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
import {FlowActionProps} from "./type";
3+
import {Button, message} from "antd";
4+
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
5+
6+
export const AddAuditAction: React.FC<FlowActionProps> = (props) => {
7+
8+
const action = props.action;
9+
const {context} = useApprovalContext()
10+
const actionPresenter = context.getPresenter().getFlowActionPresenter();
11+
12+
return (
13+
<Button
14+
danger={action.type === 'REJECT'}
15+
onClick={() => {
16+
actionPresenter.action(action.id).then((res) => {
17+
if (res.success) {
18+
message.success("操作成功");
19+
context.close();
20+
}
21+
});
22+
}}
23+
>
24+
{action.title}
25+
</Button>
26+
)
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
import {FlowActionProps} from "./type";
3+
import {Button, message} from "antd";
4+
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
5+
6+
export const CustomAction: React.FC<FlowActionProps> = (props) => {
7+
8+
const action = props.action;
9+
const {context} = useApprovalContext()
10+
const actionPresenter = context.getPresenter().getFlowActionPresenter();
11+
12+
return (
13+
<Button
14+
danger={action.type === 'REJECT'}
15+
onClick={() => {
16+
actionPresenter.action(action.id).then((res) => {
17+
if (res.success) {
18+
message.success("操作成功");
19+
context.close();
20+
}
21+
});
22+
}}
23+
>
24+
{action.title}
25+
</Button>
26+
)
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
import {FlowActionProps} from "./type";
3+
import {Button, message} from "antd";
4+
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
5+
6+
export const DelegateAction: React.FC<FlowActionProps> = (props) => {
7+
8+
const action = props.action;
9+
const {context} = useApprovalContext()
10+
const actionPresenter = context.getPresenter().getFlowActionPresenter();
11+
12+
return (
13+
<Button
14+
danger={action.type === 'REJECT'}
15+
onClick={() => {
16+
actionPresenter.action(action.id).then((res) => {
17+
if (res.success) {
18+
message.success("操作成功");
19+
context.close();
20+
}
21+
});
22+
}}
23+
>
24+
{action.title}
25+
</Button>
26+
)
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from "react";
2+
import {FlowActionProps} from "./type";
3+
import {FlowAction} from "@flow-engine/flow-types";
4+
import {PassAction} from "@/components/flow-approval/components/action/pass";
5+
import {AddAuditAction} from "@/components/flow-approval/components/action/add-audit";
6+
import {CustomAction} from "@/components/flow-approval/components/action/custom";
7+
import {DelegateAction} from "@/components/flow-approval/components/action/delegate";
8+
import {RejectAction} from "@/components/flow-approval/components/action/reject";
9+
import {ReturnAction} from "@/components/flow-approval/components/action/return";
10+
import {SaveAction} from "@/components/flow-approval/components/action/save";
11+
import {TransferAction} from "@/components/flow-approval/components/action/transfer";
12+
13+
export class ActionFactory {
14+
15+
private readonly cache: Map<string, React.ComponentType<FlowActionProps>>;
16+
17+
private constructor() {
18+
this.cache = new Map();
19+
this.initActions();
20+
}
21+
22+
private static readonly instance = new ActionFactory();
23+
24+
public static getInstance() {
25+
return ActionFactory.instance;
26+
}
27+
28+
29+
private initActions() {
30+
this.cache.set("ADD_AUDIT", AddAuditAction);
31+
this.cache.set("CUSTOM", CustomAction);
32+
this.cache.set("DELEGATE", DelegateAction);
33+
this.cache.set("PASS", PassAction);
34+
this.cache.set("REJECT", RejectAction);
35+
this.cache.set("RETURN", ReturnAction);
36+
this.cache.set("SAVE", SaveAction);
37+
this.cache.set("TRANSFER", TransferAction);
38+
39+
}
40+
41+
public render(action: FlowAction) {
42+
const FlowActionComponent = this.cache.get(action.type);
43+
if (FlowActionComponent) {
44+
return (
45+
<FlowActionComponent action={action}/>
46+
)
47+
}
48+
}
49+
50+
}

0 commit comments

Comments
 (0)