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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity" id="tbCfItemSkusMap">
        <result property="id" column="id"/>
        <result property="itemId" column="item_id"/>
        <result property="skuName" column="sku_name"/>
        <result property="skuDesc" column="sku_desc"/>
        <result property="skuPrice" column="sku_price"/>
        <result property="optionIds" column="option_ids"/>
        <result property="skuCount" column="sku_count"/>
        <result property="orderNum" column="order_num"/>
        <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.TbCfItemSkusEntity">
		select
			`id`,
			`item_id`,
			`sku_name`,
			`sku_desc`,
			`sku_price`,
			`option_ids`,
			`sku_count`,
			`order_num`,
			`del_flag`,
			`create_time`,
			`update_time`
		from tb_cf_item_skus
		where id = #{id}
	</select>

    <select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity">
        select
        `id`,
        `item_id`,
        `sku_name`,
        `sku_desc`,
        `sku_price`,
        `option_ids`,
        `sku_count`,
        `order_num`,
        `del_flag`,
        `create_time`,
        `update_time`
        from tb_cf_item_skus
        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 id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>
    <select id="querySkusByItemId" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity">
		select * from tb_cf_item_skus where item_id=#{itemId} order by  order_num asc
   </select>
    <select id="queryByOrderNum" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity">
		 select * from tb_cf_item_skus where order_num=#{orderNum} and item_id=#{itemId}
	 </select>
    <select id="queryTotal" resultType="int">
        select count(*) from tb_cf_item_skus
        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.TbCfItemSkusEntity">
		insert into tb_cf_item_skus(
			`id`,
			`item_id`,
			`sku_name`,
			`sku_desc`,
			`sku_price`,
			`option_ids`,
			`sku_count`,
			`order_num`,
			`del_flag`,
			`create_time`,
			`update_time`)
		values(
			#{id},
			#{itemId},
			#{skuName},
			#{skuDesc},
			#{skuPrice},
			#{optionIds},
			#{skuCount},
			#{orderNum},
			#{delFlag},
			#{createTime},
			#{updateTime})
	</insert>

    <update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity">
        update tb_cf_item_skus
        <set>
            <if test="itemId != null">`item_id` = #{itemId},</if>
            <if test="skuName != null">`sku_name` = #{skuName},</if>
            <if test="skuDesc != null">`sku_desc` = #{skuDesc},</if>
            <if test="skuPrice != null">`sku_price` = #{skuPrice},</if>
            <if test="optionIds != null">`option_ids` = #{optionIds},</if>
            <if test="skuCount != null">`sku_count` = #{skuCount},</if>
            <if test="orderNum != null">`order_num` = #{orderNum},</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 id = #{id}
    </update>
    <update id="changStatus" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity">
        update tb_cf_item_skus set del_flag=0 where item_id=#{itemId}
    </update>
    <update id="changStatusBatch" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfItemSkusEntity">
        update tb_cf_item_skus 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_item_skus where id = #{value}
	</delete>
    <delete id="deleteByItemId">
		delete from tb_cf_item_skus where item_id = #{item_id}
	</delete>
    <delete id="deleteBatch">
        delete from tb_cf_item_skus where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>