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

143 lines
4.5 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.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>
<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}
</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">
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>
<select id="list" resultType="com.bonus.waterdesign.domain.DeviceDto">
select
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
<if test="deviceCode != null and deviceCode != ''">
and td.device_code like concat ('%',#{deviceCode},'%')
</if>
<if test="status != null and status != ''">
and td.status = #{status}
</if>
<if test="deviceType != null and deviceType != ''">
and td.device_type = #{deviceType}
</if>
</select>
<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 and end_time is 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 tdr.id desc
</select>
<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>
<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>
</mapper>