<?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.yami.shop.distribution.comment.dao.DistributionBasicSetMapper">
    <resultMap id="BaseResultMap" type="com.yami.shop.distribution.comment.model.DistributionBasicSet">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="basic_set_id" jdbcType="BIGINT" property="basicSetId"/>
        <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
        <result column="distribution_switch" jdbcType="TINYINT" property="distributionSwitch"/>
        <result column="parallel_deal" jdbcType="TINYINT" property="parallelDeal"/>
        <result column="own_buy_award" jdbcType="TINYINT" property="ownBuyAward"/>
        <result column="vip_buy_award" jdbcType="TINYINT" property="vipBuyAward"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="modifier_id" jdbcType="BIGINT" property="modifierId"/>
    </resultMap>

    <select id="getByShopId" resultMap="BaseResultMap">
        select
          basic_set_id,
          shop_id,
          distribution_switch,
          parallel_deal,
          own_buy_award,
          vip_buy_award,
          update_time,
          modifier_id
        from
        tz_distribution_basic_set
        where
        shop_id = #{shopId}
    </select>
    <select id="getDistributionBasicSetPage" resultType="com.yami.shop.distribution.comment.model.DistributionBasicSet">
        SELECT dbs.*,sd.shop_name
        FROM tz_distribution_basic_set  dbs
        LEFT JOIN tz_shop_detail sd ON sd.shop_id = dbs.shop_id
        <where>
            <if test="distributionBasicSet.shopName != null">
                sd.shop_name LIKE concat("%",#{distributionBasicSet.shopName},"%")
            </if>
            <if test="distributionBasicSet.basicSetId != null">
                AND dbs.basic_set_id = #{distributionBasicSet.basicSetId}
            </if>
            <if test="distributionBasicSet.distributionSwitch != null">
                AND dbs.distribution_switch = #{distributionBasicSet.distributionSwitch}
            </if>
        </where>
        ORDER BY dbs.update_time DESC
    </select>

    <update id="updateDistributionSwitch">
        UPDATE tz_distribution_basic_set SET distribution_switch =#{distributionSwitch} WHERE basic_set_id = #{basicSetId}
    </update>

</mapper>
