messageMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC
  4. "-//mybatis.org//DTD Mapper 3.0//EN"
  5. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  6. <!-- 命名,每一个映射对象不一样
  7. namespace:必须与对应的接口全类名一致
  8. -->
  9. <mapper namespace="com.iamberry.app.mapper.MessageMapper">
  10. <sql id="messageAllField">
  11. ID,TITLE, CONTENT,URL,
  12. FORWORD,IS_NEEDSEND,IS_READ,
  13. CREATE_DATE,READ_DATE,SEND_TYPE,
  14. USER,REMARK,SEND_RESULT
  15. </sql>
  16. <!--通过<resultMap>映射实体类属性名和表的字段名对应关系 -->
  17. <resultMap type="Message" id="messageMap">
  18. <id property="id" column="ID"/>
  19. <result property="title" column="TITLE"/>
  20. <result property="content" column="CONTENT"/>
  21. <result property="url" column="URL"/>
  22. <result property="forword" column="FORWORD"/>
  23. <result property="is_needsend" column="IS_NEEDSEND"/>
  24. <result property="is_read" column="IS_READ"/>
  25. <result property="create_date" column="CREATE_DATE"/>
  26. <result property="read_date" column="READ_DATE"/>
  27. <result property="send_type" column="SEND_TYPE"/>
  28. <result property="user" column="USER"/>
  29. <result property="remark" column="REMARK"/>
  30. <result property="send_result" column="SEND_RESULT"/>
  31. </resultMap>
  32. <sql id="userAttribute">
  33. ID,
  34. USERNAME,
  35. PASSWORD,
  36. TOKEN,
  37. DISPLAY_NAME,
  38. DISPLAY_PICTURE,
  39. CREATED_ON,
  40. EXT_OPEN_ID,
  41. EXT_NAME,
  42. EXT_TYPE,
  43. LOCATION,
  44. BABY_NICKNAME,
  45. BABY_DOB,
  46. BABY_GENDER,
  47. STATUS_
  48. </sql>
  49. <!-- 查询符合条件的用户列表 -->
  50. <select id="selectUser" parameterType="PageBean" resultType="User">
  51. SELECT
  52. <include refid="userAttribute"></include>
  53. FROM USER
  54. WHERE 1=1
  55. <if test="params.username!=null and params.username!=''" >
  56. AND USERNAME LIKE CONCAT('%',#{params.username},'%')
  57. </if>
  58. <if test='recordBegin>0 and pageSize>0'>
  59. limit ${recordBegin},${pageSize}
  60. </if>
  61. <if test='recordBegin==0 and pageSize>0 '>
  62. limit ${pageSize}
  63. </if>
  64. </select>
  65. <!-- 获取用户总条数 -->
  66. <select id="selectUserCount" parameterType="SerchParam" resultType="int">
  67. SELECT COUNT(ID) FROM USER WHERE 1=1
  68. <if test="username!=null and username!=''">
  69. AND USERNAME LIKE CONCAT('%',#{username},'%')
  70. </if>
  71. </select>
  72. <!-- 获取符合条件所有消息 -->
  73. <select id="selectMessageRecoreds" parameterType="PageBean" resultMap="messageMap">
  74. SELECT
  75. <include refid="messageAllField"></include>
  76. FROM (
  77. SELECT ID,TITLE, CONTENT,URL,FORWORD,IS_NEEDSEND,IS_READ,CREATE_DATE,READ_DATE,SEND_TYPE,
  78. (SELECT USERNAME FROM USER WHERE ID = a.user) USER,REMARK,SEND_RESULT FROM MESSAGE a
  79. ) a
  80. WHERE 1=1
  81. <if test="params.title!=null and params.title!=''" >
  82. AND TITLE LIKE CONCAT('%',#{params.title},'%')
  83. </if>
  84. <if test="params.username!=null and params.username!=''">
  85. AND USER LIKE CONCAT('%',#{params.username},'%')
  86. </if>
  87. <if test="params.beginDate!= null and params.beginDate!= ''" >
  88. <![CDATA[AND DATE_FORMAT(create_date, '%Y-%m-%d') >= DATE_FORMAT(#{params.beginDate},'%Y-%m-%d')]]>
  89. </if>
  90. <if test="params.endDate!= null and params.endDate!= ''">
  91. <![CDATA[AND DATE_FORMAT(create_date, '%Y-%m-%d') <= DATE_FORMAT(#{params.endDate},'%Y-%m-%d')]]>
  92. </if>
  93. ORDER BY CREATE_DATE DESC,USER
  94. <if test='recordBegin>0 and pageSize>0'>
  95. LIMIT ${recordBegin},${pageSize}
  96. </if>
  97. <if test='recordBegin==0 and pageSize>0 '>
  98. LIMIT ${pageSize}
  99. </if>
  100. </select>
  101. <!-- 获取所有消息的总条数 -->
  102. <select id="selectMessageCount" parameterType="SerchParam" resultType="int">
  103. SELECT COUNT(1) FROM MESSAGE
  104. WHERE 1=1
  105. <if test="title!=null and title!=''">
  106. AND TITLE LIKE CONCAT('%',#{title},'%')
  107. </if>
  108. <if test="beginDate!= null and beginDate!= ''">
  109. <![CDATA[AND DATE_FORMAT(create_date, '%Y-%m-%d') >= DATE_FORMAT(#{beginDate},'%Y-%m-%d')]]>
  110. </if>
  111. <if test="endDate!= null and endDate!= ''">
  112. <![CDATA[AND DATE_FORMAT(create_date, '%Y-%m-%d') <= DATE_FORMAT(#{endDate},'%Y-%m-%d')]]>
  113. </if>
  114. </select>
  115. <!-- 根据id 修改一条消息 -->
  116. <update id="updateMessage" parameterType="Message">
  117. UPDATE MESSAGE
  118. <set>
  119. <if test="title != null and title != ''">
  120. TITLE=#{title},
  121. </if>
  122. <if test="content != null and content != ''">
  123. CONTENT=#{content},
  124. </if>
  125. <if test="url != null and url != ''">
  126. URL=#{url},
  127. </if>
  128. <if test="forword != null and forword != ''">
  129. FORWORD=#{forword},
  130. </if>
  131. <if test="is_needsend != null and is_needsend != ''">
  132. IS_NEEDSEND=#{is_needsend},
  133. </if>
  134. <if test="is_read != null and is_read != ''">
  135. IS_READ=#{is_read},
  136. </if>
  137. <if test="create_date != null and create_date != ''">
  138. CREATE_DATE=#{create_date},
  139. </if>
  140. <if test="read_date != null and read_date != ''">
  141. READ_DATE=#{read_date},
  142. </if>
  143. <if test="send_type != null and send_type != ''">
  144. SEND_TYPE=#{send_type},
  145. </if>
  146. <if test="user != null and user != ''">
  147. USER=#{user},
  148. </if>
  149. <if test="remark != null and remark != ''">
  150. REMARK=#{remark},
  151. </if>
  152. <if test="send_result != null and send_result != ''">
  153. SEND_RESULT=#{send_result}
  154. </if>
  155. </set>
  156. WHERE ID=#{id}
  157. </update>
  158. <!-- 添加一条消息 -->
  159. <insert id="insertMessage" parameterType="Message"
  160. useGeneratedKeys="true" keyProperty="id">
  161. INSERT INTO MESSAGE
  162. (
  163. TITLE, CONTENT,URL, FORWORD,IS_NEEDSEND,IS_READ,
  164. CREATE_DATE,READ_DATE,SEND_TYPE, USER,REMARK,SEND_RESULT
  165. )
  166. VALUES
  167. (
  168. #{title},#{content},#{url},#{forword},#{is_needsend},#{is_read},
  169. #{create_date},#{read_date},#{send_type},#{user},
  170. #{remark},#{send_result}
  171. )
  172. </insert>
  173. <!-- 获取系统的所有消息 -->
  174. <select id="selectSysMessageRecoreds" resultMap="messageMap">
  175. SELECT
  176. <include refid="messageAllField"></include>
  177. FROM MESSAGE
  178. WHERE USER IS NULL
  179. ORDER BY CREATE_DATE DESC
  180. </select>
  181. <!-- 根据id获取一条信息 -->
  182. <select id="selectUserMessageByid" parameterType="Long" resultMap="messageMap">
  183. SELECT
  184. <include refid="messageAllField"></include>
  185. FROM MESSAGE WHERE ID = #{id}
  186. </select>
  187. <!-- 根据用户id获取该用户的所有消息 -->
  188. <select id="selectUserMessageRecoreds" parameterType="Long" resultMap="messageMap">
  189. SELECT
  190. <include refid="messageAllField"></include>
  191. FROM MESSAGE WHERE USER=#{userid} ORDER BY CREATE_DATE DESC
  192. </select>
  193. <!-- 获取某状态的用户消息 -->
  194. <select id="selectUserMessageByisread" resultType="int">
  195. SELECT COUNT(1) FROM message where is_read = #{1} and user=#{0}
  196. </select>
  197. </mapper>