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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity" id="tbCfOptionMap">
        <result property="optionId" column="option_id"/>
        <result property="optionName" column="option_name"/>
        <result property="optiionSpecies" column="optiion_species"/>
        <result property="itemId" column="item_id"/>
        <result property="cid" column="cid"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
		select
			`option_id`,
			`option_name`,
			`optiion_species`,
			`item_id`,
			`cid`,
			`del_flag`,
			`create_time`,
			`update_time`
		from tb_cf_option
		where option_id = #{id}
	</select>

    <select id="queryByItemId" resultType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
         select
			`option_id`,
			`option_name`,
			`optiion_species`,
			`item_id`,
			`cid`,
			`del_flag`,
			`create_time`,
			`update_time`
		from tb_cf_option where item_id=#{itemId}
    </select>

    <select id="queryByCid" resultType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
         select
			`option_id`,
			`option_name`,
			`optiion_species`,
			`item_id`,
			`cid`,
			`del_flag`,
			`create_time`,
			`update_time`
		from tb_cf_option where cid=#{cid}
    </select>
    <select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
        select
        `option_id`,
        `option_name`,
        `optiion_species`,
        `item_id`,
        `cid`,
        `del_flag`,
        `create_time`,
        `update_time`
        from tb_cf_option
        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 option_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_option
        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.TbCfOptionEntity">
		insert into tb_cf_option(
			`option_id`,
			`option_name`,
			`optiion_species`,
			`item_id`,
			`cid`,
			`del_flag`,
			`create_time`,
			`update_time`)
		values(
			#{optionId},
			#{optionName},
			#{optiionSpecies},
			#{itemId},
			#{cid},
			#{delFlag},
			#{createTime},
			#{updateTime})
	</insert>

    <update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
        update tb_cf_option
        <set>
            <if test="optionName != null">`option_name` = #{optionName},</if>
            <if test="optiionSpecies != null">`optiion_species` = #{optiionSpecies},</if>
            <if test="itemId != null">`item_id` = #{itemId},</if>
            <if test="cid != null">`cid` = #{cid},</if>
            <if test="delFlag != null">`del_flag` = #{delFlag},</if>
            <if test="createTime != null">`create_time` = #{createTime},</if>
            <if test="updateTime != null">`update_time` = #{updateTime}</if>
        </set>
        where option_id = #{optionId}
    </update>
    <update id="changStatus" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
        update tb_cf_option set del_flag=0 where item_id=#{itemId}
    </update>
    <update id="changStatusBatch" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfOptionEntity">
        update tb_cf_option set del_flag=0 where item_id in
        <foreach item="itemId" collection="array" open="(" separator="," close=")">
            #{itemId}
        </foreach>
    </update>
    <delete id="delete">
		delete from tb_cf_option where option_id = #{value}
	</delete>

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

    <delete id="deleteByItemId">
        delete from tb_cf_option where item_id =#{itemId}
    </delete>
</mapper>