NotifyDao.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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="platform.modules.government.dao.NotifyDao">
  4. <select id="findAllNotify" resultType="platform.modules.government.entity.Notify">
  5. select temp.* from
  6. (
  7. select n.*,
  8. getPushDate(n.id,'0') as push_date,
  9. '' as receive_date,
  10. getCodeByValue('notify_type',n.type) as type_code,
  11. '1' as is_read,
  12. '' as notify_detail_id,
  13. zUser.user_type as source,
  14. case zUser.user_type
  15. when '0' then '高新区政府'
  16. when '1' then zUser.build_name
  17. when '4' then zUser.street_name
  18. else '' end as source_name,
  19. n.archive_date as archive_date_detail
  20. from z_notify n
  21. left join z_user zUser on zUser.id = n.create_by
  22. WHERE n.del_flag='0'
  23. <choose>
  24. <when test="!isArchive">
  25. and n.status=0
  26. </when>
  27. <otherwise>
  28. and n.status=1
  29. </otherwise>
  30. </choose>
  31. <!-- and zUser.user_type = #{condition.user_type} 政府,街道也能看到下级发送的通知 -->
  32. <if test="condition.street_id!=null and condition.street_id!=''">
  33. and zUser.street_id=#{condition.street_id}
  34. </if>
  35. <if test="condition.build_id!=null and condition.build_id!='' ">
  36. and zUser.build_id=#{condition.build_id}
  37. </if>
  38. <if test="condition.company_id!=null and condition.company_id!='' ">
  39. and zUser.company_id=#{condition.company_id}
  40. </if>
  41. <!-- <if test="condition.keyword!=null and condition.keyword!=''">
  42. and n.title like CONCAT('%',#{condition.keyword},'%')
  43. </if> -->
  44. <if test="condition.type!=null and condition.type!=''">
  45. and n.type = #{condition.type}
  46. </if>
  47. <!-- 政府不能看到接到园区还没推送的消息,只能看到已经推送的消息 -->
  48. <if test="condition.user_type == 0">
  49. and (zUser.user_type = 0 or n.is_push = 1 )
  50. </if>
  51. <if test="(condition.street_id!=null and condition.street_id!='')
  52. or (condition.build_id!=null and condition.build_id!='' )
  53. or (condition.company_id!=null and condition.company_id!='' )">
  54. UNION
  55. select
  56. a.*,
  57. getPushDate(a.id,b.id) as push_date,
  58. b.create_time as receive_date,
  59. getCodeByValue('notify_type',a.type) as type_code,
  60. b.is_read as is_read,
  61. b.id as notify_detail_id,
  62. zUser.user_type as source,
  63. case zUser.user_type
  64. when '0' then '高新区政府'
  65. when '1' then zUser.build_name
  66. when '4' then zUser.street_name
  67. else '' end as source_name,
  68. b.archive_date as archive_date_detail
  69. from z_notify a
  70. LEFT JOIN z_notify_detail b on b.z_notify_id=a.id
  71. left join z_user zUser on zUser.id = b.create_by
  72. WHERE
  73. b.push_type = #{condition.user_type}
  74. <if test="condition.street_id!=null and condition.street_id!=''">
  75. and b.push_id=#{condition.street_id}
  76. </if>
  77. <if test="condition.build_id!=null and condition.build_id!='' ">
  78. and b.push_id=#{condition.build_id}
  79. </if>
  80. <if test="condition.company_id!=null and condition.company_id!='' ">
  81. and b.push_id=#{condition.company_id}
  82. </if>
  83. and ( DATE(a.expiry_date) &gt; NOW() or a.expiry_date=null or a.expiry_date='' )
  84. and a.del_flag='0' and b.del_flag='0'
  85. <choose>
  86. <when test="!isArchive">
  87. and b.status=0
  88. </when>
  89. <otherwise>
  90. and b.status=1
  91. </otherwise>
  92. </choose>
  93. <!-- <if test="condition.keyword!=null and condition.keyword!=''">
  94. and a.title like CONCAT('%',#{condition.keyword},'%')
  95. </if> -->
  96. <if test="condition.type!=null and condition.type!=''">
  97. and a.type = #{condition.type}
  98. </if>
  99. </if>
  100. ) temp where 1=1
  101. <if test="condition.begin_date != null and condition.begin_date !='' ">
  102. <![CDATA[ and DATE_FORMAT(temp.create_time, '%Y-%m-%d')>= DATE_FORMAT(#{condition.begin_date}, '%Y-%m-%d') ]]>
  103. </if>
  104. <if test="condition.end_date != null and condition.end_date !='' ">
  105. <![CDATA[ and DATE_FORMAT(temp.create_time, '%Y-%m-%d')<= DATE_FORMAT(#{condition.end_date}, '%Y-%m-%d') ]]>
  106. </if>
  107. <if test="condition.keyword!=null and condition.keyword!=''">
  108. and (
  109. temp.title like CONCAT('%',#{condition.keyword},'%')
  110. or temp.source_name like CONCAT('%',#{condition.keyword},'%')
  111. )
  112. </if>
  113. order by temp.create_time desc
  114. </select>
  115. <select id="findPushNotify" resultType="platform.modules.government.entity.Notify">
  116. select
  117. a.*,
  118. getCodeByValue('notify_type',a.type) as type_code,
  119. b.is_read as is_read,
  120. b.id as notify_detail_id,
  121. zUser.user_type as source
  122. from z_notify a
  123. LEFT JOIN z_notify_detail b on b.z_notify_id=a.id
  124. left join z_user zUser on zUser.id = a.create_by
  125. WHERE
  126. a.del_flag='0'
  127. <if test="condition.street_id!=null and condition.street_id!=''">
  128. and b.push_id=#{condition.street_id}
  129. </if>
  130. <if test="condition.build_id!=null and condition.build_id!='' ">
  131. b.push_id=#{condition.build_id}
  132. </if>
  133. and a.del_flag='0' and b.del_flag='0'
  134. <if test="condition.keyword!=null and condition.keyword!=''">
  135. and a.title like CONCAT('%',#{condition.keyword},'%')
  136. </if>
  137. order by create_time desc
  138. </select>
  139. <select id="findNotifyList" resultType="platform.modules.government.entity.Notify">
  140. select temp.* from
  141. (
  142. select n.*,
  143. getPushDate(n.id,'0') as push_date,
  144. getCodeByValue('notify_type',n.type) as type_code,
  145. '1' as is_read,
  146. '' as notify_detail_id,
  147. zUser.user_type as source,
  148. case zUser.user_type
  149. when '0' then '高新区政府'
  150. when '1' then zUser.build_name
  151. when '4' then zUser.street_name
  152. else '' end as source_name
  153. from z_notify n
  154. left join z_user zUser on zUser.id = n.create_by
  155. WHERE n.del_flag='0' and n.status='0'
  156. and zUser.user_type = #{currUser.user_type}
  157. <if test="notifyDto.street_id!=null and notifyDto.street_id!=''">
  158. and zUser.street_id=#{notifyDto.street_id}
  159. </if>
  160. <if test="notifyDto.build_id!=null and notifyDto.build_id!='' ">
  161. and zUser.build_id=#{notifyDto.build_id}
  162. </if>
  163. <if test="notifyDto.company_id!=null and notifyDto.company_id!='' ">
  164. and zUser.company_id=#{notifyDto.company_id}
  165. </if>
  166. <if test="(notifyDto.street_id!=null and notifyDto.street_id!='')
  167. or (notifyDto.build_id!=null and notifyDto.build_id!='' )
  168. or (notifyDto.company_id!=null and notifyDto.company_id!='' )">
  169. UNION
  170. select
  171. a.*,
  172. getPushDate(a.id,b.id) as push_date,
  173. getCodeByValue('notify_type',a.type) as type_code,
  174. b.is_read as is_read,
  175. b.id as notify_detail_id,
  176. zUser.user_type as source,
  177. case zUser.user_type
  178. when '0' then '高新区政府'
  179. when '1' then zUser.build_name
  180. when '4' then zUser.street_name
  181. else '' end as source_name
  182. from z_notify a
  183. LEFT JOIN z_notify_detail b on b.z_notify_id=a.id
  184. left join z_user zUser on zUser.id = a.create_by
  185. WHERE
  186. b.push_type = #{currUser.user_type}
  187. <if test="notifyDto.street_id!=null and notifyDto.street_id!=''">
  188. and b.push_id=#{notifyDto.street_id}
  189. </if>
  190. <if test="notifyDto.build_id!=null and notifyDto.build_id!='' ">
  191. and b.push_id=#{notifyDto.build_id}
  192. </if>
  193. <if test="notifyDto.company_id!=null and notifyDto.company_id!=''">
  194. and b.push_id=#{notifyDto.company_id}
  195. </if>
  196. and a.del_flag='0' and a.status='0' and b.del_flag='0' and b.status='0'
  197. <if test="notifyDto.is_read!=null">
  198. and b.is_read = #{notifyDto.is_read}
  199. </if>
  200. and ( DATE(a.expiry_date) &gt; NOW() or a.expiry_date=null or a.expiry_date='' )
  201. </if>
  202. ) temp
  203. order by temp.create_time desc limit #{notifyDto.count}
  204. </select>
  205. <!-- 获取上级推送过来的通知 -->
  206. <select id="findReceivedNotifyList" resultType="platform.modules.government.entity.Notify">
  207. select temp.* from
  208. (
  209. select
  210. a.*,
  211. getPushDate(a.id,b.id) as push_date,
  212. getCodeByValue('notify_type',a.type) as type_code,
  213. b.is_read as is_read,
  214. b.id as notify_detail_id,
  215. zUser.user_type as source,
  216. case zUser.user_type
  217. when '0' then '高新区政府'
  218. when '1' then zUser.build_name
  219. when '4' then zUser.street_name
  220. else '' end as source_name
  221. from z_notify a
  222. LEFT JOIN z_notify_detail b on b.z_notify_id=a.id
  223. left join z_user zUser on zUser.id = a.create_by
  224. WHERE
  225. b.push_type = #{currUser.user_type}
  226. <if test="notifyDto.street_id!=null and notifyDto.street_id!=''">
  227. and b.push_id=#{notifyDto.street_id}
  228. </if>
  229. <if test="notifyDto.build_id!=null and notifyDto.build_id!='' ">
  230. and b.push_id=#{notifyDto.build_id}
  231. </if>
  232. <if test="notifyDto.company_id!=null and notifyDto.company_id!=''">
  233. and b.push_id=#{notifyDto.company_id}
  234. </if>
  235. and a.del_flag='0' and a.status='0' and b.del_flag='0' and b.status='0'
  236. and ( DATE(a.expiry_date) &gt; NOW() or a.expiry_date=null or a.expiry_date='' )
  237. <if test="notifyDto.is_read!=null">
  238. and b.is_read = #{notifyDto.is_read}
  239. </if>
  240. ) temp
  241. order by temp.create_time desc limit #{notifyDto.count}
  242. </select>
  243. <select id="findCompanyNotifyList" resultType="platform.modules.government.entity.Notify">
  244. select
  245. a.*,
  246. getPushDate(a.id,b.id) as push_date,
  247. getCodeByValue('notify_type',a.type) as type_code,
  248. b.is_read as is_read,
  249. b.id as notify_detail_id,
  250. zUser.user_type as source
  251. from z_notify a
  252. LEFT JOIN z_notify_detail b on b.z_notify_id=a.id
  253. left join z_user zUser on zUser.id = a.create_by
  254. WHERE
  255. b.push_type = #{currUser.user_type} and a.is_read = 0
  256. and b.push_id=#{notifyDto.company_id}
  257. and a.del_flag='0' and a.status='0' and b.del_flag='0' and b.status='0'
  258. order by temp.create_time desc limit #{notifyDto.count}
  259. </select>
  260. <select id="findStreetReadNum" resultType="Integer">
  261. select count(d.id) from z_notify_detail d
  262. inner join z_notify n on n.id=d.z_notify_id
  263. where d.user_type=4 and d.push_street_id=#{streetId} and d.del_flag=0
  264. <![CDATA[ and DATE_FORMAT(n.`create_time`, '%Y-%m-%d')<= DATE_FORMAT(#{dateTo}, '%Y-%m-%d') ]]>
  265. <![CDATA[ and DATE_FORMAT(n.`create_time`, '%Y-%m-%d')>= DATE_FORMAT(#{dateFrom}, '%Y-%m-%d')
  266. ]]> and d.is_read=true
  267. </select>
  268. <select id="findStreetPushNum" resultType="Integer">
  269. select count(d.id) from z_notify_detail d
  270. left join z_notify n on n.id=d.z_notify_id
  271. where d.user_type=4 and d.push_street_id=#{streetId} and d.del_flag=0
  272. <![CDATA[ and DATE_FORMAT(n.`create_time`, '%Y-%m-%d')<= DATE_FORMAT(#{dateTo}, '%Y-%m-%d') ]]>
  273. <![CDATA[ and DATE_FORMAT(n.`create_time`, '%Y-%m-%d')>= DATE_FORMAT(#{dateFrom}, '%Y-%m-%d')
  274. ]]>
  275. </select>
  276. <select id="findGovernmentReadNum" resultType="Integer">
  277. select count(id) from z_notify_detail where user_type=0 and del_flag=0
  278. <![CDATA[ and DATE_FORMAT(`create_time`, '%Y-%m-%d')<= DATE_FORMAT(#{dateTo}, '%Y-%m-%d') ]]>
  279. <![CDATA[ and DATE_FORMAT(`create_time`, '%Y-%m-%d')>= DATE_FORMAT(#{dateFrom}, '%Y-%m-%d')
  280. ]]> and is_read=true
  281. </select>
  282. <select id="findGovernmentPushNum" resultType="Integer">
  283. select count(id) from z_notify_detail where user_type=0 and del_flag=0
  284. <![CDATA[ and DATE_FORMAT(`create_time`, '%Y-%m-%d')<= DATE_FORMAT(#{dateTo}, '%Y-%m-%d') ]]>
  285. <![CDATA[ and DATE_FORMAT(`create_time`, '%Y-%m-%d')>= DATE_FORMAT(#{dateFrom}, '%Y-%m-%d')
  286. ]]>
  287. </select>
  288. <select id="findPublishNum" resultType="Integer">
  289. select count(n.id) from z_notify n
  290. left join z_user u on u.id = n.create_by
  291. where <![CDATA[ DATE_FORMAT(n.`create_time`, '%Y-%m-%d')<= DATE_FORMAT(#{dateTo}, '%Y-%m-%d') ]]>
  292. <![CDATA[ and DATE_FORMAT(n.`create_time`, '%Y-%m-%d')>= DATE_FORMAT(#{dateFrom}, '%Y-%m-%d')]]>
  293. and u.user_type=${userType}
  294. <if test="streetId!=null and streetId!=''">
  295. and u.street_id=#{streetId}
  296. </if>
  297. </select>
  298. <select id="findGovernmentExportPushStreet" resultType="Integer">
  299. select count(id) from z_notify_detail where push_type=4 and user_type=0 and del_flag=0 and z_notify_id=#{notifyId}
  300. </select>
  301. <select id="findGovernmentExportPushStreetNum" resultType="Integer">
  302. select count(id) from z_notify_detail where push_type=4 and user_type=0 and del_flag=0 and z_notify_id=#{notifyId} and is_read=0
  303. </select>
  304. <select id="findGovernmentExportPushBuild" resultType="Integer">
  305. select count(id) from z_notify_detail where push_type=1 and user_type=0 and del_flag=0 and z_notify_id=#{notifyId}
  306. </select>
  307. <select id="findGovernmentExportPushBuildNum" resultType="Integer">
  308. select count(id) from z_notify_detail where push_type=1 and user_type=0 and del_flag=0 and z_notify_id=#{notifyId} and is_read=0
  309. </select>
  310. <select id="findGovernmentExportPushCompany" resultType="Integer">
  311. select count(id) from z_notify_detail where push_type=3 and user_type=0 and del_flag=0 and z_notify_id=#{notifyId}
  312. </select>
  313. <select id="findGovernmentExportPushCompanyNum" resultType="Integer">
  314. select count(id) from z_notify_detail where push_type=3 and user_type=0 and del_flag=0 and z_notify_id=#{notifyId} and is_read=0
  315. </select>
  316. <select id="findStreetExportPushBuild" resultType="Integer">
  317. select count(id) from z_notify_detail where push_type=1 and del_flag=0 and z_notify_id=#{notifyId} and push_street_id=#{streetId}
  318. </select>
  319. <select id="findStreetExportPushBuildNum" resultType="Integer">
  320. select count(id) from z_notify_detail where push_type=1 and del_flag=0 and z_notify_id=#{notifyId} and is_read=0 and push_street_id=#{streetId}
  321. </select>
  322. <select id="findStreetExportPushCompany" resultType="Integer">
  323. select count(id) from z_notify_detail where push_type=3 and del_flag=0 and z_notify_id=#{notifyId} and push_street_id=#{streetId}
  324. </select>
  325. <select id="findStreetExportPushCompanyNum" resultType="Integer">
  326. select count(id) from z_notify_detail where push_type=3 and del_flag=0 and z_notify_id=#{notifyId} and is_read=0 and push_street_id=#{streetId}
  327. </select>
  328. <select id="findBuildExportPushCompany" resultType="Integer">
  329. select count(id) from z_notify_detail where push_type=3 and del_flag=0 and z_notify_id=#{notifyId} and push_build_id=#{buildId}
  330. </select>
  331. <select id="findBuildExportPushCompanyNum" resultType="Integer">
  332. select count(id) from z_notify_detail where push_type=3 and del_flag=0 and z_notify_id=#{notifyId} and is_read=0 and push_build_id=#{buildId}
  333. </select>
  334. <select id="getFullNotifyById" resultType="platform.modules.government.entity.Notify">
  335. select
  336. a.*,
  337. zUser.user_type as source
  338. from z_notify a
  339. left join z_user zUser on zUser.id = a.create_by
  340. WHERE a.id = #{notifyId}
  341. </select>
  342. </mapper>