AlarmStatMapper.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.bz.smart_city.dao.AlarmStatMapper">
  5. <sql id="where">
  6. <where>
  7. 1=1
  8. <if test="params.statDay != null">
  9. and t1.stat_day = #{params.statDay}
  10. </if>
  11. <if test="params.siteId != null">
  12. and t1.site_id = #{params.siteId}
  13. </if>
  14. <if test="params.sysId != null">
  15. and t1.sys_id = #{params.sysId}
  16. </if>
  17. <if test="params.buildingId != null">
  18. and t1.building_id = #{params.buildingId}
  19. </if>
  20. <if test="params.buildingId == null">
  21. and t1.building_id != 0
  22. </if>
  23. <if test="params.floor != null">
  24. and t1.floor = #{params.floor}
  25. </if>
  26. <if test="params.alarmCategory != null and params.alarmCategory != ''">
  27. and t1.alarm_category = #{params.alarmCategory}
  28. </if>
  29. <if test="params.alarmType != null">
  30. and t1.alarm_type = #{params.alarmType}
  31. </if>
  32. <if test="params.handleStatus != null">
  33. and t1.handle_status = #{params.handleStatus}
  34. </if>
  35. <if test="params.startDate != null and params.startDate != 0">
  36. and t1.stat_day >= #{params.startDate}
  37. </if>
  38. <if test="params.endDate != null and params.endDate != 0">
  39. and t1.stat_day &lt; #{params.endDate}
  40. </if>
  41. </where>
  42. </sql>
  43. <sql id="anotherWhere">
  44. <where>
  45. 1=1
  46. <if test="params.statDay != null">
  47. and t1.stat_day = #{params.statDay}
  48. </if>
  49. <if test="params.siteId != null and params.siteId != 0">
  50. and t1.site_id = #{params.siteId}
  51. </if>
  52. <if test="params.sysId != null and params.sysId != 0">
  53. and t1.sys_id = #{params.sysId}
  54. </if>
  55. <if test="params.buildingId != null and params.buildingId != 0">
  56. and t1.building_id = #{params.buildingId}
  57. </if>
  58. <if test='params.floor != null and params.floor != 0'>
  59. and t1.floor = #{params.floor}
  60. </if>
  61. <if test='params.alarmCategory != null and params.alarmCategory != "0"'>
  62. and t1.alarm_category = #{params.alarmCategory}
  63. </if>
  64. <if test="params.alarmType != null and params.alarmType != 0">
  65. and t1.alarm_type = #{params.alarmType}
  66. </if>
  67. <if test='params.handleStatus != null and params.handleStatus != "0" '>
  68. and t1.handle_status = #{params.handleStatus}
  69. </if>
  70. <if test="params.startDate != null and params.startDate != 0">
  71. and t1.alarm_time > #{params.startDate}
  72. </if>
  73. <if test="params.endDate != null and params.endDate != 0">
  74. and t1.alarm_time &lt; #{params.endDate}
  75. </if>
  76. <if test="params.sysIds != null and params.sysIds.size != 0">
  77. and t1.sys_id in
  78. <foreach collection="params.sysIds" item="sysId" index="index" separator="," open="(" close=")">
  79. #{sysId}
  80. </foreach>
  81. </if>
  82. <if test="params.sites != null and params.sites.size() != 0">
  83. and t1.site_id in
  84. <foreach collection="params.sites" item="site" open="(" separator="," close=")">
  85. #{site.id}
  86. </foreach>
  87. </if>
  88. </where>
  89. </sql>
  90. <!-- 查询告警天表 -->
  91. <select id="queryAlarmStatForDay" resultType="java.util.HashMap">
  92. SELECT
  93. t1.stat_day as statDay,
  94. t1.site_id as siteId,
  95. t4.`name` as siteName,
  96. t1.sys_id as sysId,
  97. t2.channel_name as sysName,
  98. t1.building_id as buildingId,
  99. t3.`name` as buildingName,
  100. t1.alarm_type as alarmTypeCode,
  101. t5.`name` as alarmTypeName,
  102. t1.alarm_category as alarmCategoryCode,
  103. t6.config_name as alarmCategoryName,
  104. t1.floor as floor,
  105. t1.handle_status as handlStatus,
  106. t7.config_name as handleStatusName,
  107. t1.alarm_times as alarmTimes,
  108. t1.alarm_device_num as alarmDeviceNumber
  109. FROM
  110. sc_stat_device_error_day t1
  111. LEFT JOIN sc_channel t2 ON ( t1.sys_id = t2.id )
  112. LEFT JOIN sc_building t3 ON ( t1.building_id = t3.id )
  113. LEFT JOIN sc_site t4 ON ( t1.site_id = t4.id )
  114. LEFT JOIN sc_alarm_type t5 ON ( t1.alarm_type = t5.id )
  115. LEFT JOIN sc_config_t t6 ON ( t1.alarm_category = t6.config_value AND t6.parent_id = 4)
  116. LEFT JOIN sc_config_t t7 ON ( t1.handle_status = t7.config_value AND t7.parent_id = 1)
  117. <include refid="where" />
  118. ${params.orderBy}
  119. <if test="limit != null and limit != 0">
  120. limit #{offset}, #{limit}
  121. </if>
  122. </select>
  123. <!-- 查询告警7天表 -->
  124. <select id="queryAlarmStatFor7Day" resultType="java.util.HashMap">
  125. SELECT
  126. t1.stat_day as statDay,
  127. t1.site_id as siteId,
  128. t4.`name` as siteName,
  129. t1.sys_id as sysId,
  130. t2.channel_name as sysName,
  131. t1.building_id as buildingId,
  132. t3.`name` as buildingName,
  133. t1.alarm_type as alarmTypeCode,
  134. t5.`name` as alarmTypeName,
  135. t1.alarm_category as alarmCategoryCode,
  136. t6.config_name as alarmCategoryName,
  137. t1.floor as floor,
  138. t1.handle_status as handlStatus,
  139. t7.config_name as handleStatusName,
  140. t1.alarm_times as alarmTimes,
  141. t1.alarm_device_num as alarmDeviceNumber
  142. FROM
  143. sc_stat_device_error_7day t1
  144. LEFT JOIN sc_channel t2 ON ( t1.sys_id = t2.id )
  145. LEFT JOIN sc_building t3 ON ( t1.building_id = t3.id )
  146. LEFT JOIN sc_site t4 ON ( t1.site_id = t4.id )
  147. LEFT JOIN sc_alarm_type t5 ON ( t1.alarm_type = t5.id )
  148. LEFT JOIN sc_config_t t6 ON ( t1.alarm_category = t6.config_value AND t6.parent_id = 4)
  149. LEFT JOIN sc_config_t t7 ON ( t1.handle_status = t7.config_value AND t7.parent_id = 1)
  150. <include refid="where" />
  151. ${params.orderBy}
  152. <if test="limit != null and limit != 0">
  153. limit #{offset}, #{limit}
  154. </if>
  155. </select>
  156. <!-- 查询告警30天表 -->
  157. <select id="queryAlarmStatFor30Day" resultType="java.util.HashMap">
  158. SELECT
  159. t1.stat_day as statDay,
  160. t1.site_id as siteId,
  161. t4.`name` as siteName,
  162. t1.sys_id as sysId,
  163. t2.channel_name as sysName,
  164. t1.building_id as buildingId,
  165. t3.`name` as buildingName,
  166. t1.alarm_type as alarmTypeCode,
  167. t5.`name` as alarmTypeName,
  168. t1.alarm_category as alarmCategoryCode,
  169. t6.config_name as alarmCategoryName,
  170. t1.floor as floor,
  171. t1.handle_status as handlStatus,
  172. t7.config_name as handleStatusName,
  173. t1.alarm_times as alarmTimes,
  174. t1.alarm_device_num as alarmDeviceNumber
  175. FROM
  176. sc_stat_device_error_30day t1
  177. LEFT JOIN sc_channel t2 ON ( t1.sys_id = t2.id )
  178. LEFT JOIN sc_building t3 ON ( t1.building_id = t3.id )
  179. LEFT JOIN sc_site t4 ON ( t1.site_id = t4.id )
  180. LEFT JOIN sc_alarm_type t5 ON ( t1.alarm_type = t5.id )
  181. LEFT JOIN sc_config_t t6 ON ( t1.alarm_category = t6.config_value AND t6.parent_id = 4)
  182. LEFT JOIN sc_config_t t7 ON ( t1.handle_status = t7.config_value AND t7.parent_id = 1)
  183. <include refid="where" />
  184. ${params.orderBy}
  185. <if test="limit != null and limit != 0">
  186. limit #{offset}, #{limit}
  187. </if>
  188. </select>
  189. <!-- 查询原始记录表 -->
  190. <select id="queryAlarmBuilding" resultType="java.util.HashMap">
  191. SELECT
  192. t1.building_id as buildingId,
  193. t2.name as buildingName,
  194. count(1) as alarmTimes
  195. FROM
  196. sc_device_error t1
  197. LEFT JOIN sc_building t2 ON ( t1.building_id = t2.id)
  198. <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.device_id and sdd.status = 1)</if>
  199. <include refid="anotherWhere" />
  200. and t1.status = 1 and t1.sys_id != -99
  201. <if test="params.programItems != null and params.programItems.size() != 0"> and
  202. <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  203. sdd.${item.dimensionCode} = #{item.dimensionValue}
  204. </foreach>
  205. </if>
  206. GROUP BY t1.building_id
  207. ${params.orderBy}
  208. <if test="limit != null and limit != 0">
  209. limit #{offset}, #{limit}
  210. </if>
  211. </select>
  212. <select id="queryAlarmCategory" resultType="java.util.HashMap">
  213. SELECT
  214. DATE_FORMAT(t1.alarm_time,'%Y%m%d') as statDay,
  215. t1.alarm_category as alarmCategoryCode,
  216. t2.config_name as alarmCategoryName,
  217. count( 1 ) as alarmTimes
  218. FROM
  219. sc_device_error t1
  220. LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
  221. <include refid="anotherWhere" />
  222. and t1.status = 1
  223. <if test='params.programItems != null and params.programItems.size() != 0' >
  224. and EXISTS (
  225. select 1 from
  226. (select
  227. distinct df.device_id
  228. FROM sc_device_dim_info df
  229. WHERE 1 = 1
  230. and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  231. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  232. </foreach> ) ud WHERE ud.device_id = t1.device_id)
  233. </if>
  234. GROUP BY
  235. DATE_FORMAT(t1.alarm_time,'%Y%m%d'),t1.alarm_category,t2.config_name
  236. </select>
  237. <select id="queryAlarmCategoryStat" resultType="java.util.HashMap">
  238. SELECT
  239. t1.alarm_category as alarmCategoryCode,
  240. t2.config_name as alarmCategoryName,
  241. count( 1 ) as alarmTimes
  242. FROM
  243. sc_device_error t1
  244. LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
  245. <include refid="anotherWhere" />
  246. and t1.status = 1
  247. GROUP BY
  248. t1.alarm_category,t2.config_name
  249. </select>
  250. <select id="queryAlarmStatus" resultType="java.util.HashMap">
  251. SELECT
  252. t1.handle_status as handlStatus,
  253. t2.config_name as handleStatusName,
  254. count(1) as alarmDeviceNumber
  255. FROM
  256. sc_device_error t1
  257. LEFT JOIN sc_config_t t2 ON ( t1.handle_status = t2.config_value AND t2.parent_id = 1 )
  258. <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.device_id and sdd.status = 1)</if>
  259. <include refid="anotherWhere" />
  260. and t1.status = 1
  261. <!-- 添加权限控制 -->
  262. <if test="params.programItems != null and params.programItems.size() != 0"> and
  263. <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  264. sdd.${item.dimensionCode} = #{item.dimensionValue}
  265. </foreach>
  266. </if>
  267. GROUP BY
  268. t1.handle_status,t2.config_name
  269. </select>
  270. <select id="queryAlarmType" resultType="java.util.HashMap">
  271. SELECT
  272. t1.alarm_type_id AS alarmTypeCode,
  273. t2.`name` AS alarmTypeName,
  274. count(1) as alarmDeviceNumber
  275. FROM
  276. sc_device_error t1
  277. LEFT JOIN sc_alarm_type t2 ON ( t1.alarm_type_id = t2.id )
  278. <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.device_id and sdd.status = 1)</if>
  279. <include refid="anotherWhere" />
  280. and t1.status = 1
  281. <!-- 添加权限控制 -->
  282. <if test="params.programItems != null and params.programItems.size() != 0"> and
  283. <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  284. sdd.${item.dimensionCode} = #{item.dimensionValue}
  285. </foreach>
  286. </if>
  287. GROUP BY
  288. t1.alarm_type_id,t2.`name`
  289. </select>
  290. <select id="queryDeviceStatus" resultType="java.util.HashMap">
  291. SELECT
  292. t1.device_status as statusCode,
  293. t2.config_name as statusName,
  294. COUNT(t1.device_no) as numberOfDevice
  295. FROM
  296. sc_device t1
  297. LEFT JOIN sc_config_t t2 ON ( t1.device_status = t2.config_value AND t2.parent_id = 7 )
  298. <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.id and sdd.status = 1)</if>
  299. <include refid="anotherWhere" />
  300. <if test="params.programItems != null and params.programItems.size() != 0"> and
  301. <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  302. sdd.${item.dimensionCode} = #{item.dimensionValue}
  303. </foreach>
  304. </if>
  305. and t1.sys_id != -99
  306. and t1.status = 1
  307. and t1.building_id is not null
  308. GROUP BY t1.device_status,t2.config_name
  309. </select>
  310. <select id="queryAlarmHandleType" resultType="java.util.HashMap">
  311. SELECT
  312. t1.handle_type as handleTypeCode,
  313. t2.config_name as handleTypeName,
  314. count(DISTINCT t1.device_id) as numberOfDevice
  315. FROM
  316. sc_device_error_handle t1
  317. LEFT JOIN sc_config_t t2 on(t1.handle_type = t2.config_value and t2.parent_id = 13 )
  318. <include refid="anotherWhere" />
  319. and t1.status = 1
  320. GROUP BY t1.handle_type, t2.config_name
  321. </select>
  322. <select id="queryAlarmIsHandleStatByAdmin" resultType="com.bz.smart_city.entity.AlarmIsHandledStat">
  323. SELECT
  324. count(1) as times,
  325. count(distinct t1.device_no) as count,
  326. t1.handle_status as is_handle_value,
  327. t2.config_name as is_handle_name
  328. FROM
  329. sc_device_error t1
  330. LEFT JOIN sc_config_t t2 ON ( t1.handle_status = t2.config_value AND t2.parent_id = 1 )
  331. <include refid="anotherWhere" />
  332. and t1.`status` = 1
  333. group by t1.handle_status, t2.config_name
  334. </select>
  335. <select id="queryAlarmIsHandleStatByUser" resultType="com.bz.smart_city.entity.AlarmIsHandledStat">
  336. SELECT
  337. count( 1 ) AS times,
  338. count( DISTINCT t1.device_no ) AS count,
  339. t1.handle_status AS is_hanlde_value,
  340. t2.config_name AS is_handle_name
  341. FROM
  342. sc_device_error t1
  343. LEFT JOIN sc_config_t t2 ON ( t1.handle_status = t2.config_value AND t2.parent_id = 1 )
  344. <include refid="anotherWhere" />
  345. and t1.`status` = 1
  346. <if test='params.programItems != null and params.programItems.size() != 0' >
  347. and EXISTS (
  348. select 1 from
  349. (select
  350. distinct df.device_id
  351. FROM sc_device_dim_info df
  352. WHERE 1 = 1
  353. and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  354. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  355. </foreach> ) ud WHERE ud.device_id = t1.device_id)
  356. </if>
  357. <!--
  358. AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
  359. -->
  360. GROUP BY
  361. t1.handle_status,
  362. t2.config_name
  363. </select>
  364. <select id="queryDeviceTypeAndStatusStatByAdmin" resultType="com.bz.smart_city.entity.DeviceTypeAndStatusStat">
  365. SELECT
  366. count(1) as total ,
  367. t1.device_type as device_type_id,
  368. dt.equipment_type as device_type_name,
  369. SUM(IF(t1.device_status = 1, 1, 0)) as normal_count,
  370. SUM(IF(t1.device_status != 1, 1, 0)) as abnormal_count,
  371. SUM(IF(t1.device_status = 2, 1, 0)) as fault_count,
  372. SUM(IF(t1.device_status = 4, 1, 0)) as early_warning_count,
  373. SUM(IF(t1.device_status = 5, 1, 0)) as not_enabled_count
  374. FROM
  375. sc_device t1
  376. left join sc_device_type dt on (t1.device_type = dt.id and dt.`status` = 1)
  377. WHERE
  378. t1.`status` = 1
  379. GROUP BY
  380. t1.device_type,dt.equipment_type
  381. </select>
  382. <select id="queryDeviceTypeAndStatusStatByUser" resultType="com.bz.smart_city.entity.DeviceTypeAndStatusStat">
  383. SELECT
  384. count(1) as total ,
  385. t1.device_type as device_type_id,
  386. dt.equipment_type as device_type_name,
  387. SUM(IF(t1.device_status = 1, 1, 0)) as normal_count,
  388. SUM(IF(t1.device_status != 1, 1, 0)) as abnormal_count,
  389. SUM(IF(t1.device_status = 2, 1, 0)) as fault_count,
  390. SUM(IF(t1.device_status = 4, 1, 0)) as early_warning_count,
  391. SUM(IF(t1.device_status = 5, 1, 0)) as not_enabled_count
  392. FROM
  393. sc_device t1
  394. <!--
  395. inner join v_sc_user_device t2 on (t1.device_no = t2.device_no and t2.user_id = #{params.userId})
  396. -->
  397. left join sc_device_type dt on (t1.device_type = dt.id and dt.`status` = 1)
  398. <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.id and sdd.status = 1)</if>
  399. <include refid="anotherWhere" />
  400. and t1.sys_id != -99
  401. <!--
  402. <if test='params.programItems != null and params.programItems.size() != 0' >
  403. and EXISTS (
  404. select 1 from
  405. (select
  406. distinct df.device_id
  407. FROM sc_device_dim_info df
  408. WHERE 1 = 1
  409. and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  410. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  411. </foreach> ) ud WHERE ud.device_id = t1.id)
  412. </if>
  413. -->
  414. and t1.`status` = 1
  415. <if test="params.programItems != null and params.programItems.size() != 0"> and
  416. <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  417. sdd.${item.dimensionCode} = #{item.dimensionValue}
  418. </foreach>
  419. </if>
  420. GROUP BY
  421. t1.device_type,dt.equipment_type
  422. </select>
  423. <select id="queryAlarmTypeStatByAdmin" resultType="com.bz.smart_city.entity.AlarmTypeStat">
  424. select
  425. count(distinct t1.device_no) as number_of_alarm_device,
  426. count(1) as alarm_times,
  427. t2.name as alarm_type_name
  428. FROM
  429. sc_device_error t1
  430. left join sc_alarm_type t2 on (t1.alarm_type_id = t2.id)
  431. <include refid="anotherWhere" />
  432. and t1.`status` = 1
  433. GROUP BY alarm_type_name
  434. order by alarm_times desc
  435. </select>
  436. <select id="queryAlarmTypeStatByUser" resultType="com.bz.smart_city.entity.AlarmTypeStat">
  437. SELECT
  438. sum( number_of_alarm_device ) as number_of_alarm_device,
  439. sum( alarm_times ) AS alarm_times,
  440. t2.`name` as alarm_type_name
  441. FROM
  442. (
  443. SELECT
  444. count( DISTINCT t1.device_no ) AS number_of_alarm_device,
  445. count( 1 ) AS alarm_times,
  446. t1.alarm_type_id
  447. FROM
  448. sc_device_error t1 FORCE INDEX ( alarm_time )
  449. <include refid="anotherWhere" />
  450. and t1.`status` = 1
  451. <if test="params.buildingIds != null and params.buildingIds.size() != 0">
  452. and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  453. </if>
  454. GROUP BY
  455. t1.alarm_type_id
  456. ) tmp
  457. LEFT JOIN sc_alarm_type t2 ON ( tmp.alarm_type_id = t2.id )
  458. GROUP BY
  459. t2.`name`
  460. ORDER BY
  461. alarm_times DESC
  462. <!--
  463. select
  464. count(distinct t1.device_no) as number_of_alarm_device,
  465. count(1) as alarm_times,
  466. t2.name as alarm_type_name
  467. FROM
  468. sc_device_error t1
  469. left join sc_alarm_type t2 on (t1.alarm_type_id = t2.id)
  470. <include refid="anotherWhere" />
  471. and t1.`status` = 1
  472. <if test="params.buildingIds != null and params.buildingIds.size() != 0">
  473. and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  474. </if>
  475. -->
  476. <!--
  477. <if test='params.programItems != null and params.programItems.size() != 0' >
  478. and EXISTS (
  479. select 1 from
  480. (select
  481. distinct df.device_id
  482. FROM sc_device_dim_info df
  483. WHERE 1 = 1
  484. and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  485. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  486. </foreach> ) ud WHERE ud.device_id = t1.device_id)
  487. </if>
  488. -->
  489. <!--
  490. AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
  491. GROUP BY alarm_type_name
  492. order by alarm_times desc
  493. -->
  494. </select>
  495. <select id="queryAlarmCategoryStatByAdmin" resultType="com.bz.smart_city.entity.AlarmCategoryStat">
  496. SELECT
  497. DATE_FORMAT(t1.alarm_time,'%Y%m%d') as stat_date,
  498. t1.alarm_category as alarm_category_code,
  499. t2.config_name as alarm_category_name,
  500. count( 1 ) as alarm_times
  501. FROM
  502. sc_device_error t1
  503. LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
  504. <include refid="anotherWhere" />
  505. and t1.status = 1
  506. GROUP BY
  507. DATE_FORMAT(t1.alarm_time,'%Y%m%d'),t1.alarm_category,t2.config_name
  508. order by stat_date asc
  509. </select>
  510. <select id="queryAlarmCategoryStatByUser" resultType="com.bz.smart_city.entity.AlarmCategoryStat">
  511. SELECT
  512. stat_date as stat_date,
  513. alarm_category as alarm_category_code,
  514. t2.config_name as alarm_category_name,
  515. alarm_times
  516. FROM
  517. (
  518. SELECT
  519. DATE_FORMAT( t1.alarm_time, '%Y%m%d' ) AS stat_date,
  520. t1.alarm_category,
  521. count( 1 ) AS alarm_times
  522. FROM
  523. sc_device_error t1 FORCE INDEX ( alarm_time )
  524. <include refid="anotherWhere" />
  525. and t1.status = 1
  526. <if test="params.buildingIds != null and params.buildingIds.size() != 0">
  527. and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  528. </if>
  529. GROUP BY
  530. DATE_FORMAT( t1.alarm_time, '%Y%m%d' ),
  531. t1.alarm_category
  532. ) tmp
  533. LEFT JOIN sc_config_t t2 ON ( tmp.alarm_category = t2.config_value AND t2.parent_id = 4 )
  534. ORDER BY
  535. stat_date ASC
  536. <!--
  537. SELECT
  538. DATE_FORMAT(t1.alarm_time,'%Y%m%d') as stat_date,
  539. t1.alarm_category as alarm_category_code,
  540. t2.config_name as alarm_category_name,
  541. count( 1 ) as alarm_times
  542. FROM
  543. sc_device_error t1
  544. LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
  545. <include refid="anotherWhere" />
  546. and t1.status = 1
  547. <if test="params.buildingIds != null and params.buildingIds.size() != 0">
  548. and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  549. </if>
  550. -->
  551. <!--
  552. <if test='params.programItems != null and params.programItems.size() != 0' >
  553. and EXISTS (
  554. select 1 from
  555. (select
  556. distinct df.device_id
  557. FROM sc_device_dim_info df
  558. WHERE 1 = 1
  559. and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  560. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  561. </foreach> ) ud WHERE ud.device_id = t1.device_id)
  562. </if>
  563. -->
  564. <!--
  565. AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
  566. GROUP BY
  567. DATE_FORMAT(t1.alarm_time,'%Y%m%d'),t1.alarm_category,t2.config_name
  568. order by stat_date asc
  569. -->
  570. </select>
  571. <select id="queryAlarmHandleStatByAdmin" resultType="com.bz.smart_city.entity.AlarmHandleStat">
  572. SELECT
  573. DATE_FORMAT( t1.alarm_time, '%Y%m%d' ) as stat_date,
  574. count( 1 ) as total_alarm_times,
  575. SUM(IF(t1.`handle_status` = 1, 1, 0)) as handled_alarm_times,
  576. SUM(IF(t1.`handle_status` = 2, 1, 0)) as unhandle_alarm_times,
  577. CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 2, 1, 0))/ COUNT(1)*100, 2), '%') as unhandle_percentage,
  578. CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 1, 1, 0))/ COUNT(1)*100, 2), '%') as handled_percentage
  579. FROM
  580. sc_device_error t1
  581. <include refid="anotherWhere" />
  582. AND t1.STATUS = 1
  583. GROUP BY
  584. DATE_FORMAT( t1.alarm_time, '%Y%m%d' )
  585. order by stat_date asc
  586. </select>
  587. <select id="queryAlarmHandleStatByUser" resultType="com.bz.smart_city.entity.AlarmHandleStat">
  588. SELECT
  589. DATE_FORMAT( t1.alarm_time, '%Y%m%d' ) as stat_date,
  590. count( 1 ) as total_alarm_times,
  591. SUM(IF(t1.`handle_status` = 1, 1, 0)) as handled_alarm_times,
  592. SUM(IF(t1.`handle_status` = 2, 1, 0)) as unhandle_alarm_times,
  593. CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 2, 1, 0))/ COUNT(1)*100, 2), '%') as unhandle_percentage,
  594. CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 1, 1, 0))/ COUNT(1)*100, 2), '%') as handled_percentage
  595. FROM
  596. sc_device_error t1
  597. <include refid="anotherWhere" />
  598. AND t1.STATUS = 1
  599. <if test="params.buildingIds != null and params.buildingIds.size() != 0">
  600. and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  601. </if>
  602. <!--
  603. AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
  604. -->
  605. <!--
  606. <if test='params.programItems != null and params.programItems.size() != 0' >
  607. and EXISTS (
  608. select 1 from
  609. (select
  610. distinct df.device_id
  611. FROM sc_device_dim_info df
  612. WHERE 1 = 1
  613. and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
  614. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  615. </foreach> ) ud WHERE ud.device_id = t1.device_id)
  616. </if>
  617. -->
  618. GROUP BY
  619. DATE_FORMAT( t1.alarm_time, '%Y%m%d' )
  620. order by stat_date asc
  621. </select>
  622. </mapper>