| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zksy.base.warning.mapper.EarlyWarningMapper">
- <resultMap id="BaseResultMap" type="com.zksy.base.warning.domain.EarlyWarning">
- <id column="warning_id" property="warningId"/>
- <result column="warning_no" property="warningNo"/>
- <result column="warning_type" property="warningType"/>
- <result column="warning_level" property="warningLevel"/>
- <result column="warning_special" property="warningSpecial"/>
- <result column="disposal_deadline" property="disposalDeadline"/>
- <result column="stage_deadline" property="stageDeadline"/>
- <result column="item_id" property="itemId"/>
- <result column="item_snapshot" property="itemSnapshot"/>
- <result column="device_code" property="deviceCode"/>
- <result column="device_name" property="deviceName"/>
- <result column="location" property="location"/>
- <result column="ownership_unit" property="ownershipUnit"/>
- <result column="publisher" property="publisher"/>
- <result column="publish_time" property="publishTime"/>
- <result column="handler" property="handler"/>
- <result column="reviewer" property="reviewer"/>
- <result column="status" property="status"/>
- <result column="warning_content" property="warningContent"/>
- <result column="process_instance_id" property="processInstanceId"/>
- <result column="create_by" property="createBy"/>
- <result column="create_time" property="createTime"/>
- <result column="update_by" property="updateBy"/>
- <result column="update_time" property="updateTime"/>
- <result column="remark" property="remark"/>
- </resultMap>
- <!-- 预警位置不再落库:统一由设备台账位置回填,出参字段名 location 保持不变。 -->
- <sql id="DeviceLocationColumn">(SELECT e.equipment_location FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS location</sql>
- <sql id="Base_Column_List">
- warning_id, warning_no, warning_type, warning_level, warning_special,
- disposal_deadline, stage_deadline, item_id, item_snapshot, device_code, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name,
- <include refid="DeviceLocationColumn"/>, ownership_unit, publisher, publish_time, handler, reviewer,
- status, warning_content, process_instance_id, create_by, create_time, update_by,
- update_time, remark
- </sql>
- <!-- The city-life project only contains water supply, drainage, gas and manhole warnings. -->
- <sql id="SupportedDashboardWarningTypes">
- AND EXISTS (SELECT 1 FROM app_user.warning_type wt WHERE wt.warning_code = w.warning_type)
- </sql>
- <sql id="DashboardWarningTypeFilter">
- <if test="warningType != null and warningType != ''">AND w.warning_type = #{warningType}</if>
- </sql>
- <sql id="DashboardWarningLevelFilter">
- <if test="warningLevel != null and warningLevel != ''">AND w.warning_level = #{warningLevel}</if>
- </sql>
- <sql id="DashboardWarningColumns">
- w.warning_id,
- w.warning_no,
- w.warning_type,
- (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name,
- w.warning_level,
- w.warning_special,
- <include refid="DeviceLocationColumn"/>,
- w.ownership_unit,
- w.publisher,
- w.publish_time,
- w.handler,
- w.status,
- w.warning_content,
- w.create_time,
- w.update_time,
- w.device_code,
- (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name
- </sql>
- <sql id="DashboardResolvedTimeJoin">
- LEFT JOIN (
- SELECT warning_id, MAX(create_time) AS resolved_time
- FROM app_user.warning_disposal
- WHERE disposal_type IN ('RESOLVE', 'CLOSE', 'CLEAR', 'AUTO_CLEAR')
- GROUP BY warning_id
- ) resolved_record ON resolved_record.warning_id = w.warning_id
- </sql>
- <!-- 统计今日预警核心指标 -->
- <select id="selectTodayWarningStats" resultType="java.util.Map">
- SELECT
- COUNT(CASE WHEN w.status != 'DRAFT' THEN 1 END) AS today_total,
- COUNT(CASE WHEN w.status = 'HANDLED' THEN 1 END) AS handled_today,
- COUNT(CASE WHEN w.status = 'CLOSED' THEN 1 END) AS closed_today
- FROM app_user.early_warning w
- WHERE w.publish_time >= CURRENT_DATE
- AND w.publish_time < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND w.publish_time <= CURRENT_TIMESTAMP
- <include refid="SupportedDashboardWarningTypes"/>
- </select>
- <!-- 查询今日预警列表 -->
- <select id="selectTodayWarningList" resultMap="BaseResultMap">
- SELECT <include refid="Base_Column_List"/>
- FROM app_user.early_warning w
- WHERE w.publish_time >= CURRENT_DATE
- AND w.publish_time < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND w.publish_time <= CURRENT_TIMESTAMP
- <include refid="SupportedDashboardWarningTypes"/>
- <choose>
- <when test="status != null and status != ''">
- AND w.status = #{status}
- </when>
- <otherwise>
- AND w.status != 'DRAFT'
- </otherwise>
- </choose>
- ORDER BY w.publish_time DESC
- </select>
- <!-- 按日统计预警发展趋势 -->
- <select id="selectWarningTrendByDay" resultType="java.util.Map">
- SELECT
- TO_CHAR(publish_time, 'YYYY-MM-DD') AS stat_date,
- COALESCE(NULLIF(warning_special, ''), '其他') AS warning_special,
- COUNT(*) AS warning_count
- FROM app_user.early_warning
- WHERE status != 'DRAFT'
- AND EXISTS (SELECT 1 FROM app_user.warning_type wt WHERE wt.warning_code = early_warning.warning_type)
- <if test="startTime != null">
- AND publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND COALESCE(NULLIF(warning_special, ''), '其他') = #{warningSpecial}
- </if>
- GROUP BY TO_CHAR(publish_time, 'YYYY-MM-DD'), COALESCE(NULLIF(warning_special, ''), '其他')
- ORDER BY stat_date ASC, warning_special ASC
- </select>
- <!-- 按月统计预警发展趋势 -->
- <select id="selectWarningTrendByMonth" resultType="java.util.Map">
- SELECT
- TO_CHAR(publish_time, 'YYYY-MM') AS stat_month,
- COALESCE(NULLIF(warning_special, ''), '其他') AS warning_special,
- COUNT(*) AS warning_count
- FROM app_user.early_warning
- WHERE status != 'DRAFT'
- AND EXISTS (SELECT 1 FROM app_user.warning_type wt WHERE wt.warning_code = early_warning.warning_type)
- <if test="startTime != null">
- AND publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND COALESCE(NULLIF(warning_special, ''), '其他') = #{warningSpecial}
- </if>
- GROUP BY TO_CHAR(publish_time, 'YYYY-MM'), COALESCE(NULLIF(warning_special, ''), '其他')
- ORDER BY stat_month ASC, warning_special ASC
- </select>
- <!-- 处置状态分析:按预警状态分组统计数量 -->
- <select id="selectWarningGroupByStatus" resultType="java.util.Map">
- SELECT
- status,
- COUNT(warning_id) AS status_count
- FROM app_user.early_warning
- WHERE status != 'DRAFT'
- AND EXISTS (SELECT 1 FROM app_user.warning_type wt WHERE wt.warning_code = early_warning.warning_type)
- <if test="startTime != null">
- AND publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND warning_special = #{warningSpecial}
- </if>
- GROUP BY status
- ORDER BY status_count DESC
- </select>
- <select id="selectDisposalGroupByType" resultType="java.util.Map">
- SELECT d.disposal_type, COUNT(*) AS disposal_count
- FROM app_user.warning_disposal d
- INNER JOIN app_user.early_warning w ON w.warning_id = d.warning_id
- WHERE w.status != 'DRAFT'
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- GROUP BY d.disposal_type
- ORDER BY disposal_count DESC
- </select>
- <!-- 处置时效分析-概览指标统计 -->
- <select id="selectDisposeEfficiencyOverview" resultType="java.util.Map">
- SELECT
- ROUND(AVG(dispose_hours), 2) AS avg_hours,
- ROUND(MAX(dispose_hours), 2) AS max_hours,
- ROUND(MIN(dispose_hours), 2) AS min_hours,
- COUNT(*) AS total_count
- FROM (
- SELECT
- EXTRACT(EPOCH FROM (CAST(MAX(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600 AS dispose_hours
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d
- ON w.warning_id = d.warning_id
- AND d.disposal_type IN ('HANDLE', 'RESOLVE', 'CLEAR', 'CLOSE', 'MISREPORT', 'AUTO_CLEAR')
- WHERE w.status IN ('HANDLED', 'CLOSED')
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- GROUP BY w.warning_id, w.publish_time
- HAVING MAX(d.create_time) >= w.publish_time
- ) AS temp
- </select>
- <!-- 处置时效分析-时效区间分布统计 -->
- <select id="selectDisposeEfficiencyRange" resultType="java.util.Map">
- SELECT
- CASE
- WHEN dispose_hours <= 2 THEN '0-2小时'
- WHEN dispose_hours <= 6 THEN '2-6小时'
- WHEN dispose_hours <= 24 THEN '6-24小时'
- ELSE '24小时以上'
- END AS time_range,
- COUNT(*) AS warning_count
- FROM (
- SELECT
- EXTRACT(EPOCH FROM (CAST(MAX(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600 AS dispose_hours
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d
- ON w.warning_id = d.warning_id
- AND d.disposal_type IN ('HANDLE', 'RESOLVE', 'CLEAR', 'CLOSE', 'MISREPORT', 'AUTO_CLEAR')
- WHERE w.status IN ('HANDLED', 'CLOSED')
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- GROUP BY w.warning_id, w.publish_time
- HAVING MAX(d.create_time) >= w.publish_time
- ) AS temp
- GROUP BY time_range
- ORDER BY
- CASE time_range
- WHEN '0-2小时' THEN 1
- WHEN '2-6小时' THEN 2
- WHEN '6-24小时' THEN 3
- ELSE 4
- END ASC
- </select>
- <!-- 处置时效分析-按预警专项统计平均时效 -->
- <select id="selectDisposeEfficiencyBySpecial" resultType="java.util.Map">
- SELECT
- COALESCE(NULLIF(warning_special, ''), '其他') AS warning_special,
- COUNT(*) AS warning_count,
- ROUND(AVG(dispose_hours), 2) AS avg_dispose_hours
- FROM (
- SELECT
- COALESCE(NULLIF(w.warning_special, ''), '其他') AS warning_special,
- EXTRACT(EPOCH FROM (CAST(MAX(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600 AS dispose_hours
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d
- ON w.warning_id = d.warning_id
- AND d.disposal_type IN ('HANDLE', 'RESOLVE', 'CLEAR', 'CLOSE', 'MISREPORT', 'AUTO_CLEAR')
- WHERE w.status IN ('HANDLED', 'CLOSED')
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND COALESCE(NULLIF(w.warning_special, ''), '其他') = #{warningSpecial}
- </if>
- GROUP BY w.warning_id, COALESCE(NULLIF(w.warning_special, ''), '其他'), w.publish_time
- HAVING MAX(d.create_time) >= w.publish_time
- ) AS temp
- GROUP BY warning_special
- ORDER BY avg_dispose_hours DESC
- </select>
- <!-- 处置时效分析-明细列表 -->
- <select id="selectDisposeEfficiencyList" resultType="java.util.Map">
- SELECT
- w.warning_id,
- w.warning_no,
- COALESCE(w.warning_special, '其他') AS warning_special,
- w.publish_time,
- MAX(d.create_time) AS dispose_time,
- ROUND(EXTRACT(EPOCH FROM (CAST(MAX(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600, 2) AS dispose_hours,
- w.status
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d
- ON w.warning_id = d.warning_id
- AND d.disposal_type IN ('HANDLE', 'RESOLVE', 'CLEAR', 'CLOSE', 'MISREPORT', 'AUTO_CLEAR')
- WHERE w.status IN ('HANDLED', 'CLOSED')
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- GROUP BY w.warning_id, w.warning_no, w.warning_special, w.publish_time, w.status
- HAVING MAX(d.create_time) >= w.publish_time
- ORDER BY dispose_hours
- <if test="sortType != null and sortType == 'desc'">
- DESC
- </if>
- <if test="sortType == null or sortType == 'asc'">
- ASC
- </if>
- </select>
- <!-- 接警效率分析-概览指标统计 -->
- <select id="selectReceiveEfficiencyOverview" resultType="java.util.Map">
- SELECT
- ROUND(AVG(receive_hours), 2) AS avg_hours,
- ROUND(MAX(receive_hours), 2) AS max_hours,
- ROUND(MIN(receive_hours), 2) AS min_hours,
- COUNT(*) AS total_count
- FROM (
- SELECT
- EXTRACT(EPOCH FROM (CAST(MIN(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600 AS receive_hours
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d ON w.warning_id = d.warning_id
- WHERE w.status != 'DRAFT'
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <include refid="DashboardWarningTypeFilter"/>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- <if test="status != null and status != ''">
- AND w.status = #{status}
- </if>
- GROUP BY w.warning_id, w.publish_time
- HAVING MIN(d.create_time) >= w.publish_time
- ) AS temp
- </select>
- <!-- 接警效率分析-时效区间分布统计 -->
- <select id="selectReceiveEfficiencyRange" resultType="java.util.Map">
- SELECT
- CASE
- WHEN receive_hours <= 0.5 THEN '0-30分钟'
- WHEN receive_hours <= 2 THEN '30分钟-2小时'
- WHEN receive_hours <= 6 THEN '2-6小时'
- ELSE '6小时以上'
- END AS time_range,
- COUNT(*) AS warning_count
- FROM (
- SELECT
- EXTRACT(EPOCH FROM (CAST(MIN(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600 AS receive_hours
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d ON w.warning_id = d.warning_id
- WHERE w.status != 'DRAFT'
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <include refid="DashboardWarningTypeFilter"/>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- <if test="status != null and status != ''">
- AND w.status = #{status}
- </if>
- GROUP BY w.warning_id, w.publish_time
- HAVING MIN(d.create_time) >= w.publish_time
- ) AS temp
- GROUP BY time_range
- ORDER BY
- CASE time_range
- WHEN '0-30分钟' THEN 1
- WHEN '30分钟-2小时' THEN 2
- WHEN '2-6小时' THEN 3
- ELSE 4
- END ASC
- </select>
- <!-- 接警效率分析-按预警类型统计平均时效 -->
- <select id="selectReceiveEfficiencyByType" resultType="java.util.Map">
- SELECT
- COALESCE(warning_type, '其他') AS warning_type,
- COUNT(*) AS warning_count,
- ROUND(AVG(receive_hours), 2) AS avg_receive_hours
- FROM (
- SELECT
- w.warning_type,
- EXTRACT(EPOCH FROM (CAST(MIN(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600 AS receive_hours
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d ON w.warning_id = d.warning_id
- WHERE w.status != 'DRAFT'
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <include refid="DashboardWarningTypeFilter"/>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- <if test="status != null and status != ''">
- AND w.status = #{status}
- </if>
- GROUP BY w.warning_id, w.warning_type, w.publish_time
- HAVING MIN(d.create_time) >= w.publish_time
- ) AS temp
- GROUP BY warning_type
- ORDER BY avg_receive_hours DESC
- </select>
- <!-- 接警效率分析-明细列表 -->
- <select id="selectReceiveEfficiencyList" resultType="java.util.Map">
- SELECT
- w.warning_id,
- w.warning_no,
- COALESCE(w.warning_type, '其他') AS warning_type,
- COALESCE(w.warning_special, '其他') AS warning_special,
- w.publish_time,
- MIN(d.create_time) AS receive_time,
- ROUND(EXTRACT(EPOCH FROM (CAST(MIN(d.create_time) AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ))) / 3600, 2) AS receive_hours,
- w.status
- FROM app_user.early_warning w
- INNER JOIN app_user.warning_disposal d ON w.warning_id = d.warning_id
- WHERE w.status != 'DRAFT'
- <include refid="SupportedDashboardWarningTypes"/>
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <include refid="DashboardWarningTypeFilter"/>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND w.warning_special = #{warningSpecial}
- </if>
- <if test="status != null and status != ''">
- AND w.status = #{status}
- </if>
- GROUP BY w.warning_id, w.warning_no, w.warning_type,
- w.warning_special, w.publish_time, w.status
- HAVING MIN(d.create_time) >= w.publish_time
- ORDER BY receive_hours
- <if test="sortType != null and sortType == 'desc'">
- DESC
- </if>
- <if test="sortType == null or sortType == 'asc'">
- ASC
- </if>
- </select>
- <!-- ————————————————————————————————————————————————————————————— -->
- <!-- Warning overview: headline numbers for current active and resolved-today warnings. -->
- <select id="selectDashboardTodaySummary" resultType="java.util.Map">
- SELECT
- COUNT(CASE
- WHEN w.publish_time >= CURRENT_DATE
- AND w.publish_time < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND w.publish_time <= CURRENT_TIMESTAMP
- AND w.status != 'DRAFT'
- THEN 1 END) AS today_total,
- COUNT(CASE
- WHEN w.publish_time <= CURRENT_TIMESTAMP
- AND w.status NOT IN ('DRAFT', 'CLOSED')
- THEN 1 END) AS unresolved_count,
- COUNT(CASE
- WHEN w.status IN ('CLOSED')
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) >= CURRENT_DATE
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time)
- < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) <= CURRENT_TIMESTAMP
- THEN 1 END) AS resolved_count
- FROM app_user.early_warning w
- <include refid="DashboardResolvedTimeJoin"/>
- WHERE 1 = 1
- <include refid="SupportedDashboardWarningTypes"/>
- </select>
- <!-- Small detail lists returned with the today overview cards. -->
- <select id="selectDashboardTodayPreview" resultType="java.util.Map">
- SELECT
- <include refid="DashboardWarningColumns"/>,
- COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) AS resolved_time,
- ROUND(
- EXTRACT(EPOCH FROM (
- CAST(CURRENT_TIMESTAMP AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ)
- )) / 3600,
- 2
- ) AS waiting_hours
- FROM app_user.early_warning w
- <include refid="DashboardResolvedTimeJoin"/>
- WHERE 1 = 1
- <include refid="SupportedDashboardWarningTypes"/>
- <choose>
- <when test="category == 'resolved'">
- AND w.status IN ('CLOSED')
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) >= CURRENT_DATE
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time)
- < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) <= CURRENT_TIMESTAMP
- ORDER BY resolved_time DESC, w.warning_id DESC
- </when>
- <otherwise>
- AND w.publish_time <= CURRENT_TIMESTAMP
- AND w.status NOT IN ('DRAFT', 'CLOSED')
- ORDER BY
- CASE w.warning_level
- WHEN '4' THEN 1 WHEN 'RED' THEN 1
- WHEN '3' THEN 2 WHEN 'ORANGE' THEN 2
- WHEN '2' THEN 3 WHEN 'YELLOW' THEN 3
- WHEN '1' THEN 4 WHEN 'BLUE' THEN 4
- ELSE 5
- END,
- w.publish_time ASC,
- w.warning_id ASC
- </otherwise>
- </choose>
- LIMIT #{limit}
- </select>
- <!-- Paged detail list for the two today overview categories. -->
- <select id="selectDashboardTodayPage" resultType="java.util.Map">
- SELECT
- <include refid="DashboardWarningColumns"/>,
- COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) AS resolved_time,
- ROUND(
- EXTRACT(EPOCH FROM (
- CAST(CURRENT_TIMESTAMP AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ)
- )) / 3600,
- 2
- ) AS waiting_hours
- FROM app_user.early_warning w
- <include refid="DashboardResolvedTimeJoin"/>
- <where>
- <include refid="SupportedDashboardWarningTypes"/>
- <choose>
- <when test="category == 'resolved'">
- AND w.status IN ('CLOSED')
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) >= CURRENT_DATE
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time)
- < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND COALESCE(resolved_record.resolved_time, w.update_time, w.publish_time) <= CURRENT_TIMESTAMP
- </when>
- <when test="category == 'all'">
- AND w.publish_time >= CURRENT_DATE
- AND w.publish_time < CAST(CURRENT_DATE AS TIMESTAMP) + CAST('1 day' AS INTERVAL)
- AND w.publish_time <= CURRENT_TIMESTAMP
- AND w.status != 'DRAFT'
- </when>
- <otherwise>
- AND w.publish_time <= CURRENT_TIMESTAMP
- AND w.status NOT IN ('DRAFT', 'CLOSED')
- </otherwise>
- </choose>
- <include refid="DashboardWarningTypeFilter"/>
- <include refid="DashboardWarningLevelFilter"/>
- <if test="keyword != null and keyword != ''">
- AND (
- w.warning_no LIKE CONCAT('%', #{keyword}, '%')
- OR w.warning_special LIKE CONCAT('%', #{keyword}, '%')
- OR w.ownership_unit LIKE CONCAT('%', #{keyword}, '%')
- )
- </if>
- </where>
- <choose>
- <when test="category == 'resolved'">
- ORDER BY resolved_time DESC, w.warning_id DESC
- </when>
- <when test="category == 'all'">
- ORDER BY w.publish_time DESC, w.warning_id DESC
- </when>
- <otherwise>
- ORDER BY
- CASE w.warning_level
- WHEN '4' THEN 1 WHEN 'RED' THEN 1
- WHEN '3' THEN 2 WHEN 'ORANGE' THEN 2
- WHEN '2' THEN 3 WHEN 'YELLOW' THEN 3
- WHEN '1' THEN 4 WHEN 'BLUE' THEN 4
- ELSE 5
- END,
- w.publish_time ASC,
- w.warning_id ASC
- </otherwise>
- </choose>
- </select>
- <!-- Historical warning summary. Drafts and unsupported facility types are excluded. -->
- <select id="selectDashboardHistorySummary" resultType="java.util.Map">
- SELECT
- COUNT(*) AS total_count,
- COUNT(CASE WHEN w.status IN ('CLOSED') THEN 1 END) AS resolved_count,
- COUNT(CASE WHEN w.status NOT IN ('CLOSED') THEN 1 END) AS active_count
- FROM app_user.early_warning w
- WHERE w.status != 'DRAFT'
- AND w.publish_time <= CURRENT_TIMESTAMP
- <include refid="SupportedDashboardWarningTypes"/>
- </select>
- <select id="selectDashboardHistorySpecialStats" resultType="java.util.Map">
- WITH special_stats AS (
- SELECT
- COALESCE(NULLIF(w.warning_special, ''), '未分类') AS special_name,
- COUNT(*) AS warning_count
- FROM app_user.early_warning w
- WHERE w.status != 'DRAFT'
- AND w.publish_time <= CURRENT_TIMESTAMP
- <include refid="SupportedDashboardWarningTypes"/>
- <include refid="DashboardWarningTypeFilter"/>
- GROUP BY COALESCE(NULLIF(w.warning_special, ''), '未分类')
- )
- SELECT
- special_name,
- warning_count,
- ROUND(warning_count * 100.0 / NULLIF(SUM(warning_count) OVER (), 0), 2) AS percentage
- FROM special_stats
- ORDER BY warning_count DESC, special_name ASC
- </select>
- <select id="selectDashboardHistoryPage" resultType="java.util.Map">
- SELECT <include refid="DashboardWarningColumns"/>
- FROM app_user.early_warning w
- <where>
- AND w.status != 'DRAFT'
- AND w.publish_time <= CURRENT_TIMESTAMP
- <include refid="SupportedDashboardWarningTypes"/>
- <include refid="DashboardWarningTypeFilter"/>
- <if test="warningSpecial != null and warningSpecial != ''">
- AND COALESCE(NULLIF(w.warning_special, ''), '未分类') = #{warningSpecial}
- </if>
- <if test="keyword != null and keyword != ''">
- AND (
- w.warning_no LIKE CONCAT('%', #{keyword}, '%')
- OR w.ownership_unit LIKE CONCAT('%', #{keyword}, '%')
- )
- </if>
- </where>
- ORDER BY w.publish_time DESC, w.warning_id DESC
- </select>
- <!-- Outstanding warning list. One most-recent open todo is attached per warning. -->
- <select id="selectDashboardUnprocessedPage" resultType="java.util.Map">
- SELECT
- <include refid="DashboardWarningColumns"/>,
- open_todo.todo_id,
- open_todo.user_id AS todo_user_id,
- open_todo.user_name AS todo_user_name,
- open_todo.todo_type,
- open_todo.read_status,
- open_todo.task_name,
- open_todo.create_time AS todo_create_time,
- ROUND(
- EXTRACT(EPOCH FROM (
- CAST(CURRENT_TIMESTAMP AS TIMESTAMPTZ) - CAST(w.publish_time AS TIMESTAMPTZ)
- )) / 3600,
- 2
- ) AS waiting_hours
- FROM app_user.early_warning w
- LEFT JOIN (
- SELECT todo_id, warning_id, user_id, user_name, todo_type, read_status, task_name, create_time
- FROM (
- SELECT
- t.*,
- ROW_NUMBER() OVER (
- PARTITION BY t.warning_id
- ORDER BY t.create_time DESC, t.todo_id DESC
- ) AS row_num
- FROM app_user.warning_todo t
- WHERE t.complete_time IS NULL
- AND (t.todo_type IS NULL OR t.todo_type != 'DONE')
- ) ranked_todo
- WHERE row_num = 1
- ) open_todo ON open_todo.warning_id = w.warning_id
- <where>
- AND w.publish_time <= CURRENT_TIMESTAMP
- AND w.status IN ('PENDING', 'RECEIVED', 'PROCESSING')
- <include refid="SupportedDashboardWarningTypes"/>
- <include refid="DashboardWarningTypeFilter"/>
- <include refid="DashboardWarningLevelFilter"/>
- <if test="keyword != null and keyword != ''">
- AND (
- w.warning_no LIKE CONCAT('%', #{keyword}, '%')
- OR w.warning_special LIKE CONCAT('%', #{keyword}, '%')
- OR w.ownership_unit LIKE CONCAT('%', #{keyword}, '%')
- )
- </if>
- </where>
- ORDER BY
- CASE w.warning_level
- WHEN '4' THEN 1 WHEN 'RED' THEN 1
- WHEN '3' THEN 2 WHEN 'ORANGE' THEN 2
- WHEN '2' THEN 3 WHEN 'YELLOW' THEN 3
- WHEN '1' THEN 4 WHEN 'BLUE' THEN 4
- ELSE 5
- END,
- w.publish_time ASC,
- w.warning_id ASC
- </select>
- <!-- Aggregate cards for the unprocessed list. The filters mirror the page
- query so counts remain correct when the user searches or narrows a
- warning type/level. -->
- <select id="selectDashboardUnprocessedSummary" resultType="java.util.Map">
- SELECT
- COUNT(*) AS total,
- COUNT(DISTINCT NULLIF(w.ownership_unit, '')) AS ownership_count,
- MIN(CASE WHEN w.warning_level IN ('1', '2', '3', '4') THEN CAST(w.warning_level AS integer) END) AS highest_level
- FROM app_user.early_warning w
- <where>
- AND w.publish_time <= CURRENT_TIMESTAMP
- AND w.status IN ('PENDING', 'RECEIVED', 'PROCESSING')
- <include refid="SupportedDashboardWarningTypes"/>
- <include refid="DashboardWarningTypeFilter"/>
- <include refid="DashboardWarningLevelFilter"/>
- <if test="keyword != null and keyword != ''">
- AND (
- w.warning_no LIKE CONCAT('%', #{keyword}, '%')
- OR w.warning_special LIKE CONCAT('%', #{keyword}, '%')
- OR w.ownership_unit LIKE CONCAT('%', #{keyword}, '%')
- )
- </if>
- </where>
- </select>
- <select id="selectWarningList" resultType="java.util.Map">
- SELECT w.*, <include refid="DeviceLocationColumn"/>, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name
- FROM early_warning w
- <where>
- <include refid="WarningVisibility"/>
- <if test="warningNo != null and warningNo != ''">AND w.warning_no LIKE CONCAT('%',#{warningNo},'%')</if>
- <if test="warningType != null and warningType != ''">
- AND w.warning_type = #{warningType}
- </if>
- <if test="warningLevel != null and warningLevel != ''">
- AND w.warning_level = #{warningLevel}
- </if>
- <if test="status != null and status != ''">
- AND w.status = #{status}
- </if>
- </where>
- ORDER BY w.create_time DESC
- </select>
- <select id="searchWarnings" resultType="java.util.Map">
- SELECT w.*, <include refid="DeviceLocationColumn"/>, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name
- FROM early_warning w
- <where>
- <include refid="WarningVisibility"/>
- <if test="warningNo != null and warningNo != ''">
- AND w.warning_no LIKE CONCAT('%', #{warningNo}, '%')
- </if>
- <if test="warningType != null and warningType != ''">
- AND w.warning_type = #{warningType}
- </if>
- <if test="warningLevel != null and warningLevel != ''">
- AND w.warning_level = #{warningLevel}
- </if>
- <if test="status != null and status != ''">
- AND w.status = #{status}
- </if>
- <if test="publisher != null and publisher != ''">
- AND w.publisher LIKE CONCAT('%', #{publisher}, '%')
- </if>
- <if test="excludePublisher != null and excludePublisher != ''">
- AND (w.publisher IS NULL OR w.publisher NOT LIKE CONCAT('%', #{excludePublisher}, '%'))
- </if>
- <if test="ownershipUnit != null and ownershipUnit != ''">
- AND w.ownership_unit LIKE CONCAT('%', #{ownershipUnit}, '%')
- </if>
- <if test="deviceCode != null and deviceCode != ''">
- AND w.device_code LIKE CONCAT('%', #{deviceCode}, '%')
- </if>
- <if test="deviceName != null and deviceName != ''">
- AND (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) LIKE CONCAT('%', #{deviceName}, '%')
- </if>
- <if test="startTime != null">
- AND w.create_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.create_time <= #{endTime}
- </if>
- </where>
- <choose>
- <when test="releaseOrder">
- ORDER BY CASE w.status
- WHEN 'DRAFT' THEN 0
- WHEN 'PENDING' THEN 1
- WHEN 'RECEIVED' THEN 2
- WHEN 'PROCESSING' THEN 3
- WHEN 'HANDLED' THEN 4
- WHEN 'CLOSED' THEN 5
- ELSE 6 END,
- COALESCE(w.update_time, w.create_time) DESC NULLS LAST,
- w.create_time DESC NULLS LAST, w.warning_id DESC
- </when>
- <otherwise>ORDER BY w.create_time DESC</otherwise>
- </choose>
- </select>
- <select id="selectTodoList" resultType="java.util.Map">
- SELECT
- t.*,
- w.warning_no,
- w.warning_type,
- w.warning_level,
- w.handler,
- w.publisher,
- <include refid="DeviceLocationColumn"/>,
- w.ownership_unit,
- w.publish_time
- FROM warning_todo t
- LEFT JOIN early_warning w ON t.warning_id = w.warning_id
- <where>
- t.user_id = #{userId}
- <if test="warningNo != null and warningNo != ''">AND w.warning_no LIKE CONCAT('%',#{warningNo},'%')</if>
- <if test="todoType != null and todoType != ''">
- AND t.todo_type = #{todoType}
- </if>
- </where>
- ORDER BY t.create_time DESC
- </select>
- <!-- 身份由服务端登录上下文传入,禁止使用请求中的 userName。 -->
- <select id="selectMyTasks" resultType="java.util.Map">
- SELECT w.*, <include refid="DeviceLocationColumn"/>, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name, t.todo_id,
- <choose>
- <when test="q.todoType == null or q.todoType == '' or q.todoType == 'TODO'">'TODO' AS todo_type,</when>
- <otherwise>t.todo_type,</otherwise>
- </choose>
- t.action_type, t.task_name, t.read_status,
- t.create_time AS task_create_time, t.complete_time,
- (SELECT STRING_AGG(DISTINCT a.alarm_no, ',')
- FROM alarm_warning_rel rel JOIN alarm_data a ON a.id = rel.alarm_id
- WHERE rel.warning_id = w.warning_id) AS alarm_numbers
- FROM early_warning w LEFT JOIN (
- SELECT task.*, ROW_NUMBER() OVER (
- PARTITION BY CASE WHEN task.todo_type = 'NOTICE' THEN task.todo_id ELSE task.warning_id END
- ORDER BY task.complete_time DESC NULLS LAST, task.create_time DESC, task.todo_id DESC
- ) AS task_rank
- FROM warning_todo task
- WHERE (task.user_name = #{username} OR task.user_id = #{userId}
- OR (task.user_name IS NULL AND task.user_id = #{username}))
- <if test="q.todoType != null and q.todoType != ''">AND task.todo_type = #{q.todoType}</if>
- <if test="q.todoType == null or q.todoType == ''">AND task.todo_type IN ('TODO', 'DONE')</if>
- ) t ON w.warning_id = t.warning_id AND t.task_rank = 1
- WHERE 1 = 1
- <include refid="WarningVisibility"/>
- <choose>
- <when test="q.todoType == null or q.todoType == '' or q.todoType == 'TODO'">
- <include refid="WarningPending"/>
- </when>
- <otherwise>AND t.todo_id IS NOT NULL</otherwise>
- </choose>
- <if test="q.warningNo != null and q.warningNo != ''">AND w.warning_no LIKE CONCAT('%',#{q.warningNo},'%')</if>
- <if test="q.warningSpecial != null and q.warningSpecial != ''">AND w.warning_special LIKE CONCAT('%',#{q.warningSpecial},'%')</if>
- <if test="q.warningType != null and q.warningType != ''">AND w.warning_type = #{q.warningType}</if>
- <if test="q.warningLevel != null and q.warningLevel != ''">AND w.warning_level = #{q.warningLevel}</if>
- <if test="q.status != null and q.status != ''">AND w.status = #{q.status}</if>
- <if test="q.handler != null and q.handler != ''">AND w.handler LIKE CONCAT('%',#{q.handler},'%')</if>
- <if test="q.publisher != null and q.publisher != ''">AND w.publisher LIKE CONCAT('%',#{q.publisher},'%')</if>
- <if test="q.ownershipUnit != null and q.ownershipUnit != ''">AND w.ownership_unit LIKE CONCAT('%',#{q.ownershipUnit},'%')</if>
- <if test="q.startTime != null and q.startTime != ''">AND COALESCE(w.publish_time, w.create_time) >= CAST(#{q.startTime} AS TIMESTAMP)</if>
- <if test="q.endTime != null and q.endTime != ''">AND COALESCE(w.publish_time, w.create_time) <= CAST(#{q.endTime} AS TIMESTAMP)</if>
- <if test="q.alarmCode != null and q.alarmCode != ''">
- AND EXISTS (SELECT 1 FROM alarm_warning_rel r JOIN alarm_data a ON a.id = r.alarm_id
- WHERE r.warning_id = w.warning_id AND a.alarm_no LIKE CONCAT('%',#{q.alarmCode},'%'))
- </if>
- ORDER BY COALESCE(t.create_time, w.create_time) DESC, w.warning_id DESC
- </select>
- <select id="selectProcessingWarnings" resultType="java.util.Map">
- SELECT w.*, <include refid="DeviceLocationColumn"/>, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name
- FROM early_warning w
- <where>
- <include refid="WarningVisibility"/>
- AND w.status IN ('PENDING', 'RECEIVED', 'PROCESSING', 'HANDLED')
- <if test="warningType != null and warningType != ''">
- AND w.warning_type = #{warningType}
- </if>
- <if test="warningLevel != null and warningLevel != ''">
- AND w.warning_level = #{warningLevel}
- </if>
- </where>
- ORDER BY w.publish_time DESC
- </select>
- <select id="selectCompletedWarnings" resultType="java.util.Map">
- SELECT w.*, <include refid="DeviceLocationColumn"/>, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name
- FROM early_warning w
- <where>
- <include refid="WarningVisibility"/>
- AND w.status = 'CLOSED'
- <if test="warningType != null and warningType != ''">
- AND w.warning_type = #{warningType}
- </if>
- <if test="warningLevel != null and warningLevel != ''">
- AND w.warning_level = #{warningLevel}
- </if>
- <if test="startTime != null">
- AND w.update_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.update_time <= #{endTime}
- </if>
- </where>
- ORDER BY w.update_time DESC
- </select>
- <sql id="WarningVisibility">
- <if test="!scope.all">
- AND (
- w.create_by = #{scope.username}
- OR w.publisher = #{scope.username}
- OR w.handler = #{scope.username}
- OR w.reviewer = #{scope.username}
- OR (w.create_by = '系统自动' AND #{scope.canPublish} = TRUE)
- OR (w.status = 'DRAFT' AND #{scope.canPublish} = TRUE)
- )
- AND EXISTS (
- SELECT 1
- FROM app_user.equipment_base eb
- INNER JOIN app_user.equipment_type et ON et.id = eb.equipment_type_id
- WHERE eb.equipment_code = w.device_code
- AND (
- <choose>
- <when test="scope.parentTypeIds != null and !scope.parentTypeIds.isEmpty()">
- et.parent_id IN
- <foreach collection="scope.parentTypeIds" item="parentTypeId" open="(" separator="," close=")">
- #{parentTypeId}
- </foreach>
- </when>
- <otherwise>1 = 0</otherwise>
- </choose>
- <if test="scope.sharedManholeVisible">
- OR (et.parent_id = 4 AND (w.handler = #{scope.username} OR w.reviewer = #{scope.username}))
- </if>
- )
- )
- </if>
- </sql>
- <sql id="WarningPending">
- AND (
- (w.handler = #{scope.username} AND #{scope.canHandle} = TRUE
- AND w.status IN ('PENDING', 'RECEIVED', 'PROCESSING'))
- OR (w.reviewer = #{scope.username} AND #{scope.canAudit} = TRUE AND w.status = 'HANDLED')
- OR (w.status = 'DRAFT' AND #{scope.canPublish} = TRUE)
- )
- </sql>
- <select id="selectMobileWarnings" resultType="java.util.Map">
- SELECT
- w.warning_id AS "warningId",
- w.warning_no AS "warningNo",
- w.warning_type AS "warningType",
- COALESCE((SELECT NULLIF(TRIM(wt.warning_name), '') FROM app_user.warning_type wt
- WHERE wt.warning_code = w.warning_type ORDER BY wt.id LIMIT 1), w.warning_type) AS "warningTypeName",
- w.warning_level AS "warningLevel",
- COALESCE((SELECT NULLIF(TRIM(dl.dict_label), '') FROM app_user.sys_dict_data dl
- WHERE dl.dict_type = 'alert_level' AND dl.dict_value = w.warning_level AND dl.status = '0'
- ORDER BY dl.dict_sort LIMIT 1), w.warning_level) AS "warningLevelName",
- w.warning_content AS "warningContent",
- w.device_code AS "deviceCode",
- (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS "deviceName",
- (SELECT et.type_name FROM app_user.equipment_base e
- LEFT JOIN app_user.equipment_type et ON et.id = e.equipment_type_id
- WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS "deviceTypeName",
- <include refid="DeviceLocationColumn"/>,
- w.status,
- w.create_by AS "createBy",
- w.publisher,
- w.handler,
- COALESCE(NULLIF(TRIM(hu.nick_name), ''), w.handler) AS "handlerName",
- w.reviewer,
- COALESCE(NULLIF(TRIM(ru.nick_name), ''), w.reviewer) AS "reviewerName",
- w.publish_time AS "publishTime",
- w.create_time AS "createTime"
- FROM app_user.early_warning w
- LEFT JOIN app_user.sys_user hu ON hu.user_name = w.handler
- LEFT JOIN app_user.sys_user ru ON ru.user_name = w.reviewer
- WHERE 1 = 1
- <include refid="WarningVisibility"/>
- <if test="pendingOnly">
- <include refid="WarningPending"/>
- </if>
- <if test="keyword != null and keyword != ''">
- AND (w.warning_no LIKE CONCAT('%', #{keyword}, '%')
- OR w.warning_content LIKE CONCAT('%', #{keyword}, '%')
- OR w.device_code LIKE CONCAT('%', #{keyword}, '%')
- OR (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) LIKE CONCAT('%', #{keyword}, '%'))
- </if>
- <if test="status != null and status != ''">AND w.status = #{status}</if>
- <if test="warningType != null and warningType != ''">AND w.warning_type = #{warningType}</if>
- <if test="warningLevel != null and warningLevel != ''">AND w.warning_level = #{warningLevel}</if>
- ORDER BY COALESCE(w.publish_time, w.create_time) DESC, w.warning_id DESC
- </select>
- <select id="countVisibleWarning" resultType="int">
- SELECT COUNT(1)
- FROM app_user.early_warning w
- WHERE w.warning_id = #{warningId}
- <include refid="WarningVisibility"/>
- </select>
- <select id="countCompanyDevice" resultType="int">
- SELECT COUNT(1) FROM app_user.equipment_base eb
- INNER JOIN app_user.equipment_type et ON et.id = eb.equipment_type_id
- WHERE eb.equipment_code = #{deviceCode}
- <if test="!scope.all">
- <choose>
- <when test="scope.parentTypeIds != null and !scope.parentTypeIds.isEmpty()">
- AND et.parent_id IN
- <foreach collection="scope.parentTypeIds" item="parentTypeId" open="(" separator="," close=")">
- #{parentTypeId}
- </foreach>
- </when>
- <otherwise>AND 1 = 0</otherwise>
- </choose>
- </if>
- </select>
- <select id="selectVisibleArchives" resultType="com.zksy.base.warning.domain.WarningArchive">
- SELECT a.* FROM app_user.warning_archive a
- JOIN app_user.early_warning w ON w.warning_id = a.warning_id
- <where>
- <include refid="WarningVisibility"/>
- <if test="warningNo != null and warningNo != ''">AND a.warning_no LIKE CONCAT('%', #{warningNo}, '%')</if>
- <if test="warningType != null and warningType != ''">AND a.warning_type = #{warningType}</if>
- <if test="warningLevel != null and warningLevel != ''">AND a.warning_level = #{warningLevel}</if>
- <if test="startTime != null">AND a.create_time >= #{startTime}</if>
- <if test="endTime != null">AND a.create_time <= #{endTime}</if>
- </where>
- ORDER BY a.create_time DESC
- </select>
- <select id="selectWarningDetail" resultType="java.util.Map">
- SELECT w.*, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name,
- COALESCE(NULLIF(TRIM(hu.nick_name), ''), w.handler) AS handler_name,
- COALESCE(NULLIF(TRIM(ru.nick_name), ''), w.reviewer) AS reviewer_name,
- COALESCE(NULLIF(TRIM(pu.nick_name), ''), w.publisher) AS publisher_name,
- COALESCE(NULLIF(TRIM(cu.nick_name), ''), w.create_by) AS creator_name,
- eb.equipment_location AS location,
- et.type_name AS device_type_name
- FROM early_warning w
- LEFT JOIN app_user.sys_user hu ON hu.user_name = w.handler
- LEFT JOIN app_user.sys_user ru ON ru.user_name = w.reviewer
- LEFT JOIN app_user.sys_user pu ON pu.user_name = w.publisher
- LEFT JOIN app_user.sys_user cu ON cu.user_name = w.create_by
- LEFT JOIN app_user.equipment_base eb ON eb.equipment_code = w.device_code
- LEFT JOIN app_user.equipment_type et ON et.id = eb.equipment_type_id
- WHERE w.warning_id = #{warningId}
- </select>
- <!-- 驾驶舱只读详情用:列表下发的是**业务编号**(warning_no),详情要的是主键(warning_id)。
- 两条口径都在契约里,因此按编号回查一次,不要求前端改拿主键。 -->
- <select id="selectWarningDetailByNo" resultType="java.util.Map">
- SELECT w.*, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name,
- COALESCE(NULLIF(TRIM(hu.nick_name), ''), w.handler) AS handler_name,
- COALESCE(NULLIF(TRIM(ru.nick_name), ''), w.reviewer) AS reviewer_name,
- COALESCE(NULLIF(TRIM(pu.nick_name), ''), w.publisher) AS publisher_name,
- COALESCE(NULLIF(TRIM(cu.nick_name), ''), w.create_by) AS creator_name,
- eb.equipment_location AS location,
- et.type_name AS device_type_name
- FROM early_warning w
- LEFT JOIN app_user.sys_user hu ON hu.user_name = w.handler
- LEFT JOIN app_user.sys_user ru ON ru.user_name = w.reviewer
- LEFT JOIN app_user.sys_user pu ON pu.user_name = w.publisher
- LEFT JOIN app_user.sys_user cu ON cu.user_name = w.create_by
- LEFT JOIN app_user.equipment_base eb ON eb.equipment_code = w.device_code
- LEFT JOIN app_user.equipment_type et ON et.id = eb.equipment_type_id
- WHERE w.warning_no = #{warningNo}
- ORDER BY w.create_time DESC NULLS LAST
- LIMIT 1
- </select>
- <select id="selectStatistics" resultType="java.util.Map">
- SELECT
- COUNT(*) AS total,
- COALESCE(SUM(CASE WHEN status = 'DRAFT' THEN 1 ELSE 0 END), 0) AS draftCount,
- COALESCE(SUM(CASE WHEN status = 'PENDING' THEN 1 ELSE 0 END), 0) AS pendingCount,
- COALESCE(SUM(CASE WHEN status = 'PROCESSING' THEN 1 ELSE 0 END), 0) AS processingCount,
- COALESCE(SUM(CASE WHEN status = 'RECEIVED' THEN 1 ELSE 0 END), 0) AS receivedCount,
- COALESCE(SUM(CASE WHEN status = 'HANDLED' THEN 1 ELSE 0 END), 0) AS handledCount,
- COALESCE(SUM(CASE WHEN status = 'CLOSED' THEN 1 ELSE 0 END), 0) AS closedCount,
- COALESCE(SUM(CASE WHEN warning_level = '1' THEN 1 ELSE 0 END), 0) AS level1Count,
- COALESCE(SUM(CASE WHEN warning_level = '2' THEN 1 ELSE 0 END), 0) AS level2Count,
- COALESCE(SUM(CASE WHEN warning_level = '3' THEN 1 ELSE 0 END), 0) AS level3Count,
- COALESCE(SUM(CASE WHEN warning_level = '4' THEN 1 ELSE 0 END), 0) AS level4Count
- FROM early_warning
- </select>
- <!-- 行业处置分析:兼容 device_code 存设备实例编码或设备类别主键两种历史格式。
- 设备类别主键改为整数后,业态由根节点 id 决定:1=供水 2=排水 3=燃气 4=窨井,
- 对外仍以 water_supply/drainage/gas/manhole 作为 industry_code,保持接口契约不变。 -->
- <sql id="IndustryWarningCte">
- WITH RECURSIVE type_tree AS (
- SELECT et.id AS leaf_id, et.id AS current_id,
- et.type_name AS current_name, et.parent_id, CAST(0 AS bigint) AS depth
- FROM app_user.equipment_type et
- UNION ALL
- SELECT tree.leaf_id, parent.id, parent.type_name,
- parent.parent_id, tree.depth + 1
- FROM type_tree tree
- INNER JOIN app_user.equipment_type parent ON parent.id = tree.parent_id
- ),
- root_ranked AS (
- SELECT leaf_id, current_id AS industry_id, current_name AS industry_name,
- ROW_NUMBER() OVER (PARTITION BY leaf_id ORDER BY depth DESC) AS row_num
- FROM type_tree
- ),
- type_roots AS (
- SELECT leaf_id,
- CASE industry_id
- WHEN 1 THEN 'water_supply'
- WHEN 2 THEN 'drainage'
- WHEN 3 THEN 'gas'
- WHEN 4 THEN 'manhole'
- END AS industry_code,
- industry_name
- FROM root_ranked
- WHERE row_num = 1
- AND industry_id IN (1, 2, 3, 4)
- ),
- equipment_map AS (
- SELECT equipment_code, MIN(equipment_type_id) AS equipment_type_id
- FROM app_user.equipment_base
- WHERE del_flag = '0'
- GROUP BY equipment_code
- ),
- warning_industry AS (
- SELECT w.*, (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = w.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
- (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name, roots.industry_code, roots.industry_name
- FROM app_user.early_warning w
- LEFT JOIN equipment_map equipment ON equipment.equipment_code = w.device_code
- LEFT JOIN app_user.equipment_type direct_type
- ON CAST(direct_type.id AS varchar) = w.device_code
- INNER JOIN type_roots roots
- ON CAST(roots.leaf_id AS varchar) =
- COALESCE(equipment.equipment_type_id, CAST(direct_type.id AS varchar))
- WHERE w.status != 'DRAFT'
- <if test="startTime != null">
- AND w.publish_time >= #{startTime}
- </if>
- <if test="endTime != null">
- AND w.publish_time < #{endTime}
- </if>
- <if test="industryCode != null and industryCode != ''">
- AND roots.industry_code = #{industryCode}
- </if>
- ),
- completed_actions AS (
- SELECT disposal.warning_id, MAX(disposal.create_time) AS dispose_time
- FROM app_user.warning_disposal disposal
- WHERE disposal.disposal_type IN ('HANDLE', 'RESOLVE', 'CLEAR', 'CLOSE', 'MISREPORT', 'AUTO_CLEAR')
- GROUP BY disposal.warning_id
- )
- </sql>
- <select id="selectIndustryAnalysisSummary" resultType="java.util.Map">
- <include refid="IndustryWarningCte"/>
- SELECT warning.industry_code,
- warning.industry_name,
- COUNT(*) AS total_count,
- SUM(CASE WHEN warning.status IN ('PENDING', 'RECEIVED') THEN 1 ELSE 0 END) AS pending_count,
- SUM(CASE WHEN warning.status = 'PROCESSING' THEN 1 ELSE 0 END) AS processing_count,
- SUM(CASE WHEN warning.status IN ('HANDLED', 'CLOSED') THEN 1 ELSE 0 END) AS completed_count,
- ROUND(100.0 * SUM(CASE WHEN warning.status IN ('HANDLED', 'CLOSED') THEN 1 ELSE 0 END)
- / NULLIF(COUNT(*), 0), 2) AS completion_rate,
- ROUND(AVG(CASE
- WHEN warning.status IN ('HANDLED', 'CLOSED')
- AND action.dispose_time >= warning.publish_time
- THEN EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600
- END), 2) AS avg_dispose_hours,
- SUM(CASE
- WHEN warning.status IN ('HANDLED', 'CLOSED')
- AND action.dispose_time >= warning.publish_time
- AND EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600 > 24
- THEN 1 ELSE 0 END) AS over_24h_count
- FROM warning_industry warning
- LEFT JOIN completed_actions action ON action.warning_id = warning.warning_id
- GROUP BY warning.industry_code, warning.industry_name
- ORDER BY CASE warning.industry_code
- WHEN 'gas' THEN 1 WHEN 'water_supply' THEN 2
- WHEN 'drainage' THEN 3 WHEN 'manhole' THEN 4 ELSE 5 END
- </select>
- <select id="selectIndustryStatusDistribution" resultType="java.util.Map">
- <include refid="IndustryWarningCte"/>
- <!-- 处置统计只使用 pre_alarm_status 字典中的 CLOSED 终态。 -->
- SELECT industry_code,
- industry_name,
- CASE WHEN status IN ('CLOSED') THEN 'CLOSED' ELSE status END AS status,
- COUNT(*) AS warning_count
- FROM warning_industry
- GROUP BY industry_code,
- industry_name,
- CASE WHEN status IN ('CLOSED') THEN 'CLOSED' ELSE status END
- ORDER BY industry_name,
- CASE WHEN status IN ('CLOSED') THEN 'CLOSED' ELSE status END
- </select>
- <select id="selectIndustryEfficiencyComparison" resultType="java.util.Map">
- <include refid="IndustryWarningCte"/>
- SELECT warning.industry_code,
- warning.industry_name,
- COUNT(*) AS completed_count,
- ROUND(AVG(EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600), 2) AS avg_dispose_hours,
- ROUND(MAX(EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600), 2) AS max_dispose_hours,
- ROUND(MIN(EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600), 2) AS min_dispose_hours,
- ROUND(100.0 * SUM(CASE WHEN EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600 <= 24
- THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 2) AS within_24h_rate
- FROM warning_industry warning
- INNER JOIN completed_actions action ON action.warning_id = warning.warning_id
- WHERE warning.status IN ('HANDLED', 'CLOSED')
- AND action.dispose_time >= warning.publish_time
- GROUP BY warning.industry_code, warning.industry_name
- ORDER BY avg_dispose_hours DESC
- </select>
- <select id="selectIndustryAnalysisList" resultType="java.util.Map">
- <include refid="IndustryWarningCte"/>
- SELECT warning.warning_id,
- warning.warning_no,
- warning.device_code,
- (SELECT e.equipment_name FROM app_user.equipment_base e WHERE e.equipment_code = warning.device_code ORDER BY e.equipment_id LIMIT 1) AS device_name,
- warning.industry_code,
- warning.industry_name,
- warning.warning_level,
- warning.publish_time,
- warning.status,
- action.dispose_time,
- CASE WHEN action.dispose_time >= warning.publish_time
- THEN ROUND(EXTRACT(EPOCH FROM (CAST(action.dispose_time AS TIMESTAMPTZ)
- - CAST(warning.publish_time AS TIMESTAMPTZ))) / 3600, 2)
- ELSE NULL END AS dispose_hours
- FROM warning_industry warning
- LEFT JOIN completed_actions action ON action.warning_id = warning.warning_id
- <where>
- <if test="status != null and status != ''">
- <choose>
- <!-- 页面只提供一个“已解除”筛选项,但兼容两种历史状态值。 -->
- <when test="status == 'CLOSED'">
- warning.status IN ('CLOSED')
- </when>
- <otherwise>
- warning.status = #{status}
- </otherwise>
- </choose>
- </if>
- </where>
- ORDER BY dispose_hours
- <if test="sortType != null and sortType == 'desc'">DESC</if>
- <if test="sortType == null or sortType == 'asc'">ASC</if>
- NULLS LAST, warning.publish_time DESC
- </select>
- </mapper>
|