Skip to content

Commit 09d0032

Browse files
committed
fix operator load
1 parent f291788 commit 09d0032

File tree

23 files changed

+137
-95
lines changed

23 files changed

+137
-95
lines changed

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.2.5.dev</version>
8+
<version>3.3.2.6.dev</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-application/src/main/java/com/codingapi/example/command/FlowRecordCmdController.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import com.codingapi.example.domain.User;
44
import com.codingapi.example.pojo.cmd.FlowCmd;
55
import com.codingapi.example.repository.UserRepository;
6+
import com.codingapi.springboot.flow.pojo.FlowResult;
7+
import com.codingapi.springboot.flow.record.FlowRecord;
68
import com.codingapi.springboot.flow.service.FlowService;
79
import com.codingapi.springboot.framework.dto.response.Response;
10+
import com.codingapi.springboot.framework.dto.response.SingleResponse;
811
import lombok.AllArgsConstructor;
912
import lombok.extern.slf4j.Slf4j;
1013
import org.springframework.web.bind.annotation.PostMapping;
@@ -22,22 +25,20 @@ public class FlowRecordCmdController {
2225
private final UserRepository userRepository;
2326

2427
@PostMapping("/startFlow")
25-
public Response startFlow(@RequestBody FlowCmd.StartFlow request) {
28+
public SingleResponse<FlowResult> startFlow(@RequestBody FlowCmd.StartFlow request) {
2629
User current = userRepository.getUserByUsername(request.getUserName());
27-
flowService.startFlow(request.getWorkCode(), current, request.getBindData(), request.getAdvice());
28-
return Response.buildSuccess();
30+
return SingleResponse.of(flowService.startFlow(request.getWorkCode(), current, request.getBindData(), request.getAdvice()));
2931
}
3032

3133

3234
@PostMapping("/submitFlow")
33-
public Response submitFlow(@RequestBody FlowCmd.SubmitFlow request) {
35+
public SingleResponse<FlowResult> submitFlow(@RequestBody FlowCmd.SubmitFlow request) {
3436
User current = userRepository.getUserByUsername(request.getUserName());
3537
if(current.isFlowManager()){
36-
flowService.interfere(request.getRecordId(), current, request.getBindData(), request.getOpinion());
38+
return SingleResponse.of(flowService.interfere(request.getRecordId(), current, request.getBindData(), request.getOpinion()));
3739
}else {
38-
flowService.submitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion());
40+
return SingleResponse.of(flowService.submitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion()));
3941
}
40-
return Response.buildSuccess();
4142
}
4243

4344

example/example-application/src/main/java/com/codingapi/example/command/LeaveCmdController.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import com.codingapi.example.domain.User;
55
import com.codingapi.example.pojo.cmd.LeaveCmd;
66
import com.codingapi.example.repository.UserRepository;
7+
import com.codingapi.springboot.flow.pojo.FlowResult;
78
import com.codingapi.springboot.flow.service.FlowService;
8-
import com.codingapi.springboot.framework.dto.response.Response;
9+
import com.codingapi.springboot.framework.dto.response.SingleResponse;
910
import lombok.AllArgsConstructor;
1011
import org.springframework.web.bind.annotation.PostMapping;
1112
import org.springframework.web.bind.annotation.RequestBody;
@@ -22,7 +23,7 @@ public class LeaveCmdController {
2223

2324

2425
@PostMapping("/startLeave")
25-
public Response startLeave(@RequestBody LeaveCmd.StartLeave request) {
26+
public SingleResponse<FlowResult> startLeave(@RequestBody LeaveCmd.StartLeave request) {
2627
User user = userRepository.getUserByUsername(request.getUsername());
2728

2829
Leave leave = new Leave();
@@ -31,8 +32,6 @@ public Response startLeave(@RequestBody LeaveCmd.StartLeave request) {
3132
leave.setDays(request.getDays());
3233
leave.setCreateTime(System.currentTimeMillis());
3334

34-
flowService.startFlow(request.getFlowCode(), user, leave, request.getDesc());
35-
36-
return Response.buildSuccess();
35+
return SingleResponse.of(flowService.startFlow(request.getFlowCode(), user, leave, request.getDesc()));
3736
}
3837
}

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.2.5.dev</version>
8+
<version>3.3.2.6.dev</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.2.5.dev</version>
8+
<version>3.3.2.6.dev</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

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

+16-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class FlowRecordConvertor {
1212

13-
public static FlowRecordEntity convert(FlowRecord flowRecord, UserRepository userRepository) {
13+
public static FlowRecordEntity convert(FlowRecord flowRecord) {
1414
if (flowRecord == null) {
1515
return null;
1616
}
@@ -22,7 +22,7 @@ public static FlowRecordEntity convert(FlowRecord flowRecord, UserRepository use
2222
entity.setProcessId(flowRecord.getProcessId());
2323
entity.setNodeCode(flowRecord.getNodeCode());
2424
entity.setTitle(flowRecord.getTitle());
25-
entity.setCurrentOperatorId(flowRecord.getCurrentOperatorId());
25+
entity.setCurrentOperatorId(flowRecord.getCurrentOperator().getUserId());
2626
entity.setFlowType(flowRecord.getFlowType().name());
2727
if (flowRecord.getFlowSourceDirection() != null) {
2828
entity.setFlowSourceDirection(flowRecord.getFlowSourceDirection().name());
@@ -32,32 +32,34 @@ public static FlowRecordEntity convert(FlowRecord flowRecord, UserRepository use
3232
entity.setFinishTime(flowRecord.getFinishTime());
3333
entity.setTimeoutTime(flowRecord.getTimeoutTime());
3434
entity.setPostponedCount(flowRecord.getPostponedCount());
35-
entity.setCreateOperatorId(flowRecord.getCreateOperatorId());
35+
entity.setCreateOperatorId(flowRecord.getCreateOperator().getUserId());
3636
if (flowRecord.getOpinion() != null) {
3737
entity.setOpinionAdvice(flowRecord.getOpinion().getAdvice());
3838
entity.setOpinionType(flowRecord.getOpinion().getType());
3939
entity.setOpinionResult(flowRecord.getOpinion().getResult());
4040
}
4141

42-
entity.setCurrentOperatorName(userRepository.getUserById(flowRecord.getCurrentOperatorId()).getName());
43-
entity.setCreateOperatorName(userRepository.getUserById(flowRecord.getCreateOperatorId()).getName());
42+
43+
entity.setCurrentOperatorName(flowRecord.getCurrentOperator().getName());
44+
entity.setCreateOperatorName(flowRecord.getCreateOperator().getName());
4445

4546
entity.setFlowStatus(flowRecord.getFlowStatus().name());
4647
entity.setErrMessage(flowRecord.getErrMessage());
4748
entity.setBindClass(flowRecord.getBindClass());
4849
entity.setSnapshotId(flowRecord.getSnapshotId());
4950
entity.setRead(flowRecord.isRead());
5051
entity.setInterfere(flowRecord.isInterfere());
51-
entity.setInterferedOperatorId(flowRecord.getInterferedOperatorId());
52-
if (flowRecord.isInterfere() && flowRecord.getInterferedOperatorId() > 0) {
53-
entity.setInterferedOperatorName(userRepository.getUserById(flowRecord.getInterferedOperatorId()).getName());
52+
53+
if (flowRecord.getInterferedOperator()!=null) {
54+
entity.setInterferedOperatorId(flowRecord.getInterferedOperator().getUserId());
55+
entity.setInterferedOperatorName(flowRecord.getInterferedOperator().getName());
5456
}
5557
entity.setReadTime(flowRecord.getReadTime());
5658
return entity;
5759
}
5860

5961

60-
public static FlowRecord convert(FlowRecordEntity entity) {
62+
public static FlowRecord convert(FlowRecordEntity entity, UserRepository userRepository) {
6163
if (entity == null) {
6264
return null;
6365
}
@@ -69,15 +71,15 @@ public static FlowRecord convert(FlowRecordEntity entity) {
6971
flowRecord.setProcessId(entity.getProcessId());
7072
flowRecord.setNodeCode(entity.getNodeCode());
7173
flowRecord.setTitle(entity.getTitle());
72-
flowRecord.setCurrentOperatorId(entity.getCurrentOperatorId());
74+
flowRecord.setCurrentOperator(userRepository.getUserById(entity.getCurrentOperatorId()));
7375
flowRecord.setFlowType(FlowType.parser(entity.getFlowType()));
7476
flowRecord.setFlowSourceDirection(FlowSourceDirection.parser(entity.getFlowSourceDirection()));
7577
flowRecord.setCreateTime(entity.getCreateTime());
7678
flowRecord.setUpdateTime(entity.getUpdateTime());
7779
flowRecord.setFinishTime(entity.getFinishTime());
7880
flowRecord.setTimeoutTime(entity.getTimeoutTime());
7981
flowRecord.setPostponedCount(entity.getPostponedCount());
80-
flowRecord.setCreateOperatorId(entity.getCreateOperatorId());
82+
flowRecord.setCreateOperator(userRepository.getUserById(entity.getCreateOperatorId()));
8183
if (entity.getOpinionResult() != null && entity.getOpinionType() != null) {
8284
flowRecord.setOpinion(new Opinion(entity.getOpinionAdvice(), entity.getOpinionResult(), entity.getOpinionType()));
8385
}
@@ -87,6 +89,9 @@ public static FlowRecord convert(FlowRecordEntity entity) {
8789
flowRecord.setSnapshotId(entity.getSnapshotId());
8890
flowRecord.setRead(entity.getRead());
8991
flowRecord.setInterfere(entity.getInterfere());
92+
if(entity.getInterferedOperatorId()!=null) {
93+
flowRecord.setInterferedOperator(userRepository.getUserById(entity.getInterferedOperatorId()));
94+
}
9095
flowRecord.setReadTime(entity.getReadTime());
9196
return flowRecord;
9297
}

example/example-infra-flow/src/main/java/com/codingapi/example/query/FlowRecordQueryImpl.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.codingapi.example.convert.FlowRecordConvertor;
44
import com.codingapi.example.entity.FlowRecordEntity;
55
import com.codingapi.example.jpa.FlowRecordEntityRepository;
6+
import com.codingapi.example.repository.UserRepository;
67
import com.codingapi.springboot.flow.query.FlowRecordQuery;
78
import com.codingapi.springboot.flow.record.FlowRecord;
89
import lombok.AllArgsConstructor;
@@ -15,41 +16,42 @@
1516
public class FlowRecordQueryImpl implements FlowRecordQuery {
1617

1718
private final FlowRecordEntityRepository flowRecordEntityRepository;
19+
private final UserRepository userRepository;
1820

1921

2022
@Override
2123
public Page<FlowRecord> findAll(PageRequest pageRequest) {
2224
Page<FlowRecordEntity> page = flowRecordEntityRepository.findAll(pageRequest);
23-
return page.map(FlowRecordConvertor::convert);
25+
return page.map(item->FlowRecordConvertor.convert(item,userRepository));
2426
}
2527

2628
@Override
2729
public Page<FlowRecord> findTodoByOperatorId(long operatorId, PageRequest pageRequest) {
2830
Page<FlowRecordEntity> page = flowRecordEntityRepository.findTodoByOperatorId(operatorId,pageRequest);
29-
return page.map(FlowRecordConvertor::convert);
31+
return page.map(item->FlowRecordConvertor.convert(item,userRepository));
3032
}
3133

3234
@Override
3335
public Page<FlowRecord> findDoneByOperatorId(long operatorId, PageRequest pageRequest) {
3436
Page<FlowRecordEntity> page = flowRecordEntityRepository.findDoneByOperatorId(operatorId,pageRequest);
35-
return page.map(FlowRecordConvertor::convert);
37+
return page.map(item->FlowRecordConvertor.convert(item,userRepository));
3638
}
3739

3840
@Override
3941
public Page<FlowRecord> findInitiatedByOperatorId(long operatorId, PageRequest pageRequest) {
4042
Page<FlowRecordEntity> page = flowRecordEntityRepository.findInitiatedByOperatorId(operatorId,pageRequest);
41-
return page.map(FlowRecordConvertor::convert);
43+
return page.map(item->FlowRecordConvertor.convert(item,userRepository));
4244
}
4345

4446
@Override
4547
public Page<FlowRecord> findTimeoutTodoByOperatorId(long operatorId, PageRequest pageRequest) {
4648
Page<FlowRecordEntity> page = flowRecordEntityRepository.findTimeoutTodoByOperatorId(operatorId,System.currentTimeMillis(), pageRequest);
47-
return page.map(FlowRecordConvertor::convert);
49+
return page.map(item->FlowRecordConvertor.convert(item,userRepository));
4850
}
4951

5052
@Override
5153
public Page<FlowRecord> findPostponedTodoByOperatorId(long operatorId, PageRequest pageRequest) {
5254
Page<FlowRecordEntity> page = flowRecordEntityRepository.findPostponedTodoByOperatorId(operatorId,pageRequest);
53-
return page.map(FlowRecordConvertor::convert);
55+
return page.map(item->FlowRecordConvertor.convert(item,userRepository));
5456
}
5557
}

example/example-infra-flow/src/main/java/com/codingapi/example/repository/FlowRecordRepositoryImpl.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codingapi.example.repository;
22

33
import com.codingapi.example.convert.FlowRecordConvertor;
4+
import com.codingapi.example.entity.FlowRecordEntity;
45
import com.codingapi.example.jpa.FlowRecordEntityRepository;
56
import com.codingapi.springboot.flow.em.FlowStatus;
67
import com.codingapi.springboot.flow.record.FlowRecord;
@@ -20,33 +21,37 @@ public class FlowRecordRepositoryImpl implements FlowRecordRepository {
2021

2122
@Override
2223
public void save(List<FlowRecord> records) {
23-
flowRecordEntityRepository.saveAll(records.stream().map(item->FlowRecordConvertor.convert(item,userRepository)).toList());
24+
List<FlowRecordEntity> entities = records.stream().map(FlowRecordConvertor::convert).toList();
25+
entities = flowRecordEntityRepository.saveAll(entities);
26+
for (int i = 0; i < records.size(); i++) {
27+
records.get(i).setId(entities.get(i).getId());
28+
}
2429
}
2530

2631
@Override
2732
public void update(FlowRecord flowRecord) {
28-
flowRecordEntityRepository.save(FlowRecordConvertor.convert(flowRecord,userRepository));
33+
flowRecordEntityRepository.save(FlowRecordConvertor.convert(flowRecord));
2934
}
3035

3136
@Override
3237
public FlowRecord getFlowRecordById(long id) {
33-
return FlowRecordConvertor.convert(flowRecordEntityRepository.getFlowRecordEntityById(id));
38+
return FlowRecordConvertor.convert(flowRecordEntityRepository.getFlowRecordEntityById(id),userRepository);
3439
}
3540

3641
@Override
3742
public List<FlowRecord> findFlowRecordByPreId(long preId) {
38-
return flowRecordEntityRepository.findFlowRecordEntityByPreId(preId).stream().map(FlowRecordConvertor::convert).toList();
43+
return flowRecordEntityRepository.findFlowRecordEntityByPreId(preId).stream().map(item->FlowRecordConvertor.convert(item,userRepository)).toList();
3944
}
4045

4146
@Override
4247
public List<FlowRecord> findFlowRecordByProcessId(String processId) {
43-
return flowRecordEntityRepository.findFlowRecordEntityByProcessId(processId).stream().map(FlowRecordConvertor::convert).toList();
48+
return flowRecordEntityRepository.findFlowRecordEntityByProcessId(processId).stream().map(item->FlowRecordConvertor.convert(item,userRepository)).toList();
4449
}
4550

4651
@Override
4752
public List<FlowRecord> findTodoFlowRecordByProcessId(String processId) {
4853
return flowRecordEntityRepository.findTodoFlowRecordByProcessId(processId)
49-
.stream().map(FlowRecordConvertor::convert).toList();
54+
.stream().map(item->FlowRecordConvertor.convert(item,userRepository)).toList();
5055
}
5156

5257
@Override
@@ -61,6 +66,6 @@ public void finishFlowRecordByProcessId(String processId) {
6166

6267
@Override
6368
public void delete(List<FlowRecord> childrenRecords) {
64-
flowRecordEntityRepository.deleteAll(childrenRecords.stream().map(item->FlowRecordConvertor.convert(item,userRepository)).toList());
69+
flowRecordEntityRepository.deleteAll(childrenRecords.stream().map(FlowRecordConvertor::convert).toList());
6570
}
6671
}

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.2.5.dev</version>
8+
<version>3.3.2.6.dev</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.2.5.dev</version>
8+
<version>3.3.2.6.dev</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>com.codingapi.springboot</groupId>
1515
<artifactId>springboot-parent</artifactId>
16-
<version>3.3.2.5.dev</version>
16+
<version>3.3.2.6.dev</version>
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.2.5.dev</version>
20+
<version>3.3.2.6.dev</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
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.3.2.5.dev</version>
15+
<version>3.3.2.6.dev</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>

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.2.5.dev</version>
8+
<version>3.3.2.6.dev</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.2.5.dev</version>
9+
<version>3.3.2.6.dev</version>
1010
</parent>
1111

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

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,16 @@ public FlowRecord createRecord(long workId,
202202
//寻找委托人
203203
flowOperator = flowOperator.entrustOperator();
204204
}
205-
206205
FlowRecord record = new FlowRecord();
207206
record.setProcessId(processId);
208207
record.setNodeCode(this.code);
209208
record.setCreateTime(System.currentTimeMillis());
210209
record.setWorkId(workId);
211210
record.setFlowStatus(FlowStatus.RUNNING);
212211
record.setPostponedCount(0);
213-
record.setCreateOperatorId(createOperator.getUserId());
212+
record.setCreateOperator(createOperator);
214213
record.setBindClass(snapshot.getClazzName());
215-
record.setCurrentOperatorId(flowOperator.getUserId());
214+
record.setCurrentOperator(flowOperator);
216215
record.setPreId(preId);
217216
record.setTitle(title);
218217
record.setTimeoutTime(this.loadTimeoutTime());

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/pojo/FlowDetail.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public FlowDetail(FlowRecord flowRecord,
7070
this.bindData = snapshot.toBindData();
7171
this.historyRecords = historyRecords;
7272
this.opinions = historyRecords.stream().map(FlowOpinion::new).toList();
73-
this.flowCreator = operators.stream().filter(o -> o.getUserId() == flowRecord.getCreateOperatorId()).findFirst().orElse(null);
73+
this.flowCreator = flowRecord.getCreateOperator();
7474
this.flowCreateTime = flowRecord.getCreateTime();
7575
this.flowNode = flowWork.getNodeByCode(flowRecord.getNodeCode());
7676
}
@@ -86,7 +86,7 @@ public final class FlowOpinion {
8686
public FlowOpinion(FlowRecord flowRecord) {
8787
this.recordId = flowRecord.getId();
8888
this.opinion = flowRecord.getOpinion();
89-
this.operator = operators.stream().filter(o -> o.getUserId() == flowRecord.getCurrentOperatorId()).findFirst().orElse(null);
89+
this.operator = flowRecord.getCurrentOperator();
9090
this.createTime = flowRecord.getUpdateTime();
9191
}
9292
}

0 commit comments

Comments
 (0)