Skip to content

Commit f07c3ce

Browse files
committed
add FlowDirection
1 parent 7fee9cb commit f07c3ce

File tree

8 files changed

+170
-69
lines changed

8 files changed

+170
-69
lines changed

admin-ui/src/components/Flow/view/FlowView.tsx

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {Button, Divider, Form, message, Modal, Row, Space, Tabs} from "antd";
3-
import {detail, postponed, recall, saveFlow, submitFlow} from "@/api/flow";
3+
import {detail, postponed, recall, saveFlow, submitFlow, transfer} from "@/api/flow";
44
import {
55
ModalForm,
66
ProDescriptions,
@@ -10,6 +10,7 @@ import {
1010
ProFormTextArea
1111
} from "@ant-design/pro-components";
1212
import moment from "moment";
13+
import UserSelect from "@/pages/flow/user/select";
1314

1415

1516
interface FlowFormView {
@@ -32,11 +33,14 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
3233

3334
const [postponedVisible, setPostponedVisible] = React.useState(false);
3435
const [transferVisible,setTransferVisible] = React.useState(false);
36+
const [selectUserVisible, setSelectUserVisible] = React.useState(false);
3537

3638
const [viewForm] = Form.useForm();
3739

3840
const [opinionForm] = Form.useForm();
3941

42+
const [transferForm] = Form.useForm();
43+
4044
const handlerSaveFlow = () => {
4145
const advice = opinionForm.getFieldValue('advice');
4246
const recordId = props.id;
@@ -87,6 +91,29 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
8791
})
8892
}
8993

94+
const handlerTransferFlow = (values:any) => {
95+
const advice = opinionForm.getFieldValue('advice');
96+
const recordId = props.id;
97+
const binData = viewForm.getFieldsValue();
98+
const clazzName = data.flowRecord.bindClass;
99+
const body = {
100+
recordId,
101+
advice,
102+
targetUserId: values.userId,
103+
formData: {
104+
...binData,
105+
clazzName
106+
}
107+
}
108+
transfer(body).then(res => {
109+
if (res.success) {
110+
message.success('已经转办给'+values.userName).then();
111+
setTransferVisible(false);
112+
props.setVisible(false);
113+
}
114+
});
115+
}
116+
90117
const handleSubmitFlow = (success: boolean) => {
91118
const advice = opinionForm.getFieldValue('advice');
92119
const recordId = props.id;
@@ -103,7 +130,7 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
103130
}
104131
submitFlow(body).then(res => {
105132
if (res.success) {
106-
message.success('保存成功').then();
133+
message.success('流程已提交').then();
107134
props.setVisible(false);
108135
}
109136
})
@@ -137,7 +164,7 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
137164
const handleDetail = () => {
138165
detail(props.id).then(res => {
139166
if (res.success) {
140-
opinionForm.setFieldValue('advice', res.data.flowRecord.opinion.advice);
167+
opinionForm.setFieldValue('advice', res.data.flowRecord.opinion?.advice);
141168
setData(res.data);
142169
}
143170
});
@@ -451,6 +478,7 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
451478

452479
<ModalForm
453480
title={"延期人员选择"}
481+
form={transferForm}
454482
open={transferVisible}
455483
modalProps={{
456484
onCancel: () => {
@@ -461,16 +489,22 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
461489
}
462490
}}
463491
onFinish={async (values) => {
464-
console.log(values);
492+
handlerTransferFlow(values);
465493
}}
466494
>
495+
467496
<ProFormText
468-
name={"user"}
497+
name={"userId"}
498+
hidden={true}
499+
/>
500+
501+
<ProFormText
502+
name={"userName"}
469503
label={"转交人员"}
470504
fieldProps={{
471505
addonAfter: (
472506
<a onClick={()=>{
473-
console.log('选人员');
507+
setSelectUserVisible(true);
474508
}}>选人员</a>
475509
)
476510
}}
@@ -484,6 +518,22 @@ const FlowView: React.FC<FlowViewProps> = (props) => {
484518
</ModalForm>
485519

486520

521+
<UserSelect
522+
multiple={false}
523+
visible={selectUserVisible}
524+
setVisible={setSelectUserVisible}
525+
onSelect={(selectedRowKeys) => {
526+
if (selectedRowKeys && selectedRowKeys.length > 0) {
527+
const user = selectedRowKeys[0];
528+
transferForm.setFieldsValue({
529+
userId: user.id,
530+
userName: user.name
531+
});
532+
}
533+
}}
534+
/>
535+
536+
487537
</Modal>
488538
)
489539
}

example/example-application/src/main/java/com/codingapi/example/query/FlowRecordQueryController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.codingapi.springboot.security.gateway.TokenContext;
1313
import lombok.AllArgsConstructor;
1414
import org.springframework.data.domain.PageRequest;
15+
import org.springframework.data.domain.Sort;
1516
import org.springframework.web.bind.annotation.GetMapping;
1617
import org.springframework.web.bind.annotation.RequestMapping;
1718
import org.springframework.web.bind.annotation.RestController;
@@ -27,7 +28,7 @@ public class FlowRecordQueryController {
2728

2829
@GetMapping("/list")
2930
public MultiResponse<FlowRecordEntity> list(SearchRequest searchRequest) {
30-
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize());
31+
PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize(), Sort.by("createTime").descending());
3132
return MultiResponse.of(flowRecordQuery.findAll(pageRequest));
3233
}
3334

