wangwei 7 年 前
コミット
3e86575f74

+ 17 - 9
examcloud-core-basic-api-client/src/main/java/cn/com/qmth/examcloud/core/basic/api/client/OrgCloudServiceClient.java

@@ -5,30 +5,38 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
 import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgListByNameLikeReq;
 import cn.com.qmth.examcloud.core.basic.api.request.OrgReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgListByNameLikeResp;
 import cn.com.qmth.examcloud.core.basic.api.response.OrgResp;
 
 /**
  * 机构服务客户端
- * @author  	chenken
- * @date    	2018年5月4日 下午3:28:53
- * @company 	QMTH
+ * 
+ * @author chenken
+ * @date 2018年5月4日 下午3:28:53
+ * @company QMTH
  * @description OrgCloudServiceClient.java
  */
 @Service
-public class OrgCloudServiceClient extends BasicCloudClientSupport implements OrgCloudService{
-	
+public class OrgCloudServiceClient extends BasicCloudClientSupport implements OrgCloudService {
+
 	@Autowired
 	RestTemplate restTemplate;
 
+	@Override
+	protected RestTemplate getRestTemplate() {
+		return restTemplate;
+	}
+
 	@Override
 	public OrgResp saveOrg(OrgReq orgReq) {
-		return post("org", orgReq, OrgResp.class);
+		return post("org/saveOrg", orgReq, OrgResp.class);
 	}
 
 	@Override
-	protected RestTemplate getRestTemplate() {
-		return restTemplate;
+	public GetOrgListByNameLikeResp getOrgListByNameLike(GetOrgListByNameLikeReq req) {
+		return post("org/getOrgListByNameLike", req, GetOrgListByNameLikeResp.class);
 	}
-	
+
 }

+ 54 - 12
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/OrgCloudServiceProvider.java

@@ -1,44 +1,86 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
-import io.swagger.annotations.ApiOperation;
+import java.util.List;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 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.common.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.GetOrgListByNameLikeReq;
 import cn.com.qmth.examcloud.core.basic.api.request.OrgReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgListByNameLikeResp;
 import cn.com.qmth.examcloud.core.basic.api.response.OrgResp;
+import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
 import cn.com.qmth.examcloud.core.basic.service.impl.OrgService;
-
+import io.swagger.annotations.ApiOperation;
 
 @RestController
 @RequestMapping("${url.prefix}/org")
-public class OrgCloudServiceProvider  extends ControllerSupport implements OrgCloudService{
+public class OrgCloudServiceProvider extends ControllerSupport implements OrgCloudService {
 
 	@Autowired
 	private OrgService orgService;
-	
+
+	@Autowired
+	private OrgRepo orgRepo;
+
 	@ApiOperation(value = "保存机构", notes = "保存机构")
-	@PostMapping
+	@PostMapping("saveOrg")
 	@Override
 	public OrgResp saveOrg(OrgReq orgReq) throws Exception {
 		OrgResp orgResp = new OrgResp();
-		Org org = orgService.findFirstByParentIdAndCode(orgReq.getRootOrgId(),orgReq.getOrgCode());
-		if(org == null){
+		Org org = orgService.findFirstByParentIdAndCode(orgReq.getRootOrgId(), orgReq.getOrgCode());
+		if (org == null) {
 			org = new Org();
 			org.setName(orgReq.getOrgName());
-            org.setCode(orgReq.getOrgCode());
-            org.setParentId(orgReq.getRootOrgId());
-            org.setRootId(orgReq.getRootOrgId());
-            org.setEnable(true);
-            org = orgService.save(org);
+			org.setCode(orgReq.getOrgCode());
+			org.setParentId(orgReq.getRootOrgId());
+			org.setRootId(orgReq.getRootOrgId());
+			org.setEnable(true);
+			org = orgService.save(org);
 		}
 		orgResp.setId(org.getId());
 		orgResp.setName(org.getName());
 		return orgResp;
 	}
+
+	@ApiOperation(value = "按机构名称模糊查询机构列表", notes = "按机构名称模糊查询机构列表")
+	@PostMapping("getOrgListByNameLike")
+	@Override
+	public GetOrgListByNameLikeResp getOrgListByNameLike(GetOrgListByNameLikeReq req) {
+		String orgName = req.getOrgName();
+		String rootOrgId = req.getRootOrgId();
+
+		List<Org> list = Lists.newArrayList();
+		if (StringUtils.isNotBlank(orgName)) {
+			list = orgRepo.findByRootIdAndNameLike(Long.parseLong(rootOrgId), orgName);
+		}
+
+		GetOrgListByNameLikeResp resp = new GetOrgListByNameLikeResp();
+		List<OrgBean> orgList = Lists.newArrayList();
+		resp.setOrgList(orgList);
+
+		if (CollectionUtils.isNotEmpty(list)) {
+			for (Org curOrg : list) {
+				OrgBean orgBean = new OrgBean();
+				orgBean.setId(curOrg.getId());
+				orgBean.setLevel(curOrg.getLevel());
+				orgBean.setName(curOrg.getName());
+				orgBean.setParentId(curOrg.getParentId());
+				orgBean.setRootId(curOrg.getRootId());
+				orgList.add(orgBean);
+			}
+		}
+
+		return resp;
+	}
 }

+ 9 - 4
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/OrgCloudService.java

@@ -1,17 +1,22 @@
 package cn.com.qmth.examcloud.core.basic.api;
 
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgListByNameLikeReq;
 import cn.com.qmth.examcloud.core.basic.api.request.OrgReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgListByNameLikeResp;
 import cn.com.qmth.examcloud.core.basic.api.response.OrgResp;
 
 /**
  * 机构服务
- * @author  	chenken
- * @date    	2018年5月4日 下午3:27:55
- * @company 	QMTH
+ * 
+ * @author chenken
+ * @date 2018年5月4日 下午3:27:55
+ * @company QMTH
  * @description OrgCloudService.java
  */
 public interface OrgCloudService {
 
 	public OrgResp saveOrg(OrgReq orgReq) throws Exception;
-	
+
+	GetOrgListByNameLikeResp getOrgListByNameLike(GetOrgListByNameLikeReq req);
+
 }

+ 64 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/bean/OrgBean.java

@@ -0,0 +1,64 @@
+package cn.com.qmth.examcloud.core.basic.api.bean;
+
+import java.io.Serializable;
+
+/**
+ * 
+ * @author WANG
+ *
+ */
+public class OrgBean implements Serializable {
+
+	private static final long serialVersionUID = -4045967342902486442L;
+
+	private Long id;
+
+	private Long rootId;
+
+	private Long parentId;
+
+	private Integer level;
+
+	private String name;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootId() {
+		return rootId;
+	}
+
+	public void setRootId(Long rootId) {
+		this.rootId = rootId;
+	}
+
+	public Long getParentId() {
+		return parentId;
+	}
+
+	public void setParentId(Long parentId) {
+		this.parentId = parentId;
+	}
+
+	public Integer getLevel() {
+		return level;
+	}
+
+	public void setLevel(Integer level) {
+		this.level = level;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+}

+ 29 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/request/GetOrgListByNameLikeReq.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.core.basic.api.request;
+
+import cn.com.qmth.examcloud.common.support.BaseRequest;
+
+public class GetOrgListByNameLikeReq extends BaseRequest {
+
+	private static final long serialVersionUID = 612496100625952940L;
+
+	private String rootOrgId;
+
+	private String orgName;
+
+	public String getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(String rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public String getOrgName() {
+		return orgName;
+	}
+
+	public void setOrgName(String orgName) {
+		this.orgName = orgName;
+	}
+
+}

+ 22 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/response/GetOrgListByNameLikeResp.java

@@ -0,0 +1,22 @@
+package cn.com.qmth.examcloud.core.basic.api.response;
+
+import java.util.List;
+
+import cn.com.qmth.examcloud.common.support.BaseResponse;
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
+
+public class GetOrgListByNameLikeResp extends BaseResponse {
+
+	private static final long serialVersionUID = -4635477352326141785L;
+
+	List<OrgBean> orgList;
+
+	public List<OrgBean> getOrgList() {
+		return orgList;
+	}
+
+	public void setOrgList(List<OrgBean> orgList) {
+		this.orgList = orgList;
+	}
+
+}

+ 5 - 3
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/OrgRepo.java

@@ -15,15 +15,17 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
  */
 public interface OrgRepo extends JpaRepository<Org,Long>,QueryByExampleExecutor<Org> , JpaSpecificationExecutor<Org>{
 
-    List<Org> findByRootId(long rootId);
+    List<Org> findByRootId(Long rootId);
+    
+	List<Org> findByRootIdAndNameLike(long rootId, String name);
 
-    List<Org> findById(long id);
+    List<Org> findById(Long id);
 
     @Query(nativeQuery = true,value = "select *from ecs_core_org where parent_id=:parentId")
     List<Org> findBothByParentId(@Param("parentId") long parentId);
 
     @Query(nativeQuery = true,value = "select *from ecs_core_org where parent_id=:parentId and enable = 1")
-    List<Org> findByParentId(@Param("parentId") long parentId);
+    List<Org> findByParentId(@Param("parentId") Long parentId);
 
     @Query(nativeQuery = true,value = "select *from ecs_core_org where (id=:parentId or parent_id=:parentId) and enable = 1 and type = \"SCHOOL\"")
     List<Org> findAllSchoolByParentId(@Param("parentId") long parentId);