1
0
suochencheng 7 лет назад
Родитель
Сommit
b1b857c57a

+ 44 - 0
src/main/java/com/izouma/awesomeadmin/dao/ChatInfoMapper.java

@@ -0,0 +1,44 @@
+package com.izouma.awesomeadmin.dao;
+
+import com.izouma.awesomeadmin.model.ChatInfo;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+@Repository("com.izouma.awesomeadmin.dao.ChatInfoMapper")
+public interface ChatInfoMapper {
+
+    int deleteByPrimaryKey(Integer id);
+
+
+    int insert(ChatInfo record);
+
+
+    int insertSelective(ChatInfo record);
+
+
+    ChatInfo selectByPrimaryKey(Integer id);
+
+
+    int updateByPrimaryKeySelective(ChatInfo record);
+
+
+    int updateByPrimaryKey(ChatInfo record);
+
+
+    List<ChatInfo> queryAllChatInfo();
+
+
+    List<ChatInfo> queryChatInfosByPage(Map<String, Object> parameter);
+
+
+    int delete(String id);
+
+
+    ChatInfo queryChatInfo(ChatInfo chatInfo);
+
+    int readAll(int userId, int toUserId);
+    
+    ChatInfo queryLastChatInfo(ChatInfo chatInfo);
+}

+ 215 - 0
src/main/java/com/izouma/awesomeadmin/dao/ChatInfoMapper.xml

