SuggestWordDefMapper.xml 3.54 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.SuggestWordDefMapper">
	<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SuggestWordDef">
		<id column="id" property="id" jdbcType="INTEGER" />
		<result column="keyword" property="keyword" jdbcType="VARCHAR" />
		<result column="weight" property="weight" jdbcType="INTEGER" />
		<result column="count" property="count" jdbcType="INTEGER" />
		<result column="count_for_blk" property="countForBlk" jdbcType="INTEGER" />
		<result column="count_for_global" property="countForGlobal" jdbcType="INTEGER" />
		<result column="type" property="type" jdbcType="INTEGER" />
		<result column="status" property="status" jdbcType="INTEGER" />
	</resultMap>
	<sql id="Base_Column_List">
		id, keyword, weight, count, count_for_blk, count_for_global, type, status
	</sql>

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

	<update id="updateBatch" parameterType="java.util.List">
		update suggest_word_def
		<trim prefix="set" suffixOverrides=",">
			<trim prefix="count =case" suffix="end,">
				<foreach collection="suggestWordDefList" item="item" index="index">
					when id = #{item.id,jdbcType=INTEGER} then #{item.count,jdbcType=INTEGER}
				</foreach>
			</trim>
			<trim prefix="count_for_blk =case" suffix="end,">
				<foreach collection="suggestWordDefList" item="item" index="index">
					when id = #{item.id,jdbcType=INTEGER} then #{item.countForBlk,jdbcType=INTEGER}
				</foreach>
			</trim>
			<trim prefix="count_for_global =case" suffix="end,">
				<foreach collection="suggestWordDefList" item="item" index="index">
					when id = #{item.id,jdbcType=INTEGER} then #{item.countForGlobal,jdbcType=INTEGER}
				</foreach>
			</trim>
			<trim prefix="weight =case" suffix="end,">
				<foreach collection="suggestWordDefList" item="item" index="index">
					when id = #{item.id,jdbcType=INTEGER} then #{item.weight,jdbcType=DECIMAL}
				</foreach>
			</trim>
		</trim>
		where
		<foreach collection="suggestWordDefList" separator="or" item="item" index="index" >
			id = #{item.id,jdbcType=INTEGER}
		</foreach>
	</update>

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

	<select id="selectTotalCount" resultType="java.lang.Integer" timeout="20000">
		SELECT count(1) FROM suggest_word_def
	</select>
	<select id="selectCountByWordType" resultType="java.lang.Integer" timeout="20000">
		SELECT count(1) FROM suggest_word_def where type = #{type,jdbcType=INTEGER}
	</select>
	<select id="selectPageList" resultMap="BaseResultMap" timeout="20000">
		select
		<include refid="Base_Column_List" />
		from suggest_word_def limit #{offset},#{pageSize}
	</select>
	<select id="selectByKeywordType" resultMap="BaseResultMap" timeout="20000">
		select
		<include refid="Base_Column_List" />
		from suggest_word_def where type = #{type} limit #{offset},#{pageSize}
	</select>
</mapper>