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