<?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.tofly.gpsboot.mapper.build.BuildMapper">

    <resultMap id="buildMap" type="com.tofly.pojo.build.Build">
        <id property="id" column="ID"/>
        <result property="submitTime" column="SUBMIT_TIME"/>
        <result property="submitUser" column="SUBMIT_USER"/>
        <result property="auditResult" column="AUDIT_RESULT"/>
        <result property="auditTime" column="AUDIT_TIME"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditNotes" column="AUDIT_NOTES"/>
        <result property="isread" column="ISREAD"/>
        <result property="typeId" column="TYPE_ID"/>
        <result property="uploadType" column="UPLOAD_TYPE"/>
        <result property="lgtd" column="LGTD"/>
        <result property="lttd" column="LTTD"/>
        <result property="address" column="ADDRESS"/>
        <result property="sgdw" column="SGDW"/>
        <result property="gdfzr" column="GDFZR"/>
        <result property="phone" column="PHONE"/>
        <result property="notes" column="NOTES"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="uploadFileids" column="UPLOAD_FILEIDS"/>
        <result property="ischeackRead" column="ISCHEACK_READ"/>
        <result property="isrespect" column="ISRESPECT"/>
        <result property="state" column="STATE"/>
        <result property="isSubmit" column="IS_SUBMIT"/>
        <result property="regionId" column="REGION_ID"/>
        <result property="regionName" column="REGION_NAME"/>
        <result property="ownerUnitName" column="OWNER_UNIT_NAME"/>
        <result property="ownerUnitUser" column="OWNER_UNIT_USER"/>
        <result property="ownerUnitPhone" column="OWNER_UNIT_PHONE"/>
        <result property="siteName" column="SITE_NAME"/>
    </resultMap>


    <select id="getBuildListPge" resultMap="buildMap">
        select t1.*
        from TF_YWPN_BUILD_W t1
        where 1=1
        <if test="userIdList != null and userIdList.size>0  ">
            and t1.CREATE_USER in
            <foreach collection="userIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="flag != null and flag != '' ">
            and t1.ID in (select w2.build_Id from TF_YWPN_PLANCHILD_W w1 left join TF_YWPN_BUILDPLAN_W w2
            on w1.plan_Id = w2.plan_Id
            where w1.resp_User = #{respUser}
            )
        </if>
        <if test="state != null and state != '' ">
            and t1.state in
            <foreach collection="state.split(',')" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="auditResults != null and auditResults != '' ">
            and t1.AUDIT_RESULT in
            <foreach collection="auditResults.split(',')" item="item" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="address != null and address != '' ">
            and t1.ADDRESS like '%' || #{address} || '%'
        </if>
        <if test="auditUser != null">
            and t1.AUDIT_USER = #{auditUser}
        </if>
        <if test="typeId != null">
            and t1.TYPE_ID = #{typeId}
        </if>
    order by t1.CREATE_TIME DESC ,AUDIT_TIME DESC
    </select>

</mapper>
