Skip to content

Commit df0488b

Browse files
committed
#13 create
1 parent aa75be0 commit df0488b

23 files changed

Lines changed: 253 additions & 34 deletions

File tree

flow-engine-example/src/main/java/com/codingapi/example/entity/User.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public boolean isFlowManager() {
6565

6666
@Override
6767
public IFlowOperator forwardOperator() {
68-
return GatewayContext.getInstance().getFlowOperator(flowOperatorId);
68+
if(flowOperatorId!=null && flowOperatorId > 0){
69+
return GatewayContext.getInstance().getFlowOperator(flowOperatorId);
70+
}
71+
return null;
6972
}
7073
}

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/request/FlowActionRequest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public class FlowActionRequest {
3131
private FlowAdviceBody advice;
3232

3333

34+
public void updateOperatorId(long operatorId) {
35+
if (advice != null) {
36+
advice.setOperatorId(operatorId);
37+
}
38+
}
39+
40+
3441
public FlowAdvice toFlowAdvice(Workflow workflow, IFlowAction flowAction) {
3542
FlowAdvice flowAdvice = new FlowAdvice();
3643
flowAdvice.setAdvice(advice.getAdvice());

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.codingapi.flow.operator.IFlowOperator;
99
import com.codingapi.flow.record.FlowRecord;
1010
import com.codingapi.flow.session.FlowSession;
11-
import com.codingapi.flow.strategy.node.OperatorLoadStrategy;
1211
import com.codingapi.flow.workflow.Workflow;
1312
import lombok.Data;
1413

@@ -26,10 +25,16 @@ public class FlowContent {
2625
* 流程记录编号
2726
*/
2827
private long recordId;
28+
2929
/**
3030
* 流程编号
3131
*/
32-
private String workflowCode;
32+
private String workId;
33+
34+
/**
35+
* 流程编码
36+
*/
37+
private String workCode;
3338
/**
3439
* 流程视图
3540
*/
@@ -109,7 +114,8 @@ public void pushCurrentNode(IFlowNode currentNode) {
109114

110115
public void pushWorkflow(Workflow workflow) {
111116
this.form = workflow.getForm();
112-
this.workflowCode = workflow.getCode();
117+
this.workCode = workflow.getCode();
118+
this.workId = workflow.getId();
113119
}
114120

115121
public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {

flow-engine-framework/src/main/java/com/codingapi/flow/service/FlowService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import com.codingapi.flow.pojo.response.FlowContent;
1111
import com.codingapi.flow.repository.*;
1212
import com.codingapi.flow.service.impl.*;
13+
import org.springframework.transaction.annotation.Transactional;
1314

1415
/**
1516
* 流程服务
1617
*/
18+
@Transactional
1719
public class FlowService {
1820

1921
public FlowService(WorkflowRepository workflowRepository,
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.codingapi.flow.api.controller;
22

33
import com.codingapi.flow.operator.IFlowOperator;
4+
import com.codingapi.flow.pojo.request.FlowActionRequest;
5+
import com.codingapi.flow.pojo.request.FlowCreateRequest;
6+
import com.codingapi.flow.pojo.response.FlowContent;
47
import com.codingapi.flow.service.FlowService;
58
import com.codingapi.springboot.framework.dto.request.IdRequest;
69
import com.codingapi.springboot.framework.dto.response.Response;
710
import com.codingapi.springboot.framework.dto.response.SingleResponse;
811
import com.codingapi.springboot.framework.user.UserContext;
912
import lombok.AllArgsConstructor;
10-
import org.springframework.web.bind.annotation.GetMapping;
11-
import org.springframework.web.bind.annotation.RequestMapping;
12-
import org.springframework.web.bind.annotation.RestController;
13+
import org.springframework.web.bind.annotation.*;
1314

1415
@RestController
1516
@RequestMapping("/api/cmd/record")
@@ -19,10 +20,27 @@ public class FlowRecordController {
1920
private final FlowService flowService;
2021

2122
@GetMapping("/detail")
22-
public Response detail(IdRequest request) {
23+
public SingleResponse<FlowContent> detail(IdRequest request) {
2324
String id = request.getStringId();
2425
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
2526
return SingleResponse.of(flowService.detail(id, current));
2627
}
2728

29+
30+
@PostMapping("/create")
31+
public SingleResponse<Long> create(@RequestBody FlowCreateRequest request) {
32+
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
33+
request.setOperatorId(current.getUserId());
34+
return SingleResponse.of(flowService.create(request));
35+
}
36+
37+
38+
@PostMapping("/action")
39+
public Response action(@RequestBody FlowActionRequest request) {
40+
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
41+
request.updateOperatorId(current.getUserId());
42+
flowService.action(request);
43+
return Response.buildSuccess();
44+
}
45+
2846
}

flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowRecordConvertor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public static FlowRecordEntity convert(FlowRecord record) {
5959
return null;
6060
}
6161
FlowRecordEntity entity = new FlowRecordEntity();
62-
entity.setId(record.getId());
62+
if(record.getId()>0) {
63+
entity.setId(record.getId());
64+
}
6365
entity.setWorkBackupId(record.getWorkBackupId());
6466
entity.setWorkCode(record.getWorkCode());
6567
entity.setNodeId(record.getNodeId());

flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowTodoMargeConvertor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public static FlowTodoMargeEntity convert(FlowTodoMerge marge) {
2222
return null;
2323
}
2424
FlowTodoMargeEntity entity = new FlowTodoMargeEntity();
25-
entity.setId(marge.getId());
25+
if(marge.getId()>0) {
26+
entity.setId(marge.getId());
27+
}
2628
entity.setTodoId(marge.getTodoId());
2729
entity.setRecordId(marge.getRecordId());
2830
entity.setCreateTime(marge.getCreateTime());

flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowTodoRecordConvertor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public static FlowTodoRecordEntity convert(FlowTodoRecord record){
3838
}
3939

4040
FlowTodoRecordEntity entity = new FlowTodoRecordEntity();
41-
entity.setId(record.getId());
41+
if(record.getId()>0) {
42+
entity.setId(record.getId());
43+
}
4244
entity.setProcessId(record.getProcessId());
4345
entity.setWorkBackupId(record.getWorkBackupId());
4446
entity.setWorkCode(record.getWorkCode());

flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/UrgeIntervalConvertor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public static UrgeIntervalEntity convert(UrgeInterval interval) {
1010
return null;
1111
}
1212
UrgeIntervalEntity entity = new UrgeIntervalEntity();
13-
entity.setId(interval.getId());
13+
if(interval.getId()>0) {
14+
entity.setId(interval.getId());
15+
}
1416
entity.setProcessId(interval.getProcessId());
1517
entity.setRecordId(interval.getRecordId());
1618
entity.setCreateTime(interval.getCreateTime());

flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowBackupConvertor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55

66
public class WorkflowBackupConvertor {
77

8-
public static WorkflowBackupEntity convert(WorkflowBackup workflowBackup){
9-
if(workflowBackup==null){
8+
public static WorkflowBackupEntity convert(WorkflowBackup workflowBackup) {
9+
if (workflowBackup == null) {
1010
return null;
1111
}
1212
WorkflowBackupEntity entity = new WorkflowBackupEntity();
13+
if (workflowBackup.getId() > 0) {
14+
entity.setId(workflowBackup.getId());
15+
}
1316
entity.setWorkflow(workflowBackup.getWorkflow());
1417
entity.setWorkId(workflowBackup.getWorkId());
1518
entity.setWorkCode(workflowBackup.getWorkCode());
1619
entity.setWorkVersion(workflowBackup.getWorkVersion());
1720
entity.setWorkTitle(workflowBackup.getWorkTitle());
1821
entity.setCreateTime(workflowBackup.getCreateTime());
19-
entity.setId(workflowBackup.getId());
2022
return entity;
2123
}
2224

23-
public static WorkflowBackup convert(WorkflowBackupEntity entity){
24-
if(entity==null){
25+
public static WorkflowBackup convert(WorkflowBackupEntity entity) {
26+
if (entity == null) {
2527
return null;
2628
}
27-
return new WorkflowBackup(entity.getId(),entity.getWorkId(),entity.getWorkCode(),entity.getWorkVersion(),entity.getWorkTitle(),entity.getCreateTime(),entity.getWorkflow());
29+
return new WorkflowBackup(entity.getId(), entity.getWorkId(), entity.getWorkCode(), entity.getWorkVersion(), entity.getWorkTitle(), entity.getCreateTime(), entity.getWorkflow());
2830
}
2931
}

0 commit comments

Comments
 (0)