25
25
import io .swagger .v3 .oas .annotations .Parameter ;
26
26
import io .swagger .v3 .oas .annotations .tags .Tag ;
27
27
import org .springframework .beans .factory .annotation .Autowired ;
28
+ import org .springframework .data .domain .Page ;
29
+ import org .springframework .data .domain .PageRequest ;
30
+ import org .springframework .data .domain .Sort ;
28
31
import org .springframework .data .jpa .domain .Specification ;
29
32
import org .springframework .http .ResponseEntity ;
30
33
import org .springframework .web .bind .annotation .DeleteMapping ;
@@ -85,8 +88,12 @@ public ResponseEntity<Message<Void>> deleteNoticeReceiver(
85
88
@ GetMapping (path = "/receivers" )
86
89
@ Operation (summary = "Get a list of message notification recipients based on query filter items" ,
87
90
description = "根据查询过滤项获取消息通知接收人列表" )
88
- public ResponseEntity <Message <List <NoticeReceiver >>> getReceivers (
89
- @ Parameter (description = "en: Recipient name,zh: 接收人名称,模糊查询" , example = "tom" ) @ RequestParam (required = false ) final String name ) {
91
+ public ResponseEntity <Message <Page <NoticeReceiver >>> getReceivers (
92
+ @ Parameter (description = "en: Recipient name,zh: 接收人名称,模糊查询" , example = "tom" ) @ RequestParam (required = false ) final String name ,
93
+ @ Parameter (description = "en: Sort Field,default id,zh: 排序字段,默认更新时间" , example = "name" ) @ RequestParam (defaultValue = "gmtUpdate" ) final String sort ,
94
+ @ Parameter (description = "en: Sort by,zh: 排序方式,asc:升序,desc:降序" , example = "desc" ) @ RequestParam (defaultValue = "desc" ) final String order ,
95
+ @ Parameter (description = "en: List current page,zh: 列表当前分页" , example = "0" ) @ RequestParam (defaultValue = "0" ) int pageIndex ,
96
+ @ Parameter (description = "en: Number of list pagination,zh: 列表分页数量" , example = "8" ) @ RequestParam (defaultValue = "8" ) int pageSize ) {
90
97
Specification <NoticeReceiver > specification = (root , query , criteriaBuilder ) -> {
91
98
Predicate predicate = criteriaBuilder .conjunction ();
92
99
if (name != null && !"" .equals (name )) {
@@ -95,8 +102,10 @@ public ResponseEntity<Message<List<NoticeReceiver>>> getReceivers(
95
102
}
96
103
return predicate ;
97
104
};
98
- List <NoticeReceiver > receivers = noticeConfigService .getNoticeReceivers (specification );
99
- Message <List <NoticeReceiver >> message = new Message <>(receivers );
105
+ Sort sortExp = Sort .by (new Sort .Order (Sort .Direction .fromString (order ), sort ));
106
+ PageRequest pageRequest = PageRequest .of (pageIndex , pageSize , sortExp );
107
+ Page <NoticeReceiver > receivers = noticeConfigService .getNoticeReceivers (specification , pageRequest );
108
+ Message <Page <NoticeReceiver >> message = new Message <>(receivers );
100
109
return ResponseEntity .ok (message );
101
110
}
102
111
@@ -131,8 +140,12 @@ public ResponseEntity<Message<Void>> deleteNoticeRule(
131
140
@ GetMapping (path = "/rules" )
132
141
@ Operation (summary = "Get a list of message notification policies based on query filter items" ,
133
142
description = "根据查询过滤项获取消息通知策略列表" )
134
- public ResponseEntity <Message <List <NoticeRule >>> getRules (
135
- @ Parameter (description = "en: Recipient name,zh: 接收人名称,模糊查询" , example = "rule1" ) @ RequestParam (required = false ) final String name ) {
143
+ public ResponseEntity <Message <Page <NoticeRule >>> getRules (
144
+ @ Parameter (description = "en: Recipient name,zh: 接收人名称,模糊查询" , example = "rule1" ) @ RequestParam (required = false ) final String name ,
145
+ @ Parameter (description = "en: Sort Field,default id,zh: 排序字段,默认更新时间" , example = "name" ) @ RequestParam (defaultValue = "gmtUpdate" ) final String sort ,
146
+ @ Parameter (description = "en: Sort by,zh: 排序方式,asc:升序,desc:降序" , example = "desc" ) @ RequestParam (defaultValue = "desc" ) final String order ,
147
+ @ Parameter (description = "en: List current page,zh: 列表当前分页" , example = "0" ) @ RequestParam (defaultValue = "0" ) int pageIndex ,
148
+ @ Parameter (description = "en: Number of list pagination,zh: 列表分页数量" , example = "8" ) @ RequestParam (defaultValue = "8" ) int pageSize ) {
136
149
Specification <NoticeRule > specification = (root , query , criteriaBuilder ) -> {
137
150
Predicate predicate = criteriaBuilder .conjunction ();
138
151
if (name != null && !"" .equals (name )) {
@@ -141,8 +154,10 @@ public ResponseEntity<Message<List<NoticeRule>>> getRules(
141
154
}
142
155
return predicate ;
143
156
};
144
- List <NoticeRule > receiverPage = noticeConfigService .getNoticeRules (specification );
145
- Message <List <NoticeRule >> message = new Message <>(receiverPage );
157
+ Sort sortExp = Sort .by (new Sort .Order (Sort .Direction .fromString (order ), sort ));
158
+ PageRequest pageRequest = PageRequest .of (pageIndex , pageSize , sortExp );
159
+ Page <NoticeRule > receiverPage = noticeConfigService .getNoticeRules (specification , pageRequest );
160
+ Message <Page <NoticeRule >> message = new Message <>(receiverPage );
146
161
return ResponseEntity .ok (message );
147
162
}
148
163
0 commit comments