<?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.xxfc.platform.vehicle.mapper.VehiclePublishMapper">


    <select id="selectList"  resultType="com.xxfc.platform.vehicle.pojo.vo.VehiclePublishVo" parameterType="com.xxfc.platform.vehicle.pojo.dto.VehiclePublishFindDTO">
        SELECT p.*,c.`name` as companyName FROM vehicle_publish p
        LEFT JOIN branch_company c ON p.company_id = c.id
        <where>
              p.is_del = 0
            <if test="type != null ">
                AND  p.`type`= #{type}
            </if>
            <if test="companyId != null and companyId > 0">
                AND  p.`company_id`= #{companyId}
            </if>
            <if test="publishId != null and publishId > 0">
                AND  p.`id`= #{publishId}
            </if>
            <if test="goodsType != null ">
                AND  p.`goods_type`= #{goodsType}
            </if>
            <if test="nowTime != null  and nowTime > 0">
                AND  p.`publish_end_time` >= #{nowTime} AND  p.number > (p.confirm_number+p.wait_confirm_number)
            </if>
            <if test="dataCompanyIds != null and dataCompanyIds.size > 0">
                and p.id in
                <foreach collection="dataCompanyIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="dataCorporationIds != null and dataCorporationIds.size > 0">
                and p.company_id  in
                <foreach collection="dataCorporationIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
        <if test="selectType != null ">
            <choose>
                <when test="selectType == 1">
                    order by p.publish_end_time ASC
                </when>
                <when test="selectType == 2">
                    order by p.wait_confirm_number DESC,p.publish_end_time ASC
                </when>
                <otherwise>
                    order by p.id DESC
                </otherwise>
            </choose>
        </if>
    </select>

</mapper>