|
|
@@ -0,0 +1,207 @@
|
|
|
+<?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
|
|
|
+ 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>
|
|
|
+ </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
|
|
|
+ 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 f on u.dept_id = f.farm_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}
|
|
|
+ </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>
|
|
|
+</mapper>
|