OaNotifyMapper.xml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.jeeplus.modules.oa.mapper.OaNotifyMapper">
  4. <sql id="oaNotifyColumns">
  5. a.ID AS "id",
  6. a.TYPE AS "type",
  7. a.TITLE AS "title",
  8. a.CONTENT AS "content",
  9. a.FILES AS "files",
  10. a.STATUS AS "status",
  11. a.CREATE_BY AS "createBy.id",
  12. a.CREATE_DATE AS "createDate",
  13. a.UPDATE_BY AS "updateBy.id",
  14. a.UPDATE_DATE AS "updateDate",
  15. a.REMARKS AS "remarks",
  16. a.DEL_FLAG AS "delFlag",
  17. b.read_num,
  18. b.un_read_num
  19. </sql>
  20. <sql id="oaNotifyJoins">
  21. <!-- 查询已读和未读条数 -->
  22. LEFT JOIN (
  23. SELECT r.oa_notify_id,
  24. sum(case when r.read_flag = '1' then 1 else 0 end) read_num,
  25. sum(case when r.read_flag != '1' then 1 else 0 end) un_read_num
  26. FROM oa_notify_record r GROUP BY r.oa_notify_id
  27. ) b ON b.oa_notify_id = a.id
  28. </sql>
  29. <select id="get" resultType="OaNotify">
  30. SELECT
  31. <include refid="oaNotifyColumns"/>
  32. FROM oa_notify a
  33. <include refid="oaNotifyJoins"/>
  34. WHERE a.id = #{id}
  35. </select>
  36. <select id="findList" resultType="OaNotify">
  37. SELECT
  38. <include refid="oaNotifyColumns"/>
  39. <if test="isSelf">,
  40. r.read_flag AS "readFlag"
  41. </if>
  42. FROM oa_notify a
  43. <include refid="oaNotifyJoins"/>
  44. <!-- 我的通知 -->
  45. <if test="isSelf">
  46. JOIN oa_notify_record r ON r.oa_notify_id = a.id AND r.user_id = #{currentUser.id}
  47. <if test="readFlag != null and readFlag != ''">
  48. AND r.read_flag = #{readFlag}
  49. </if>
  50. </if>
  51. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  52. <if test="title != null and title != ''">
  53. AND a.TITLE LIKE
  54. <if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
  55. <if test="dbName == 'mysql'">CONCAT('%', #{title}, '%')</if>
  56. <if test="dbName == 'mssql'">'%'+#{title}+'%'</if>
  57. </if>
  58. <if test="type != null and type != ''">
  59. AND a.TYPE = #{type}
  60. </if>
  61. <if test="status != null and status != ''">
  62. AND a.STATUS = #{status}
  63. </if>
  64. <if test="isSelf">
  65. AND a.STATUS = '1'
  66. </if>
  67. <choose>
  68. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  69. ORDER BY ${page.orderBy}
  70. </when>
  71. <otherwise>
  72. ORDER BY a.update_date DESC
  73. </otherwise>
  74. </choose>
  75. </select>
  76. <select id="findAllList" resultType="OaNotify">
  77. SELECT
  78. <include refid="oaNotifyColumns"/>
  79. FROM oa_notify a
  80. <include refid="oaNotifyJoins"/>
  81. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  82. <choose>
  83. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  84. ORDER BY ${page.orderBy}
  85. </when>
  86. <otherwise>
  87. ORDER BY a.update_date DESC
  88. </otherwise>
  89. </choose>
  90. </select>
  91. <select id="findCount" resultType="Long">
  92. SELECT
  93. count(1)
  94. FROM oa_notify a
  95. <if test="isSelf">
  96. JOIN oa_notify_record r ON r.oa_notify_id = a.id AND r.user_id = #{currentUser.id}
  97. <if test="readFlag != null and readFlag != ''">
  98. AND r.read_flag = #{readFlag}
  99. </if>
  100. </if>
  101. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  102. <if test="isSelf">
  103. AND a.STATUS = '1'
  104. </if>
  105. </select>
  106. <insert id="insert">
  107. INSERT INTO oa_notify(
  108. ID,
  109. TYPE,
  110. TITLE,
  111. CONTENT,
  112. FILES,
  113. STATUS,
  114. CREATE_BY,
  115. CREATE_DATE,
  116. UPDATE_BY,
  117. UPDATE_DATE,
  118. REMARKS,
  119. DEL_FLAG
  120. ) VALUES (
  121. #{id},
  122. #{type},
  123. #{title},
  124. #{content},
  125. #{files},
  126. #{status},
  127. #{createBy.id},
  128. #{createDate},
  129. #{updateBy.id},
  130. #{updateDate},
  131. #{remarks},
  132. #{delFlag}
  133. )
  134. </insert>
  135. <update id="update">
  136. UPDATE oa_notify SET
  137. TYPE = #{type},
  138. TITLE = #{title},
  139. CONTENT = #{content},
  140. FILES = #{files},
  141. STATUS = #{status},
  142. UPDATE_BY = #{updateBy.id},
  143. UPDATE_DATE = #{updateDate},
  144. REMARKS = #{remarks}
  145. WHERE id = #{id}
  146. </update>
  147. <update id="delete">
  148. DELETE FROM oa_notify
  149. WHERE id = #{id}
  150. </update>
  151. <update id="deleteByLogic">
  152. UPDATE oa_notify SET
  153. del_flag = #{DEL_FLAG_DELETE}
  154. WHERE id = #{id}
  155. </update>
  156. </mapper>