|
|
@@ -0,0 +1,124 @@
|
|
|
+<?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.uniapp.mapper.DeviceMapper">
|
|
|
+
|
|
|
+ <resultMap type="com.ruoyi.uniapp.domain.Device" id="DeviceResult">
|
|
|
+ <id property="id" column="id"/>
|
|
|
+ <result property="deviceId" column="device_id"/>
|
|
|
+ <result property="deviceName" column="device_name"/>
|
|
|
+ <result property="deviceTypeId" column="device_type_id"/>
|
|
|
+ <result property="farmId" column="farm_id"/>
|
|
|
+ <result property="model" column="model"/>
|
|
|
+ <result property="longitude" column="longitude"/>
|
|
|
+ <result property="latitude" column="latitude"/>
|
|
|
+ <result property="manufacturer" column="manufacturer"/>
|
|
|
+ <result property="installDate" column="install_date"/>
|
|
|
+ <result property="status" column="status"/>
|
|
|
+ <result property="lastActiveTime" column="last_active_time"/>
|
|
|
+ <result property="createTime" column="create_time"/>
|
|
|
+ <result property="updateTime" column="update_time"/>
|
|
|
+ <result property="remark" column="remark"/>
|
|
|
+ <result property="fieldName" column="field_name"/>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <sql id="selectDeviceVo">
|
|
|
+ select d.id, d.device_id, d.device_name, d.device_type_id, d.farm_id, d.model, d.longitude,
|
|
|
+ d.latitude, d.manufacturer, d.install_date, d.status, d.last_active_time, d.create_time,
|
|
|
+ d.update_time, d.remark, f.field_name
|
|
|
+ from device d
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <select id="selectDeviceList" parameterType="com.ruoyi.uniapp.domain.dto.DeviceDto" resultMap="DeviceResult">
|
|
|
+ <include refid="selectDeviceVo"/>
|
|
|
+ LEFT JOIN field_device fd ON fd.device_id = d.id
|
|
|
+ LEFT JOIN field f ON f.id = fd.field_id
|
|
|
+ LEFT JOIN field_personnel fp ON fd.id = fp.field_id
|
|
|
+ <where>
|
|
|
+ <if test="deviceId != null and deviceId != ''"> and d.device_id = #{deviceId}</if>
|
|
|
+ <if test="fieldId != null and fieldId != ''"> and fd.field_id = #{fieldId}</if>
|
|
|
+ <if test="userId != null and userId != ''"> and fp.user_id = #{userId}</if>
|
|
|
+ <if test="deviceName != null and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
|
|
|
+ <if test="deviceTypeId != null and deviceTypeId != ''"> and d.device_type_id = #{deviceTypeId}</if>
|
|
|
+ <if test="status != null "> and d.status = #{status}</if>
|
|
|
+ <if test="deviceQueryParams != null and deviceQueryParams != ''">
|
|
|
+ and (
|
|
|
+ d.device_name like concat('%', #{deviceQueryParams}, '%') OR
|
|
|
+ d.device_id like concat('%', #{deviceQueryParams}, '%')
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ AND fd.`status` = 0
|
|
|
+ AND fp.`status` = 0
|
|
|
+ </where>
|
|
|
+ order by create_time desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectDeviceById" parameterType="Integer" resultMap="DeviceResult">
|
|
|
+ <include refid="selectDeviceVo"/>
|
|
|
+ where id = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="countDeviceStatistics" resultType="com.ruoyi.uniapp.domain.vo.DeviceOverviewVO">
|
|
|
+ SELECT
|
|
|
+ COUNT(DISTINCT d.id) AS totalDevices,
|
|
|
+ SUM(CASE WHEN d.status = 1 THEN 1 ELSE 0 END) AS onlineDevices,
|
|
|
+ SUM(CASE WHEN d.status = 0 THEN 1 ELSE 0 END) AS offlineDevices
|
|
|
+ FROM device d
|
|
|
+ LEFT JOIN field_device fd ON fd.device_id = d.id
|
|
|
+ LEFT JOIN field_personnel fp ON fd.id = fp.field_id
|
|
|
+ <where>
|
|
|
+ <if test="fieldId != null and fieldId != ''">
|
|
|
+ AND fd.field_id = #{fieldId}
|
|
|
+ </if>
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND fp.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ AND fp.`status` = 0
|
|
|
+ AND fd.`status` = 0
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+
|
|
|
+ <select id="countDevicesByType" resultType="java.util.Map">
|
|
|
+ SELECT
|
|
|
+ d.device_type_id AS deviceTypeId,
|
|
|
+ SUM( CASE WHEN d.STATUS = 1 THEN 1 ELSE 0 END ) AS online,
|
|
|
+ SUM( CASE WHEN d.STATUS = 0 THEN 1 ELSE 0 END ) AS offline
|
|
|
+ FROM
|
|
|
+ device d
|
|
|
+ LEFT JOIN field_device fd ON fd.device_id = d.id
|
|
|
+ LEFT JOIN field_personnel fp ON fd.field_id = fp.field_id
|
|
|
+ <where>
|
|
|
+ <if test="fieldId != null and fieldId != ''">
|
|
|
+ AND fd.field_id = #{fieldId}
|
|
|
+ </if>
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND fp.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ AND fd.`status` = 0
|
|
|
+ AND fp.`status` = 0
|
|
|
+ </where>
|
|
|
+ GROUP BY device_type_id
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="countAlertsByType" resultType="java.util.Map">
|
|
|
+ SELECT
|
|
|
+ d.device_type_id as deviceTypeId,
|
|
|
+ COUNT(a.id) as alerts
|
|
|
+ FROM
|
|
|
+ device d
|
|
|
+ LEFT JOIN
|
|
|
+ device_alert a ON d.device_id = a.device_id AND a.status = 0
|
|
|
+ <where>
|
|
|
+ <if test="farmId != null and farmId != ''">
|
|
|
+ AND d.farm_id = #{farmId}
|
|
|
+ </if>
|
|
|
+ <if test="fieldId != null and fieldId != ''">
|
|
|
+ AND d.field_id = #{fieldId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY d.device_type_id
|
|
|
+ </select>
|
|
|
+
|
|
|
+</mapper>
|