<?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.zm.order.tool.server.dao.RecommendItemDao">
    <resultMap id="ResultMap" type="com.zm.order.tool.server.model.RecommendItem">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
		<result column="user_id" jdbcType="BIGINT" property="userId"/>
		<result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
		<result column="store_id" jdbcType="BIGINT" property="storeId"/>
		<result column="item_name" jdbcType="VARCHAR" property="itemName"/>
		<result column="item_id" jdbcType="VARCHAR" property="itemId"/>
		<result column="item_image" jdbcType="VARCHAR" property="itemImage"/>
		<result column="features" jdbcType="VARCHAR" property="features"/>
		<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
		<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
		<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
	</resultMap>

	<sql id="tb">
        comment_recommend_items
    </sql>

    <sql id="cols_all">
        id,
		order_no,
		user_id,
		seller_id,
		store_id,
		item_name,
		item_id,
		item_image,
		features,
		created_at,
		updated_at,
		is_deleted
    </sql>

    <sql id="values">
    	#{id,jdbcType=BIGINT},
		#{orderNo,jdbcType=VARCHAR},
		#{userId,jdbcType=BIGINT},
		#{sellerId,jdbcType=BIGINT},
		#{storeId,jdbcType=BIGINT},
		#{itemName,jdbcType=VARCHAR},
		#{itemId,jdbcType=VARCHAR},
		#{itemImage,jdbcType=VARCHAR},
		#{features,jdbcType=LONGVARCHAR},
		now(),
		now(),
		0
    </sql>

    <insert id="insert" parameterType="com.zm.order.tool.server.model.RecommendItem"
                        keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="tb"/>
        (<include refid="cols_all"/>)
        values
        (<include refid="values"/>)
    </insert>

    <select id="selectByOrderNo" parameterType="map" resultMap="ResultMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
			order_no = #{orderNo} and seller_id = #{sellerId}
        </where>
    </select>

    <update id="update" parameterType="com.zm.order.tool.server.model.RecommendItem">
        UPDATE
        <include refid="tb"/>
        <set>
			<if test="itemName != null">
				item_name = #{itemName,jdbcType=VARCHAR},
			</if>
			<if test="itemId != null">
				item_id = #{itemId,jdbcType=VARCHAR},
			</if>
			<if test="itemImage != null">
				item_image = #{itemImage,jdbcType=VARCHAR},
			</if>
			<if test="features != null">
				features = #{features,jdbcType=VARCHAR},
			</if>
			updated_at = now()
        </set>
        where id = #{id} and seller_id = #{sellerId}
    </update>

	<insert id="insertList" parameterType="list">
		insert into
		<include refid="tb"/>
		(<include refid="cols_all"/>)
		values
		<foreach collection="list" item="record" index="index" separator=",">
			(
			#{record.id,jdbcType=BIGINT},
			#{record.orderNo,jdbcType=VARCHAR},
			#{record.userId,jdbcType=BIGINT},
			#{record.sellerId,jdbcType=BIGINT},
			#{record.storeId,jdbcType=BIGINT},
			#{record.itemName,jdbcType=VARCHAR},
			#{record.itemId,jdbcType=VARCHAR},
			#{record.itemImage,jdbcType=VARCHAR},
			#{record.features,jdbcType=LONGVARCHAR},
			now(),
			now(),
			0
			)
		</foreach>
	</insert>

</mapper>