liupeng 5 gadi atpakaļ
vecāks
revīzija
bfe574e33d

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

@@ -17,10 +17,6 @@
 	<select id="selectListByParentId" resultType="SapOrg">
 		select * from sap_org 
 		where 1=1
-		and id in (SELECT DISTINCT firstOrgId from sap_user where delFlag = 0
-			union all SELECT DISTINCT secondOrgId from sap_user where delFlag = 0
-			union all SELECT DISTINCT thirdOrgId from sap_user where delFlag = 0
-			union all SELECT DISTINCT fourthOrgId from sap_user where delFlag = 0)
 		<if test="parentId != null and parentId != ''">
 			and parentId=#{parentId} 
 		</if>
@@ -29,10 +25,6 @@
 	<select id="selectListByName" resultType="SapOrg">
 		select * from sap_org 
 		where sapName like CONCAT(CONCAT('%', #{pd.name}),'%')
-		and id in (SELECT DISTINCT firstOrgId from sap_user where delFlag = 0
-			union all SELECT DISTINCT secondOrgId from sap_user where delFlag = 0
-			union all SELECT DISTINCT thirdOrgId from sap_user where delFlag = 0
-			union all SELECT DISTINCT fourthOrgId from sap_user where delFlag = 0)
 	</select>
 	
 	<select id="selectById" resultType="SapOrg">
@@ -42,4 +34,12 @@
 	<update id="updateWxDepartId">
 		update sap_org set wxDepartId=#{wxDepartId} where id=#{id}
 	</update>
+	
+	<delete id="deleteNotUsed">
+		delete from sap_org 
+		where id not in (SELECT DISTINCT firstOrgId from sap_user where delFlag = 0
+			union all SELECT DISTINCT secondOrgId from sap_user where delFlag = 0
+			union all SELECT DISTINCT thirdOrgId from sap_user where delFlag = 0
+			union all SELECT DISTINCT fourthOrgId from sap_user where delFlag = 0)
+	</delete>
 </mapper>

+ 7 - 1
code/sapparent/sapservice/src/main/java/org/fouram/service/SapOrgService.java

@@ -126,6 +126,8 @@ public class SapOrgService extends BaseService {
 	}
 
 	public Map<String, Long> updateAllWxDepartId() throws Exception {
+		// 删除未使用部门
+		deleteNotUsed();
 		Map<String, Long> result = Maps.newHashMap();
 		List<SapOrg> firstOrgs = selectListByParentId(WebConstants.TOP_DEPART.toString());
 		List<SapOrg> allOrgs = Lists.newArrayList();
@@ -169,7 +171,11 @@ public class SapOrgService extends BaseService {
 	public void updateWxDepartId(SapOrg org) throws Exception {
 		update("SapOrgMapper.updateWxDepartId", org);
 	}
-
+	
+	public void deleteNotUsed() throws Exception {
+		delete("SapOrgMapper.deleteNotUsed", null);
+	}
+	
 	@SuppressWarnings("unchecked")
 	public List<SapOrg> selectListByName(String name) throws Exception {
 		return toInfoDetails((List<SapOrg>) findList("SapOrgMapper.selectListByName", name));