|
|
@@ -0,0 +1,395 @@
|
|
|
+<?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.izouma.awesomeadmin.dao.UsersSessionMapper">
|
|
|
+ <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.UsersSession">
|
|
|
+ <id column="id" property="id" jdbcType="INTEGER"/>
|
|
|
+ <result column="user_id" property="userId" jdbcType="INTEGER"/>
|
|
|
+ <result column="to_user_id" property="toUserId" jdbcType="INTEGER"/>
|
|
|
+ <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
|
|
+ <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
|
|
+ <result column="type" property="type" jdbcType="INTEGER"/>
|
|
|
+ <result column="project_id" property="projectId" jdbcType="INTEGER"/>
|
|
|
+ <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
|
|
|
+ <result column="contact_id" property="contactId" jdbcType="INTEGER"/>
|
|
|
+ </resultMap>
|
|
|
+ <sql id="Base_Column_List">
|
|
|
+ id, user_id, to_user_id, create_time, update_time, type, project_id, del_flag, contact_id
|
|
|
+ </sql>
|
|
|
+ <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
|
|
|
+ select
|
|
|
+ <include refid="Base_Column_List"/>
|
|
|
+ from users_session
|
|
|
+ where id = #{id,jdbcType=INTEGER}
|
|
|
+ </select>
|
|
|
+ <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
|
|
+ DELETE FROM users_session
|
|
|
+ WHERE id = #{id,jdbcType=INTEGER}
|
|
|
+ </delete>
|
|
|
+ <insert id="insert" parameterType="com.izouma.awesomeadmin.model.UsersSession" useGeneratedKeys="true" keyProperty="id">
|
|
|
+ INSERT INTO users_session (id, user_id, to_user_id,
|
|
|
+ create_time, update_time, type,
|
|
|
+ project_id, del_flag, contact_id)
|
|
|
+ VALUES (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{toUserId,jdbcType=INTEGER},
|
|
|
+ #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{type,jdbcType=INTEGER},
|
|
|
+ #{projectId,jdbcType=INTEGER}, #{delFlag,jdbcType=CHAR}, #{contactId,jdbcType=INTEGER})
|
|
|
+ </insert>
|
|
|
+ <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.UsersSession" useGeneratedKeys="true"
|
|
|
+ keyProperty="id">
|
|
|
+ insert into users_session
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">
|
|
|
+ id,
|
|
|
+ </if>
|
|
|
+ <if test="userId != null">
|
|
|
+ user_id,
|
|
|
+ </if>
|
|
|
+ <if test="toUserId != null">
|
|
|
+ to_user_id,
|
|
|
+ </if>
|
|
|
+ <if test="createTime != null">
|
|
|
+ create_time,
|
|
|
+ </if>
|
|
|
+ <if test="updateTime != null">
|
|
|
+ update_time,
|
|
|
+ </if>
|
|
|
+ <if test="type != null">
|
|
|
+ type,
|
|
|
+ </if>
|
|
|
+ <if test="projectId != null">
|
|
|
+ project_id,
|
|
|
+ </if>
|
|
|
+ <if test="delFlag != null">
|
|
|
+ del_flag,
|
|
|
+ </if>
|
|
|
+ <if test="contactId != null">
|
|
|
+ contact_id,
|
|
|
+ </if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">
|
|
|
+ #{id,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="userId != null">
|
|
|
+ #{userId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="toUserId != null">
|
|
|
+ #{toUserId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="createTime != null">
|
|
|
+ #{createTime,jdbcType=TIMESTAMP},
|
|
|
+ </if>
|
|
|
+ <if test="updateTime != null">
|
|
|
+ #{updateTime,jdbcType=TIMESTAMP},
|
|
|
+ </if>
|
|
|
+ <if test="type != null">
|
|
|
+ #{type,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="projectId != null">
|
|
|
+ #{projectId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="delFlag != null">
|
|
|
+ #{delFlag,jdbcType=CHAR},
|
|
|
+ </if>
|
|
|
+ <if test="contactId != null">
|
|
|
+ #{contactId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+ <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.UsersSession">
|
|
|
+ update users_session
|
|
|
+ <set>
|
|
|
+ <if test="userId != null">
|
|
|
+ user_id = #{userId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="toUserId != null">
|
|
|
+ to_user_id = #{toUserId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="createTime != null">
|
|
|
+ create_time = #{createTime,jdbcType=TIMESTAMP},
|
|
|
+ </if>
|
|
|
+ <if test="updateTime != null">
|
|
|
+ update_time = #{updateTime,jdbcType=TIMESTAMP},
|
|
|
+ </if>
|
|
|
+ <if test="type != null">
|
|
|
+ type = #{type,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="projectId != null">
|
|
|
+ project_id = #{projectId,jdbcType=INTEGER},
|
|
|
+ </if>
|
|
|
+ <if test="delFlag != null">
|
|
|
+ del_flag = #{delFlag,jdbcType=CHAR},
|
|
|
+ </if>
|
|
|
+ </set>
|
|
|
+ where id = #{id,jdbcType=INTEGER}
|
|
|
+ </update>
|
|
|
+ <update id="updateByPrimaryKey" parameterType="com.izouma.awesomeadmin.model.UsersSession">
|
|
|
+ UPDATE users_session
|
|
|
+ SET user_id = #{userId,jdbcType=INTEGER},
|
|
|
+ to_user_id = #{toUserId,jdbcType=INTEGER},
|
|
|
+ create_time = #{createTime,jdbcType=TIMESTAMP},
|
|
|
+ update_time = #{updateTime,jdbcType=TIMESTAMP},
|
|
|
+ type = #{type,jdbcType=INTEGER},
|
|
|
+ project_id = #{projectId,jdbcType=INTEGER},
|
|
|
+ del_flag = #{delFlag,jdbcType=CHAR}
|
|
|
+ WHERE id = #{id,jdbcType=INTEGER}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <update id="updateByChatInfo" parameterType="com.izouma.awesomeadmin.model.ChatInfo">
|
|
|
+ UPDATE users_session
|
|
|
+ SET update_time = NOW()
|
|
|
+ WHERE
|
|
|
+ del_flag = 'N'
|
|
|
+ AND (
|
|
|
+ (user_id = #{userId} AND to_user_id = #{toUserId})
|
|
|
+ OR (to_user_id = #{userId} AND user_id = #{toUserId})
|
|
|
+ )
|
|
|
+ AND project_id = #{projectId}
|
|
|
+ </update>
|
|
|
+
|
|
|
+
|
|
|
+ <select id="queryUsersSessionsByPage" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.UsersSession">
|
|
|
+ select
|
|
|
+ <include refid="Base_Column_List"/>
|
|
|
+ from users_session
|
|
|
+ <where>
|
|
|
+ and del_flag = 'N'
|
|
|
+
|
|
|
+ <if test="usersSession.id != null and !"".equals(usersSession.id)">
|
|
|
+ and id=#{UsersSession.id}
|
|
|
+ </if>
|
|
|
+ <if test="usersSession.userId != null and !"".equals(usersSession.userId)">
|
|
|
+ and user_id=#{usersSession.userId}
|
|
|
+ </if>
|
|
|
+ <if test="usersSession.toUserId != null and !"".equals(usersSession.toUserId)">
|
|
|
+ and to_user_id=#{usersSession.toUserId}
|
|
|
+ </if>
|
|
|
+ <if test="usersSession.type != null and !"".equals(usersSession.type)">
|
|
|
+ and type=#{usersSession.type}
|
|
|
+ </if>
|
|
|
+ <if test="usersSession.projectId != null and !"".equals(usersSession.projectId)">
|
|
|
+ and project_id=#{usersSession.projectId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ order by update_time desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="queryAllUsersSession" parameterType="java.util.Map" resultMap="UsersSessionResultMap">
|
|
|
+ SELECT
|
|
|
+ tmp.id,
|
|
|
+ tmp.user_id,
|
|
|
+ tmp.to_user_id,
|
|
|
+ tmp.create_time,
|
|
|
+ tmp.update_time,
|
|
|
+ tmp.type,
|
|
|
+ tmp.project_id,
|
|
|
+ tmp.nick_name,
|
|
|
+ tmp.icon,
|
|
|
+ tmp.amount,
|
|
|
+ CASE WHEN ctime.time IS NULL THEN tmp.create_time ELSE MAX(ctime.time) END AS chattime
|
|
|
+ FROM
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ us.id,
|
|
|
+ us.user_id,
|
|
|
+ us.to_user_id,
|
|
|
+ us.create_time,
|
|
|
+ us.update_time,
|
|
|
+ us.type,
|
|
|
+ us.project_id,
|
|
|
+ tu.nick_name,
|
|
|
+ tu.icon,
|
|
|
+ COUNT(chat.id) AS amount
|
|
|
+ FROM
|
|
|
+ users_session us
|
|
|
+ LEFT JOIN user_info tu ON us.to_user_id = tu.id
|
|
|
+ LEFT JOIN chat_info chat ON chat.user_id = us.to_user_id
|
|
|
+ AND chat.to_user_id = us.user_id
|
|
|
+ AND chat.state = 0
|
|
|
+ AND CASE WHEN chat.project_id IS NULL THEN 1 ELSE chat.project_id = us.project_id END
|
|
|
+ WHERE
|
|
|
+ us.user_id = #{userId}
|
|
|
+ AND us.type = 0
|
|
|
+ AND us.del_flag = 'N'
|
|
|
+ GROUP BY
|
|
|
+ us.project_id,
|
|
|
+ us.user_id,
|
|
|
+ us.to_user_id
|
|
|
+ ) tmp
|
|
|
+ LEFT JOIN chat_info ctime ON (
|
|
|
+ ctime.user_id = tmp.to_user_id
|
|
|
+ AND ctime.to_user_id = tmp.user_id
|
|
|
+ )
|
|
|
+ OR (
|
|
|
+ ctime.user_id = tmp.user_id
|
|
|
+ AND ctime.to_user_id = tmp.to_user_id
|
|
|
+ )
|
|
|
+ and ctime.project_id = tmp.project_id
|
|
|
+ GROUP BY
|
|
|
+ tmp.id,
|
|
|
+ tmp.user_id,
|
|
|
+ tmp.to_user_id,
|
|
|
+ tmp.create_time,
|
|
|
+ tmp.update_time,
|
|
|
+ tmp.type,
|
|
|
+ tmp.project_id,
|
|
|
+ tmp.nick_name,
|
|
|
+ tmp.icon,
|
|
|
+ tmp.amount
|
|
|
+ ORDER BY
|
|
|
+ chattime DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+
|
|
|
+ <select id="queryAllUsersSessionByPage" parameterType="java.util.Map" resultMap="UsersSessionResultMap">
|
|
|
+
|
|
|
+ SELECT DISTINCT
|
|
|
+ us.user_id,
|
|
|
+ us.to_user_id,
|
|
|
+ us.contact_id,
|
|
|
+ us.type,
|
|
|
+ us.project_id,
|
|
|
+ tu.nick_name,
|
|
|
+ tu.icon,
|
|
|
+ myInfo.nick_name AS my_nick_name,
|
|
|
+ myInfo.icon AS my_icon,
|
|
|
+ MAX(us.update_time) update_time
|
|
|
+ FROM
|
|
|
+ users_session us
|
|
|
+ LEFT JOIN user_info tu ON us.to_user_id = tu.id
|
|
|
+ LEFT JOIN user_info myInfo ON us.user_id = myInfo.id
|
|
|
+ WHERE
|
|
|
+ us.user_id != 1
|
|
|
+ AND us.to_user_id != 1
|
|
|
+ AND us.type = 0
|
|
|
+ AND us.project_id IN (
|
|
|
+ SELECT
|
|
|
+ id
|
|
|
+ FROM
|
|
|
+ project_info
|
|
|
+ WHERE
|
|
|
+ del_flag = 'N'
|
|
|
+ )
|
|
|
+ AND us.to_user_id = us.contact_id
|
|
|
+ AND us.del_flag = 'N'
|
|
|
+
|
|
|
+ <if test="userId != null and !"".equals(userId)">
|
|
|
+ AND (us.user_id = #{userId} or us.to_user_id = #{userId})
|
|
|
+ </if>
|
|
|
+ <if test="projectId != null and !"".equals(projectId)">
|
|
|
+ AND us.project_id = #{projectId}
|
|
|
+ </if>
|
|
|
+ <if test="companyId != null and !"".equals(companyId)">
|
|
|
+ AND us.project_id in (select id from project_info where company_id = #{companyId})
|
|
|
+ </if>
|
|
|
+
|
|
|
+
|
|
|
+ <if test="beginTime != null and !"".equals(beginTime)">
|
|
|
+ <![CDATA[ and us.update_time >= #{beginTime}]]>
|
|
|
+ </if>
|
|
|
+
|
|
|
+ <if test="endTime != null and !"".equals(endTime)">
|
|
|
+ <![CDATA[ and us.update_time <= #{endTime}]]>
|
|
|
+ </if>
|
|
|
+
|
|
|
+ GROUP BY
|
|
|
+ us.user_id,
|
|
|
+ us.to_user_id,
|
|
|
+ us.contact_id,
|
|
|
+ us.type,
|
|
|
+ us.project_id,
|
|
|
+ tu.nick_name,
|
|
|
+ tu.icon,
|
|
|
+ my_nick_name,
|
|
|
+ my_icon
|
|
|
+ ORDER BY
|
|
|
+ update_time DESC
|
|
|
+
|
|
|
+
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="queryUsersSession" parameterType="com.izouma.awesomeadmin.model.UsersSession" resultType="com.izouma.awesomeadmin.model.UsersSession">
|
|
|
+ select
|
|
|
+ <include refid="Base_Column_List"/>
|
|
|
+ from users_session
|
|
|
+ <where>
|
|
|
+ and del_flag = 'N'
|
|
|
+
|
|
|
+ <if test="id != null and !"".equals(id)">
|
|
|
+ and id=#{id}
|
|
|
+ </if>
|
|
|
+ <if test="userId != null and !"".equals(userId)">
|
|
|
+ and user_id=#{userId}
|
|
|
+ </if>
|
|
|
+ <if test="toUserId != null and !"".equals(toUserId)">
|
|
|
+ and to_user_id=#{toUserId}
|
|
|
+ </if>
|
|
|
+ <if test="type != null and !"".equals(type)">
|
|
|
+ and type=#{type}
|
|
|
+ </if>
|
|
|
+ <if test="projectId != null and !"".equals(projectId)">
|
|
|
+ and project_id=#{projectId}
|
|
|
+ </if>
|
|
|
+ <if test="contactId != null and !"".equals(contactId)">
|
|
|
+ and contact_id=#{contactId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ LIMIT 1
|
|
|
+ </select>
|
|
|
+
|
|
|
+
|
|
|
+ <update id="delete">
|
|
|
+ UPDATE users_session SET del_flag = 'Y'
|
|
|
+ <where>
|
|
|
+ AND id = #{id}
|
|
|
+ </where>
|
|
|
+ </update>
|
|
|
+
|
|
|
+
|
|
|
+ <select id="getChat" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.ChatInfo">
|
|
|
+ SELECT *
|
|
|
+ FROM
|
|
|
+ chat_info
|
|
|
+ WHERE
|
|
|
+ (
|
|
|
+ (
|
|
|
+ user_id = #{userId}
|
|
|
+ AND to_user_id = #{toUserId}
|
|
|
+ )
|
|
|
+ OR (
|
|
|
+ user_id = #{toUserId}
|
|
|
+ AND to_user_id = #{userId}
|
|
|
+ )
|
|
|
+ )
|
|
|
+ AND state != 2
|
|
|
+ <if test="projectId != null and !"".equals(projectId)">
|
|
|
+ AND project_id = #{projectId}
|
|
|
+ </if>
|
|
|
+ ORDER BY
|
|
|
+ time DESC
|
|
|
+ LIMIT 1
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <resultMap id="UsersSessionResultMap" type="com.izouma.awesomeadmin.model.UsersSession">
|
|
|
+
|
|
|
+ <id column="id" property="id" jdbcType="INTEGER"/>
|
|
|
+ <result column="user_id" property="userId" jdbcType="INTEGER"/>
|
|
|
+ <result column="to_user_id" property="toUserId" jdbcType="INTEGER"/>
|
|
|
+ <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
|
|
+ <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
|
|
+ <result column="type" property="type" jdbcType="INTEGER"/>
|
|
|
+ <result column="project_id" property="projectId" jdbcType="INTEGER"/>
|
|
|
+ <result column="nick_name" property="nickName"/>
|
|
|
+ <result column="icon" property="icon"/>
|
|
|
+ <result column="my_nick_name" property="myNickName"/>
|
|
|
+ <result column="my_icon" property="myIcon"/>
|
|
|
+ <result column="project_name" property="projectName"/>
|
|
|
+ <result column="chattime" property="chattime"/>
|
|
|
+ <association
|
|
|
+ property="chatInfo" javaType="com.izouma.awesomeadmin.model.ChatInfo"
|
|
|
+ select="getChat"
|
|
|
+ column="{ userId = user_id , toUserId = to_user_id , projectId = project_id }"/>
|
|
|
+
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+
|
|
|
+</mapper>
|