2025-11-11 09:49:51 +08:00
<?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.bonus.waterdesign.mapper.DeviceMapper" >
<insert id= "add" >
insert into tb_device(device_name,device_type,device_code,user_id,status,remark) values(#{deviceName},#{deviceType},#{deviceCode},#{userId},#{status},#{remark})
</insert>
<insert id= "addUseRecord" >
insert into tb_device_record(device_id,user_id,start_time) values(#{deviceId},#{userId},#{startTime})
</insert>
<update id= "update" >
2025-11-11 18:10:08 +08:00
UPDATE tb_device
<set >
<if test= "deviceName != null and deviceName != ''" >
device_name = #{deviceName},
</if>
<if test= "deviceType != null and deviceType != ''" >
device_type = #{deviceType},
</if>
<if test= "deviceCode != null and deviceCode != ''" >
device_code = #{deviceCode},
</if>
<if test= "userId != null" >
user_id = #{userId},
</if>
<if test= "status != null and status != ''" >
status = #{status},
</if>
<if test= "remark != null and remark != ''" >
remark = #{remark},
</if>
</set>
WHERE id = #{id}
2025-11-11 09:49:51 +08:00
</update>
<update id= "updateStatus" >
update tb_device set status = #{status} where id = #{deviceId}
</update>
<update id= "updateReturnRecord" >
update tb_device_record set end_time = #{endTime} where device_id = #{deviceId} and end_time is null
</update>
<delete id= "delete" >
delete from tb_device where id = #{id}
</delete>
<select id= "get" resultType= "com.bonus.waterdesign.domain.DeviceDto" >
2025-11-11 16:39:36 +08:00
select
device_name as deviceName,
device_type as deviceType,
device_code as deviceCode,
user_id as userId,
status,
remark
from tb_device
where id = #{id}
</select>
2025-11-11 09:49:51 +08:00
<select id= "list" resultType= "com.bonus.waterdesign.domain.DeviceDto" >
2025-11-11 16:39:36 +08:00
select
2025-11-11 18:10:08 +08:00
td.id,
td.device_name as deviceName,
td.device_type as deviceType,
tdt.type_name as deviceTypeName,
td.device_code as deviceCode,
td.user_id as userId,
su.nick_name as userName,
td.status,
td.remark
from tb_device td
left join tb_device_type tdt on td.device_type = tdt.id
left join sys_user su on td.user_id = su.user_id
where td.del_flag = 0
2025-11-11 16:39:36 +08:00
<if test= "deviceCode != null and deviceCode != ''" >
2025-11-11 18:10:08 +08:00
and td.device_code like concat ('%',#{deviceCode},'%')
2025-11-11 16:39:36 +08:00
</if>
<if test= "status != null and status != ''" >
2025-11-11 18:10:08 +08:00
and td.status = #{status}
2025-11-11 16:39:36 +08:00
</if>
<if test= "deviceType != null and deviceType != ''" >
2025-11-11 18:10:08 +08:00
and td.device_type = #{deviceType}
2025-11-11 16:39:36 +08:00
</if>
</select>
2025-11-11 09:49:51 +08:00
<select id= "getDeviceType" resultType= "com.bonus.waterdesign.domain.SelectDto" >
select id,
type_name as name
from tb_device_type
</select>
<select id= "getLastUse" resultType= "com.bonus.waterdesign.domain.DeviceRecord" >
select tdr.user_id as userId,
su.nick_name as userName,
tdr.start_time as startTime
from tb_device_record tdr
left join sys_user su on tdr.user_id = su.user_id
2025-11-11 18:10:08 +08:00
where tdr.device_id = #{deviceId} and start_time is not null and end_time is null
2025-11-11 09:49:51 +08:00
order by id desc limit 1
</select>
<select id= "getRecordList" resultType= "com.bonus.waterdesign.domain.DeviceRecord" >
select tdr.device_id as deviceId,
tdr.user_id as userId,
su.nick_name as userName,
tdr.start_time as startTime,
tdr.end_time as endTime,
tdr.status as status,
td.device_type as deviceType,
sd.dict_label as deviceTypeName
from tb_device_record tdr
left join tb_device td on tdr.device_id = td.id
left join sys_user su on tdr.user_id = su.user_id
left join tb_device_type sd on td.device_type = sd.id
where tdr.device_id = #{deviceId}
<if test= "userId != null and userId != ''" >
and tdr.user_id = #{userId}
</if>
<if test= "startTime != null and startTime != ''" >
and tdr.start_time = #{startTime}
</if>
<if test= "endTime != null and endTime != ''" >
and tdr.end_time = #{endTime}
</if>
2025-11-11 18:10:08 +08:00
order by tdr.id desc
2025-11-11 09:49:51 +08:00
</select>
2025-11-11 16:39:36 +08:00
<select id= "getCount" resultType= "java.lang.Integer" >
select count(1) from tb_device
where del_flag = 0 and device_code = #{deviceCode}
<if test= "id != null and id != ''" >
and id != #{id}
</if>
</select>
2025-11-11 18:10:08 +08:00
<select id= "getDeviceKeepUser" resultType= "com.bonus.waterdesign.domain.SelectDto" >
select
user_id as id,
nick_name as name
from sys_user
where del_flag = 0 and status = 0 and user_id not in (1,2)
</select>
2025-11-11 09:49:51 +08:00
</mapper>