<?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.example.mapper.SaleStatementMapper">

    <sql id="Base_Column_List">
        id,shop_id,count,time_over,product_id,amount
    </sql>

    <select id="selectAll" resultType="com.example.entity.SaleStatement">
        select
        <include refid="Base_Column_List" />
        from sale_statement
        <where>
            <if test="id != null"> and id = #{id}</if>
            <if test="shopId != null"> and shop_id = #{shopId}</if>
            <if test="count != null"> and count = #{count}</if>
            <if test="timeOver != null"> and time_over like concat('%', #{timeOver}, '%')</if>
            <if test="productId != null"> and product_id = #{productId}</if>
            <if test="amount != null"> and amount = #{amount}</if>
        </where>
        order by id desc
    </select>

    <select id="selectById" resultType="com.example.entity.SaleStatement">
        select
        <include refid="Base_Column_List" />
        from sale_statement
        where id = #{id}
    </select>

    <delete id="deleteById">
        delete from sale_statement
        where  id = #{id}
    </delete>

    <insert id="insert" parameterType="com.example.entity.SaleStatement" useGeneratedKeys="true">
        insert into sale_statement
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="shopId != null">shop_id,</if>
            <if test="count != null">count,</if>
            <if test="timeOver != null">time_over,</if>
            <if test="productId != null">product_id,</if>
            <if test="amount != null">amount,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="shopId != null">#{shopId},</if>
            <if test="count != null">#{count},</if>
            <if test="timeOver != null">#{timeOver},</if>
            <if test="productId != null">#{productId},</if>
            <if test="amount != null">#{amount},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.example.entity.SaleStatement">
        update sale_statement
        <set>
            <if test="shopId != null">
                shop_id = #{shopId},
            </if>
            <if test="count != null">
                count = #{count},
            </if>
            <if test="timeOver != null">
                time_over = #{timeOver},
            </if>
            <if test="productId != null">
                product_id = #{productId},
            </if>
            <if test="amount != null">
                amount = #{amount},
            </if>
        </set>
        where id = #{id} 
    </update>

</mapper>