liupeng 5 år sedan
förälder
incheckning
13c885cbc9

+ 23 - 27
code/sapparent/sapcms/src/main/java/org/fouram/controller/ApiController.java

@@ -1,14 +1,13 @@
 package org.fouram.controller;
 
-import java.util.List;
+import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
+import org.fouram.constants.WebConstants;
 import org.fouram.core.base.controller.BaseController;
 import org.fouram.core.util.AppUtil;
 import org.fouram.core.util.AppUtil.ResultConstant;
 import org.fouram.core.util.LoggerUtil;
-import org.fouram.core.util.TreeUtil;
-import org.fouram.entity.SapOrg;
-import org.fouram.entity.SapUser;
 import org.fouram.service.SapOrgService;
 import org.fouram.service.SapUserService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,47 +15,44 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.google.common.collect.Maps;
+
 @Controller
 @RequestMapping(value = "/API")
 public class ApiController extends BaseController {
-	
+
 	@Autowired
 	private SapOrgService sapOrgService;
 	@Autowired
 	private SapUserService sapUserService;
 
-	@RequestMapping(value = "/getDepartTree", produces = "application/json;charset=utf-8")
+	@RequestMapping(value = "/getChildDepartAndUserListByDepartId", produces = "application/json;charset=utf-8")
 	@ResponseBody
-	public Object getDepartTree() {
+	public Object getChildDepartAndUserListByDepartId() {
 		try {
-			List<SapOrg> allOrgs = sapOrgService.findAll();
-			return AppUtil.success(TreeUtil.buildTreeSimple(allOrgs), null);
+			String departId = getPageData().getString("departId");
+			if (StringUtils.isBlank(departId)) {
+				departId = WebConstants.TOP_DEPART.toString();
+			}
+			Map<String, Object> result = Maps.newHashMap();
+			result.put("departList", sapOrgService.selectListByParentId(departId));
+			result.put("userList", sapUserService.selectListByDepartId(departId));
+			return AppUtil.success(result, null);
 		} catch (Exception e) {
 			LoggerUtil.error(e);
 			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
 		}
 	}
-	
-	@RequestMapping(value = "/getDepartListByName", produces = "application/json;charset=utf-8")
-	@ResponseBody
-	public Object getDepartListByName() {
-		try {
-			String name = getPageData().getString("name");
-			List<SapOrg> orgs = sapOrgService.getDepartListByName(name);
-			return AppUtil.success(orgs, null);
-		} catch (Exception e) {
-			LoggerUtil.error(e);
-			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
-		}
-	}
-	
-	@RequestMapping(value = "/getUserListByName", produces = "application/json;charset=utf-8")
+
+	@RequestMapping(value = "/getDepartAndUserListByName", produces = "application/json;charset=utf-8")
 	@ResponseBody
-	public Object getUserListByName() {
+	public Object getDepartAndUserListByName() {
 		try {
 			String name = getPageData().getString("name");
-			List<SapUser> users = sapUserService.getUserListByName(name);
-			return AppUtil.success(users, null);
+			Map<String, Object> result = Maps.newHashMap();
+			result.put("departList", sapOrgService.selectListByName(name));
+			result.put("userList", sapUserService.selectListByName(name));
+			return AppUtil.success(result, null);
 		} catch (Exception e) {
 			LoggerUtil.error(e);
 			return AppUtil.error(ResultConstant.WEB_ERR_MSG);

+ 2 - 2
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapOrgMapper.xml

@@ -14,7 +14,7 @@
 		select * from sap_org where parentId=#{parentId} and sapCode=#{sapCode} and level=#{level}
 	</select>
 	
-	<select id="findListByParentId" resultType="SapOrg">
+	<select id="selectListByParentId" resultType="SapOrg">
 		select * from sap_org 
 		where 1=1
 		<if test="parentId != null and parentId != ''">
@@ -22,7 +22,7 @@
 		</if>
 	</select>
 	
-	<select id="getDepartListByName" resultType="SapOrg">
+	<select id="selectListByName" resultType="SapOrg">
 		select * from sap_org where sapName like CONCAT(CONCAT('%', #{pd.name}),'%')
 	</select>
 	

+ 9 - 1
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapUserMapper.xml

@@ -65,9 +65,17 @@
 		select * from sap_user where result != '垃圾数据' or result is null
 	</select>
 	
-	<select id="getUserListByName" resultType="SapUser">
+	<select id="selectListByName" resultType="SapUser">
 		select * from sap_user 
 		where result = 'SUCCESS' and name like CONCAT(CONCAT('%', #{name}),'%')
 		order by sortNumber ASC
 	</select>
+	
+	<select id="selectListByDepartId" resultType="SapUser">
+		select * from sap_user 
+		where result = 'SUCCESS' and (
+			firstOrgWxDepartId = #{departId} or secondOrgWxDepartId = #{departId} 
+			or thirdOrgWxDepartId = #{departId} or fourthOrgWxDepartId = #{departId})
+		order by sortNumber ASC
+	</select>
 </mapper>

+ 8 - 12
code/sapparent/sapservice/src/main/java/org/fouram/service/SapOrgService.java

@@ -126,20 +126,20 @@ public class SapOrgService extends BaseService {
 
 	public Map<String, Long> updateAllWxDepartId() throws Exception {
 		Map<String, Long> result = Maps.newHashMap();
-		List<SapOrg> firstOrgs = findListByParentId(WebConstants.TOP_DEPART.toString());
+		List<SapOrg> firstOrgs = selectListByParentId(WebConstants.TOP_DEPART.toString());
 		List<SapOrg> allOrgs = Lists.newArrayList();
 		for (SapOrg firstOrg : firstOrgs) {
 			firstOrg.setWxDepartId(getWxDepartId(firstOrg, WebConstants.TOP_DEPART));
 			allOrgs.add(firstOrg);
-			List<SapOrg> sencodOrgs = findListByParentId(firstOrg.getId());
+			List<SapOrg> sencodOrgs = selectListByParentId(firstOrg.getId());
 			for (SapOrg sencodOrg : sencodOrgs) {
 				sencodOrg.setWxDepartId(getWxDepartId(sencodOrg, firstOrg.getWxDepartId()));
 				allOrgs.add(sencodOrg);
-				List<SapOrg> thirdOrgs = findListByParentId(sencodOrg.getId());
+				List<SapOrg> thirdOrgs = selectListByParentId(sencodOrg.getId());
 				for (SapOrg thirdOrg : thirdOrgs) {
 					thirdOrg.setWxDepartId(getWxDepartId(thirdOrg, sencodOrg.getWxDepartId()));
 					allOrgs.add(thirdOrg);
-					List<SapOrg> fourthOrgs = findListByParentId(thirdOrg.getId());
+					List<SapOrg> fourthOrgs = selectListByParentId(thirdOrg.getId());
 					for (SapOrg fourthOrg : fourthOrgs) {
 						fourthOrg.setWxDepartId(getWxDepartId(fourthOrg, thirdOrg.getWxDepartId()));
 						allOrgs.add(fourthOrg);
@@ -160,21 +160,17 @@ public class SapOrgService extends BaseService {
 	}
 
 	@SuppressWarnings("unchecked")
-	public List<SapOrg> findListByParentId(String parentId) throws Exception {
+	public List<SapOrg> selectListByParentId(String parentId) throws Exception {
 		SapOrg org = SapOrg.builder().parentId(parentId).build();
-		return (List<SapOrg>) findList("SapOrgMapper.findListByParentId", org);
+		return (List<SapOrg>) findList("SapOrgMapper.selectListByParentId", org);
 	}
 	
-	public List<SapOrg> findAll() throws Exception {
-		return findListByParentId(null);
-	}
-
 	public void updateWxDepartId(SapOrg org) throws Exception {
 		update("SapOrgMapper.updateWxDepartId", org);
 	}
 
 	@SuppressWarnings("unchecked")
-	public List<SapOrg> getDepartListByName(String name) throws Exception {
-		return (List<SapOrg>) findList("SapOrgMapper.getDepartListByName", name);
+	public List<SapOrg> selectListByName(String name) throws Exception {
+		return (List<SapOrg>) findList("SapOrgMapper.selectListByName", name);
 	}
 }

+ 7 - 2
code/sapparent/sapservice/src/main/java/org/fouram/service/SapUserService.java

@@ -189,7 +189,12 @@ public class SapUserService extends BaseService {
 	}
 
 	@SuppressWarnings("unchecked")
-	public List<SapUser> getUserListByName(String name) throws Exception {
-		return (List<SapUser>) findList("SapUserMapper.getUserListByName", name);
+	public List<SapUser> selectListByName(String name) throws Exception {
+		return (List<SapUser>) findList("SapUserMapper.selectListByName", name);
+	}
+
+	@SuppressWarnings("unchecked")
+	public List<SapUser> selectListByDepartId(String departId) throws Exception {
+		return (List<SapUser>) findList("SapUserMapper.selectListByDepartId", departId);
 	}
 }