<?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.EnterprisesUnitMapper">
    <resultMap id="EnterprisesUnitPagerVoResultMap" type="com.changhu.module.management.pojo.vo.EnterprisesUnitPagerVo">
        <result
                column="contact_person_info"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler"
                property="contactPersonInfo"/>
    </resultMap>
    <select id="pager" resultMap="EnterprisesUnitPagerVoResultMap">
        select eu.*,
               ad1.name as provinceName,
               ad2.name as cityName,
               ad3.name as districtsName,
               ad4.name as streetName
        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
        where eu.delete_flag = 0
          and eu.police_unit_id = #{params.policeUnitId}
        order by eu.create_time desc
    </select>

    <resultMap id="PoliceEnterprisesUnitPagerVoResultMap"
               type="com.changhu.module.management.pojo.vo.PoliceEnterprisesUnitPagerVo">
        <result
                column="contact_person_info"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler"
                property="contactPersonInfo"/>
    </resultMap>
    <select id="policeEnterprisesUnitPager"
            resultMap="PoliceEnterprisesUnitPagerVoResultMap">
        select eu.*,
               ad1.name as provinceName,
               ad2.name as cityName,
               ad3.name as districtsName,
               ad4.name as streetName
        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
        where eu.delete_flag = 0
          and eu.police_unit_id = ${@com.changhu.common.utils.UserUtil@getUnitId()}
        <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>