526350f0b908ea4964b7329380a6e9aaa218cf7b
[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   public default Page<Account> selectPageList(int pageIndex, int pageSize, Map<String, Object> mapBean) {
35     Account probe = new Account();
36     if (mapBean != null) {
37       probe.setUsername(MapBeanUtils.getString(mapBean, "username"));
38       probe.setName(MapBeanUtils.getString(mapBean, "name"));
39       probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
40     }
41     
42     ExampleMatcher matcher = ExampleMatcher.matching()
43         .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
44         .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
45         .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
46     
47     PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
48     Example<Account> example = Example.of(probe, matcher);
49     
50     Page<Account> page = this.findAll(example, pageRequest);
51     
52     return page;
53   }
54   
55   /*
56   public default User selectById(String id) {
57     
58     try {
59       Optional<User> entity = this.findById(id);
60       
61       return entity.get();
62     } catch(RuntimeException e) {
63       System.out.println("RuntimeException:"+e.getMessage());
64     } catch(Exception e) {
65       System.out.println("Exception:"+e.getMessage());
66     }
67     
68     return null;
69   }
70   
71   public default User insert(User entity) {
72     
73     if (entity.getCompanyId() == null || entity.getCompanyId().isEmpty()) {
74       entity.setCompanyId("1");
75     }
76     
77     entity.setDeleted(false);
78     //entity.setAddAccount(AuthUtil.getRemoteUser());
79     entity.setAddTime(Calendar.getInstance().getTime());
80     
81     User e = this.save(entity);
82     
83     return e;
84   }
85   
86   public default User update(User entity) {
87     
88     //entity.setEditAccount(AuthUtil.getRemoteUser());
89     entity.setEditTime(Calendar.getInstance().getTime());
90     
91     User e = this.save(entity);
92     
93     return e;
94   }
95   */
96   
97   public default Account selectByUsername(String username) {
98     Account probe = new Account();
99     probe.setUsername(username);
100     
101     ExampleMatcher matcher = ExampleMatcher.matching()
102         .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.exact());
103     
104     Example<Account> example = Example.of(probe, matcher);
105     
106     Optional<Account> u = this.findOne(example);
107     
108     if (u.isPresent()) {
109       return u.get();
110     }
111     
112     return null;
113   }
114
115 }