<?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.diaoyun.zion.chinafrica.dao.TbCfCartRecordRDao">

	<resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity" id="tbCfCartRecordRMap">
		<result property="cartRecordId" column="cart_record_id"/>
		<result property="itemId" column="item_id"/>
		<result property="userId" column="user_id"/>
		<result property="checkFlag" column="check_flag"/>
		<result property="enableFlag" column="enable_flag"/>
		<result property="createTime" column="create_time"/>
		<result property="sourceItemId" column="source_item_id"/>
		<result property="itemSku" column="item_sku"/>
		<result property="itemNum" column="item_num"/>
	</resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		select
			`cart_record_id`,
			`item_id`,
			`user_id`,
			`check_flag`,
			`enable_flag`,
			`create_time`,
			`item_num`,
			`item_sku`,
			`source_item_id`
		from tb_cf_cart_record_r
		where cart_record_id = #{id}
	</select>
	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		select
		`cart_record_id`,
		`item_id`,
		`user_id`,
		`check_flag`,
		`enable_flag`,
		`create_time`,
		`item_num`,
		`item_sku`,
		`source_item_id`
		from tb_cf_cart_record_r
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
		<choose>
			<when test="sidx != null and sidx.trim() != ''">
				order by ${sidx} ${order}
			</when>
			<otherwise>
				order by cart_record_id desc
			</otherwise>
		</choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>

	<select id="queryTotal" resultType="int">
		select count(*) from tb_cf_cart_record_r
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
	</select>

	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		insert into tb_cf_cart_record_r(
			`cart_record_id`,
			`item_id`,
			`user_id`,
			`check_flag`,
			`enable_flag`,
			`create_time`,
			`item_num`,
			`item_sku`,
			`source_item_id`)
		values(
			#{cartRecordId},
			#{itemId},
			#{userId},
			#{checkFlag},
			#{enableFlag},
			#{createTime},
			#{itemNum},
			#{itemSku},
			#{sourceItemId})

	</insert>

	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		update tb_cf_cart_record_r
		<set>
			<if test="itemNum != null">`item_num` = #{itemNum}, </if>
			<if test="sourceItemId != null">`source_item_id` = #{sourceItemId}, </if>
			<if test="itemSku != null">`item_sku` = #{itemSku}, </if>
			<if test="itemId != null">`item_id` = #{itemId}, </if>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="checkFlag != null">`check_flag` = #{checkFlag}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}</if>
		</set>
		where cart_record_id = #{cartRecordId}
	</update>

	<delete id="delete">
		delete from tb_cf_cart_record_r where cart_record_id = #{value}
	</delete>

	<delete id="deleteBatch">
		delete from tb_cf_cart_record_r where cart_record_id in
		<foreach item="cartRecordId" collection="array" open="(" separator="," close=")">
			#{cartRecordId}
		</foreach>
	</delete>

	<!--伪删除-->
	<delete id="deleteItems">
		update tb_cf_cart_record_r set enable_flag=0 where cart_record_id in
		<foreach item="cartRecordId" collection="array" open="(" separator="," close=")">
			#{cartRecordId}
		</foreach>
	</delete>
	<select id="querySkuAndUrl" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		select
			`cart_record_id`,
			`item_id`,
			`user_id`,
			`check_flag`,
			`enable_flag`,
			`create_time`,
			`source_item_id`,
			`item_sku`,
			`item_num`
		from tb_cf_cart_record_r
		where  item_sku =#{itemSku} and source_item_id=#{sourceItemId}  and enable_flag=1
	</select>
	<select id="queryByItemId" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		select `cart_record_id`,
			`item_id`,
			`user_id`,
			`check_flag`,
			`enable_flag`,
			`create_time`,
			`source_item_id`,
			`item_sku`,
			`item_num` from tb_cf_cart_record_r where item_id =#{itemId}  and enable_flag=1
	</select>
</mapper>