场景模型测试工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
scmy/psdc-business/src/main/resources/mapper/business/PsdcDeviceMapper.xml

365 lines
15 KiB

<?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.psdc.mapper.PsdcDeviceMapper">
<resultMap type="com.psdc.entity.PsdcDevice" id="PsdcDeviceMap">
<result property="deviceId" column="device_id" />
<result property="parentId" column="parent_id" />
<result property="userId" column="user_id" />
<result property="deviceType" column="device_type" />
<result property="deviceModel" column="device_model" />
<result property="deviceSn" column="device_sn" />
<result property="deviceName" column="device_name" />
<result property="isControl" column="is_control" />
<result property="hardVersion" column="hard_version" />
<result property="softVersion" column="soft_version" />
<result property="deviceAddress" column="device_address" />
<result property="startTime" column="start_time" />
<result property="deviceStatus" column="device_status" />
<result property="photoUrl" column="photo_url" />
<result property="deviceRunstatus" column="device_runstatus" />
<result property="photoUrl" column="photo_url" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<resultMap id="PsdcDeviceMap2" type="com.psdc.entity.vo.DeviceStatusVo">
<result property="deviceId" column="device_id" />
<result property="deviceType" column="device_type" />
<result property="deviceSn" column="device_sn" />
<result property="deviceName" column="device_name" />
<result property="photoUrl" column="photo_url" />
<result property="deviceRunstatus" column="device_runstatus" />
</resultMap>
<resultMap type="com.psdc.entity.res.PsdcDeviceInfoRes" id="PsdcDeviceMap3">
<result property="deviceId" column="device_id" />
<result property="parentId" column="parent_id" />
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="deviceModel" column="device_model" />
<result property="deviceSn" column="device_sn" />
<result property="deviceName" column="device_name" />
<result property="totp" column="TotP" />
<result property="temp" column="thermometer_value" />
<result property="tempIn" column="thermometer_value_in" />
<result property="tempOut" column="thermometer_value_out" />
<result property="totWh" column="TotWh" />
<result property="deviceAddress" column="device_address" />
<result property="startTime" column="start_time" />
<result property="deviceStatus" column="device_status" />
<result property="deviceRunstatus" column="device_runstatus" />
</resultMap>
<select id="queryDeviceStatusById" resultMap="PsdcDeviceMap2">
Select device_id, device_type, device_sn, device_name, device_runstatus, photo_url From psdc_device
Where device_id = #{deviceId}
</select>
<!-- 通过ID查询单条数据 -->
<select id="queryById" resultMap="PsdcDeviceMap">
select device_id, parent_id, device_model, is_control,
user_id,
device_type,
device_sn,
device_name,
hard_version,
soft_version,
device_address,
start_time,
device_status,
device_runstatus,
photo_url,
create_by,
create_time,
update_by,
update_time
from psdc_device
where device_id = #{deviceId}
</select>
<select id="selMyWorkDevices" resultType="java.lang.Integer">
Select device_id From psdc_device
<where>
<if test="devType != null and devType != ''">
device_type = #{devType}
</if>
<if test="userId != null and userId != ''">
And user_id = #{userId}
</if>
</where>
</select>
<select id="queryByUserId" resultMap="PsdcDeviceMap">
Select * From psdc_device
<where>
<if test="userId != null and userId != ''">
And user_id = #{userId}
</if>
<if test="parentId != null ">
And parent_id = #{parentId}
</if>
</where>
GROUP BY device_model
</select>
<select id="queryByModel" resultMap="PsdcDeviceMap">
Select * From psdc_device
<where>
<if test="userId != null and userId != ''">
And user_id = #{userId}
</if>
<if test="devModel != null and devModel != ''">
and device_model = #{devModel}
</if>
</where>
</select>
<!--分页查询指定行数据-->
<select id="queryAllByLimit" resultMap="PsdcDeviceMap3">
Select
pd.device_id, device_name, device_address, device_status, device_runstatus, parent_id, device_model, su.user_id, su.user_name,
device_sn, per.TotP, per.TotWh, start_time, ptr.thermometer_value, ptr.thermometer_value_in, ptr.thermometer_value_out
From psdc_device pd
Left Join sys_user su On su.user_id = pd.user_id
Left Join psdc_electric_rtdata per On per.device_id = pd.device_id
Left Join psdc_thermometer_rtdata ptr On ptr.device_id = pd.device_id
Where !(device_model = "温度传感器" And parent_id = 0)
<if test="deviceId != null and deviceId != ''">
and pd.device_id = #{deviceId}
</if>
<if test="userId != null and userId != ''">
and pd.user_id = #{userId}
</if>
<if test="deviceModel != null and deviceModel != ''">
and device_model Like concat('%', #{deviceModel}, '%')
</if>
<if test="deviceSn != null and deviceSn != ''">
and device_sn = #{deviceSn}
</if>
<if test="deviceName != null and deviceName != ''">
and device_name = #{deviceName}
</if>
<if test="hardVersion != null and hardVersion != ''">
and hard_version = #{hardVersion}
</if>
<if test="softVersion != null and softVersion != ''">
and soft_version = #{softVersion}
</if>
<if test="deviceAddress != null and deviceAddress != ''">
and device_address = #{deviceAddress}
</if>
<if test="startTime != null and startTime != ''">
and start_time = #{startTime}
</if>
<if test="deviceStatus != null and deviceStatus != ''">
and device_status = #{deviceStatus}
</if>
<if test="deviceRunstatus != null and deviceRunstatus != ''">
and device_runstatus = #{deviceRunstatus}
</if>
<if test="photoUrl != null and photoUrl != ''">
and photo_url = #{photoUrl}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null and createTime != ''">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null and updateTime != ''">
and update_time = #{updateTime}
</if>
Order by pd.device_id
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from psdc_device
<where>
<if test="deviceId != null and deviceId != ''">
and device_id = #{deviceId}
</if>
<if test="userId != null and userId != ''">
and user_id = #{userId}
</if>
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</if>
<if test="deviceSn != null and deviceSn != ''">
and device_sn = #{deviceSn}
</if>
<if test="deviceName != null and deviceName != ''">
and device_name = #{deviceName}
</if>
<if test="hardVersion != null and hardVersion != ''">
and hard_version = #{hardVersion}
</if>
<if test="softVersion != null and softVersion != ''">
and soft_version = #{softVersion}
</if>
<if test="deviceAddress != null and deviceAddress != ''">
and device_address = #{deviceAddress}
</if>
<if test="startTime != null and startTime != ''">
and start_time = #{startTime}
</if>
<if test="deviceStatus != null and deviceStatus != ''">
and device_status = #{deviceStatus}
</if>
<if test="deviceRunstatus != null and deviceRunstatus != ''">
and device_runstatus = #{deviceRunstatus}
</if>
<if test="photoUrl != null and photoUrl != ''">
and photo_url = #{photoUrl}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null and createTime != ''">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null and updateTime != ''">
and update_time = #{updateTime}
</if>
</where>
</select>
<!--新增数据-->
<insert id="insert">
insert into psdc_device(user_id, device_type, device_model, parent_id, is_control, device_sn, device_name, hard_version, soft_version,
device_address, start_time, device_status, device_runstatus, photo_url, create_by,
create_time, update_by, update_time)
values (#{userId}, #{deviceType}, #{deviceModel},#{parentId},#{isControl}, #{deviceSn}, #{deviceName}, #{hardVersion}, #{softVersion}, #{deviceAddress},
#{startTime}, #{deviceStatus}, #{deviceRunstatus}, #{photoUrl}, #{createBy}, #{createTime}, #{updateBy},
#{updateTime})
</insert>
<insert id="saveDevicesData" parameterType="com.psdc.entity.PsdcDevice" useGeneratedKeys="true">
Insert into psdc_device(user_id, device_type, device_sn, parent_id, device_model, is_control, device_name, hard_version, soft_version,
device_address, start_time, device_status, device_runstatus, photo_url, create_by,
create_time, update_by, update_time)
Values
<foreach collection="devRecord" item="entity" separator=",">
(NULL, #{entity.deviceType}, #{entity.deviceSn},#{entity.parentId}, #{entity.deviceModel}, #{entity.isControl}, #{entity.deviceName}, #{entity.hardVersion}, #{entity.softVersion}, #{entity.deviceAddress},
#{entity.startTime}, #{entity.deviceStatus}, #{entity.deviceRunstatus}, #{entity.photoUrl}, #{entity.createBy}, #{entity.createTime}, NULL, NULL)
</foreach>
</insert>
<!-- 更新数据 -->
<update id="update">
update psdc_device
<set>
<if test="deviceId != null and deviceId != ''">
device_id = #{deviceId},
</if>
<if test="userId != null and userId != ''">
user_id = #{userId},
</if>
<if test="parentId != null and parentId != ''">
parent_id = #{parentId},
</if>
<if test="deviceType != null and deviceType != ''">
device_type = #{deviceType},
</if>
<if test="deviceModel != null and deviceModel != ''">
device_model = #{deviceModel},
</if>
<if test="deviceSn != null and deviceSn != ''">
device_sn = #{deviceSn},
</if>
<if test="deviceName != null and deviceName != ''">
device_name = #{deviceName},
</if>
<if test="hardVersion != null and hardVersion != ''">
hard_version = #{hardVersion},
</if>
<if test="softVersion != null and softVersion != ''">
soft_version = #{softVersion},
</if>
<if test="deviceAddress != null and deviceAddress != ''">
device_address = #{deviceAddress},
</if>
<if test="startTime != null and startTime != ''">
start_time = #{startTime},
</if>
<if test="deviceStatus != null and deviceStatus != ''">
device_status = #{deviceStatus},
</if>
<if test="deviceRunstatus != null and deviceRunstatus != ''">
device_runstatus = #{deviceRunstatus},
</if>
<if test="photoUrl != null and photoUrl != ''">
photo_url = #{photoUrl},
</if>
<if test="isControl != null and isControl != ''">
is_control = #{isControl},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="createTime != null and createTime != ''">
create_time = #{createTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="updateTime != null ">
update_time = #{updateTime},
</if>
</set>
where device_id = #{deviceId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from psdc_device where device_id in
<foreach collection="deviceIds" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</delete>
<update id="updateDevRunStatusByDevId">
update psdc_device set device_runstatus = #{runStatus} where device_id = #{deviceId}
</update>
<update id="upDevStaUser">
Update psdc_device Set user_id = #{userId} Where device_id = ${devId}
</update>
<!-- 根据设备id查询设备名称-->
<select id="queryDeviceNameByDeviceId" resultType="string">
select device_name from psdc_device where device_id = #{deviceId}
</select>
<select id="controlQueryByUserId" resultMap="PsdcDeviceMap" >
select device_id,
user_id,
device_type,
device_sn,
device_name,
hard_version,
soft_version,
device_address,
start_time,
device_status,
device_runstatus,
photo_url,
create_by,
create_time,
update_by,
update_time
from psdc_device
where user_id = #{userId} and is_control = 2
</select>
</mapper>