water-design-const-service/water-design-const/src/main/resources/mapper/DeviceMapper.xml

133 lines
4.4 KiB
XML
Raw Normal View History

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">
UPDATE tb_device
<set>
<trim prefix="(" suffix=")" suffixOverrides=",">
<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>
</trim>
</set>
WHERE id = #{id}
</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
device_name as deviceName,
device_type as deviceType,
device_code as deviceCode,
user_id as userId,
status,
remark
from tb_device
where del_flag = 0
<if test="deviceCode != null and deviceCode != ''">
and device_code like concat ('%',#{deviceCode},'%')
</if>
<if test="status != null and status != ''">
and status = #{status}
</if>
<if test="deviceType != null and deviceType != ''">
and device_type = #{deviceType}
</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
where tdr.device_id = #{deviceId} and start_time is not null
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>
order by id desc
</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 09:49:51 +08:00
</mapper>