example/example-infra-flow/src/main/java/com/codingapi/example/jpa/FlowRecordEntityRepository.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ public interface FlowRecordEntityRepository extends FastRepository<FlowRecordEnt
1919
List<FlowRecordEntity> findFlowRecordEntityByProcessId(String processId);
2020

2121

22-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING'")
22+
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING' order by r.createTime desc")
2323
Page<FlowRecordEntity> findTodoByOperatorId(long operatorId,PageRequest pageRequest);
2424

25-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'DONE'")
25+
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'DONE' order by r.createTime desc")
2626
Page<FlowRecordEntity> findDoneByOperatorId(long operatorId, PageRequest pageRequest);
2727

28-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start'")
28+
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' order by r.createTime desc")
2929
Page<FlowRecordEntity> findInitiatedByOperatorId(long operatorId, PageRequest pageRequest);
3030

31-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2")
31+
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 order by r.createTime desc")
3232
Page<FlowRecordEntity> findTimeoutTodoByOperatorId(long operatorId,long currentTime, PageRequest pageRequest);
3333

34-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0")
34+
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.createTime desc")
3535
Page<FlowRecordEntity> findPostponedTodoByOperatorId(long operatorId, PageRequest pageRequest);
3636

37-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING'")
37+
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.recodeType = 'TODO' and r.flowStatus = 'RUNNING' order by r.createTime desc")
3838
List<FlowRecordEntity> findTodoFlowRecordByProcessId(String processId);
3939
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/domain/FlowNode.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
44
import com.codingapi.springboot.flow.content.FlowContent;
5-
import com.codingapi.springboot.flow.em.ApprovalType;
6-
import com.codingapi.springboot.flow.em.FlowStatus;
7-
import com.codingapi.springboot.flow.em.NodeType;
8-
import com.codingapi.springboot.flow.em.RecodeType;
5+
import com.codingapi.springboot.flow.em.*;
96
import com.codingapi.springboot.flow.error.ErrTrigger;
107
import com.codingapi.springboot.flow.error.ErrorResult;
118
import com.codingapi.springboot.flow.generator.TitleGenerator;
@@ -179,7 +176,7 @@ public List<? extends IFlowOperator> loadFlowNodeOperator(FlowContent flowConten
179176

180177

181178
/**
182-
* 开始流程
179+
* 创建流程记录
183180
*
184181
* @param workId 流程设计id
185182
* @param processId 流程id
@@ -189,7 +186,7 @@ public List<? extends IFlowOperator> loadFlowNodeOperator(FlowContent flowConten
189186
* @param currentOperator 当前操作者
190187
* @param snapshot 快照数据
191188
* @param opinion 审批意见
192-
* @param pass 流程方式
189+
* @param flowDirection 流程方式
193190
* @return 流程记录
194191
*/
195192
public FlowRecord createRecord(long workId,
@@ -200,7 +197,7 @@ public FlowRecord createRecord(long workId,
200197
IFlowOperator currentOperator,
201198
BindDataSnapshot snapshot,
202199
Opinion opinion,
203-
boolean pass) {
200+
FlowDirection flowDirection) {
204201

205202
// 当前操作者存在委托人时,才需要寻找委托人
206203
IFlowOperator flowOperator = currentOperator;
@@ -222,7 +219,7 @@ public FlowRecord createRecord(long workId,
222219
record.setCurrentOperatorId(flowOperator.getUserId());
223220
record.setPreId(preId);
224221
record.setTitle(title);
225-
record.setPass(pass);
222+
record.setFlowDirection(flowDirection);
226223
record.setTimeoutTime(this.loadTimeoutTime());
227224
record.setRecodeType(RecodeType.TODO);
228225
record.setErrMessage(null);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.codingapi.springboot.flow.em;
2+
3+
/**
4+
* 流转方式
5+
* 包括 同意、拒绝、转办
6+
*/
7+
public enum FlowDirection {
8+
9+
/**
10+
* 同意
11+
*/
12+
PASS,
13+
/**
14+
* 拒绝
15+
*/
16+
REJECT,
17+
/**
18+
*
19+
*/
20+
TRANSFER;
21+
22+
public static FlowDirection parser(String type){
23+
for(FlowDirection flowDirection :values()){
24+
if(flowDirection.name().equalsIgnoreCase(type)){
25+
return flowDirection;
26+
}
27+
}
28+
return PASS;
29+
}
30+
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowRecord.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codingapi.springboot.flow.domain.Opinion;
66
import com.codingapi.springboot.flow.em.FlowStatus;
77
import com.codingapi.springboot.flow.em.RecodeType;
8+
import com.codingapi.springboot.flow.em.FlowDirection;
89
import com.codingapi.springboot.flow.user.IFlowOperator;
910
import lombok.Getter;
1011
import lombok.Setter;
@@ -56,7 +57,7 @@ public class FlowRecord {
5657
* 流转产生方式
5758
* 流程是退回产生的还是通过产生的
5859
*/
59-
private boolean pass;
60+
private FlowDirection flowDirection;
6061

6162
/**
6263
* 创建时间
@@ -192,12 +193,12 @@ public void submitStateVerify() {
192193
/**
193194
* 提交流程
194195
*
195-
* @param flowOperator 操作者
196-
* @param snapshot 绑定数据
197-
* @param opinion 意见
198-
* @param pass 是否通过
196+
* @param flowOperator 操作者
197+
* @param snapshot 绑定数据
198+
* @param opinion 意见
199+
* @param flowDirection 流转方式
199200
*/
200-
public void submitRecord(IFlowOperator flowOperator, BindDataSnapshot snapshot, Opinion opinion, boolean pass) {
201+
public void submitRecord(IFlowOperator flowOperator, BindDataSnapshot snapshot, Opinion opinion, FlowDirection flowDirection) {
201202
if (!flowOperator.isFlowManager()) {
202203
if (flowOperator.getUserId() != this.currentOperatorId) {
203204
throw new IllegalArgumentException("current operator is not match");
@@ -207,7 +208,7 @@ public void submitRecord(IFlowOperator flowOperator, BindDataSnapshot snapshot,
207208
this.interfere = true;
208209
}
209210
this.read();
210-
this.pass = pass;
211+
this.flowDirection = flowDirection;
211212
this.recodeType = RecodeType.DONE;
212213
this.updateTime = System.currentTimeMillis();
213214
this.snapshotId = snapshot.getId();
@@ -223,14 +224,35 @@ public void transfer(IFlowOperator flowOperator, BindDataSnapshot snapshot, Opin
223224
throw new IllegalArgumentException("current operator is not match");
224225
}
225226
this.read();
226-
this.pass = true;
227+
this.flowDirection = FlowDirection.TRANSFER;
227228
this.recodeType = RecodeType.TRANSFER;
228229
this.updateTime = System.currentTimeMillis();
229230
this.snapshotId = snapshot.getId();
230231
this.bindClass = snapshot.getClazzName();
231232
this.opinion = opinion;
232233
}
233234

235+
236+
/**
237+
* 转办产生的流程记录
238+
*
239+
* @param title 标题
240+
* @param operator 操作者
241+
*/
242+
public void transferToTodo(String title, IFlowOperator operator) {
243+
this.id = 0;
244+
this.recodeType = RecodeType.TODO;
245+
this.flowStatus = FlowStatus.RUNNING;
246+
this.postponedCount = 0;
247+
this.updateTime = 0;
248+
this.readTime = 0;
249+
this.read = false;
250+
this.title = title;
251+
this.opinion = null;
252+
this.flowDirection = null;
253+
this.currentOperatorId = operator.getUserId();
254+
}
255+
234256
/**
235257
* 自动提交流程 (非会签时自通审批)
236258
*
@@ -239,7 +261,7 @@ public void transfer(IFlowOperator flowOperator, BindDataSnapshot snapshot, Opin
239261
*/
240262
public void unSignAutoDone(IFlowOperator flowOperator, BindDataSnapshot snapshot) {
241263
this.read();
242-
this.pass = true;
264+
this.flowDirection = FlowDirection.PASS;
243265
this.currentOperatorId = flowOperator.getUserId();
244266
this.recodeType = RecodeType.DONE;
245267
this.updateTime = System.currentTimeMillis();
@@ -321,7 +343,7 @@ public FlowRecord copy() {
321343
record.setTitle(this.title);
322344
record.setCurrentOperatorId(this.currentOperatorId);
323345
record.setRecodeType(this.recodeType);
324-
record.setPass(this.pass);
346+
record.setFlowDirection(this.flowDirection);
325347
record.setCreateTime(this.createTime);
326348
record.setUpdateTime(this.updateTime);
327349
record.setFinishTime(this.finishTime);
@@ -338,25 +360,6 @@ public FlowRecord copy() {
338360
return record;
339361
}
340362

341-
/**
342-
* 转待办
343-
*
344-
* @param title 标题
345-
* @param operator 操作者
346-
*/
347-
public void toTodo(String title, IFlowOperator operator) {
348-
this.id = 0;
349-
this.recodeType = RecodeType.TODO;
350-
this.flowStatus = FlowStatus.RUNNING;
351-
this.postponedCount = 0;
352-
this.updateTime = 0;
353-
this.readTime = 0;
354-
this.read = false;
355-
this.title = title;
356-
this.opinion = null;
357-
this.pass = false;
358-
this.currentOperatorId = operator.getUserId();
359-
}
360363

361364
/**
362365
* 是否超时

0 commit comments

Comments
 (0)