<?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.mapper.EnterprisesUnitMapper">
    <resultMap id="EnterprisesUnitPagerVoResultMap" type="com.changhu.pojo.vo.EnterprisesUnitPagerVo">
        <result
                column="contact_person_info"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler"
                property="contactPersonInfo"/>
        <result
                column="createUser"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler"
                property="createUser"/>
    </resultMap>
    <select id="pager" resultMap="EnterprisesUnitPagerVoResultMap">
        select eu.*,
        ad1.name as provinceName,
        ad2.name as cityName,
        ad3.name as districtsName,
        ad4.name as streetName,
        json_object('snowFlakeId',spu.snow_flake_id,'name',spu.name,'type', spu.type) as 'createUser'
        from enterprises_unit eu
        left join administrative_division ad1 on eu.province = ad1.code and ad1.delete_flag = 0
        left join administrative_division ad2 on eu.city = ad2.code and ad2.delete_flag = 0
        left join administrative_division ad3 on eu.districts = ad3.code and ad3.delete_flag = 0
        left join administrative_division ad4 on eu.street = ad4.code and ad4.delete_flag = 0
        left join super_police_users spu on eu.create_by = spu.snow_flake_id
        where eu.delete_flag = 0
        <choose>
            <when test="unitId != null">
                and eu.police_unit_id = #{unitId}
            </when>
            <otherwise>
                and eu.police_unit_id = #{params.policeUnitId}
            </otherwise>
        </choose>
        <if test="params.name != null and params.name != ''">
            and eu.name like concat('%', #{params.name}, '%')
        </if>
        <if test="params.address != null and params.address != ''">
            and eu.address like concat('%', #{params.address}, '%')
        </if>
        <if test="params.remark != null and params.remark != ''">
            and eu.remark like concat('%', #{params.remark}, '%')
        </if>
        order by eu.create_time desc
    </select>

</mapper>