<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.countrygarden.bi.main.dao.twerp.hm.ManagerMapForErpMapper">

	<select id="selectHouseCountPageDataByErp" resultType="cn.com.countrygarden.bi.main.dto.HouseKeeperDTO">
		SELECT COUNT(CASE WHEN bt.DictionaryName LIKE '%洋房' AND r.PropertyUses = '住宅' THEN 1 ELSE NULL END) houses
		,COUNT(CASE WHEN bt.DictionaryName LIKE '%别墅' AND r.PropertyUses = '住宅' THEN 1 ELSE NULL END) villas
		,COUNT(CASE r.PropertyUses WHEN '商业' THEN 1 ELSE NULL END) shops
		FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BuildHousekeeper] AS bh
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_Building] AS b  ON b.CommID = bh.CommID AND b.BuildSNum = bh.BuildSNum AND ISNULL(b.IsDelete,0) = 0 AND bh.rentid = b.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Dictionary_BuildType] AS bt  ON bt.DictionaryCode = b.BuildType AND bh.rentid = bt.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_Room] AS r  ON r.CommID = b.CommID AND r.BuildSNum = b.BuildSNum AND ISNULL(r.IsDelete,0) = 0 AND bh.rentid = r.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_User] AS u  ON u.UserCode = bh.UserCode AND ISNULL(u.IsDelete,0) = 0 AND bh.rentid = u.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c ON c.CommID = bh.CommID AND c.isDelete = 0 AND bh.rentid = c.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] AS o ON o.OrganCode = c.OrganCode AND o.isDelete = 0 AND bh.rentid = o.rentid
		<where>
			<if test="organName!=null and organName!=''">
				and o.OrganName = #{organName}
			</if>
			<if test="projectName!=null and projectName!=''">
				and REPLACE(REPLACE(REPLACE(c.CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '') = #{projectName}
			</if>
			<if test="name!=null and name!=''">
				and u.UserName = #{name}
			</if>
		</where>
		GROUP BY bh.UserCode
	</select>
	<select id="selectCommByErp" resultType="cn.com.countrygarden.bi.main.dto.HouseKeeperDTO">
		SELECT DISTINCT thb.DevelopmentSubject developmentSubject,c.CommName commName
		FROM  [dbo].[Tb_Sys_User] u
		INNER JOIN  [dbo].[Tb_Sys_UserRole] AS tsur ON ( tsur.UserCode = u.UserCode )  AND u.rentid = tsur.rentid
		INNER JOIN  [dbo].[Tb_Sys_RoleData] AS d ON ( d.RoleCode = tsur.RoleCode )   AND u.rentid = d.rentid
		INNER JOIN (SELECT CommID,CommName,isDelete,OrganCode,rentid FROM [dbo].[Tb_HSPR_Community]) AS c ON u.CommID = c.CommID  AND u.rentid = c.rentid <!-- AND c.isDelete = 0 -->
		INNER JOIN (SELECT OrganCode,OrganName,isDelete,rentid FROM [dbo].[Tb_Sys_Organ]) AS o ON o.OrganCode = c.OrganCode AND u.rentid = o.rentid <!-- AND c.isDelete = 0 -->
		INNER JOIN (SELECT DevelopmentSubject,CommID,rentid FROM [dbo].[Tb_HSPR_BasicInfo] WHERE IsDelete = 0 ) thb ON thb.CommID=c.CommID AND u.rentid = thb.rentid
		<where>
			<if test="organName!=null and organName!=''">
				and o.OrganName = #{organName}
			</if>
			<if test="commName!=null and commName!=''">
				and REPLACE(REPLACE(REPLACE(c.CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '') = REPLACE(REPLACE(REPLACE(#{commName}, '(测试)', ''), '(预生产)', ''), '(正式)', '')
			</if>
		</where>
	</select>
	<select id="selectDevelopmentsubjectTree" resultType="cn.com.countrygarden.bi.main.dto.HouseKeeperNameTreeDTO">
		SELECT DISTINCT ISNULL(thb.DevelopmentSubject,' ') code,ISNULL(thb.developmentsubject,' ') name
		FROM (SELECT DevelopmentSubject,CommID FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] where rentid=1853 AND IsDelete = 0) thb
	</select>
	<select id="selectDevelopmentsubjectData" resultType="cn.com.countrygarden.bi.main.dto.DevelopmentSubjectDTO">
		SELECT DISTINCT ISNULL(IIF(CHARINDEX('(', c.CommName)>1,REPLACE(c.CommName, RIGHT(c.CommName,CHARINDEX('(', REVERSE(c.CommName))), ''),c.CommName),'') commName,ISNULL(thb.DevelopmentSubject,'') developmentSubject,ISNULL(c.commId,' ') commId,ISNULL(thb.OrganCode,' ') organCode,ISNULL(thb.PropertyArea,' ') organName
		FROM (SELECT DevelopmentSubject,CommID,OrganCode ,PropertyArea FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] where rentid=1853 AND IsDelete = 0) thb
		LEFT JOIN (SELECT commId,CommName FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] where rentid=1853) c ON thb.CommID=c.commId
    </select>
	<select id="selectCommByDevelopmentsubject" resultType="cn.com.countrygarden.bi.main.dto.DevelopmentSubjectDTO">
		SELECT DISTINCT ISNULL(c.CommName,' ') commName,ISNULL(thb.DevelopmentSubject,' ') developmentSubject,ISNULL(c.commId,' ') commId,ISNULL(thb.OrganCode,' ') organCode,ISNULL(thb.PropertyArea,' ') organName
		FROM (SELECT DevelopmentSubject,CommID,OrganCode ,PropertyArea FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] WHERE IsDelete = 0 AND rentid = 1853) thb
		LEFT JOIN (SELECT commId,CommName FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] WHERE rentid = 1853) c ON thb.CommID=c.commId
		<where>
			<if test="commNames!=null and commNames.size()>0">
				REPLACE(REPLACE(REPLACE(c.CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '') in
				<foreach item="item" index="index" collection="commNames" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
	</select>
	<select id="selectCommByDevelopmentsubjectByOne" resultType="cn.com.countrygarden.bi.main.dto.DevelopmentSubjectDTO">
		SELECT TOP 1 ISNULL(c.CommName,' ') commName,ISNULL(thb.DevelopmentSubject,' ') developmentSubject,ISNULL(c.commId,' ') commId,ISNULL(thb.OrganCode,' ') organCode,ISNULL(thb.PropertyArea,' ') organName
		FROM (SELECT DevelopmentSubject,CommID,OrganCode ,PropertyArea FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] WHERE rentid = 1853 AND IsDelete = 0) thb
		LEFT JOIN (SELECT commId,CommName FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] WHERE rentid = 1853) c ON thb.CommID=c.commId
    	WHERE
			REPLACE(REPLACE(REPLACE(c.CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '') = #{commName}
    </select>
	<select id="selectDevelopmentsubjectByComm" resultType="cn.com.countrygarden.bi.main.dto.DevelopmentSubjectDTO">
		SELECT DISTINCT ISNULL(c.CommName,' ') commName,ISNULL(thb.DevelopmentSubject,' ') developmentSubject,ISNULL(c.commId,' ') commId,ISNULL(thb.OrganCode,' ') organCode,ISNULL(thb.PropertyArea,' ') organName
		FROM (SELECT DevelopmentSubject,CommID,OrganCode ,PropertyArea FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] WHERE rentid = 1853 AND IsDelete = 0) thb
		LEFT JOIN (SELECT CommId,CommName FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] WHERE IsDelete = 0 AND rentid = 1853) c ON thb.CommID=c.commId
		<if test="commName!=null">
			AND REPLACE(REPLACE(REPLACE(c.CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '') = #{commName}
		</if>
	</select>
	<select id="selectAllCommName" resultType="cn.com.countrygarden.bi.main.dto.HouseKeeperNameTreeDTO">
		SELECT CommName code,CommName name
		FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community]
		WHERE rentid = 1853
		GROUP BY CommName
		ORDER BY CommName DESC
    </select>
	<select id="queryCommInfo" resultType="cn.com.countrygarden.bi.main.dto.manager.CommunityInfo">
		SELECT c.CommID,c.CommName,o.OrganCode,o.OrganName
		,COALESCE(ci.CityCompany,'0002') AS CompanyCode
		,COALESCE(cc.DictionaryName,'碧桂园物业服务有限公司') AS CompanyName
		,COALESCE(cc.DictionaryOrderID,1) AS CompanyOrder
		,c.Province,c.City
		,(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID AND ISNULL(i.IsDelete,0) = 0) NCSystemNumber
		FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] AS c
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] AS o ON (o.OrganCode = c.OrganCode AND o.rentid=1853)
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_CoreIndex] AS ci ON (ci.OrganCode = o.OrganCode AND ci.rentid=1853)
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_Dictionary_CityCompany] AS cc ON (cc.DictionaryCode = ci.CityCompany AND cc.rentid=1853)
		WHERE (o.OrganName != '测试区域') AND (c.CommName != '测试项目') AND c.rentid=1853
		<if test="commIDs!=null and commIDs!=''">
			AND (c.CommID IN ( ${commIDs} ))
		</if>
		ORDER BY COALESCE(cc.DictionaryOrderID,1),o.OrganCode,c.CommID
	</select>
	<select id="queryCommId" resultType="java.lang.Integer">
		SELECT DISTINCT c.CommID
		FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_User] u
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_UserRole] ur ON ur.UserCode = u.UserCode  AND ur.rentid=1853
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Role] r ON r.RoleCode = ur.RoleCode AND r.rentid=1853
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_RoleData] rd ON rd.RoleCode = r.RoleCode AND rd.rentid=1853
		INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c ON c.CommID = rd.CommID AND c.rentid=1853
		WHERE ISNULL(c.IsDelete,0) = 0 AND
		c.CommName != '测试项目' AND c.rentid=1853
		AND u.UserCode =#{userCode}
	</select>
	<select id="queryAllRegion" resultType="cn.com.countrygarden.bi.main.model.dup.DupOrgan">
		select OrganCode,OrganName from [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] WHERE ISNULL(IsDelete,0) = 0 AND isComp=1 and rentid=1853
	</select>
	<select id="queryAllRegionRdInfo" resultType="cn.com.countrygarden.bi.main.model.dup.DupOrgan">
		select OrganCode,OrganName from [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] WHERE ISNULL(IsDelete,0) = 0 AND isComp=1 and rentid=1853
		<if test="organCodeString!=null and organCodeString.size()!=0">
			and OrganCode in
			<foreach item="organCodeString" index="index" collection="organCodeString" open="(" separator="," close=")">
				#{organCodeString}
			</foreach>
		</if>
		<if test="principaString!=null and principaString.size()!=0">
			and OrganCode in
			<foreach item="principaString" index="index" collection="principaString" open="(" separator="," close=")">
				#{principaString}
			</foreach>
		</if>
		<if test="organCode!=null and organCode!=''">
			and OrganCode=#{organCode}
		</if>
	</select>
	<select id="queryAllRegionRdDistrict" resultType="cn.com.countrygarden.bi.main.model.dup.DupOrgan">
		select OrganCode,OrganName from [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] WHERE ISNULL(IsDelete,0) = 0 AND isComp=1 AND rentid=1853
		<if test="regionName!=null and regionName!=''">
			and OrganName=#{regionName}
		</if>
		<if test="organCode!=null and organCode!=''">
			and OrganCode=#{organCode}
		</if>
		<if test="organCodeString!=null and organCodeString.size()!=0">
			and OrganCode in
			<foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
				#{organCodeString}
			</foreach>
		</if>
	</select>
	<select id="queryAllComm" resultType="cn.com.countrygarden.bi.main.model.dup.DupComm">
		select c.CommID,c.CommName,
		(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID and i.rentid=1853 AND ISNULL(i.IsDelete,0) = 0) NCSystemNumber
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0  AND c.OrganCode=#{organCode} and c.rentid=1853
	</select>
	<select id="queryAllCommCase" resultType="cn.com.countrygarden.bi.main.model.dup.DupComm">
		select c.CommID,c.CommName,c.OrganCode,
		(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID and i.rentid=1853 AND ISNULL(i.IsDelete,0) = 0) NCSystemNumber
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0  AND c.OrganCode=#{organCode} and c.rentid=1853
		<if test="CommIdfenghuang!=null">
			and c.CommID not in
			<foreach item="CommIdfenghuang" index="index" collection="CommIdfenghuang" open="(" separator="," close=")">
				#{CommIdfenghuang}
			</foreach>
		</if>
	</select>
	<select id="queryAllCommCaseDistrict" resultType="cn.com.countrygarden.bi.main.model.dup.DupComm">
		select DISTINCT c.CommID,c.CommName,c.OrganCode,
		(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID and i.rentid=1853 AND ISNULL(i.IsDelete,0) = 0) NCSystemNumber
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0 and c.rentid=1853
		<if test="organCode!=null and organCode!=''">
			AND c.OrganCode=#{organCode}
		</if>
		<if test="commid!=null and commid!=''">
			and c.CommID=#{commid}
		</if>
		<if test="commIdString!=null and commIdString.size()!=0">
			and c.CommID in
			<foreach item="commIdString" index="index" collection="commIdString" open="(" separator="," close=")">
				#{commIdString}
			</foreach>
		</if>
		<if test="NotIncommIdString!=null and NotIncommIdString.size()!=0">
			and c.CommID not in
			<foreach item="NotIncommIdString" index="index" collection="NotIncommIdString" open="(" separator="," close=")">
				#{NotIncommIdString}
			</foreach>
		</if>
		<if test="NotIncommIdName!=null and NotIncommIdName.size()!=0">
			and c.CommName not in
			<foreach item="NotIncommIdName" index="index" collection="NotIncommIdName" open="(" separator="," close=")">
				#{NotIncommIdName}
			</foreach>
		</if>

	</select>
	<select id="queryAllCommCaseDistrictCommName" resultType="cn.com.countrygarden.bi.main.model.dup.DupComm">
		select c.CommID,c.CommName,c.OrganCode,
		(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID AND ISNULL(i.IsDelete,0) = 0 AND i.rentid=1853) NCSystemNumber
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0 AND c.rentid=1853
		<if test="commId!=null and commId!=''">
			AND c.CommID=#{commId}
		</if>
		<if test="commName!=null and commName!=''">
			AND c.CommName=#{commName}
		</if>
		<if test="commIdString!=null and commIdString.size()!=0">
			and c.CommID in
			<foreach item="commIdString" index="index" collection="commIdString" open="(" separator="," close=")">
				#{commIdString}
			</foreach>
		</if>
	</select>
	<select id="queryRegionByUserCode" resultType="java.lang.String">
		SELECT ISNULL(REPLACE(a.OrganName, '/', ''),'') organName
		FROM [HM_wygl_new_1853].[dbo].Tb_Sys_User u
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_UserRole ur ON ur.UserCode = u.UserCode AND u.rentid=ur.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_Role r ON r.RoleCode = ur.RoleCode AND r.rentid=ur.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_RoleData rd ON rd.RoleCode = r.RoleCode AND r.rentid=rd.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_HSPR_Community c ON c.CommID = rd.CommID and COALESCE(c.IsDelete,0) = 0 AND c.rentid=rd.rentid
		left join [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] a ON a.OrganCode = c.OrganCode and a.isdelete = 0 AND c.rentid=a.rentid
		where u.UserCode = #{userCode} AND u.rentid=1853
		group by a.OrganName
	</select>
	<select id="queryCommByOrgan" resultType="cn.com.countrygarden.bi.main.dto.HouseKeeperNameTreeDTO">
		SELECT DISTINCT c.CommName  name
		FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] o ON c.OrganCode = o.OrganCode AND o.IsDelete = 0  AND c.rentid=1853
		WHERE	ISNULL(c.IsDelete,0) = 0  AND c.rentid=1853 AND o.OrganName in
		<foreach collection="organList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
	<select id="queryCommByOrganAndUser" resultType="cn.com.countrygarden.bi.main.dto.manager.TreeNode">
		SELECT DISTINCT c.CommName  label,c.CommID code,b.DevelopmentSubject DevelopmentSubject
		FROM [HM_wygl_new_1853].[dbo].Tb_Sys_User u
		LEFT JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_UserRole ur ON ur.UserCode = u.UserCode AND u.rentid = ur.rentid
		LEFT JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_Role r ON r.RoleCode = ur.RoleCode AND u.rentid = r.rentid
		LEFT JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_RoleData rd ON rd.RoleCode = r.RoleCode AND u.rentid = rd.rentid
		LEFT JOIN  [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c ON rd.CommID = c.CommID AND u.rentid = c.rentid
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] o ON c.OrganCode = o.OrganCode AND o.IsDelete = 0 AND u.rentid = o.rentid
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] b ON c.CommID = b.CommID AND b.IsDelete = 0 AND u.rentid = b.rentid
		WHERE	ISNULL(c.IsDelete,0) = 0 AND o.OrganName = #{organ} AND u.UserCode = #{userCode} AND u.rentid=1853
	</select>
	<select id="queryCommByOrganName" resultType="cn.com.countrygarden.bi.main.dto.manager.TreeNode">
		SELECT DISTINCT c.CommName  label,c.CommID code,b.DevelopmentSubject DevelopmentSubject
		FROM  [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] o ON c.OrganCode = o.OrganCode AND o.IsDelete = 0 AND o.rentid=c.rentid
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] b ON c.CommID = b.CommID AND b.IsDelete = 0 AND c.rentid = b.rentid
		WHERE	ISNULL(c.IsDelete,0) = 0 AND c.rentid=1853 AND o.OrganName = #{organ}
	</select>
	<select id="queryAllRegionName" resultType="java.lang.String">
		select OrganName
		from [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ]
		WHERE ISNULL(IsDelete,0) = 0 AND isComp=1 AND rentid=1853
		ORDER BY OrganName
	</select>

	<select id="queryCommStringByOrganAndUser" resultType="java.lang.String">
		SELECT DISTINCT REPLACE(REPLACE(REPLACE(c.CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '')   label
		FROM [HM_wygl_new_1853].[dbo].Tb_Sys_User u
		LEFT JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_UserRole ur ON ur.UserCode = u.UserCode AND ur.rentid=1853
		LEFT JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_Role r ON r.RoleCode = ur.RoleCode AND r.rentid=1853
		LEFT JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_RoleData rd ON rd.RoleCode = r.RoleCode AND rd.rentid=1853
		LEFT JOIN  [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c ON rd.CommID = c.CommID AND rd.rentid=1853
		LEFT JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] o ON c.OrganCode = o.OrganCode AND o.IsDelete = 0 AND o.rentid=1853
		WHERE	ISNULL(c.IsDelete,0) = 0 AND u.rentid=1853 AND o.OrganName = #{organ} AND u.UserCode = #{userCode}
	</select>
	<select id="selectCommCodeByCommName" resultType="java.lang.String">
		SELECT DISTINCT  TOP 1 CommID
		FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community]
		WHERE	REPLACE(REPLACE(REPLACE(CommName, '(测试)', ''), '(预生产)', ''), '(正式)', '')  = #{commName} AND OrganCode = #{regionCode} AND IsDelete = 0 AND rentid=1853
	</select>
	<select id="hasNotYetOpenedList" resultType="cn.com.countrygarden.bi.main.dto.districtReport.hasNotYetOpenedDTO">
		SELECT a.commid as commid,a.commname AS commName,规划用地面积 AS plannedLandArea,总建筑面积 AS totalSurfaceSrea,建筑类型 AS buildingType,总规划 AS masterPlan,物业费定价 AS propertyFeePricing
		FROM HM_wygl_new_1853..tb_hspr_community a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..tb_sys_organ o WITH(nolock) ON a.organcode=o.organcode AND a.rentid=1853
		LEFT JOIN (
		SELECT commid,CONVERT(DECIMAL(18,2),SUM(ISNULL(TotalManageArea,0))/10000) 总建筑面积 FROM HM_wygl_new_1853..tb_hspr_ContractInfo WITH(nolock)
		WHERE ISNULL(isdelete,0)=0 AND ISNULL(ContractState,0)='有效'  AND rentid=1853 GROUP BY commid
		) c ON a.commid=c.commid
		LEFT JOIN (
		SELECT p.CommID,CONVERT(DECIMAL(18,2),SUM(ISNULL(p.ResidentialArea,0)+ISNULL(p.PublicArea,0)+ISNULL(p.RoadArea,0)+ISNULL(p.GreenArea,0))*0.0015) 规划用地面积,
		SUM(ISNULL(p.HouseQuantity,0)+ISNULL(p.CommercialAuantity,0))+SUM(ISNULL(p.ParkeNumber,0)+ISNULL(p.OtherQuantity,0)) 总规划
		FROM HM_wygl_new_1853..tb_hspr_planinfo p WITH(nolock)
		WHERE ISNULL(p.isdelete,0)=0 AND p.rentid=1853
		GROUP BY p.CommID
		) d ON a.commid=d.commid
		LEFT JOIN (
		SELECT commid,stuff((SELECT ',' + REPLACE(costid,'收费标准','') FROM (
		SELECT DISTINCT a.commid,c.costid,c.price FROM HM_wygl_new_1853..tb_hspr_ContractInfo a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_ContractInfoCost c WITH(nolock) ON a.ContractID=c.ContractID
		WHERE ISNULL(a.isdelete,0)=0 AND c.ContractID IS NOT NULL AND ISNULL(ContractState,0)='有效'
		AND c.CostID IN('步梯洋房收费标准','电梯洋房收费标准','独栋别墅收费标准','双拼/联排别墅收费标准','三拼别墅收费标准','四拼别墅收费标准',
		'公寓收费标准','商铺收费标准','会所收费标准','办公楼/写字楼收费标准','学校收费标准')
		) AS b WHERE a.CommID = b.CommID FOR xml path('')),1,1,'') AS 建筑类型,
		stuff((SELECT ',' + costid+CONVERT(VARCHAR(100),price) FROM (
		SELECT DISTINCT a.commid,c.costid,c.price FROM HM_wygl_new_1853..tb_hspr_ContractInfo a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_ContractInfoCost c WITH(nolock) ON a.ContractID=c.ContractID
		WHERE ISNULL(a.isdelete,0)=0 AND c.ContractID IS NOT NULL AND ISNULL(ContractState,0)='有效'
		AND c.CostID IN('步梯洋房收费标准','电梯洋房收费标准','独栋别墅收费标准','双拼/联排别墅收费标准','三拼别墅收费标准','四拼别墅收费标准',
		'公寓收费标准','商铺收费标准','会所收费标准','办公楼/写字楼收费标准','学校收费标准')
		) AS b WHERE a.CommID = b.CommID FOR xml path('')),1,1,'') AS 物业费定价
		FROM HM_wygl_new_1853..tb_hspr_ContractInfo AS a WITH(nolock)
		WHERE commid IS NOT NULL AND ISNULL(IsDelete,0)=0 AND ISNULL(ContractState,0)='有效' AND rentid=1853
		GROUP BY commid
		) g ON a.commid=g.commid
		WHERE ISNULL(a.isdelete,0)=0
		<if test="organCode!=null and organCode!=''">
			AND o.organcode=#{organCode}
		</if>
		<if test="commid!=null and commid!=''">
			and a.commid=#{commid}
		</if>
	</select>

	<select id="repossessedERPList" resultType="cn.com.countrygarden.bi.main.dto.districtReport.repossessedERP">
		<![CDATA[
		SELECT a.commid as commid,a.commname as commName,d.规划占地面积 as planPlaceArea,d.规划建筑面积 as planBuildArea,c.接管建筑面积 as managerArea,d.规划车位面积 as planCarArea,住宅 as houseChargesArea,商业 as businessChargesArea,规划户数 as planHouseholds,累积接管户数 as managerHouseholds,接管车位数 as managerCarHouseholds,业态构成 as industryComposition,bi.ActualProperty as firstPayDate,
		物业费标准 as propertyPrice,车位服务费标准 as carPrice,RTRIM(本年综合收费率2)+'%' as  propertyCollectionRate,RTRIM(本年累计追缴率)+'%' as lastYearRecoveryRate,绿化面积 as greenArea,容积率 as volumeRatio,办公地址 as officePlace,项目负责人 as projectResponsibler,联系方式 as contact
		FROM HM_wygl_new_1853..tb_hspr_community a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..tb_sys_organ o WITH(nolock) ON a.organcode=o.organcode
		LEFT JOIN rts..Tb_DeskTop_经营主题 b WITH(nolock) ON a.commid=b.commid
		LEFT JOIN (
		SELECT commid,CONVERT(DECIMAL(18,2),SUM(ISNULL(TotalManageArea,0))/10000) 接管建筑面积 FROM HM_wygl_new_1853..tb_hspr_ContractInfo WITH(nolock)
		WHERE ISNULL(isdelete,0)=0 AND ISNULL(ContractState,0)='有效' GROUP BY commid
		) c ON a.commid=c.commid
		LEFT JOIN (
		SELECT p.CommID,CONVERT(DECIMAL(18,2),SUM(ISNULL(p.ResidentialArea,0)+ISNULL(p.PublicArea,0)+ISNULL(p.RoadArea,0)+ISNULL(p.GreenArea,0))/10000) 规划占地面积,
		CONVERT(DECIMAL(18,2),SUM(ISNULL(p.TotalResidentialArea,0)+ISNULL(p.TotalCommercialArea,0)+ISNULL(p.TotalParkingArea,0)+ISNULL(p.OtherTotalArea,0))/10000) 规划建筑面积,
		CONVERT(DECIMAL(18,2),SUM(ISNULL(p.TotalParkingArea,0))/10000) 规划车位面积,SUM(ISNULL(p.GreenArea,0)) 绿化面积,SUM(ISNULL(p.VolumeRate,0))/COUNT(*) 容积率,
		SUM(ISNULL(p.HouseQuantity,0)+ISNULL(p.CommercialAuantity,0))+SUM(ISNULL(p.ParkeNumber,0)+ISNULL(p.OtherQuantity,0)) 规划户数
		FROM HM_wygl_new_1853..tb_hspr_planinfo p WITH(nolock)
		WHERE ISNULL(p.isdelete,0)=0
		GROUP BY p.CommID
		) d ON a.commid=d.commid
		LEFT JOIN (
		SELECT commid,CONVERT(DECIMAL(18,2),SUM(ISNULL(buildarea,0))/10000) 住宅 FROM HM_wygl_new_1853..tb_hspr_room WITH(nolock)
		WHERE isdelete=0 AND propertyuses='住宅' GROUP BY commid
		) e ON a.commid=e.commid
		LEFT JOIN (
		SELECT commid,CONVERT(DECIMAL(18,2),SUM(ISNULL(buildarea,0))/10000) 商业 FROM HM_wygl_new_1853..tb_hspr_room WITH(nolock)
		WHERE isdelete=0 AND propertyuses='商业' GROUP BY commid
		) f ON a.commid=f.commid
		LEFT JOIN (
		SELECT commid,COUNT(*) 累积接管户数 FROM HM_wygl_new_1853..tb_hspr_room WITH(nolock)
		WHERE isdelete=0 AND issplitunite<>1 AND issplitunite<>3 AND propertyuses<>'公共' GROUP BY commid
		) r ON a.commid=r.commid
		LEFT JOIN (
		SELECT commid,COUNT(*) 接管车位数 FROM HM_wygl_new_1853..tb_hspr_parking WITH(nolock)
		WHERE isdelete=0 GROUP BY commid
		) p ON a.commid=p.commid
		LEFT JOIN HM_wygl_new_1853..tb_hspr_basicinfo bi WITH(nolock) ON a.commid=bi.commid AND ISNULL(bi.isdelete,0)=0
		LEFT JOIN (
		SELECT commid,stuff((SELECT ',' + REPLACE(costid,'收费标准','') FROM (
		SELECT DISTINCT a.commid,c.costid FROM HM_wygl_new_1853..tb_hspr_ContractInfo a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_ContractInfoCost c WITH(nolock) ON a.ContractID=c.ContractID
		WHERE ISNULL(a.isdelete,0)=0 AND c.ContractID IS NOT NULL AND ISNULL(ContractState,0)='有效'
		AND c.CostID IN('步梯洋房收费标准','电梯洋房收费标准','独栋别墅收费标准','双拼/联排别墅收费标准','三拼别墅收费标准','四拼别墅收费标准',
		'			公寓收费标准','商铺收费标准','会所收费标准','办公楼/写字楼收费标准','学校收费标准')
		) AS b WHERE a.CommID = b.CommID FOR xml path('')),1,1,'') AS 业态构成,
		stuff((SELECT ',' + costid+CONVERT(VARCHAR(100),price) FROM (
		SELECT DISTINCT a.commid,c.costid,c.price FROM HM_wygl_new_1853..tb_hspr_ContractInfo a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_ContractInfoCost c WITH(nolock) ON a.ContractID=c.ContractID
		WHERE ISNULL(a.isdelete,0)=0 AND c.ContractID IS NOT NULL AND ISNULL(ContractState,0)='有效'
		AND c.CostID IN('步梯洋房收费标准','电梯洋房收费标准','独栋别墅收费标准','双拼/联排别墅收费标准','三拼别墅收费标准','四拼别墅收费标准',
		'公寓收费标准','商铺收费标准','会所收费标准','办公楼/写字楼收费标准','学校收费标准')
		) AS b WHERE a.CommID = b.CommID FOR xml path('')),1,1,'') AS 物业费标准
		FROM HM_wygl_new_1853..tb_hspr_ContractInfo AS a WITH(nolock)
		WHERE commid IS NOT NULL AND ISNULL(IsDelete,0)=0 AND ISNULL(ContractState,0)='有效'
		GROUP BY commid
		) g ON a.commid=g.commid
		LEFT JOIN (
		SELECT commid,stuff((SELECT ',' + costid+CONVERT(VARCHAR(100),price) FROM (
		SELECT DISTINCT a.commid,c.costid,c.price FROM HM_wygl_new_1853..tb_hspr_ContractInfo a WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_ContractInfoCost c WITH(nolock) ON a.ContractID=c.ContractID
		WHERE ISNULL(a.isdelete,0)=0 AND c.ContractID IS NOT NULL AND ISNULL(ContractState,0)='有效'
		AND c.CostID IN('地下车位收费标准','露天车位收费标准')
		) AS b WHERE a.CommID = b.CommID FOR xml path('')),1,1,'') AS 车位服务费标准
		FROM HM_wygl_new_1853..tb_hspr_ContractInfo AS a WITH(nolock)
		WHERE commid IS NOT NULL AND ISNULL(IsDelete,0)=0 AND ISNULL(ContractState,0)='有效'
		GROUP BY commid
		) h ON a.commid=h.commid
		LEFT JOIN (
		SELECT commid,officeaddress 办公地址,contactname 项目负责人,contactphone 联系方式 FROM (
		SELECT a.*, ROW_NUMBER() OVER (PARTITION BY a.commid ORDER BY a.updatetime DESC) AS GROUP_IDX
		FROM HM_wygl_new_1853..Tb_HSPR_ContactInfo a WITH(nolock) WHERE ISNULL(a.IsDelete,0)=0
		) b
		WHERE b.GROUP_IDX=1
		) s ON a.commid=s.commid
		WHERE ISNULL(a.isdelete,0)=0
		]]>
		<if test="organCode!=null and organCode!=''">
			AND o.organcode=#{organCode}
		</if>
		<if test="commid!=null and commid!=''">
			and a.commid=#{commid}
		</if>
	</select>

	<select id="rdprojectInformationSummaryList" resultType="cn.com.countrygarden.bi.main.dto.districtReport.RdprojectInformationSummaryDTO">
		SELECT o.organcode as regionCode,o.OrganName as regionName,c.commid AS commId,c.commname AS commName,p.PlanArea AS planArea,b.DevelopmentSubject AS developmentSubject,p.ResidentialArea AS residentialArea,p.PublicArea AS publicArea,p.RoadArea AS roadArea,p.GreenArea AS greenArea,p.HouseQuantity AS houseQuantity,p.CommercialAuantity AS commercialAuantity,p.ParkeNumber AS parkeNumber,p.OtherQuantity AS otherQuantity,
		p.TotalResidentialArea AS totalResidentialArea,p.TotalCommercialArea AS totalCommercialArea,p.TotalParkingArea AS totalParkingArea,p.OtherTotalArea AS  otherTotalArea,p.VolumeRate AS volumeRate
		FROM HM_wygl_new_1853..tb_hspr_planinfo p WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_BasicInfo b WITH(nolock) ON p.commid=b.commid AND ISNULL(b.isdelete,0)=0  AND b.rentid=1853
		LEFT JOIN HM_wygl_new_1853..tb_hspr_community c WITH(nolock) ON p.commid=c.commid AND p.rentid=1853
		LEFT JOIN HM_wygl_new_1853..tb_sys_organ o WITH(nolock) ON c.organcode=o.organcode AND c.rentid=1853
		WHERE ISNULL(p.isdelete,0)=0 AND p.rentid=1853
		<if test="organCodeString!=null and organCodeString.size()!=0">
			and o.organcode in
			<foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
				#{organCodeString}
			</foreach>
		</if>
		<if test="commIdString!=null and commIdString.size()!=0">
			and c.commid in
			<foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
				#{commIdString}
			</foreach>
		</if>
		<if test="commId!=null and commId.size()!=0">
			and c.commid in
			<foreach collection="commId" item="commId" index="index" open="(" close=")" separator=",">
				#{commId}
			</foreach>
		</if>
		<if test="rdClosedBuildingProjectDTO.regionCode!=null and rdClosedBuildingProjectDTO.regionCode!=''">
			and o.organcode=#{rdClosedBuildingProjectDTO.regionCode}
		</if>
		<if test="rdClosedBuildingProjectDTO.districtCode!=null and rdClosedBuildingProjectDTO.districtCode!=''">

		</if>
		<if test="rdClosedBuildingProjectDTO.projectCode!=null and rdClosedBuildingProjectDTO.projectCode!=''">
			and c.commid=#{rdClosedBuildingProjectDTO.projectCode}
		</if>
		<if test="rdClosedBuildingProjectDTO.developmentSubject!=null and rdClosedBuildingProjectDTO.developmentSubject!=''">
			and b.DevelopmentSubject like concat('%',#{rdClosedBuildingProjectDTO.developmentSubject},'%')
		</if>
		ORDER BY  c.commid
	</select>

	<select id="evaluationrdprojectInformationSummary" resultType="cn.com.countrygarden.bi.main.dto.districtReport.RdprojectInformationSummaryVO">
		SELECT o.organcode as regionCode,o.OrganName as regionName,c.commid AS commId,c.commname AS commName,p.PlanArea AS planArea,b.DevelopmentSubject AS developmentSubject,p.ResidentialArea AS residentialArea,p.PublicArea AS publicArea,p.RoadArea AS roadArea,p.GreenArea AS greenArea,p.HouseQuantity AS houseQuantity,p.CommercialAuantity AS commercialAuantity,p.ParkeNumber AS parkeNumber,p.OtherQuantity AS otherQuantity,
		p.TotalResidentialArea AS totalResidentialArea,p.TotalCommercialArea AS totalCommercialArea,p.TotalParkingArea AS totalParkingArea,p.OtherTotalArea AS  otherTotalArea,p.VolumeRate AS volumeRate
		FROM HM_wygl_new_1853..tb_hspr_planinfo p WITH(nolock)
		LEFT JOIN HM_wygl_new_1853..Tb_HSPR_BasicInfo b WITH(nolock) ON p.commid=b.commid AND ISNULL(b.isdelete,0)=0  AND b.rentid=1853
		LEFT JOIN HM_wygl_new_1853..tb_hspr_community c WITH(nolock) ON p.commid=c.commid  AND p.rentid=1853
		LEFT JOIN HM_wygl_new_1853..tb_sys_organ o WITH(nolock) ON c.organcode=o.organcode  AND o.rentid=1853
		WHERE ISNULL(p.isdelete,0)=0  AND c.rentid=1853
		<if test="organCodeString!=null and organCodeString.size()!=0">
			and o.organcode in
			<foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
				#{organCodeString}
			</foreach>
		</if>
		<if test="commIdString!=null and commIdString.size()!=0">
			and c.commid in
			<foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
				#{commIdString}
			</foreach>
		</if>
		<if test="commId!=null and commId.size()!=0">
			and c.commid in
			<foreach collection="commId" item="commId" index="index" open="(" close=")" separator=",">
				#{commId}
			</foreach>
		</if>
		<if test="rdClosedBuildingProjectDTO.regionCode!=null and rdClosedBuildingProjectDTO.regionCode!=''">
			and o.organcode=#{rdClosedBuildingProjectDTO.regionCode}
		</if>
		<if test="rdClosedBuildingProjectDTO.districtCode!=null and rdClosedBuildingProjectDTO.districtCode!=''">

		</if>
		<if test="rdClosedBuildingProjectDTO.projectCode!=null and rdClosedBuildingProjectDTO.projectCode!=''">
			and c.commid=#{rdClosedBuildingProjectDTO.projectCode}
		</if>
		<if test="rdClosedBuildingProjectDTO.developmentSubject!=null and rdClosedBuildingProjectDTO.developmentSubject!=''">
			and b.DevelopmentSubject like concat('%',#{rdClosedBuildingProjectDTO.developmentSubject},'%')
		</if>
		ORDER BY  c.commid
	</select>
	<select id="organCodeString" resultType="string">
		SELECT DISTINCT a.OrganCode organCode
		FROM [HM_wygl_new_1853].[dbo].Tb_Sys_User u
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_UserRole ur ON ur.UserCode = u.UserCode and ur.rentid=u.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_Role r ON r.RoleCode = ur.RoleCode and r.rentid=ur.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_RoleData rd ON rd.RoleCode = r.RoleCode and rd.rentid=r.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_HSPR_Community c ON c.CommID = rd.CommID and COALESCE(c.IsDelete,0) = 0 and c.rentid=rd.rentid
		left join [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] a ON a.OrganCode = c.OrganCode and a.isdelete = 0 and a.rentid=c.rentid
		where   a.OrganCode is not null and u.rentid=1853
		<if test="sysUserCode!=null and sysUserCode!=''">
			and u.UserCode = #{sysUserCode}
		</if>
		<if test="commIdString!=null and commIdString.size()!=0">
			and c.CommID in
			<foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
				#{commIdString}
			</foreach>
		</if>
	</select>
	<select id="commIdString" resultType="string">
		SELECT DISTINCT c.CommID commId
		FROM [HM_wygl_new_1853].[dbo].Tb_Sys_User u
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_UserRole ur ON ur.UserCode = u.UserCode AND ur.rentid=u.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_Role r ON r.RoleCode = ur.RoleCode AND r.rentid=ur.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_RoleData rd ON rd.RoleCode = r.RoleCode AND rd.rentid=r.rentid
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_HSPR_Community c ON c.CommID = rd.CommID and COALESCE(c.IsDelete,0) = 0 AND c.rentid=rd.rentid
		left join [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] a ON a.OrganCode = c.OrganCode and a.isdelete = 0 AND a.rentid=c.rentid
		where u.UserCode =  #{sysUserCode} AND u.rentid=1853
	</select>

	<select id="commIdStringName" resultType="string">
		SELECT DISTINCT c.commname AS commName
		FROM [HM_wygl_new_1853].[dbo].Tb_Sys_User u
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_UserRole ur ON ur.UserCode = u.UserCode AND ur.rentid=1853
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_Role r ON r.RoleCode = ur.RoleCode AND r.rentid=1853
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_Sys_RoleData rd ON rd.RoleCode = r.RoleCode AND rd.rentid=1853
		INNER JOIN [HM_wygl_new_1853].[dbo].Tb_HSPR_Community c ON c.CommID = rd.CommID and COALESCE(c.IsDelete,0) = 0 AND c.rentid=1853
		left join [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] a ON a.OrganCode = c.OrganCode and a.isdelete = 0 AND a.rentid=1853
		where u.UserCode =  #{sysUserCode} AND u.rentid=1853
	</select>
	<select id="selectOrganTree" resultType="cn.com.countrygarden.bi.main.dto.wcx.SelectTreeDTO">
		SELECT OrganCode code , OrganName name
		FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ]
		WHERE IsDelete = 0 AND IsComp = 1 and rentid=1853
	</select>
	<select id="selectDevelopmentsubjectByCommCode" resultType="java.lang.String">
		SELECT DevelopmentSubject
		FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo]
		WHERE IsDelete = 0 AND CommID = #{commCode} and rentid=1853
	</select>
	<select id="selectOrganCountByOrganCode" resultType="java.lang.Integer">
		SELECT COUNT(1)
		FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ]
		WHERE IsDelete = 0 AND OrganCode = #{organCode} and rentid=1853
	</select>

	<select id="selectOrgNameByCode" resultType="string">
			select OrganName from [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] WHERE ISNULL(IsDelete,0) = 0 AND isComp=1 and rentid=1853
			AND OrganCode = #{organCode}
	</select>

	<select id="queryCommNameByOrganCodeAndCommId" resultType="string">
		select DISTINCT c.CommName
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0 and c.rentid=1853
		<if test="organCode!=null and organCode!=''">
			AND c.OrganCode=#{organCode}
		</if>
		<if test="commId!=null and commId!=''">
			and c.CommID=#{commId}
		</if>
	</select>

	<select id="selectOrganCodeByOrganName" resultType="java.lang.String">
		SELECT OrganCode
		FROM dbo.Tb_Sys_Organ
		WHERE IsDelete = 0 AND IsComp = 1 AND rentid = '1853' AND OrganName = #{organName}
	</select>

	<select id="queryAllRegionRdName" resultType="cn.com.countrygarden.bi.main.model.dup.DupOrgan">
		select OrganCode,OrganName from [HM_wygl_new_1853].[dbo].[Tb_Sys_Organ] WHERE ISNULL(IsDelete,0) = 0 AND isComp=1 and rentid=1853
	</select>

	<select id="queryAllCommName" resultType="cn.com.countrygarden.bi.main.model.dup.DupComm">
		select DISTINCT c.CommID,c.CommName,c.OrganCode,
		(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID and i.rentid=1853 AND ISNULL(i.IsDelete,0) = 0) NCSystemNumber
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0 and c.rentid=1853
		<if test="organCode!=null and organCode!=''">
			AND c.OrganCode=#{organCode}
		</if>
	</select>

	<select id="queryAllCommCaseDistrictDTO" resultType="cn.com.countrygarden.bi.main.model.dup.DupComm">
		select DISTINCT c.CommID,c.CommName,c.OrganCode,
		(SELECT TOP 1 i.NCSystemNumber FROM [HM_wygl_new_1853].[dbo].[Tb_HSPR_BasicInfo] i WHERE i.CommID = c.CommID and i.rentid=1853 AND ISNULL(i.IsDelete,0) = 0) NCSystemNumber
		from [HM_wygl_new_1853].[dbo].[Tb_HSPR_Community] c WHERE ISNULL(c.IsDelete,0) = 0 and c.rentid=1853
		<if test="organCode!=null and organCode!=''">
			AND c.OrganCode=#{organCode}
		</if>
		<if test="commid!=null and commid!=''">
			and c.CommID=#{commid}
		</if>
		<if test="commIdString!=null and commIdString.size()!=0">
			or c.CommID in
			<foreach item="commIdString" index="index" collection="commIdString" open="(" separator="," close=")">
				#{commIdString}
			</foreach>
		</if>
		<if test="NotIncommIdString!=null and NotIncommIdString.size()!=0">
			and c.CommID not in
			<foreach item="NotIncommIdString" index="index" collection="NotIncommIdString" open="(" separator="," close=")">
				#{NotIncommIdString}
			</foreach>
		</if>
		<if test="NotIncommIdName!=null and NotIncommIdName.size()!=0">
			and c.CommName not in
			<foreach item="NotIncommIdName" index="index" collection="NotIncommIdName" open="(" separator="," close=")">
				#{NotIncommIdName}
			</foreach>
		</if>

	</select>
</mapper>
