liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?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.jeeplus.modules.iim.dao.ChatHistoryDao">
    
    <sql id="chatHistoryColumns">
        a.id AS "id",
        a.userid1 AS "userid1",
        a.userid2 AS "userid2",
        a.msg AS "msg",
        a.status AS "status",
        a.create_date AS "createDate"
    </sql>
    
    <sql id="chatHistoryJoins">
    </sql>
    
    <select id="get" resultType="ChatHistory">
        SELECT 
            <include refid="chatHistoryColumns"/>
        FROM iim_chat_history a
        <include refid="chatHistoryJoins"/>
        WHERE a.id = #{id}
    </select>
    
    <select id="findList" resultType="ChatHistory">
        SELECT 
            <include refid="chatHistoryColumns"/>
        FROM iim_chat_history a
        <include refid="chatHistoryJoins"/>
        <where>
            
            <if test="userid1 != null and userid1 != ''">
                AND a.userid1 = #{userid1}
            </if>
            <if test="userid2 != null and userid2 != ''">
                AND a.userid2 = #{userid2}
            </if>
            <if test="msg != null and msg != ''">
                AND a.msg LIKE 
                    <if test="dbName == 'oracle'">'%'||#{msg}||'%'</if>
                    <if test="dbName == 'mssql'">'%'+#{msg}+'%'</if>
                    <if test="dbName == 'mysql'">concat('%',#{msg},'%')</if>
            </if>
            <if test="status != null and status != ''">
                AND a.status = #{status}
            </if>
            <if test="createDate != null and createDate != ''">
                AND a.create_date = #{createDate}
            </if>
        </where>
                ORDER BY a.create_date asc
    </select>
    
    <select id="findLogList" resultType="ChatHistory">
        SELECT 
            <include refid="chatHistoryColumns"/>
        FROM iim_chat_history a
        <include refid="chatHistoryJoins"/>
        <where>
            
            <if test="userid1 != null and userid1 != '' and userid2 != null and userid2 != ''">
                AND  ((a.userid1 = #{userid1} AND a.userid2 = #{userid2}) or  (a.userid1 = #{userid2} AND a.userid2 = #{userid1}))
            </if>
            <if test="msg != null and msg != ''">
                AND a.msg LIKE 
                    <if test="dbName == 'oracle'">'%'||#{msg}||'%'</if>
                    <if test="dbName == 'mssql'">'%'+#{msg}+'%'</if>
                    <if test="dbName == 'mysql'">concat('%',#{msg},'%')</if>
            </if>
            <if test="status != null and status != ''">
                AND a.status = #{status}
            </if>
            <if test="createDate != null and createDate != ''">
                AND a.create_date = #{createDate}
            </if>
        </where>
                ORDER BY a.create_date desc
    </select>
    
    <select id="findAllList" resultType="ChatHistory">
        SELECT 
            <include refid="chatHistoryColumns"/>
        FROM iim_chat_history a
        <include refid="chatHistoryJoins"/>
        <where>
            
        </where>        
        ORDER BY a.create_date asc
    </select>
    
    <insert id="insert">
        INSERT INTO iim_chat_history(
            id,
            userid1,
            userid2,
            msg,
            status,
            create_date
        ) VALUES (
            #{id},
            #{userid1},
            #{userid2},
            #{msg},
            #{status},
            #{createDate}
        )
    </insert>
    
    <update id="update">
        UPDATE iim_chat_history SET     
            userid1 = #{userid1},
            userid2 = #{userid2},
            msg = #{msg},
            status = #{status},
            create_date = #{createDate}
        WHERE id = #{id}
    </update>
    
    <update id="delete">
        DELETE FROM iim_chat_history
        WHERE id = #{id}
    </update>
    
    <!-- 查询全部用户数目 -->
    <select id="findUnReadCount" resultType="int">
        SELECT
            COUNT(1)
        FROM iim_chat_history a WHERE
                a.userid1 = #{userid2} AND a.userid2 = #{userid1}
                AND a.status = '0'
    </select>
    
</mapper>