<?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.lutao.cloud.oil.mapper.PersonInInfoMapper">



    <resultMap id="getPersonGoSeaDetailInformationPageMap"
               type="com.lutao.cloud.oil.pojo.vo.PersonGoSeaDetailInformationVO">
        <result property="personName" column="person_name"/>
        <result property="onPlatformDate" column="in_time"/>
        <result property="certificateNumber" column="certificate"/>
        <result property="tel" column="phone"/>
    </resultMap>

    <select id="getPersonGoSeaDetailInformationPage"
            resultType="com.lutao.cloud.oil.pojo.vo.PersonGoSeaDetailInformationVO">

        select pii.person_name AS personName, pii.in_time AS onPlatformDate, pc.certificate as certificateNumber,
        pi.phone AS tel,
        pfi.platform_name AS platformName,
        pfi.oil_gas_name AS oilGasName,
        pfi.operating_company AS operatingCompany,
        ai.app_name AS appName
        from person_in_info pii
        LEFT JOIN person_certificate pc ON pii.person_id = pc.person_id AND pc.certificate_type = 8
        LEFT JOIN person_info pi ON pii.person_id = pi.origin_id
        LEFT JOIN platform_info pfi ON pii.platform_code = pfi.platform_code
        LEFT JOIN app_info ai ON pii.app_id = ai.id
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
               and pii.platform_code = #{param.platformId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and pfi.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and pfi.oil_gas_name = #{param.oilGasName}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and pii.app_id = #{param.appId}
            </if>
            <if test="param.name != null and param.name != ''">
                and pii.person_name like concat('%',#{param.name},'%')
            </if>
        </where>
        ORDER BY
        onPlatformDate DESC,
        certificateNumber IS NULL DESC
    </select>
</mapper>
