<?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.changhu.module.management.mapper.SecurityUnitMapper">
    <resultMap id="SecurityUnitPagerVoResultMap" type="com.changhu.module.management.pojo.vo.SecurityUnitPagerVo">
        <result
                column="legal_person_info"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler"
                property="legalPersonInfo"/>
    </resultMap>
    <select id="pager" resultMap="SecurityUnitPagerVoResultMap">
        select
            su.*,
            ad1.name as provinceName,
            ad2.name as cityName,
            ad3.name as districtsName,
            ad4.name as streetName
        from
            security_unit su
            left join administrative_division ad1 on su.province = ad1.code and ad1.delete_flag = 0
            left join administrative_division ad2 on su.city = ad2.code and ad2.delete_flag = 0
            left join administrative_division ad3 on su.districts = ad3.code and ad3.delete_flag = 0
            left join administrative_division ad4 on su.street = ad4.code and ad4.delete_flag = 0
        where
            su.delete_flag = 0
            <if test="params.name!=null and params.name!=''">
                and su.name like concat('%',#{params.name},'%')
            </if>
            <if test="params.socialCode!=null and params.socialCode!=''">
                and su.socialCode like concat('%',#{params.socialCode},'%')
            </if>
            <if test="params.administrativeDivisionCodes!=null">
                <if test="params.administrativeDivisionCodes.size>=1">
                    and su.province = #{params.administrativeDivisionCodes[0]}
                </if>
                <if test="params.administrativeDivisionCodes.size>=2">
                    and su.city = #{params.administrativeDivisionCodes[1]}
                </if>
                <if test="params.administrativeDivisionCodes.size>=3">
                    and su.districts = #{params.administrativeDivisionCodes[2]}
                </if>
                <if test="params.administrativeDivisionCodes.size>=4">
                    and su.street = #{params.administrativeDivisionCodes[3]}
                </if>
                order by su.create_time desc
            </if>
            <if test="params.isEnable!=null">and su.is_enable = #{params.isEnable.value}</if>
            <if test="params.checkStatus!=null">and su.check_status = #{params.checkStatus.value}</if>
        order by su.create_time desc
    </select>
</mapper>