1 package com.supwisdom.institute.backend.system.domain.repo;
4 import java.util.Optional;
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;
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;
17 public interface AccountRepository extends BaseJpaRepository<Account> {
19 public default Page<Account> selectPageList(int pageIndex, int pageSize, Account probe) {
21 ExampleMatcher matcher = ExampleMatcher.matching()
22 .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
23 .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
24 .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
26 PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
27 Example<Account> example = Example.of(probe, matcher);
29 Page<Account> page = this.findAll(example, pageRequest);
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"));
42 ExampleMatcher matcher = ExampleMatcher.matching()
43 .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
44 .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
45 .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
47 PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
48 Example<Account> example = Example.of(probe, matcher);
50 Page<Account> page = this.findAll(example, pageRequest);
56 public default User selectById(String id) {
59 Optional<User> entity = this.findById(id);
62 } catch(RuntimeException e) {
63 System.out.println("RuntimeException:"+e.getMessage());
64 } catch(Exception e) {
65 System.out.println("Exception:"+e.getMessage());
71 public default User insert(User entity) {
73 if (entity.getCompanyId() == null || entity.getCompanyId().isEmpty()) {
74 entity.setCompanyId("1");
77 entity.setDeleted(false);
78 //entity.setAddAccount(AuthUtil.getRemoteUser());
79 entity.setAddTime(Calendar.getInstance().getTime());
81 User e = this.save(entity);
86 public default User update(User entity) {
88 //entity.setEditAccount(AuthUtil.getRemoteUser());
89 entity.setEditTime(Calendar.getInstance().getTime());
91 User e = this.save(entity);
97 public default Account selectByUsername(String username) {
98 Account probe = new Account();
99 probe.setUsername(username);
101 ExampleMatcher matcher = ExampleMatcher.matching()
102 .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.exact());
104 Example<Account> example = Example.of(probe, matcher);
106 Optional<Account> u = this.findOne(example);