<?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.platform.dao.RelatedGoodsDao">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.platform.entity.RelatedGoodsEntity" id="relatedGoodsMap">
        <result property="id" column="id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="relatedGoodsId" column="related_goods_id"/>
    </resultMap>

	<select id="queryObject" resultType="com.platform.entity.RelatedGoodsEntity">
		select * from nideshop_related_goods where id = #{value}
	</select>

	<select id="queryList" resultType="com.platform.entity.RelatedGoodsEntity">
		select * from nideshop_related_goods
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from nideshop_related_goods 
	</select>
	 
	<insert id="save" parameterType="com.platform.entity.RelatedGoodsEntity" useGeneratedKeys="true" keyProperty="id">
		insert into nideshop_related_goods
		(
			`goods_id`, 
			`related_goods_id`
		)
		values
		(
			#{goodsId}, 
			#{relatedGoodsId}
		)
	</insert>
	 
	<update id="update" parameterType="com.platform.entity.RelatedGoodsEntity">
		update nideshop_related_goods 
		<set>
			<if test="goodsId != null">`goods_id` = #{goodsId}, </if>
			<if test="relatedGoodsId != null">`related_goods_id` = #{relatedGoodsId}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from nideshop_related_goods where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from nideshop_related_goods where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>