Skip to content

Commit 6099570

Browse files
authored
Merge pull request #87 from codingapi/dev
Dev
2 parents d17932e + c10422b commit 6099570

File tree

20 files changed

+204
-42
lines changed

20 files changed

+204
-42
lines changed

admin-ui/src/api/validate.ts

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import {FormInstance} from "antd/es/form/hooks/useForm";
2+
import {NamePath} from "rc-field-form/es/interface";
3+
4+
// 流程表单API 提供get post的能力
5+
export interface FlowFormApi {
6+
get: (url: string, params?: any) => Promise<any>;
7+
post: (url: string, data: any) => Promise<any>;
8+
}
9+
10+
// 流程表单验证内容
11+
export class FlowFormValidateContent {
12+
readonly value: any;
13+
readonly form: FormInstance;
14+
readonly api?: FlowFormApi
15+
16+
constructor(value: any, form: FormInstance, api?: FlowFormApi) {
17+
this.value = value;
18+
this.form = form;
19+
this.api = api;
20+
}
21+
}
22+
23+
// 自定义验证
24+
export interface FlowFormCustomValidate {
25+
name: NamePath;
26+
validate: (content: FlowFormValidateContent) => Promise<string[]>;
27+
}
28+
29+
// 流程表单API上下文
30+
export class FlowFormApiContext {
31+
32+
private static readonly instance: FlowFormApiContext = new FlowFormApiContext();
33+
34+
private api: FlowFormApi | undefined;
35+
36+
private constructor() {
37+
this.api = undefined;
38+
}
39+
40+
public static getInstance() {
41+
return FlowFormApiContext.instance;
42+
}
43+
44+
public setApi(api: FlowFormApi) {
45+
this.api = api;
46+
}
47+
48+
public getApi() {
49+
return this.api;
50+
}
51+
}
52+
53+
// 自定义验证上下文
54+
export class FlowFormCustomValidateContext {
55+
56+
private readonly map: Map<NamePath, FlowFormCustomValidate>;
57+
58+
constructor() {
59+
this.map = new Map();
60+
}
61+
62+
public addValidate(validate: FlowFormCustomValidate) {
63+
this.map.set(validate.name, validate);
64+
}
65+
66+
public addCustomFunctionCodeValidate(namePath:NamePath,validateFuncCode:string){
67+
const validateFunc = new Function('content', validateFuncCode);
68+
this.addValidate({
69+
name: namePath,
70+
validate: async (content) => {
71+
return validateFunc(content);
72+
}
73+
});
74+
}
75+
76+
public validate(form: FormInstance) {
77+
this.map.values().forEach((validate) => {
78+
const value = form.getFieldValue(validate.name);
79+
const content = new FlowFormValidateContent(value, form, FlowFormApiContext.getInstance().getApi());
80+
validate.validate(content).then((res) => {
81+
form.setFields(
82+
[
83+
{
84+
name: validate.name,
85+
errors: res,
86+
}
87+
]
88+
)
89+
}).catch((error) => {
90+
form.setFields(
91+
[
92+
{
93+
name: validate.name,
94+
errors: [error],
95+
}
96+
]
97+
)
98+
});
99+
});
100+
}
101+
}
102+
103+

admin-ui/src/components/Flow/flow/FlowButtons.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const FlowButtons: React.FC<FlowButtonsProps> = (props) => {
2121
return null;
2222
}
2323

24+
if(flowData.hasData() && !flowData.canHandle()){
25+
return null;
26+
}
27+
2428
const buttons = flowData.getNodeButtons();
2529

