SafetyAlertSystem/bonus-modules/bonus-base/src/main/resources/mapper/base/TbDeviceMapper.xml

333 lines
12 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.base.mapper.TbDeviceMapper">
<resultMap id="BaseResultMap" type="com.bonus.base.domain.TbDevice">
<!--@mbg.generated-->
<!--@Table tb_device-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="dev_type" jdbcType="VARCHAR" property="devType" />
<result column="dev_code" jdbcType="VARCHAR" property="devCode" />
<result column="dev_name" jdbcType="VARCHAR" property="devName" />
<result column="bd_id" jdbcType="BIGINT" property="bdId" />
<result column="config_id" jdbcType="BIGINT" property="configId" />
<result column="dev_status" jdbcType="INTEGER" property="devStatus" />
<result column="dev_warn" jdbcType="INTEGER" property="devWarn" />
<result column="del_flag" jdbcType="INTEGER" property="delFlag" />
<result column="logo_url" jdbcType="VARCHAR" property="logoUrl" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, dev_type, dev_code, dev_name, bd_id, config_id, dev_status, dev_warn, del_flag,
logo_url
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List" />
from tb_device
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
update tb_device set del_flag = 1
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.bonus.base.domain.TbDevice">
<!--@mbg.generated-->
insert into tb_device (id, dev_type, dev_code,
dev_name, bd_id, config_id,
dev_status, dev_warn, del_flag,
logo_url)
values (#{id,jdbcType=BIGINT}, #{devType,jdbcType=VARCHAR}, #{devCode,jdbcType=VARCHAR},
#{devName,jdbcType=VARCHAR}, #{bdId,jdbcType=BIGINT}, #{configId,jdbcType=BIGINT},
#{devStatus,jdbcType=INTEGER}, #{devWarn,jdbcType=INTEGER}, #{delFlag,jdbcType=INTEGER},
#{logoUrl,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.bonus.base.domain.TbDevice">
<!--@mbg.generated-->
insert into tb_device
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="devType != null and devType != ''">
dev_type,
</if>
<if test="devCode != null and devCode != ''">
dev_code,
</if>
<if test="devName != null and devName != ''">
dev_name,
</if>
<if test="bdId != null">
bd_id,
</if>
<if test="configId != null">
config_id,
</if>
<if test="devStatus != null">
dev_status,
</if>
<if test="devWarn != null">
dev_warn,
</if>
del_flag,
<if test="logoUrl != null and logoUrl != ''">
logo_url,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="devType != null and devType != ''">
#{devType,jdbcType=VARCHAR},
</if>
<if test="devCode != null and devCode != ''">
#{devCode,jdbcType=VARCHAR},
</if>
<if test="devName != null and devName != ''">
#{devName,jdbcType=VARCHAR},
</if>
<if test="bdId != null">
#{bdId,jdbcType=BIGINT},
</if>
<if test="configId != null">
#{configId,jdbcType=BIGINT},
</if>
<if test="devStatus != null">
#{devStatus,jdbcType=INTEGER},
</if>
<if test="devWarn != null">
#{devWarn,jdbcType=INTEGER},
</if>
0,
<if test="logoUrl != null and logoUrl != ''">
#{logoUrl,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.bonus.base.domain.TbDevice">
<!--@mbg.generated-->
update tb_device
<set>
<if test="devType != null and devType != ''">
dev_type = #{devType,jdbcType=VARCHAR},
</if>
<if test="devCode != null and devCode != ''">
dev_code = #{devCode,jdbcType=VARCHAR},
</if>
<if test="devName != null and devName != ''">
dev_name = #{devName,jdbcType=VARCHAR},
</if>
<if test="bdId != null">
bd_id = #{bdId,jdbcType=BIGINT},
</if>
<if test="configId != null">
config_id = #{configId,jdbcType=BIGINT},
</if>
<if test="devStatus != null">
dev_status = #{devStatus,jdbcType=INTEGER},
</if>
<if test="devWarn != null">
dev_warn = #{devWarn,jdbcType=INTEGER},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=INTEGER},
</if>
<if test="logoUrl != null and logoUrl != ''">
logo_url = #{logoUrl,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.bonus.base.domain.TbDevice">
<!--@mbg.generated-->
update tb_device
set dev_type = #{devType,jdbcType=VARCHAR},
dev_code = #{devCode,jdbcType=VARCHAR},
dev_name = #{devName,jdbcType=VARCHAR},
bd_id = #{bdId,jdbcType=BIGINT},
config_id = #{configId,jdbcType=BIGINT},
dev_status = #{devStatus,jdbcType=INTEGER},
dev_warn = #{devWarn,jdbcType=INTEGER},
del_flag = #{delFlag,jdbcType=INTEGER},
logo_url = #{logoUrl,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateBatch" parameterType="java.util.List">
<!--@mbg.generated-->
update tb_device
<trim prefix="set" suffixOverrides=",">
<trim prefix="dev_type = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.devType,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="dev_code = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.devCode,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="dev_name = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.devName,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="bd_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.bdId,jdbcType=BIGINT}
</foreach>
</trim>
<trim prefix="config_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.configId,jdbcType=BIGINT}
</foreach>
</trim>
<trim prefix="dev_status = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.devStatus,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="dev_warn = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.devWarn,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="del_flag = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.delFlag,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="logo_url = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=BIGINT} then #{item.logoUrl,jdbcType=VARCHAR}
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
<delete id="deleteByPrimaryKeyIn">
update tb_device set del_flag = 1 where id in
<foreach close=")" collection="list" item="id" open="(" separator=", ">
#{id,jdbcType=BIGINT}
</foreach>
</delete>
<select id="getDeviceView" resultType="com.bonus.screen.vo.DeviceViewVo">
select count(1) as deviceTotal,
count(dev_status = 1) as deviceOnlineTotal
from tb_device
where del_flag = 0
</select>
<select id="getSensingDevice" resultType="com.bonus.screen.vo.DeviceViewVo">
select count(1) as deviceTotal,
count(CASE WHEN dev_type = #{param1.code} THEN 1 END) as baseSafetyHat,
count(CASE WHEN dev_type = #{param2.code} THEN 1 END) as baseEnvironmentMonitor,
count(CASE WHEN dev_type = #{param3.code} THEN 1 END) as basePitMonitor,
count(CASE WHEN dev_type = #{param4.code} THEN 1 END) as towerRakeMonitor,
count(CASE WHEN dev_type = #{param5.code} THEN 1 END) as towerWaterMonitor,
count(CASE WHEN dev_type = #{param6.code} THEN 1 END) as leadStrainMonitor
from tb_device
where del_flag = 0
</select>
<select id="getAll" resultType="com.bonus.base.domain.TbDevice">
SELECT
td.id as id,
td.dev_type as devType,
sda.dict_label as devTypeName,
td.dev_code as devCode,
td.dev_name as devName,
td.bd_id as bdId,
t1.dev_name as bdName,
td.config_id as configId,
t2.config_name as configName,
td.dev_status as devStatus,
CASE
WHEN td.dev_status = 0 THEN
'离线'
WHEN td.dev_status = 1 THEN
'在线'
ELSE
'未知状态'
END devStatusName,
td.dev_warn as devWarn,
td.del_flag as delFlag,
td.logo_url as logoUrl
FROM
tb_device td
LEFT JOIN sys_dict_data sda ON td.dev_type = sda.dict_code
LEFT JOIN tb_bd_device_record t1 on td.bd_id = t1.id
LEFT JOIN tb_warn_config t2 on t2.id = td.config_id and t2.del_flag = 0
WHERE
td.del_flag = 0
<if test="devType != null and devType != ''">
and td.dev_type = #{devType}
</if>
<if test="devName != null and devName != ''">
and td.dev_name like concat('%',#{devName},'%')
</if>
<if test="devCode != null and devCode != ''">
and td.dev_code like concat('%',#{devCode},'%')
</if>
<if test="devStatus != null">
and td.dev_status = #{devStatus}
</if>
</select>
<select id="selectByDevCode" resultType="com.bonus.base.domain.TbDevice">
select
<include refid="Base_Column_List" />
from tb_device
where del_flag = 0
<if test="devName != null and devName != ''">
<if test="devCode != null and devCode != ''">
and (dev_name = #{devName} or dev_code = #{devCode})
</if>
<if test="devCode == null or devCode == ''">
and dev_name = #{devName}
</if>
</if>
<if test="devName == null or devName == ''">
<if test="devCode != null and devCode != ''">
and dev_code = #{devCode}
</if>
</if>
<if test="devType != null and devType != ''">
and dev_type = #{devType}
</if>
</select>
<select id="getDeviceModelDetailsPage" resultType="com.bonus.screen.vo.DeviceWarnRecordVo">
SELECT
td.dev_name as devName,
td.dev_code AS devCode,
td.dev_type AS devTypeName,
CASE WHEN td.dev_status = 0 THEN '离线'
WHEN td.dev_status = 1 THEN '在线'
ELSE '未知状态' END devStatusName,
tp.pro_name AS proName,
tbdr.dev_name AS bdDeviceName,
tbdr.dev_user AS devUserName
FROM tb_device td
LEFT JOIN tb_bd_device_record tbdr ON tbdr.id = td.bd_id
LEFT JOIN tb_project tp ON tbdr.pro_id = tp.id
WHERE td.del_flag = 0
<if test="devTypeCode != null">
and td.dev_type = #{devTypeCode}
</if>
</select>
</mapper>