push.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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.lemon.lifecenter.mapper.PushMapper">
  4. <select id="selectPushResultTableCount" parameterType="PushDTO" resultType="int">
  5. <![CDATA[
  6. SELECT COUNT(*) total
  7. FROM db_class
  8. WHERE class_name LIKE '%push_result_${ym}%'
  9. ]]>
  10. </select>
  11. <select id="selectPushListTotal" parameterType="PushDTO" resultType="int">
  12. <![CDATA[
  13. SELECT SUM( A.total ) total
  14. FROM (
  15. SELECT COUNT(*) total
  16. FROM push_log PL
  17. LEFT JOIN member M
  18. ON M.id = PL.sender
  19. WHERE 1 = 1
  20. AND DATE_FORMAT( PL.start_date, '%Y%m' ) = #{ym}
  21. ]]>
  22. <if test='centerCode != null and centerCode != "0"'>
  23. <![CDATA[
  24. AND M.CENTER_CODE = #{centerCode}
  25. ]]>
  26. </if>
  27. <if test='sendType != null and sendType != ""'>
  28. <![CDATA[
  29. AND PL.send_type = #{sendType}
  30. ]]>
  31. </if>
  32. <if test='targetType != null and targetType != ""'>
  33. <![CDATA[
  34. AND PL.target_type = #{targetType}
  35. ]]>
  36. </if>
  37. <if test='startDate != null and startDate != ""'>
  38. <![CDATA[
  39. AND DATE_FORMAT( PL.start_date, '%Y-%m-%d') >= #{startDate}
  40. ]]>
  41. </if>
  42. <if test='endDate != null and endDate != ""'>
  43. <![CDATA[
  44. AND DATE_FORMAT( PL.start_date, '%Y-%m-%d') <= #{endDate}
  45. ]]>
  46. </if>
  47. <if test='searchType != null and searchType != ""'>
  48. <if test='searchType == "title" and q != null and q !=""'>
  49. <![CDATA[
  50. AND PL.push_title LIKE CONCAT('%', #{q}, '%')
  51. ]]>
  52. </if>
  53. <if test='searchType == "name" and q != null and q !=""'>
  54. <![CDATA[
  55. AND M.name LIKE CONCAT('%', #{q}, '%')
  56. ]]>
  57. </if>
  58. <if test='searchType == "id" and q != null and q !=""'>
  59. <![CDATA[
  60. AND PL.sender LIKE CONCAT('%', #{q}, '%')
  61. ]]>
  62. </if>
  63. </if>
  64. <![CDATA[
  65. UNION
  66. SELECT COUNT(*) total
  67. FROM push_schedule
  68. WHERE send_type = 'D'
  69. AND send_state = 'W'
  70. ) A
  71. ]]>
  72. </select>
  73. <select id="selectPushListData" parameterType="PushDTO" resultType="PushDTO">
  74. <![CDATA[
  75. SELECT PL.idx AS idx,
  76. PL.push_idx AS pushIdx,
  77. PL.send_type AS sendType,
  78. PL.send_state AS sendState,
  79. PL.target_type AS targetType,
  80. PL.center_code AS centerCode,
  81. PL.sender_ip AS senderIp,
  82. PL.sender AS sender,
  83. PL.push_title AS pushTitle,
  84. PL.push_content AS pushContent,
  85. M.name AS name,
  86. DATE_FORMAT( PL.create_date, '%Y-%m-%d %H:%i' ) AS createDate,
  87. DATE_FORMAT( PL.start_date, '%Y-%m-%d %H:%i' ) AS startDate,
  88. DATE_FORMAT( PL.end_date, '%Y-%m-%d %H:%i' ) AS endDate,
  89. PR.total_count AS totalCount,
  90. PR.success_count AS successCount,
  91. PR.fail_count AS failCount,
  92. PR.wait_count AS waitCount,
  93. ( SELECT center_name FROM center_info WHERE center_code = PL.center_code ) AS centerName
  94. FROM push_log PL
  95. LEFT JOIN member M
  96. ON M.id = PL.sender
  97. LEFT JOIN ( SELECT A.push_idx,
  98. COUNT( push_idx ) total_count,
  99. COUNT( IF(success_yn='Y', 1, null) ) success_count,
  100. COUNT( IF(success_yn='N', 1, null) ) fail_count,
  101. COUNT( IF(state='W', 1, null) ) wait_count
  102. FROM push_result_${ym} A
  103. WHERE push_idx = PL.push_idx
  104. AND log_idx = PL.idx
  105. GROUP BY A.push_idx ) PR
  106. ON PR.push_idx = PL.push_idx
  107. WHERE 1 = 1
  108. AND DATE_FORMAT( PL.start_date, '%Y%m' ) = #{ym}
  109. ]]>
  110. <if test='centerCode != null and centerCode != "0"'>
  111. <![CDATA[
  112. AND M.CENTER_CODE = #{centerCode}
  113. ]]>
  114. </if>
  115. <if test='sendType != null and sendType != ""'>
  116. <![CDATA[
  117. AND PL.send_type = #{sendType}
  118. ]]>
  119. </if>
  120. <if test='targetType != null and targetType != ""'>
  121. <![CDATA[
  122. AND PL.target_type = #{targetType}
  123. ]]>
  124. </if>
  125. <if test='startDate != null and startDate != ""'>
  126. <![CDATA[
  127. AND DATE_FORMAT( PL.start_date, '%Y-%m-%d') >= #{startDate}
  128. ]]>
  129. </if>
  130. <if test='endDate != null and endDate != ""'>
  131. <![CDATA[
  132. AND DATE_FORMAT( PL.start_date, '%Y-%m-%d') <= #{endDate}
  133. ]]>
  134. </if>
  135. <if test='searchType != null and searchType != ""'>
  136. <if test='searchType == "title" and q != null and q !=""'>
  137. <![CDATA[
  138. AND PL.push_title LIKE CONCAT('%', #{q}, '%')
  139. ]]>
  140. </if>
  141. <if test='searchType == "name" and q != null and q !=""'>
  142. <![CDATA[
  143. AND M.name LIKE CONCAT('%', #{q}, '%')
  144. ]]>
  145. </if>
  146. <if test='searchType == "id" and q != null and q !=""'>
  147. <![CDATA[
  148. AND PL.sender LIKE CONCAT('%', #{q}, '%')
  149. ]]>
  150. </if>
  151. </if>
  152. <![CDATA[
  153. UNION
  154. SELECT 0 idx,
  155. push_idx AS pushIdx,
  156. send_type AS sendType,
  157. send_state AS sendState,
  158. target_type AS targetType,
  159. center_code AS centerCode,
  160. sender_ip AS senderIp,
  161. sender AS sender,
  162. push_title AS pushTitle,
  163. push_content AS pushContent,
  164. ( SELECT `name` FROM member WHERE id= sender ) AS `name`,
  165. DATE_FORMAT( create_date, '%Y-%m-%d %H:%i' ) AS createDate,
  166. DATE_FORMAT( create_date, '%Y-%m-%d %H:%i' ) AS startDate,
  167. null AS endDate,
  168. 0 AS totalCount,
  169. 0 AS successCount,
  170. 0 AS failCount,
  171. 0 AS waitCount,
  172. ( SELECT center_name FROM center_info WHERE center_code = push_schedule.center_code ) AS centerName
  173. FROM push_schedule
  174. WHERE send_type = 'D'
  175. AND send_state = 'W'
  176. ORDER BY startDate desc
  177. LIMIT ${limit}, ${limitMax}
  178. ]]>
  179. </select>
  180. <select id="selectPushResultTotal" parameterType="PushDTO" resultType="int">
  181. <![CDATA[
  182. SELECT COUNT(*) total
  183. FROM push_result_${ym} PR
  184. WHERE 1=1
  185. AND PR.push_idx = #{pushIdx}
  186. AND PR.log_idx = #{logIdx}
  187. ]]>
  188. <if test='state != null and state !=""'>
  189. <![CDATA[
  190. AND PR.state = #{state}
  191. ]]>
  192. </if>
  193. <if test='successYn != null and successYn !=""'>
  194. <![CDATA[
  195. AND PR.success_yn = #{successYn}
  196. ]]>
  197. </if>
  198. </select>
  199. <select id="selectPushResultList" parameterType="PushDTO" resultType="PushDTO">
  200. <![CDATA[
  201. SELECT PR.idx AS idx,
  202. PR.push_idx AS pushIdx,
  203. PR.patient_idx AS patientIdx,
  204. PR.device_key AS deviceKey,
  205. PR.state AS state,
  206. PR.success_yn AS successYn,
  207. PR.fail_code AS failCode,
  208. PR.note AS note,
  209. DATE_FORMAT( PR.create_date, '%Y-%m-%d %H:%i:%s' ) AS createDate,
  210. DATE_FORMAT( PR.update_date, '%Y-%m-%d %H:%i:%s' ) AS updateDate,
  211. PC.patient_name AS patientName,
  212. PC.ward_number AS wardNumber,
  213. PC.room_number AS roomNumber,
  214. PC.gender AS gender,
  215. PC.jumin AS jumin
  216. FROM push_result_${ym} PR
  217. LEFT JOIN patient_care PC
  218. ON PR.patient_idx = PC.patient_idx
  219. WHERE 1=1
  220. AND PC.USE_YN = 'Y'
  221. AND PR.push_idx = #{pushIdx}
  222. AND PR.log_idx = #{logIdx}
  223. ]]>
  224. <if test='state != null and state !=""'>
  225. <![CDATA[
  226. AND PR.state = #{state}
  227. ]]>
  228. </if>
  229. <if test='successYn != null and successYn !=""'>
  230. <![CDATA[
  231. AND PR.success_yn = #{successYn}
  232. ]]>
  233. </if>
  234. </select>
  235. <insert id="insertPushData" parameterType="PushDTO" useGeneratedKeys="true">
  236. <selectKey keyProperty="pushIdx" resultType="int" order="AFTER">
  237. <![CDATA[
  238. SELECT CURRENT_VAL AS pushIdx FROM db_serial WHERE NAME = 'push_schedule_ai_push_idx';
  239. ]]>
  240. </selectKey>
  241. <![CDATA[
  242. INSERT
  243. INTO push_schedule
  244. ( send_type, send_state, target_type, center_code, sender_ip, sender,
  245. push_title, push_content, push_payload1, send_date, send_time, create_date )
  246. VALUES ( #{sendType}, #{sendState}, #{targetType}, #{centerCode}, #{senderIp}, #{sender},
  247. #{pushTitle}, #{pushContent}, #{pushPayLoad1}, #{sendDate}, #{sendTime}, NOW() );
  248. ]]>
  249. </insert>
  250. <update id="updatePushData" parameterType="PushDTO">
  251. <![CDATA[
  252. UPDATE push_schedule
  253. SET send_type = #{sendType},
  254. target_type = #{targetType},
  255. push_title = #{pushTitle},
  256. push_content = #{pushContent},
  257. send_date = #{sendDate},
  258. send_time = #{sendTime},
  259. update_date = NOW(),
  260. update_by = #{updateBy}
  261. WHERE push_idx = #{pushIdx}
  262. ]]>
  263. </update>
  264. <delete id="deletePushData" parameterType="PushDTO">
  265. <![CDATA[
  266. DELETE
  267. FROM push_schedule
  268. WHERE push_idx = #{pushIdx}
  269. ]]>
  270. </delete>
  271. <insert id="insertPushTargetTemp" parameterType="PushDTO">
  272. <![CDATA[
  273. INSERT
  274. INTO push_target_temp
  275. ( push_idx, patient_idx )
  276. VALUES ( #{pushIdx}, #{patientIdx} )
  277. ]]>
  278. </insert>
  279. <delete id="deletePushTargetTemp" parameterType="PushDTO">
  280. <![CDATA[
  281. DELETE
  282. FROM push_target_temp
  283. WHERE push_idx = #{pushIdx}
  284. ]]>
  285. </delete>
  286. <select id="selectPushTargetTempCount" parameterType="PushDTO" resultType="int">
  287. <![CDATA[
  288. SELECT COUNT(*) total
  289. FROM push_target_temp
  290. WHERE push_idx = #{pushIdx}
  291. ]]>
  292. </select>
  293. <select id="selectPushTargetTempList" parameterType="PushDTO" resultType="PushDTO">
  294. <![CDATA[
  295. SELECT PT.push_idx AS pushIdx,
  296. PT.patient_idx AS patientIdx,
  297. PC.patient_name AS patientName,
  298. CASE WHEN PC.GENDER = 'M' THEN '남'
  299. WHEN PC.GENDER = 'F' THEN '여'
  300. ELSE ''
  301. END AS gender,
  302. (SELECT TRUNC((SYSDATE-TO_DATE(PC.JUMIN, 'YYYYMMDD'))/365) + 1) AS age,
  303. PC.ward_number AS wardNumber,
  304. PC.room_number AS roomNumber,
  305. DATE_FORMAT(PC.JUMIN, '%Y-%m-%d') AS jumin,
  306. DATE_FORMAT(PC.HOSPITALIZATION_DATE, '%Y-%m-%d') AS hospitalizationDate
  307. FROM push_target_temp PT
  308. LEFT JOIN patient_care PC
  309. ON PC.patient_idx = PT.patient_idx
  310. WHERE push_idx = #{pushIdx}
  311. AND PC.USE_YN = 'Y'
  312. ]]>
  313. </select>
  314. <select id="selectPushScheduleCount" parameterType="PushDTO" resultType="int">
  315. <![CDATA[
  316. SELECT COUNT(*) total
  317. FROM push_schedule
  318. WHERE send_type != 'D'
  319. ]]>
  320. <if test='centerCode != null and centerCode !=""'>
  321. <![CDATA[
  322. AND center_code = #{centerCode}
  323. ]]>
  324. </if>
  325. </select>
  326. <select id="selectPushScheduleList" parameterType="PushDTO" resultType="PushDTO">
  327. <![CDATA[
  328. SELECT PS.push_idx AS pushIdx,
  329. PS.send_type AS sendType,
  330. PS.send_state AS sendState,
  331. PS.target_type AS targetType,
  332. PS.center_code AS centerCode,
  333. PS.sender_ip AS senderIp,
  334. PS.sender AS sender,
  335. PS.push_title AS pushTitle,
  336. PS.push_content AS pushContent,
  337. PS.send_date AS sendDate,
  338. TIME_FORMAT( PS.send_time, '%H:%i' ) AS sendTime,
  339. DATE_FORMAT( PS.create_date, '%Y-%m-%d %H:%i' ) AS createDate,
  340. M.name AS name
  341. FROM push_schedule PS
  342. LEFT JOIN member M
  343. ON PS.sender = M.id
  344. WHERE PS.send_type != 'D'
  345. ]]>
  346. <if test='centerCode != null and centerCode !=""'>
  347. <![CDATA[
  348. AND PS.center_code = #{centerCode}
  349. ]]>
  350. </if>
  351. <![CDATA[
  352. ORDER BY PS.push_idx DESC
  353. ]]>
  354. </select>
  355. <select id="selectPushScheduleOneCount" parameterType="PushDTO" resultType="int">
  356. <![CDATA[
  357. SELECT COUNT(*) total
  358. FROM push_schedule
  359. WHERE push_idx = #{pushIdx}
  360. ]]>
  361. </select>
  362. <select id="selectPushScheduleOneData" parameterType="PushDTO" resultType="PushDTO">
  363. <![CDATA[
  364. SELECT PS.push_idx AS pushIdx,
  365. PS.send_type AS sendType,
  366. PS.send_state AS sendState,
  367. PS.target_type AS targetType,
  368. PS.center_code AS centerCode,
  369. PS.sender_ip AS senderIp,
  370. PS.sender AS sender,
  371. PS.push_title AS pushTitle,
  372. PS.push_content AS pushContent,
  373. PS.send_date AS sendDate,
  374. TIME_FORMAT( PS.send_time, '%H:%i' ) AS sendTime,
  375. DATE_FORMAT( PS.create_date, '%Y-%m-%d %H:%i' ) AS createDate,
  376. M.name AS name,
  377. ( SELECT center_name FROM center_info WHERE center_code = PS.center_code ) AS centerName
  378. FROM push_schedule PS
  379. LEFT JOIN member M
  380. ON PS.sender = M.id
  381. WHERE PS.push_idx = #{pushIdx}
  382. ]]>
  383. </select>
  384. <select id="mobilePushMessageBoxCount" parameterType="PushDTO" resultType="int">
  385. <![CDATA[
  386. SELECT COUNT(*) AS cnt
  387. FROM PUSH_RESULT_${ym} PR
  388. LEFT JOIN (SELECT PUSH_IDX,
  389. PUSH_TITLE,
  390. PUSH_CONTENT
  391. FROM PUSH_LOG) PL
  392. ON PR.PUSH_IDX = PL.PUSH_IDX
  393. WHERE 1 = 1
  394. AND PR.PATIENT_IDX = #{patientIdx}
  395. AND PR.SUCCESS_YN = 'Y'
  396. AND PR.STATE = 'C'
  397. ]]>
  398. </select>
  399. <select id="mobilePushMessageBox" parameterType="PushDTO" resultType="PushDTO">
  400. <![CDATA[
  401. SELECT PL.PUSH_TITLE AS pushTitle,
  402. PL.PUSH_CONTENT AS pushContent,
  403. DATE_FORMAT(PR.UPDATE_DATE, '%Y-%m-%d %H:%i') AS updateDate
  404. FROM PUSH_RESULT_${ym} PR
  405. LEFT JOIN (SELECT PUSH_IDX,
  406. PUSH_TITLE,
  407. PUSH_CONTENT
  408. FROM PUSH_LOG) PL
  409. ON PR.PUSH_IDX = PL.PUSH_IDX
  410. WHERE 1 = 1
  411. AND PR.PATIENT_IDX = #{patientIdx}
  412. AND PR.SUCCESS_YN = 'Y'
  413. AND PR.STATE = 'C'
  414. ORDER BY PR.UPDATE_DATE DESC
  415. ]]>
  416. </select>
  417. </mapper>