55import com .codingapi .flow .infra .entity .FlowTodoRecordEntity ;
66import com .codingapi .flow .infra .jpa .FlowRecordEntityRepository ;
77import com .codingapi .flow .infra .jpa .FlowTodoRecordEntityRepository ;
8+ import com .codingapi .flow .mock .FlowQueryMockService ;
9+ import com .codingapi .flow .mock .FlowServiceMockFactory ;
810import com .codingapi .flow .operator .IFlowOperator ;
911import com .codingapi .flow .pojo .response .FlowRecordContent ;
1012import com .codingapi .springboot .framework .dto .request .Relation ;
1113import com .codingapi .springboot .framework .dto .request .SearchRequest ;
1214import com .codingapi .springboot .framework .dto .response .MultiResponse ;
1315import com .codingapi .springboot .framework .user .UserContext ;
16+ import jakarta .servlet .http .HttpServletRequest ;
1417import lombok .AllArgsConstructor ;
1518import org .springframework .data .domain .Page ;
1619import org .springframework .data .domain .PageRequest ;
1720import org .springframework .data .domain .Sort ;
21+ import org .springframework .util .StringUtils ;
1822import org .springframework .web .bind .annotation .GetMapping ;
1923import org .springframework .web .bind .annotation .RequestMapping ;
2024import 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