BigSreenMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.care.bigscreen.mapper.BigSreenMapper">
  4. <!--查询-->
  5. <select id="selectBigScreenStatisticsByOp" resultType="com.care.bigscreen.vo.OpBigScreenStatisticsVO">
  6. SELECT
  7. sum(older_amount) olderAmount,
  8. sum(older_60_80_amount) older6080Amount,
  9. convert(sum(older_60_80_amount)/sum(older_amount),decimal(20,2)) older6080Rate,
  10. sum(older_80_above_amount) older80AboveAmount,
  11. convert(sum(older_80_above_amount)/sum(older_amount),decimal(20,2)) older80AboveRate,
  12. sum(alone_living_amount) aloneLivingAmount,
  13. convert(sum(alone_living_amount)/sum(older_amount),decimal(20,2)) aloneLivingRate,
  14. sum(no_alone_living_amount) noAloneLivingAmount,
  15. convert(sum(no_alone_living_amount)/sum(older_amount),decimal(20,2)) noAloneLivingRate,
  16. sum(concentrate_living_amount) concentrateLivingAmount,
  17. convert(sum(concentrate_living_amount)/sum(older_amount),decimal(20,2)) concentrateLivingRate,
  18. sum(other_living_amount) otherLivingAmount,
  19. convert(sum(other_living_amount)/sum(older_amount),decimal(20,2)) otherLivingRate,
  20. sum(one_level_amount) oneLevelAmount,
  21. sum(two_level_amount) twoLevelAmount,
  22. sum(three_level_amount) threeLevelAmount,
  23. sum(chamberlain_amount) chamberlainAmount,
  24. convert(sum(older_amount)/sum(chamberlain_amount),decimal(20,2)) serveAmountAvg,
  25. sum(serve_amount) serveAmount,
  26. sum(device_amount) deviceAmount,
  27. convert(sum(indoor_online_amount)/(sum(indoor_online_amount) + sum(indoor_offline_amount)),decimal(20,2)) indoorOnlineRate,
  28. sum(indoor_online_amount) indoorOnlineAmount,
  29. sum(indoor_offline_amount) indoorOfflineAmount,
  30. convert(sum(outdoor_online_amount)/(sum(outdoor_online_amount) + sum(outdoor_offline_amount)),decimal(20,2)) outdoorOnlineRate,
  31. sum(outdoor_online_amount) outdoorOnlineAmount,
  32. sum(outdoor_offline_amount) outdoorOfflineAmount,
  33. sum(rt_event_amount) rtEventAmount,
  34. sum(rt_fall_amount) rtFallAmount,
  35. sum(rt_stagnation_amount) rtStagnationAmount,
  36. sum(rt_falling_bed_amount) rtFallingBedAmount,
  37. sum(rt_active_call_amount) rtActiveCallAmount,
  38. sum(rt_outdoors_call_amount) rtOutdoorsCallAmount,
  39. sum(his_event_amount) hisEventAmount,
  40. sum(his_fall_amount) hisFallAmount,
  41. sum(his_stagnation_amount) hisStagnationAmount,
  42. sum(his_falling_bed_amount) hisFallingBedAmount,
  43. sum(his_active_call_amount) hisActiveCallAmount,
  44. sum(his_outdoors_call_amount) hisOutdoorsCallAmount
  45. FROM st_station t
  46. <where>
  47. 1 = 1
  48. <if test="stationId != null and stationId != ''">
  49. AND t.station_id = #{stationId}
  50. </if>
  51. </where>
  52. </select>
  53. <!--机构统计表查询-->
  54. <select id="selectBigScreenOrgStatistics" resultType="com.care.bigscreen.vo.BigScreenOrgVO">
  55. SELECT
  56. sum(station_amount) stationAmount,
  57. sum(seats_amount) seatsAmount,
  58. convert(sum(seats_online_duration)/3600,decimal(20,2)) seatsOnlineDuration
  59. FROM st_organization t
  60. <where>
  61. 1 = 1
  62. <if test="orgId != null and orgId != ''">
  63. AND t.org_id = #{orgId}
  64. </if>
  65. </where>
  66. </select>
  67. <!--运营商大屏根据经纬度查询-->
  68. <select id="selectOpBigScreenStatisticsByLongitudeLatitude" resultType="com.care.bigscreen.vo.OpBigScreenStatisticsVO">
  69. SELECT
  70. sum(older_amount) olderAmount,
  71. sum(older_60_80_amount) older6080Amount,
  72. convert(sum(older_60_80_amount)/sum(older_amount),decimal(20,2)) older6080Rate,
  73. sum(older_80_above_amount) older80AboveAmount,
  74. convert(sum(older_80_above_amount)/sum(older_amount),decimal(20,2)) older80AboveRate
  75. FROM st_station t
  76. <where>
  77. t.longitude >= #{longitudeLeftUp} and t.longitude &lt;= #{longitudeRightDown}
  78. AND t.latitude &lt;= #{latitudeLeftUp} and t.longitude >= #{latitudeRightDown}
  79. </where>
  80. </select>
  81. <!--机构大屏查询统计-->
  82. <select id="selectBigScreenStatisticsByOrg" resultType="com.care.bigscreen.vo.OrgBigScreenStatisticsVO">
  83. SELECT
  84. sum(chamberlain_amount) chamberlainAmount,
  85. sum(chamberlain_in_service_amount) chamberlainInServiceAmount,
  86. sum(serve_amount) serveAmount,
  87. sum(device_amount) deviceAmount,
  88. sum(indoor_online_amount + outdoor_online_amount) deviceOnlineAmount,
  89. sum(indoor_offline_amount + outdoor_offline_amount) deviceOfflineAmount,
  90. sum(rt_event_amount) rtEventAmount,
  91. sum(rt_fall_amount + his_fall_amount) fallAmount,
  92. convert(sum(rt_fall_amount + his_fall_amount)/sum(rt_event_amount + his_event_amount),decimal(20,2)) fallRate,
  93. sum(rt_stagnation_amount + his_stagnation_amount) stagnationAmount,
  94. convert(sum(rt_stagnation_amount + his_stagnation_amount)/sum(rt_event_amount + his_event_amount),decimal(20,2)) stagnationRate,
  95. sum(rt_falling_bed_amount + his_falling_bed_amount) fallingBedAmount,
  96. convert(sum(rt_falling_bed_amount + his_falling_bed_amount)/sum(rt_event_amount + his_event_amount),decimal(20,2)) fallingBedRate,
  97. sum(rt_active_call_amount + his_active_call_amount) activeCallAmount,
  98. convert(sum(rt_active_call_amount + his_active_call_amount)/sum(rt_event_amount + his_event_amount),decimal(20,2)) activeCallRate,
  99. sum(rt_outdoors_call_amount + his_outdoors_call_amount) outdoorsCallAmount,
  100. convert(sum(rt_outdoors_call_amount + his_outdoors_call_amount)/sum(rt_event_amount + his_event_amount),decimal(20,2)) outdoorsCallRate
  101. FROM st_station t
  102. <where>
  103. 1 = 1
  104. <if test="orgId != null and orgId != ''">
  105. AND t.org_id = #{orgId}
  106. </if>
  107. <if test="stationId != null and stationId != ''">
  108. AND t.station_id = #{stationId}
  109. </if>
  110. </where>
  111. </select>
  112. <!--机构大屏根据经纬度查询-->
  113. <select id="selectOrgBigScreenStatisticsByLongitudeLatitude" resultType="com.care.bigscreen.vo.OrgBigScreenStatisticsVO">
  114. SELECT
  115. (select station_amount from st_organization where org_id = t.org_id) stationAmount,
  116. sum(device_amount) deviceAmount,
  117. sum(indoor_online_amount + outdoor_online_amount) deviceOnlineAmount
  118. FROM st_station t
  119. <where>
  120. t.longitude >= #{longitudeLeftUp} and t.longitude &lt;= #{longitudeRightDown}
  121. AND t.latitude &lt;= #{latitudeLeftUp} and t.longitude >= #{latitudeRightDown}
  122. AND t.org_id = #{orgId}
  123. </where>
  124. </select>
  125. <select id="selectBigScreenStationList" resultType="com.care.bigscreen.vo.BigScreenStationVO">
  126. SELECT
  127. a.station_id stationId,
  128. a.station_name stationName,
  129. a.org_id orgId,
  130. a.longitude,
  131. a.latitude,
  132. b.director,
  133. b.phone,
  134. b.addr,
  135. a.chamberlain_amount chamberlainAmount,
  136. a.device_amount deviceAmount,
  137. (a.rt_event_amount + a.his_event_amount) eventAmount
  138. FROM st_station a INNER JOIN care_station b ON a.station_id = b.id
  139. <where>
  140. 1 = 1
  141. <if test="orgId != null and orgId != ''">
  142. AND a.org_id = #{orgId}
  143. </if>
  144. </where>
  145. </select>
  146. <select id="selectOrgBigScreenDeviceList" resultType="com.care.bigscreen.vo.BigScreenDeviceVO">
  147. SELECT
  148. a.dev_name deviceName,
  149. (case when a.longitude is null then
  150. (select b.longitude from care_house b where b.id = a.house_id)
  151. else a.longitude end ) longitude,
  152. (case when a.longitude is null then
  153. (select b.latitude from care_house b where b.id = a.house_id)
  154. else a.latitude end ) latitude,
  155. a.status,
  156. (select b.addr from care_house b where b.id = a.house_id) deviceAddr
  157. FROM care_device a
  158. <where>
  159. 1 = 1
  160. <if test="orgId != null and orgId != ''">
  161. AND a.org_id = #{orgId}
  162. </if>
  163. <if test="stationId != null and stationId != ''">
  164. AND a.station_id = #{stationId}
  165. </if>
  166. <if test="status != null and status != ''">
  167. AND a.status = #{status}
  168. </if>
  169. </where>
  170. </select>
  171. <select id="selectStationBigScreenStatisticsByStation" resultType="com.care.bigscreen.vo.StationBigScreenStatisticsVO">
  172. SELECT
  173. a.station_id stationId,
  174. a.station_name stationName,
  175. a.older_amount olderAmount,
  176. a.chamberlain_amount chamberlainAmount,
  177. a.serve_amount serveAmount,
  178. a.serve_today_amount serveTodayAmount,
  179. (select b.seats_amount from st_organization b where b.org_id=a.org_id) seatsAmount,
  180. (select b.seats_curr_online_amount from st_organization b where b.org_id=a.org_id) seatsCurrOnlineAmount,
  181. (select b.seats_call_min_amount from st_organization b where b.org_id=a.org_id) seatsCallMinAmount
  182. FROM st_station a
  183. where a.station_id = #{stationId}
  184. </select>
  185. <select id="selectBigScreenAlarmOlderList" resultType="com.care.bigscreen.vo.BigScreenAlarmOlderVO">
  186. SELECT a.older_id olderId,
  187. CONCAT((select b.name from care_older b where b.id = a.older_id),'--', (select sdc.name from sys_dim_code sdc where sdc.dim_code = (select b.status from care_older b where b.id = a.older_id) and sdc.type_code='older_status')) nameOlderStatus,
  188. a.status eventStatus,
  189. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.status and sdc.type_code='event_order_status') eventStatusName
  190. FROM care_event_order a
  191. where a.station_id = #{stationId} and a.status in ('0','1')
  192. <if test="olderName != null and olderName != ''">
  193. AND (select b.name from care_older b where b.id = a.older_id) like CONCAT('%',#{olderName},'%')
  194. </if>
  195. and a.modify_time in (
  196. SELECT modify_time from (SELECT MAX(modify_time) modify_time FROM care_event_order GROUP BY older_id) a
  197. )
  198. order by a.status,a.modify_time desc
  199. </select>
  200. <resultMap id="BigScreenOlderDetailVOMap" type="com.care.bigscreen.vo.BigScreenOlderDetailVO">
  201. <id column="id" property="olderId"/>
  202. <result column="name" property="name"/>
  203. <result column="gender" property="gender"/>
  204. <result column="age" property="age"/>
  205. <result column="live_type" property="liveType"/>
  206. <result column="bed_number" property="bedNumber"/>
  207. <result column="safe_level" property="safeLevel"/>
  208. <result column="key_escrow_type" property="keyEscrowType"/>
  209. <result column="addr" property="addr"/>
  210. <result column="phone" property="phone"/>
  211. <result column="older_status" property="olderStatus"/>
  212. <result column="older_event_status" property="olderEventStatus"/>
  213. <collection property="olderContactList" ofType="com.care.bigscreen.vo.BigSreenOlderContactVO">
  214. <id column="contact_id" property="contactId"/>
  215. <result column="contact_name" property="contactName"/>
  216. <result column="contact_phone" property="contactPhone"/>
  217. <result column="relation_type" property="relationType"/>
  218. </collection>
  219. </resultMap>
  220. <select id="selectStationBigScreenOlderDetail" resultMap="BigScreenOlderDetailVOMap">
  221. SELECT
  222. a.id,
  223. a.name,
  224. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.gender and sdc.type_code='gender') gender,
  225. ROUND(DATEDIFF(CURDATE(), a.birthday)/365.2422) age,
  226. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.live_type and sdc.type_code='older_live_type') live_type,
  227. a.bed_number,
  228. a.safe_level,
  229. ch.key_escrow_type,
  230. <!-- a.breath_rate,
  231. a.heart_rate,-->
  232. ch.addr,
  233. a.phone,
  234. <!-- (case when (select count(1) from care_device b where b.dev_type='2' and b.id in (select c.dev_id from care_older_device_rel c where c.older_id = a.id)) > 0 then 'Y' else 'N' end) has_our_door_device,-->
  235. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.status and sdc.type_code='older_status') older_status,
  236. (select c.status from care_event_order c where c.older_id = a.id order by c.create_time desc limit 1) older_event_status,
  237. d.id contact_id,
  238. d.contact_name contact_name,
  239. d.contact_phone contact_phone,
  240. (select sdc.name from sys_dim_code sdc where sdc.dim_code = d.relation_type and sdc.type_code='older_contact_relation_type') relation_type
  241. FROM care_older a left join care_house_older_rel chor on chor.older_id = a.id
  242. left join care_house_contact_rel chcr on chcr.house_id=chor.house_id
  243. left join care_house_contact d on d.id = chcr.contact_id
  244. left join care_house ch on ch.id=chcr.house_id
  245. where a.id = #{olderId}
  246. order by a.id,d.contact_level
  247. </select>
  248. <select id="selectStationBigScreenEventTotal" resultType="com.care.bigscreen.vo.BigScreenEventTotalVO">
  249. SELECT
  250. (select count(1) from care_event_order where station_id = #{stationId} and status in ('0','1') ) rtEventAmount,
  251. (select count(1) from care_event_order where station_id = #{stationId} and status not in ('0','1') ) hisEventAmount
  252. from dual
  253. </select>
  254. <select id="selectBigScreenRtEventList" resultType="com.care.bigscreen.vo.BigScreenEventVO">
  255. SELECT
  256. a.title,
  257. a.create_time createTime,
  258. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.status and sdc.type_code='event_order_status') status,
  259. '告警' eventType
  260. FROM care_event_order a
  261. where a.status in ('0','1')
  262. <if test="orgId != null and orgId != ''">
  263. and a.org_id = #{orgId}
  264. </if>
  265. <if test="stationId != null and stationId != ''">
  266. and a.station_id = #{stationId}
  267. </if>
  268. order by a.status,a.create_time
  269. </select>
  270. <select id="selectBigScreenHisEventListByCount" resultType="int" >
  271. SELECT
  272. count(1)
  273. FROM care_event_order a
  274. where a.station_id = #{stationId} and a.status not in ('0','1')
  275. </select>
  276. <select id="selectBigScreenHisEventListByPage" resultType="com.care.bigscreen.vo.BigScreenEventVO">
  277. SELECT
  278. a.title,
  279. a.create_time createTime,
  280. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.status and sdc.type_code='event_order_status') status,
  281. '告警' eventType
  282. FROM care_event_order a
  283. where a.station_id = #{stationId} and a.status not in ('0','1')
  284. order by a.create_time desc
  285. LIMIT #{pageUtil.start}, #{pageUtil.pageSize}
  286. </select>
  287. <select id="selectStationBigScreenOlderCardTotal" resultType="com.care.bigscreen.vo.BigScreenOlderCardTotalVO">
  288. SELECT
  289. (select count(1) from care_older where station_id = #{stationId}
  290. <if test="olderName != null and olderName != ''">
  291. AND name like CONCAT('%',#{olderName},'%')
  292. </if>
  293. ) allOlderAmount,
  294. (select count(1) from care_older where station_id = #{stationId} and status not in ('0','1')
  295. <if test="olderName != null and olderName != ''">
  296. AND name like CONCAT('%',#{olderName},'%')
  297. </if>
  298. ) alarmOlderAmount
  299. from dual
  300. </select>
  301. <select id="selectBigScreenOlderCardListByCount" resultType="int" >
  302. SELECT
  303. count(1)
  304. FROM care_older a
  305. where a.station_id = #{stationId}
  306. <if test="olderName != null and olderName != ''">
  307. AND a.name like CONCAT('%',#{olderName},'%')
  308. </if>
  309. <if test="isAlarm == '1'.toString()">
  310. AND a.status not in ('1','2')
  311. </if>
  312. </select>
  313. <select id="selectBigScreenOlderCardListByPage" resultType="com.care.bigscreen.vo.BigScreenOlderDetailVO">
  314. SELECT
  315. a.id older_id,
  316. a.name,
  317. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.gender and sdc.type_code='gender') gender,
  318. ROUND(DATEDIFF(CURDATE(), a.birthday)/365.2422) age,
  319. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.live_type and sdc.type_code='older_live_type') live_type,
  320. a.bed_number,
  321. a.safe_level,
  322. ch.key_escrow_type,
  323. ch.addr,
  324. a.phone,
  325. <!--(case when (select count(1) from care_device b where b.dev_type='2' and b.id in (select c.dev_id from care_older_device_rel c where c.older_id = a.id)) > 0 then 'Y' else 'N' end) has_our_door_device,-->
  326. (select sdc.name from sys_dim_code sdc where sdc.dim_code = a.status and sdc.type_code='older_status') olderStatus,
  327. (select c.status from care_event_order c where c.older_id = a.id order by c.create_time desc limit 1) olderEventStatus
  328. FROM care_older a left join care_house_older_rel rel on a.id=older_id
  329. left join care_house ch on ch.id=rel.house_id
  330. where a.station_id = #{stationId}
  331. <if test="olderName != null and olderName != ''">
  332. AND a.name like CONCAT('%',#{olderName},'%')
  333. </if>
  334. <if test="isAlarm == '1'.toString()">
  335. AND a.status not in ('1','2')
  336. </if>
  337. order by ifnull((select c.status from care_event_order c where c.older_id = a.id order by c.create_time desc limit 1),99), a.modify_time desc
  338. LIMIT #{pageUtil.start}, #{pageUtil.pageSize}
  339. </select>
  340. </mapper>