UfoSuggestWordMapper.xml 6.68 KB
<?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.yoho.search.dal.UfoSuggestWordMapper" >
  
    <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.UfoSuggestWord" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="keyword" property="keyword" jdbcType="VARCHAR" />
        <result column="count" property="count" jdbcType="INTEGER" />
        <result column="weight" property="weight" jdbcType="INTEGER" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="status" property="status" jdbcType="INTEGER" />
    </resultMap>
  
    <sql id="Base_Column_List" >
    id, keyword, count, weight, type, status
    </sql>
  
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from ufo_suggest_word
    where id = #{id,jdbcType=INTEGER}
    </select>
  
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from ufo_suggest_word
    where id = #{id,jdbcType=INTEGER}
    </delete>
  
    <insert id="insert" parameterType="com.yoho.search.dal.model.UfoSuggestWord" >
    insert into ufo_suggest_word (id, keyword, count, 
      weight, type, status
      )
    values (#{id,jdbcType=INTEGER}, #{keyword,jdbcType=VARCHAR}, #{count,jdbcType=INTEGER}, 
      #{weight,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}
      )
    </insert>
    
    <insert id="insertSelective" parameterType="com.yoho.search.dal.model.UfoSuggestWord" >
    insert into ufo_suggest_word
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="keyword != null" >
        keyword,
      </if>
      <if test="count != null" >
        count,
      </if>
      <if test="weight != null" >
        weight,
      </if>
      <if test="type != null" >
        type,
      </if>
      <if test="status != null" >
        status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="keyword != null" >
        #{keyword,jdbcType=VARCHAR},
      </if>
      <if test="count != null" >
        #{count,jdbcType=INTEGER},
      </if>
      <if test="weight != null" >
        #{weight,jdbcType=INTEGER},
      </if>
      <if test="type != null" >
        #{type,jdbcType=INTEGER},
      </if>
      <if test="status != null" >
        #{status,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  
    <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.UfoSuggestWord" >
    update ufo_suggest_word
    <set >
      <if test="keyword != null" >
        keyword = #{keyword,jdbcType=VARCHAR},
      </if>
      <if test="count != null" >
        count = #{count,jdbcType=INTEGER},
      </if>
      <if test="weight != null" >
        weight = #{weight,jdbcType=INTEGER},
      </if>
      <if test="type != null" >
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
 
  <update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.UfoSuggestWord" >
    update ufo_suggest_word
    set keyword = #{keyword,jdbcType=VARCHAR},
      count = #{count,jdbcType=INTEGER},
      weight = #{weight,jdbcType=INTEGER},
      type = #{type,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

    <insert id="insertBatch" parameterType="java.util.List" timeout="20000">
        insert ignore into ufo_suggest_word (keyword, weight, count, type)
        values
        <foreach collection="list" item="item" index="index"
                 separator=",">
            (#{item.keyword, jdbcType=VARCHAR},
            #{item.weight, jdbcType=INTEGER},
            #{item.count, jdbcType=INTEGER},
            #{item.type, jdbcType=INTEGER})
        </foreach>
    </insert>

    <update id="updateBatch" parameterType="java.util.List" timeout="20000">
        update ufo_suggest_word
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="count =case" suffix="end,">
                <foreach collection="suggestWordList" item="item" index="index">
                    when id = #{item.id,jdbcType=INTEGER} then #{item.count,jdbcType=INTEGER}
                </foreach>
            </trim>
            <trim prefix="weight =case" suffix="end,">
                <foreach collection="suggestWordList" item="item" index="index">
                    when id = #{item.id,jdbcType=INTEGER} then #{item.weight,jdbcType=DECIMAL}
                </foreach>
            </trim>
        </trim>
        where
        <foreach collection="suggestWordList" separator="or" item="item" index="index" >
            id = #{item.id,jdbcType=INTEGER}
        </foreach>
    </update>
    
    <update id="updateStatusByPrimaryKey" timeout="20000">
		update ufo_suggest_word set status = #{status,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
	</update>

    <delete id="deleteBatch" parameterType="java.util.List" timeout="20000">
        DELETE FROM ufo_suggest_word WHERE ID in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <delete id="deleteAllValidKeywords" timeout="20000">
		DELETE FROM ufo_suggest_word WHERE status=1 and type!=0
	</delete>

    <select id="selectTotalCount" resultType="java.lang.Integer" timeout="20000">
		SELECT count(1) FROM ufo_suggest_word
	</select>
    
    <select id="selectCountByWordType" resultType="java.lang.Integer" timeout="20000">
		SELECT count(1) FROM ufo_suggest_word where type = #{type,jdbcType=INTEGER}
	</select>
    
    <select id="selectPageList" resultMap="BaseResultMap" timeout="20000">
        select
        <include refid="Base_Column_List" />
        from ufo_suggest_word limit #{offset},#{pageSize}
    </select>
    
    <select id="selectByKeywordTypes" resultMap="BaseResultMap" timeout="20000">
        select
        <include refid="Base_Column_List" />
        from ufo_suggest_word where type in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    
    <select id="selectByKeyword" resultMap="BaseResultMap" timeout="20000">
        select
        <include refid="Base_Column_List" />
        from ufo_suggest_word where keyword = #{keyword,jdbcType=VARCHAR}
        limit 1
    </select>

</mapper>