<?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.cool.store.mapper.ShopDeliveryPlanItemMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.plan.ShopDeliveryPlanItemDO">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="plan_id" property="planId" jdbcType="BIGINT"/>
        <result column="item_type" property="itemType" jdbcType="INTEGER"/>
        <result column="delivery_status" property="deliveryStatus" jdbcType="INTEGER"/>
        <result column="delivery_remark" property="deliveryRemark" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, plan_id, item_type, delivery_status, delivery_remark, create_time, update_time
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zxjp_shop_delivery_plan_item
        WHERE id = #{id}
    </select>

    <select id="listByPlanId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zxjp_shop_delivery_plan_item
        WHERE plan_id = #{planId}
        ORDER BY id ASC
    </select>

    <select id="getByPlanIdAndItemType" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zxjp_shop_delivery_plan_item
        WHERE plan_id = #{planId} AND item_type = #{itemType}
        LIMIT 1
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="com.cool.store.entity.plan.ShopDeliveryPlanItemDO">
        INSERT INTO zxjp_shop_delivery_plan_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planId != null">plan_id,</if>
            <if test="itemType != null">item_type,</if>
            <if test="deliveryStatus != null">delivery_status,</if>
            <if test="deliveryRemark != null">delivery_remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="planId != null">#{planId,jdbcType=BIGINT},</if>
            <if test="itemType != null">#{itemType,jdbcType=INTEGER},</if>
            <if test="deliveryStatus != null">#{deliveryStatus,jdbcType=INTEGER},</if>
            <if test="deliveryRemark != null">#{deliveryRemark,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>

    <insert id="batchInsert">
        INSERT INTO zxjp_shop_delivery_plan_item
        (plan_id, item_type, delivery_status, delivery_remark, create_time, update_time)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.planId}, #{item.itemType}, #{item.deliveryStatus}, #{item.deliveryRemark}, now(), now())
        </foreach>
    </insert>

    <update id="update" parameterType="com.cool.store.entity.plan.ShopDeliveryPlanItemDO">
        UPDATE zxjp_shop_delivery_plan_item
        <set>
            <if test="planId != null">plan_id = #{planId,jdbcType=BIGINT},</if>
            <if test="itemType != null">item_type = #{itemType,jdbcType=INTEGER},</if>
            <if test="deliveryStatus != null">delivery_status = #{deliveryStatus,jdbcType=INTEGER},</if>
            <if test="deliveryRemark != null">delivery_remark = #{deliveryRemark,jdbcType=VARCHAR},</if>
            <if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        WHERE id = #{id,jdbcType=BIGINT}
    </update>

    <delete id="deleteById">
        DELETE FROM zxjp_shop_delivery_plan_item
        WHERE id = #{id}
    </delete>

    <delete id="deleteByPlanId">
        DELETE FROM zxjp_shop_delivery_plan_item
        WHERE plan_id = #{planId}
    </delete>

</mapper>