| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?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')
- <if test="actualStartTime!=null and actualStartTime!=''">
- AND DATE(drl.create_time) = #{actualStartTime}
- </if>
- <if test="deviceCategoryIds != null and deviceCategoryIds.size > 0">
- AND mta.device_category_id IN
- <foreach collection="deviceCategoryIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY drl.device_id, mta.`code`
- </select>
- <select id="distinctDevicesSearch"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
- SELECT drl.device_id,
- MAX(drl.total_run_time) AS total_run_time,
- 0.0 total_mileage,
- drl.point_name point_name
- FROM rq_iot_device_max_run_log drl
- WHERE drl.deleted = 0
- AND drl.is_sum = 1
- <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>
- GROUP BY drl.device_id, drl.point_name
- </select>
- <!-- 查询正常统计的累计 公里数 时长 -->
- <select id="normalCumulativeAttrs"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
- SELECT
- mta.device_category_id,
- mta.`name` pointName,
- mta.`code` point_code
- FROM rq_iot_model_template_attrs mta
- WHERE mta.deleted = 0
- AND (mta.`code` ='sc' OR mta.`code`='gls')
- <if test="deviceCategoryIds != null and deviceCategoryIds.size > 0">
- AND mta.device_category_id IN
- <foreach collection="deviceCategoryIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </select>
- <select id="selectListByCreateTimeAndDeptList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
- SELECT a.id, a.create_time,a.total_run_time,a.fill_content
- FROM rq_iot_device_run_log a
- WHERE a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
- and a.point_name = #{pointName}
- and (a.device_code is null or a.device_code='')
- <if test="deptIds != null and deptIds.size > 0">
- AND a.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- </select>
- <select id="selectYearTotalGas" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.YearTotalGas">
- SELECT
- DATE_FORMAT(create_time, '%Y-%m') AS month,
- SUM(IFNULL(fill_content, 0)) AS total_gas
- FROM
- rq_iot_device_run_log a
- WHERE
- a.create_time >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
- AND a.fill_content IS NOT NULL
- and (a.device_code is null or a.device_code ='')
- and a.point_name = #{pointName}
- <if test="deptIds != null and deptIds.size > 0">
- AND a.dept_id IN
- <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY
- month
- ORDER BY
- month ASC;
- </select>
- <!-- 查询指定设备 指定运行模板属性的累计时长 累计公里数 -->
- <select id="multipleAccumulatedData"
- resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
- SELECT
- device_id,
- point_name,
- MAX( total_run_time ) AS total_run_time,
- MAX( total_mileage ) AS total_mileage
- FROM
- rq_iot_device_run_log
- WHERE
- deleted = 0
- <if test="actualStartTime!=null and actualStartTime!=''">
- AND DATE(create_time) = #{actualStartTime}
- </if>
- <if test="deviceIds != null and deviceIds.size > 0">
- AND device_id IN
- <foreach collection="deviceIds" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- <if test="attrNames != null and attrNames.size > 0">
- AND point_name IN
- <foreach collection="attrNames" index="index" item="key" open="(" separator="," close=")">
- #{key}
- </foreach>
- </if>
- GROUP BY
- device_id,
- point_name
- </select>
- <select id="theMaxTotalRuntime" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
- resultType="java.math.BigDecimal">
- SELECT MAX(total_run_time)
- FROM rq_iot_device_run_log
- WHERE deleted = 0
- AND device_id = #{deviceId}
- AND point_name = #{pointName}
- </select>
- </mapper>
|