From d0b0e00e40226700a0ffa1f1671a8dc273610f67 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Mon, 18 Dec 2023 14:28:10 +0800
Subject: [PATCH] 菜单分类优化

---
 src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 101 insertions(+), 2 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 2cd2896..11fe4a6 100644
--- a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
+++ b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
@@ -89,8 +89,31 @@
         </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,
@@ -116,6 +139,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 +153,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
@@ -236,4 +265,74 @@
     </select>
 
 
+    <select id="getHouseHoldStatistics" resultType="java.util.Map">
+        SELECT
+        CASE
+        WHEN
+        jh.gender = 1 THEN
+        '男'
+        WHEN jh.gender = 0 THEN
+        '女' ELSE '未知'
+        END AS gender,
+        count( 1 ) numbers
+        FROM
+        jczz_household jh
+        LEFT JOIN jczz_doorplate_address jda ON jh.house_code = jda.address_code
+        WHERE
+        jda.nei_code = #{code}
+        AND jh.is_deleted = 0
+        <if test="userId != null">
+        AND jda.address_code IN (
+        SELECT
+        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 jh.house_code = jgr.house_code
+        AND jg.is_deleted = 0
+        )
+        </if>
+        GROUP BY
+        gender
+
+
+    </select>
+    <select id="getHouseHoldStatisticsAge" resultType="java.util.Map">
+
+        select
+            case
+                when TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ >= ]]> 0  and TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ <= ]]> 3   then '0~3岁'
+                when TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ >= ]]> 4 and TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())   <![CDATA[ <= ]]> 17  then '4~17岁'
+                when TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ >= ]]> 18 and TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ <= ]]> 39  then '18~39岁'
+                when TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ >= ]]> 40 and TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ <= ]]> 59  then '40~59岁'
+                when TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ >= ]]> 60 and TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate())  <![CDATA[ <= ]]> 79  then '60~79岁'
+                when TIMESTAMPDIFF(YEAR,STR_TO_DATE(substr(id_card,7,8),'%Y%m%d'),sysdate()) <![CDATA[ > ]]> 80 then '80岁以上'
+                ELSE '无身份信息'
+                END AS age,
+            count(1) as number FROM
+            jczz_household jh
+                LEFT JOIN jczz_doorplate_address jda ON jh.house_code = jda.address_code
+        WHERE
+            jda.nei_code =  #{code}
+          AND jh.is_deleted = 0
+        <if test="userId != null">
+        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>
+        GROUP BY age
+    </select>
+
+
 </mapper>

--
Gitblit v1.9.3