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

	<resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfExpressTemplateEntity" id="tbCfExpressTemplateMap">
		<result property="templateId" column="template_id"/>
		<result property="templateTitle" column="template_title"/>
		<result property="itemCategoryId" column="item_category_id"/>
		<result property="continuationFee" column="continuation_fee"/>
		<result property="expressFee" column="express_fee"/>
		<result property="countryCode" column="country_code"/>
		<result property="createTime" column="create_time"/>
	</resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfExpressTemplateEntity">
		select
			`template_id`,
			`template_title`,
			`item_category_id`,
			`express_fee`,
			`continuation_fee`,
			`country_code`,
			`create_time`
		from tb_cf_express_template
		where template_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfExpressTemplateEntity">
		select
		`template_id`,
		`template_title`,
		`item_category_id`,
		`express_fee`,
		`continuation_fee`,
		`country_code`,
		`create_time`
		from tb_cf_express_template
		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 template_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_express_template
		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.TbCfExpressTemplateEntity">
		insert into tb_cf_express_template(
			`template_id`,
			`template_title`,
			`item_category_id`,
			`express_fee`,
			`continuation_fee`,
			`country_code`,
			`create_time`)
		values(
			#{templateId},
			#{templateTitle},
			#{itemCategoryId},
			#{expressFee},
			#{continuationFee},
			#{countryCode},
			#{createTime})
	</insert>

	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfExpressTemplateEntity">
		update tb_cf_express_template
		<set>
			<if test="templateTitle != null">`template_title` = #{templateTitle}, </if>
			<if test="itemCategoryId != null">`item_category_id` = #{itemCategoryId}, </if>
			<if test="expressFee != null">`express_fee` = #{expressFee}, </if>
			<if test="`continuation_fee`, != null">`continuation_fee` = #{`continuation_fee`,}, </if>
			<if test="countryCode != null">`country_code` = #{countryCode}, </if>
			<if test="createTime != null">`create_time` = #{createTime}</if>
		</set>
		where template_id = #{templateId}
	</update>

	<delete id="delete">
		delete from tb_cf_express_template where template_id = #{value}
	</delete>

	<delete id="deleteBatch">
		delete from tb_cf_express_template where template_id in
		<foreach item="templateId" collection="array" open="(" separator="," close=")">
			#{templateId}
		</foreach>
	</delete>
	<select id="getDescriptionById" resultType="com.diaoyun.zion.chinafrica.vo.ExpressTemplateVo">
		select
			t.template_id descriptionId,
			t.template_title descriptionName,
			t.item_category_id,
			t.express_fee,
			t.country_code,
			t.create_time
		from tb_cf_express_template t
		where t.template_id = #{descriptionId}
	</select>
</mapper>