<?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.ruoyi.safety.mapper.SafetyInspectionRecordMapper">
|
|
<select id="selectTodayStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectionTodayStatistics">
|
SELECT
|
COUNT(1) AS totalCount,
|
IFNULL(SUM(CASE WHEN status <> 3 THEN 1 ELSE 0 END), 0) AS completedCount,
|
IFNULL(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) AS abnormalCount,
|
IFNULL(SUM(CASE WHEN status = 2 OR is_missed = 1 THEN 1 ELSE 0 END), 0) AS missedCount,
|
IFNULL(SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END), 0) AS unexecutedCount,
|
CASE
|
WHEN COUNT(1) = 0 THEN 0
|
ELSE ROUND(IFNULL(SUM(CASE WHEN status <> 3 THEN 1 ELSE 0 END), 0) / COUNT(1) * 100, 2)
|
END AS completionRate,
|
COUNT(DISTINCT inspector_id) AS inspectorCount
|
FROM safety_inspection_record
|
WHERE del_flag = 0
|
AND DATE(inspection_time) = #{statDate}
|
</select>
|
|
<select id="selectTrendStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectionTrendStat">
|
SELECT
|
DATE(inspection_time) AS statDate,
|
COUNT(1) AS totalCount,
|
IFNULL(SUM(CASE WHEN status <> 3 THEN 1 ELSE 0 END), 0) AS completedCount,
|
IFNULL(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) AS abnormalCount,
|
IFNULL(SUM(CASE WHEN status = 2 OR is_missed = 1 THEN 1 ELSE 0 END), 0) AS missedCount,
|
IFNULL(SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END), 0) AS unexecutedCount
|
FROM safety_inspection_record
|
WHERE del_flag = 0
|
AND DATE(inspection_time) BETWEEN #{startDate} AND #{endDate}
|
GROUP BY DATE(inspection_time)
|
ORDER BY statDate ASC
|
</select>
|
|
<select id="selectTypeStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectionTypeStat">
|
SELECT
|
IFNULL(type, 'unknown') AS type,
|
COUNT(1) AS count
|
FROM safety_inspection_record
|
WHERE del_flag = 0
|
AND DATE(inspection_time) BETWEEN #{startDate} AND #{endDate}
|
GROUP BY IFNULL(type, 'unknown')
|
ORDER BY count DESC
|
</select>
|
|
<select id="selectInspectorStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectorStat">
|
SELECT
|
inspector_id AS inspectorId,
|
inspector AS inspector,
|
COUNT(1) AS totalCount,
|
IFNULL(SUM(CASE WHEN status <> 3 THEN 1 ELSE 0 END), 0) AS completedCount,
|
IFNULL(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) AS abnormalCount,
|
IFNULL(SUM(CASE WHEN status = 2 OR is_missed = 1 THEN 1 ELSE 0 END), 0) AS missedCount,
|
IFNULL(SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END), 0) AS unexecutedCount,
|
CASE
|
WHEN COUNT(1) = 0 THEN 0
|
ELSE ROUND(IFNULL(SUM(CASE WHEN status <> 3 THEN 1 ELSE 0 END), 0) / COUNT(1) * 100, 2)
|
END AS completionRate
|
FROM safety_inspection_record
|
WHERE del_flag = 0
|
AND DATE(inspection_time) BETWEEN #{startDate} AND #{endDate}
|
GROUP BY inspector_id, inspector
|
ORDER BY totalCount DESC
|
</select>
|
</mapper>
|