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.Resource;
17 public interface ResourceRepository extends BaseJpaRepository<Resource> {
20 public default Page<Resource> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
23 pageSize = Integer.MAX_VALUE;
26 Resource probe = new Resource();
27 if (mapBean != null) {
28 probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
29 probe.setCode(MapBeanUtils.getString(mapBean, "code"));
30 probe.setName(MapBeanUtils.getString(mapBean, "name"));
31 probe.setMemo(MapBeanUtils.getString(mapBean, "memo"));
32 probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
35 ExampleMatcher matcher = ExampleMatcher.matching()
36 .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
37 .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.contains())
38 .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
39 .withMatcher("memo", ExampleMatcher.GenericPropertyMatchers.contains())
40 .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
42 PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
43 Example<Resource> example = Example.of(probe, matcher);
45 Page<Resource> page = this.findAll(example, pageRequest);
50 public default Resource selectByCode(String code) {
51 Resource probe = new Resource();
54 ExampleMatcher matcher = ExampleMatcher.matching()
55 .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.exact());
57 Example<Resource> example = Example.of(probe, matcher);
59 Optional<Resource> o = this.findOne(example);