<?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.bailuntec.mapper.SalesDayConfigMapper">
    <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku"/>
        <result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode"/>
        <result column="bailun_sku_warehouse_code" jdbcType="VARCHAR" property="bailunSkuWarehouseCode"/>
        <result column="date" jdbcType="TIMESTAMP" property="date"/>
        <result column="date_str" jdbcType="VARCHAR" property="dateStr"/>
        <result column="sales" jdbcType="DECIMAL" property="sales"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="create_user" jdbcType="VARCHAR" property="createUser"/>
        <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
        <result column="update_user" jdbcType="VARCHAR" property="updateUser"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        id, bailun_sku, warehouse_code, bailun_sku_warehouse_code, date, date_str, sales,
        create_date, create_user, update_date, update_user
    </sql>
    <select id="selectByExample" parameterType="com.bailuntec.domain.example.SalesDayConfigExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from sales_day_config
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        <if test="rows != null">
            <if test="offset != null">
                limit ${offset}, ${rows}
            </if>
            <if test="offset == null">
                limit ${rows}
            </if>
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List"/>
        from sales_day_config
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from sales_day_config
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.SalesDayConfigExample">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from sales_day_config
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into sales_day_config (id, bailun_sku, warehouse_code,
        bailun_sku_warehouse_code, date, date_str,
        sales, create_date, create_user,
        update_date, update_user)
        values (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR},
        #{bailunSkuWarehouseCode,jdbcType=VARCHAR}, #{date,jdbcType=TIMESTAMP}, #{dateStr,jdbcType=VARCHAR},
        #{sales,jdbcType=DECIMAL}, #{createDate,jdbcType=TIMESTAMP}, #{createUser,jdbcType=VARCHAR},
        #{updateDate,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into sales_day_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="bailunSku != null">
                bailun_sku,
            </if>
            <if test="warehouseCode != null">
                warehouse_code,
            </if>
            <if test="bailunSkuWarehouseCode != null">
                bailun_sku_warehouse_code,
            </if>
            <if test="date != null">
                date,
            </if>
            <if test="dateStr != null">
                date_str,
            </if>
            <if test="sales != null">
                sales,
            </if>
            <if test="createDate != null">
                create_date,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="updateDate != null">
                update_date,
            </if>
            <if test="updateUser != null">
                update_user,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="bailunSku != null">
                #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="bailunSkuWarehouseCode != null">
                #{bailunSkuWarehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="date != null">
                #{date,jdbcType=TIMESTAMP},
            </if>
            <if test="dateStr != null">
                #{dateStr,jdbcType=VARCHAR},
            </if>
            <if test="sales != null">
                #{sales,jdbcType=DECIMAL},
            </if>
            <if test="createDate != null">
                #{createDate,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null">
                #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="updateDate != null">
                #{updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                #{updateUser,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="com.bailuntec.domain.example.SalesDayConfigExample"
            resultType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from sales_day_config
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update sales_day_config
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=INTEGER},
            </if>
            <if test="record.bailunSku != null">
                bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="record.warehouseCode != null">
                warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="record.bailunSkuWarehouseCode != null">
                bailun_sku_warehouse_code = #{record.bailunSkuWarehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="record.date != null">
                date = #{record.date,jdbcType=TIMESTAMP},
            </if>
            <if test="record.dateStr != null">
                date_str = #{record.dateStr,jdbcType=VARCHAR},
            </if>
            <if test="record.sales != null">
                sales = #{record.sales,jdbcType=DECIMAL},
            </if>
            <if test="record.createDate != null">
                create_date = #{record.createDate,jdbcType=TIMESTAMP},
            </if>
            <if test="record.createUser != null">
                create_user = #{record.createUser,jdbcType=VARCHAR},
            </if>
            <if test="record.updateDate != null">
                update_date = #{record.updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="record.updateUser != null">
                update_user = #{record.updateUser,jdbcType=VARCHAR},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update sales_day_config
        set id = #{record.id,jdbcType=INTEGER},
        bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
        warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
        bailun_sku_warehouse_code = #{record.bailunSkuWarehouseCode,jdbcType=VARCHAR},
        date = #{record.date,jdbcType=TIMESTAMP},
        date_str = #{record.dateStr,jdbcType=VARCHAR},
        sales = #{record.sales,jdbcType=DECIMAL},
        create_date = #{record.createDate,jdbcType=TIMESTAMP},
        create_user = #{record.createUser,jdbcType=VARCHAR},
        update_date = #{record.updateDate,jdbcType=TIMESTAMP},
        update_user = #{record.updateUser,jdbcType=VARCHAR}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update sales_day_config
        <set>
            <if test="bailunSku != null">
                bailun_sku = #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="bailunSkuWarehouseCode != null">
                bailun_sku_warehouse_code = #{bailunSkuWarehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="date != null">
                date = #{date,jdbcType=TIMESTAMP},
            </if>
            <if test="dateStr != null">
                date_str = #{dateStr,jdbcType=VARCHAR},
            </if>
            <if test="sales != null">
                sales = #{sales,jdbcType=DECIMAL},
            </if>
            <if test="createDate != null">
                create_date = #{createDate,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null">
                create_user = #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="updateDate != null">
                update_date = #{updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update sales_day_config
        set bailun_sku = #{bailunSku,jdbcType=VARCHAR},
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
        bailun_sku_warehouse_code = #{bailunSkuWarehouseCode,jdbcType=VARCHAR},
        date = #{date,jdbcType=TIMESTAMP},
        date_str = #{dateStr,jdbcType=VARCHAR},
        sales = #{sales,jdbcType=DECIMAL},
        create_date = #{createDate,jdbcType=TIMESTAMP},
        create_user = #{createUser,jdbcType=VARCHAR},
        update_date = #{updateDate,jdbcType=TIMESTAMP},
        update_user = #{updateUser,jdbcType=VARCHAR}
        where id = #{id,jdbcType=INTEGER}
    </update>
    <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          @project https://github.com/itfsw/mybatis-generator-plugin
        -->
        insert into sales_day_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="bailunSku != null">
                bailun_sku,
            </if>
            <if test="warehouseCode != null">
                warehouse_code,
            </if>
            <if test="bailunSkuWarehouseCode != null">
                bailun_sku_warehouse_code,
            </if>
            <if test="date != null">
                date,
            </if>
            <if test="dateStr != null">
                date_str,
            </if>
            <if test="sales != null">
                sales,
            </if>
            <if test="createDate != null">
                create_date,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="updateDate != null">
                update_date,
            </if>
            <if test="updateUser != null">
                update_user,
            </if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="bailunSku != null">
                #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="bailunSkuWarehouseCode != null">
                #{bailunSkuWarehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="date != null">
                #{date,jdbcType=TIMESTAMP},
            </if>
            <if test="dateStr != null">
                #{dateStr,jdbcType=VARCHAR},
            </if>
            <if test="sales != null">
                #{sales,jdbcType=DECIMAL},
            </if>
            <if test="createDate != null">
                #{createDate,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null">
                #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="updateDate != null">
                #{updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                #{updateUser,jdbcType=VARCHAR},
            </if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=INTEGER},
            </if>
            <if test="bailunSku != null">
                bailun_sku = #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="bailunSkuWarehouseCode != null">
                bailun_sku_warehouse_code = #{bailunSkuWarehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="date != null">
                date = #{date,jdbcType=TIMESTAMP},
            </if>
            <if test="dateStr != null">
                date_str = #{dateStr,jdbcType=VARCHAR},
            </if>
            <if test="sales != null">
                sales = #{sales,jdbcType=DECIMAL},
            </if>
            <if test="createDate != null">
                create_date = #{createDate,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null">
                create_user = #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="updateDate != null">
                update_date = #{updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <insert id="upsert" parameterType="com.bailuntec.domain.entity.SalesDayConfig">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          @project https://github.com/itfsw/mybatis-generator-plugin
        -->
        insert into sales_day_config
        (id, bailun_sku, warehouse_code, bailun_sku_warehouse_code, date, date_str, sales,
        create_date, create_user, update_date, update_user)
        values
        (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR},
        #{bailunSkuWarehouseCode,jdbcType=VARCHAR}, #{date,jdbcType=TIMESTAMP}, #{dateStr,jdbcType=VARCHAR},
        #{sales,jdbcType=DECIMAL}, #{createDate,jdbcType=TIMESTAMP}, #{createUser,jdbcType=VARCHAR},
        #{updateDate,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR})
        on duplicate key update
        id = #{id,jdbcType=INTEGER},
        bailun_sku = #{bailunSku,jdbcType=VARCHAR},
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
        bailun_sku_warehouse_code = #{bailunSkuWarehouseCode,jdbcType=VARCHAR},
        date = #{date,jdbcType=TIMESTAMP},
        date_str = #{dateStr,jdbcType=VARCHAR},
        sales = #{sales,jdbcType=DECIMAL},
        create_date = #{createDate,jdbcType=TIMESTAMP},
        create_user = #{createUser,jdbcType=VARCHAR},
        update_date = #{updateDate,jdbcType=TIMESTAMP},
        update_user = #{updateUser,jdbcType=VARCHAR}
    </insert>

    <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.SalesDayConfigExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          @project https://github.com/itfsw/mybatis-generator-plugin
        -->
        select
        <include refid="Base_Column_List"/>
        from sales_day_config
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        limit 1
    </select>
    <select id="selectByDays" resultType="com.bailuntec.domain.entity.SalesDayConfig">
        SELECT * from week_config t1
        LEFT JOIN sales_day_config t2
        on t1.`week_date` = t2.date and t2.bailun_sku = #{bailunSku} and t2.warehouse_code = #{warehouseCode}
        where t1.week_date in
        <foreach close=")" collection="salesDetailItemList" item="item" open="(" separator=",">
            #{item.date}
        </foreach>
        and t2.id is not null
    </select>

    <select id="selectTarget" resultType="com.bailuntec.domain.entity.SalesDayConfig">
        select DISTINCT bailun_sku,warehouse_code from sales_day_config
        where create_date &gt; '2020-12-15'
    </select>


</mapper>
