From 7987c4f005f5bd8739411d08e4e3bfb67e4df9ef Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期日, 01 十二月 2019 13:48:07 +0800
Subject: [PATCH] 优化设备脚本查询

---
 java110-db/src/main/resources/mapper/community/CommunityServiceDaoImplMapper.xml |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 103 insertions(+), 11 deletions(-)

diff --git a/java110-db/src/main/resources/mapper/community/CommunityServiceDaoImplMapper.xml b/java110-db/src/main/resources/mapper/community/CommunityServiceDaoImplMapper.xml
index 4981c72..76b7490 100644
--- a/java110-db/src/main/resources/mapper/community/CommunityServiceDaoImplMapper.xml
+++ b/java110-db/src/main/resources/mapper/community/CommunityServiceDaoImplMapper.xml
@@ -6,8 +6,8 @@
     
     <!-- 淇濆瓨灏忓尯淇℃伅 add by wuxw 2018-07-03 -->
     <insert id="saveBusinessCommunityInfo" parameterType="Map">
-        insert into business_community(community_id,b_id,name,address,city_code,nearby_landmarks,map_x,map_y,month,operate)
-        values(#{communityId},#{bId},#{name},#{address},#{cityCode},#{nearbyLandmarks},#{mapX},#{mapY},#{month},#{operate})
+        insert into business_community(community_id,b_id,name,address,city_code,nearby_landmarks,map_x,map_y,month,state,operate)
+        values(#{communityId},#{bId},#{name},#{address},#{cityCode},#{nearbyLandmarks},#{mapX},#{mapY},#{month},#{state},#{operate})
     </insert>
     <!-- 淇濆瓨灏忓尯灞炴�т俊鎭�  add by wuxw 2018-07-03 -->
     <insert id="saveBusinessCommunityAttr" parameterType="Map">
@@ -23,7 +23,7 @@
 
     <!-- 鏌ヨ灏忓尯淇℃伅锛圔usiness锛� add by wuxw 2018-07-03 -->
     <select id="getBusinessCommunityInfo" parameterType="Map" resultType="Map">
-        select s.community_id,s.b_id,s.name,s.address,s.city_code,s.nearby_landmarks,s.map_x,s.map_y,s.operate
+        select s.community_id,s.b_id,s.name,s.address,s.city_code,s.nearby_landmarks,s.map_x,s.map_y,s.operate,s.state
         from business_community s where 1 = 1
         <if test="operate != null and operate != ''">
             and s.operate = #{operate}
@@ -73,8 +73,8 @@
 
     <!-- 淇濆瓨灏忓尯淇℃伅鑷� instance琛ㄤ腑 add by wuxw 2018-07-03 -->
     <insert id="saveCommunityInfoInstance" parameterType="Map">
-        insert into s_community(community_id,b_id,name,address,city_code,nearby_landmarks,map_x,map_y,status_cd)
-        values(#{community_id},#{b_id},#{name},#{address},#{city_code},#{nearby_landmarks},#{map_x},#{map_y},'0')
+        insert into s_community(community_id,b_id,name,address,city_code,nearby_landmarks,map_x,map_y,status_cd,state)
+        values(#{community_id},#{b_id},#{name},#{address},#{city_code},#{nearby_landmarks},#{map_x},#{map_y},'0',#{state})
     </insert>
 
     <!-- 淇濆瓨灏忓尯灞炴�т俊鎭埌 instance add by wuxw 2018-07-03 -->
@@ -102,7 +102,7 @@
 
     <!-- 鏌ヨ灏忓尯淇℃伅 add by wuxw 2018-07-03 -->
     <select id="getCommunityInfo" parameterType="Map" resultType="Map">
-        select s.community_id,s.b_id,s.name,s.address,s.city_code,s.nearby_landmarks,s.map_x,s.map_y,s.status_cd
+        select s.community_id,s.b_id,s.name,s.address,s.city_code,s.nearby_landmarks,s.map_x,s.map_y,s.status_cd,s.state
         from s_community s
         where 1=1
         <if test="statusCd != null and statusCd != ''">
@@ -179,6 +179,9 @@
         </if>
         <if test="mapY != null and mapY != ''">
             ,s.map_y = #{mapY}
+        </if>
+        <if test="state != null and state != ''">
+            ,s.state = #{state}
         </if>
         where 1=1
         <if test="bId != null and bId !=''">
@@ -274,11 +277,31 @@
 
     <!-- 鏌ヨ灏忓尯鎴愬憳  add by wuxw 2018-07-03 -->
     <select id="getCommunityMember" parameterType="Map" resultType="Map">
-        select ms.community_member_id ,ms.b_id,ms.community_id,ms.member_id,ms.member_type_cd,ms.status_cd,ms.audit_status_cd,
+        select ms.community_member_id , ms.b_id,ms.community_id,ms.member_id,ms.member_type_cd,ms.status_cd,ms.audit_status_cd,
         ms.community_member_id communityMemberId ,ms.b_id bId,ms.community_id communityId,ms.member_id memberId,ms.member_type_cd memberTypeCd,ms.status_cd statusCd,
-        ms.audit_status_cd auditStatusCd
+        ms.audit_status_cd auditStatusCd,
+        (CASE
+        WHEN ms.audit_status_cd='1000'
+        THEN '寰呭鏍�'
+        WHEN ms.audit_status_cd = '1100'
+        THEN '瀹℃牳瀹屾垚'
+        ELSE
+        '瀹℃牳鎷掔粷'
+        END) stateName
+        <if test="needCommunityInfo == true">
+            ,sc.name
+        </if>
         from s_community_member ms
+        <if test="needCommunityInfo == true">
+            ,s_community sc,
+            s_community_member msc
+        </if>
         where 1=1
+        <if test="needCommunityInfo == true">
+            and sc.`community_id` = ms.`community_id`
+            AND sc.`status_cd` = '0'
+            and sc.state='1100'
+        </if>
         <if test="statusCd != null and statusCd != ''">
             and ms.status_cd = #{statusCd}
         </if>
@@ -289,8 +312,15 @@
         <if test="communityMemberId != null and communityMemberId !=''">
             and ms.community_member_id = #{communityMemberId}
         </if>
-        <if test="memberId != null and memberId != ''">
+        <if test="memberId != null and memberId != '' and needCommunityInfo == true">
+            AND ms.`community_id` = msc.`community_id`
+            and msc.member_id = #{memberId}
+        </if>
+        <if test="memberId != null and memberId != '' and needCommunityInfo == false">
             and ms.member_id = #{memberId}
+        </if>
+        <if test="noAuditEnterCommunity == true">
+            and ms.member_type_cd not in ('390001200003','390001200005','390001200000')
         </if>
         <if test="memberTypeCd != null and memberTypeCd != ''">
             and ms.member_type_cd = #{memberTypeCd}
@@ -330,7 +360,16 @@
     <select id="getCommunityMemberCount" parameterType="Map" resultType="Map">
         select count(1) count
         from s_community_member ms
+        <if test="needCommunityInfo == true">
+            ,s_community sc,
+            s_community_member msc
+        </if>
         where 1=1
+        <if test="needCommunityInfo == true">
+            and sc.`community_id` = ms.`community_id`
+            AND sc.`status_cd` = '0'
+            and sc.state='1100'
+        </if>
         <if test="statusCd != null and statusCd != ''">
             and ms.status_cd = #{statusCd}
         </if>
@@ -341,9 +380,18 @@
         <if test="communityMemberId != null and communityMemberId !=''">
             and ms.community_member_id = #{communityMemberId}
         </if>
-        <if test="memberId != null and memberId != ''">
+        <if test="memberId != null and memberId != '' and needCommunityInfo == true">
+            AND ms.`community_id` = msc.`community_id`
+            and msc.member_id = #{memberId}
+        </if>
+        <if test="memberId != null and memberId != '' and needCommunityInfo == false">
             and ms.member_id = #{memberId}
         </if>
+
+        <if test="noAuditEnterCommunity == true">
+            and ms.member_type_cd not in ('390001200003','390001200005','390001200000')
+        </if>
+
         <if test="memberTypeCd != null and memberTypeCd != ''">
             and ms.member_type_cd = #{memberTypeCd}
         </if>
@@ -351,6 +399,12 @@
             and ms.audit_status_cd = #{auditStatusCd}
         </if>
 
+        <if test="auditStatusCds != null and auditStatusCds != null">
+            and ms.audit_status_cd in
+            <foreach collection="auditStatusCds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
         <if test="communityId != null and communityId != ''">
             and ms.community_id = #{communityId}
         </if>
@@ -358,8 +412,21 @@
 
     <!-- 鏌ヨ灏忓尯淇℃伅 add by wuxw 2018-07-03 -->
     <select id="getCommunityInfoNew" parameterType="Map" resultType="Map">
-        select  t.address,t.nearby_landmarks,t.nearby_landmarks nearbyLandmarks,t.city_code,t.city_code cityCode,t.name,t.status_cd,t.status_cd statusCd,t.community_id,t.community_id communityId,t.b_id,t.b_id bId,t.map_y,t.map_y mapY,t.map_x,t.map_x mapX
+        select  t.address,t.nearby_landmarks,t.nearby_landmarks nearbyLandmarks,
+        t.city_code,t.city_code cityCode,t.name,t.status_cd,t.status_cd statusCd,
+        t.community_id,t.community_id communityId,t.b_id,t.b_id bId,t.map_y,t.map_y mapY,
+        t.map_x,t.map_x mapX,t.state,(CASE
+        WHEN t.state='1000'
+        THEN '寰呭鏍�'
+        WHEN t.state = '1100'
+        THEN '瀹℃牳瀹屾垚'
+        ELSE
+        '瀹℃牳鎷掔粷'
+        END) stateName
         from s_community t
+        <if test="memberId !=null and memberId !=''">
+            ,s_community_member cm
+        </if>
         where 1 =1
         <if test="address !=null and address != ''">
             and t.address= #{address}
@@ -379,6 +446,12 @@
         <if test="communityId !=null and communityId != ''">
             and t.community_id= #{communityId}
         </if>
+        <if test="communityIds !=null">
+            and t.community_id in
+            <foreach collection="communityIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
         <if test="bId !=null and bId != ''">
             and t.b_id= #{bId}
         </if>
@@ -387,6 +460,14 @@
         </if>
         <if test="mapX !=null and mapX != ''">
             and t.map_x= #{mapX}
+        </if>
+        <if test="state !=null and state != ''">
+            and t.state= #{state}
+        </if>
+        <if test="memberId !=null and memberId !=''">
+            and cm.community_id = t.community_id
+            and cm.member_id = #{memberId}
+            and cm.status_cd = '0'
         </if>
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
@@ -400,6 +481,9 @@
     <select id="queryCommunitysCount" parameterType="Map" resultType="Map">
         select  count(1) count
         from s_community t
+        <if test="memberId !=null and memberId !=''">
+            ,s_community_member cm
+        </if>
         where 1 =1
         <if test="address !=null and address != ''">
             and t.address= #{address}
@@ -428,6 +512,14 @@
         <if test="mapX !=null and mapX != ''">
             and t.map_x= #{mapX}
         </if>
+        <if test="state !=null and state != ''">
+            and t.state= #{state}
+        </if>
+        <if test="memberId !=null and memberId !=''">
+            and cm.community_id = t.community_id
+                and cm.member_id = #{memberId}
+                and cm.status_cd = '0'
+        </if>
 
 
     </select>

--
Gitblit v1.8.0