From 224e0bbfc8d24785fea2e0160c36d7a8f6cd7269 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Thu, 21 Dec 2023 14:17:17 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml |   88 ++++++++++++++++++++++++++++----------------
 1 files changed, 56 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
index b60cee6..974aac7 100644
--- a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
+++ b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
@@ -89,14 +89,40 @@
         </collection>
     </resultMap>
 
+    <resultMap id="householdPageAndLabelMap" type="org.springblade.modules.house.vo.HouseholdVO" autoMapping="true">
+        <id property="id" column="id"/>
+        <collection property="householdLabelList" javaType="java.util.List" select="selectHouseLabelPage"  column="id"
+                    ofType="org.springblade.modules.house.vo.HouseholdLabelVO" autoMapping="true">
+        </collection>
+    </resultMap>
+
+    <select id="selectHouseLabelPage" resultType="org.springblade.modules.house.vo.HouseholdLabelVO">
+        select
+        id,
+        house_code,
+        label_id,
+        label_name,
+        color,
+        remark cremark,
+        user_id,
+        lable_type,
+        household_id
+        from
+        jczz_user_house_label
+        where household_id = #{id} and lable_type = 1
+    </select>
+
     <!--自定义分页数据查询-->
-    <select id="selectHouseholdPage" resultType="org.springblade.modules.house.vo.HouseholdVO">
+    <select id="selectHouseholdPage" resultMap="householdPageAndLabelMap">
         select
         jh.*,
         jhs.district_name aoiName,
-        concat(jhs.building," ",unit," ",room) as address
+        concat(jhs.building," ",unit," ",room) as address,
+        jda.town_street_name as townStreetName,jda.nei_name as neiName
         from
-        jczz_household jh join jczz_house jhs on jh.house_code = jhs.house_code and jhs.is_deleted = 0
+        jczz_household jh
+        join jczz_house jhs on jh.house_code = jhs.house_code and jhs.is_deleted = 0
+        left join jczz_doorplate_address jda on jda.address_code = jh.house_code
         where jh.is_deleted = 0
         <if test="household.name!=null and household.name !=''">
             and jh.name like concat('%',#{household.name},'%')
@@ -116,6 +142,10 @@
         <if test="household.confirmFlag != null ">
             and jh.confirm_flag = #{household.confirmFlag}
         </if>
+
+        <if test="household.housingRentalId != null ">
+            and jh.housing_rental_id = #{household.housingRentalId}
+        </if>
     </select>
 
     <!--查询房屋集合信息-->
@@ -126,7 +156,9 @@
                false            as hasChildren,
                jda.doorplate_type  doorplateType,
                jda.address_level   addressLevel,
-               jda.nei_name   neiName
+               jda.nei_name        neiName,
+               jda.aoi_code        aoiCode,
+               jh.relationship     relationship
         from jczz_household jh
                  left join jczz_doorplate_address jda on jh.house_code = jda.address_code
         where 1 = 1
@@ -237,21 +269,17 @@
 
 
     <select id="getHouseHoldStatistics" resultType="java.util.Map">
-
         SELECT
         a.gender,
         count( a.gender ) numbers
         FROM
+        ( SELECT
+        IF
         (
-        SELECT
-        CASE
-
-        WHEN
-        jh.gender = 1 THEN
-        '男'
-        WHEN jh.gender = 0 THEN
-        '女' ELSE '未知'
-        END AS gender
+        id_card IS NULL,
+        '未知',
+        IF
+        (SUBSTRING( id_card, 17, 1 ) % 2 = 1, '男', '女' )) AS gender
         FROM
         jczz_household jh
         LEFT JOIN jczz_doorplate_address jda ON jh.house_code = jda.address_code
@@ -259,9 +287,9 @@
         jda.nei_code = #{code}
         AND jh.is_deleted = 0
         <if test="userId != null">
-            AND EXISTS (
+            AND jda.address_code IN (
             SELECT
-            *
+            jgr.house_code
             FROM
             jczz_grid jg
             LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
@@ -294,24 +322,20 @@
         WHERE
             jda.nei_code =  #{code}
           AND jh.is_deleted = 0
-        GROUP BY
-                age
         <if test="userId != null">
-            AND EXISTS (
-            SELECT
-            *
-            FROM
-            jczz_grid jg
-            LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
-            LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
-            WHERE
-            jgm.user_id = #{userId}
-            AND jh.house_code = jgr.house_code
-            AND jg.is_deleted = 0
-            )
+        AND jda.address_code IN (
+        SELECT
+        distinct jgr.house_code
+        FROM
+        jczz_grid jg
+        LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
+        LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
+        WHERE
+        jgm.user_id = #{userId}
+        AND jg.is_deleted = 0
+        )
         </if>
-        ORDER BY
-            age
+        GROUP BY age
     </select>
 
 

--
Gitblit v1.9.3