wangwei преди 7 години
родител
ревизия
db6d670c2e

+ 37 - 6
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -9,6 +9,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.persistence.criteria.Predicate;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -21,6 +22,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -123,15 +125,44 @@ public class OrgController extends ControllerSupport {
 		return orgList;
 	}
 
-	@ApiOperation(value = "查询下属机构分页带查询", notes = "分页")
-	@GetMapping("/sub/{parentId}/{curPage}/{pageSize}")
-	public Page<Org> getAllSubOrg(@ModelAttribute Org orgCriteria, @PathVariable Long parentId,
-			@PathVariable Integer curPage, @PathVariable Integer pageSize) {
+	/**
+	 * 修改请通知作者
+	 *
+	 * @author WANGWEI
+	 * @param curPage
+	 * @param pageSize
+	 * @param rootOrgId
+	 * @param code
+	 * @param name
+	 * @return
+	 */
+	@ApiOperation(value = "模糊查询顶级机构的子机构")
+	@GetMapping("/getSubOrgList/{curPage}/{pageSize}")
+	public Page<Org> getSubOrgListOfRootOrg(@PathVariable Integer curPage,
+			@PathVariable Integer pageSize, @RequestParam Long parentOrgId,
+			@RequestParam String code, @RequestParam String name) {
 
-		orgCriteria.setParentId(parentId);
 		Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
 				"updateTime");
-		Page<Org> ret = orgService.findAll(orgCriteria, pageable);
+
+		Org criteria = new Org();
+		criteria.setParentId(parentOrgId);
+		criteria.setCode(code);
+		criteria.setName(name);
+
+		Specification<Org> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			if (StringUtils.isNotEmpty(criteria.getName())) {
+				predicates.add(cb.like(root.get("name"), toSqlSearchPattern(criteria.getName())));
+			}
+			if (StringUtils.isNotEmpty(criteria.getCode())) {
+				predicates.add(cb.like(root.get("code"), toSqlSearchPattern(criteria.getCode())));
+			}
+			predicates.add(cb.equal(root.get("parentId"), criteria.getParentId()));
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		Page<Org> ret = orgRepo.findAll(specification, pageable);
 		return ret;
 	}