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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfCategoryHsEntity" id="tbCfCategoryHsMap">
        <result property="categoryId" column="category_id"/>
        <result property="name" column="name"/>
        <result property="itemNo" column="item_no"/>
        <result property="price" column="price"/>
        <result property="hsCode" column="hs_code"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCategoryHsEntity">
		select
			`category_id`,
			`name`,
			`item_no`,
			`price`,
			`hs_code`
		from tb_cf_category_hs
		where category_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCategoryHsEntity">
		select
    		`category_id`,
    		`name`,
    		`item_no`,
    		`price`,
    		`hs_code`
		from tb_cf_category_hs t1
		WHERE 1=1 and t1.category_id not in (select category_id from tb_cf_exp_cat_rel)
		<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 category_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_category_hs
		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.TbCfCategoryHsEntity" >
		insert into tb_cf_category_hs(
			`name`,
			`item_no`,
			`price`,
			`hs_code`)
		values(
			#{name},
			#{itemNo},
			#{price},
			#{hsCode})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCategoryHsEntity">
		update tb_cf_category_hs 
		<set>
			<if test="name != null">`name` = #{name}, </if>
			<if test="itemNo != null">`item_no` = #{itemNo}, </if>
			<if test="price != null">`price` = #{price}, </if>
			<if test="hsCode != null">`hs_code` = #{hsCode}</if>
		</set>
		where category_id = #{categoryId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_category_hs where category_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_category_hs where category_id in 
		<foreach item="categoryId" collection="array" open="(" separator="," close=")">
			#{categoryId}
		</foreach>
	</delete>

</mapper>