<?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"/>
    </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`
		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`
		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`)
		values(
			#{cartRecordId},
			#{itemId},
			#{userId},
			#{checkFlag},
			#{enableFlag},
			#{createTime})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity">
		update tb_cf_cart_record_r 
		<set>
			<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>

</mapper>