<?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.cku.dao.CkuMatchRuleMapper" >
  <resultMap id="BaseResultMap" type="com.cku.model.CkuMatchRule" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="rule_name" property="ruleName" jdbcType="VARCHAR" />
    <result column="rule_info" property="ruleInfo" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, rule_name, rule_info, create_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from cku_match_rule
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from cku_match_rule
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.cku.model.CkuMatchRule" >
    insert into cku_match_rule (id, rule_name, rule_info, 
      create_time)
    values (#{id,jdbcType=INTEGER}, #{ruleName,jdbcType=VARCHAR}, #{ruleInfo,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.cku.model.CkuMatchRule" >
    insert into cku_match_rule
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="ruleName != null" >
        rule_name,
      </if>
      <if test="ruleInfo != null" >
        rule_info,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="ruleName != null" >
        #{ruleName,jdbcType=VARCHAR},
      </if>
      <if test="ruleInfo != null" >
        #{ruleInfo,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.cku.model.CkuMatchRule" >
    update cku_match_rule
    <set >
      <if test="ruleName != null" >
        rule_name = #{ruleName,jdbcType=VARCHAR},
      </if>
      <if test="ruleInfo != null" >
        rule_info = #{ruleInfo,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.cku.model.CkuMatchRule" >
    update cku_match_rule
    set rule_name = #{ruleName,jdbcType=VARCHAR},
      rule_info = #{ruleInfo,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--********************************************************* 自定义********************************************* -->
  <select id="getAll" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select <include refid="Base_Column_List" />
    from cku_match_rule
  </select>
  
   <select id="getList" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
	SELECT TOP ${limit} * FROM cku_match_rule 
	WHERE ID NOT IN(
	SELECT TOP ${count} ID FROM cku_match_rule 
	where 1= 1 
	<if test="ruleName != '' and  ruleName != null" >
		and rule_name like '%${ruleName}%'
    </if>
	<if test="ruleInfo != '' and  ruleInfo != null" >
		and rule_info like '%${ruleInfo}%'
    </if>
	ORDER BY ID DESC
	) 
	<if test="ruleName != '' and  ruleName != null" >
		and rule_name like '%${ruleName}%'
    </if>
	<if test="ruleInfo != '' and  ruleInfo != null" >
		and rule_info like '%${ruleInfo}%'
    </if>
	ORDER BY ID DESC  
  </select>
  <select id="getCount" resultType="java.lang.Long" parameterType="java.lang.Integer" >
    SELECT
		count(*)
	FROM cku_match_rule 
	WHERE 1=1 
	<if test="ruleName != '' and  ruleName != null" >
		and rule_name like '%${ruleName}%'
    </if>
	<if test="ruleInfo != '' and  ruleInfo != null" >
		and rule_info like '%${ruleInfo}%'
    </if>
  </select>
</mapper>