@@ -0,0 +1,215 @@
+<?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.ChatInfoMapper">
+    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.ChatInfo">
+        <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="content" property="content" jdbcType="VARCHAR"/>
+        <result column="time" property="time" jdbcType="TIMESTAMP"/>
+        <result column="content_type" property="contentType" jdbcType="INTEGER"/>
+        <result column="state" property="state" jdbcType="INTEGER"/>
+        <result column="project_id" property="projectId" jdbcType="INTEGER"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        id, user_id, to_user_id, content, time, content_type, state, project_id
+    </sql>
+    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
+        select
+        <include refid="Base_Column_List"/>
+        from chat_info
+        where id = #{id,jdbcType=INTEGER}
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+        DELETE FROM chat_info
+        WHERE id = #{id,jdbcType=INTEGER}
+    </delete>
+    <insert id="insert" parameterType="com.izouma.awesomeadmin.model.ChatInfo" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO chat_info (id, user_id, to_user_id,
+                               content, time, content_type,
+                               state,project_id)
+        VALUES (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{toUserId,jdbcType=INTEGER},
+                #{content,jdbcType=VARCHAR}, #{time,jdbcType=TIMESTAMP}, #{contentType,jdbcType=INTEGER},
+                #{state,jdbcType=INTEGER},#{projectId,jdbcType=INTEGER})
+    </insert>
+    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.ChatInfo" useGeneratedKeys="true"
+            keyProperty="id">
+        insert into chat_info
+        <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="content != null">
+                content,
+            </if>
+            <if test="time != null">
+                time,
+            </if>
+            <if test="contentType != null">
+                content_type,
+            </if>
+            <if test="state != null">
+                state,
+            </if>
+            <if test="projectId != null">
+                project_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="content != null">
+                #{content,jdbcType=VARCHAR},
+            </if>
+            <if test="time != null">
+                #{time,jdbcType=TIMESTAMP},
+            </if>
+            <if test="contentType != null">
+                #{contentType,jdbcType=INTEGER},
+            </if>
+            <if test="state != null">
+                #{state,jdbcType=INTEGER},
+            </if>
+            <if test="projectId != null">
+                #{projectId,jdbcType=INTEGER},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.ChatInfo">
+        update chat_info
+        <set>
+            <if test="userId != null">
+                user_id = #{userId,jdbcType=INTEGER},
+            </if>
+            <if test="toUserId != null">
+                to_user_id = #{toUserId,jdbcType=INTEGER},
+            </if>
+            <if test="content != null">
+                content = #{content,jdbcType=VARCHAR},
+            </if>
+            <if test="time != null">
+                time = #{time,jdbcType=TIMESTAMP},
+            </if>
+            <if test="contentType != null">
+                content_type = #{contentType,jdbcType=INTEGER},
+            </if>
+            <if test="state != null">
+                state = #{state,jdbcType=INTEGER},
+            </if>
+            <if test="projectId != null">
+                project_id = #{projectId,jdbcType=INTEGER},
+            </if>
+        </set>
+        where id = #{id,jdbcType=INTEGER}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="com.izouma.awesomeadmin.model.ChatInfo">
+        UPDATE chat_info
+        SET user_id      = #{userId,jdbcType=INTEGER},
+            to_user_id   = #{toUserId,jdbcType=INTEGER},
+            content      = #{content,jdbcType=VARCHAR},
+            time         = #{time,jdbcType=TIMESTAMP},
+            content_type = #{contentType,jdbcType=INTEGER},
+            state        = #{state,jdbcType=INTEGER},
+            project_id        = #{projectId,jdbcType=INTEGER}
+        WHERE id = #{id,jdbcType=INTEGER}
+    </update>
+
+
+    <select id="queryChatInfosByPage" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.ChatInfo">
+        SELECT
+			chat_info.*, uInfo.nick_name,
+			uInfo.icon
+		FROM
+			chat_info
+		LEFT JOIN user_info uInfo ON chat_info.user_id = uInfo.id
+        <where>
+            and state != 2
+
+            <if test="chatInfo.id != null and !&quot;&quot;.equals(chatInfo.id)">
+                and chat_info.id=#{chatInfo.id}
+            </if>
+            <if test="chatInfo.userId != null and !&quot;&quot;.equals(chatInfo.userId) and chatInfo.toUserId != null and !&quot;&quot;.equals(chatInfo.toUserId)">
+                and ((user_id=#{chatInfo.userId} and to_user_id=#{chatInfo.toUserId}) or (user_id=#{chatInfo.toUserId}
+                and to_user_id=#{chatInfo.userId}))
+            </if>
+            <if test="chatInfo.contentType != null and !&quot;&quot;.equals(chatInfo.contentType)">
+                and content_type=#{chatInfo.contentType}
+            </if>
+            <if test="chatInfo.projectId != null and !&quot;&quot;.equals(chatInfo.projectId)">
+                and chat_info.project_id=#{chatInfo.projectId}
+            </if>
+        </where>
+        order by time desc
+    </select>
+	
+	<select id="queryLastChatInfo" parameterType="com.izouma.awesomeadmin.model.ChatInfo" resultType="com.izouma.awesomeadmin.model.ChatInfo">
+        select
+        <include refid="Base_Column_List"/>
+        from chat_info
+        <where>
+            user_id = #{userId} and to_user_id = #{toUserId} and project_id=#{projectId}
+        </where>
+        order by time desc
+        limit 1
+    </select>
+	
+    <select id="queryAllChatInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.ChatInfo">
+        select
+        <include refid="Base_Column_List"/>
+        from chat_info
+        <where>
+            and state != 2
+        </where>
+        order by time desc
+    </select>
+
+    <select id="queryChatInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.ChatInfo">
+        select
+        <include refid="Base_Column_List"/>
+        from chat_info
+        <where>
+            and state != 2
+
+            <if test="chatInfo.id != null and !&quot;&quot;.equals(chatInfo.id)">
+                and id=#{chatInfo.id}
+            </if>
+            <if test="chatInfo.userId != null and !&quot;&quot;.equals(chatInfo.userId)">
+                and user_id=#{chatInfo.userId}
+            </if>
+            <if test="chatInfo.toUserId != null and !&quot;&quot;.equals(chatInfo.toUserId)">
+                and to_user_id=#{chatInfo.toUserId}
+            </if>
+            <if test="chatInfo.contentType != null and !&quot;&quot;.equals(chatInfo.contentType)">
+                and content_type=#{chatInfo.contentType}
+            </if>
+        </where>
+        LIMIT 1
+    </select>
+
+
+    <update id="delete">
+        UPDATE chat_info SET state = 2
+        <where>
+            AND id = #{id}
+        </where>
+    </update>
+    <update id="readAll">
+        UPDATE chat_info
+        SET state = 1
+        WHERE user_id = #{param2} AND to_user_id = #{param1}
+    </update>
+
+</mapper>

+ 47 - 0
src/main/java/com/izouma/awesomeadmin/dao/UsersSessionMapper.java

@@ -0,0 +1,47 @@
+package com.izouma.awesomeadmin.dao;
+
+import com.izouma.awesomeadmin.model.ChatInfo;
+import com.izouma.awesomeadmin.model.UsersSession;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+@Repository("com.izouma.awesomeadmin.dao.UsersSessionMapper")
+public interface UsersSessionMapper {
+
+    int deleteByPrimaryKey(Integer id);
+
+
+    int insert(UsersSession record);
+
+
+    int insertSelective(UsersSession record);
+
+
+    UsersSession selectByPrimaryKey(Integer id);
+
+
+    int updateByPrimaryKeySelective(UsersSession record);
+
+
+    int updateByPrimaryKey(UsersSession record);
+
+
+    List<UsersSession> queryAllUsersSession(Map<String, Object> parameter);
+
+
+    List<UsersSession> queryAllUsersSessionByPage(Map<String, Object> parameter);
+
+
+    List<UsersSession> queryUsersSessionsByPage(Map<String, Object> parameter);
+
+
+    int delete(String id);
+
+
+    UsersSession queryUsersSession(UsersSession usersSession);
+
+    int updateByChatInfo(ChatInfo chatInfo);
+
+}

+ 395 - 0
src/main/java/com/izouma/awesomeadmin/dao/UsersSessionMapper.xml

@@ -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 !&quot;&quot;.equals(usersSession.id)">
+                and id=#{UsersSession.id}
+            </if>
+            <if test="usersSession.userId != null and !&quot;&quot;.equals(usersSession.userId)">
+                and user_id=#{usersSession.userId}
+            </if>
+            <if test="usersSession.toUserId != null and !&quot;&quot;.equals(usersSession.toUserId)">
+                and to_user_id=#{usersSession.toUserId}
+            </if>
+            <if test="usersSession.type != null and !&quot;&quot;.equals(usersSession.type)">
+                and type=#{usersSession.type}
+            </if>
+            <if test="usersSession.projectId != null and !&quot;&quot;.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 !&quot;&quot;.equals(userId)">
+            AND (us.user_id = #{userId} or us.to_user_id = #{userId})
+        </if>
+        <if test="projectId != null and !&quot;&quot;.equals(projectId)">
+            AND us.project_id = #{projectId}
+        </if>
+        <if test="companyId != null and !&quot;&quot;.equals(companyId)">
+            AND us.project_id in (select id from project_info where company_id = #{companyId})
+        </if>
+
+
+        <if test="beginTime != null and !&quot;&quot;.equals(beginTime)">
+            <![CDATA[ and  us.update_time >= #{beginTime}]]>
+        </if>
+
+        <if test="endTime != null and !&quot;&quot;.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 !&quot;&quot;.equals(id)">
+                and id=#{id}
+            </if>
+            <if test="userId != null and !&quot;&quot;.equals(userId)">
+                and user_id=#{userId}
+            </if>
+            <if test="toUserId != null and !&quot;&quot;.equals(toUserId)">
+                and to_user_id=#{toUserId}
+            </if>
+            <if test="type != null and !&quot;&quot;.equals(type)">
+                and type=#{type}
+            </if>
+            <if test="projectId != null and !&quot;&quot;.equals(projectId)">
+                and project_id=#{projectId}
+            </if>
+            <if test="contactId != null and !&quot;&quot;.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 !&quot;&quot;.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>

+ 170 - 0
src/main/java/com/izouma/awesomeadmin/model/ChatInfo.java

@@ -0,0 +1,170 @@
+package com.izouma.awesomeadmin.model;
+
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+import java.util.Date;
+
+@JsonAutoDetect
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class ChatInfo {
+
+    private Integer id;
+
+    private Integer userId;
+
+    private Integer toUserId;
+
+    private String content;
+
+    private Date time;
+
+    private Integer contentType;
+
+    private Integer state;
+
+    private String nickName;
+
+    private String icon;
+
+    private Integer projectId;
+
+    private String formId;
+
+    public String getFormId() {
+        return formId;
+    }
+
+    public void setFormId(String formId) {
+        this.formId = formId;
+    }
+
+    public Integer getId() {
+
+        return id;
+    }
+
+
+    public void setId(Integer id) {
+
+        this.id = id;
+    }
+
+
+    public Integer getUserId() {
+
+        return userId;
+    }
+
+
+    public void setUserId(Integer userId) {
+
+        this.userId = userId;
+    }
+
+
+    public Integer getToUserId() {
+
+        return toUserId;
+    }
+
+
+    public void setToUserId(Integer toUserId) {
+
+        this.toUserId = toUserId;
+    }
+
+
+    public String getContent() {
+
+        return content;
+    }
+
+
+    public void setContent(String content) {
+
+        this.content = content;
+    }
+
+
+    public Date getTime() {
+
+        return time;
+    }
+
+
+    public void setTime(Date time) {
+
+        this.time = time;
+    }
+
+
+    public Integer getContentType() {
+
+        return contentType;
+    }
+
+
+    public void setContentType(Integer contentType) {
+
+        this.contentType = contentType;
+    }
+
+
+    public Integer getState() {
+
+        return state;
+    }
+
+
+    public void setState(Integer state) {
+
+        this.state = state;
+    }
+
+
+    public String getNickName() {
+
+        return nickName;
+    }
+
+
+    public void setNickName(String nickName) {
+
+        this.nickName = nickName;
+    }
+
+
+    public String getIcon() {
+
+        return icon;
+    }
+
+
+    public void setIcon(String icon) {
+
+        this.icon = icon;
+    }
+
+
+    public Integer getProjectId() {
+
+        return projectId;
+    }
+
+
+    public void setProjectId(Integer projectId) {
+
+        this.projectId = projectId;
+    }
+
+
+    @Override
+    public String toString() {
+
+        return "ChatInfo [id=" + id + ", userId=" + userId + ", toUserId=" + toUserId + ", content=" + content + ", time=" + time + ", contentType="
+                + contentType + ", state=" + state + ", nickName=" + nickName + ", icon=" + icon + ", projectId=" + projectId + "]";
+    }
+
+}

+ 289 - 0
src/main/java/com/izouma/awesomeadmin/model/UsersSession.java

@@ -0,0 +1,289 @@
+package com.izouma.awesomeadmin.model;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+import java.util.Date;
+
+@JsonAutoDetect
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class UsersSession {
+
+    private Integer id;
+
+    private Integer userId;
+
+    private Integer toUserId;
+
+    private Date createTime;
+
+    private Date updateTime;
+
+    private Integer type;
+
+    private Integer projectId;
+
+    private String delFlag;
+
+    private String nickName;
+
+    private String icon;
+
+    private Integer amount;
+
+    private Date chattime;
+
+    private ChatInfo chatInfo;
+
+    private String myNickName;
+
+    private String myIcon;
+
+    private String projectName;
+
+    private Date beginTime;
+
+    private Date endTime;
+
+    private Integer contactId;
+
+    public Integer getContactId() {
+        return contactId;
+    }
+
+    public void setContactId(Integer contactId) {
+        this.contactId = contactId;
+    }
+
+    public Integer getId() {
+
+        return id;
+    }
+
+
+    public void setId(Integer id) {
+
+        this.id = id;
+    }
+
+
+    public Integer getUserId() {
+
+        return userId;
+    }
+
+
+    public void setUserId(Integer userId) {
+
+        this.userId = userId;
+    }
+
+
+    public Integer getToUserId() {
+
+        return toUserId;
+    }
+
+
+    public void setToUserId(Integer toUserId) {
+
+        this.toUserId = toUserId;
+    }
+
+
+    public Date getCreateTime() {
+
+        return createTime;
+    }
+
+
+    public void setCreateTime(Date createTime) {
+
+        this.createTime = createTime;
+    }
+
+
+    public Date getUpdateTime() {
+
+        return updateTime;
+    }
+
+
+    public void setUpdateTime(Date updateTime) {
+
+        this.updateTime = updateTime;
+    }
+
+
+    public Integer getType() {
+
+        return type;
+    }
+
+
+    public void setType(Integer type) {
+
+        this.type = type;
+    }
+
+
+    public Integer getProjectId() {
+
+        return projectId;
+    }
+
+
+    public void setProjectId(Integer projectId) {
+
+        this.projectId = projectId;
+    }
+
+
+    public String getDelFlag() {
+
+        return delFlag;
+    }
+
+
+    public void setDelFlag(String delFlag) {
+
+        this.delFlag = delFlag;
+    }
+
+
+    public String getNickName() {
+
+        return nickName;
+    }
+
+
+    public void setNickName(String nickName) {
+
+        this.nickName = nickName;
+    }
+
+
+    public String getIcon() {
+        if (icon != null) {
+            return icon + "?x-oss-process=image/resize,m_lfit,w_128,h_128,limit_0/auto-orient,1/quality,q_60";
+        } else {
+            return null;
+        }
+    }
+
+
+    public void setIcon(String icon) {
+
+        this.icon = icon;
+    }
+
+
+    public Integer getAmount() {
+
+        return amount;
+    }
+
+
+    public void setAmount(Integer amount) {
+
+        this.amount = amount;
+    }
+
+
+    public Date getChattime() {
+
+        return chattime;
+    }
+
+
+    public void setChattime(Date chattime) {
+
+        this.chattime = chattime;
+    }
+
+
+    public ChatInfo getChatInfo() {
+
+        return chatInfo;
+    }
+
+
+    public void setChatInfo(ChatInfo chatInfo) {
+
+        this.chatInfo = chatInfo;
+    }
+
+
+    public String getMyNickName() {
+
+        return myNickName;
+    }
+
+
+    public void setMyNickName(String myNickName) {
+
+        this.myNickName = myNickName;
+    }
+
+
+    public String getMyIcon() {
+        if (myIcon != null) {
+            return myIcon + "?x-oss-process=image/resize,m_lfit,w_128,h_128,limit_0/auto-orient,1/quality,q_60";
+        } else {
+            return null;
+        }
+    }
+
+
+    public void setMyIcon(String myIcon) {
+
+        this.myIcon = myIcon;
+    }
+
+
+    public String getProjectName() {
+
+        return projectName;
+    }
+
+
+    public void setProjectName(String projectName) {
+
+        this.projectName = projectName;
+    }
+
+
+    public Date getBeginTime() {
+
+        return beginTime;
+    }
+
+
+    public void setBeginTime(Date beginTime) {
+
+        this.beginTime = beginTime;
+    }
+
+
+    public Date getEndTime() {
+
+        return endTime;
+    }
+
+
+    public void setEndTime(Date endTime) {
+
+        this.endTime = endTime;
+    }
+
+
+    @Override
+    public String toString() {
+
+        return "UsersSession [id=" + id + ", userId=" + userId + ", toUserId=" + toUserId + ", createTime=" + createTime + ", updateTime="
+                + updateTime + ", type=" + type + ", projectId=" + projectId + ", delFlag=" + delFlag + ", nickName=" + nickName + ", icon=" + icon
+                + ", amount=" + amount + ", chattime=" + chattime + ", chatInfo=" + chatInfo + ", myNickName=" + myNickName + ", myIcon=" + myIcon
+                + ", projectName=" + projectName + ", beginTime=" + beginTime + ", endTime=" + endTime + "]";
+    }
+
+}

+ 34 - 0
src/main/java/com/izouma/awesomeadmin/service/ChatInfoService.java

@@ -0,0 +1,34 @@
+package com.izouma.awesomeadmin.service;
+
+
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.model.ChatInfo;
+
+import java.util.List;
+
+public interface ChatInfoService {
+
+    List<ChatInfo> getChatInfoList();
+
+
+    List<ChatInfo> getChatInfoByPage(Page page, ChatInfo chatInfo);
+
+
+    ChatInfo getChatInfoById(String id);
+
+
+    ChatInfo getChatInfo(ChatInfo chatInfo);
+
+
+    boolean createChatInfo(ChatInfo chatInfo);
+
+
+    boolean deleteChatInfo(String id);
+
+
+    boolean updateChatInfo(ChatInfo chatInfo);
+
+    boolean readAll(int userId, int toUserId);
+
+
+}

+ 34 - 0
src/main/java/com/izouma/awesomeadmin/service/UsersSessionService.java

@@ -0,0 +1,34 @@
+package com.izouma.awesomeadmin.service;
+
+
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.model.UsersSession;
+
+import java.util.List;
+
+public interface UsersSessionService {
+
+    List<UsersSession> getUsersSessionList(String userId);
+
+
+    List<UsersSession> queryAllUsersSessionByPage(Page page, UsersSession usersSession, String companyId);
+
+
+    List<UsersSession> getUsersSessionByPage(Page page, UsersSession usersSession);
+
+
+    UsersSession getUsersSessionById(String id);
+
+
+    UsersSession getUsersSession(UsersSession usersSession);
+
+
+    boolean createUsersSession(UsersSession usersSession);
+
+
+    boolean deleteUsersSession(String id);
+
+
+    boolean updateUsersSession(UsersSession usersSession);
+
+}

+ 149 - 0
src/main/java/com/izouma/awesomeadmin/service/impl/ChatInfoServiceImpl.java

@@ -0,0 +1,149 @@
+package com.izouma.awesomeadmin.service.impl;
+
+import com.izouma.awesomeadmin.constant.AppConstant;
+import com.izouma.awesomeadmin.dao.ChatInfoMapper;
+import com.izouma.awesomeadmin.dao.UsersSessionMapper;
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.model.ChatInfo;
+import com.izouma.awesomeadmin.service.ChatInfoService;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class ChatInfoServiceImpl implements ChatInfoService {
+
+    private static Logger logger = Logger.getLogger(ChatInfoServiceImpl.class);
+
+    @Autowired
+    private ChatInfoMapper chatInfoMapper;
+
+    @Autowired
+    private UsersSessionMapper usersSessionMapper;
+
+
+    @Override
+    public List<ChatInfo> getChatInfoList() {
+
+        logger.info("getChatInfoList");
+        try {
+
+            return chatInfoMapper.queryAllChatInfo();
+        } catch (Exception e) {
+            logger.error("getChatInfoList", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public List<ChatInfo> getChatInfoByPage(Page page, ChatInfo chatInfo) {
+
+        logger.info("getChatInfoByPage");
+        try {
+
+            Map<String, Object> parameter = new HashMap<String, Object>();
+            parameter.put("chatInfo", chatInfo);
+            parameter.put(AppConstant.PAGE, page);
+
+            return chatInfoMapper.queryChatInfosByPage(parameter);
+        } catch (Exception e) {
+            logger.error("getChatInfoByPage", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public ChatInfo getChatInfoById(String id) {
+
+        logger.info("getChatInfoById");
+        try {
+
+            return chatInfoMapper.selectByPrimaryKey(Integer.valueOf(id));
+        } catch (Exception e) {
+            logger.error("getChatInfoById", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public ChatInfo getChatInfo(ChatInfo chatInfo) {
+
+        logger.info("getChatInfo");
+        try {
+
+            return chatInfoMapper.queryChatInfo(chatInfo);
+        } catch (Exception e) {
+            logger.error("getChatInfo", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public boolean createChatInfo(ChatInfo chatInfo) {
+        logger.info("createChatInfo");
+        try {
+
+            ChatInfo c = new ChatInfo();
+            c.setUserId(chatInfo.getUserId());
+            c.setToUserId(chatInfo.getToUserId());
+            c.setProjectId(chatInfo.getProjectId());
+            int updates = chatInfoMapper.insertSelective(chatInfo);
+
+            usersSessionMapper.updateByChatInfo(chatInfo);
+
+            if (updates > 0) {
+                return true;
+            }
+        } catch (Exception e) {
+            logger.error("createChatInfo", e);
+        }
+        return false;
+    }
+
+    @Override
+    public boolean deleteChatInfo(String id) {
+
+        logger.info("deleteChatInfo");
+        try {
+
+            int updates = chatInfoMapper.delete(id);
+
+            if (updates > 0) {
+                return true;
+            }
+        } catch (Exception e) {
+            logger.error("deleteChatInfo", e);
+        }
+        return false;
+    }
+
+
+    @Override
+    public boolean updateChatInfo(ChatInfo chatInfo) {
+
+        logger.info("updateChatInfo");
+        try {
+            return chatInfoMapper.updateByPrimaryKeySelective(chatInfo) > 0;
+        } catch (Exception e) {
+            logger.error("updateChatInfo", e);
+        }
+        return false;
+    }
+
+
+    @Override
+    public boolean readAll(int userId, int toUserId) {
+
+        return chatInfoMapper.readAll(userId, toUserId) > 0;
+    }
+
+
+}

+ 164 - 0
src/main/java/com/izouma/awesomeadmin/service/impl/UsersSessionServiceImpl.java

@@ -0,0 +1,164 @@
+package com.izouma.awesomeadmin.service.impl;
+
+import com.izouma.awesomeadmin.constant.AppConstant;
+import com.izouma.awesomeadmin.dao.UsersSessionMapper;
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.model.UsersSession;
+import com.izouma.awesomeadmin.service.UsersSessionService;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class UsersSessionServiceImpl implements UsersSessionService {
+
+    private static Logger logger = Logger.getLogger(UsersSessionServiceImpl.class);
+
+    @Autowired
+    private UsersSessionMapper usersSessionMapper;
+
+
+    @Override
+    public List<UsersSession> getUsersSessionList(String userId) {
+
+        logger.info("getUsersSessionList");
+        try {
+            Map<String, Object> parameter = new HashMap<String, Object>();
+            parameter.put("userId", userId);
+            return usersSessionMapper.queryAllUsersSession(parameter);
+        } catch (Exception e) {
+            logger.error("getUsersSessionList", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public List<UsersSession> queryAllUsersSessionByPage(Page page, UsersSession usersSession, String companyId) {
+
+        logger.info("queryAllUsersSessionByPage");
+        try {
+            Map<String, Object> parameter = new HashMap<String, Object>();
+            parameter.put(AppConstant.PAGE, page);
+            parameter.put("userId", usersSession.getUserId());
+            parameter.put("projectId", usersSession.getProjectId());
+            parameter.put("beginTime", usersSession.getBeginTime());
+            parameter.put("endTime", usersSession.getEndTime());
+            parameter.put("companyId", companyId);
+            return usersSessionMapper.queryAllUsersSessionByPage(parameter);
+        } catch (Exception e) {
+            logger.error("queryAllUsersSessionByPage", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public List<UsersSession> getUsersSessionByPage(Page page, UsersSession usersSession) {
+
+        logger.info("getUsersSessionByPage");
+        try {
+
+            Map<String, Object> parameter = new HashMap<String, Object>();
+            parameter.put("usersSession", usersSession);
+            parameter.put(AppConstant.PAGE, page);
+
+            return usersSessionMapper.queryUsersSessionsByPage(parameter);
+        } catch (Exception e) {
+            logger.error("getUsersSessionByPage", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public UsersSession getUsersSessionById(String id) {
+
+        logger.info("getUsersSessionById");
+        try {
+
+            return usersSessionMapper.selectByPrimaryKey(Integer.valueOf(id));
+        } catch (Exception e) {
+            logger.error("getUsersSessionById", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public UsersSession getUsersSession(UsersSession usersSession) {
+
+        logger.info("getUsersSession");
+        try {
+
+            return usersSessionMapper.queryUsersSession(usersSession);
+        } catch (Exception e) {
+            logger.error("getUsersSession", e);
+        }
+        return null;
+    }
+
+
+    @Override
+    public boolean createUsersSession(UsersSession usersSession) {
+
+        logger.info("createUsersSession");
+        try {
+            UsersSession us = usersSessionMapper.queryUsersSession(usersSession);
+            if (us != null) {
+                return true;
+            }
+            usersSession.setCreateTime(new Date());
+            int updates = usersSessionMapper.insertSelective(usersSession);
+
+            if (updates > 0) {
+                return true;
+            }
+        } catch (Exception e) {
+            logger.error("createUsersSession", e);
+        }
+        return false;
+    }
+
+
+    @Override
+    public boolean deleteUsersSession(String id) {
+
+        logger.info("deleteUsersSession");
+        try {
+
+            int updates = usersSessionMapper.delete(id);
+
+            if (updates > 0) {
+                return true;
+            }
+        } catch (Exception e) {
+            logger.error("deleteUsersSession", e);
+        }
+        return false;
+    }
+
+
+    @Override
+    public boolean updateUsersSession(UsersSession usersSession) {
+
+        logger.info("updateUsersSession");
+        try {
+
+            int updates = usersSessionMapper.updateByPrimaryKeySelective(usersSession);
+
+            if (updates > 0) {
+                return true;
+            }
+        } catch (Exception e) {
+            logger.error("updateUsersSession", e);
+        }
+        return false;
+    }
+
+}

+ 105 - 0
src/main/java/com/izouma/awesomeadmin/web/ChatInfoController.java

@@ -0,0 +1,105 @@
+package com.izouma.awesomeadmin.web;
+
+import com.izouma.awesomeadmin.constant.AppConstant;
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.dto.Result;
+import com.izouma.awesomeadmin.model.ChatInfo;
+import com.izouma.awesomeadmin.service.ChatInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Controller
+@RequestMapping("/chatInfo")
+public class ChatInfoController {
+
+    @Autowired
+    private ChatInfoService chatInfoService;
+
+    @RequestMapping(value = "/all", method = RequestMethod.GET)
+    @ResponseBody
+    public List<ChatInfo> all() {
+
+        List<ChatInfo> pp = chatInfoService.getChatInfoList();
+        return pp;
+    }
+
+    @RequestMapping(value = "/getChatInfo", method = RequestMethod.GET)
+    @ResponseBody
+    public Result getChatInfo(@RequestParam(required = false, value = "id") String id) {
+
+        ChatInfo data = chatInfoService.getChatInfoById(id);
+        return new Result(true, data);
+    }
+
+    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
+    @ResponseBody
+    public Result getOne(ChatInfo chatInfo) {
+
+        ChatInfo data = chatInfoService.getChatInfo(chatInfo);
+        return new Result(true, data);
+    }
+
+    @RequestMapping(value = "/page", method = RequestMethod.GET)
+    @ResponseBody
+    public Result page(Page page, ChatInfo chatInfo) {
+
+        Map<String, Object> result = new HashMap<>();
+
+        List<ChatInfo> pp = chatInfoService.getChatInfoByPage(page, chatInfo);
+
+        result.put(AppConstant.PAGE, page);
+        result.put("pp", pp);
+        return new Result(true, result);
+    }
+
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @ResponseBody
+    public Result save(ChatInfo chatInfo) {
+
+
+        boolean num = chatInfoService.createChatInfo(chatInfo);
+        if (num) {
+            return new Result(true, chatInfo);
+        }
+        return new Result(false, "保存异常");
+
+    }
+
+    @RequestMapping(value = "/update", method = RequestMethod.POST)
+    @ResponseBody
+    public Result updateChatInfo(ChatInfo chatInfo) {
+
+        boolean num = chatInfoService.updateChatInfo(chatInfo);
+        if (num) {
+            return new Result(true, "保存成功");
+        }
+        return new Result(false, "保存异常");
+    }
+
+    @RequestMapping(value = "/del", method = RequestMethod.POST)
+    @ResponseBody
+    public Result deleteChatInfoId(@RequestParam("id") String id) {
+
+        boolean num = chatInfoService.deleteChatInfo(id);
+        if (num) {
+            return new Result(true, "删除成功");
+        }
+        return new Result(false, "删除异常");
+    }
+
+
+    @RequestMapping(value = "/readAll", method = RequestMethod.GET)
+    @ResponseBody
+    public Result readAll(@RequestParam("userId") String userId, @RequestParam("toUserId") String toUserId) {
+        return new Result(chatInfoService.readAll(Integer.valueOf(userId), Integer.valueOf(toUserId)), "");
+    }
+
+}

+ 55 - 1
src/main/java/com/izouma/awesomeadmin/web/RongCloudController.java

@@ -2,11 +2,15 @@ package com.izouma.awesomeadmin.web;
 
 import com.izouma.awesomeadmin.constant.RongConstant;
 import com.izouma.awesomeadmin.dto.Result;
+import com.izouma.awesomeadmin.model.RongYunToken;
+import com.izouma.awesomeadmin.model.UserInfo;
 import com.izouma.awesomeadmin.service.RongYunTokenService;
+import com.izouma.awesomeadmin.service.UserInfoService;
 import com.izouma.awesomeadmin.util.PropertiesFileLoader;
 import io.rong.RongCloud;
 import io.rong.models.SMSSendCodeResult;
 import io.rong.models.SMSVerifyCodeResult;
+import io.rong.models.TokenResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,15 +19,20 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
 
 
 @Controller
 @RequestMapping("/rong")
-public class RongCloudController  {
+public class RongCloudController {
 
     @Autowired
     private RongYunTokenService rongYunTokenService;
 
+    @Autowired
+    private UserInfoService userService;
+
 
     private RongCloud rongCloud = RongCloud.getInstance(PropertiesFileLoader.getProperties("rongyunappkey"), PropertiesFileLoader.getProperties("rongyunappsecret"));
 
@@ -87,4 +96,49 @@ public class RongCloudController  {
 
         return new Result(false, "发送失败,请稍后重试");
     }
+
+    @RequestMapping(value = "/getToken", method = RequestMethod.GET)
+    @ResponseBody
+    public Map<String, Object> getToken(@RequestParam("rongKey") String rongKey) {
+
+        Map<String, Object> token = new HashMap<String, Object>();
+
+        String userToken = "";
+        RongYunToken ryt = rongYunTokenService.getRongToken(rongKey);
+        if (ryt != null) {
+            userToken = ryt.getToken();
+        } else {
+
+            try {
+                UserInfo userInfo = userService.getUserInfoById(rongKey);
+                TokenResult userGetTokenResult = rongCloud.user.getToken(rongKey, rongKey, userInfo != null ? userInfo.getIcon() : "http://www.rongcloud.cn/images/logo.png");
+                userToken = userGetTokenResult.getToken();
+
+                RongYunToken rong = new RongYunToken();
+
+                rong.setUserId(Long.valueOf(rongKey));
+                rong.setToken(userToken);
+                rongYunTokenService.saveRongToken(rong);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
+
+        token.put("token", userToken);
+        token.put("appKey", PropertiesFileLoader.getProperties("rongyunappkey"));
+        return token;
+    }
+
+    @RequestMapping(value = "/userInfo", method = RequestMethod.GET)
+    @ResponseBody
+    public Map<String, Object> getUserInfo(@RequestParam(required = true, value = "targetId") String targetId) {
+
+        Map<String, Object> token = new HashMap<String, Object>();
+
+        UserInfo uinfo = userService.getUserInfoById(targetId);
+        token.put("name", uinfo.getNickname());
+        token.put("portraitUri", uinfo.getIcon());
+        return token;
+    }
 }

+ 172 - 0
src/main/java/com/izouma/awesomeadmin/web/UsersSessionController.java

@@ -0,0 +1,172 @@
+package com.izouma.awesomeadmin.web;
+
+import com.izouma.awesomeadmin.constant.AppConstant;
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.dto.Result;
+import com.izouma.awesomeadmin.model.UsersSession;
+import com.izouma.awesomeadmin.service.UsersSessionService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * The type Users session controller.
+ */
+@Controller
+@RequestMapping("/usersSession")
+public class UsersSessionController {
+
+    @Autowired
+    private UsersSessionService usersSessionService;
+
+
+    /**
+     * <p>获取全部记录。</p>
+     *
+     * @param userId the user id
+     * @return result
+     */
+    @RequestMapping(value = "/all", method = RequestMethod.GET)
+    @ResponseBody
+    public Result all(@RequestParam(required = false, value = "userId") String userId) {
+
+        List<UsersSession> pp = usersSessionService.getUsersSessionList(userId);
+        return new Result(true, pp);
+    }
+
+
+    /**
+     * <p>根据Id。</p>
+     *
+     * @param id the id
+     * @return users session
+     */
+    @RequestMapping(value = "/getUsersSession", method = RequestMethod.GET)
+    @ResponseBody
+    public Result getUsersSession(@RequestParam(required = false, value = "id") String id) {
+
+        UsersSession data = usersSessionService.getUsersSessionById(id);
+        return new Result(true, data);
+    }
+
+
+    /**
+     * <p>根据条件获取。</p>
+     *
+     * @param usersSession the users session
+     * @return one
+     */
+    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
+    @ResponseBody
+    public Result getOne(UsersSession usersSession) {
+
+        UsersSession data = usersSessionService.getUsersSession(usersSession);
+        return new Result(true, data);
+    }
+
+
+    /**
+     * Page result.
+     *
+     * @param page         the page
+     * @param usersSession the users session
+     * @return the result
+     */
+    @RequestMapping(value = "/page", method = RequestMethod.GET)
+    @ResponseBody
+    public Result page(Page page, UsersSession usersSession) {
+
+        Map<String, Object> result = new HashMap<>();
+
+        List<UsersSession> pp = usersSessionService.getUsersSessionByPage(page, usersSession);
+
+        result.put(AppConstant.PAGE, page);
+        result.put("pp", pp);
+        return new Result(true, result);
+    }
+
+
+    /**
+     * <p>后台获取。</p>
+     *
+     * @param page         the page
+     * @param usersSession the users session
+     * @param companyId    the company id
+     * @return result
+     */
+    @RequestMapping(value = "/pageAll", method = RequestMethod.GET)
+    @ResponseBody
+    public Result pageAll(Page page, UsersSession usersSession, String companyId) {
+
+        Map<String, Object> result = new HashMap<>();
+
+        List<UsersSession> pp = usersSessionService.queryAllUsersSessionByPage(page, usersSession, companyId);
+        result.put(AppConstant.PAGE, page);
+        result.put("pp", pp);
+        return new Result(true, result);
+    }
+
+
+    /**
+     * <p>保存。</p>
+     *
+     * @param usersSession the users session
+     * @return result
+     */
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @ResponseBody
+    public Result save(UsersSession usersSession) {
+
+        boolean num = usersSessionService.createUsersSession(usersSession);
+        if (num) {
+            return new Result(true, "保存成功");
+        }
+        return new Result(false, "保存异常");
+
+    }
+
+
+    /**
+     * <p>更新信息。</p>
+     *
+     * @param usersSession the users session
+     * @return result
+     */
+    @RequestMapping(value = "/update", method = RequestMethod.POST)
+    @ResponseBody
+    public Result updateUsersSession(UsersSession usersSession) {
+
+        boolean num = usersSessionService.updateUsersSession(usersSession);
+        if (num) {
+            return new Result(true, "保存成功");
+        }
+        return new Result(false, "保存异常");
+    }
+
+
+    /**
+     * <p>删除。</p>
+     *
+     * @param id the id
+     * @return result
+     */
+    @RequestMapping(value = "/del", method = RequestMethod.POST)
+    @ResponseBody
+    public Result deleteUsersSessionId(@RequestParam(required = true, value = "id") String id) {
+
+        boolean num = usersSessionService.deleteUsersSession(id);
+        if (num) {
+            return new Result(true, "删除成功");
+        }
+        return new Result(false, "删除异常");
+    }
+
+}

+ 2 - 2
src/main/resources/properties/outsidews.properties

@@ -7,8 +7,8 @@ aliosskey=e1MS6j0wypXJrw8CM0hObZu8qKbfah
 aliossendpoit=http://oss-cn-hangzhou.aliyuncs.com
 alibucketname=microball
 aliImageSever=http://oss.izouma.com
-rongyunappkey=pwe86ga5ee376
-rongyunappsecret=ARj0hyU5Cp
+rongyunappkey=n19jmcy5n1qy9
+rongyunappsecret=z4pJJH6nSqJ
 jwtsecret=3MgWy/pJjxHCQW2pHlQbkjomTUPRo9WhsPFjUPYZZlo=
 host=http://1eaed69e.ngrok.io
 base_domain=http://localhost:8080