<?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.yc.ship.module.ota.dal.mysql.distributorproduct.DistributorProjectMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->
    <select id="getDistributorProjectList"
            resultType="com.yc.ship.module.ota.dal.dataobject.distributorproduct.DistributorProjectDO">
        select t1.*
        from ota_distributor_project t1
        where 1 = 1 and t1.deleted = 0
        <if test="params.distributorProductId != null and params.distributorProductId !=''">
            and t1.distributor_product_id = #{params.distributorProductId}
        </if>
        <if test="params.distributorId != null and params.distributorId !=''">
            and t1.distributor_id = #{params.distributorId}
        </if>
        <if test="params.productId != null and params.productId !=''">
            and t1.product_id = #{params.productId}
        </if>
        <if test="params.productBaseId != null and params.productBaseId !=''">
            and t1.product_base_id = #{params.productBaseId}
        </if>
        <if test="params.isUse != null">
            and t1.is_use = #{params.isUse}
        </if>
    </select>

    <select id="getProductGroupList"
            resultType="com.yc.ship.module.ota.controller.admin.distributorproduct.vo.product.ProductGroupRespVO">
        SELECT
        pd.product_id,pd.product_base_id, pd.spec_type specType, pd.cost_price costPrice, pd.sale_price salePrice,pd.is_use isUse,
        pd.specification_id, pb.`name` productBaseName, pp.`name` specificationName
        FROM
        ota_distributor_project pd
        INNER JOIN product_base pb on pd.product_base_id = pb.id
        INNER JOIN product_project pp on pp.id = pd.specification_id
        where 1 = 1
        <if test="params.distributorId != null and params.distributorId !=''">
            and pd.distributor_id = #{params.distributorId}
        </if>
        <if test="params.productId != null and params.productId !=''">
            and pd.product_id = #{params.productId}
        </if>
        <if test="params.distributorProductId != null and params.distributorProductId !=''">
            and pd.distributor_product_id = #{params.distributorProductId}
        </if>
        <if test="params.productBaseId != null and params.productBaseId !=''">
            and pd.product_base_id = #{params.productBaseId}
        </if>
    </select>
</mapper>