1.智慧安防小区

  • 1.参考foreach
   <!--人员搜素分页-->
    <select id="pageWithCustom" resultType="com.gxhj.safecommunity.person.entity.PersonInfo">
        select pi.name as name,pi.age ,pi.person_id as personId,pi.gender_code as genderCode,pi.idcard as idcard
        from (select (to_char(sysdate, 'yyyy') - substr(IDCARD, 7, 4)) as age, a.*
        from Person_Info a) pi
        <!--/*关键字搜索*/-->
        <where>
            <if test="personInfo.key != null and personInfo.key!= ''">
                and (pi.name like '%' || #{personInfo.key} || '%' or pi.idcard like '%' || #{personInfo.key} || '%' or
                pi.current_address like '%' || #{personInfo.key} || '%')
            </if>

            <if test="personInfo.lstAgeScope != null and personInfo.lstAgeScope.size() > 0 ">
                and
                <foreach collection="personInfo.lstAgeScope" item="item" open="(" separator=" or " close=")"
                         index="index">
                    ( pi.age &gt;= #{item.minAge} and pi.age &lt;= #{item.maxAge})
                </foreach>
            </if>

            <!-- 实有人口管理类别(SYRKGLLBDM)-人员类型统计 -->
            <!--            <if test="personInfo.personManageType != null and personInfo.personManageType!= ''">-->
            <!--                and pi.person_manage_type = #{personInfo.personManageType}-->
            <!--            </if>-->
            <if test="personInfo.queryPersonManageTypeList != null and personInfo.queryPersonManageTypeList.size() > 0 ">
                and pi.person_manage_type in
                <foreach collection="personInfo.queryPersonManageTypeList" item="item" open="(" separator="," close=")" index="index">
                    #{item}
                </foreach>
            </if>
            <!--/*重点人员类型统计*/-->
           <!--   <if test="personInfo.attentionTypeCode != null and personInfo.attentionTypeCode!= ''">
                  and (exists (select * from person_attentionperson pa where pa.attention_type_code=
                  #{personInfo.attentionTypeCode} and pa.person_id = pi.person_id))
              </if>-->
            <if test="personInfo.queryAttentionTypeCodeList != null and personInfo.queryAttentionTypeCodeList.size()>0 ">
                and (exists (select * from person_attentionperson pa where pa.attention_type_code in
                <foreach collection="personInfo.queryAttentionTypeCodeList" item="item" open="(" separator="," close=")" index="index">
                    #{item}
                </foreach>
                and pa.person_id = pi.person_id))
            </if>
            <!--/*户籍地址_行政区划代码 省份统计*/-->
            <!--            <if test="personInfo.nativeAdminAreaCode != null and personInfo.nativeAdminAreaCode!= ''">-->
            <!--                and substr(pi.native_admin_area_code,0,2) = #{personInfo.nativeAdminAreaCode}-->
            <!--            </if>-->
            <if test="personInfo.queryNativeAdminAreaCodeList != null and personInfo.queryNativeAdminAreaCodeList.size() > 0 ">
                and substr(pi.native_admin_area_code,0,2) in
                <foreach collection="personInfo.queryNativeAdminAreaCodeList" item="item" open="(" separator="," close=")" index="index">
                    #{item}
                </foreach>
            </if>

        <!--/*小区信息标识*/-->
        <if test="personInfo.villageId != null and personInfo.villageId!= ''">
            and ( exists (select *
            from village_house h
            where village_id = #{personInfo.villageId}
            and h.owner_person_id = pi.person_id)
            or exists (select *
            from village_personhouserelation r
            where r.village_id = #{personInfo.villageId}
            and r.person_id = pi.person_id and (departure_date is null or departure_date >= sysdate) ) )
        </if>

        <!--/*租客*/-->
        <if test="personInfo.queryTenantList != null and personInfo.queryTenantList!= '' and  personInfo.queryTenantList == 3 ">
            and ( exists (select *
            from Village_Personhouserelation vph
            where (vph.departure_date is null or departure_date >= sysdate)
            and EXISTS (select *
            from VILLAGE_HOUSE vh
            where live_type = '4'
            and vph.person_id != vh.owner_person_id)
            and vph.person_id = pi.person_id))
        </if>
    </where>
</select>

<?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="com.gxhj.safecommunity.person.mapper.PersonMapper">


    <!--人员省份统计-->
    <select id="queryCountGroupByProvince" resultType="java.util.Map">
          select count(1) as COUNT, code as NAME
            from (select ( substr(pi.NATIVE_ADMIN_AREA_CODE, 0, 2)) as code,pi.NATIVE_ADMIN_AREA_CODE
                  from
                 Person_Info pi where pi.NATIVE_ADMIN_AREA_CODE is not null)
           group by code
           order by count(1) asc
    </select>


    <!--统计年零范围-->
    <select id="queryCountGroupByAge" resultType="com.gxhj.safecommunity.person.entity.PersonInfo">
        select count(1) as PERSON_ID, age as NAME
          from (select (to_char(sysdate, 'yyyy') - substr(IDCARD, 7, 4)) as age
                  from Person_Info)
         group by age
         order by age asc
    </select>

    <!--根据关注人员类型统计-->
    <select id="queryCountGroupByAttentionType" resultType="java.util.Map">
        select count(pa.attention_type_code) as COUNT ,
               pa.attention_type_code as NAME
          from PERSON_INFO pi
          join Person_Attentionperson pa
            on pi.person_id = pa.person_id
         group by pa.attention_type_code
         order by count(pa.attention_type_code) desc
    </select>
    <!--人员搜素分页-->
    <select id="pageWithCustom" resultType="com.gxhj.safecommunity.person.entity.PersonInfo">
        select pi.name as name,pi.age ,pi.person_id as personId,pi.gender_code as genderCode,pi.idcard as idcard
        from (select (to_char(sysdate, 'yyyy') - substr(IDCARD, 7, 4)) as age, a.*
        from Person_Info a) pi
        <!--/*关键字搜索*/-->
        <where>
            <if test="personInfo.key != null and personInfo.key!= ''">
                and (pi.name like '%' || #{personInfo.key} || '%' or pi.idcard like '%' || #{personInfo.key} || '%' or
                pi.current_address like '%' || #{personInfo.key} || '%')
            </if>

            <if test="personInfo.lstAgeScope != null and personInfo.lstAgeScope.size() > 0 ">
                and
                <foreach collection="personInfo.lstAgeScope" item="item" open="(" separator=" or " close=")"
                         index="index">
                    ( pi.age &gt;= #{item.minAge} and pi.age &lt;= #{item.maxAge})
                </foreach>
            </if>

            <!-- 实有人口管理类别(SYRKGLLBDM)-人员类型统计 -->
            <!--            <if test="personInfo.personManageType != null and personInfo.personManageType!= ''">-->
            <!--                and pi.person_manage_type = #{personInfo.personManageType}-->
            <!--            </if>-->
            <if test="personInfo.queryPersonManageTypeList != null and personInfo.queryPersonManageTypeList.size() > 0 ">
                and pi.person_manage_type in
                <foreach collection="personInfo.queryPersonManageTypeList" item="item" open="(" separator="," close=")" index="index">
                    #{item}
                </foreach>
            </if>
            <!--/*重点人员类型统计*/-->
           <!--   <if test="personInfo.attentionTypeCode != null and personInfo.attentionTypeCode!= ''">
                  and (exists (select * from person_attentionperson pa where pa.attention_type_code=
                  #{personInfo.attentionTypeCode} and pa.person_id = pi.person_id))
              </if>-->
            <if test="personInfo.queryAttentionTypeCodeList != null and personInfo.queryAttentionTypeCodeList.size()>0 ">
                and (exists (select * from person_attentionperson pa where pa.attention_type_code in
                <foreach collection="personInfo.queryAttentionTypeCodeList" item="item" open="(" separator="," close=")" index="index">
                    #{item}
                </foreach>
                and pa.person_id = pi.person_id))
            </if>
            <!--/*户籍地址_行政区划代码 省份统计*/-->
            <!--            <if test="personInfo.nativeAdminAreaCode != null and personInfo.nativeAdminAreaCode!= ''">-->
            <!--                and substr(pi.native_admin_area_code,0,2) = #{personInfo.nativeAdminAreaCode}-->
            <!--            </if>-->
            <if test="personInfo.queryNativeAdminAreaCodeList != null and personInfo.queryNativeAdminAreaCodeList.size() > 0 ">
                and substr(pi.native_admin_area_code,0,2) in
                <foreach collection="personInfo.queryNativeAdminAreaCodeList" item="item" open="(" separator="," close=")" index="index">
                    #{item}
                </foreach>
            </if>

        <!--/*小区信息标识*/-->
        <if test="personInfo.villageId != null and personInfo.villageId!= ''">
            and ( exists (select *
            from village_house h
            where village_id = #{personInfo.villageId}
            and h.owner_person_id = pi.person_id)
            or exists (select *
            from village_personhouserelation r
            where r.village_id = #{personInfo.villageId}
            and r.person_id = pi.person_id and (departure_date is null or departure_date >= sysdate) ) )
        </if>

        <!--/*租客*/-->
        <if test="personInfo.queryTenantList != null and personInfo.queryTenantList!= '' and  personInfo.queryTenantList == 3 ">
            and ( exists (select *
            from Village_Personhouserelation vph
            where (vph.departure_date is null or departure_date >= sysdate)
            and EXISTS (select *
            from VILLAGE_HOUSE vh
            where live_type = '4'
            and vph.person_id != vh.owner_person_id)
            and vph.person_id = pi.person_id))
        </if>
    </where>
</select>

<!--查询人员关联信息-->
    <select id="queryAllRelationById" resultType="com.gxhj.safecommunity.person.vo.RelationVo">

        <if test="relationType.size > 0">
            select pi.person_id as id, pi.name, pi.gender_code as sex, pi.IDCARD as idcard, pr.relation_name as
            queryType, 0 as dataType
            from person_info pi right join person_relation pr on pi.person_id = pr.sub_people_id
            <where>
                and pr.main_people_id = #{id}
                and pr.relation_name in
                <foreach collection="relationType" item="item" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </where>
        </if>

        <if test="type.contains('04')">
            <if test="type.contains('04') and relationType.size > 0">
                union all
            </if>
            select v1.person_id as id, p.name, p.GENDER_CODE as sex, p.IDCARD as idcard, '04' as queryType, 0 as
            dataType
            from VILLAGE_PERSONHOUSERELATION v1 left join person_info p on v1.person_id = p.person_id
            where
            exists ( select v2.house_id from VILLAGE_PERSONHOUSERELATION v2
            where v2.person_id = #{id} and v2.house_id = v1.house_id and (v2.departure_date is null or v2.departure_date
            >= sysdate))
            or exists ( select v3.house_id from village_house v3 where v3.owner_person_id = #{id} and v3.house_id =
            v1.house_id)
        </if>

        <if test="type.contains('05')">
            <if test="type.contains('05') and (relationType.size > 0 or type.contains('04'))">
                union all
            </if>
            select pi5.person_id as id, pi5.name, pi5.GENDER_CODE as sex, pi5.IDCARD as idcard, '05' as queryType, 0
            as dataType
            from PERCEPTION_VISITOR pv5 left join person_Info pi5 on pv5.visitor_person_id = pi5.person_id
            where
            exists ( select v2.house_id from VILLAGE_PERSONHOUSERELATION v2 where v2.person_id = #{id} and v2.house_id =
            pv5.access_house_id and (v2.departure_date is null or v2.departure_date &gt;= sysdate))
            or exists ( select v3.house_id from village_house v3 where v3.owner_person_id = #{id} and v3.house_id =
            pv5.access_house_id)
        </if>

        <if test="type.contains('06')">
            <if test="type.contains('06') and (relationType.size > 0 or type.contains('04') or type.contains('05'))">
                union all
            </if>
            select v.vehicle_id as id, v.license_plate as name, '' as sex, '' as idcard, '06' as queryType, 1 as
            dataType from vehicle_info v
            where v.person_id = #{id}
        </if>
        <if test="type.contains('07')">
            <if test="type.contains('07') and (relationType.size > 0 or type.contains('04') or type.contains('05') or type.contains('06'))">
                union all
            </if>
            select vh.house_id as id, v.ADDRESS_NAME || vh.CODE as name, '' as sex, '' as idcard, '07' as queryType, 2
            as dataType
            from VILLAGE_HOUSE vh left join village_info v on vh.village_id = v.village_id
            where vh.owner_person_id = #{id}
        </if>

    </select>


</mapper>


©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容