|
@@ -1,20 +1,35 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.api.provider;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
+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.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgsReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.SaveOrgReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgsResp;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.SaveOrgResp;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
|
|
@@ -104,4 +119,53 @@ public class OrgCloudServiceProvider extends ControllerSupport implements OrgClo
|
|
|
resp.setOrg(orgBean);
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GetOrgsResp getOrgs(@RequestBody GetOrgsReq req) {
|
|
|
+
|
|
|
+ Long parentId = req.getParentId();
|
|
|
+
|
|
|
+ final Long start = null == req.getStart() ? 1 : req.getStart();
|
|
|
+
|
|
|
+ Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "id");
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if (null == parentId) {
|
|
|
+ predicates.add(cb.isNull(root.get("parentId")));
|
|
|
+ } else {
|
|
|
+ predicates.add(cb.equal(root.get("parentId"), parentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ predicates.add(cb.greaterThanOrEqualTo(root.get("id"), start));
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Page<OrgEntity> page = orgRepo.findAll(specification, pageable);
|
|
|
+
|
|
|
+ Iterator<OrgEntity> iterator = page.iterator();
|
|
|
+
|
|
|
+ List<OrgBean> list = Lists.newArrayList();
|
|
|
+ long next = 0;
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ OrgEntity org = iterator.next();
|
|
|
+ OrgBean orgBean = new OrgBean();
|
|
|
+ orgBean.setId(org.getId());
|
|
|
+ orgBean.setName(org.getName());
|
|
|
+ orgBean.setCode(org.getCode());
|
|
|
+ orgBean.setParentId(org.getParentId());
|
|
|
+ orgBean.setRootId(org.getRootId());
|
|
|
+ orgBean.setEnable(org.getEnable());
|
|
|
+
|
|
|
+ next = org.getId();
|
|
|
+ list.add(orgBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ GetOrgsResp resp = new GetOrgsResp();
|
|
|
+ next++;
|
|
|
+ resp.setNext(next);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|