Skip to content

Commit cc0e2ff

Browse files
committed
add #82
1 parent 29a8c7a commit cc0e2ff

4 files changed

Lines changed: 46 additions & 94 deletions

File tree

flow-engine-starter-api/src/main/java/com/codingapi/flow/api/controller/WorkflowController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public SingleResponse<String> mock() {
7676
return SingleResponse.of(FlowServiceMockFactory.getInstance().create(GatewayContext.getInstance().getFlowOperatorGateway()));
7777
}
7878

79+
@PostMapping("/cleanMock")
80+
public Response mock(@RequestBody IdRequest request) {
81+
FlowServiceMockFactory.getInstance().clear(request.getStringId());
82+
return Response.buildSuccess();
83+
}
84+
7985

8086
@PostMapping("/create")
8187
public SingleResponse<JSONObject> create() {

flow-engine-starter-query/src/main/java/com/codingapi/flow/query/controller/FlowRecordMockQueryController.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

flow-engine-starter-query/src/main/java/com/codingapi/flow/query/controller/FlowRecordQueryController.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55
import com.codingapi.flow.infra.entity.FlowTodoRecordEntity;
66
import com.codingapi.flow.infra.jpa.FlowRecordEntityRepository;
77
import com.codingapi.flow.infra.jpa.FlowTodoRecordEntityRepository;
8+
import com.codingapi.flow.mock.FlowQueryMockService;
9+
import com.codingapi.flow.mock.FlowServiceMockFactory;
810
import com.codingapi.flow.operator.IFlowOperator;
911
import com.codingapi.flow.pojo.response.FlowRecordContent;
1012
import com.codingapi.springboot.framework.dto.request.Relation;
1113
import com.codingapi.springboot.framework.dto.request.SearchRequest;
1214
import com.codingapi.springboot.framework.dto.response.MultiResponse;
1315
import com.codingapi.springboot.framework.user.UserContext;
16+
import jakarta.servlet.http.HttpServletRequest;
1417
import lombok.AllArgsConstructor;
1518
import org.springframework.data.domain.Page;
1619
import org.springframework.data.domain.PageRequest;
1720
import org.springframework.data.domain.Sort;
21+
import org.springframework.util.StringUtils;
1822
import org.springframework.web.bind.annotation.GetMapping;
1923
import org.springframework.web.bind.annotation.RequestMapping;
2024
import org.springframework.web.bind.annotation.RestController;
25+
import org.springframework.web.context.request.RequestContextHolder;
26+
import org.springframework.web.context.request.ServletRequestAttributes;
2127

2228
@RestController
2329
@RequestMapping("/api/query/record")
@@ -27,11 +33,28 @@ public class FlowRecordQueryController {
2733
private final FlowRecordEntityRepository flowRecordEntityRepository;
2834
private final FlowTodoRecordEntityRepository flowTodoRecordEntityRepository;
2935

36+
37+
private FlowQueryMockService loadFlowService(){
38+
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
39+
HttpServletRequest request = attributes.getRequest();
40+
String key = request.getParameter("mockKey");
41+
if(StringUtils.hasText(key)) {
42+
return FlowServiceMockFactory.getInstance().getFlowQueryService(key);
43+
}else {
44+
return null;
45+
}
46+
}
47+
3048
/**
3149
* 全部流程记录接口
3250
*/
3351
@GetMapping("/list")
3452
public MultiResponse<FlowRecordContent> list(SearchRequest request) {
53+
FlowQueryMockService flowQueryMockService = loadFlowService();
54+
if(flowQueryMockService!=null){
55+
PageRequest pageRequest = PageRequest.of(request.getCurrent(),request.getPageSize());
56+
return MultiResponse.of(flowQueryMockService.findAll(pageRequest));
57+
}
3558
request.addSort(Sort.by("id").descending());
3659
request.addFilter("revoked", Relation.EQUAL,false);
3760
Page<FlowRecordEntity> page = flowRecordEntityRepository.searchRequest(request);
@@ -45,6 +68,12 @@ public MultiResponse<FlowRecordContent> list(SearchRequest request) {
4568
@GetMapping("/todo")
4669
public MultiResponse<FlowRecordContent> todo(SearchRequest request) {
4770
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
71+
FlowQueryMockService flowQueryMockService = loadFlowService();
72+
if(flowQueryMockService!=null){
73+
PageRequest pageRequest = PageRequest.of(request.getCurrent(),request.getPageSize());
74+
return MultiResponse.of(flowQueryMockService.findTodoRecordPage(current.getUserId(),pageRequest.withSort(Sort.by("id").descending())));
75+
}
76+
4877
PageRequest pageRequest = request.toPageRequest(FlowRecordEntity.class);
4978
Page<FlowTodoRecordEntity> page = flowTodoRecordEntityRepository.findTodoRecordPage(current.getUserId(),pageRequest.withSort(Sort.by("id").descending()));
5079
return MultiResponse.of(page.map(FlowRecordContentConvertor::convert));
@@ -56,6 +85,11 @@ public MultiResponse<FlowRecordContent> todo(SearchRequest request) {
5685
@GetMapping("/notify")
5786
public MultiResponse<FlowRecordContent> notify(SearchRequest request) {
5887
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
88+
FlowQueryMockService flowQueryMockService = loadFlowService();
89+
if(flowQueryMockService!=null){
90+
PageRequest pageRequest = PageRequest.of(request.getCurrent(),request.getPageSize());
91+
return MultiResponse.of(flowQueryMockService.findNotifyRecordPage(current.getUserId(),pageRequest.withSort(Sort.by("id").descending())));
92+
}
5993
PageRequest pageRequest = request.toPageRequest(FlowRecordEntity.class);
6094
Page<FlowRecordEntity> page =flowRecordEntityRepository.findNotifyRecordPage(current.getUserId(),pageRequest.withSort(Sort.by("id").descending()));
6195
return MultiResponse.of(page.map(FlowRecordContentConvertor::convert));
@@ -68,6 +102,11 @@ public MultiResponse<FlowRecordContent> notify(SearchRequest request) {
68102
@GetMapping("/done")
69103
public MultiResponse<FlowRecordContent> done(SearchRequest request) {
70104
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
105+
FlowQueryMockService flowQueryMockService = loadFlowService();
106+
if(flowQueryMockService!=null){
107+
PageRequest pageRequest = PageRequest.of(request.getCurrent(),request.getPageSize());
108+
return MultiResponse.of(flowQueryMockService.findDoneRecordPage(current.getUserId(),pageRequest.withSort(Sort.by("id").descending())));
109+
}
71110
PageRequest pageRequest = request.toPageRequest(FlowRecordEntity.class);
72111
Page<FlowRecordEntity> page =flowRecordEntityRepository.findDoneRecordPage(current.getUserId(),pageRequest.withSort(Sort.by("id").descending()));
73112
return MultiResponse.of(page.map(FlowRecordContentConvertor::convert));

0 commit comments

Comments
 (0)