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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfExpTemKeywordEntity" id="tbCfExpTemKeywordMap">
        <result property="id" column="id"/>
        <result property="templateId" column="template_id"/>
        <result property="keyword" column="keyword"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfExpTemKeywordEntity">
		select
			`id`,
			`template_id`,
			`keyword`
		from tb_cf_exp_tem_keyword
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfExpTemKeywordEntity">
		select
    		`id`,
    		`template_id`,
    		`keyword`
		from tb_cf_exp_tem_keyword
		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="queryTotal" resultType="int">
		select count(*) from tb_cf_exp_tem_keyword
		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.TbCfExpTemKeywordEntity" useGeneratedKeys="true" keyProperty="id">
		insert into tb_cf_exp_tem_keyword(
			`template_id`,
			`keyword`)
		values(
			#{templateId},
			#{keyword})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfExpTemKeywordEntity">
		update tb_cf_exp_tem_keyword 
		<set>
			<if test="templateId != null">`template_id` = #{templateId}, </if>
			<if test="keyword != null">`keyword` = #{keyword}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from tb_cf_exp_tem_keyword where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_exp_tem_keyword where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

    <!--根据keyword获取运费模板-->
	<select id="getTemplateByKeyword"  resultType="com.diaoyun.zion.chinafrica.entity.TbCfExpressTemplateEntity">
        select t2.* from tb_cf_exp_tem_keyword t1,tb_cf_express_template t2 where t1.keyword=#{keyword}
        and t1.template_id=t2.template_id
    </select>

</mapper>