1 package com.supwisdom.institute.backend.system.domain.repo;
3 import org.springframework.data.domain.Example;
4 import org.springframework.data.domain.ExampleMatcher;
5 import org.springframework.data.domain.Page;
6 import org.springframework.data.domain.PageRequest;
7 import org.springframework.stereotype.Repository;
9 import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
10 import com.supwisdom.institute.backend.common.util.MapBeanUtils;
11 import com.supwisdom.institute.backend.system.domain.entity.Config;
14 import java.util.Optional;
20 public interface ConfigRepository extends BaseJpaRepository<Config> {
22 public default Page<Config> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
23 Config probe = new Config();
24 if (mapBean != null) {
25 probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
26 probe.setCategoryCode(MapBeanUtils.getString(mapBean, "categoryCode"));
27 probe.setCategoryName(MapBeanUtils.getString(mapBean, "categoryName"));
28 probe.setName(MapBeanUtils.getString(mapBean, "name"));
29 probe.setDescription(MapBeanUtils.getString(mapBean, "description"));
30 probe.setConfigKey(MapBeanUtils.getString(mapBean, "configKey"));
31 probe.setEditable(MapBeanUtils.getBoolean(mapBean, "editable"));
34 ExampleMatcher matcher = ExampleMatcher.matching()
35 .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
36 .withMatcher("categoryCode", ExampleMatcher.GenericPropertyMatchers.exact())
37 .withMatcher("categoryName", ExampleMatcher.GenericPropertyMatchers.contains())
38 .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
39 .withMatcher("description", ExampleMatcher.GenericPropertyMatchers.contains())
40 .withMatcher("configKey", ExampleMatcher.GenericPropertyMatchers.exact())
41 .withMatcher("editable", ExampleMatcher.GenericPropertyMatchers.exact())
46 pageSize = Integer.MAX_VALUE;
49 PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
50 Example<Config> example = Example.of(probe, matcher);
52 Page<Config> page = this.findAll(example, pageRequest);
57 public default Config selectByCategoryKey(String categoryCode, String configKey) {
58 Config probe = new Config();
60 probe.setDeleted(false);
61 probe.setCategoryCode(categoryCode);
62 probe.setConfigKey(configKey);
64 ExampleMatcher matcher = ExampleMatcher.matching()
65 .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
66 .withMatcher("categoryCode", ExampleMatcher.GenericPropertyMatchers.exact())
67 .withMatcher("configKey", ExampleMatcher.GenericPropertyMatchers.exact())
70 Example<Config> example = Example.of(probe, matcher);
72 Optional<Config> config = this.findOne(example);
74 return config.isPresent() ? config.get() : null;