InBoxMapper.xml 4.88 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.message.dal.InBoxMapper">

    <resultMap id="BaseResultMap" type="com.yoho.message.dal.model.InBox" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="uid" property="uid" jdbcType="INTEGER" />
        <result column="send_uid" property="sendUid" jdbcType="INTEGER" />
        <result column="title" property="title" jdbcType="VARCHAR" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="is_read" property="isRead" jdbcType="CHAR" />
        <result column="create_time" property="createTime" jdbcType="INTEGER" />
        <result column="read_time" property="readTime" jdbcType="INTEGER" />
        <result column="verify_key" property="verifyKey" jdbcType="INTEGER" />
        <result column="is_del" property="isDel" jdbcType="CHAR" />
        <result column="content" property="content" jdbcType="LONGVARCHAR" />
        <result column="business_type" property="businessType" jdbcType="INTEGER" />
    </resultMap>

    <sql id="Base_Column_List" >
        id, uid, send_uid, title, type, is_read, create_time, read_time, verify_key, is_del,content, business_type
    </sql>
    <insert id="insertBatch">
    	INSERT INTO ${tableName} (uid,send_uid,title,content,type,is_read,create_time,read_time,verify_key,is_del,business_type)
    	values 
    	<foreach collection="list" item="item" index="index" separator="," >  
        	(#{item.uid}, #{item.sendUid},#{item.title},#{item.content},#{item.type},#{item.isRead}, #{item.createTime}, #{item.readTime}, #{item.verifyKey}, #{item.isDel}, #{item.businessType})
    	</foreach>
    </insert>
    <insert id="insertInbox">
        <selectKey keyProperty="id" resultType="int" order="AFTER">

            select LAST_INSERT_ID()

        </selectKey>
        INSERT INTO ${tableName} (id,uid,send_uid,title,content,type,is_read,create_time,read_time,verify_key,is_del)
        values
        (#{inBox.id},#{inBox.uid},#{inBox.sendUid},#{inBox.title},#{inBox.content},#{inBox.type},#{inBox.isRead},
        #{inBox.createTime},#{inBox.readTime},#{inBox.verifyKey},#{inBox.isDel})
    </insert>
    <update id="updateById">
        UPDATE ${tableName} SET
<if test="inbox.isDel !=null and inbox.isDel!=''">
            is_del=#{inbox.isDel},
        </if>

        <if test="inbox.isRead!=null and inbox.isRead!=''">
            is_read=#{inbox.isRead},
        </if>
        id=id WHERE id=#{inbox.id}
    </update>
    
    <delete id="deleteByIdsAndUid">
    	delete from ${inbox.tableName} where  uid=#{inbox.uid} and 
            id in
            <foreach item="id" index="index" collection="inbox.ids"
                     open="(" separator="," close=")">
                #{id}
            </foreach>
    </delete>
    
    <update id="updateToIsRead" parameterType="java.util.Map">
    	update ${tableName} set is_read='Y', read_time=UNIX_TIMESTAMP() where is_read='N' and id in(${query})
    </update>

    <select id="selectByUid" resultMap="BaseResultMap">
       SELECT  <include refid="Base_Column_List"/> FROM  ${tableName} where uid = #{uid}
    </select>
    <select id="selectCoutByUid" resultType="java.lang.Integer">
        SELECT count(*) FROM ${tableName} where uid=#{uid}
    </select>
    
     <!--<select id="selectCoutByParam" resultType="java.lang.Integer">-->
        <!--SELECT count(*) FROM ${tableName} where uid=#{uid} and is_read=#{isRead} and is_del=#{isDel}-->
    <!--</select>-->

    <select id="selectCoutByParam" resultType="java.lang.Integer">
        SELECT count(*) FROM ${tableName} where uid=#{uid}
        <if test="isRead !=null and isRead != 'all'">
            and is_read=#{isRead}
        </if>
        and is_del=#{isDel}
    </select>
    
    <!-- 兼容老APP的接口 -->
    <select id="selectInBoxList_OLDList" resultMap="BaseResultMap"
		parameterType="com.yoho.message.dal.page.PageBean">
		select * from ${params.tableName} where uid=#{params.uid} and is_del=#{params.isDel} AND type in (1,3,8,9,10,11,12) order by id DESC limit #{startIndex},#{pageSize}
	</select>
	<select id="selectInBoxList_OLDTotal" resultType="java.lang.Integer"
		parameterType="com.yoho.message.dal.page.PageBean">
		select count(1) from ${params.tableName} where uid=#{params.uid} and is_del=#{params.isDel} AND type in (1,3,8,9,10,11,12)
	</select>
    
    <select id="selectInBoxList" resultMap="BaseResultMap"
		parameterType="com.yoho.message.dal.page.PageBean">
		select * from ${params.tableName} where uid=#{params.uid} and is_del=#{params.isDel} order by id DESC limit #{startIndex},#{pageSize}
	</select>
	<select id="selectInBoxListTotal" resultType="java.lang.Integer"
		parameterType="com.yoho.message.dal.page.PageBean">
		select count(1) from ${params.tableName} where uid=#{params.uid} and is_del=#{params.isDel}
	</select>
</mapper>