| 12345678910111213141516171819202122232425262728293031 |
- <?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="cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog.IotDeviceRunLogMapper">
- <!--
- 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
- 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
- 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
- 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
- -->
- <select id="distinctDevices"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
- SELECT drl.device_id,
- MAX(CASE WHEN mta.`code` = 'sc' THEN drl.total_run_time ELSE 0 END) AS total_run_time,
- MAX(CASE WHEN mta.`code` = 'gls' THEN drl.total_run_time ELSE 0 END) AS total_mileage,
- MAX(drl.point_name) point_name,
- mta.`code` point_code
- FROM rq_iot_device_run_log drl
- LEFT JOIN rq_iot_model_template_attrs mta ON (mta.`name` = drl.point_name AND (mta.`code` ='sc' OR mta.`code`='gls'))
- WHERE drl.deleted = 0
- <if test="deviceIds != null and deviceIds.size > 0">
- AND drl.device_id IN
- <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- AND (mta.`code` = 'sc' OR mta.`code` = 'gls')
- GROUP BY drl.device_id, mta.`code`
- </select>
- </mapper>
|