e23f46e4e1fae09e309cb2f3f95b25c6afc6e1fb
[institute/sw-backend.git] /
1 package com.supwisdom.institute.backend.system.domain.repo;
2
3 import java.util.Map;
4 import java.util.Optional;
5
6 import org.springframework.data.domain.Example;
7 import org.springframework.data.domain.ExampleMatcher;
8 import org.springframework.data.domain.Page;
9 import org.springframework.data.domain.PageRequest;
10 import org.springframework.stereotype.Repository;
11
12 import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
13 import com.supwisdom.institute.backend.common.util.MapBeanUtils;
14 import com.supwisdom.institute.backend.system.domain.entity.Account;
15
16 @Repository
17 public interface AccountRepository extends BaseJpaRepository<Account> {
18   
19 //  public default Page<Account> selectPageList(int pageIndex, int pageSize, Account probe) {
20 //    
21 //    ExampleMatcher matcher = ExampleMatcher.matching()
22 //        .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
23 //        .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
24 //        .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
25 //    
26 //    PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
27 //    Example<Account> example = Example.of(probe, matcher);
28 //    
29 //    Page<Account> page = this.findAll(example, pageRequest);
30 //    
31 //    return page;
32 //  }
33   
34   @Override
35   public default Page<Account> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
36     if (loadAll) {
37       pageIndex = 0;
38       pageSize = Integer.MAX_VALUE;
39     }
40     
41     Account probe = new Account();
42     if (mapBean != null) {
43       probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
44       probe.setUsername(MapBeanUtils.getString(mapBean, "username"));
45       probe.setName(MapBeanUtils.getString(mapBean, "name"));
46       probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
47     }
48     
49     ExampleMatcher matcher = ExampleMatcher.matching()
50         .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
51         .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
52         .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
53         .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
54     
55     PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
56     Example<Account> example = Example.of(probe, matcher);
57     
58     Page<Account> page = this.findAll(example, pageRequest);
59     
60     return page;
61   }
62   
63   /*
64   public default User selectById(String id) {
65     
66     try {
67       Optional<User> entity = this.findById(id);
68       
69       return entity.get();
70     } catch(RuntimeException e) {
71       System.out.println("RuntimeException:"+e.getMessage());
72     } catch(Exception e) {
73       System.out.println("Exception:"+e.getMessage());
74     }
75     
76     return null;
77   }
78   
79   public default User insert(User entity) {
80     
81     if (entity.getCompanyId() == null || entity.getCompanyId().isEmpty()) {
82       entity.setCompanyId("1");
83     }
84     
85     entity.setDeleted(false);
86     //entity.setAddAccount(AuthUtil.getRemoteUser());
87     entity.setAddTime(Calendar.getInstance().getTime());
88     
89     User e = this.save(entity);
90     
91     return e;
92   }
93   
94   public default User update(User entity) {
95     
96     //entity.setEditAccount(AuthUtil.getRemoteUser());
97     entity.setEditTime(Calendar.getInstance().getTime());
98     
99     User e = this.save(entity);
100     
101     return e;
102   }
103   */
104   
105   public default Account selectByUsername(String username) {
106     Account probe = new Account();
107     probe.setUsername(username);
108     
109     ExampleMatcher matcher = ExampleMatcher.matching()
110         .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.exact());
111     
112     Example<Account> example = Example.of(probe, matcher);
113     
114     Optional<Account> u = this.findOne(example);
115     
116     if (u.isPresent()) {
117       return u.get();
118     }
119     
120     return null;
121   }
122
123 }