linwe
2023-12-15 6e9f2c5ade8802645fd4e0b718ae14d40066b4d5
src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
@@ -116,6 +116,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 +130,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 +242,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>