<?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="lingtao.net.dao.CustomerTrainMapper">

	<select id="getCustomerTrainContents" parameterType="CustomerTrainContent"
		resultType="CustomerTrainContent">
		SELECT
		*
		FROM
		t_customer_train_content
		<where>
			<if test="type != null and type != ''">
				and type = #{type}
			</if>
			<if test="proType != null and proType != ''">
				and pro_type = #{proType}
			</if>
			<if test="kind != null and kind != ''">
				and kind = #{kind}
			</if>
		</where>
		ORDER BY sort
	</select>

	<insert id="addCustomerTrainContent" parameterType="CustomerTrainContent">
		insert into t_customer_train_content
		(pro_type,kind,sort,content,type,create_by,create_date)
		values
		(#{proType},#{kind},#{sort},#{content},#{type},#{createBy},now())
	</insert>
	
	<update id="updateCustomerTrainContentById">
		update t_customer_train_content
		<set>
			<if test="proType != null and proType != ''">
				pro_type = #{proType},
			</if>
			<if test="kind != null and kind != ''">
				kind = #{kind},
			</if>
			<if test="content != null and content != ''">
				content = #{content,jdbcType=VARCHAR},
			</if>
			type = #{type},
			update_by = #{updateBy},
			update_date = now(),
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>
	
	<delete id="deleteCustomerTrainContentById" parameterType="java.lang.Integer">
    	delete from t_customer_train_content
    	where id = #{id,jdbcType=INTEGER}
  </delete>
  
  <!-- 产品种类字典 -->
  <select id="getCustomerTrainProTypes" parameterType="CustomerTrainProType"
		resultType="CustomerTrainProType">
		SELECT
		*
		FROM
		t_customer_train_pro_type
		<where>
			<if test="type != null and type != ''">
				and type = #{type}
			</if>
			<if test="proType != null and proType != ''">
				and pro_type = #{proType}
			</if>
		</where>
		ORDER BY sort
	</select>

	<insert id="addCustomerTrainProType" parameterType="CustomerTrainProType">
		insert into t_customer_train_pro_type
		(pro_type,remark,sort,type,create_by,create_date)
		values
		(#{proType},#{remark},#{sort},#{type},#{createBy},now())
	</insert>
	
	<update id="updateCustomerTrainProTypeById">
		update t_customer_train_pro_type
		set
		pro_type 	= #{proType},
		remark 		= #{remark},
		sort 		= #{sort},
		type 		= #{type},
		update_by 	= #{updateBy},
		update_date = now()
		where id 	= #{id,jdbcType=INTEGER}
	</update>
	
	<delete id="deleteCustomerTrainProTypeById" parameterType="java.lang.Integer">
    	delete from t_customer_train_pro_type
    	where id = #{id,jdbcType=INTEGER}
  </delete>
  
  <!-- 产品类型字典 -->
  <select id="getCustomerTrainKindLabelsByProType" parameterType="CustomerTrainKindLabel"
		resultType="CustomerTrainKindLabel">
		SELECT
		*
		FROM
		t_customer_train_kind_label
		where pro_type = #{proType}
		and type = #{type}
		ORDER BY sort
	</select>

	<insert id="addCustomerTrainKindLabel" parameterType="CustomerTrainKindLabel">
		insert into t_customer_train_kind_label
		(pro_type,kind_label,remark,sort,type,create_by,create_date)
		values
		(#{proType},#{kindLabel},#{remark},#{sort},#{type},#{createBy},now())
	</insert>
	
	<update id="updateCustomerTrainKindLabelById">
		update t_customer_train_kind_label
		set
		kind_label 	= #{kindLabel},
		remark 		= #{remark},
		sort 		= #{sort},
		type 		= #{type},
		update_by 	= #{updateBy},
		update_date = now()
		where id 	= #{id,jdbcType=INTEGER}
	</update>
	
	<delete id="deleteCustomerTrainKindLabelById" parameterType="java.lang.Integer">
    	delete from t_customer_train_kind_label
    	where id = #{id,jdbcType=INTEGER}
  </delete>
  
</mapper>