Blame view

backend/portal/src/main/resources/mapper/SysMessageMapper.xml 10.6 KB
8ea9c133   陈威   初始化提交
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?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.hotent.portal.persistence.dao.SysMessageDao">
	<resultMap id="SysMessage" type="com.hotent.portal.model.SysMessage">
		<id property="id" column="id_" jdbcType="VARCHAR"/>
		<result property="subject" column="subject_" jdbcType="VARCHAR"/>
		<result property="ownerId" column="owner_id_" jdbcType="VARCHAR"/>
		<result property="owner" column="owner_" jdbcType="VARCHAR"/>
		<result property="messageType" column="message_type_" jdbcType="VARCHAR"/>
		<result property="canReply" column="can_reply_" jdbcType="NUMERIC"/>
		<result property="isPublic" column="is_public_" jdbcType="NUMERIC"/>
		<result property="content" column="content_" jdbcType="LONGVARCHAR"/>
		<result property="fileMsg" column="file_msg_" jdbcType="VARCHAR"/>
		<result property="receiverName" column="receiver_name_" jdbcType="VARCHAR"/>
		<result property="createBy" column="CREATE_BY_" jdbcType="VARCHAR"/>
		<result property="createOrgId" column="CREATE_ORG_ID_" jdbcType="VARCHAR"/>
		<result property="createTime" column="CREATE_TIME_" jdbcType="TIMESTAMP"/>
		<result property="updateBy" column="UPDATE_BY_" jdbcType="VARCHAR"/>
		<result property="updateTime" column="UPDATE_TIME_" jdbcType="TIMESTAMP"/>
	</resultMap>
	
	<select id="getMsgByUserId" parameterType="java.util.Map" resultType="com.hotent.portal.model.SysMessage">
		SELECT 
		   id, subject, owner,  messageType,  createTime, 
		    canReply,  isPublic,  rid, receivetime
		FROM(
			SELECT 
			   send.id_ id,send.subject_ subject, send.owner_ as owner,
			   send.message_type_ messageType, send.create_time_ createTime, 
			   send.can_reply_ canReply, send.is_public_ isPublic, rece.id_ rid,
			   red.receiver_time_ receivetime FROM
			   portal_sys_msg send 
			LEFT JOIN portal_sys_msg_read red ON send.id_=red.msg_id_ and red.receiver_id_=#{map.receiverId} , 
			portal_sys_msg_receiver rece
			WHERE
				 send.id_=rece.msg_id_
			   and   rece.receiver_id_=#{map.receiverId}
		    <if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.subject) or @com.hotent.base.ognl.Ognl@isNotEmpty(map.content)">
		    	AND (
		    		<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.subject)">send.subject_ LIKE #{map.subject} </if>
		    		<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.subject) and @com.hotent.base.ognl.Ognl@isNotEmpty(map.content)"> or </if>
					<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.content)"> send.content_ LIKE #{map.content} </if>
				)
		    </if>
	        <if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.messageType)"> AND send.message_type_ LIKE #{map.messageType} </if>
	        <if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.beginreceiveTime)"> AND send.create_time_>=#{map.beginreceiveTime,jdbcType=TIMESTAMP}</if>
			<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.endreceiveTime)"> AND send.create_time_ &lt;=#{map.endreceiveTime,jdbcType=TIMESTAMP}</if>
			<if test="map.receiveTime == 1"> AND red.receiver_time_ is null  </if>
	        <if test="map.receiveTime == 2"> AND red.receiver_time_ is not null </if>
			UNION
			SELECT 
			   send1.id_ id,send1.subject_ subject, send1.owner_ as owner,
			   send1.message_type_ messageType, send1.create_time_ createTime, 
			   send1.can_reply_ canReply, send1.is_public_ isPublic, send1.id_ rid,
			   red1.receiver_time_ receivetime FROM
			   portal_sys_msg send1 
			LEFT JOIN portal_sys_msg_read red1 ON send1.id_=red1.msg_id_ and red1.receiver_id_=#{map.receiverId}
			WHERE
				 send1.is_public_=1
			<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.subject) or @com.hotent.base.ognl.Ognl@isNotEmpty(map.content)">
		    	AND (
		    		<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.subject)">send1.subject_ LIKE #{map.subject} </if>
		    		<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.subject) and @com.hotent.base.ognl.Ognl@isNotEmpty(map.content)"> or </if>
					<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.content)"> send1.content_ LIKE #{map.content} </if>
				)
		    </if>
	        <if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.messageType)"> AND send1.message_type_ LIKE #{map.messageType} </if>
	        <if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.beginreceiveTime)"> AND send1.create_time_>=#{map.beginreceiveTime,jdbcType=TIMESTAMP}</if>
			<if test="@com.hotent.base.ognl.Ognl@isNotEmpty(map.endreceiveTime)"> AND send1.create_time_ &lt;=#{map.endreceiveTime,jdbcType=TIMESTAMP}</if>
			<if test="map.receiveTime == 1"> AND red1.receiver_time_ is null  </if>
	        <if test="map.receiveTime == 2"> AND red1.receiver_time_ is not null </if>
			
		)temp
		<choose>
			<when test= 'map.receiveTime == 2 and map.receiveTimeOrder == "asc"'>
				ORDER BY receivetime asc
			</when>
			<when test= 'map.receiveTime == 2 and map.receiveTimeOrder == "desc"'>
				ORDER BY receivetime desc
			</when>
			<otherwise>
				ORDER BY createTime desc
			</otherwise>
		</choose>
	</select>
	
	<select id="getNotReadMsgByUserId" resultMap="SysMessage">
	     <if test="isPublish == 0">
	    	SELECT a.id_,a.subject_,a.owner_id_,a.message_type_
	    	FROM portal_sys_msg a,portal_sys_msg_receiver b where a.id_=b.msg_id_ 
			and (b.receiver_id_=#{receiverId} or b.receiver_id_ in (SELECT c.group_id_ FROM XOG_USER_GROUP c where c.user_id_=#{receiverId}))
			and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId}) and a.is_public_=0 order by a.create_time_ desc
		</if>
		<if test="isPublish == 1">
		    SELECT a.id_,a.subject_,a.owner_id_,a.message_type_
	    	FROM portal_sys_msg a
			where a.is_public_=1
			and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId})  order by a.create_time_ desc
		</if>
		
	</select>
	
	
		
	<select id="getOneNotReadMsgByUserIdOracle" resultMap="SysMessage">
		    SELECT * 
		    FROM(
			    SELECT  *
					FROM(
						SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
				    	FROM portal_sys_msg a,portal_sys_msg_receiver b where a.id_=b.msg_id_ 
						and (b.receiver_id_=#{receiverId} or b.receiver_id_ in (SELECT c.group_id_ FROM XOG_USER_GROUP c where c.user_id_=#{receiverId}))
						and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId}) and a.is_public_=0 
						UNION
						SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
				    	FROM portal_sys_msg a
						where a.is_public_=1
						and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId})
					) temp
				order by create_time_ desc 
			) temp1 where rownum &lt;=1
		
	</select>
	
	<select id="getOneNotReadMsgByUserIdMysql" resultMap="SysMessage">
		    SELECT  *
			FROM(
				SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
		    	FROM portal_sys_msg a,portal_sys_msg_receiver b where a.id_=b.msg_id_ 
				and (b.receiver_id_=#{receiverId} or b.receiver_id_ in (SELECT c.group_id_ FROM XOG_USER_GROUP c where c.user_id_=#{receiverId}))
				and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId}) and a.is_public_=0 
				UNION
				SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
		    	FROM portal_sys_msg a
				where a.is_public_=1
				and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId})
			) temp
			order by create_time_ desc limit 1
		
	</select>
	
	<select id="getOneNotReadMsgByUserIdMssql" resultMap="SysMessage">
		    SELECT top 1 *
			FROM(
				SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
		    	FROM portal_sys_msg a,portal_sys_msg_receiver b where a.id_=b.msg_id_ 
				and (b.receiver_id_=#{receiverId} or b.receiver_id_ in (SELECT c.group_id_ FROM XOG_USER_GROUP c where c.user_id_=#{receiverId}))
				and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId}) and a.is_public_=0 
				UNION
				SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
		    	FROM portal_sys_msg a
				where a.is_public_=1
				and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId})
			) temp
			order by create_time_ desc
		
	</select>
	
	<select id="getOneNotReadMsgByUserIdDb2" resultMap="SysMessage">
	      SELECT * 
		    FROM(
			    SELECT  *
				FROM(
					SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
			    	FROM portal_sys_msg a,portal_sys_msg_receiver b where a.id_=b.msg_id_ 
					and (b.receiver_id_=#{receiverId} or b.receiver_id_ in (SELECT c.group_id_ FROM XOG_USER_GROUP c where c.user_id_=#{receiverId}))
					and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId}) and a.is_public_=0 
					UNION
					SELECT a.id_,a.subject_,a.owner_,a.message_type_,a.content_,a.create_time_,a.can_reply_
			    	FROM portal_sys_msg a
					where a.is_public_=1
					and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId})
				) temp
				order by create_time_ desc
			) temp1 where rownum &lt;=1
	</select>
	
	 <select id="getNotReadMsgNum" resultType="java.lang.Integer">
	    SELECT count(id_)
			FROM(
				SELECT a.id_
		    	FROM portal_sys_msg a,portal_sys_msg_receiver b where a.id_=b.msg_id_ 
				and (b.receiver_id_=#{receiverId})
				and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId}) and a.is_public_=0 
				UNION
				SELECT a.id_
		    	FROM portal_sys_msg a
				where a.is_public_=1
				and not exists (SELECT 1 FROM portal_sys_msg_read d where a.id_=d.msg_id_ and d.receiver_id_=#{receiverId})
			) temp
	</select>
	
	<select id="getMsgSize" parameterType="java.lang.String" resultType="java.lang.Integer">
		SELECT count(id)
		FROM(
			SELECT 
			   send.id_ id, rece.id_ rid,
			   red.receiver_time_ receivetime FROM
			   portal_sys_msg send 
			LEFT JOIN portal_sys_msg_read red ON send.id_=red.msg_id_ and red.receiver_id_=#{receiverId} , 
			portal_sys_msg_receiver rece
			WHERE
				 send.id_=rece.msg_id_
			   and   rece.receiver_id_=#{receiverId}
			
			UNION
			SELECT 
			   	send1.id_ id,send1.is_public_ isPublic, send1.id_ rid,
			    red1.receiver_time_ receivetime FROM
			   portal_sys_msg send1 
			LEFT JOIN portal_sys_msg_read red1 ON send1.id_=red1.msg_id_ and red1.receiver_id_=#{receiverId}
			WHERE
				 send1.is_public_=1	
		)temp
		 where  receivetime is null
			ORDER BY rid DESC
	</select>
</mapper>