| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?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.base.mapper.DeviceMapper">
- <resultMap type="com.ruoyi.base.domain.Device" id="DeviceResult">
- <result 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="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="bindStatus" column="bindStatus" />
- <result property="bindTime" column="binding_time" />
- <result property="fieldName" column="field_name" />
- <result property="longitude" column="longitude" />
- <result property="latitude" column="latitude" />
- <result property="remark" column="remark" />
- <association property="dept" javaType="com.ruoyi.system.api.domain.SysDept" resultMap="deptResult" />
- <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
- </resultMap>
- <resultMap type="FieldPersonnel" id="FieldPersonnelResult">
- <result property="id" column="id" />
- <result property="fieldId" column="field_id" />
- <result property="userId" column="user_id" />
- <result property="roleType" column="role_type" />
- <result property="bindingTime" column="binding_time" />
- <result property="status" column="status" />
- <result property="createTime" column="create_time" />
- <result property="updateTime" column="update_time" />
- <result property="createdBy" column="created_by" />
- <result property="updatedBy" column="updated_by" />
- <result property="isDeleted" column="is_deleted" />
- <result property="userName" column="user_name" />
- <result property="postName" column="post_name" />
- <result property="phonenumber" column="phonenumber" />
- </resultMap>
- <resultMap id="deptResult" type="com.ruoyi.system.api.domain.SysDept">
- <id property="deptId" column="dept_id" />
- <result property="parentId" column="parent_id" />
- <result property="deptName" column="dept_name" />
- <result property="ancestors" column="ancestors" />
- <result property="orderNum" column="order_num" />
- <result property="leader" column="leader" />
- <result property="status" column="dept_status" />
- </resultMap>
- <resultMap id="RoleResult" type="com.ruoyi.system.api.domain.SysDept">
- <id property="roleId" column="role_id" />
- <result property="roleName" column="role_name" />
- <result property="roleKey" column="role_key" />
- <result property="roleSort" column="role_sort" />
- <result property="dataScope" column="data_scope" />
- <result property="status" column="role_status" />
- </resultMap>
- <sql id="selectDeviceVo">
- select id, device_id, device_name, device_type_id, farm_id, model, manufacturer, install_date, status, last_active_time, create_time, update_time, remark from device
- </sql>
- <select id="selectDeviceList" parameterType="com.ruoyi.base.domain.Device" resultMap="DeviceResult">
- select de.id, de.device_id, de.device_name, de.device_type_id, de.farm_id, de.model,
- de.manufacturer, de.install_date, de.status, de.last_active_time, de.create_time, de.update_time, de.remark,d.dept_name, d.leader,f.field_name
- from device de
- left join sys_dept d on de.farm_id = d.dept_id
- LEFT JOIN field_device fd ON de.id = fd.device_id AND fd.status = '0'
- left join field f on fd.field_id = f.id
- <where>
- (fd.status = 0 or fd.status is null)
- <if test="deviceId != null and deviceId != ''"> and de.device_id = #{deviceId}</if>
- <if test="deviceName != null and deviceName != ''"> and de.device_name like concat('%', #{deviceName}, '%')</if>
- <if test="deptIdList != null and deptIdList.size() != 0"> and de.farm_id in (<foreach collection="deptIdList" item="deptId" separator=",">#{deptId}</foreach>)</if>
- <if test="fieldIdList != null and fieldIdList.size() != 0"> and f.id in (<foreach collection="fieldIdList" item="deptId" separator=",">#{deptId}</foreach>)</if>
- <if test="deviceTypeId != null and deviceTypeId != ''"> and de.device_type_id = #{deviceTypeId}</if>
- <if test="farmId != null and farmId != ''"> and de.farm_id = #{farmId}</if>
- <if test="model != null and model != ''"> and de.model = #{model}</if>
- <if test="manufacturer != null and manufacturer != ''"> and de.manufacturer = #{manufacturer}</if>
- <if test="installDate != null "> and de.install_date = #{installDate}</if>
- <if test="status != null "> and de.status = #{status}</if>
- <if test="lastActiveTime != null "> and de.last_active_time = #{lastActiveTime}</if>
- ${params.dataScope}
- </where>
- </select>
- <select id="selectDeviceById" parameterType="Long" resultMap="DeviceResult">
- select de.id, de.device_id, de.device_name, de.device_type_id, de.farm_id, de.model,
- de.manufacturer, de.install_date, de.status, de.last_active_time,d.dept_name,f.field_name,de.remark,longitude,latitude
- from device de
- left join sys_dept d on de.farm_id = d.dept_id
- left join field_device fd on de.id = fd.device_id and fd.status = '0'
- left join field f on fd.field_id = f.id
- where de.id = #{id} and (fd.status = 0 or fd.status is null);
- </select>
- <select id="selectDeviceByField" resultMap="DeviceResult">
- select d.*,fd.status as bindStatus,fd.binding_time as binding_time
- from field f
- left join field_device fd on f.id = fd.field_id
- left join device d on fd.device_id = d.id where f.id = #{id} and fd.status = 0;
- </select>
- <select id="selectUserById" resultMap="FieldPersonnelResult">
- select u.user_name,p.post_name,u.phonenumber,fp.binding_time,u.user_id
- from field f
- join field_personnel fp on f.id = fp.field_id
- left join sys_user u on fp.user_id = u.user_id
- left join sys_user_post sup on u.user_id = sup.user_id
- left join sys_post p on sup.post_id = p.post_id
- where f.id = #{id} and fp.status = 0
- </select>
- <select id="selectDeviceByunField" resultMap="DeviceResult">
- select d.*
- from device d
- left join field f on d.farm_id = f.farm_id
- where d.id not in (select device_id from field_device f where f.field_id = #{id} and f.status = 0) and
- d.farm_id = #{farmId}
- </select>
- <select id="selectDeviceByunUser" resultMap="FieldPersonnelResult">
- select u.user_name,p.post_name,u.phonenumber,u.user_id,sd.dept_name
- from sys_user u
- left join field_personnel fp on u.user_id = fp.user_id
- left join field f on f.id = fp.field_id
- left join sys_user_post sup on u.user_id = sup.user_id
- left join sys_post p on sup.post_id = p.post_id
- left join sys_dept sd on u.dept_id = sd.dept_id
- where u.user_id not in (select user_id from field_personnel where field_id = #{id} and status = 0)
- and u.dept_id = #{deptId}
- group by u.user_id,p.post_name,sd.dept_name
- </select>
- <insert id="insertDevice" parameterType="com.ruoyi.base.domain.Device" useGeneratedKeys="true" keyProperty="id">
- insert into device
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="deviceId != null and deviceId != ''">device_id,</if>
- <if test="deviceName != null and deviceName != ''">device_name,</if>
- <if test="deviceTypeId != null and deviceTypeId != ''">device_type_id,</if>
- <if test="farmId != null">farm_id,</if>
- <if test="model != null">model,</if>
- <if test="manufacturer != null">manufacturer,</if>
- <if test="longitude != null">longitude,</if>
- <if test="latitude != null">latitude,</if>
- <if test="installDate != null">install_date,</if>
- <if test="status != null">status,</if>
- <if test="lastActiveTime != null">last_active_time,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="remark != null">remark,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
- <if test="deviceName != null and deviceName != ''">#{deviceName},</if>
- <if test="deviceTypeId != null and deviceTypeId != ''">#{deviceTypeId},</if>
- <if test="farmId != null">#{farmId},</if>
- <if test="model != null">#{model},</if>
- <if test="manufacturer != null">#{manufacturer},</if>
- <if test="longitude != null">#{longitude},</if>
- <if test="latitude != null">#{latitude},</if>
- <if test="installDate != null">#{installDate},</if>
- <if test="status != null">#{status},</if>
- <if test="lastActiveTime != null">#{lastActiveTime},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="remark != null">#{remark},</if>
- </trim>
- </insert>
- <update id="updateDevice" parameterType="com.ruoyi.base.domain.Device">
- update device
- <trim prefix="SET" suffixOverrides=",">
- <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
- <if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
- <if test="deviceTypeId != null and deviceTypeId != ''">device_type_id = #{deviceTypeId},</if>
- <if test="farmId != null">farm_id = #{farmId},</if>
- <if test="model != null">model = #{model},</if>
- <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
- <if test="installDate != null">install_date = #{installDate},</if>
- <if test="status != null">status = #{status},</if>
- <if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="remark != null">remark = #{remark},</if>
- </trim>
- where id = #{id}
- </update>
- <delete id="deleteDeviceById" parameterType="Long">
- delete from device where id = #{id}
- </delete>
- <delete id="deleteDeviceByIds" parameterType="String">
- delete from device where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- <select id="selectUniappDeviceList" parameterType="com.ruoyi.base.domain.dto.DeviceDto" resultMap="DeviceResult">
- 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
- INNER JOIN field_device fd ON fd.device_id = d.id AND fd.status = 0
- INNER JOIN field f ON f.id = fd.field_id
- INNER JOIN field_personnel fp ON fp.field_id = f.id AND fp.status = 0
- <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 in
- <foreach item="id" collection="deviceTypeId.split(',')" open="(" separator="," close=")">
- #{id}
- </foreach>
- </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>
- </where>
- order by create_time desc
- </select>
- <select id="countDeviceStatistics" resultType="com.ruoyi.base.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
- INNER JOIN field_device fd ON fd.device_id = d.id AND fd.status = 0
- INNER JOIN field f ON f.id = fd.field_id
- INNER JOIN field_personnel fp ON fp.field_id = f.id AND fp.status = 0
- <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>
- </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>
|