2630
return (

admin-ui/src/pages/welcome/index.tsx

+47-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,59 @@
11
import React from 'react';
2-
import logo from '@/assets/logo.svg';
32
import './index.scss';
4-
import {useSelector} from "react-redux";
5-
import {RootState} from "@/store/Redux";
6-
import RoleControl from "@/utils/RoleControl";
73
import Page from "@/components/Layout/Page";
4+
import {Button, Form, Input} from "antd";
5+
import {FlowFormApiContext, FlowFormCustomValidateContext} from "@/api/validate";
6+
import * as api from "@/api"
7+
8+
FlowFormApiContext.getInstance().setApi({
9+
get: (url: string, params?: any) => {
10+
return api.get(url, params);
11+
},
12+
post: (url: string, data: any) => {
13+
return api.post(url, data);
14+
}
15+
});
816

917
const Index = () => {
1018

11-
const counter = useSelector((state: RootState) => state.counter.value);
12-
const username = localStorage.getItem('username');
19+
const [form] = Form.useForm();
20+
21+
const context = new FlowFormCustomValidateContext();
22+
23+
const validateFuncCode = `
24+
if (content.value) {
25+
return [];
26+
} else {
27+
return ["姓名不存在"];
28+
}
29+
`;
30+
context.addCustomFunctionCodeValidate(["user", "name"], validateFuncCode);
1331

1432
return (
1533
<Page enablePageContainer={true}>
16-
<div className="App">
17-
<header className="App-header">
18-
<img src={logo} className="App-logo" alt="logo"/>
19-
<p>
20-
hi {username} , Redux counter: {counter}, Roles: {RoleControl.roles().map(item => (
21-
<label
22-
key={item}
23-
style={{
24-
margin: '0 5px',
25-
padding: '5px',
26-
}}>{item}</label>
27-
))}
28-
</p>
29-
</header>
30-
</div>
34+
35+
<Form
36+
form={form}
37+
>
38+
39+
<Form.Item
40+
name={["user", "name"]}
41+
label={"姓名"}
42+
>
43+
<Input/>
44+
</Form.Item>
45+
</Form>
46+
47+
<Button onClick={() => {
48+
form.validateFields().then(res => {
49+
console.log(res);
50+
})
51+
}}>test1</Button>
52+
53+
<Button onClick={() => {
54+
context.validate(form);
55+
}}>test2</Button>
56+
3157
</Page>
3258
);
3359
}

example/example-application/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.51</version>
20+
<version>3.3.55</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>3.3.51</version>
18+
<version>3.3.55</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-parent</artifactId>
9-
<version>3.3.51</version>
9+
<version>3.3.55</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-data-authorization</artifactId>

springboot-starter-data-authorization/src/main/java/com/codingapi/springboot/authorization/interceptor/DefaultSQLInterceptor.java

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public boolean beforeHandler(String sql) {
2121

2222
@Override
2323
public void afterHandler(String sql, String newSql, SQLException exception) {
24+
if(exception!=null){
25+
log.error("sql:{}",sql);
26+
log.error("newSql:{}",newSql);
27+
log.error(exception.getMessage(),exception);
28+
}
2429
if (DataAuthorizationPropertyContext.getInstance().showSql()) {
2530
log.info("newSql:{}", newSql);
2631
}

springboot-starter-data-fast/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.51</version>
9+
<version>3.3.55</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/content/FlowSession.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ public MessageResult rejectFlow() {
184184
}
185185

186186
/**
187-
* 是否为驳回状态
188-
*
189-
* @return 是否为驳回状态
187+
* 上级节点的状态是驳回状态
188+
* @return 上级节点的状态是驳回状态
190189
*/
191-
public boolean isRejectState() {
190+
public boolean backStateIsReject() {
191+
if (flowRecord == null) {
192+
return false;
193+
}
192194
long preId = flowRecord.getPreId();
193195
if (preId == 0) {
194196
return false;
@@ -201,6 +203,26 @@ public boolean isRejectState() {
201203
return false;
202204
}
203205

206+
/**
207+
* 上级节点的状态是驳回状态
208+
*
209+
* @see #backStateIsReject()
210+
*/
211+
@Deprecated
212+
public boolean isRejectState() {
213+
return this.backStateIsReject();
214+
}
215+
216+
/**
217+
* 当前节点的状态是驳回状态
218+
*/
219+
public boolean currentStateIsReject() {
220+
if (flowRecord != null) {
221+
return flowRecord.getFlowSourceDirection() == FlowSourceDirection.REJECT;
222+
}
223+
return false;
224+
}
225+
204226

205227
/**
206228
* 预提交流程

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowNodeService.java

-3
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ private List<FlowRecord> createNextRecord() {
251251
if (customOperatorIds != null && !customOperatorIds.isEmpty()) {
252252
operators = operators.stream()
253253
.filter(operator -> customOperatorIds.contains(operator.getUserId())).toList();
254-
if (operators.size() != customOperatorIds.size()) {
255-
throw new IllegalArgumentException("operator not match.");
256-
}
257254
}
258255
List<FlowRecord> recordList;
259256
if (operators.isEmpty()) {

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowSubmitService.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private FlowResult submitCurrentFlow() {
303303
this.saveFlowRecord(flowRecord);
304304
this.updateFinishFlowRecord();
305305

306-
this.pushEvent(flowRecord, FlowApprovalEvent.STATE_CREATE);
306+
this.pushEvent(flowRecord, FlowApprovalEvent.STATE_FINISH);
307307

308308
if (!nextRecords.isEmpty()) {
309309
return new FlowResult(flowWork, nextRecords.get(0));
@@ -369,6 +369,11 @@ public FlowSubmitResult trySubmitFlow() {
369369

370370
this.loadNextNode(historyRecords);
371371

372+
while (nextNode.isCirculate()){
373+
flowNodeService.skipCirculate();
374+
this.nextNode = flowNodeService.getNextNode();
375+
}
376+
372377
List<? extends IFlowOperator> operators = flowNodeService.loadNextNodeOperators();
373378
return new FlowSubmitResult(flowWork, nextNode, operators);
374379
}

springboot-starter-security/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.51</version>
9+
<version>3.3.55</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>3.3.51</version>
8+
<version>3.3.55</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
------------------------------------------------------
2-
CodingApi SpringBoot-Starter 3.3.51
2+
CodingApi SpringBoot-Starter 3.3.55
33
springboot version (${spring-boot.version})
44
------------------------------------------------------

0 commit comments

Comments
 (0)