22 lines
804 B
XML

<?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="github.benjamin.equipreservebackend.mapper.DeviceMapper">
<select id="getDeviceUsageStats" resultType="github.benjamin.equipreservebackend.vo.DeviceStatsVO">
SELECT
d.id AS deviceId,
d.name AS deviceName,
COUNT(*) AS usageCount,
SUM(TIMESTAMPDIFF(DAY, r.start_time, r.end_time)) AS totalUsageDays
FROM reservations r
JOIN devices d ON r.device_id = d.id
WHERE r.status IN ('APPROVED', 'APPROVED_ASSIST')
AND r.start_time >= #{start}
AND r.end_time &lt; #{end}
GROUP BY d.id
ORDER BY totalUsageDays DESC
</select>
</mapper>