File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed
springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository
springboot-starter/src/main/java/com/codingapi/springboot/framework Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .fast .jpa .repository ;
2+
3+ import com .codingapi .springboot .framework .domain .ISort ;
4+ import com .codingapi .springboot .framework .dto .request .SortRequest ;
5+ import org .springframework .data .jpa .repository .JpaRepository ;
6+ import org .springframework .data .repository .NoRepositoryBean ;
7+
8+ import java .util .ArrayList ;
9+ import java .util .List ;
10+
11+ @ NoRepositoryBean
12+ public interface SortRepository <T extends ISort , ID > extends JpaRepository <T , ID > {
13+
14+
15+ default void reSort (SortRequest request ) {
16+ if (request != null && !request .getIds ().isEmpty ()) {
17+ List <T > list = new ArrayList <>();
18+ int minSort = 0 ;
19+ for (Object objectId : request .getIds ()) {
20+ ID id = (ID ) objectId ;
21+ T t = getReferenceById (id );
22+ if (t .getSort () != null && t .getSort () < minSort ) {
23+ minSort = t .getSort ();
24+ }
25+ list .add (t );
26+ }
27+ for (T t : list ) {
28+ t .setSort (minSort ++);
29+ }
30+ saveAll (list );
31+ }
32+ }
33+
34+
35+ }
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .domain ;
2+
3+ public interface ISort {
4+
5+ void setSort (Integer sort );
6+
7+ Integer getSort ();
8+ }
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .dto .request ;
2+
3+ import lombok .Getter ;
4+ import lombok .Setter ;
5+
6+ import java .util .List ;
7+
8+ @ Setter
9+ @ Getter
10+ public class SortRequest {
11+
12+ private List <Object > ids ;
13+
14+ }
You can’t perform that action at this time.
0 commit comments