<?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.TbCfItemOrderRDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfItemOrderREntity" id="tbCfItemOrderRMap">
        <result property="orderItemId" column="order_item_id"/>
        <result property="itemId" column="item_id"/>
        <result property="orderId" column="order_id"/>
        <result property="enableFlag" column="enable_flag"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemOrderREntity">
		select
			`order_item_id`,
			`item_id`,
			`order_id`,
			`enable_flag`
		from tb_cf_item_order_r
		where order_item_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemOrderREntity">
		select
    		`order_item_id`,
    		`item_id`,
    		`order_id`,
    		`enable_flag`
		from tb_cf_item_order_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 order_item_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_item_order_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.TbCfItemOrderREntity">
		insert into tb_cf_item_order_r(
			`order_item_id`,
			`item_id`,
			`order_id`,
			`enable_flag`)
		values(
			#{orderItemId},
			#{itemId},
			#{orderId},
			#{enableFlag})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfItemOrderREntity">
		update tb_cf_item_order_r 
		<set>
			<if test="itemId != null">`item_id` = #{itemId}, </if>
			<if test="orderId != null">`order_id` = #{orderId}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}</if>
		</set>
		where order_item_id = #{orderItemId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_item_order_r where order_item_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_item_order_r where order_item_id in 
		<foreach item="orderItemId" collection="array" open="(" separator="," close=")">
			#{orderItemId}
		</foreach>
	</delete>

    <!--批量保存-->
	<insert id="saveBatch" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfItemOrderREntity">
        insert into tb_cf_item_order_r(
        `order_item_id`,
        `item_id`,
        `order_id`,
        `enable_flag`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.orderItemId},
            #{item.itemId},
            #{item.orderId},
            #{item.enableFlag}
            )
        </foreach>

    </insert>

</mapper>