MsgMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.zhyc.xps.common.mapper.MsgMapper">
  4. <resultMap id="MsgDtoResultMap" type="com.zhyc.xps.common.dto.MsgDto" >
  5. <result column="oc_id" property="ocId" jdbcType="BIGINT" />
  6. <result column="msg_id" property="msgId" jdbcType="BIGINT" />
  7. <result column="msg_fr_id" property="msgFrId" jdbcType="BIGINT" />
  8. <result column="msg_to_group" property="msgToGroup" jdbcType="VARCHAR" />
  9. <result column="msg_cc" property="msgCc" jdbcType="VARCHAR" />
  10. <result column="msg_to" property="msgTo" jdbcType="VARCHAR" />
  11. <result column="msg_cat_id" property="msgCatId" jdbcType="BIGINT" />
  12. <result column="msg_content" property="msgContent" jdbcType="VARCHAR" />
  13. <result column="msg_time" property="msgTime" jdbcType="TIMESTAMP"/>
  14. <result column="status" property="status" jdbcType="BIGINT" />
  15. <result column="msg_fr_name" property="msgFrName" jdbcType="VARCHAR" />
  16. <result column="msg_fr_real_name" property="msgFrRealName" jdbcType="VARCHAR" />
  17. <result column="msg_fr_avatar" property="msgFrAvatar" jdbcType="VARCHAR" />
  18. <result column="msg_cat_title" property="msgCatTitle" jdbcType="VARCHAR" />
  19. <result column="is_link" property="isLink" jdbcType="BIGINT" />
  20. <result column="msg_cat_link" property="msgCatLink" jdbcType="VARCHAR" />
  21. <result column="msg_cat_link_params" property="msgCatLinkParams" jdbcType="VARCHAR" />
  22. <result column="msg_params" property="msgParams" jdbcType="VARCHAR" />
  23. <result column="is_detailed" property="isDetailed" jdbcType="BIGINT" />
  24. <result column="is_read" property="isRead" jdbcType="BIGINT" />
  25. </resultMap>
  26. <resultMap id="MsgDetailDtoResultMap" type="com.zhyc.xps.common.dto.MsgDetailDto" >
  27. <result column="oc_id" property="ocId" jdbcType="BIGINT" />
  28. <result column="msg_id" property="msgId" jdbcType="BIGINT" />
  29. <result column="msg_fr_id" property="msgFrId" jdbcType="BIGINT" />
  30. <result column="msg_fr_name" property="msgFrName" jdbcType="VARCHAR" />
  31. <result column="msg_fr_real_name" property="msgFrRealName" jdbcType="VARCHAR" />
  32. <result column="msg_fr_avatar" property="msgFrAvatar" jdbcType="VARCHAR" />
  33. <result column="msg_cat_id" property="msgCatId" jdbcType="BIGINT" />
  34. <result column="msg_cat_title" property="msgCatTitle" jdbcType="VARCHAR" />
  35. <result column="is_link" property="isLink" jdbcType="BIGINT" />
  36. <result column="msg_cat_link" property="msgCatLink" jdbcType="VARCHAR" />
  37. <result column="msg_cat_link_params" property="msgCatLinkParams" jdbcType="VARCHAR" />
  38. <result column="msg_params" property="msgParams" jdbcType="VARCHAR" />
  39. <result column="is_detailed" property="isDetailed" jdbcType="BIGINT" />
  40. <result column="msg_to_group" property="msgToGroup" jdbcType="VARCHAR" />
  41. <result column="msg_cc" property="msgCc" jdbcType="VARCHAR" />
  42. <result column="msg_to" property="msgTo" jdbcType="VARCHAR" />
  43. <result column="msg_time" property="msgTime" jdbcType="TIMESTAMP"/>
  44. <result column="status" property="status" jdbcType="BIGINT" />
  45. <result column="msg_content" property="msgContent" jdbcType="VARCHAR" />
  46. <result column="msg_detail" property="msgDetail" jdbcType="VARCHAR" />
  47. </resultMap>
  48. <sql id="MsgDto_Cols">
  49. M.oc_id,
  50. M.msg_id,
  51. M.msg_fr_id,
  52. A.account_name AS msg_fr_name,
  53. A.account_real_name AS msg_fr_real_name,
  54. A.account_avatar AS msg_fr_avatar,
  55. M.msg_to_group,
  56. M.msg_cc,
  57. M.msg_to,
  58. M.msg_content,
  59. M.msg_cat_id,
  60. MC.msg_cat_title,
  61. MC.is_link,
  62. MC.msg_cat_link,
  63. MC.msg_cat_link_params,
  64. M.msg_params,
  65. MC.is_detailed,
  66. M.status,
  67. IFNULL(CASE WHEN B.status > 0 THEN B.status ELSE C.status END, 0) AS is_read,
  68. M.msg_time
  69. </sql>
  70. <sql id="MsgDetailDto_Cols">
  71. M.oc_id,
  72. M.msg_id,
  73. M.msg_fr_id,
  74. A.account_name AS msg_fr_name,
  75. A.account_real_name AS msg_fr_real_name,
  76. A.account_avatar AS msg_fr_avatar,
  77. M.msg_to_group,
  78. M.msg_cc,
  79. M.msg_to,
  80. M.msg_content,
  81. M.msg_detail,
  82. M.msg_cat_id,
  83. MC.msg_cat_title,
  84. MC.is_link,
  85. MC.msg_cat_link,
  86. MC.msg_cat_link_params,
  87. M.msg_params,
  88. MC.is_detailed,
  89. M.status,
  90. M.msg_time
  91. </sql>
  92. <!--列表查询-->
  93. <select id="getByList" parameterType="java.util.Map" resultMap="MsgDtoResultMap">
  94. SELECT
  95. <include refid="MsgDto_Cols"/>
  96. FROM msg AS M
  97. LEFT JOIN account AS A ON (M.oc_id = A.oc_id AND M.msg_fr_id = A.account_id)
  98. LEFT JOIN msg_to AS B ON (M.oc_id = B.oc_id AND M.msg_id = B.msg_id AND B.msg_to_id=#{msgToCc, jdbcType=BIGINT})
  99. LEFT JOIN msg_cc AS C ON (M.oc_id = C.oc_id AND M.msg_id = C.msg_id AND C.msg_cc_id=#{msgToCc, jdbcType=BIGINT})
  100. LEFT JOIN msg_cat AS MC ON (MC.msg_cat_id = M.msg_cat_id)
  101. WHERE M.deleted_flag = 0
  102. <if test="ocId != null">
  103. AND M.oc_id = #{ocId,jdbcType=BIGINT}
  104. </if>
  105. <if test="msgFrId != null">
  106. AND M.msg_fr_id = #{msgFrId, jdbcType=BIGINT}
  107. </if>
  108. <if test="msgToCc != null">
  109. AND (
  110. EXISTS (
  111. SELECT 1 FROM msg_to TT
  112. WHERE M.oc_id = TT.oc_id AND M.msg_id = TT.msg_id AND TT.msg_to_id = #{msgToCc, jdbcType=BIGINT}
  113. ) OR
  114. EXISTS (
  115. SELECT 1 FROM msg_cc CC
  116. WHERE M.oc_id = CC.oc_id AND M.msg_id = CC.msg_id AND CC.msg_cc_id = #{msgToCc, jdbcType=BIGINT}
  117. )
  118. )
  119. </if>
  120. ORDER BY M.created_at DESC
  121. </select>
  122. <!--分页查询-->
  123. <select id="getByPage" parameterType="java.util.Map" resultMap="MsgDtoResultMap">
  124. SELECT
  125. <include refid="MsgDto_Cols"/>
  126. FROM msg AS M
  127. LEFT JOIN account AS A ON ( M.oc_id = A.oc_id AND M.msg_fr_id = A.account_id)
  128. LEFT JOIN msg_to AS B ON ( M.oc_id = B.oc_id AND M.msg_id = B.msg_id AND B.msg_to_id=#{msgToCc, jdbcType=BIGINT})
  129. LEFT JOIN msg_cc AS C ON ( M.oc_id = C.oc_id AND M.msg_id = C.msg_id AND C.msg_cc_id=#{msgToCc, jdbcType=BIGINT})
  130. LEFT JOIN msg_cat AS MC ON ( MC.msg_cat_id = M.msg_cat_id)
  131. WHERE M.deleted_flag = 0
  132. <if test="ocId != null">
  133. AND M.oc_id = #{ocId,jdbcType=BIGINT}
  134. </if>
  135. <if test="msgFrId != null">
  136. AND M.msg_fr_id = #{msgFrId,jdbcType=BIGINT}
  137. </if>
  138. <if test="msgToCc != null">
  139. AND (
  140. EXISTS (
  141. SELECT 1 FROM msg_to TT
  142. WHERE M.oc_id = TT.oc_id AND M.msg_id = TT.msg_id AND TT.msg_to_id = #{msgToCc, jdbcType=BIGINT}
  143. ) OR
  144. EXISTS (
  145. SELECT 1 FROM msg_cc CC
  146. WHERE M.oc_id = CC.oc_id AND M.msg_id = CC.msg_id AND CC.msg_cc_id = #{msgToCc, jdbcType=BIGINT}
  147. )
  148. )
  149. </if>
  150. ORDER BY M.created_at DESC
  151. </select>
  152. <!--基于ID查询-->
  153. <select id="getById" resultMap="MsgDetailDtoResultMap">
  154. SELECT
  155. <include refid="MsgDetailDto_Cols"/>
  156. FROM msg AS M
  157. LEFT JOIN account AS A ON (M.oc_id = A.oc_id AND M.msg_fr_id = A.account_id)
  158. LEFT JOIN msg_cat AS MC ON (MC.msg_cat_id = M.msg_cat_id)
  159. WHERE M.deleted_flag = 0
  160. <if test="ocId != null">
  161. AND M.oc_id = #{ocId, jdbcType=BIGINT}
  162. </if>
  163. <if test="msgId != null">
  164. AND M.msg_id = #{msgId, jdbcType=BIGINT}
  165. </if>
  166. </select>
  167. <!--新增Create-->
  168. <insert id="create" parameterType="com.zhyc.xps.common.entity.Msg">
  169. INSERT INTO msg
  170. <trim prefix="(" suffix=")" suffixOverrides=",">
  171. <if test="ocId != null">
  172. oc_id,
  173. </if>
  174. <if test="msgId != null">
  175. msg_id,
  176. </if>
  177. <if test="msgFrId != null">
  178. msg_fr_id,
  179. </if>
  180. <if test="msgToGroup != null and msgToGroup != ''">
  181. msg_to_group,
  182. </if>
  183. <if test="msgTo != null and msgTo != ''">
  184. msg_to,
  185. </if>
  186. <if test="msgCc != null and msgCc != ''">
  187. msg_cc,
  188. </if>
  189. <if test="msgCatId != null">
  190. msg_cat_id,
  191. </if>
  192. <if test="msgContent != null and msgContent != ''">
  193. msg_content,
  194. </if>
  195. <if test="msgDetail != null and msgDetail !=''">
  196. msg_detail,
  197. </if>
  198. <if test="msgTime != null">
  199. msg_time,
  200. </if>
  201. <if test="msgParams != null and msgParams !=''">
  202. msg_params,
  203. </if>
  204. <if test="createdBy != null">
  205. created_by,
  206. </if>
  207. <if test="createdAt != null">
  208. created_at,
  209. </if>
  210. </trim>
  211. <trim prefix="values (" suffix=")" suffixOverrides=",">
  212. <if test="ocId != null">
  213. #{ocId,jdbcType=BIGINT},
  214. </if>
  215. <if test="msgId != null">
  216. #{msgId,jdbcType=BIGINT},
  217. </if>
  218. <if test="msgFrId != null">
  219. #{msgFrId,jdbcType=BIGINT},
  220. </if>
  221. <if test="msgToGroup != null and msgToGroup !=''">
  222. #{msgToGroup,jdbcType=VARCHAR},
  223. </if>
  224. <if test="msgTo != null and msgTo != ''">
  225. #{msgTo,jdbcType=VARCHAR},
  226. </if>
  227. <if test="msgCc != null and msgCc != ''">
  228. #{msgCc,jdbcType=VARCHAR},
  229. </if>
  230. <if test="msgCatId != null">
  231. #{msgCatId,jdbcType=BIGINT},
  232. </if>
  233. <if test="msgContent != null and msgContent != ''">
  234. #{msgContent,jdbcType=VARCHAR},
  235. </if>
  236. <if test="msgDetail != null and msgDetail != ''">
  237. #{msgDetail,jdbcType=VARCHAR},
  238. </if>
  239. <if test="msgTime != null">
  240. #{msgTime,jdbcType=TIMESTAMP},
  241. </if>
  242. <if test="msgParams != null and msgParams !=''">
  243. #{msgParams, jdbcType=VARCHAR},
  244. </if>
  245. <if test="createdBy != null">
  246. #{createdBy,jdbcType=BIGINT},
  247. </if>
  248. <if test="createdAt != null">
  249. #{createdAt,jdbcType=TIMESTAMP},
  250. </if>
  251. </trim>
  252. </insert>
  253. <!--更新-->
  254. <update id="update" parameterType="com.zhyc.xps.common.entity.Msg">
  255. UPDATE msg
  256. <trim suffixOverrides=",">
  257. <set>
  258. <if test="msgFrId != null">
  259. msg_fr_id = #{msgFrId ,jdbcType=BIGINT},
  260. </if>
  261. <if test="msgToGroup != null and msgToGroup !=''">
  262. msg_to_group = #{msgToGroup ,jdbcType=VARCHAR},
  263. </if>
  264. <if test="msgTo != null and msgTo !=''">
  265. msg_to = #{msgTo ,jdbcType=VARCHAR},
  266. </if>
  267. <if test="msgCc != null and msgCc != ''">
  268. msg_cc = #{msgCc ,jdbcType=VARCHAR},
  269. </if>
  270. <if test="msgCatId != null">
  271. msg_cat_id = #{msgCatId ,jdbcType=BIGINT},
  272. </if>
  273. <if test="msgContent != null and msgContent != ''">
  274. msg_content =#{msgContent ,jdbcType=VARCHAR},
  275. </if>
  276. <if test="msgDetail != null and msgDetail != ''">
  277. msg_detail = #{msgDetail ,jdbcType=VARCHAR},
  278. </if>
  279. <if test="msgParams != null and msgParams !=''">
  280. msg_params = #{msgParams, jdbcType=VARCHAR},
  281. </if>
  282. <if test="updatedBy != null">
  283. updated_by = #{updatedBy ,jdbcType=BIGINT},
  284. </if>
  285. <if test="updatedAt != null">
  286. updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
  287. </if>
  288. </set>
  289. </trim>
  290. WHERE msg_id = #{msgId ,jdbcType=BIGINT}
  291. <if test="ocId != null">
  292. AND oc_id = #{ocId ,jdbcType=BIGINT}
  293. </if>
  294. </update>
  295. <!--删除-->
  296. <update id="delete" parameterType="java.util.Map">
  297. UPDATE msg
  298. <trim suffixOverrides=",">
  299. <set>
  300. <if test="deletedBy != null">
  301. deleted_by = #{deletedBy ,jdbcType=BIGINT},
  302. </if>
  303. <if test="deletedAt != null">
  304. deleted_at = #{deletedAt ,jdbcType=DATE},
  305. </if>
  306. <if test="deletedFlag != null">
  307. deleted_flag = #{deletedFlag ,jdbcType=BIGINT},
  308. </if>
  309. </set>
  310. </trim>
  311. WHERE 1 = 1 AND deleted_flag = 0
  312. <if test="ocId != null">
  313. AND oc_id = #{ocId,jdbcType=BIGINT}
  314. </if>
  315. <if test="msgId != null ">
  316. AND msg_id = #{msgId ,jdbcType=BIGINT}
  317. </if>
  318. </update>
  319. <select id="getUnReadCount" resultType="int">
  320. SELECT count(*)
  321. FROM msg AS M
  322. WHERE M.oc_id = #{ocId,jdbcType=BIGINT}
  323. AND (
  324. EXISTS (
  325. SELECT 1 FROM msg_to TT
  326. WHERE M.oc_id = TT.oc_id AND M.msg_id = TT.msg_id AND TT.msg_to_id = #{msgToCc, jdbcType=BIGINT} AND TT.status=0
  327. ) OR
  328. EXISTS (
  329. SELECT 1 FROM msg_cc CC
  330. WHERE M.oc_id = CC.oc_id AND M.msg_id = CC.msg_id AND CC.msg_cc_id = #{msgToCc, jdbcType=BIGINT} AND CC.status=0
  331. )
  332. )
  333. </select>
  334. </mapper>