You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
13 KiB
XML

<?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.business.mapper.PlcDeviceDao">
<resultMap type="com.ruoyi.business.domain.PlcDevice" id="PlcDeviceMap">
<result property="deviceId" column="device_id" jdbcType="INTEGER"/>
<result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
<result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
<result property="tenantId" column="tenant_id" jdbcType="INTEGER"/>
<result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
<result property="ip" column="ip" jdbcType="VARCHAR"/>
<result property="port1" column="port1" jdbcType="INTEGER"/>
<result property="location" column="location" jdbcType="VARCHAR"/>
<result property="accessProtocol" column="access_protocol" jdbcType="INTEGER"/>
<result property="length" column="length" jdbcType="INTEGER"/>
<result property="deviceStatus" column="device_status" jdbcType="VARCHAR"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="PlcDeviceMap">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,data_type,station,device_mode_id,station
from plc_device
-- where device_id = #{deviceId}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="PlcDeviceMap">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time
from plc_device
<where>
<if test="deviceId != null">
and device_id = #{deviceId}
</if>
<if test="deviceCode != null and deviceCode != ''">
and device_code = #{deviceCode}
</if>
<if test="deviceName != null and deviceName != ''">
and device_name = #{deviceName}
</if>
<if test="tenantId != null">
and tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and scene_id = #{sceneId}
</if>
<if test="ip != null and ip != ''">
and ip = #{ip}
</if>
<if test="port1 != null">
and port1 = #{port1}
</if>
<if test="location != null and location != ''">
and location = #{location}
</if>
<if test="accessProtocol != null">
and access_protocol = #{accessProtocol}
</if>
<if test="length != null">
and length = #{length}
</if>
<if test="deviceStatus != null and deviceStatus != ''">
and device_status = #{deviceStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from plc_device
<where>
<if test="deviceId != null">
and device_id = #{deviceId}
</if>
<if test="deviceCode != null and deviceCode != ''">
and device_code = #{deviceCode}
</if>
<if test="deviceName != null and deviceName != ''">
and device_name = #{deviceName}
</if>
<if test="tenantId != null">
and tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and scene_id = #{sceneId}
</if>
<if test="ip != null and ip != ''">
and ip = #{ip}
</if>
<if test="port1 != null">
and port1 = #{port1}
</if>
<if test="location != null and location != ''">
and location = #{location}
</if>
<if test="accessProtocol != null">
and access_protocol = #{accessProtocol}
</if>
<if test="length != null">
and length = #{length}
</if>
<if test="deviceStatus != null and deviceStatus != ''">
and device_status = #{deviceStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
</select>
<select id="queryPlcDevices" resultType="com.ruoyi.business.domain.PlcDevice">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,data_type,station,device_mode_id,station
from plc_device where access_protocol = #{accessProtocol}
</select>
<select id="selectHwDeviceJoinList" resultType="com.ruoyi.business.domain.PlcDevice"
parameterType="com.ruoyi.business.domain.PlcDevice">
select hd.device_id,hd.device_name,
hd.tenant_id,hd.scene_id,hd.device_mode_id,hd.ip,hd.port1,hd.location,hd.data_type,hd.length,
hd.device_status,
hd.access_protocol,hd.station,
hs.scene_name,hdmf.device_mode_name,ht.tenant_name
from plc_device hd
left join hw_scene hs on hd.scene_id = hs.scene_id
left join plc_device_mode hdmf on hd.device_mode_id = hdmf.device_mode_id
left join hw_tenant ht on hd.tenant_id=ht.tenant_id
<where>
and hd.device_status != '9'
<if test="deviceCode != null and deviceCode != ''"> and hd.device_code like concat('%', #{deviceCode}, '%')</if>
<if test="deviceName != null and deviceName != ''"> and hd.device_name like concat('%', #{deviceName}, '%')</if>
<if test="sceneId != null "> and hd.scene_id = #{sceneId}</if>
<if test="deviceModeId != null "> and hd.device_mode_id = #{deviceModeId}</if>
<if test="deviceStatus != null and deviceStatus != ''"> and hd.device_status = #{deviceStatus}</if>
<if test="tenantId != null "> and hd.tenant_id = #{tenantId}</if>
</where>
order by hd.device_id desc
</select>
<select id="selectPlcDeviceMode" resultType="com.ruoyi.business.domain.PlcDeviceMode"
parameterType="com.ruoyi.business.domain.PlcDeviceMode">
select * from plc_device_mode
<where>
<if test="sceneId != null "> and scene_id = #{sceneId}</if>
</where>
order by device_mode_id desc
</select>
<select id="selectHwDeviceByDeviceId" resultType="com.ruoyi.business.domain.PlcDevice"
parameterType="java.lang.Long">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location , access_protocol, length, device_status, create_by, create_time, update_by, update_time,data_type,station,device_mode_id,station
from plc_device
where device_id = #{deviceId}
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="deviceId" useGeneratedKeys="true">
insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,station,data_type,device_mode_id)
values (#{deviceCode}, #{deviceName}, #{tenantId}, #{sceneId}, #{ip}, #{port1}, #{location}, #{accessProtocol}, #{length}, #{deviceStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime},#{station},#{dataType},#{deviceModeId})
</insert>
<insert id="insertBatch" keyProperty="deviceId" useGeneratedKeys="true">
insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="deviceId" useGeneratedKeys="true">
insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
</foreach>
on duplicate key update
device_code = values(device_code),
device_name = values(device_name),
tenant_id = values(tenant_id),
scene_id = values(scene_id),
ip = values(ip),
port1 = values(port1),
location = values(location),
access_protocol = values(access_protocol),
length = values(length),
device_status = values(device_status),
create_by = values(create_by),
create_time = values(create_time),
update_by = values(update_by),
update_time = values(update_time)
</insert>
<!--通过主键修改数据-->
<update id="update">
update plc_device
<set>
<if test="deviceCode != null and deviceCode != ''">
device_code = #{deviceCode},
</if>
<if test="deviceName != null and deviceName != ''">
device_name = #{deviceName},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId},
</if>
<if test="sceneId != null">
scene_id = #{sceneId},
</if>
<if test="ip != null and ip != ''">
ip = #{ip},
</if>
<if test="port1 != null">
port1 = #{port1},
</if>
<if test="location != null and location != ''">
location = #{location},
</if>
<if test="accessProtocol != null">
access_protocol = #{accessProtocol},
</if>
<if test="length != null">
length = #{length},
</if>
<if test="deviceStatus != null and deviceStatus != ''">
device_status = #{deviceStatus},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="dataType != null">
data_type = #{dataType},
</if>
<if test="station != null">
station = #{station},
</if>
</set>
where device_id = #{deviceId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from plc_device where device_id = #{deviceId}
</delete>
</mapper>