WANG 6 年之前
父节点
当前提交
32f6a1d8c9

+ 48 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/SystemPropertyController.java

@@ -1,12 +1,26 @@
 package cn.com.qmth.examcloud.core.basic.api.controller;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.criteria.Predicate;
+
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import cn.com.qmth.examcloud.core.basic.dao.SystemPropertyRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.SystemPropertyEntity;
 import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
@@ -26,6 +40,9 @@ public class SystemPropertyController extends ControllerSupport {
 	@Autowired
 	SystemPropertyService systemPropertyService;
 
+	@Autowired
+	SystemPropertyRepo systemPropertyRepo;
+
 	@ApiOperation(value = "查询系统配置")
 	@GetMapping("{key}")
 	public Object get(@PathVariable String key) {
@@ -33,4 +50,35 @@ public class SystemPropertyController extends ControllerSupport {
 		return object;
 	}
 
+	@ApiOperation(value = "查询系统配置")
+	@GetMapping("page/{curPage}/{pageSize}")
+	public Page<SystemPropertyEntity> get(@PathVariable Integer curPage,
+			@PathVariable Integer pageSize, @RequestParam(required = false) String propKey,
+			@RequestParam(required = false) String description,
+			@RequestParam(required = false) String propValue) {
+
+		Specification<SystemPropertyEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+
+			if (StringUtils.isNotBlank(propKey)) {
+				predicates.add(cb.like(root.get("propKey"), toSqlSearchPattern(propKey)));
+			}
+			if (StringUtils.isNotBlank(description)) {
+				predicates.add(cb.like(root.get("description"), toSqlSearchPattern(description)));
+			}
+			if (StringUtils.isNotBlank(propValue)) {
+				predicates.add(cb.like(root.get("propValue"), toSqlSearchPattern(propValue)));
+			}
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		PageRequest pageRequest = PageRequest.of(curPage, pageSize,
+				new Sort(Direction.DESC, "updateTime"));
+
+		Page<SystemPropertyEntity> page = systemPropertyRepo.findAll(specification, pageRequest);
+
+		return page;
+	}
+
 }