<?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.VehiclePublishGoodsMapper">


    <select id="selectList"  resultType="com.xxfc.platform.vehicle.pojo.vo.VehiclePublishGoodsVo" parameterType="com.xxfc.platform.vehicle.pojo.dto.VehiclePublishFindDTO">
        SELECT g.*, IFNULL(b1.cn_name,b.cn_name) as brandName,IFNULL(c1.`name`,c.`name`) as categoryName FROM vehicle_publish_goods g
        LEFT JOIN vehicle v ON g.vehicle_id=v.id
        LEFT JOIN vehicle_brand b1 ON v.brand_id=b1.id
        LEFT JOIN vehicle_category c1 ON v.category_id=c1.id
        LEFT JOIN vehicle_brand b ON g.brand_id=b.id
        LEFT JOIN vehicle_category c ON g.category_id=c.id
        <where>
              g.is_del = 0
            <if test="publishId != null and publishId > 0">
                AND  g.`publish_id`= #{publishId}
            </if>
        </where>
       order by g.number DESC
    </select>


    <select id="selectListByOrderNo"  resultType="com.xxfc.platform.vehicle.pojo.vo.VehiclePublishGoodsVo" parameterType="com.xxfc.platform.vehicle.pojo.dto.VehiclePublishFindDTO">
       SELECT r.goodsNumber,g.*,IFNULL(b1.cn_name,b.cn_name) as brandName,IFNULL(c1.`name`,c.`name`) as categoryName FROM
        (SELECT COUNT(id) as goodsNumber,publish_goods_id FROM vehicle_publish_receive
        WHERE receive_order_no = #{orderNo}
        GROUP BY publish_goods_id) r
        LEFT JOIN vehicle_publish_goods g  ON r.publish_goods_id=g.id
        LEFT JOIN vehicle v ON g.vehicle_id=v.id
        LEFT JOIN vehicle_brand b1 ON v.brand_id=b1.id
        LEFT JOIN vehicle_category c1 ON v.category_id=c1.id
        LEFT JOIN vehicle_brand b ON g.brand_id=b.id
        LEFT JOIN vehicle_category c ON g.category_id=c.id
        order by g.number DESC
    </select>


    
</mapper>