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);
35 public default Page<Account> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
38 pageSize = Integer.MAX_VALUE;
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"));
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());
55 PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
56 Example<Account> example = Example.of(probe, matcher);
58 Page<Account> page = this.findAll(example, pageRequest);
64 public default User selectById(String id) {
67 Optional<User> entity = this.findById(id);
70 } catch(RuntimeException e) {
71 System.out.println("RuntimeException:"+e.getMessage());
72 } catch(Exception e) {
73 System.out.println("Exception:"+e.getMessage());
79 public default User insert(User entity) {
81 if (entity.getCompanyId() == null || entity.getCompanyId().isEmpty()) {
82 entity.setCompanyId("1");
85 entity.setDeleted(false);
86 //entity.setAddAccount(AuthUtil.getRemoteUser());
87 entity.setAddTime(Calendar.getInstance().getTime());
89 User e = this.save(entity);
94 public default User update(User entity) {
96 //entity.setEditAccount(AuthUtil.getRemoteUser());
97 entity.setEditTime(Calendar.getInstance().getTime());
99 User e = this.save(entity);
105 public default Account selectByUsername(String username) {
106 Account probe = new Account();
107 probe.setUsername(username);
109 ExampleMatcher matcher = ExampleMatcher.matching()
110 .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.exact());
112 Example<Account> example = Example.of(probe, matcher);
114 Optional<Account> u = this.findOne(example);